Subversion Repositories Kolibri OS

Rev

Rev 7730 | Rev 8954 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // Notes v1.1
  2.  
  3. #define MEMSIZE 0xDAE80
  4. #include "..\lib\kolibri.h"
  5.  
  6. #include "..\lib\obj\box_lib.h"
  7. #include "..\lib\gui.h"
  8. #include "..\lib\list_box.h"
  9.  
  10. //===================================================//
  11. //                                                   //
  12. //                       DATA                        //
  13. //                                                   //
  14. //===================================================//
  15.  
  16. #ifndef AUTOBUILD
  17.         #include "lang.h--"
  18. #endif
  19.  
  20. #ifdef LANG_RUS
  21.         ?define WINDOW_CAPTION "‡ ¬¥âª¨"
  22.         ?define DELETE_TEXT "“¤ «¨âì";
  23. #else
  24.         ?define WINDOW_CAPTION "Notes and reminders"
  25.         ?define DELETE_TEXT "Delete";
  26. #endif
  27.  
  28. #define RED_LINE_X 22
  29. #define COL_RED_LINE 0xF3C9C9
  30. unsigned char edge[sizeof(file "img/edge.raw")]= FROM "img/edge.raw"; //292x6
  31. #define EDGE_H 6
  32. #define TITLE_H 24
  33. #define HEADER_HEIGHT TITLE_H+EDGE_H
  34. #define LINES_COUNT 13
  35.  
  36. #define WIN_W 270
  37. #define WIN_H RED_LINE_X*LINES_COUNT+HEADER_HEIGHT+4
  38.  
  39. #define DELETE_BTN 4;
  40. #define DELETE_W sizeof(DELETE_TEXT)+2*6
  41.  
  42. proc_info Form;
  43.  
  44. #include "engine.h"
  45. #include "ini.h"
  46.  
  47. edit_box notebox = {NULL,NULL,NULL,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,
  48.         MAX_LINE_CHARS-1,NULL,0,ed_always_focus+ed_focus};
  49. dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
  50.  
  51. bool delete_active = false;
  52. bool window_dragable = true;
  53. block delBtn;
  54.  
  55. //===================================================//
  56. //                                                   //
  57. //                       CODE                        //
  58. //                                                   //
  59. //===================================================//
  60.  
  61. void main()
  62. {  
  63.         bool first_redraw=true;
  64.         dword cur_line_offset;
  65.         load_dll(boxlib, #box_lib_init,0);
  66.  
  67.         if (GetCpuFrequency()/1000000>=1000) window_dragable=true; else window_dragable=false;
  68.        
  69.         if (param) notes.OpenTxt(#param); else notes.OpenTxt("/sys/notes.txt");
  70.  
  71.         @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  72.         LoadIniSettings();
  73.  
  74.         loop() switch(@WaitEvent())
  75.         {
  76.                 case evMouse:
  77.                         edit_box_mouse stdcall (#notebox);
  78.  
  79.                         mouse.get();
  80.  
  81.                         if (delete_active) && (delBtn.hovered()) break;
  82.  
  83.                         if (mouse.lkm) && (mouse.y<TITLE_H) && (mouse.x<WIN_W-39)
  84.                                 && (window_dragable) EventDragWindow();
  85.  
  86.                         if (mouse.pkm)
  87.                         && (notes.MouseOver(mouse.x, mouse.y)) {
  88.                                 if (notes.ProcessMouse(mouse.x, mouse.y)) EventListRedraw();
  89.                                 EventDrawDeleteButton();
  90.                         }
  91.  
  92.                         if (mouse.key&MOUSE_LEFT)&&(mouse.up)
  93.                         && (notes.ProcessMouse(mouse.x, mouse.y)) {
  94.                                 notebox.pos = mouse.x - notebox.left / 6;
  95.                                 EventListRedraw();
  96.                                 EventActivateLine(notes.cur_y);
  97.                         }
  98.  
  99.                         break;
  100.  
  101.                  case evButton:
  102.                         @GetButtonID();
  103.                         switch(EAX)
  104.                         {
  105.                                 case CLOSE_BTN:
  106.                                         EventExitApp();
  107.                                         break;
  108.                                 case DELETE_BTN:
  109.                                         EventDeleteCurrentNode();
  110.                                         break;
  111.                                 default:
  112.                                         EventCheckBoxClick(EAX-CHECKBOX_ID);
  113.                                         break;
  114.                         }  
  115.                         break;
  116.          
  117.                 case evKey:
  118.                         GetKeys();
  119.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
  120.                         {
  121.                                 if (key_scancode == SCAN_CODE_SPACE)
  122.                                 {
  123.                                         EventCheckBoxClick(notes.cur_y);
  124.                                 }
  125.                         }
  126.                         switch(key_scancode)
  127.                         {
  128.                                 case SCAN_CODE_ESC:
  129.                                         EventExitApp();
  130.                                         break;
  131.                                 case SCAN_CODE_DOWN:
  132.                                         EventActivateLine(notes.cur_y+1);
  133.                                         break;
  134.                                 case SCAN_CODE_UP:
  135.                                         EventActivateLine(notes.cur_y-1);
  136.                                         break;
  137.                                 default:
  138.                                         if (notes.cur_y>=0) {
  139.                                                 EAX = key_editbox;
  140.                                                 edit_box_key stdcall (#notebox);
  141.                                         }
  142.                                
  143.                         }
  144.                         break;
  145.                  
  146.                  case evReDraw:
  147.                         draw_window();
  148.                         if (first_redraw) {
  149.                                 first_redraw = false;
  150.                                 EventActivateLine(0);
  151.                         }
  152.    }
  153. }
  154.  
  155. void DrawCloseButton(dword x,y,w,h)
  156. {
  157.         DrawRectangle(x,y,w,h,0xC96832);
  158.         DrawRectangle3D(x+1,y+1,w-2,h-2,0xE6A37F,0xDD8452);
  159.         PutPixel(x+w-1, y+1, 0xE08C5E);
  160.         DefineButton(x+1,y+1,w-1,h-1,CLOSE_BTN+BT_HIDE,0);
  161.         WriteTextB(-6+w/2+x,h/2-4+y,0x80,0xFFFfff,"x");
  162. }
  163.  
  164. void draw_window()
  165. {
  166.         int i;
  167.         if (window_dragable)
  168.                 DefineUnDragableWindow(Form.left,Form.top,WIN_W, WIN_H);
  169.         else
  170.                 DefineDragableWindow(Form.left,Form.top,WIN_W, WIN_H);
  171.         GetProcessInfo(#Form, SelfInfo);
  172.         notes.SetSizes(RED_LINE_X+1, HEADER_HEIGHT, WIN_W-1, RED_LINE_X*LINES_COUNT, RED_LINE_X);
  173.         DrawRectangle3D(0,0,WIN_W,TITLE_H-1,0xBB6535, 0xCD6F3B);
  174.         DrawRectangle3D(1,1,WIN_W-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
  175.         DrawBar(2,2,WIN_W-3,TITLE_H-4,0xE08C5E);
  176.         WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
  177.         WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
  178.         _PutImage(1, TITLE_H, 292,EDGE_H, #edge);
  179.         PutPixel(notes.x, notes.y-1, COL_RED_LINE);
  180.         ECX-=1; $int 0x40;
  181.         DrawCloseButton(WIN_W-23,4,16,16);
  182.         DrawRectangle(0,TITLE_H,WIN_W,WIN_H-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
  183.         for (i=0; lists[i]!=0; i++) DrawBar(1,WIN_H-i-1, WIN_W-1, 1, lists[i]);
  184.         EventListRedraw();
  185. }
  186.  
  187. void DrawEditBoxN()
  188. {
  189.         notebox.width = notes.w-notes.x-8;
  190.         notebox.left = notes.x+5;
  191.         notebox.offset = notebox.shift = notebox.shift_old = 0;
  192.         notebox.cl_curs_x = notebox.cl_curs_y = 0;
  193.         notebox.size = strlen(notebox.text);
  194.         notebox.flags = ed_always_focus+ed_focus;
  195.         if (notebox.pos > notebox.size) notebox.pos = notebox.size;
  196.         notebox.top = notes.cur_y*notes.item_h+4+notes.y;
  197.         edit_box_draw stdcall(#notebox);       
  198. }
  199.  
  200. //===================================================//
  201. //                                                   //
  202. //                     EVENTS                        //
  203. //                                                   //
  204. //===================================================//
  205.  
  206. void EventActivateLine(int line_n)
  207. {
  208.         if (line_n<0) || (line_n>=notes.count) return;
  209.         notes.cur_y = line_n;
  210.         notebox.text = notes.DrawLine(notes.cur_y, notes.item_h);
  211.         EventListRedraw();
  212.         DrawEditBoxN();
  213. }
  214.  
  215. void EventExitApp()
  216. {
  217.         notes.SaveTxt();
  218.         SaveIniSettings();
  219.         ExitProcess();
  220. }
  221.  
  222. void EventDrawDeleteButton()
  223. {
  224.         notes.DrawLine(notes.cur_y, notes.item_h);
  225.         delBtn.set_size(WIN_W-DELETE_W-1, notes.cur_y*notes.item_h+notes.y, DELETE_W, notes.item_h-1);
  226.         DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000);
  227.         WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT);
  228.         notebox.top=-20;
  229.         delete_active = true;
  230. }
  231.  
  232. void EventDeleteCurrentNode()
  233. {
  234.         dword t;
  235.         t = notes.cur_y;
  236.         notes.lines[t].Delete();
  237.         EventListRedraw();
  238. }
  239.  
  240. void EventListRedraw()
  241. {
  242.         delete_active = false;
  243.         DeleteButton(DELETE_BTN);
  244.         notes.DrawList();
  245. }
  246.  
  247. void EventCheckBoxClick(int id)
  248. {
  249.         notes.lines[id].state ^= 1;
  250.         EventListRedraw();
  251. }
  252.  
  253. stop:
  254.