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