Rev 7730 | Rev 8955 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7444 | leency | 1 | // Notes v1.1 |
7331 | leency | 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 "Заметки" |
||
7422 | leency | 22 | ?define DELETE_TEXT "Удалить"; |
7331 | leency | 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 |
||
7434 | leency | 30 | unsigned char edge[sizeof(file "img/edge.raw")]= FROM "img/edge.raw"; //292x6 |
7331 | leency | 31 | #define EDGE_H 6 |
32 | #define TITLE_H 24 |
||
33 | #define HEADER_HEIGHT TITLE_H+EDGE_H |
||
7422 | leency | 34 | #define LINES_COUNT 13 |
7331 | leency | 35 | |
7422 | leency | 36 | #define WIN_W 270 |
37 | #define WIN_H RED_LINE_X*LINES_COUNT+HEADER_HEIGHT+4 |
||
38 | |||
7331 | leency | 39 | #define DELETE_BTN 4; |
7422 | leency | 40 | #define DELETE_W sizeof(DELETE_TEXT)+2*6 |
7331 | leency | 41 | |
7532 | leency | 42 | proc_info Form; |
43 | |||
7331 | leency | 44 | #include "engine.h" |
7532 | leency | 45 | #include "ini.h" |
7331 | leency | 46 | |
7434 | leency | 47 | edit_box notebox = {NULL,NULL,NULL,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0, |
7984 | leency | 48 | MAX_LINE_CHARS-1,NULL,0,ed_always_focus+ed_focus}; |
7331 | leency | 49 | dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 }; |
50 | |||
7422 | leency | 51 | bool delete_active = false; |
7444 | leency | 52 | bool window_dragable = true; |
7422 | leency | 53 | block delBtn; |
54 | |||
7331 | leency | 55 | //===================================================// |
56 | // // |
||
57 | // CODE // |
||
58 | // // |
||
59 | //===================================================// |
||
60 | |||
61 | void main() |
||
62 | { |
||
7434 | leency | 63 | bool first_redraw=true; |
7331 | leency | 64 | dword cur_line_offset; |
65 | load_dll(boxlib, #box_lib_init,0); |
||
7444 | leency | 66 | |
67 | if (GetCpuFrequency()/1000000>=1000) window_dragable=true; else window_dragable=false; |
||
7331 | leency | 68 | |
7640 | leency | 69 | if (param) notes.OpenTxt(#param); else notes.OpenTxt("/sys/notes.txt"); |
7331 | leency | 70 | |
7984 | leency | 71 | @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
7532 | leency | 72 | LoadIniSettings(); |
7331 | leency | 73 | |
7984 | leency | 74 | loop() switch(@WaitEvent()) |
7331 | leency | 75 | { |
76 | case evMouse: |
||
7422 | leency | 77 | edit_box_mouse stdcall (#notebox); |
78 | |||
7331 | leency | 79 | mouse.get(); |
80 | |||
7422 | leency | 81 | if (delete_active) && (delBtn.hovered()) break; |
82 | |||
7444 | leency | 83 | if (mouse.lkm) && (mouse.y |
84 | && (window_dragable) EventDragWindow(); |
||
7422 | leency | 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)) { |
||
7434 | leency | 94 | notebox.pos = mouse.x - notebox.left / 6; |
7422 | leency | 95 | EventListRedraw(); |
96 | EventActivateLine(notes.cur_y); |
||
7331 | leency | 97 | } |
98 | |||
99 | break; |
||
100 | |||
101 | case evButton: |
||
7984 | leency | 102 | @GetButtonID(); |
103 | switch(EAX) |
||
7331 | leency | 104 | { |
7422 | leency | 105 | case CLOSE_BTN: |
106 | EventExitApp(); |
||
107 | break; |
||
108 | case DELETE_BTN: |
||
109 | EventDeleteCurrentNode(); |
||
110 | break; |
||
111 | default: |
||
7984 | leency | 112 | EventCheckBoxClick(EAX-CHECKBOX_ID); |
7422 | leency | 113 | break; |
114 | } |
||
7331 | leency | 115 | break; |
116 | |||
117 | case evKey: |
||
118 | GetKeys(); |
||
7434 | leency | 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 | } |
||
7422 | leency | 126 | switch(key_scancode) |
127 | { |
||
128 | case SCAN_CODE_ESC: |
||
129 | EventExitApp(); |
||
130 | break; |
||
131 | case SCAN_CODE_DOWN: |
||
132 | EventActivateLine(notes.cur_y+1); |
||
133 | break; |
||
134 | case SCAN_CODE_UP: |
||
135 | EventActivateLine(notes.cur_y-1); |
||
136 | break; |
||
137 | default: |
||
138 | if (notes.cur_y>=0) { |
||
139 | EAX = key_editbox; |
||
140 | edit_box_key stdcall (#notebox); |
||
141 | } |
||
142 | |||
143 | } |
||
7331 | leency | 144 | break; |
145 | |||
146 | case evReDraw: |
||
147 | draw_window(); |
||
7434 | leency | 148 | if (first_redraw) { |
149 | first_redraw = false; |
||
150 | EventActivateLine(0); |
||
151 | } |
||
7331 | leency | 152 | } |
153 | } |
||
154 | |||
155 | void DrawCloseButton(dword x,y,w,h) |
||
156 | { |
||
157 | DrawRectangle(x,y,w,h,0xC96832); |
||
158 | DrawRectangle3D(x+1,y+1,w-2,h-2,0xE6A37F,0xDD8452); |
||
159 | PutPixel(x+w-1, y+1, 0xE08C5E); |
||
160 | DefineButton(x+1,y+1,w-1,h-1,CLOSE_BTN+BT_HIDE,0); |
||
161 | WriteTextB(-6+w/2+x,h/2-4+y,0x80,0xFFFfff,"x"); |
||
162 | } |
||
163 | |||
164 | void draw_window() |
||
165 | { |
||
166 | int i; |
||
7444 | leency | 167 | if (window_dragable) |
7532 | leency | 168 | DefineUnDragableWindow(Form.left,Form.top,WIN_W, WIN_H); |
7444 | leency | 169 | else |
7532 | leency | 170 | DefineDragableWindow(Form.left,Form.top,WIN_W, WIN_H); |
171 | GetProcessInfo(#Form, SelfInfo); |
||
7422 | leency | 172 | notes.SetSizes(RED_LINE_X+1, HEADER_HEIGHT, WIN_W-1, RED_LINE_X*LINES_COUNT, RED_LINE_X); |
173 | DrawRectangle3D(0,0,WIN_W,TITLE_H-1,0xBB6535, 0xCD6F3B); |
||
174 | DrawRectangle3D(1,1,WIN_W-2,TITLE_H-3,0xEFBFA4, 0xDD8452); |
||
175 | DrawBar(2,2,WIN_W-3,TITLE_H-4,0xE08C5E); |
||
7331 | leency | 176 | WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION); |
177 | WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION); |
||
178 | _PutImage(1, TITLE_H, 292,EDGE_H, #edge); |
||
7437 | leency | 179 | PutPixel(notes.x, notes.y-1, COL_RED_LINE); |
7331 | leency | 180 | ECX-=1; $int 0x40; |
7422 | leency | 181 | DrawCloseButton(WIN_W-23,4,16,16); |
182 | DrawRectangle(0,TITLE_H,WIN_W,WIN_H-HEADER_HEIGHT+EDGE_H,0xBBBBBB); |
||
183 | for (i=0; lists[i]!=0; i++) DrawBar(1,WIN_H-i-1, WIN_W-1, 1, lists[i]); |
||
184 | EventListRedraw(); |
||
7331 | leency | 185 | } |
186 | |||
7422 | leency | 187 | void DrawEditBoxN() |
7331 | leency | 188 | { |
7422 | leency | 189 | notebox.width = notes.w-notes.x-8; |
190 | notebox.left = notes.x+5; |
||
7434 | leency | 191 | notebox.offset = notebox.shift = notebox.shift_old = 0; |
7422 | leency | 192 | notebox.cl_curs_x = notebox.cl_curs_y = 0; |
193 | notebox.size = strlen(notebox.text); |
||
7437 | leency | 194 | notebox.flags = ed_always_focus+ed_focus; |
7434 | leency | 195 | if (notebox.pos > notebox.size) notebox.pos = notebox.size; |
7422 | leency | 196 | notebox.top = notes.cur_y*notes.item_h+4+notes.y; |
197 | edit_box_draw stdcall(#notebox); |
||
7331 | leency | 198 | } |
199 | |||
200 | //===================================================// |
||
201 | // // |
||
202 | // EVENTS // |
||
203 | // // |
||
204 | //===================================================// |
||
205 | |||
206 | void EventActivateLine(int line_n) |
||
207 | { |
||
7444 | leency | 208 | if (line_n<0) || (line_n>=notes.count) return; |
7422 | leency | 209 | notes.cur_y = line_n; |
210 | notebox.text = notes.DrawLine(notes.cur_y, notes.item_h); |
||
211 | EventListRedraw(); |
||
212 | DrawEditBoxN(); |
||
7331 | leency | 213 | } |
214 | |||
215 | void EventExitApp() |
||
216 | { |
||
217 | notes.SaveTxt(); |
||
7532 | leency | 218 | SaveIniSettings(); |
7331 | leency | 219 | ExitProcess(); |
220 | } |
||
221 | |||
222 | void EventDrawDeleteButton() |
||
223 | { |
||
7422 | leency | 224 | notes.DrawLine(notes.cur_y, notes.item_h); |
225 | delBtn.set_size(WIN_W-DELETE_W-1, notes.cur_y*notes.item_h+notes.y, DELETE_W, notes.item_h-1); |
||
226 | DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000); |
||
227 | WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT); |
||
228 | notebox.top=-20; |
||
229 | delete_active = true; |
||
7331 | leency | 230 | } |
231 | |||
7422 | leency | 232 | void EventDeleteCurrentNode() |
7331 | leency | 233 | { |
7629 | leency | 234 | dword t; |
235 | t = notes.cur_y; |
||
7434 | leency | 236 | notes.lines[t].Delete(); |
7422 | leency | 237 | EventListRedraw(); |
7331 | leency | 238 | } |
239 | |||
7422 | leency | 240 | void EventListRedraw() |
241 | { |
||
242 | delete_active = false; |
||
243 | DeleteButton(DELETE_BTN); |
||
244 | notes.DrawList(); |
||
245 | } |
||
246 | |||
7434 | leency | 247 | void EventCheckBoxClick(int id) |
248 | { |
||
249 | notes.lines[id].state ^= 1; |
||
250 | EventListRedraw(); |
||
251 | } |
||
252 | |||
7331 | leency | 253 | stop:0)> |