Rev 7228 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7228 | Rev 7229 | ||
---|---|---|---|
1 | #define MEMSIZE 1024 * 50 |
1 | #define MEMSIZE 1024 * 50 |
2 | #include "../lib/kolibri.h" |
2 | #include "../lib/kolibri.h" |
3 | #include "../lib/strings.h" |
3 | #include "../lib/strings.h" |
4 | #include "../lib/mem.h" |
4 | #include "../lib/mem.h" |
5 | #include "../lib/gui.h" |
5 | #include "../lib/gui.h" |
6 | 6 | ||
7 | #include "../lib/obj/libimg.h" |
7 | #include "../lib/obj/libimg.h" |
8 | #include "../lib/obj/box_lib.h" |
8 | #include "../lib/obj/box_lib.h" |
9 | - | ||
10 | #include "../lib/patterns/libimg_load_skin.h" |
- | |
11 | 9 | ||
12 | #ifndef AUTOBUILD |
10 | #ifndef AUTOBUILD |
13 | #include "lang.h--" |
11 | #include "lang.h--" |
14 | #endif |
12 | #endif |
15 | 13 | ||
16 | /* === TRANSLATIONS === */ |
14 | /* === TRANSLATIONS === */ |
17 | 15 | ||
18 | #define T_WTITLE "EasyShot v0.7" |
16 | #define T_WTITLE "EasyShot v0.7" |
19 | 17 | ||
20 | #ifdef LANG_RUS |
18 | #ifdef LANG_RUS |
21 | ?define T_TAKE_SCREENSHOT " ¤¥« âì áªà¨è®â" |
19 | ?define T_TAKE_SCREENSHOT " ¤¥« âì áªà¨è®â" |
22 | ?define T_SAVE " ®åà ¨âì" |
20 | ?define T_SAVE " ®åà ¨âì" |
23 | ?define T_PREVIEW "।¯à®á¬®âà" |
21 | ?define T_PREVIEW "।¯à®á¬®âà" |
24 | #else |
22 | #else |
25 | ?define T_TAKE_SCREENSHOT " Take a screenshot" |
23 | ?define T_TAKE_SCREENSHOT " Take a screenshot" |
26 | ?define T_SAVE " Save" |
24 | ?define T_SAVE " Save" |
27 | ?define T_PREVIEW "Preview" |
25 | ?define T_PREVIEW "Preview" |
28 | #endif |
26 | #endif |
29 | 27 | ||
30 | /* === DATA === */ |
28 | /* === DATA === */ |
31 | 29 | ||
32 | proc_info Form; |
30 | proc_info Form; |
33 | 31 | ||
34 | dword screenshot, |
32 | dword screenshot, |
35 | preview; |
33 | preview; |
36 | 34 | ||
37 | int screenshot_length, |
35 | int screenshot_length, |
38 | preview_length; |
36 | preview_length; |
39 | 37 | ||
40 | enum { |
38 | enum { |
41 | BTN_MAKE_SCREENSHOT=10, |
39 | BTN_MAKE_SCREENSHOT=10, |
42 | BTN_SAVE, |
40 | BTN_SAVE, |
43 | BTN_SETTINGS |
41 | BTN_SETTINGS |
44 | }; |
42 | }; |
45 | 43 | ||
46 | #define PD 18 //padding |
44 | #define PD 18 //padding |
47 | #define TOOLBAR_H 20+PD |
45 | #define TOOLBAR_H 20+PD |
48 | 46 | ||
49 | block pw; |
47 | block pw; |
50 | 48 | ||
51 | struct _settings { |
49 | struct _settings { |
52 | bool minimise; |
50 | bool minimise; |
53 | int delay; |
51 | int delay; |
54 | char save_path[4096]; |
52 | char save_path[4096]; |
55 | } settings = { true, 1, "/tmp0/1" }; |
53 | } settings = { true, 1, "/tmp0/1" }; |
56 | 54 | ||
57 | /* === CODE === */ |
55 | /* === CODE === */ |
58 | 56 | ||
59 | void main() |
57 | void main() |
60 | { |
58 | { |
61 | char id; |
59 | char id; |
62 | 60 | ||
63 | load_dll(libio, #libio_init, 1); |
61 | load_dll(libio, #libio_init, 1); |
64 | load_dll(libimg, #libimg_init, 1); |
62 | load_dll(libimg, #libimg_init, 1); |
65 | load_dll(boxlib, #box_lib_init,0); |
63 | load_dll(boxlib, #box_lib_init,0); |
66 | 64 | ||
67 | Libimg_LoadImage(#skin, "/sys/icons16.png"); |
65 | Libimg_LoadImage(#skin, "/sys/icons16.png"); |
68 | 66 | ||
69 | screenshot_length = screen.width * screen.height * 3; |
67 | screenshot_length = screen.width * screen.height * 3; |
70 | pw.set_size(PD, TOOLBAR_H+PD, screen.width/2, screen.height/2); |
68 | pw.set_size(PD, TOOLBAR_H+PD, screen.width/2, screen.height/2); |
71 | preview_length = screenshot_length / 2; |
69 | preview_length = screenshot_length / 2; |
72 | 70 | ||
73 | screenshot = malloc(screenshot_length); |
71 | screenshot = malloc(screenshot_length); |
74 | preview = malloc(screenshot_length/2); |
72 | preview = malloc(screenshot_length/2); |
75 | 73 | ||
76 | loop() switch(WaitEvent()) |
74 | loop() switch(WaitEvent()) |
77 | { |
75 | { |
78 | case evButton: |
76 | case evButton: |
79 | id = GetButtonID(); |
77 | id = GetButtonID(); |
80 | if (id == CLOSE_BTN) ExitProcess(); |
78 | if (id == CLOSE_BTN) ExitProcess(); |
81 | if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot(); |
79 | if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot(); |
82 | if (id == BTN_SAVE) EventSaveImageFile(); |
80 | if (id == BTN_SAVE) EventSaveImageFile(); |
83 | if (id == BTN_SETTINGS) EventShowSettings(); |
81 | if (id == BTN_SETTINGS) EventShowSettings(); |
84 | break; |
82 | break; |
85 | 83 | ||
86 | case evKey: |
84 | case evKey: |
87 | GetKeys(); |
85 | GetKeys(); |
88 | if (SCAN_CODE_KEY_S == key_scancode) EventSaveImageFile(); |
86 | if (SCAN_CODE_KEY_S == key_scancode) EventSaveImageFile(); |
89 | if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot(); |
87 | if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot(); |
90 | break; |
88 | break; |
91 | 89 | ||
92 | case evReDraw: |
90 | case evReDraw: |
93 | DefineAndDrawWindow(screen.width/4, screen.height/4, pw.w + 9 +PD+PD, |
91 | DefineAndDrawWindow(screen.width/4, screen.height/4, pw.w + 9 +PD+PD, |
94 | pw.h + skin_height + TOOLBAR_H + 4 +PD+PD, 0x74, 0, T_WTITLE,0); |
92 | pw.h + skin_height + TOOLBAR_H + 4 +PD+PD, 0x74, 0, T_WTITLE,0); |
95 | GetProcessInfo(#Form, SelfInfo); |
93 | GetProcessInfo(#Form, SelfInfo); |
96 | if (Form.status_window>2) break; |
94 | if (Form.status_window>2) break; |
97 | system.color.get(); |
95 | system.color.get(); |
98 | DrawMainContent(); |
96 | DrawMainContent(); |
99 | } |
97 | } |
100 | } |
98 | } |
101 | 99 | ||
102 | void DrawMainContent() |
100 | void DrawMainContent() |
103 | { |
101 | { |
104 | int take_scr_btn_width; |
102 | int take_scr_btn_width; |
105 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H, system.color.work); |
103 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H, system.color.work); |
106 | DrawWideRectangle(0, TOOLBAR_H, pw.w+PD+PD, pw.h+PD+PD, PD-1, system.color.work); |
104 | DrawWideRectangle(0, TOOLBAR_H, pw.w+PD+PD, pw.h+PD+PD, PD-1, system.color.work); |
107 | DrawRectangle(pw.x-1, pw.y-1, pw.w+1, pw.h+1, system.color.work_graph); |
105 | DrawRectangle(pw.x-1, pw.y-1, pw.w+1, pw.h+1, system.color.work_graph); |
108 | take_scr_btn_width = DrawIconButton(pw.x, pw.y-42, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44); |
106 | take_scr_btn_width = DrawIconButton(pw.x, pw.y-42, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44); |
109 | if (ESDWORD[preview]==0) { |
107 | if (ESDWORD[preview]==0) { |
110 | DrawBar(pw.x, pw.y, pw.w, pw.h, 0xEEEeee); |
108 | DrawBar(pw.x, pw.y, pw.w, pw.h, 0xEEEeee); |
111 | WriteText(Form.cwidth-calc(strlen(T_PREVIEW)*8)/2, pw.h/2+pw.y, 0x90, 0x777777, T_PREVIEW); |
109 | WriteText(Form.cwidth-calc(strlen(T_PREVIEW)*8)/2, pw.h/2+pw.y, 0x90, 0x777777, T_PREVIEW); |
112 | } |
110 | } |
113 | else { |
111 | else { |
114 | _PutImage(pw.x, pw.y, pw.w, pw.h, preview); |
112 | _PutImage(pw.x, pw.y, pw.w, pw.h, preview); |
115 | DrawIconButton(take_scr_btn_width + pw.x, pw.y-42, BTN_SAVE, T_SAVE, 5); |
113 | DrawIconButton(take_scr_btn_width + pw.x, pw.y-42, BTN_SAVE, T_SAVE, 5); |
116 | } |
114 | } |
117 | DrawIconButton(Form.cwidth-40-PD, pw.y-42, BTN_SETTINGS, " ", 10); |
115 | DrawIconButton(Form.cwidth-40-PD, pw.y-42, BTN_SETTINGS, " ", 10); |
118 | } |
116 | } |
119 | 117 | ||
120 | void EventTakeScreenshot() { |
118 | void EventTakeScreenshot() { |
121 | if (settings.minimise) MinimizeWindow(); |
119 | if (settings.minimise) MinimizeWindow(); |
122 | pause(settings.delay*100); |
120 | pause(settings.delay*100); |
123 | CopyScreen(screenshot, 0, 0, screen.width, screen.height); |
121 | CopyScreen(screenshot, 0, 0, screen.width, screen.height); |
124 | ZoomImageTo50percent(); |
122 | ZoomImageTo50percent(); |
125 | ActivateWindow(GetProcessSlot(Form.ID)); |
123 | ActivateWindow(GetProcessSlot(Form.ID)); |
126 | if (!settings.minimise) DrawMainContent(); |
124 | if (!settings.minimise) DrawMainContent(); |
127 | } |
125 | } |
128 | 126 | ||
129 | void EventSaveImageFile() |
127 | void EventSaveImageFile() |
130 | { |
128 | { |
131 | int i=0; |
129 | int i=0; |
132 | char save_file_name[4096]; |
130 | char save_file_name[4096]; |
133 | do { |
131 | do { |
134 | i++; |
132 | i++; |
135 | sprintf(#save_file_name, "%s/screen_%i.png", #settings.save_path, i); |
133 | sprintf(#save_file_name, "%s/screen_%i.png", #settings.save_path, i); |
136 | } while (file_exists(#save_file_name)); |
134 | } while (file_exists(#save_file_name)); |
137 | save_image(screenshot, screen.width, screen.height, #save_file_name); |
135 | save_image(screenshot, screen.width, screen.height, #save_file_name); |
138 | } |
136 | } |
139 | 137 | ||
140 | void EventShowSettings() |
138 | void EventShowSettings() |
141 | { |
139 | { |
142 | CreateThread(#SettingsWindow,#settings_stak+4092); |
140 | CreateThread(#SettingsWindow,#settings_stak+4092); |
143 | } |
141 | } |
144 | 142 | ||
145 | char path_tmp[4096]; |
143 | char path_tmp[4096]; |
146 | dword mouse_dd1; |
144 | dword mouse_dd1; |
147 | edit_box edit_box_path = {270,10,70,0xffffff,0x94AECE,0xFFFfff,0xffffff,0x10000000,sizeof(path_tmp),#path_tmp,#mouse_dd1, 0b}; |
145 | edit_box edit_box_path = {270,10,70,0xffffff,0x94AECE,0xFFFfff,0xffffff,0x10000000,sizeof(path_tmp),#path_tmp,#mouse_dd1, 0b}; |
148 | 146 | ||
149 | void SettingsWindow() |
147 | void SettingsWindow() |
150 | { |
148 | { |
151 | #define x 15 |
149 | #define x 15 |
152 | int id; |
150 | int id; |
153 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
151 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
154 | loop() switch(WaitEvent()) |
152 | loop() switch(WaitEvent()) |
155 | { |
153 | { |
156 | case evMouse: |
154 | case evMouse: |
157 | //edit_box_mouse stdcall (#address_box); |
155 | //edit_box_mouse stdcall (#address_box); |
158 | break; |
156 | break; |
159 | 157 | ||
160 | case evKey: |
158 | case evKey: |
161 | GetKeys(); |
159 | GetKeys(); |
162 | if (SCAN_CODE_ESC == key_scancode) ExitProcess(); |
160 | if (SCAN_CODE_ESC == key_scancode) ExitProcess(); |
163 | break; |
161 | break; |
164 | 162 | ||
165 | case evButton: |
163 | case evButton: |
166 | id = GetButtonID(); |
164 | id = GetButtonID(); |
167 | if (CLOSE_BTN == id) ExitProcess(); |
165 | if (CLOSE_BTN == id) ExitProcess(); |
168 | if (10 == id) settings.delay++; |
166 | if (10 == id) settings.delay++; |
169 | if (11 == id) && (settings.delay>0) settings.delay--; |
167 | if (11 == id) && (settings.delay>0) settings.delay--; |
170 | if (12 == id) settings.minimise ^= 1; |
168 | if (12 == id) settings.minimise ^= 1; |
171 | goto _DRAW_CONTENT; |
169 | goto _DRAW_CONTENT; |
172 | break; |
170 | break; |
173 | 171 | ||
174 | case evReDraw: |
172 | case evReDraw: |
175 | DefineAndDrawWindow(Form.left+100, Form.top-40, 330, 170, 0x34, system.color.work, "Settings",0); |
173 | DefineAndDrawWindow(Form.left+100, Form.top-40, 330, 170, 0x34, system.color.work, "Settings",0); |
176 | _DRAW_CONTENT: |
174 | _DRAW_CONTENT: |
177 | CheckBox(x, 10, 12, "Minimize window", settings.minimise); |
175 | CheckBox(x, 10, 12, "Minimize window", settings.minimise); |
178 | MoreLessBox(x, 40, 10, 11, settings.delay, "Delay in seconds"); |
176 | MoreLessBox(x, 40, 10, 11, settings.delay, "Delay in seconds"); |
179 | //DrawEditBox(#edit_box_path); |
177 | //DrawEditBox(#edit_box_path); |
180 | } |
178 | } |
181 | } |
179 | } |
182 | 180 | ||
183 | inline byte calc_rgb(dword B, item_h) |
181 | inline byte calc_rgb(dword B, item_h) |
184 | { |
182 | { |
185 | return calc(ESBYTE[B+3] + ESBYTE[B] + ESBYTE[B-3] |
183 | return calc(ESBYTE[B+3] + ESBYTE[B] + ESBYTE[B-3] |
186 | + ESBYTE[B-item_h] + ESBYTE[B+item_h] / 5); |
184 | + ESBYTE[B-item_h] + ESBYTE[B+item_h] / 5); |
187 | } |
185 | } |
188 | 186 | ||
189 | void ZoomImageTo50percent() { |
187 | void ZoomImageTo50percent() { |
190 | dword point_x = 0; |
188 | dword point_x = 0; |
191 | dword item_h = screen.width * 3; |
189 | dword item_h = screen.width * 3; |
192 | dword small = preview; |
190 | dword small = preview; |
193 | dword big = screenshot; |
191 | dword big = screenshot; |
194 | 192 | ||
195 | while( (small <= preview + preview_length) && (big <= screenshot + screenshot_length ) ) { |
193 | while( (small <= preview + preview_length) && (big <= screenshot + screenshot_length ) ) { |
196 | 194 | ||
197 | if (big <= screenshot + item_h) || (big >= screenshot + screenshot_length - item_h) |
195 | if (big <= screenshot + item_h) || (big >= screenshot + screenshot_length - item_h) |
198 | { |
196 | { |
199 | ESBYTE[small] = ESBYTE[big]; |
197 | ESBYTE[small] = ESBYTE[big]; |
200 | ESBYTE[small+1] = ESBYTE[big+1]; |
198 | ESBYTE[small+1] = ESBYTE[big+1]; |
201 | ESBYTE[small+2] = ESBYTE[big+2]; |
199 | ESBYTE[small+2] = ESBYTE[big+2]; |
202 | } |
200 | } |
203 | else |
201 | else |
204 | { |
202 | { |
205 | ESBYTE[small] = calc_rgb(big, item_h); |
203 | ESBYTE[small] = calc_rgb(big, item_h); |
206 | ESBYTE[small+1] = calc_rgb(big+1, item_h); |
204 | ESBYTE[small+1] = calc_rgb(big+1, item_h); |
207 | ESBYTE[small+2] = calc_rgb(big+2, item_h); |
205 | ESBYTE[small+2] = calc_rgb(big+2, item_h); |
208 | } |
206 | } |
209 | 207 | ||
210 | small+=3; |
208 | small+=3; |
211 | big+=6; |
209 | big+=6; |
212 | 210 | ||
213 | point_x+=2; |
211 | point_x+=2; |
214 | if (point_x >= screen.width) |
212 | if (point_x >= screen.width) |
215 | { |
213 | { |
216 | big += item_h; |
214 | big += item_h; |
217 | point_x = 0; |
215 | point_x = 0; |
218 | } |
216 | } |
219 | } |
217 | } |
220 | } |
218 | } |
221 | 219 | ||
222 | int DrawIconButton(dword x, y, id, text, icon) |
220 | int DrawIconButton(dword x, y, id, text, icon) |
223 | { |
221 | { |
224 | int btwidth; |
222 | int btwidth; |
225 | system.color.work_button = 0xFFFfff; |
223 | system.color.work_button = 0xFFFfff; |
226 | system.color.work_button_text = 0; |
224 | system.color.work_button_text = 0; |
227 | btwidth = DrawStandartCaptButton(x, y, id, text); |
225 | btwidth = DrawStandartCaptButton(x, y, id, text); |
228 | img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16); |
226 | img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16); |
229 | system.color.get(); |
227 | system.color.get(); |
230 | return btwidth; |
228 | return btwidth; |
231 | } |
229 | } |
232 | 230 | ||
233 | stop: |
231 | stop: |
234 | 232 | ||
235 | char settings_stak[4096];=>=>=> |
233 | char settings_stak[4096];=>=>=> |