Subversion Repositories Kolibri OS

Rev

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