Rev 7422 | Rev 7437 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7434 | leency | 1 | // Notes v0.9 Beta |
7331 | leency | 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 "Заметки" |
||
7422 | leency | 27 | ?define DELETE_TEXT "Удалить"; |
7331 | leency | 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 |
||
7434 | leency | 35 | unsigned char edge[sizeof(file "img/edge.raw")]= FROM "img/edge.raw"; //292x6 |
7331 | leency | 36 | #define EDGE_H 6 |
37 | #define TITLE_H 24 |
||
38 | #define HEADER_HEIGHT TITLE_H+EDGE_H |
||
7422 | leency | 39 | #define LINES_COUNT 13 |
7331 | leency | 40 | |
7422 | leency | 41 | #define WIN_W 270 |
42 | #define WIN_H RED_LINE_X*LINES_COUNT+HEADER_HEIGHT+4 |
||
43 | |||
7331 | leency | 44 | #define DELETE_BTN 4; |
7422 | leency | 45 | #define DELETE_W sizeof(DELETE_TEXT)+2*6 |
7331 | leency | 46 | |
47 | #include "engine.h" |
||
48 | |||
7422 | leency | 49 | dword ed_mouse; |
7434 | leency | 50 | edit_box notebox = {NULL,NULL,NULL,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0, |
7422 | leency | 51 | MAX_LINE_CHARS-1,NULL,#ed_mouse,ed_always_focus+ed_focus}; |
7331 | leency | 52 | dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 }; |
53 | |||
7422 | leency | 54 | bool delete_active = false; |
55 | block delBtn; |
||
56 | |||
7331 | leency | 57 | //===================================================// |
58 | // // |
||
59 | // CODE // |
||
60 | // // |
||
61 | //===================================================// |
||
62 | |||
63 | void main() |
||
64 | { |
||
65 | int btn; |
||
7434 | leency | 66 | bool first_redraw=true; |
7331 | leency | 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")); |
||
7434 | leency | 71 | //notes.cur_y = 0; |
7331 | leency | 72 | |
7434 | leency | 73 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
7331 | leency | 74 | |
75 | loop() switch(WaitEvent()) |
||
76 | { |
||
77 | case evMouse: |
||
7422 | leency | 78 | edit_box_mouse stdcall (#notebox); |
79 | |||
7331 | leency | 80 | mouse.get(); |
81 | |||
7422 | leency | 82 | if (delete_active) && (delBtn.hovered()) break; |
83 | |||
84 | if (mouse.lkm) && (mouse.y |
||
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: |
||
7422 | leency | 102 | btn = GetButtonID(); |
103 | switch(btn) |
||
7331 | leency | 104 | { |
7422 | leency | 105 | case CLOSE_BTN: |
106 | EventExitApp(); |
||
107 | break; |
||
108 | case DELETE_BTN: |
||
109 | EventDeleteCurrentNode(); |
||
110 | break; |
||
111 | default: |
||
7434 | leency | 112 | EventCheckBoxClick(btn-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 | break; |
||
126 | } |
||
7422 | leency | 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 | } |
||
7331 | leency | 145 | break; |
146 | |||
147 | case evReDraw: |
||
148 | draw_window(); |
||
7434 | leency | 149 | if (first_redraw) { |
150 | first_redraw = false; |
||
151 | EventActivateLine(0); |
||
152 | } |
||
7331 | leency | 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; |
||
7422 | leency | 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); |
||
7331 | leency | 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); |
||
7422 | leency | 176 | PutPixel(notes.x+RED_LINE_X, notes.y-1, COL_RED_LINE); |
7331 | leency | 177 | ECX-=1; $int 0x40; |
7422 | leency | 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(); |
||
7331 | leency | 182 | } |
183 | |||
7422 | leency | 184 | void DrawEditBoxN() |
7331 | leency | 185 | { |
7422 | leency | 186 | notebox.width = notes.w-notes.x-8; |
187 | notebox.left = notes.x+5; |
||
7434 | leency | 188 | notebox.offset = notebox.shift = notebox.shift_old = 0; |
7422 | leency | 189 | notebox.cl_curs_x = notebox.cl_curs_y = 0; |
190 | notebox.size = strlen(notebox.text); |
||
7434 | leency | 191 | if (notebox.pos > notebox.size) notebox.pos = notebox.size; |
7422 | leency | 192 | notebox.top = notes.cur_y*notes.item_h+4+notes.y; |
193 | edit_box_draw stdcall(#notebox); |
||
7331 | leency | 194 | } |
195 | |||
196 | //===================================================// |
||
197 | // // |
||
198 | // EVENTS // |
||
199 | // // |
||
200 | //===================================================// |
||
201 | |||
202 | void EventActivateLine(int line_n) |
||
203 | { |
||
7422 | leency | 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(); |
||
7331 | leency | 209 | } |
210 | |||
211 | void EventExitApp() |
||
212 | { |
||
213 | notes.SaveTxt(); |
||
214 | ExitProcess(); |
||
215 | } |
||
216 | |||
217 | void EventDrawDeleteButton() |
||
218 | { |
||
7422 | leency | 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; |
||
7331 | leency | 225 | } |
226 | |||
7422 | leency | 227 | void EventDeleteCurrentNode() |
7331 | leency | 228 | { |
7434 | leency | 229 | int t = notes.cur_y; |
230 | notes.lines[t].Delete(); |
||
7422 | leency | 231 | EventListRedraw(); |
7331 | leency | 232 | } |
233 | |||
7422 | leency | 234 | void EventListRedraw() |
235 | { |
||
236 | delete_active = false; |
||
237 | DeleteButton(DELETE_BTN); |
||
238 | notes.DrawList(); |
||
239 | } |
||
240 | |||
7434 | leency | 241 | void EventCheckBoxClick(int id) |
242 | { |
||
243 | notes.lines[id].state ^= 1; |
||
244 | EventListRedraw(); |
||
245 | } |
||
246 | |||
7331 | leency | 247 | stop:0)> |