Subversion Repositories Kolibri OS

Rev

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

  1. // Notes v0.9 Beta
  2.  
  3. #define MEMSIZE 0xDAE80
  4. #include "..\lib\kolibri.h"
  5. #include "..\lib\mem.h"
  6. #include "..\lib\strings.h"
  7. #include "..\lib\fs.h"
  8. #include "..\lib\dll.h"
  9.  
  10. #include "..\lib\obj\box_lib.h"
  11. #include "..\lib\gui.h"
  12. #include "..\lib\encoding.h"
  13. #include "..\lib\list_box.h"
  14.  
  15. //===================================================//
  16. //                                                   //
  17. //                       DATA                        //
  18. //                                                   //
  19. //===================================================//
  20.  
  21. #ifndef AUTOBUILD
  22.         #include "lang.h--"
  23. #endif
  24.  
  25. #ifdef LANG_RUS
  26.         ?define WINDOW_CAPTION "‡ ¬¥âª¨"
  27.         ?define DELETE_TEXT "“¤ «¨âì";
  28. #else
  29.         ?define WINDOW_CAPTION "Notes and reminders"
  30.         ?define DELETE_TEXT "Delete";
  31. #endif
  32.  
  33. #define RED_LINE_X 22
  34. #define COL_RED_LINE 0xF3C9C9
  35. unsigned char edge[sizeof(file "img/edge.raw")]= FROM "img/edge.raw"; //292x6
  36. #define EDGE_H 6
  37. #define TITLE_H 24
  38. #define HEADER_HEIGHT TITLE_H+EDGE_H
  39. #define LINES_COUNT 13
  40.  
  41. #define WIN_W 270
  42. #define WIN_H RED_LINE_X*LINES_COUNT+HEADER_HEIGHT+4
  43.  
  44. #define DELETE_BTN 4;
  45. #define DELETE_W sizeof(DELETE_TEXT)+2*6
  46.  
  47. #include "engine.h"
  48.  
  49. dword ed_mouse;
  50. edit_box notebox = {NULL,NULL,NULL,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,
  51.         MAX_LINE_CHARS-1,NULL,#ed_mouse,ed_always_focus+ed_focus};
  52. dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
  53.  
  54. bool delete_active = false;
  55. block delBtn;
  56.  
  57. //===================================================//
  58. //                                                   //
  59. //                       CODE                        //
  60. //                                                   //
  61. //===================================================//
  62.  
  63. void main()
  64. {  
  65.         int btn;
  66.         bool first_redraw=true;
  67.         dword cur_line_offset;
  68.         load_dll(boxlib, #box_lib_init,0);
  69.        
  70.         if (param) notes.OpenTxt(#param); else notes.OpenTxt(abspath("notes.txt"));
  71.         //notes.cur_y = 0;
  72.  
  73.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  74.  
  75.         loop() switch(WaitEvent())
  76.         {
  77.                 case evMouse:
  78.                         edit_box_mouse stdcall (#notebox);
  79.  
  80.                         mouse.get();
  81.  
  82.                         if (delete_active) && (delBtn.hovered()) break;
  83.  
  84.                         if (mouse.lkm) && (mouse.y<TITLE_H) && (mouse.x<WIN_W-39) 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.                         btn = GetButtonID();
  103.                         switch(btn)
  104.                         {
  105.                                 case CLOSE_BTN:
  106.                                         EventExitApp();
  107.                                         break;
  108.                                 case DELETE_BTN:
  109.                                         EventDeleteCurrentNode();
  110.                                         break;
  111.                                 default:
  112.                                         EventCheckBoxClick(btn-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.                                 break;
  126.                         }
  127.                         switch(key_scancode)
  128.                         {
  129.                                 case SCAN_CODE_ESC:
  130.                                         EventExitApp();
  131.                                         break;
  132.                                 case SCAN_CODE_DOWN:
  133.                                         EventActivateLine(notes.cur_y+1);
  134.                                         break;
  135.                                 case SCAN_CODE_UP:
  136.                                         EventActivateLine(notes.cur_y-1);
  137.                                         break;
  138.                                 default:
  139.                                         if (notes.cur_y>=0) {
  140.                                                 EAX = key_editbox;
  141.                                                 edit_box_key stdcall (#notebox);
  142.                                         }
  143.                                
  144.                         }
  145.                         break;
  146.                  
  147.                  case evReDraw:
  148.                         draw_window();
  149.                         if (first_redraw) {
  150.                                 first_redraw = false;
  151.                                 EventActivateLine(0);
  152.                         }
  153.    }
  154. }
  155.  
  156. void DrawCloseButton(dword x,y,w,h)
  157. {
  158.         DrawRectangle(x,y,w,h,0xC96832);
  159.         DrawRectangle3D(x+1,y+1,w-2,h-2,0xE6A37F,0xDD8452);
  160.         PutPixel(x+w-1, y+1, 0xE08C5E);
  161.         DefineButton(x+1,y+1,w-1,h-1,CLOSE_BTN+BT_HIDE,0);
  162.         WriteTextB(-6+w/2+x,h/2-4+y,0x80,0xFFFfff,"x");
  163. }
  164.  
  165. void draw_window()
  166. {
  167.         int i;
  168.         DefineUnDragableWindow(100,100,WIN_W, WIN_H);
  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+RED_LINE_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. void DrawEditBoxN()
  185. {
  186.         notebox.width = notes.w-notes.x-8;
  187.         notebox.left = notes.x+5;
  188.         notebox.offset = notebox.shift = notebox.shift_old = 0;
  189.         notebox.cl_curs_x = notebox.cl_curs_y = 0;
  190.         notebox.size = strlen(notebox.text);
  191.         if (notebox.pos > notebox.size) notebox.pos = notebox.size;
  192.         notebox.top = notes.cur_y*notes.item_h+4+notes.y;
  193.         edit_box_draw stdcall(#notebox);       
  194. }
  195.  
  196. //===================================================//
  197. //                                                   //
  198. //                     EVENTS                        //
  199. //                                                   //
  200. //===================================================//
  201.  
  202. void EventActivateLine(int line_n)
  203. {
  204.         if (line_n<0) || (line_n>notes.count) return;
  205.         notes.cur_y = line_n;
  206.         notebox.text = notes.DrawLine(notes.cur_y, notes.item_h);
  207.         EventListRedraw();
  208.         DrawEditBoxN();
  209. }
  210.  
  211. void EventExitApp()
  212. {
  213.         notes.SaveTxt();
  214.         ExitProcess();
  215. }
  216.  
  217. void EventDrawDeleteButton()
  218. {
  219.         notes.DrawLine(notes.cur_y, notes.item_h);
  220.         delBtn.set_size(WIN_W-DELETE_W-1, notes.cur_y*notes.item_h+notes.y, DELETE_W, notes.item_h-1);
  221.         DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000);
  222.         WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT);
  223.         notebox.top=-20;
  224.         delete_active = true;
  225. }
  226.  
  227. void EventDeleteCurrentNode()
  228. {
  229.         int t = notes.cur_y;
  230.         notes.lines[t].Delete();
  231.         EventListRedraw();
  232. }
  233.  
  234. void EventListRedraw()
  235. {
  236.         delete_active = false;
  237.         DeleteButton(DELETE_BTN);
  238.         notes.DrawList();
  239. }
  240.  
  241. void EventCheckBoxClick(int id)
  242. {
  243.         notes.lines[id].state ^= 1;
  244.         EventListRedraw();
  245. }
  246.  
  247. stop:
  248.