Subversion Repositories Kolibri OS

Rev

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

Rev 8381 Rev 8389
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
 
-
 
7
#include "../lib/obj/libio.h"
6
 
8
#include "../lib/obj/libimg.h"
7
#include "../lib/obj/libimg.h"
9
#include "../lib/obj/box_lib.h"
8
#include "../lib/obj/box_lib.h"
10
#include "../lib/obj/proc_lib.h"
9
#include "../lib/obj/proc_lib.h"
11
 
10
 
12
#ifndef AUTOBUILD
11
#ifndef AUTOBUILD
13
	#include "lang.h--"
12
	#include "lang.h--"
14
#endif
13
#endif
15
 
14
 
16
/* === TRANSLATIONS === */
15
/* === TRANSLATIONS === */
17
 
16
 
18
#ifdef LANG_RUS
17
#ifdef LANG_RUS
19
	?define T_TAKE_SCREENSHOT "‘¤¥« âì áªà¨­è®â"
18
	?define T_TAKE_SCREENSHOT "‘¤¥« âì áªà¨­è®â"
20
	?define T_SETTINGS " áâனª¨"
19
	?define T_SETTINGS " áâனª¨"
21
	?define T_EDITBOX_FRAME "ãâì á®åà ­¥­¨ï áªà¨­è®â "
20
	?define T_EDITBOX_FRAME "ãâì á®åà ­¥­¨ï áªà¨­è®â "
22
	?define T_DELAY "‡ ¤¥à¦ª  ¢ ᥪ㭤 å"
21
	?define T_DELAY "‡ ¤¥à¦ª  ¢ ᥪ㭤 å"
23
	?define T_NO_DIR "' ¯ª  ­¥ áãé¥áâ¢ã¥â!' -E"
22
	?define T_NO_DIR "' ¯ª  ­¥ áãé¥áâ¢ã¥â!' -E"
24
#else
23
#else
25
	?define T_TAKE_SCREENSHOT "Take a screenshot"
24
	?define T_TAKE_SCREENSHOT "Take a screenshot"
26
	?define T_SETTINGS "Settings"
25
	?define T_SETTINGS "Settings"
27
	?define T_EDITBOX_FRAME "Save path"
26
	?define T_EDITBOX_FRAME "Save path"
28
	?define T_DELAY "Delay in seconds"
27
	?define T_DELAY "Delay in seconds"
29
	?define T_NO_DIR "'Directory does not exists!' -E"
28
	?define T_NO_DIR "'Directory does not exists!' -E"
30
#endif
29
#endif
31
 
30
 
32
/* === DATA === */	
31
/* === DATA === */	
33
 
32
 
34
proc_info Form;
33
proc_info Form;
35
 
34
 
36
enum {
35
enum {
37
	BTN_MAKE_SCREENSHOT=10,
36
	BTN_MAKE_SCREENSHOT=10,
38
	BTN_SETTINGS,
37
	BTN_SETTINGS,
39
	BTN_CHOOSE_SAVING_PATH
38
	BTN_CHOOSE_SAVING_PATH
40
};
39
};
41
 
40
 
42
#define PD 18 //padding
41
#define PD 18 //padding
43
#define SETTINGS_Y PD+PD+30+10
42
#define SETTINGS_Y PD+PD+30+10
44
 
43
 
45
char save_path[4096];
44
char save_path[4096];
46
char open_dir[4096];
45
char open_dir[4096];
47
 
46
 
48
more_less_box delay = { 1, 0, SETTINGS_Y, T_DELAY };
47
more_less_box delay = { 1, 0, SETTINGS_Y, T_DELAY };
49
edit_box edit_save = {260,PD,SETTINGS_Y+50,0xffffff,0x94AECE,0xFFFfff,0xffffff,
48
edit_box edit_save = {260,PD,SETTINGS_Y+50,0xffffff,0x94AECE,0xFFFfff,0xffffff,
50
	0x10000000,sizeof(save_path)-2,#save_path,0, 0b};
49
	0x10000000,sizeof(save_path)-2,#save_path,0, 0b};
51
 
50
 
52
bool show_settings = false;
51
bool show_settings = false;
53
 
52
 
54
opendialog open_folder_dialog = 
53
opendialog open_folder_dialog = 
55
{
54
{
56
  2, //0-file, 2-save, 3-select folder
55
  2, //0-file, 2-save, 3-select folder
57
  #Form,
56
  #Form,
58
  #communication_area_name,
57
  #communication_area_name,
59
  0,
58
  0,
60
  0, //dword opendir_path,
59
  0, //dword opendir_path,
61
  #open_dir, //dword dir_default_path,
60
  #open_dir, //dword dir_default_path,
62
  #open_dialog_path,
61
  #open_dialog_path,
63
  #DrawWindow,
62
  #DrawWindow,
64
  0,
63
  0,
65
  #open_dir, //dword openfile_path,
64
  #open_dir, //dword openfile_path,
66
  0, //dword filename_area,
65
  0, //dword filename_area,
67
  0, //dword filter_area,
66
  0, //dword filter_area,
68
  420,
67
  420,
69
  NULL,
68
  NULL,
70
  320,
69
  320,
71
  NULL
70
  NULL
72
};
71
};
73
 
72
 
74
/* === CODE === */
73
/* === CODE === */
75
 
74
 
76
void init_libraries()
75
void init_libraries()
77
{
76
{
78
	load_dll(libio,  #libio_init,  1);
-
 
79
	load_dll(libimg, #libimg_init, 1);
77
	load_dll(libimg, #libimg_init, 1);
80
	load_dll(boxlib, #box_lib_init,0);
78
	load_dll(boxlib, #box_lib_init,0);
81
	load_dll(Proc_lib,  #OpenDialog_init,0);
79
	load_dll(Proc_lib,  #OpenDialog_init,0);
82
	OpenDialog_init stdcall (#open_folder_dialog);	
80
	OpenDialog_init stdcall (#open_folder_dialog);	
83
}
81
}
84
 
82
 
85
void main()
83
void main()
86
{	
84
{	
87
	int id;
85
	int id;
88
 
86
 
89
	init_libraries();
87
	init_libraries();
90
 
88
 
91
	strcpy(#save_path, "/tmp0/1");
89
	strcpy(#save_path, "/tmp0/1");
92
	EditBox_UpdateText(#edit_save, 0);
90
	EditBox_UpdateText(#edit_save, 0);
93
 
91
 
94
	@SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
92
	@SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
95
	loop() switch(@WaitEvent())
93
	loop() switch(@WaitEvent())
96
	{
94
	{
97
	case evMouse:
95
	case evMouse:
98
		edit_box_mouse stdcall (#edit_save);
96
		edit_box_mouse stdcall (#edit_save);
99
		break;
97
		break;
100
 
98
 
101
	case evButton:
99
	case evButton:
102
		id = @GetButtonID();
100
		id = @GetButtonID();
103
		switch(id){
101
		switch(id){
104
			case CLOSE_BTN: ExitProcess();
102
			case CLOSE_BTN: ExitProcess();
105
			case BTN_MAKE_SCREENSHOT: EventTakeScreenshot(); break;
103
			case BTN_MAKE_SCREENSHOT: EventTakeScreenshot(); break;
106
			case BTN_SETTINGS: EventClickSettings(); break;
104
			case BTN_SETTINGS: EventClickSettings(); break;
107
			case BTN_CHOOSE_SAVING_PATH: EventChooseSavePath(); break;
105
			case BTN_CHOOSE_SAVING_PATH: EventChooseSavePath(); break;
108
			default: delay.click(id);
106
			default: delay.click(id);
109
		}
107
		}
110
		break;
108
		break;
111
 
109
 
112
	case evKey:
110
	case evKey:
113
		GetKey();
111
		GetKey();
114
		edit_box_key stdcall (#edit_save);
112
		edit_box_key stdcall (#edit_save);
115
		EAX >>= 16;
113
		EAX >>= 16;
116
		if (SCAN_CODE_ENTER == AL) EventTakeScreenshot();
114
		if (SCAN_CODE_ENTER == AL) EventTakeScreenshot();
117
		if (SCAN_CODE_ESC == AL) ExitProcess();
115
		if (SCAN_CODE_ESC == AL) ExitProcess();
118
		break;
116
		break;
119
     
117
     
120
	case evReDraw:
118
	case evReDraw:
121
		DrawWindow();
119
		DrawWindow();
122
	}
120
	}
123
}
121
}
124
 
122
 
125
 
123
 
126
void DrawWindow()
124
void DrawWindow()
127
{
125
{
128
	int i;
126
	int i;
129
 
127
 
130
	sc.get();
128
	sc.get();
131
	DefineAndDrawWindow(screen.width-400, screen.height/3, 270, 
129
	DefineAndDrawWindow(screen.width-400, screen.height/3, 270, 
132
		skin_height + 30+PD+PD, 0x34, sc.work, "EasyShot",0);
130
		skin_height + 30+PD+PD, 0x34, sc.work, "EasyShot",0);
133
	GetProcessInfo(#Form, SelfInfo);
131
	GetProcessInfo(#Form, SelfInfo);
134
 
132
 
135
	DrawCaptButton(PD, PD, 170, 28, BTN_MAKE_SCREENSHOT, 0x0090B8, 0xFFFfff, T_TAKE_SCREENSHOT);
133
	DrawCaptButton(PD, PD, 170, 28, BTN_MAKE_SCREENSHOT, 0x0090B8, 0xFFFfff, T_TAKE_SCREENSHOT);
136
	DefineButton(PD+170+20, PD, 35, 28, BTN_SETTINGS, sc.button);
134
	DefineButton(PD+170+20, PD, 35, 28, BTN_SETTINGS, sc.button);
137
	for (i=0; i<=2; i++) DrawBar(PD+170+30, i*5+PD+9, 15, 2, sc.button_text);
135
	for (i=0; i<=2; i++) DrawBar(PD+170+30, i*5+PD+9, 15, 2, sc.button_text);
138
	delay.draw(PD, SETTINGS_Y);
136
	delay.draw(PD, SETTINGS_Y);
139
	DrawFileBox(#edit_save, T_EDITBOX_FRAME, BTN_CHOOSE_SAVING_PATH);	
137
	DrawFileBox(#edit_save, T_EDITBOX_FRAME, BTN_CHOOSE_SAVING_PATH);	
140
}
138
}
141
 
139
 
142
 
140
 
143
void EventChooseSavePath()
141
void EventChooseSavePath()
144
{
142
{
145
	OpenDialog_start stdcall (#open_folder_dialog);
143
	OpenDialog_start stdcall (#open_folder_dialog);
146
	if (open_folder_dialog.status) {
144
	if (open_folder_dialog.status) {
147
		strcpy(#save_path, open_folder_dialog.opendir_path);
145
		strcpy(#save_path, open_folder_dialog.opendir_path);
148
		EditBox_UpdateText(#edit_save, 0);		
146
		EditBox_UpdateText(#edit_save, 0);		
149
	}
147
	}
150
}
148
}
151
 
149
 
152
 
150
 
153
void EventClickSettings()
151
void EventClickSettings()
154
{
152
{
155
	show_settings ^= 1;
153
	show_settings ^= 1;
156
	MoveSize(OLD, OLD, show_settings*75 + 270, 
154
	MoveSize(OLD, OLD, show_settings*75 + 270, 
157
		show_settings*110 + skin_height + PD+PD+30);
155
		show_settings*110 + skin_height + PD+PD+30);
158
}
156
}
159
 
157
 
160
 
158
 
161
void EventTakeScreenshot() 
159
void EventTakeScreenshot() 
162
{
160
{
163
	int i=0;
161
	int i=0;
164
	char save_file_name[4096];
162
	char save_file_name[4096];
165
	static dword screenshot;
163
	static dword screenshot;
166
 
164
 
167
	if (!screenshot) screenshot = malloc(screen.width * screen.height * 3);
165
	if (!screenshot) screenshot = malloc(screen.width * screen.height * 3);
168
 
166
 
169
	do {
167
	do {
170
		i++;
168
		i++;
171
		//sprintf(, "%s/screen_%i.png", #save_path, i);
169
		//sprintf(, "%s/screen_%i.png", #save_path, i);
172
		strcpy(#save_file_name, #save_path);
170
		strcpy(#save_file_name, #save_path);
173
		if (save_file_name[strlen(#save_file_name)-1]!='/') chrcat(#save_file_name, '/');
171
		if (save_file_name[strlen(#save_file_name)-1]!='/') chrcat(#save_file_name, '/');
174
		strcat(#save_file_name, "screen_");
172
		strcat(#save_file_name, "screen_");
175
		strcat(#save_file_name, itoa(i));
173
		strcat(#save_file_name, itoa(i));
176
		strcat(#save_file_name, ".png");
174
		strcat(#save_file_name, ".png");
177
	} while (file_exists(#save_file_name));
175
	} while (file_exists(#save_file_name));
178
 
176
 
179
	if (!dir_exists(#save_path)) {
177
	if (!dir_exists(#save_path)) {
180
		notify(T_NO_DIR);
178
		notify(T_NO_DIR);
181
		return;
179
		return;
182
	}
180
	}
183
 
181
 
184
	MinimizeWindow(); 
182
	MinimizeWindow(); 
185
	pause(delay.value*100);
183
	pause(delay.value*100);
186
	CopyScreen(screenshot, 0, 0, screen.width, screen.height);
184
	CopyScreen(screenshot, 0, 0, screen.width, screen.height);
187
	save_image(screenshot, screen.width, screen.height, #save_file_name);
185
	save_image(screenshot, screen.width, screen.height, #save_file_name);
188
	ActivateWindow(GetProcessSlot(Form.ID));
186
	ActivateWindow(GetProcessSlot(Form.ID));
189
}
187
}