Rev 9597 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8752 | leency | 1 | #define MEMSIZE 1024 * 40 |
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 | |
7221 | leency | 11 | /* === TRANSLATIONS === */ |
12 | |||
13 | #ifdef LANG_RUS |
||
9015 | leency | 14 | ?define T_SCREENSHOT "Скриншот" |
15 | ?define T_READY "Готов." |
||
16 | ?define T_RECORD "Запись" |
||
17 | ?define T_STOP "Остановить запись" |
||
7245 | leency | 18 | ?define T_SETTINGS "Настройки" |
7783 | leency | 19 | ?define T_EDITBOX_FRAME "Путь сохранения скриншота" |
7245 | leency | 20 | ?define T_DELAY "Задержка в секундах" |
9015 | leency | 21 | ?define T_NO_DIR "Папка для сохранения не существует!" |
7221 | leency | 22 | #else |
9015 | leency | 23 | ?define T_SCREENSHOT "Screenshot" |
24 | ?define T_READY "Ready." |
||
25 | ?define T_RECORD "Record" |
||
26 | ?define T_STOP "Stop recording" |
||
7245 | leency | 27 | ?define T_SETTINGS "Settings" |
7783 | leency | 28 | ?define T_EDITBOX_FRAME "Save path" |
7245 | leency | 29 | ?define T_DELAY "Delay in seconds" |
9015 | leency | 30 | ?define T_NO_DIR "Saving directory does not exists!" |
7221 | leency | 31 | #endif |
32 | |||
7235 | leency | 33 | /* === DATA === */ |
5520 | leency | 34 | |
35 | proc_info Form; |
||
36 | |||
7220 | leency | 37 | enum { |
9015 | leency | 38 | BTN_SCREENSHOT=10, |
39 | BTN_RECORD, |
||
7783 | leency | 40 | BTN_SETTINGS, |
41 | BTN_CHOOSE_SAVING_PATH |
||
7220 | leency | 42 | }; |
5520 | leency | 43 | |
9015 | leency | 44 | bool recording=false; |
45 | |||
7224 | leency | 46 | #define PD 18 //padding |
9015 | leency | 47 | #define SETTINGS_Y PD+PD+60+10 |
7220 | leency | 48 | |
7245 | leency | 49 | char save_path[4096]; |
7224 | leency | 50 | |
7783 | leency | 51 | more_less_box delay = { 1, 0, SETTINGS_Y, T_DELAY }; |
52 | edit_box edit_save = {260,PD,SETTINGS_Y+50,0xffffff,0x94AECE,0xFFFfff,0xffffff, |
||
7506 | leency | 53 | 0x10000000,sizeof(save_path)-2,#save_path,0, 0b}; |
7244 | leency | 54 | |
7783 | leency | 55 | bool show_settings = false; |
7244 | leency | 56 | |
7245 | leency | 57 | opendialog open_folder_dialog = |
58 | { |
||
59 | 2, //0-file, 2-save, 3-select folder |
||
7783 | leency | 60 | #Form, |
7245 | leency | 61 | #communication_area_name, |
62 | 0, |
||
63 | 0, //dword opendir_path, |
||
8752 | leency | 64 | #save_path, //dword dir_default_path, |
7245 | leency | 65 | #open_dialog_path, |
7783 | leency | 66 | #DrawWindow, |
7245 | leency | 67 | 0, |
8752 | leency | 68 | #save_path, //dword openfile_path, |
7245 | leency | 69 | 0, //dword filename_area, |
70 | 0, //dword filter_area, |
||
71 | 420, |
||
72 | NULL, |
||
73 | 320, |
||
74 | NULL |
||
75 | }; |
||
76 | |||
5520 | leency | 77 | /* === CODE === */ |
78 | |||
7783 | leency | 79 | void init_libraries() |
80 | { |
||
7221 | leency | 81 | load_dll(libimg, #libimg_init, 1); |
7224 | leency | 82 | load_dll(boxlib, #box_lib_init,0); |
7245 | leency | 83 | load_dll(Proc_lib, #OpenDialog_init,0); |
7783 | leency | 84 | OpenDialog_init stdcall (#open_folder_dialog); |
85 | } |
||
7221 | leency | 86 | |
7783 | leency | 87 | void main() |
88 | { |
||
89 | int id; |
||
5520 | leency | 90 | |
9015 | leency | 91 | I_Param = T_READY; |
7783 | leency | 92 | init_libraries(); |
7245 | leency | 93 | |
8752 | leency | 94 | edit_box_set_text stdcall (#edit_save, "/tmp0/1"); |
7783 | leency | 95 | |
7984 | leency | 96 | @SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
9015 | leency | 97 | loop() switch(@WaitEventTimeout(delay.value*100)) |
5520 | leency | 98 | { |
7783 | leency | 99 | case evMouse: |
100 | edit_box_mouse stdcall (#edit_save); |
||
101 | break; |
||
102 | |||
7220 | leency | 103 | case evButton: |
7984 | leency | 104 | id = @GetButtonID(); |
7783 | leency | 105 | switch(id){ |
8752 | leency | 106 | case CLOSE_BTN: @ExitProcess(); |
9015 | leency | 107 | case BTN_SCREENSHOT: EventScreenshotClick(); break; |
108 | case BTN_RECORD: EventRecordingClick(); break; |
||
109 | case BTN_SETTINGS: EventSettingsClick(); break; |
||
110 | case BTN_CHOOSE_SAVING_PATH: EventChooseSavePathClick(); break; |
||
7783 | leency | 111 | default: delay.click(id); |
112 | } |
||
7220 | leency | 113 | break; |
114 | |||
115 | case evKey: |
||
8752 | leency | 116 | @GetKey(); |
7984 | leency | 117 | edit_box_key stdcall (#edit_save); |
118 | EAX >>= 16; |
||
9015 | leency | 119 | if (SCAN_CODE_ENTER == AL) EventScreenshotClick(); |
120 | else if (SCAN_CODE_ESC == AL) ExitProcess(); |
||
7220 | leency | 121 | break; |
122 | |||
123 | case evReDraw: |
||
7783 | leency | 124 | DrawWindow(); |
9015 | leency | 125 | |
126 | default: |
||
127 | if (recording) MakeScreenshot(); |
||
7220 | leency | 128 | } |
5520 | leency | 129 | } |
130 | |||
7783 | leency | 131 | |
132 | void DrawWindow() |
||
7224 | leency | 133 | { |
9015 | leency | 134 | unsigned i; |
7783 | leency | 135 | |
7806 | leency | 136 | sc.get(); |
9597 | leency | 137 | DefineAndDrawWindow(screen.w-400, screen.h/3, 280, |
138 | skin_h + 50+PD+PD, 0x34, sc.work, "EasyShot",0); |
||
7783 | leency | 139 | GetProcessInfo(#Form, SelfInfo); |
140 | |||
9015 | leency | 141 | if (!recording) { |
142 | DrawCaptButton(PD, PD, 101, 28, BTN_SCREENSHOT, |
||
143 | 0x0090B8, 0xFFFfff, T_SCREENSHOT); |
||
144 | DrawCaptButton(PD+105, PD, 75, 28, BTN_RECORD, |
||
145 | 0x0090B8, 0xFFFfff, T_RECORD); |
||
146 | } else { |
||
147 | DrawCaptButton(PD, PD, 96+80+4, 28, BTN_RECORD, |
||
148 | 0xC75C54, 0xFFFfff, T_STOP); |
||
149 | } |
||
150 | DefineButton(PD+200, PD, 35, 28, BTN_SETTINGS, sc.button); |
||
151 | for (i=0; i<=2; i++) DrawBar(PD+210, i*5+PD+9, 15, 2, sc.button_text); |
||
152 | DrawStatusBar(I_Param); |
||
153 | |||
7783 | leency | 154 | delay.draw(PD, SETTINGS_Y); |
9015 | leency | 155 | DrawFileBox(#edit_save, T_EDITBOX_FRAME, BTN_CHOOSE_SAVING_PATH); |
156 | |||
7224 | leency | 157 | } |
158 | |||
9015 | leency | 159 | void DrawStatusBar(char *s) |
7783 | leency | 160 | { |
9015 | leency | 161 | I_Param = s; |
9602 | leency | 162 | WriteTextWithBg(PD, 35+PD, 0xD0, sc.work_text, I_Param, sc.light); |
5520 | leency | 163 | } |
164 | |||
9015 | leency | 165 | dword ScreenshotBuf() |
7220 | leency | 166 | { |
9015 | leency | 167 | static dword screenshot; |
9597 | leency | 168 | if (!screenshot) screenshot = malloc(screen.w * screen.h * 3); |
9015 | leency | 169 | return screenshot; |
7783 | leency | 170 | } |
171 | |||
9015 | leency | 172 | bool GetSavingPath() |
7783 | leency | 173 | { |
7221 | leency | 174 | int i=0; |
175 | char save_file_name[4096]; |
||
176 | do { |
||
177 | i++; |
||
7783 | leency | 178 | //sprintf(, "%s/screen_%i.png", #save_path, i); |
179 | strcpy(#save_file_name, #save_path); |
||
180 | if (save_file_name[strlen(#save_file_name)-1]!='/') chrcat(#save_file_name, '/'); |
||
9015 | leency | 181 | strcat(#save_file_name, "scr_"); |
7771 | leency | 182 | strcat(#save_file_name, itoa(i)); |
183 | strcat(#save_file_name, ".png"); |
||
7221 | leency | 184 | } while (file_exists(#save_file_name)); |
7220 | leency | 185 | |
7783 | leency | 186 | if (!dir_exists(#save_path)) { |
9015 | leency | 187 | DrawStatusBar(T_NO_DIR); |
188 | return NULL; |
||
7220 | leency | 189 | } |
9015 | leency | 190 | return #save_file_name; |
191 | } |
||
7220 | leency | 192 | |
9015 | leency | 193 | void MakeScreenshot() |
194 | { |
||
195 | if (I_Path = GetSavingPath()) { |
||
9597 | leency | 196 | CopyScreen(ScreenshotBuf(), 0, 0, screen.w, screen.h); |
197 | I_Param = save_image(ScreenshotBuf(), screen.w, screen.h, I_Path); |
||
9015 | leency | 198 | if (!I_Param) I_Param = I_Path; |
199 | DrawStatusBar(I_Param); |
||
200 | } else { |
||
201 | recording = false; |
||
202 | DrawWindow(); |
||
203 | } |
||
204 | } |
||
205 | |||
206 | //===================================================// |
||
207 | // // |
||
208 | // EVENTS // |
||
209 | // // |
||
210 | //===================================================// |
||
211 | |||
212 | void EventScreenshotClick() |
||
213 | { |
||
214 | MinimizeWindow(); |
||
7783 | leency | 215 | pause(delay.value*100); |
9015 | leency | 216 | MakeScreenshot(); |
7783 | leency | 217 | ActivateWindow(GetProcessSlot(Form.ID)); |
7245 | leency | 218 | } |
219 | |||
9015 | leency | 220 | void EventRecordingClick() |
221 | { |
||
222 | recording ^= 1; |
||
223 | DrawWindow(); |
||
224 | } |
||
225 | |||
226 | void EventSettingsClick() |
||
227 | { |
||
228 | show_settings ^= 1; |
||
229 | @MoveSize(OLD, OLD, show_settings*65 + 280, |
||
9597 | leency | 230 | show_settings*110 + skin_h + PD+PD+50); |
9015 | leency | 231 | } |
232 | |||
233 | void EventChooseSavePathClick() |
||
234 | { |
||
235 | OpenDialog_start stdcall (#open_folder_dialog); |
||
236 | if (open_folder_dialog.status) { |
||
237 | edit_box_set_text stdcall (#edit_save, #save_path); |
||
238 | } |
||
239 | }=2;> |