Subversion Repositories Kolibri OS

Rev

Rev 7228 | 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
 
7224 leency 16
#define T_WTITLE "EasyShot v0.7"
17
 
7221 leency 18
#ifdef LANG_RUS
7224 leency 19
	?define T_TAKE_SCREENSHOT "  Сделать скриншот"
20
	?define T_SAVE "  Сохранить"
7221 leency 21
	?define T_PREVIEW "Предпросмотр"
22
#else
7224 leency 23
	?define T_TAKE_SCREENSHOT "  Take a screenshot"
24
	?define T_SAVE "  Save"
7221 leency 25
	?define T_PREVIEW "Preview"
26
#endif
27
 
5520 leency 28
/* === DATA === */
29
 
30
proc_info Form;
31
 
7221 leency 32
dword screenshot,
7220 leency 33
      preview;
5520 leency 34
 
7221 leency 35
int screenshot_length,
7220 leency 36
    preview_length;
5520 leency 37
 
7220 leency 38
enum {
39
	BTN_MAKE_SCREENSHOT=10,
7224 leency 40
	BTN_SAVE,
41
	BTN_SETTINGS
7220 leency 42
};
5520 leency 43
 
7224 leency 44
#define PD 18 //padding
45
#define TOOLBAR_H 20+PD
7220 leency 46
 
7228 leency 47
block pw;
7224 leency 48
 
49
struct _settings {
50
	bool minimise;
51
	int delay;
52
	char save_path[4096];
53
} settings = { true, 1, "/tmp0/1" };
54
 
5520 leency 55
/* === CODE === */
56
 
57
void main()
58
{
59
	char id;
7221 leency 60
 
7224 leency 61
	load_dll(libio,  #libio_init,  1);
7221 leency 62
	load_dll(libimg, #libimg_init, 1);
7224 leency 63
	load_dll(boxlib, #box_lib_init,0);
7221 leency 64
 
7224 leency 65
	Libimg_LoadImage(#skin, "/sys/icons16.png");
66
 
7221 leency 67
	screenshot_length = screen.width * screen.height * 3;
7224 leency 68
	pw.set_size(PD, TOOLBAR_H+PD, screen.width/2, screen.height/2);
7221 leency 69
	preview_length = screenshot_length / 2;
5520 leency 70
 
7221 leency 71
	screenshot  = malloc(screenshot_length);
72
	preview = malloc(screenshot_length/2);
5520 leency 73
 
7220 leency 74
	loop() switch(WaitEvent())
5520 leency 75
	{
7220 leency 76
	case evButton:
77
		id = GetButtonID();
78
		if (id == CLOSE_BTN) ExitProcess();
79
		if (id == BTN_MAKE_SCREENSHOT) EventTakeScreenshot();
7224 leency 80
		if (id == BTN_SAVE) EventSaveImageFile();
81
		if (id == BTN_SETTINGS) EventShowSettings();
7220 leency 82
		break;
83
 
84
	case evKey:
85
		GetKeys();
7224 leency 86
		if (SCAN_CODE_KEY_S == key_scancode) EventSaveImageFile();
7220 leency 87
		if (SCAN_CODE_ENTER == key_scancode) EventTakeScreenshot();
88
		break;
89
 
90
	case evReDraw:
7224 leency 91
		DefineAndDrawWindow(screen.width/4, screen.height/4, pw.w + 9 +PD+PD,
92
			pw.h + skin_height + TOOLBAR_H + 4 +PD+PD, 0x74, 0, T_WTITLE,0);
7220 leency 93
		GetProcessInfo(#Form, SelfInfo);
94
		if (Form.status_window>2) break;
7224 leency 95
		system.color.get();
96
		DrawMainContent();
7220 leency 97
	}
5520 leency 98
}
99
 
7224 leency 100
void DrawMainContent()
101
{
102
	int take_scr_btn_width;
103
	DrawBar(0, 0, Form.cwidth, TOOLBAR_H, system.color.work);
104
	DrawWideRectangle(0, TOOLBAR_H, pw.w+PD+PD, pw.h+PD+PD, PD-1, system.color.work);
105
	DrawRectangle(pw.x-1, pw.y-1, pw.w+1, pw.h+1, system.color.work_graph);
106
	take_scr_btn_width = DrawIconButton(pw.x, pw.y-42, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT, 44);
107
	if (ESDWORD[preview]==0) {
108
		DrawBar(pw.x, pw.y, pw.w, pw.h, 0xEEEeee);
109
		WriteText(Form.cwidth-calc(strlen(T_PREVIEW)*8)/2, pw.h/2+pw.y, 0x90, 0x777777, T_PREVIEW);
110
	}
111
	else {
112
		_PutImage(pw.x, pw.y, pw.w, pw.h, preview);
113
		DrawIconButton(take_scr_btn_width + pw.x, pw.y-42, BTN_SAVE, T_SAVE, 5);
114
	}
115
	DrawIconButton(Form.cwidth-40-PD, pw.y-42, BTN_SETTINGS, " ", 10);
116
}
117
 
7220 leency 118
void EventTakeScreenshot() {
7224 leency 119
	if (settings.minimise) MinimizeWindow();
120
	pause(settings.delay*100);
7221 leency 121
	CopyScreen(screenshot, 0, 0, screen.width, screen.height);
5520 leency 122
	ZoomImageTo50percent();
123
	ActivateWindow(GetProcessSlot(Form.ID));
7224 leency 124
	if (!settings.minimise) DrawMainContent();
5520 leency 125
}
126
 
7224 leency 127
void EventSaveImageFile()
7220 leency 128
{
7221 leency 129
	int i=0;
130
	char save_file_name[4096];
131
	do {
132
		i++;
7224 leency 133
		sprintf(#save_file_name, "%s/screen_%i.png", #settings.save_path, i);
7221 leency 134
	} while (file_exists(#save_file_name));
7224 leency 135
	save_image(screenshot, screen.width, screen.height, #save_file_name);
7220 leency 136
}
137
 
7224 leency 138
void EventShowSettings()
7220 leency 139
{
7224 leency 140
	CreateThread(#SettingsWindow,#settings_stak+4092);
141
}
7220 leency 142
 
7224 leency 143
char path_tmp[4096];
144
dword mouse_dd1;
145
edit_box edit_box_path = {270,10,70,0xffffff,0x94AECE,0xFFFfff,0xffffff,0x10000000,sizeof(path_tmp),#path_tmp,#mouse_dd1, 0b};
7220 leency 146
 
7224 leency 147
void SettingsWindow()
148
{
149
	#define x 15
150
	int id;
151
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
152
	loop() switch(WaitEvent())
153
	{
154
	case evMouse:
155
		//edit_box_mouse stdcall (#address_box);
156
		break;
7220 leency 157
 
7224 leency 158
	case evKey:
159
		GetKeys();
160
		if (SCAN_CODE_ESC == key_scancode) ExitProcess();
161
		break;
7220 leency 162
 
7224 leency 163
	case evButton:
164
		id = GetButtonID();
165
		if (CLOSE_BTN == id) ExitProcess();
166
		if (10 == id) settings.delay++;
167
		if (11 == id) && (settings.delay>0) settings.delay--;
168
		if (12 == id) settings.minimise ^= 1;
169
		goto _DRAW_CONTENT;
170
		break;
171
 
172
	case evReDraw:
173
		DefineAndDrawWindow(Form.left+100, Form.top-40, 330, 170, 0x34, system.color.work, "Settings",0);
174
		_DRAW_CONTENT:
175
		CheckBox(x, 10, 12, "Minimize window", settings.minimise);
176
		MoreLessBox(x, 40, 10, 11, settings.delay, "Delay in seconds");
177
		//DrawEditBox(#edit_box_path);
7220 leency 178
	}
179
}
180
 
7221 leency 181
inline byte calc_rgb(dword B, item_h)
182
{
183
	return calc(ESBYTE[B+3] + ESBYTE[B] + ESBYTE[B-3]
184
		+ ESBYTE[B-item_h] + ESBYTE[B+item_h] / 5);
185
}
186
 
5520 leency 187
void ZoomImageTo50percent() {
7221 leency 188
	dword point_x = 0;
189
	dword item_h = screen.width * 3;
190
	dword small = preview;
191
	dword big = screenshot;
5520 leency 192
 
7221 leency 193
	while( (small <= preview + preview_length) && (big <= screenshot + screenshot_length ) ) {
5520 leency 194
 
7221 leency 195
		if (big <= screenshot + item_h) || (big >= screenshot + screenshot_length - item_h)
5520 leency 196
		{
7221 leency 197
			ESBYTE[small]   = ESBYTE[big];
198
			ESBYTE[small+1] = ESBYTE[big+1];
199
			ESBYTE[small+2] = ESBYTE[big+2];
5520 leency 200
		}
201
		else
202
		{
7221 leency 203
			ESBYTE[small]   = calc_rgb(big, item_h);
204
			ESBYTE[small+1] = calc_rgb(big+1, item_h);
205
			ESBYTE[small+2] = calc_rgb(big+2, item_h);
5520 leency 206
		}
207
 
7221 leency 208
		small+=3;
209
		big+=6;
5520 leency 210
 
211
		point_x+=2;
7220 leency 212
		if (point_x >= screen.width)
5520 leency 213
		{
7221 leency 214
			big += item_h;
5520 leency 215
			point_x = 0;
216
		}
217
	}
218
}
219
 
7224 leency 220
int DrawIconButton(dword x, y, id, text, icon)
221
{
222
	int btwidth;
223
	system.color.work_button = 0xFFFfff;
224
	system.color.work_button_text = 0;
225
	btwidth = DrawStandartCaptButton(x, y, id, text);
226
	img_draw stdcall(skin.image, x+12, y+5, 16, 16, 0, icon*16);
227
	system.color.get();
228
	return btwidth;
229
}
5520 leency 230
 
7224 leency 231
stop:
7221 leency 232
 
7224 leency 233
char settings_stak[4096];