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