Rev 7221 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7221 | Rev 7224 | ||
---|---|---|---|
Line 1... | Line -... | ||
1 | // TODO |
- | |
2 | // Settings: delay, savepath |
- | |
3 | // Icons and better UI |
- | |
4 | - | ||
5 | #define MEMSIZE 1024 * 20 |
1 | #define MEMSIZE 1024 * 50 |
6 | #include "../lib/kolibri.h" |
2 | #include "../lib/kolibri.h" |
7 | #include "../lib/strings.h" |
3 | #include "../lib/strings.h" |
8 | #include "../lib/mem.h" |
4 | #include "../lib/mem.h" |
9 | #include "../lib/gui.h" |
5 | #include "../lib/gui.h" |
Line 10... | Line 6... | ||
10 | 6 | ||
- | 7 | #include "../lib/obj/libimg.h" |
|
- | 8 | #include "../lib/obj/box_lib.h" |
|
- | 9 | ||
Line 11... | Line 10... | ||
11 | #include "../lib/obj/libimg.h" |
10 | #include "../lib/patterns/libimg_load_skin.h" |
12 | 11 | ||
13 | #ifndef AUTOBUILD |
12 | #ifndef AUTOBUILD |
Line 14... | Line 13... | ||
14 | #include "lang.h--" |
13 | #include "lang.h--" |
Line -... | Line 14... | ||
- | 14 | #endif |
|
- | 15 | ||
15 | #endif |
16 | /* === TRANSLATIONS === */ |
16 | 17 | ||
17 | /* === TRANSLATIONS === */ |
18 | #define T_WTITLE "EasyShot v0.7" |
18 | 19 | ||
19 | #ifdef LANG_RUS |
20 | #ifdef LANG_RUS |
Line 32... | Line 33... | ||
32 | 33 | ||
33 | dword screenshot, |
34 | dword screenshot, |
Line 34... | Line 35... | ||
34 | preview; |
35 | preview; |
35 | - | ||
36 | int screenshot_length, |
- | |
37 | preview_width, |
36 | |
Line 38... | Line 37... | ||
38 | preview_height, |
37 | int screenshot_length, |
39 | preview_length; |
38 | preview_length; |
40 | 39 | ||
- | 40 | enum { |
|
41 | enum { |
41 | BTN_MAKE_SCREENSHOT=10, |
Line -... | Line 42... | ||
- | 42 | BTN_SAVE, |
|
42 | BTN_MAKE_SCREENSHOT=10, |
43 | BTN_SETTINGS |
Line -... | Line 44... | ||
- | 44 | }; |
|
- | 45 | ||
43 | BTN_SAVE |
46 | #define PD 18 //padding |
- | 47 | #define TOOLBAR_H 20+PD |
|
- | 48 | ||
- | 49 | rect pw; |
|
- | 50 | ||
Line -... | Line 51... | ||
- | 51 | struct _settings { |
|
Line 44... | Line 52... | ||
44 | }; |
52 | bool minimise; |
45 | 53 | int delay; |
|
46 | #define TOOLBAR_H 46; |
54 | char save_path[4096]; |
47 | - | ||
Line -... | Line 55... | ||
- | 55 | } settings = { true, 1, "/tmp0/1" }; |
|
48 | /* === CODE === */ |
56 | |
- | 57 | /* === CODE === */ |
|
- | 58 | ||
- | 59 | void main() |
|
Line 49... | Line 60... | ||
49 | 60 | { |
|
50 | - | ||
51 | void main() |
61 | char id; |
52 | { |
62 | |
Line 53... | Line 63... | ||
53 | char id; |
63 | load_dll(libio, #libio_init, 1); |
54 | int take_scr_btn_width; |
64 | load_dll(libimg, #libimg_init, 1); |
Line 67... | Line 77... | ||
67 | { |
77 | { |
68 | case evButton: |
78 | case evButton: |
69 | id = GetButtonID(); |
79 | id = GetButtonID(); |
70 | if (id == CLOSE_BTN) ExitProcess(); |
80 | if (id == CLOSE_BTN) ExitProcess(); |
71 | if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot(); |
81 | if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot(); |
72 | if (id == BTN_SAVE) EventSaveFile(); |
82 | if (id == BTN_SAVE) EventSaveImageFile(); |
- | 83 | if (id == BTN_SETTINGS) EventShowSettings(); |
|
73 | break; |
84 | break; |
Line 74... | Line 85... | ||
74 | 85 | ||
75 | case evKey: |
86 | case evKey: |
76 | GetKeys(); |
87 | GetKeys(); |
77 | if (SCAN_CODE_KEY_S == key_scancode) EventSaveFile(); |
88 | if (SCAN_CODE_KEY_S == key_scancode) EventSaveImageFile(); |
78 | if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot(); |
89 | if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot(); |
Line 79... | Line 90... | ||
79 | break; |
90 | break; |
80 | - | ||
81 | case evReDraw: |
91 | |
82 | system.color.get(); |
92 | case evReDraw: |
83 | DefineAndDrawWindow(screen.width/4, screen.height/4, |
- | |
84 | preview_width + 9, preview_height + skin_height + TOOLBAR_H + 4, |
93 | DefineAndDrawWindow(screen.width/4, screen.height/4, pw.w + 9 +PD+PD, |
85 | 0x74, 0, "EasyShot v0.5",0); |
94 | pw.h + skin_height + TOOLBAR_H + 4 +PD+PD, 0x74, 0, T_WTITLE,0); |
- | 95 | GetProcessInfo(#Form, SelfInfo); |
|
- | 96 | if (Form.status_window>2) break; |
|
- | 97 | system.color.get(); |
|
- | 98 | DrawMainContent(); |
|
- | 99 | } |
|
- | 100 | } |
|
- | 101 | ||
- | 102 | void DrawMainContent() |
|
86 | GetProcessInfo(#Form, SelfInfo); |
103 | { |
- | 104 | int take_scr_btn_width; |
|
- | 105 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H, system.color.work); |
|
87 | if (Form.status_window>2) break; |
106 | DrawWideRectangle(0, TOOLBAR_H, pw.w+PD+PD, pw.h+PD+PD, PD-1, system.color.work); |
88 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H, system.color.work); |
107 | DrawRectangle(pw.x-1, pw.y-1, pw.w+1, pw.h+1, system.color.work_graph); |
89 | take_scr_btn_width = DrawStandartCaptButton(10, 10, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT); |
108 | take_scr_btn_width = DrawIconButton(pw.x, pw.y-42, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44); |
90 | if (ESDWORD[preview]==0) { |
109 | if (ESDWORD[preview]==0) { |
91 | DrawBar(0, TOOLBAR_H, preview_width, preview_height, 0xEEEeee); |
110 | DrawBar(pw.x, pw.y, pw.w, pw.h, 0xEEEeee); |
92 | WriteText(Form.cwidth-calc(strlen(T_PREVIEW)*8)/2, Form.cheight/2, 0x90, 0x777777, T_PREVIEW); |
111 | WriteText(Form.cwidth-calc(strlen(T_PREVIEW)*8)/2, pw.h/2+pw.y, 0x90, 0x777777, T_PREVIEW); |
93 | } |
112 | } |
94 | else { |
113 | else { |
95 | _PutImage(0, TOOLBAR_H, preview_width, preview_height, preview); |
- | |
96 | DrawStandartCaptButton(take_scr_btn_width + 10, 10, BTN_SAVE, T_SAVE); |
114 | _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); |
|
97 | } |
116 | } |
Line 98... | Line 117... | ||
98 | } |
117 | DrawIconButton(Form.cwidth-40-PD, pw.y-42, BTN_SETTINGS, " ", 10); |
99 | } |
118 | } |
100 | 119 | ||
101 | void EventTakeScreenshot() { |
120 | void EventTakeScreenshot() { |
102 | MinimizeWindow(); |
121 | if (settings.minimise) MinimizeWindow(); |
103 | pause(100); |
122 | pause(settings.delay*100); |
- | 123 | CopyScreen(screenshot, 0, 0, screen.width, screen.height); |
|
104 | CopyScreen(screenshot, 0, 0, screen.width, screen.height); |
124 | ZoomImageTo50percent(); |
Line 105... | Line 125... | ||
105 | ZoomImageTo50percent(); |
125 | ActivateWindow(GetProcessSlot(Form.ID)); |
106 | ActivateWindow(GetProcessSlot(Form.ID)); |
126 | if (!settings.minimise) DrawMainContent(); |
107 | } |
127 | } |
108 | 128 | ||
109 | void EventSaveFile() |
129 | void EventSaveImageFile() |
110 | { |
130 | { |
111 | int i=0; |
131 | int i=0; |
112 | char save_file_name[4096]; |
132 | char save_file_name[4096]; |
113 | do { |
133 | do { |
114 | i++; |
134 | i++; |
Line 115... | Line 135... | ||
115 | sprintf(#save_file_name, "/tmp0/1/screen_%i.png", i); |
135 | sprintf(#save_file_name, "%s/screen_%i.png", #settings.save_path, i); |
116 | } while (file_exists(#save_file_name)); |
136 | } while (file_exists(#save_file_name)); |
117 | SaveFile(screenshot, screen.width, screen.height, #save_file_name); |
137 | save_image(screenshot, screen.width, screen.height, #save_file_name); |
118 | } |
- | |
119 | - | ||
120 | void SaveFile(dword _image, _w, _h, _path) |
- | |
- | 138 | } |
|
Line 121... | Line 139... | ||
121 | { |
139 | |
- | 140 | void EventShowSettings() |
|
- | 141 | { |
|
Line 122... | Line 142... | ||
122 | char save_success_message[4096+200]; |
142 | CreateThread(#SettingsWindow,#settings_stak+4092); |
- | 143 | } |
|
- | 144 | ||
- | 145 | char path_tmp[4096]; |
|
123 | dword encoded_data=0; |
146 | 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}; |
|
124 | dword encoded_size=0; |
148 | |
125 | dword image_ptr = 0; |
149 | void SettingsWindow() |
126 | - | ||
127 | image_ptr = create_image(Image_bpp24, _w, _h); |
150 | { |
- | 151 | #define x 15 |
|
Line -... | Line 152... | ||
- | 152 | int id; |
|
- | 153 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
|
128 | 154 | loop() switch(WaitEvent()) |
|
- | 155 | { |
|
Line -... | Line 156... | ||
- | 156 | case evMouse: |
|
- | 157 | //edit_box_mouse stdcall (#address_box); |
|
- | 158 | break; |
|
- | 159 | ||
- | 160 | case evKey: |
|
129 | if (image_ptr == 0) { |
161 | GetKeys(); |
- | 162 | if (SCAN_CODE_ESC == key_scancode) ExitProcess(); |
|
- | 163 | break; |
|
Line 130... | Line 164... | ||
130 | notify("'Error saving file, probably not enought memory!' -E"); |
164 | |
131 | } |
165 | case evButton: |
132 | else { |
- | |
133 | EDI = image_ptr; |
166 | id = GetButtonID(); |
134 | memmov(EDI._Image.Data, _image, _w * _h * 3); |
167 | if (CLOSE_BTN == id) ExitProcess(); |
135 | 168 | if (10 == id) settings.delay++; |
|
136 | encoded_data = encode_image(image_ptr, LIBIMG_FORMAT_PNG, 0, #encoded_size); |
169 | if (11 == id) && (settings.delay>0) settings.delay--; |
137 | - | ||
138 | img_destroy stdcall(image_ptr); |
- | |
139 | - | ||
140 | if(encoded_data == 0) { |
- | |
141 | notify("'Error saving file, incorrect data!' -E"); |
- | |
142 | } |
170 | if (12 == id) settings.minimise ^= 1; |
143 | else { |
171 | goto _DRAW_CONTENT; |
Line 144... | Line 172... | ||
144 | if (WriteFile(encoded_size, encoded_data, _path) == 0) { |
172 | break; |
145 | sprintf(#save_success_message, "'File saved as %s' -O", _path); |
173 | |
Line 189... | Line 217... | ||
189 | point_x = 0; |
217 | point_x = 0; |
190 | } |
218 | } |
191 | } |
219 | } |
192 | } |
220 | } |
Line -... | Line 221... | ||
- | 221 | ||
193 | 222 | int DrawIconButton(dword x, y, id, text, icon) |
|
- | 223 | { |
|
- | 224 | int btwidth; |
|
- | 225 | system.color.work_button = 0xFFFfff; |
|
- | 226 | system.color.work_button_text = 0; |
|
- | 227 | btwidth = DrawStandartCaptButton(x, y, id, text); |
|
- | 228 | img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16); |
|
- | 229 | system.color.get(); |
|
- | 230 | return btwidth; |
|
Line 194... | Line 231... | ||
194 | 231 | } |
|
- | 232 | ||
- | 233 | stop: |
|
195 | 234 |