Subversion Repositories Kolibri OS

Rev

Rev 7437 | Rev 7532 | 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. #include "engine.h"
  43.  
  44. dword ed_mouse;
  45. edit_box notebox = {NULL,NULL,NULL,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,
  46.         MAX_LINE_CHARS-1,NULL,#ed_mouse,ed_always_focus+ed_focus};
  47. dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
  48.  
  49. bool delete_active = false;
  50. bool window_dragable = true;
  51. block delBtn;
  52.  
  53. //===================================================//
  54. //                                                   //
  55. //                       CODE                        //
  56. //                                                   //
  57. //===================================================//
  58.  
  59. void main()
  60. {  
  61.         int btn;
  62.         bool first_redraw=true;
  63.         dword cur_line_offset;
  64.         load_dll(boxlib, #box_lib_init,0);
  65.  
  66.         if (GetCpuFrequency()/1000000>=1000) window_dragable=true; else window_dragable=false;
  67.        
  68.         if (param) notes.OpenTxt(#param); else notes.OpenTxt(abspath("notes.txt"));
  69.  
  70.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  71.  
  72.         loop() switch(WaitEvent())
  73.         {
  74.                 case evMouse:
  75.                         edit_box_mouse stdcall (#notebox);
  76.  
  77.                         mouse.get();
  78.  
  79.                         if (delete_active) && (delBtn.hovered()) break;
  80.  
  81.                         if (mouse.lkm) && (mouse.y<TITLE_H) && (mouse.x<WIN_W-39)
  82.                                 && (window_dragable) EventDragWindow();
  83.  
  84.                         if (mouse.pkm)
  85.                         && (notes.MouseOver(mouse.x, mouse.y)) {
  86.                                 if (notes.ProcessMouse(mouse.x, mouse.y)) EventListRedraw();
  87.                                 EventDrawDeleteButton();
  88.                         }
  89.  
  90.                         if (mouse.key&MOUSE_LEFT)&&(mouse.up)
  91.                         && (notes.ProcessMouse(mouse.x, mouse.y)) {
  92.                                 notebox.pos = mouse.x - notebox.left / 6;
  93.                                 EventListRedraw();
  94.                                 EventActivateLine(notes.cur_y);
  95.                         }
  96.  
  97.                         break;
  98.  
  99.                  case evButton:
  100.                         btn = GetButtonID();
  101.                         switch(btn)
  102.                         {
  103.                                 case CLOSE_BTN:
  104.                                         EventExitApp();
  105.                                         break;
  106.                                 case DELETE_BTN:
  107.                                         EventDeleteCurrentNode();
  108.                                         break;
  109.                                 default:
  110.                                         EventCheckBoxClick(btn-CHECKBOX_ID);
  111.                                         break;
  112.                         }  
  113.                         break;
  114.          
  115.                 case evKey:
  116.                         GetKeys();
  117.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
  118.                         {
  119.                                 if (key_scancode == SCAN_CODE_SPACE)
  120.                                 {
  121.                                         EventCheckBoxClick(notes.cur_y);
  122.                                 }
  123.                                 break;
  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(100,100,WIN_W, WIN_H);
  168.         else
  169.                 DefineDragableWindow(100,100,WIN_W, WIN_H);
  170.         notes.SetSizes(RED_LINE_X+1, HEADER_HEIGHT, WIN_W-1, RED_LINE_X*LINES_COUNT, RED_LINE_X);
  171.         DrawRectangle3D(0,0,WIN_W,TITLE_H-1,0xBB6535, 0xCD6F3B);
  172.         DrawRectangle3D(1,1,WIN_W-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
  173.         DrawBar(2,2,WIN_W-3,TITLE_H-4,0xE08C5E);
  174.         WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
  175.         WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
  176.         _PutImage(1, TITLE_H, 292,EDGE_H, #edge);
  177.         PutPixel(notes.x, notes.y-1, COL_RED_LINE);
  178.         ECX-=1; $int 0x40;
  179.         DrawCloseButton(WIN_W-23,4,16,16);
  180.         DrawRectangle(0,TITLE_H,WIN_W,WIN_H-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
  181.         for (i=0; lists[i]!=0; i++) DrawBar(1,WIN_H-i-1, WIN_W-1, 1, lists[i]);
  182.         EventListRedraw();
  183. }
  184.  
  185. void DrawEditBoxN()
  186. {
  187.         notebox.width = notes.w-notes.x-8;
  188.         notebox.left = notes.x+5;
  189.         notebox.offset = notebox.shift = notebox.shift_old = 0;
  190.         notebox.cl_curs_x = notebox.cl_curs_y = 0;
  191.         notebox.size = strlen(notebox.text);
  192.         notebox.flags = ed_always_focus+ed_focus;
  193.         if (notebox.pos > notebox.size) notebox.pos = notebox.size;
  194.         notebox.top = notes.cur_y*notes.item_h+4+notes.y;
  195.         edit_box_draw stdcall(#notebox);       
  196. }
  197.  
  198. //===================================================//
  199. //                                                   //
  200. //                     EVENTS                        //
  201. //                                                   //
  202. //===================================================//
  203.  
  204. void EventActivateLine(int line_n)
  205. {
  206.         if (line_n<0) || (line_n>=notes.count) return;
  207.         notes.cur_y = line_n;
  208.         notebox.text = notes.DrawLine(notes.cur_y, notes.item_h);
  209.         EventListRedraw();
  210.         DrawEditBoxN();
  211. }
  212.  
  213. void EventExitApp()
  214. {
  215.         notes.SaveTxt();
  216.         ExitProcess();
  217. }
  218.  
  219. void EventDrawDeleteButton()
  220. {
  221.         notes.DrawLine(notes.cur_y, notes.item_h);
  222.         delBtn.set_size(WIN_W-DELETE_W-1, notes.cur_y*notes.item_h+notes.y, DELETE_W, notes.item_h-1);
  223.         DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000);
  224.         WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT);
  225.         notebox.top=-20;
  226.         delete_active = true;
  227. }
  228.  
  229. void EventDeleteCurrentNode()
  230. {
  231.         int t = notes.cur_y;
  232.         notes.lines[t].Delete();
  233.         EventListRedraw();
  234. }
  235.  
  236. void EventListRedraw()
  237. {
  238.         delete_active = false;
  239.         DeleteButton(DELETE_BTN);
  240.         notes.DrawList();
  241. }
  242.  
  243. void EventCheckBoxClick(int id)
  244. {
  245.         notes.lines[id].state ^= 1;
  246.         EventListRedraw();
  247. }
  248.  
  249. stop:
  250.