Rev 7235 | 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; |
29 | int screenshot_length; |
||
5520 | leency | 30 | |
7220 | leency | 31 | enum { |
32 | BTN_MAKE_SCREENSHOT=10, |
||
7224 | leency | 33 | BTN_SETTINGS |
7220 | leency | 34 | }; |
5520 | leency | 35 | |
7224 | leency | 36 | #define PD 18 //padding |
7220 | leency | 37 | |
7224 | leency | 38 | struct _settings { |
39 | bool minimise; |
||
40 | int delay; |
||
41 | char save_path[4096]; |
||
42 | } settings = { true, 1, "/tmp0/1" }; |
||
43 | |||
5520 | leency | 44 | /* === CODE === */ |
45 | |||
46 | void main() |
||
47 | { |
||
48 | char id; |
||
7221 | leency | 49 | |
7224 | leency | 50 | load_dll(libio, #libio_init, 1); |
7221 | leency | 51 | load_dll(libimg, #libimg_init, 1); |
7224 | leency | 52 | load_dll(boxlib, #box_lib_init,0); |
7221 | leency | 53 | |
7224 | leency | 54 | Libimg_LoadImage(#skin, "/sys/icons16.png"); |
55 | |||
7221 | leency | 56 | screenshot_length = screen.width * screen.height * 3; |
5520 | leency | 57 | |
7221 | leency | 58 | screenshot = malloc(screenshot_length); |
5520 | leency | 59 | |
7220 | leency | 60 | loop() switch(WaitEvent()) |
5520 | leency | 61 | { |
7220 | leency | 62 | case evButton: |
63 | id = GetButtonID(); |
||
64 | if (id == CLOSE_BTN) ExitProcess(); |
||
65 | if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot(); |
||
7224 | leency | 66 | if (id == BTN_SETTINGS) EventShowSettings(); |
7220 | leency | 67 | break; |
68 | |||
69 | case evKey: |
||
70 | GetKeys(); |
||
71 | if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot(); |
||
72 | break; |
||
73 | |||
74 | case evReDraw: |
||
7235 | leency | 75 | system.color.get(); |
76 | DefineAndDrawWindow(screen.width/4, screen.height-100/3, 270, |
||
77 | skin_height + 27+PD+PD, 0x34, system.color.work, T_WTITLE,0); |
||
7220 | leency | 78 | GetProcessInfo(#Form, SelfInfo); |
79 | if (Form.status_window>2) break; |
||
7224 | leency | 80 | DrawMainContent(); |
7220 | leency | 81 | } |
5520 | leency | 82 | } |
83 | |||
7224 | leency | 84 | void DrawMainContent() |
85 | { |
||
86 | int take_scr_btn_width; |
||
7235 | leency | 87 | take_scr_btn_width = DrawIconButton(PD, PD, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44); |
88 | DrawIconButton(PD+take_scr_btn_width, PD, BTN_SETTINGS, " ", 10); |
||
7224 | leency | 89 | } |
90 | |||
7220 | leency | 91 | void EventTakeScreenshot() { |
7224 | leency | 92 | if (settings.minimise) MinimizeWindow(); |
93 | pause(settings.delay*100); |
||
7221 | leency | 94 | CopyScreen(screenshot, 0, 0, screen.width, screen.height); |
5520 | leency | 95 | ActivateWindow(GetProcessSlot(Form.ID)); |
7224 | leency | 96 | if (!settings.minimise) DrawMainContent(); |
7235 | leency | 97 | EventSaveImageFile(); |
5520 | leency | 98 | } |
99 | |||
7224 | leency | 100 | void EventSaveImageFile() |
7220 | leency | 101 | { |
7221 | leency | 102 | int i=0; |
103 | char save_file_name[4096]; |
||
104 | do { |
||
105 | i++; |
||
7224 | leency | 106 | sprintf(#save_file_name, "%s/screen_%i.png", #settings.save_path, i); |
7221 | leency | 107 | } while (file_exists(#save_file_name)); |
7224 | leency | 108 | save_image(screenshot, screen.width, screen.height, #save_file_name); |
7220 | leency | 109 | } |
110 | |||
7224 | leency | 111 | void EventShowSettings() |
7220 | leency | 112 | { |
7224 | leency | 113 | CreateThread(#SettingsWindow,#settings_stak+4092); |
114 | } |
||
7220 | leency | 115 | |
7224 | leency | 116 | char path_tmp[4096]; |
117 | dword mouse_dd1; |
||
118 | edit_box edit_box_path = {270,10,70,0xffffff,0x94AECE,0xFFFfff,0xffffff,0x10000000,sizeof(path_tmp),#path_tmp,#mouse_dd1, 0b}; |
||
7220 | leency | 119 | |
7243 | leency | 120 | more_less_box delay = { 1, 0, 64, "Delay in seconds" }; |
121 | |||
7224 | leency | 122 | void SettingsWindow() |
123 | { |
||
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(); |
||
7243 | leency | 139 | delay.click(id); |
7224 | leency | 140 | if (CLOSE_BTN == id) ExitProcess(); |
7243 | leency | 141 | if (12 == id) { settings.minimise ^= 1; goto _DRAW_CONTENT; } |
7224 | leency | 142 | break; |
143 | |||
144 | case evReDraw: |
||
145 | DefineAndDrawWindow(Form.left+100, Form.top-40, 330, 170, 0x34, system.color.work, "Settings",0); |
||
146 | _DRAW_CONTENT: |
||
7243 | leency | 147 | CheckBox(15, 10, 12, "Minimize window", settings.minimise); |
148 | delay.draw(15, 40); |
||
7224 | leency | 149 | //DrawEditBox(#edit_box_path); |
7220 | leency | 150 | } |
151 | } |
||
152 | |||
7221 | leency | 153 | inline byte calc_rgb(dword B, item_h) |
154 | { |
||
155 | return calc(ESBYTE[B+3] + ESBYTE[B] + ESBYTE[B-3] |
||
156 | + ESBYTE[B-item_h] + ESBYTE[B+item_h] / 5); |
||
157 | } |
||
158 | |||
7224 | leency | 159 | int DrawIconButton(dword x, y, id, text, icon) |
160 | { |
||
161 | int btwidth; |
||
162 | system.color.work_button = 0xFFFfff; |
||
163 | system.color.work_button_text = 0; |
||
164 | btwidth = DrawStandartCaptButton(x, y, id, text); |
||
165 | img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16); |
||
166 | system.color.get(); |
||
167 | return btwidth; |
||
168 | } |
||
5520 | leency | 169 | |
7224 | leency | 170 | stop: |
7221 | leency | 171 | |
7224 | leency | 172 | char settings_stak[4096]; |