Subversion Repositories Kolibri OS

Rev

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