Subversion Repositories Kolibri OS

Rev

Rev 7220 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7220 Rev 7221
Line -... Line 1...
-
 
1
// TODO
-
 
2
// Settings: delay, savepath
-
 
3
// Icons and better UI
-
 
4
 
1
#define MEMSIZE 1024 * 420
5
#define MEMSIZE 1024 * 20
2
#include "../lib/kolibri.h" 
6
#include "../lib/kolibri.h" 
3
#include "../lib/strings.h" 
7
#include "../lib/strings.h" 
4
#include "../lib/mem.h" 
8
#include "../lib/mem.h" 
5
#include "../lib/gui.h" 
9
#include "../lib/gui.h" 
Line 8... Line 12...
8
 
12
 
9
#ifndef AUTOBUILD
13
#ifndef AUTOBUILD
10
	#include "lang.h--"
14
	#include "lang.h--"
Line -... Line 15...
-
 
15
#endif
-
 
16
 
-
 
17
/* === TRANSLATIONS === */
-
 
18
 
-
 
19
#ifdef LANG_RUS
-
 
20
	?define T_TAKE_SCREENSHOT "‘¤¥« âì áªà¨­è®â"
-
 
21
	?define T_SAVE "‘®åà ­¨âì"
-
 
22
	?define T_PREVIEW "à¥¤¯à®á¬®âà"
-
 
23
#else
-
 
24
	?define T_TAKE_SCREENSHOT "Take a screenshot"
-
 
25
	?define T_SAVE "Save"
-
 
26
	?define T_PREVIEW "Preview"
11
#endif
27
#endif
Line 12... Line 28...
12
 
28
 
Line 13... Line 29...
13
/* === DATA === */
29
/* === DATA === */
14
 
30
 
Line 15... Line 31...
15
proc_info Form;
31
proc_info Form;
16
 
32
 
17
dword b_screen,
33
dword screenshot,
18
      preview;
34
      preview;
Line 19... Line 35...
19
 
35
 
20
int b_screen_length,
36
int screenshot_length,
21
    preview_width,
37
    preview_width,
22
    preview_height,
38
    preview_height,
Line 23... Line 39...
23
    preview_length;
39
    preview_length;
Line 24... Line 40...
24
 
40
 
Line 25... Line 41...
25
enum {
41
enum {
26
	BTN_MAKE_SCREENSHOT=10,
42
	BTN_MAKE_SCREENSHOT=10,
27
	BTN_SAVE
43
	BTN_SAVE
-
 
44
};
-
 
45
 
-
 
46
#define TOOLBAR_H 46;
-
 
47
 
28
};
48
/* === CODE === */
29
 
49
 
30
#define TOOLBAR_H 50;
50
 
31
 
51
void main()
Line 32... Line 52...
32
/* === CODE === */
52
{	
33
 
53
	char id;
Line 34... Line 54...
34
 
54
	int take_scr_btn_width;
35
void main()
55
 
36
{	
56
	load_dll(libimg, #libimg_init, 1);
37
	char id;
57
 
Line 59... Line 79...
59
		break;
79
		break;
Line 60... Line 80...
60
     
80
     
61
	case evReDraw:
81
	case evReDraw:
62
		system.color.get();
82
		system.color.get();
63
		DefineAndDrawWindow(screen.width/4, screen.height/4, 
83
		DefineAndDrawWindow(screen.width/4, screen.height/4, 
64
			preview_width + 9, preview_height + skin_height + TOOLBAR_H,
84
			preview_width + 9, preview_height + skin_height + TOOLBAR_H + 4,
65
			0x74, 0, "EasyShot v0.3",0);
85
			0x74, 0, "EasyShot v0.5",0);
66
		GetProcessInfo(#Form, SelfInfo);
86
		GetProcessInfo(#Form, SelfInfo);
67
		if (Form.status_window>2) break;
87
		if (Form.status_window>2) break;
68
		DrawBar(0, 0, Form.cwidth, TOOLBAR_H-4, system.color.work);
88
		DrawBar(0, 0, Form.cwidth, TOOLBAR_H, system.color.work);
69
		DrawStandartCaptButton(10, 10, BTN_MAKE_SCREENSHOT, "Take a screenshot");
-
 
70
		_PutImage(0, Form.cheight - preview_height,  preview_width, preview_height, preview);
89
		take_scr_btn_width = DrawStandartCaptButton(10, 10, BTN_MAKE_SCREENSHOT, T_TAKE_SCREENSHOT);
-
 
90
		if (ESDWORD[preview]==0) {
71
		if (ESDWORD[preview]==0) {
91
			DrawBar(0, TOOLBAR_H,  preview_width, preview_height, 0xEEEeee);
72
			WriteTextB(Form.cwidth/2 - 90, Form.cheight/2+10, 0x90, 0xFFFfff, "There will be a preview");
92
			WriteText(Form.cwidth-calc(strlen(T_PREVIEW)*8)/2, Form.cheight/2, 0x90, 0x777777, T_PREVIEW);
73
		}
93
		}
-
 
94
		else {
74
		else {
95
			_PutImage(0, TOOLBAR_H,  preview_width, preview_height, preview);
75
			DrawStandartCaptButton(200, 10, BTN_SAVE, "Save");
96
			DrawStandartCaptButton(take_scr_btn_width + 10, 10, BTN_SAVE, T_SAVE);
76
		}
97
		}
77
	}
98
	}
Line 78... Line 99...
78
}
99
}
79
 
100
 
80
void EventTakeScreenshot() {
101
void EventTakeScreenshot() {
81
	MinimizeWindow();
102
	MinimizeWindow();
82
	pause(100);
103
	pause(100);
83
	CopyScreen(b_screen, 0, 0, screen.width, screen.height);
104
	CopyScreen(screenshot, 0, 0, screen.width, screen.height);
84
	ZoomImageTo50percent();
-
 
85
	ActivateWindow(GetProcessSlot(Form.ID));
105
	ZoomImageTo50percent();
Line 86... Line 106...
86
	//_PutImage(0, Form.cheight - preview_height,  preview_width, preview_height, preview);
106
	ActivateWindow(GetProcessSlot(Form.ID));
87
}
107
}
-
 
108
 
-
 
109
void EventSaveFile()
-
 
110
{
-
 
111
	int i=0;
-
 
112
	char save_file_name[4096];
-
 
113
	do {
88
 
114
		i++;
89
void EventSaveFile()
115
		sprintf(#save_file_name, "/tmp0/1/screen_%i.png", i);
Line 90... Line 116...
90
{
116
	} while (file_exists(#save_file_name));
91
	SaveFile(b_screen, screen.width, screen.height, "/tmp0/1/screen.png");
117
	SaveFile(screenshot, screen.width, screen.height, #save_file_name);
-
 
118
}
92
}
119
 
93
 
120
void SaveFile(dword _image, _w, _h, _path)
94
void SaveFile(dword _image, _w, _h, _path)
121
{
Line 95... Line 122...
95
{
122
	char save_success_message[4096+200];
Line 113... Line 140...
113
		if(encoded_data == 0) {
140
		if(encoded_data == 0) {
114
			notify("'Error saving file, incorrect data!' -E");
141
			notify("'Error saving file, incorrect data!' -E");
115
		}
142
		}
116
		else {
143
		else {
117
			if (WriteFile(encoded_size, encoded_data, _path) == 0) {
144
			if (WriteFile(encoded_size, encoded_data, _path) == 0) {
-
 
145
				sprintf(#save_success_message, "'File saved as %s' -O", _path);
118
				notify("'File saved as /rd/1/saved_image.png' -O");
146
				notify(#save_success_message);
119
			}
147
			}
120
			else {
148
			else {
121
				notify("'Error saving file, probably not enought space on ramdisk!' -E");
149
				notify("'Error saving file! Probably not enought space or file system is not writable!' -E");
122
			}
150
			}
123
		}
151
		}
124
	}
152
	}
125
}
153
}
Line -... Line 154...
-
 
154
 
-
 
155
inline byte calc_rgb(dword B, item_h)
-
 
156
{
-
 
157
	return calc(ESBYTE[B+3] + ESBYTE[B] + ESBYTE[B-3]
-
 
158
		+ ESBYTE[B-item_h] + ESBYTE[B+item_h] / 5);
-
 
159
}
126
 
160
 
127
void ZoomImageTo50percent() {
161
void ZoomImageTo50percent() {
128
	dword point_x,
162
	dword point_x = 0;
129
	      item_h= screen.width * 3,
163
	dword item_h = screen.width * 3;
130
	      s_off = preview + 3,
164
	dword small = preview;
131
	      b_off = b_screen + 6,
-
 
132
	      b_off_r,
-
 
133
	      b_off_g,
-
 
134
	      b_off_b,
-
 
135
	      rez_r, 
-
 
136
	      rez_g, 
-
 
137
	      rez_b;
165
	dword big = screenshot;
138
 
166
 
139
	while( (s_off <= preview + preview_length) && (b_off <= b_screen + b_screen_length ) ) {
167
	while( (small <= preview + preview_length) && (big <= screenshot + screenshot_length ) ) {
140
		
168
		
141
		if (b_off <= b_screen + item_h) || (b_off >= b_screen + b_screen_length - item_h)
169
		if (big <= screenshot + item_h) || (big >= screenshot + screenshot_length - item_h)
142
		{
170
		{
143
			ESBYTE[s_off]   = ESBYTE[b_off];
171
			ESBYTE[small]   = ESBYTE[big];
144
			ESBYTE[s_off+1] = ESBYTE[b_off+1];
172
			ESBYTE[small+1] = ESBYTE[big+1];
145
			ESBYTE[s_off+2] = ESBYTE[b_off+2];
173
			ESBYTE[small+2] = ESBYTE[big+2];
146
		}
174
		}
147
		else
175
		else
148
		{
-
 
149
			// line[x].R = (line[x+1].R + line[x].R + line[x-1].R + line1[x].R + line2[x].R) / 5;
-
 
150
			// line[x].G = (line[x+1].G + line[x].G + line[x-1].G + line1[x].G + line2[x].G) / 5;
-
 
151
			// line[x].B = (line[x+1].B + line[x].B + line[x-1].B + line1[x].B + line2[x].B) / 5
-
 
152
			b_off_r = b_off;
-
 
153
			b_off_g = b_off + 1;
-
 
154
			b_off_b = b_off + 2;
-
 
155
			rez_r = ESBYTE[b_off_r+3] + ESBYTE[b_off_r] + ESBYTE[b_off_r-3] + ESBYTE[b_off_r-item_h] + ESBYTE[b_off_r+item_h] / 5;
-
 
156
			rez_g = ESBYTE[b_off_g+3] + ESBYTE[b_off_g] + ESBYTE[b_off_g-3] + ESBYTE[b_off_g-item_h] + ESBYTE[b_off_g+item_h] / 5;
-
 
157
			rez_b = ESBYTE[b_off_b+3] + ESBYTE[b_off_b] + ESBYTE[b_off_b-3] + ESBYTE[b_off_b-item_h] + ESBYTE[b_off_b+item_h] / 5;
176
		{
158
			ESBYTE[s_off] = rez_r;
177
			ESBYTE[small]   = calc_rgb(big, item_h);
159
			ESBYTE[s_off+1] = rez_g;
178
			ESBYTE[small+1] = calc_rgb(big+1, item_h);
160
			ESBYTE[s_off+2] = rez_b;
-
 
161
 
179
			ESBYTE[small+2] = calc_rgb(big+2, item_h);
Line 162... Line 180...
162
		}
180
		}
163
	
181
	
Line 164... Line 182...
164
		s_off+=3;
182
		small+=3;
165
		b_off+=6;
183
		big+=6;
166
 
184
 
167
		point_x+=2;
185
		point_x+=2;
168
		if (point_x >= screen.width) 
186
		if (point_x >= screen.width) 
169
		{
187
		{
170
			b_off += item_h;
188
			big += item_h;
171
			point_x = 0;
189
			point_x = 0;
Line -... Line 190...
-
 
190
		}
172
		}
191
	}