Subversion Repositories Kolibri OS

Rev

Rev 8752 | Rev 9015 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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