Subversion Repositories Kolibri OS

Rev

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