Subversion Repositories Kolibri OS

Rev

Rev 7243 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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