Rev 7229 | 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" |
7220 | leency | 9 | |
5520 | leency | 10 | #ifndef AUTOBUILD |
11 | #include "lang.h--" |
||
12 | #endif |
||
13 | |||
7221 | leency | 14 | /* === TRANSLATIONS === */ |
15 | |||
7235 | leency | 16 | #define T_WTITLE "EasyShot v0.75" |
7224 | leency | 17 | |
7221 | leency | 18 | #ifdef LANG_RUS |
7224 | leency | 19 | ?define T_TAKE_SCREENSHOT " Сделать скриншот" |
7221 | leency | 20 | #else |
7224 | leency | 21 | ?define T_TAKE_SCREENSHOT " Take a screenshot" |
7221 | leency | 22 | #endif |
23 | |||
7235 | leency | 24 | /* === DATA === */ |
5520 | leency | 25 | |
26 | proc_info Form; |
||
27 | |||
7235 | leency | 28 | dword screenshot; |
5520 | leency | 29 | |
7235 | leency | 30 | int screenshot_length; |
5520 | leency | 31 | |
7220 | leency | 32 | enum { |
33 | BTN_MAKE_SCREENSHOT=10, |
||
7224 | leency | 34 | BTN_SETTINGS |
7220 | leency | 35 | }; |
5520 | leency | 36 | |
7224 | leency | 37 | #define PD 18 //padding |
7220 | leency | 38 | |
7224 | leency | 39 | struct _settings { |
40 | bool minimise; |
||
41 | int delay; |
||
42 | char save_path[4096]; |
||
43 | } settings = { true, 1, "/tmp0/1" }; |
||
44 | |||
5520 | leency | 45 | /* === CODE === */ |
46 | |||
47 | void main() |
||
48 | { |
||
49 | char id; |
||
7221 | leency | 50 | |
7224 | leency | 51 | load_dll(libio, #libio_init, 1); |
7221 | leency | 52 | load_dll(libimg, #libimg_init, 1); |
7224 | leency | 53 | load_dll(boxlib, #box_lib_init,0); |
7221 | leency | 54 | |
7224 | leency | 55 | Libimg_LoadImage(#skin, "/sys/icons16.png"); |
56 | |||
7221 | leency | 57 | screenshot_length = screen.width * screen.height * 3; |
5520 | leency | 58 | |
7221 | leency | 59 | screenshot = malloc(screenshot_length); |
5520 | leency | 60 | |
7220 | leency | 61 | loop() switch(WaitEvent()) |
5520 | leency | 62 | { |
7220 | leency | 63 | case evButton: |
64 | id = GetButtonID(); |
||
65 | if (id == CLOSE_BTN) ExitProcess(); |
||
66 | if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot(); |
||
7224 | leency | 67 | if (id == BTN_SETTINGS) EventShowSettings(); |
7220 | leency | 68 | break; |
69 | |||
70 | case evKey: |
||
71 | GetKeys(); |
||
72 | if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot(); |
||
73 | break; |
||
74 | |||
75 | case evReDraw: |
||
7235 | leency | 76 | system.color.get(); |
77 | DefineAndDrawWindow(screen.width/4, screen.height-100/3, 270, |
||
78 | skin_height + 27+PD+PD, 0x34, system.color.work, T_WTITLE,0); |
||
7220 | leency | 79 | GetProcessInfo(#Form, SelfInfo); |
80 | if (Form.status_window>2) break; |
||
7224 | leency | 81 | DrawMainContent(); |
7220 | leency | 82 | } |
5520 | leency | 83 | } |
84 | |||
7224 | leency | 85 | void DrawMainContent() |
86 | { |
||
87 | int take_scr_btn_width; |
||
7235 | leency | 88 | take_scr_btn_width = DrawIconButton(PD, PD, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44); |
89 | DrawIconButton(PD+take_scr_btn_width, PD, BTN_SETTINGS, " ", 10); |
||
7224 | leency | 90 | } |
91 | |||
7220 | leency | 92 | void EventTakeScreenshot() { |
7224 | leency | 93 | if (settings.minimise) MinimizeWindow(); |
94 | pause(settings.delay*100); |
||
7221 | leency | 95 | CopyScreen(screenshot, 0, 0, screen.width, screen.height); |
5520 | leency | 96 | ActivateWindow(GetProcessSlot(Form.ID)); |
7224 | leency | 97 | if (!settings.minimise) DrawMainContent(); |
7235 | leency | 98 | EventSaveImageFile(); |
5520 | leency | 99 | } |
100 | |||
7224 | leency | 101 | void EventSaveImageFile() |
7220 | leency | 102 | { |
7221 | leency | 103 | int i=0; |
104 | char save_file_name[4096]; |
||
105 | do { |
||
106 | i++; |
||
7224 | leency | 107 | sprintf(#save_file_name, "%s/screen_%i.png", #settings.save_path, i); |
7221 | leency | 108 | } while (file_exists(#save_file_name)); |
7224 | leency | 109 | save_image(screenshot, screen.width, screen.height, #save_file_name); |
7220 | leency | 110 | } |
111 | |||
7224 | leency | 112 | void EventShowSettings() |
7220 | leency | 113 | { |
7224 | leency | 114 | CreateThread(#SettingsWindow,#settings_stak+4092); |
115 | } |
||
7220 | leency | 116 | |
7224 | leency | 117 | char path_tmp[4096]; |
118 | dword mouse_dd1; |
||
119 | edit_box edit_box_path = {270,10,70,0xffffff,0x94AECE,0xFFFfff,0xffffff,0x10000000,sizeof(path_tmp),#path_tmp,#mouse_dd1, 0b}; |
||
7220 | leency | 120 | |
7224 | leency | 121 | void SettingsWindow() |
122 | { |
||
123 | #define x 15 |
||
124 | int id; |
||
125 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
||
126 | loop() switch(WaitEvent()) |
||
127 | { |
||
128 | case evMouse: |
||
129 | //edit_box_mouse stdcall (#address_box); |
||
130 | break; |
||
7220 | leency | 131 | |
7224 | leency | 132 | case evKey: |
133 | GetKeys(); |
||
134 | if (SCAN_CODE_ESC == key_scancode) ExitProcess(); |
||
135 | break; |
||
7220 | leency | 136 | |
7224 | leency | 137 | case evButton: |
138 | id = GetButtonID(); |
||
139 | if (CLOSE_BTN == id) ExitProcess(); |
||
140 | if (10 == id) settings.delay++; |
||
141 | if (11 == id) && (settings.delay>0) settings.delay--; |
||
142 | if (12 == id) settings.minimise ^= 1; |
||
143 | goto _DRAW_CONTENT; |
||
144 | break; |
||
145 | |||
146 | case evReDraw: |
||
147 | DefineAndDrawWindow(Form.left+100, Form.top-40, 330, 170, 0x34, system.color.work, "Settings",0); |
||
148 | _DRAW_CONTENT: |
||
149 | CheckBox(x, 10, 12, "Minimize window", settings.minimise); |
||
150 | MoreLessBox(x, 40, 10, 11, settings.delay, "Delay in seconds"); |
||
151 | //DrawEditBox(#edit_box_path); |
||
7220 | leency | 152 | } |
153 | } |
||
154 | |||
7221 | leency | 155 | inline byte calc_rgb(dword B, item_h) |
156 | { |
||
157 | return calc(ESBYTE[B+3] + ESBYTE[B] + ESBYTE[B-3] |
||
158 | + ESBYTE[B-item_h] + ESBYTE[B+item_h] / 5); |
||
159 | } |
||
160 | |||
7224 | leency | 161 | int DrawIconButton(dword x, y, id, text, icon) |
162 | { |
||
163 | int btwidth; |
||
164 | system.color.work_button = 0xFFFfff; |
||
165 | system.color.work_button_text = 0; |
||
166 | btwidth = DrawStandartCaptButton(x, y, id, text); |
||
167 | img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16); |
||
168 | system.color.get(); |
||
169 | return btwidth; |
||
170 | } |
||
5520 | leency | 171 | |
7224 | leency | 172 | stop: |
7221 | leency | 173 | |
7224 | leency | 174 | char settings_stak[4096]; |