Rev 7249 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7224 | leency | 1 | #define MEMSIZE 1024 * 50 |
5598 | pavelyakov | 2 | #include "../lib/kolibri.h" |
3 | #include "../lib/strings.h" |
||
4 | #include "../lib/mem.h" |
||
5 | #include "../lib/gui.h" |
||
5520 | leency | 6 | |
7220 | leency | 7 | #include "../lib/obj/libimg.h" |
7224 | leency | 8 | #include "../lib/obj/box_lib.h" |
7245 | leency | 9 | #include "../lib/obj/proc_lib.h" |
7220 | leency | 10 | |
5520 | leency | 11 | #ifndef AUTOBUILD |
12 | #include "lang.h--" |
||
13 | #endif |
||
14 | |||
7221 | leency | 15 | /* === TRANSLATIONS === */ |
16 | |||
7245 | leency | 17 | #define T_WTITLE "EasyShot v1.0" |
7224 | leency | 18 | |
7221 | leency | 19 | #ifdef LANG_RUS |
7224 | leency | 20 | ?define T_TAKE_SCREENSHOT " Сделать скриншот" |
7245 | leency | 21 | ?define T_SETTINGS "Настройки" |
22 | ?define T_EDITBOX_FRAME " Путь сохранения скриншота " |
||
23 | ?define T_DELAY "Задержка в секундах" |
||
7247 | theonlymir | 24 | ?define T_MINIMIZE "Свернуть окно при снимке" |
7245 | leency | 25 | ?define T_NO_DIR "'Папка не существует!' -E" |
26 | ?define T_SET_PATH "Задать" |
||
7221 | leency | 27 | #else |
7224 | leency | 28 | ?define T_TAKE_SCREENSHOT " Take a screenshot" |
7245 | leency | 29 | ?define T_SETTINGS "Settings" |
30 | ?define T_EDITBOX_FRAME " Save path " |
||
31 | ?define T_DELAY "Delay in seconds" |
||
32 | ?define T_MINIMIZE "Minimize window" |
||
33 | ?define T_NO_DIR "'Directory does not exists!' -E" |
||
34 | ?define T_SET_PATH "Set" |
||
7221 | leency | 35 | #endif |
36 | |||
7235 | leency | 37 | /* === DATA === */ |
5520 | leency | 38 | |
39 | proc_info Form; |
||
7246 | leency | 40 | proc_info Settings; |
5520 | leency | 41 | |
7235 | leency | 42 | dword screenshot; |
43 | int screenshot_length; |
||
5520 | leency | 44 | |
7220 | leency | 45 | enum { |
46 | BTN_MAKE_SCREENSHOT=10, |
||
7224 | leency | 47 | BTN_SETTINGS |
7220 | leency | 48 | }; |
5520 | leency | 49 | |
7224 | leency | 50 | #define PD 18 //padding |
7220 | leency | 51 | |
7245 | leency | 52 | char save_path[4096]; |
53 | char save_path_stable[4096]; |
||
54 | char open_dir[4096]; |
||
7224 | leency | 55 | |
7245 | leency | 56 | edit_box edit_save = {250,25,100,0xffffff,0x94AECE,0xFFFfff,0xffffff, |
7252 | leency | 57 | 0x10000000,sizeof(save_path),#save_path,0, 0b}; |
7244 | leency | 58 | |
7245 | leency | 59 | more_less_box delay = { 1, 0, 64, T_DELAY }; |
60 | checkbox minimize = { T_MINIMIZE, true }; |
||
7244 | leency | 61 | |
62 | |||
7245 | leency | 63 | opendialog open_folder_dialog = |
64 | { |
||
65 | 2, //0-file, 2-save, 3-select folder |
||
66 | #Settings, |
||
67 | #communication_area_name, |
||
68 | 0, |
||
69 | 0, //dword opendir_path, |
||
70 | #open_dir, //dword dir_default_path, |
||
71 | #open_dialog_path, |
||
72 | #DrawSettingsWindow, |
||
73 | 0, |
||
74 | #open_dir, //dword openfile_path, |
||
75 | 0, //dword filename_area, |
||
76 | 0, //dword filter_area, |
||
77 | 420, |
||
78 | NULL, |
||
79 | 320, |
||
80 | NULL |
||
81 | }; |
||
82 | |||
5520 | leency | 83 | /* === CODE === */ |
84 | |||
85 | void main() |
||
86 | { |
||
7249 | leency | 87 | int id; |
7221 | leency | 88 | |
7224 | leency | 89 | load_dll(libio, #libio_init, 1); |
7221 | leency | 90 | load_dll(libimg, #libimg_init, 1); |
7224 | leency | 91 | load_dll(boxlib, #box_lib_init,0); |
7245 | leency | 92 | load_dll(Proc_lib, #OpenDialog_init,0); |
93 | OpenDialog_init stdcall (#open_folder_dialog); |
||
7221 | leency | 94 | |
7245 | leency | 95 | system.color.get(); |
7224 | leency | 96 | Libimg_LoadImage(#skin, "/sys/icons16.png"); |
7245 | leency | 97 | Libimg_ReplaceColor(skin.image, skin.w, skin.h, 0xffFFFfff, system.color.work_button); |
98 | Libimg_ReplaceColor(skin.image, skin.w, skin.h, 0xffCACBD6, MixColors(system.color.work_button, 0, 200)); |
||
7221 | leency | 99 | screenshot_length = screen.width * screen.height * 3; |
7244 | leency | 100 | screenshot = malloc(screenshot_length); |
5520 | leency | 101 | |
7245 | leency | 102 | strcpy(#save_path_stable, "/tmp0/1"); |
103 | strcpy(#save_path, #save_path_stable); |
||
104 | edit_save.size = strlen(#save_path); |
||
105 | |||
7220 | leency | 106 | loop() switch(WaitEvent()) |
5520 | leency | 107 | { |
7220 | leency | 108 | case evButton: |
109 | id = GetButtonID(); |
||
110 | if (id == CLOSE_BTN) ExitProcess(); |
||
111 | if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot(); |
||
7244 | leency | 112 | if (id == BTN_SETTINGS) CreateThread(#SettingsWindow,#settings_stak+4092); |
7220 | leency | 113 | break; |
114 | |||
115 | case evKey: |
||
116 | GetKeys(); |
||
117 | if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot(); |
||
118 | break; |
||
119 | |||
120 | case evReDraw: |
||
7235 | leency | 121 | DefineAndDrawWindow(screen.width/4, screen.height-100/3, 270, |
122 | skin_height + 27+PD+PD, 0x34, system.color.work, T_WTITLE,0); |
||
7220 | leency | 123 | GetProcessInfo(#Form, SelfInfo); |
7224 | leency | 124 | DrawMainContent(); |
7220 | leency | 125 | } |
5520 | leency | 126 | } |
127 | |||
7224 | leency | 128 | void DrawMainContent() |
129 | { |
||
130 | int take_scr_btn_width; |
||
7235 | leency | 131 | take_scr_btn_width = DrawIconButton(PD, PD, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44); |
132 | DrawIconButton(PD+take_scr_btn_width, PD, BTN_SETTINGS, " ", 10); |
||
7224 | leency | 133 | } |
134 | |||
7220 | leency | 135 | void EventTakeScreenshot() { |
7245 | leency | 136 | if (minimize.checked) MinimizeWindow(); |
7244 | leency | 137 | pause(delay.value*100); |
7221 | leency | 138 | CopyScreen(screenshot, 0, 0, screen.width, screen.height); |
5520 | leency | 139 | ActivateWindow(GetProcessSlot(Form.ID)); |
7245 | leency | 140 | if (!minimize.checked) DrawMainContent(); |
7235 | leency | 141 | EventSaveImageFile(); |
5520 | leency | 142 | } |
143 | |||
7224 | leency | 144 | void EventSaveImageFile() |
7220 | leency | 145 | { |
7221 | leency | 146 | int i=0; |
147 | char save_file_name[4096]; |
||
148 | do { |
||
149 | i++; |
||
7245 | leency | 150 | sprintf(#save_file_name, "%s/screen_%i.png", #save_path_stable, i); |
7221 | leency | 151 | } while (file_exists(#save_file_name)); |
7224 | leency | 152 | save_image(screenshot, screen.width, screen.height, #save_file_name); |
7220 | leency | 153 | } |
154 | |||
155 | |||
7224 | leency | 156 | void SettingsWindow() |
157 | { |
||
7245 | leency | 158 | #define BTN_OD 10 |
159 | #define BTN_SET 11 |
||
160 | int id, butw; |
||
161 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
||
7224 | leency | 162 | loop() switch(WaitEvent()) |
163 | { |
||
164 | case evMouse: |
||
7245 | leency | 165 | edit_box_mouse stdcall (#edit_save); |
7224 | leency | 166 | break; |
7220 | leency | 167 | |
7224 | leency | 168 | case evKey: |
169 | GetKeys(); |
||
170 | if (SCAN_CODE_ESC == key_scancode) ExitProcess(); |
||
7245 | leency | 171 | EAX= key_ascii << 8; |
172 | edit_box_key stdcall (#edit_save); |
||
7224 | leency | 173 | break; |
7220 | leency | 174 | |
7224 | leency | 175 | case evButton: |
176 | id = GetButtonID(); |
||
7244 | leency | 177 | if (CLOSE_BTN == id) ExitProcess(); |
7245 | leency | 178 | if (BTN_OD == id) { |
179 | OpenDialog_start stdcall (#open_folder_dialog); |
||
180 | if (open_folder_dialog.status) { |
||
181 | strcpy(#save_path, open_folder_dialog.opendir_path); |
||
182 | edit_save.size = edit_save.pos = edit_save.shift |
||
183 | = edit_save.shift_old = strlen(#save_path); |
||
184 | } |
||
185 | } |
||
186 | if (BTN_SET == id) { |
||
187 | if (save_path[0]) && (dir_exists(#save_path)) { |
||
188 | strcpy(#save_path_stable, #save_path); |
||
189 | strrtrim(#save_path_stable); |
||
190 | if (save_path_stable[strlen(#save_path_stable)-1]=='/') |
||
191 | save_path_stable[strlen(#save_path_stable)-1]=NULL; //no "/" at the end |
||
192 | } |
||
193 | else notify(T_NO_DIR); |
||
194 | |||
195 | } |
||
7243 | leency | 196 | delay.click(id); |
7245 | leency | 197 | minimize.click(id); |
7224 | leency | 198 | break; |
199 | |||
200 | case evReDraw: |
||
7245 | leency | 201 | DrawSettingsWindow(); |
7220 | leency | 202 | } |
203 | } |
||
204 | |||
7245 | leency | 205 | void DrawSettingsWindow() |
206 | { |
||
207 | DefineAndDrawWindow(Form.left+100, Form.top-40, 400, 230, 0x34, system.color.work, T_SETTINGS, 0); |
||
208 | GetProcessInfo(#Settings, SelfInfo); |
||
209 | minimize.draw(15, 15); |
||
210 | delay.draw(15, 45); |
||
211 | DrawFrame(15, 85, 360, 95, T_EDITBOX_FRAME); |
||
212 | DrawEditBoxPos(32, 110, #edit_save); |
||
213 | DrawStandartCaptButton(edit_save.left + edit_save.width + 15, edit_save.top-3, BTN_OD, "..."); |
||
214 | DrawStandartCaptButton(edit_save.left, edit_save.top+32, BTN_SET, T_SET_PATH); |
||
215 | } |
||
216 | |||
7224 | leency | 217 | int DrawIconButton(dword x, y, id, text, icon) |
218 | { |
||
219 | int btwidth; |
||
220 | btwidth = DrawStandartCaptButton(x, y, id, text); |
||
221 | img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16); |
||
222 | return btwidth; |
||
223 | } |
||
5520 | leency | 224 | |
7224 | leency | 225 | stop: |
7221 | leency | 226 | |
7224 | leency | 227 | char settings_stak[4096];><> |