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