Subversion Repositories Kolibri OS

Rev

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

Rev 9585 Rev 9597
Line 19... Line 19...
19
//                                                   //
19
//                                                   //
20
//                       DATA                        //
20
//                       DATA                        //
21
//                                                   //
21
//                                                   //
22
//===================================================//
22
//===================================================//
Line 23... Line 23...
23
 
23
 
24
#define PAD 12
24
#define PAD 13
25
#define TOOLBAR_ITEM_H PAD+PAD
25
#define TOOLBAR_ITEM_H PAD+PAD
-
 
26
#define TOOLBAR_W 132
26
#define TOOLBAR_W 110
27
#define STATUSBAR_H 20
Line 27... Line 28...
27
#define ISIZE 18
28
#define ISIZE 18
Line 28... Line 29...
28
 
29
 
29
block canvas = { TOOLBAR_W + PAD + PAD, 0, NULL, NULL };
30
block canvas = { TOOLBAR_W + PAD + PAD, 0, NULL, NULL };
Line 30... Line 31...
30
 
31
 
31
EVENTS button;
32
EVENTS button;
32
EVENTS key;
-
 
Line 33... Line 33...
33
 
33
EVENTS key;
34
proc_info Form;
34
 
Line 35... Line 35...
35
dword semi_white;
35
proc_info Form;
36
bool bg_dark=false;
36
dword semi_white;
Line 37... Line 37...
37
 
37
 
Line 38... Line 38...
38
char default_dir[4096] = "/sys";
38
char default_dir[4096] = "/sys";
39
od_filter filter2 = { 69, "BMP\0GIF\0ICO\0CUR\0JPEG\0JPG\0PNG\0PNM\0TGA\0TIFF\0TIF\0WBMP\0XBM\0XCF\Z80\0\0" };
39
od_filter filter2 = { 69, "BMP\0GIF\0ICO\0CUR\0JPEG\0JPG\0PNG\0PNM\0TGA\0TIFF\0TIF\0WBMP\0XBM\0XCF\Z80\0\0" };
Line 40... Line -...
40
 
-
 
-
 
40
 
41
libimg_image icons18;
41
libimg_image icons18;
42
libimg_image main_image;
42
libimg_image main_image;
43
 
43
 
44
char win_title[256] = "ImageEdit";
44
char win_title[256] = "ImageEdit";
-
 
45
 
-
 
46
scroll_bar scroll_v = { 15,NULL,NULL,NULL,15,2,NULL,0,0,0xeeeeee,0xBBDDFF,0xeeeeee};
-
 
47
scroll_bar scroll_h = { NULL,NULL,15,NULL,15,2,NULL,0,0,0xeeeeee,0xBBDDFF,0xeeeeee};
-
 
48
 
45
 
49
enum { SAVE_AS_PNG=1, SAVE_AS_BMP=2, SAVE_AS_RAW=4 };
46
scroll_bar scroll_v = { 15,NULL,NULL,NULL,15,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
50
int saving_type=SAVE_AS_PNG;
47
scroll_bar scroll_h = { NULL,NULL,15,NULL,15,2,NULL,0,0,0xeeeeee,0xBBBbbb,0xeeeeee};
-
 
48
 
51
 
49
/*
52
char* libimg_bpp[] = { "8pal", "24", "32", "15", "16",
Line 50... Line 53...
50
struct scroll_bar
53
"mono", "8gray", "2pal", "4pal", "8pal" };
51
{
54
 
52
	word size_x, start_x, size_y, start_y;
55
enum {
53
	dword btn_height, type, max_area, cur_area, position,
56
	TOOL_CROP=1, 
54
	bckg_col, frnt_col, line_col, redraw;
57
	TOOL_RESIZE=2,
Line 55... Line 58...
55
	word delta, delta2, r_size_x, r_start_x, r_size_y, r_start_y;
58
	TOOL_COLOR_DEPTH=4,
56
	dword m_pos, m_pos_2, m_keys, run_size, position2, work_size, all_redraw, ar_offset;
59
	TOOL_FLIP_ROTATE=8
57
};
60
};
58
*/
61
int active_tool = NULL;
59
 
-
 
60
//===================================================//
62
 
61
//                                                   //
63
//===================================================//
62
//                       CODE                        //
64
//                                                   //
63
//                                                   //
65
//                       CODE                        //
Line 90... Line 92...
90
		case evMouse:
92
		case evMouse:
91
			mouse.get();
93
			mouse.get();
92
			scrollbar_v_mouse stdcall(#scroll_v);
94
			scrollbar_v_mouse stdcall(#scroll_v);
93
			scrollbar_h_mouse stdcall(#scroll_h);
95
			scrollbar_h_mouse stdcall(#scroll_h);
94
			if (scroll_v.delta) || (scroll_h.delta) draw_canvas();
96
			if (scroll_v.delta) || (scroll_h.delta) draw_canvas();
-
 
97
			if (EAX = mouse.vert) {
-
 
98
				if (EAX<10) event_scroll_canvas(SCAN_CODE_DOWN); 
-
 
99
				else event_scroll_canvas(SCAN_CODE_UP);
-
 
100
			} if (EAX = mouse.hor) {
-
 
101
				debugval("mouse.hor", mouse.hor);
-
 
102
				if (EAX<10) event_scroll_canvas(SCAN_CODE_RIGHT); 
-
 
103
				else event_scroll_canvas(SCAN_CODE_LEFT);
-
 
104
			}
95
			break;
105
			break;
Line 96... Line 106...
96
 
106
 
97
		case evButton:
107
		case evButton:
98
			pressed_button_id = GetButtonID();
108
			pressed_button_id = GetButtonID();
99
			if (pressed_button_id==1) ExitProcess();
109
			if (pressed_button_id==1) ExitProcess();
100
			button.press(pressed_button_id);
110
			button.press(pressed_button_id);
Line 101... Line 111...
101
			break;
111
			break;
102
 
112
 
103
		case evKey:
113
		case evKey:
104
			GetKeys();
114
			GetKeys();
105
			if (key_scancode == SCAN_CODE_DOWN) {
-
 
106
				scroll_v.position = math.min(scroll_v.position+25, scroll_v.max_area - scroll_v.cur_area);
-
 
107
				draw_canvas();
115
			if (key_scancode == SCAN_CODE_DOWN) event_scroll_canvas(SCAN_CODE_DOWN);
108
			}
116
			if (key_scancode == SCAN_CODE_UP) event_scroll_canvas(SCAN_CODE_UP);
109
			if (key_scancode == SCAN_CODE_UP) {
117
			if (key_scancode == SCAN_CODE_LEFT) event_scroll_canvas(SCAN_CODE_LEFT);
110
				scroll_v.position = math.max(scroll_v.position-25, 0);
-
 
111
				draw_canvas();
118
			if (key_scancode == SCAN_CODE_RIGHT) event_scroll_canvas(SCAN_CODE_RIGHT);
Line 112... Line 119...
112
			}
119
			key.press(key_scancode);
113
			break;
120
			break;
114
 
121
 
Line 119... Line 126...
119
}
126
}
Line 120... Line 127...
120
 
127
 
121
void draw_window()
128
void draw_window()
122
{
129
{
-
 
130
	incn tx;
-
 
131
	char save_as_type[32];
-
 
132
	sc.get();
-
 
133
	Form.width = screen.w/6*5;
123
	incn tx;
134
	Form.height = screen.h/6*5;
124
	DefineAndDrawWindow(random(100)+40, 40+random(100), screen.width/3*2, screen.height/3*2, 0x73, NULL, #win_title, 0);
135
	DefineAndDrawWindow(screen.w-Form.width/2, screen.h-Form.height/2, Form.width, Form.height, 0x73, NULL, #win_title, 0);
125
	GetProcessInfo(#Form, SelfInfo);
136
	GetProcessInfo(#Form, SelfInfo);
126
	if (Form.status_window&ROLLED_UP) return;
137
	if (Form.status_window&ROLLED_UP) return;
127
	if (Form.width  < 560) { MoveSize(OLD,OLD,560,OLD); return; }
138
	if (Form.width  < 560) { MoveSize(OLD,OLD,560,OLD); return; }
128
	if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
139
	if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
129
	button.init(40);
140
	button.init(40);
Line 130... Line 141...
130
	key.init(40);
141
	key.init(40);
Line 131... Line 142...
131
 
142
 
132
	DrawBar(0, 0, canvas.x, Form.cheight, sc.work);
143
	DrawBar(0, 0, canvas.x, Form.cheight, sc.work);
133
 
144
 
134
	canvas.w = Form.cwidth - canvas.x;
145
	canvas.w = Form.cwidth - canvas.x;
Line 135... Line 146...
135
	canvas.h = Form.cheight;
146
	canvas.h = Form.cheight - STATUSBAR_H;
136
	if (main_image.h > canvas.h) canvas.w -= scroll_v.size_x + 1;
147
	if (main_image.h > canvas.h) canvas.w -= scroll_v.size_x + 1;
137
	if (main_image.w > canvas.w) canvas.h -= scroll_h.size_y + 1;
148
	if (main_image.w > canvas.w) canvas.h -= scroll_h.size_y + 1;
138
 
149
 
Line 139... Line 150...
139
	DrawBar(canvas.x, 0, 1, canvas.h, sc.work_graph);
150
	DrawBar(canvas.x, 0, 1, canvas.h, sc.work_text);
-
 
151
	if (main_image.h > canvas.h) && (main_image.w > canvas.w) {
-
 
152
		DrawBar(canvas.x+canvas.w, canvas.y+canvas.h, scroll_v.size_x+1, scroll_h.size_y+1, sc.work);
140
	if (main_image.h > canvas.h) && (main_image.w > canvas.w) {
153
	}
141
		DrawBar(canvas.x+canvas.w, canvas.y+canvas.h, scroll_v.size_x+1, scroll_h.size_y+1, sc.work);
154
 
-
 
155
	scroll_v.all_redraw = scroll_h.all_redraw = 1;
-
 
156
	if (skin_is_dark()) 
142
	}
157
	{
Line 143... Line 158...
143
 
158
		scroll_v.bckg_col = scroll_h.bckg_col = sc.work_light;
144
	scroll_v.all_redraw = scroll_h.all_redraw = 1;
159
		scroll_v.frnt_col = scroll_h.frnt_col = sc.button;
145
	scroll_v.bckg_col = scroll_h.bckg_col = MixColors(sc.work, 0xBBBbbb, 80);
160
		scroll_v.line_col = scroll_h.line_col = sc.button_text;
146
	scroll_v.frnt_col = scroll_h.frnt_col = MixColors(sc.work,0xFFFfff,120);
161
	}
147
	scroll_v.line_col = scroll_h.line_col = sc.work_graph;
162
	scroll_v.line_col = scroll_h.line_col = sc.work_text;		
148
 
163
 
149
	#define GAP_S 24+7
164
	#define GAP_S TOOLBAR_ITEM_H+8
150
	#define GAP_B 24+23
165
	#define GAP_B TOOLBAR_ITEM_H+23
151
	tx.set(PAD-GAP_S);
166
	tx.set(PAD-GAP_S);
152
	//draw_icon(10, ECTRL + SCAN_CODE_KEY_N, PAD, tx.inc(GAP_S), 02, "Create image");
167
	//draw_tool_btn(10, ECTRL + SCAN_CODE_KEY_N, PAD, tx.inc(GAP_S), 02, "Create image", false);
153
	draw_icon(#event_open, ECTRL + SCAN_CODE_KEY_O, PAD, tx.inc(GAP_S), 00, "Open image");
168
	draw_tool_btn(#event_open, ECTRL + SCAN_CODE_KEY_O, PAD, tx.inc(GAP_S), 00, "Open image", false);
154
	//draw_icon(13, ECTRL + SCAN_CODE_LEFT,  PAD, tx.inc(GAP_B), 30);
169
	//draw_tool_btn(13, ECTRL + SCAN_CODE_LEFT,  PAD, tx.inc(GAP_B), 30, false);
155
	//draw_icon(14, ECTRL + SCAN_CODE_RIGHT, PAD, tx.inc(GAP_S), 31);
170
	//draw_tool_btn(14, ECTRL + SCAN_CODE_RIGHT, PAD, tx.inc(GAP_S), 31, false);
156
	//draw_icon(15, ECTRL + SCAN_CODE_UP,    PAD, tx.inc(GAP_S), 32);
-
 
157
	//draw_icon(16, ECTRL + SCAN_CODE_DOWN,  PAD, tx.inc(GAP_S), 33);
171
	//draw_tool_btn(15, ECTRL + SCAN_CODE_UP,    PAD, tx.inc(GAP_S), 32, false);
158
 
172
	//draw_tool_btn(16, ECTRL + SCAN_CODE_DOWN,  PAD, tx.inc(GAP_S), 33, false);
159
 	//draw_icon(#event_save,     ECTRL + SCAN_CODE_KEY_S, PAD, tx.inc(GAP_B), 05, "Save file");
173
 
160
 	//draw_icon(12, 0,                                    PAD, tx.inc(GAP_B), 05, "PNG");
174
 	draw_tool_btn(#event_save, ECTRL + SCAN_CODE_KEY_S, PAD, tx.inc(GAP_B), 05, "Save file", false);
161
	//draw_icon(12, 0,                                    PAD, tx.inc(GAP_S), 05, "BMP");
175
 	draw_tool_btn(#event_save_png, 0, PAD, tx.inc(GAP_S), -1, "PNG", saving_type & SAVE_AS_PNG);
-
 
176
	draw_tool_btn(#event_save_bmp, 0, PAD*2+34, tx.n,     -1, "BMP", saving_type & SAVE_AS_BMP);
162
	//draw_icon(12, 0,                                    PAD, tx.inc(GAP_S), 05, "RAW");
177
	draw_tool_btn(#event_save_raw, 0, PAD*3+68, tx.n,     -1, "RAW", saving_type & SAVE_AS_RAW);
163
	draw_icon(#event_save,     ECTRL + SCAN_CODE_KEY_S, PAD, tx.inc(GAP_S), 05, "Save as PNG");
178
 
164
 
179
 	draw_tool_btn(#event_activate_crop,  0, PAD, tx.inc(GAP_B), 46, "Crop", active_tool & TOOL_CROP);
Line 165... Line 180...
165
 	draw_icon(0, 0,                       PAD, tx.inc(GAP_B), 46, "Crop");
180
	draw_tool_btn(#event_activate_resize,0, PAD, tx.inc(GAP_S), 06, "Resize", active_tool & TOOL_RESIZE);
166
	draw_icon(0, 0,                       PAD, tx.inc(GAP_S), 06, "Resize");
181
	draw_tool_btn(#event_activate_depth, 0, PAD, tx.inc(GAP_S), 52, "Color depth", active_tool & TOOL_COLOR_DEPTH);
167
	draw_icon(0, 0,                       PAD, tx.inc(GAP_S), 52, "Color depth");
182
	draw_tool_btn(#event_activate_flprot,0, PAD, tx.inc(GAP_S), 36, "Flip/Rotate", active_tool & TOOL_FLIP_ROTATE);
Line 168... Line -...
168
	draw_icon(#event_flip_hor, ECTRL + SCAN_CODE_KEY_H, PAD,     tx.inc(GAP_S), 34, NULL);
-
 
169
	draw_icon(#event_flip_ver, ECTRL + SCAN_CODE_KEY_V, PAD*4+3, tx.n,          35, NULL);
-
 
170
	draw_icon(#event_rotate,   ECTRL + SCAN_CODE_KEY_R, PAD*7+6, tx.n,          36, NULL);
-
 
171
 
183
	//draw_tool_btn(#event_flip_hor, ECTRL + SCAN_CODE_KEY_H, PAD,      tx.inc(GAP_S), 34, NULL, false);
172
	draw_image_info(tx.inc(GAP_B));
-
 
173
	draw_canvas();
-
 
174
}
-
 
175
 
-
 
176
char* libimg_bpp[] = { "8 pal", "24", "32", "15", "16",
-
 
177
"1 mono", "8 gray", "2 pal", "4 pal", "8 pal" };
-
 
178
 
-
 
179
void draw_image_info(int _y)
-
 
180
{
-
 
181
	WriteText(PAD, _y, 0x90, sc.work_text, "Properties");
-
 
182
	DrawBar(PAD, _y+14, TOOLBAR_W, 1, sc.work_graph);
-
 
183
	WriteText(PAD, _y+22, 0x90, sc.work_text, "Width:");
-
 
184
	WriteText(PAD, _y+42, 0x90, sc.work_text, "Heigh:");
-
 
185
	WriteText(PAD, _y+62, 0x90, sc.work_text, "Depth:");
184
	//draw_tool_btn(#event_flip_ver, ECTRL + SCAN_CODE_KEY_V, PAD*2+34, tx.n,          35, NULL, false);
-
 
185
	//draw_tool_btn(#event_rotate,   ECTRL + SCAN_CODE_KEY_R, PAD*3+68, tx.n,          36, NULL, false);
-
 
186
 
-
 
187
	draw_status_bar();
-
 
188
	draw_canvas();
-
 
189
}
-
 
190
 
-
 
191
void draw_status_bar()
-
 
192
{
-
 
193
	char img_info[24];
186
 
194
	//draw_image_info
187
	WriteText(PAD+60, _y+22, 0x90, sc.work_text, itoa(main_image.w));
195
	sprintf(#img_info, "%ix%i@%s", main_image.w, main_image.h, libimg_bpp[main_image.type-1]);
-
 
196
	DrawBar(canvas.x, Form.cheight - STATUSBAR_H, Form.cwidth - canvas.x, STATUSBAR_H, sc.work);
-
 
197
	WriteText(canvas.x, Form.cheight - STATUSBAR_H + 2, 0x90, sc.work_text, #img_info);
188
	WriteText(PAD+60, _y+42, 0x90, sc.work_text, itoa(main_image.h));
198
}
189
	WriteText(PAD+60, _y+62, 0x90, sc.work_text, libimg_bpp[main_image.type-1]);
199
 
190
}
200
void draw_tool_btn(dword _event, _hotkey, _x, _y, _icon_n, _text, _active)
191
 
201
{
192
void draw_icon(dword _event, _key, _x, _y, _icon_n, _text)
202
	int w = TOOLBAR_W;
193
{
203
	if (!_text) w = PAD + PAD + 12;
194
	int w;
204
	if (_icon_n==-1) w = strlen(_text) * 8 + 14;
-
 
205
	if (_active) EDX = sc.button; else EDX = semi_white;
195
	if (_text) w = TOOLBAR_W; else w = PAD + PAD + 8;
206
	DrawBar(_x, _y, w, TOOLBAR_ITEM_H+1, EDX);
-
 
207
	PutPixel(_x,_y,sc.work);
-
 
208
	PutPixel(_x,_y+TOOLBAR_ITEM_H,sc.work);
-
 
209
	PutPixel(_x+w-1,_y,sc.work);
-
 
210
	PutPixel(_x+w-1,_y+TOOLBAR_ITEM_H,sc.work);
-
 
211
	if (_event) DefineHiddenButton(_x, _y, w, TOOLBAR_ITEM_H, button.add(_event));
-
 
212
	if (_hotkey) key.add_n(_hotkey, _event);
-
 
213
	if (_icon_n!=-1) {
-
 
214
		img_draw stdcall(icons18.image, _x+7, _y+4, ISIZE, ISIZE, 0, _icon_n*ISIZE);
196
	DrawBar(_x, _y, w, TOOLBAR_ITEM_H+1, semi_white);
215
		_x += PAD+ISIZE+2;
Line 197... Line 216...
197
	PutPixel(_x,_y,sc.work);
216
	} else {
198
	PutPixel(_x,_y+TOOLBAR_ITEM_H,sc.work);
217
		_x += 7;
199
	PutPixel(_x+w-1,_y,sc.work);
218
	}
Line 287... Line 306...
287
	img_rotate stdcall (main_image.image, ROTATE_90_CW);
306
	img_rotate stdcall (main_image.image, ROTATE_90_CW);
288
	main_image.w >< main_image.h;
307
	main_image.w >< main_image.h;
289
	draw_window();
308
	draw_window();
290
}
309
}
Line -... Line 310...
-
 
310
 
-
 
311
void event_save_png() { saving_type = SAVE_AS_PNG; draw_window(); }
-
 
312
void event_save_bmp() { saving_type = SAVE_AS_BMP; draw_window(); }
-
 
313
void event_save_raw() { saving_type = SAVE_AS_RAW; draw_window(); }
-
 
314
 
-
 
315
void event_activate_crop() { active_tool = TOOL_CROP; draw_window(); }
-
 
316
void event_activate_resize() { active_tool = TOOL_RESIZE; draw_window(); }
-
 
317
void event_activate_depth() { active_tool = TOOL_COLOR_DEPTH; draw_window(); }
-
 
318
void event_activate_flprot() { active_tool = TOOL_FLIP_ROTATE; draw_window(); }
291
 
319
 
292
void event_save()
320
void event_save()
293
{
321
{
-
 
322
	o_dialog.type = 1; //save file
-
 
323
	switch (saving_type) {
294
	o_dialog.type = 1; //save file
324
		case SAVE_AS_PNG:
295
	strcpy(#filename_area, "image.png");
325
				strcpy(#filename_area, "image.png");
296
	OpenDialog_start stdcall (#o_dialog);
326
				OpenDialog_start stdcall (#o_dialog);
297
	if (o_dialog.status) {
327
				if (o_dialog.status) {
298
		update_title(#openfile_path);
328
					update_title(#openfile_path);
299
		img_to_rgb stdcall (main_image.image);
329
					img_to_rgb stdcall (main_image.image);
300
		save_image(main_image.imgsrc, main_image.w, main_image.h, #openfile_path);
330
					save_image(main_image.imgsrc, main_image.w, main_image.h, #openfile_path);
-
 
331
				}
-
 
332
				break;
-
 
333
		case SAVE_AS_BMP:
-
 
334
				notify("Not implemented yet.");
-
 
335
				break;
-
 
336
		case SAVE_AS_RAW:
-
 
337
				notify("Not implemented yet.");
-
 
338
				break;
-
 
339
	}
-
 
340
}
-
 
341
 
-
 
342
void event_scroll_canvas(int _direction)
-
 
343
{
-
 
344
	switch(_direction) {
-
 
345
		case SCAN_CODE_DOWN:
-
 
346
			scroll_v.position = math.min(scroll_v.position+25, 
-
 
347
				scroll_v.max_area - scroll_v.cur_area);
-
 
348
			break;
-
 
349
		case SCAN_CODE_UP:
-
 
350
			scroll_v.position = math.max(scroll_v.position-25, 0);
-
 
351
			break;
-
 
352
		case SCAN_CODE_RIGHT:
-
 
353
			scroll_h.position = math.min(scroll_h.position+25, 
-
 
354
				scroll_h.max_area - scroll_h.cur_area);
-
 
355
			break;
-
 
356
		case SCAN_CODE_LEFT:
-
 
357
			scroll_h.position = math.max(scroll_h.position-25, 0);
-
 
358
	}
301
	}
359
	draw_canvas();
Line 302... Line 360...
302
}
360
}