Subversion Repositories Kolibri OS

Rev

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

  1. // Notes v0.8 ALPHA
  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 "edge.raw")]= FROM "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 = {0,999,0,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.         dword cur_line_offset;
  67.         load_dll(boxlib, #box_lib_init,0);
  68.        
  69.         if (param) notes.OpenTxt(#param); else notes.OpenTxt(abspath("notes.txt"));
  70.         notes.cur_y = -1;
  71.  
  72.         SetEventMask(0x27);
  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) 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.                                 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.                                         notes.lines[btn-CHECKBOX_ID].state ^= 1;
  111.                                         EventListRedraw();
  112.                                         break;
  113.                         }  
  114.                         break;
  115.          
  116.                 case evKey:
  117.                         GetKeys();
  118.                         switch(key_scancode)
  119.                         {
  120.                                 case SCAN_CODE_ESC:
  121.                                         EventExitApp();
  122.                                         break;
  123.                                 case SCAN_CODE_DOWN:
  124.                                         EventActivateLine(notes.cur_y+1);
  125.                                         break;
  126.                                 case SCAN_CODE_UP:
  127.                                         EventActivateLine(notes.cur_y-1);
  128.                                         break;
  129.                                 default:
  130.                                         if (notes.cur_y>=0) {
  131.                                                 EAX = key_editbox;
  132.                                                 edit_box_key stdcall (#notebox);
  133.                                         }
  134.                                
  135.                         }
  136.                         break;
  137.                  
  138.                  case evReDraw:
  139.                         draw_window();
  140.    }
  141. }
  142.  
  143. void DrawCloseButton(dword x,y,w,h)
  144. {
  145.         DrawRectangle(x,y,w,h,0xC96832);
  146.         DrawRectangle3D(x+1,y+1,w-2,h-2,0xE6A37F,0xDD8452);
  147.         PutPixel(x+w-1, y+1, 0xE08C5E);
  148.         DefineButton(x+1,y+1,w-1,h-1,CLOSE_BTN+BT_HIDE,0);
  149.         WriteTextB(-6+w/2+x,h/2-4+y,0x80,0xFFFfff,"x");
  150. }
  151.  
  152. void draw_window()
  153. {
  154.         int i;
  155.         DefineUnDragableWindow(100,100,WIN_W, WIN_H);
  156.         notes.SetSizes(RED_LINE_X+1, HEADER_HEIGHT, WIN_W-1, RED_LINE_X*LINES_COUNT, RED_LINE_X);
  157.         DrawRectangle3D(0,0,WIN_W,TITLE_H-1,0xBB6535, 0xCD6F3B);
  158.         DrawRectangle3D(1,1,WIN_W-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
  159.         DrawBar(2,2,WIN_W-3,TITLE_H-4,0xE08C5E);
  160.         WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
  161.         WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
  162.         _PutImage(1, TITLE_H, 292,EDGE_H, #edge);
  163.         PutPixel(notes.x+RED_LINE_X, notes.y-1, COL_RED_LINE);
  164.         ECX-=1; $int 0x40;
  165.         DrawCloseButton(WIN_W-23,4,16,16);
  166.         DrawRectangle(0,TITLE_H,WIN_W,WIN_H-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
  167.         for (i=0; lists[i]!=0; i++) DrawBar(1,WIN_H-i-1, WIN_W-1, 1, lists[i]);
  168.         EventListRedraw();
  169. }
  170.  
  171. void DrawEditBoxN()
  172. {
  173.         notebox.width = notes.w-notes.x-8;
  174.         notebox.left = notes.x+5;
  175.         notebox.pos = notebox.offset = notebox.shift = notebox.shift_old = 0;
  176.         notebox.cl_curs_x = notebox.cl_curs_y = 0;
  177.         notebox.size = strlen(notebox.text);
  178.         notebox.top = notes.cur_y*notes.item_h+4+notes.y;
  179.         edit_box_draw stdcall(#notebox);       
  180. }
  181.  
  182. //===================================================//
  183. //                                                   //
  184. //                     EVENTS                        //
  185. //                                                   //
  186. //===================================================//
  187.  
  188. void EventActivateLine(int line_n)
  189. {
  190.         if (line_n<0) || (line_n>notes.count) return;
  191.         notes.cur_y = line_n;
  192.         notebox.text = notes.DrawLine(notes.cur_y, notes.item_h);
  193.         EventListRedraw();
  194.         DrawEditBoxN();
  195. }
  196.  
  197. void EventExitApp()
  198. {
  199.         notes.SaveTxt();
  200.         ExitProcess();
  201. }
  202.  
  203. void EventDrawDeleteButton()
  204. {
  205.         notes.DrawLine(notes.cur_y, notes.item_h);
  206.         delBtn.set_size(WIN_W-DELETE_W-1, notes.cur_y*notes.item_h+notes.y, DELETE_W, notes.item_h-1);
  207.         DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000);
  208.         WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT);
  209.         notebox.top=-20;
  210.         delete_active = true;
  211. }
  212.  
  213. void EventDeleteCurrentNode()
  214. {
  215.         notes.lines[notes.cur_y].Delete();
  216.         EventListRedraw();
  217. }
  218.  
  219. void EventListRedraw()
  220. {
  221.         delete_active = false;
  222.         DeleteButton(DELETE_BTN);
  223.         notes.DrawList();
  224. }
  225.  
  226. stop:
  227.