Subversion Repositories Kolibri OS

Rev

Rev 8955 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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