Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
9396 leency 1
#define MEMSIZE 1024*100
2
 
9643 leency 3
/*=====================================================
4
|                                                     |
5
|                         LIB                         |
6
|                                                     |
7
=====================================================*/
8
 
9396 leency 9
#include "../lib/gui.h"
10
#include "../lib/random.h"
11
#include "../lib/mem.h"
12
#include "../lib/cursor.h"
13
#include "../lib/list_box.h"
14
#include "../lib/events.h"
15
 
16
#include "../lib/obj/libimg.h"
17
#include "../lib/obj/box_lib.h"
18
#include "../lib/obj/proc_lib.h"
19
 
20
#include "../lib/patterns/rgb.h"
21
#include "../lib/patterns/toolbar_button.h"
22
#include "../lib/patterns/simple_open_dialog.h"
23
 
9643 leency 24
/*=====================================================
25
|                                                     |
26
|                        DATA                         |
27
|                                                     |
28
=====================================================*/
9396 leency 29
 
9643 leency 30
#include "data.h"
9396 leency 31
 
9643 leency 32
/*=====================================================
33
|                                                     |
34
|                        CODE                         |
35
|                                                     |
36
=====================================================*/
9396 leency 37
 
9643 leency 38
void main()
39
{
40
	/* Init external libraries */
41
	load_dll(libimg, #libimg_init, 1);
42
	load_dll(boxlib, #box_lib_init,0);
43
	load_dll(Proc_lib, #OpenDialog_init,0);
44
	OpenDialog_init stdcall (#o_dialog);
9632 leency 45
 
9643 leency 46
	/* Init UI */
9396 leency 47
	icons18.load("/sys/icons16.png");
9632 leency 48
	icons18.replace_2colors(0xffFFFfff, COL_LIGHT, 0xffCACBD6, COL_LIGHT-0x080808);
49
	icons18a.load("/sys/icons16.png");
50
	icons18a.replace_2colors(0xffFFFfff, COL_BUTTON, 0xffCACBD6, 0);
51
	pixie_skin.load("/sys/media/pixieskn.png");
9643 leency 52
	Form.width = screen.w/6*5;
53
	Form.height = screen.h/6*5;
9644 leency 54
	sc.work = COL_WORK;
55
	sc.work_text = COL_WORK_TEXT;
56
	sc.light = COL_LIGHT;
57
	sc.dark = COL_DARK;
58
	sc.line = COL_LINE;
59
	sc.button = COL_BUTTON;
60
	sc.button_text = COL_BUTTON_TEXT;
9396 leency 61
 
9643 leency 62
	/* Handle application parameters */
63
	//if (!param) open_image("/sys/home.png");
9396 leency 64
 
9643 leency 65
	/* Set event mask and go to main loop */
9396 leency 66
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
67
	loop() switch(WaitEvent())
68
	{
69
		case evMouse:
70
			mouse.get();
9643 leency 71
			if (main_image.h > canvas.h) scrollbar_v_mouse stdcall(#scroll_v);
72
			if (main_image.w > canvas.w) scrollbar_h_mouse stdcall(#scroll_h);
9644 leency 73
			if (active_tool == TOOL_SCALE) {
74
				edit_box_mouse stdcall (#edit_w);
75
				edit_box_mouse stdcall (#edit_h);
76
			}
9396 leency 77
			if (scroll_v.delta) || (scroll_h.delta) draw_canvas();
9597 leency 78
			if (EAX = mouse.vert) {
79
				if (EAX<10) event_scroll_canvas(SCAN_CODE_DOWN);
80
				else event_scroll_canvas(SCAN_CODE_UP);
81
			} if (EAX = mouse.hor) {
82
				if (EAX<10) event_scroll_canvas(SCAN_CODE_RIGHT);
83
				else event_scroll_canvas(SCAN_CODE_LEFT);
84
			}
9396 leency 85
			break;
86
 
87
		case evButton:
88
			pressed_button_id = GetButtonID();
89
			if (pressed_button_id==1) ExitProcess();
9644 leency 90
			keep_ratio.click(pressed_button_id);
9396 leency 91
			button.press(pressed_button_id);
92
			break;
93
 
94
		case evKey:
95
			GetKeys();
9644 leency 96
			if (active_tool == TOOL_SCALE)
97
			&& (edit_w.flags & ed_focus) || (edit_h.flags & ed_focus) {
98
				if (key_scancode == SCAN_CODE_TAB) {
99
					edit_w.flags >< edit_h.flags;
100
					draw_acive_panel();
101
					break;
102
				}
103
				if (edit_w.flags & ed_focus) {
104
					edit_box_key_c stdcall (#edit_w, key_editbox);
105
					if (keep_ratio.checked) && (text_w) && (atoi(#text_w)) {
106
						EDI = main_image.h*100 / calc(main_image.w*100 / atoi(#text_w));
107
						edit_box_set_text stdcall (#edit_h, itoa(EDI));
108
						edit_box_draw stdcall (#edit_h);
109
					}
110
				} else {
111
					edit_box_key_c stdcall (#edit_h, key_editbox);
112
					if (keep_ratio.checked) && (text_h) && (atoi(#text_h)) {
113
						EDI = main_image.h*100 / calc(main_image.w*100 / atoi(#text_h));
114
						edit_box_set_text stdcall (#edit_w, itoa(EDI));
115
						edit_box_draw stdcall (#edit_w);
116
					}
117
				}
118
				break;
119
			}
9597 leency 120
			if (key_scancode == SCAN_CODE_DOWN) event_scroll_canvas(SCAN_CODE_DOWN);
121
			if (key_scancode == SCAN_CODE_UP) event_scroll_canvas(SCAN_CODE_UP);
122
			if (key_scancode == SCAN_CODE_LEFT) event_scroll_canvas(SCAN_CODE_LEFT);
123
			if (key_scancode == SCAN_CODE_RIGHT) event_scroll_canvas(SCAN_CODE_RIGHT);
124
			key.press(key_scancode);
9396 leency 125
			break;
126
 
127
		case evReDraw:
128
			draw_window();
129
			break;
130
	}
131
}
132
 
133
void draw_window()
134
{
9632 leency 135
	DefineAndDrawWindow(screen.w-Form.width/2, screen.h-Form.height/2, Form.width, Form.height, 0x42, NULL, NULL, 0);
9396 leency 136
	GetProcessInfo(#Form, SelfInfo);
9643 leency 137
	/* Draw window borders */
138
	DrawRectangle(0,0,Form.width,Form.height,COL_LINE);
139
	DrawRectangle(1,1,Form.width-2,Form.height-2,COL_LIGHT);
140
	/* Check if the window is collapsed into header */
141
	if (Form.status_window&ROLLED_UP) {
142
		DrawBar(2, 2, Form.width-3, skin_h-4, COL_WORK);
143
		WriteText(5, skin_h-11/2, 0x90, COL_WORK_TEXT, "ImageEditor Pro [Collapsed]");
144
		draw_window_manipulation_buttons(skin_h-17/2);
145
		return;
146
	}
9396 leency 147
	if (Form.width  < 560) { MoveSize(OLD,OLD,560,OLD); return; }
148
	if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
9632 leency 149
	scroll_v.all_redraw = scroll_h.all_redraw = 1;
150
	draw_content();
151
}
152
 
153
void draw_content()
154
{
155
	incn tx;
9396 leency 156
	button.init(40);
157
	key.init(40);
158
 
9632 leency 159
	canvas.w = Form.cwidth - CANVASX - 1;
160
	canvas.h = Form.cheight - STATUSBAR_H - CANVASY - 1;
9396 leency 161
	if (main_image.h > canvas.h) canvas.w -= scroll_v.size_x + 1;
162
	if (main_image.w > canvas.w) canvas.h -= scroll_h.size_y + 1;
163
 
9643 leency 164
	//draw panel border
9632 leency 165
	DrawBar(CANVASX, 0, 1, Form.cheight, COL_LINE);
166
 
167
	//draw title
168
	DrawBar(2, 2, CANVASX-2, HEADERH-1, COL_DARK);
9633 leency 169
	WriteText(PAD+5, HEADER_TEXTY, 0x90, COL_WORK_TEXT, "ImageEditor Pro");
9632 leency 170
 
171
	//draw header
172
	DrawBar(CANVASX+1, CANVASY-1, Form.width-CANVASX-2, 1, COL_LINE);
173
	draw_acive_panel();
9643 leency 174
	draw_window_manipulation_buttons(7);
9632 leency 175
 
176
	//left panel bg
177
	DrawBar(2, 1+HEADERH, CANVASX-2, Form.cheight-2-HEADERH, COL_WORK);
178
 
9396 leency 179
	if (main_image.h > canvas.h) && (main_image.w > canvas.w) {
9632 leency 180
		DrawBar(CANVASX+canvas.w, CANVASY+canvas.h, scroll_v.size_x+1, scroll_h.size_y+1, COL_WORK);
9396 leency 181
	}
182
 
9597 leency 183
	#define GAP_S TOOLBAR_ITEM_H+8
184
	#define GAP_B TOOLBAR_ITEM_H+23
9632 leency 185
	tx.set(PAD-GAP_S+HEADERH);
9597 leency 186
	//draw_tool_btn(10, ECTRL + SCAN_CODE_KEY_N, PAD, tx.inc(GAP_S), 02, "Create image", false);
9643 leency 187
	draw_tool_btn(#event_open, ECTRL + SCAN_CODE_KEY_O, PAD, tx.inc(GAP_S), 00, "Open image  ", false);
188
	if (main_image.image) {
189
	 	draw_tool_btn(#event_activate_export, ECTRL + SCAN_CODE_KEY_S, PAD, tx.inc(GAP_S), 05, "Export image", active_tool & TOOL_EXPORT);
190
	 	//draw_tool_btn(#event_activate_crop,  0, PAD, tx.inc(GAP_B), 46, "Crop", active_tool & TOOL_CROP);
191
		draw_tool_btn(#event_activate_depth, 0, PAD, tx.inc(GAP_B), 52, "Color depth ", active_tool & TOOL_COLOR_DEPTH);
192
		draw_tool_btn(#event_activate_flprot,0, PAD, tx.inc(GAP_S), 36, "Flip/Rotate ", active_tool & TOOL_FLIP_ROTATE);
9644 leency 193
		draw_tool_btn(#event_activate_scale, 0, PAD, tx.inc(GAP_S), 06, "Scale       ", active_tool & TOOL_SCALE);
9643 leency 194
	}
9597 leency 195
	draw_status_bar();
9396 leency 196
	draw_canvas();
197
}
198
 
9643 leency 199
void draw_window_manipulation_buttons(int y)
200
{
201
	DrawBar(Form.width-65, 2, 63, HEADERH-1, COL_WORK);
202
	img_draw stdcall(pixie_skin.image, Form.width-63, y, 57, 18, 265, 0);
203
	DefineHiddenButton(Form.width-63, y, 28, 17, button.add(#MinimizeWindow));
204
	DefineHiddenButton(Form.width-35, y, 28, 17, 1);
205
}
206
 
9597 leency 207
void draw_status_bar()
9396 leency 208
{
9597 leency 209
	char img_info[24];
9633 leency 210
	sprintf(#img_info, "%i\01%i\02%s", main_image.w, main_image.h, libimg_bpp[main_image.type]);
9632 leency 211
	DrawBar(CANVASX+1, Form.cheight - STATUSBAR_H - 1, Form.cwidth - CANVASX -2, STATUSBAR_H, COL_WORK);
212
	WriteText(CANVASX+4, Form.cheight - STATUSBAR_H + 2, 0x90, COL_WORK_TEXT, #img_info);
213
	for (ESI=0; img_info[ESI]!=0; ESI++) {
214
		if (img_info[ESI] == '\01') img_info[ESI]='x';
215
		else if (img_info[ESI] == '\02') img_info[ESI]='@';
216
		else img_info[ESI]=' ';
217
	}
218
	ECX = 0x90 << 24 + COL_BUTTON_TEXT;
219
	$int 64
9396 leency 220
}
221
 
9633 leency 222
int draw_tool_btn(dword _event, _hotkey, _x, _y, _icon_n, _text, _active)
9396 leency 223
{
9633 leency 224
	dword img_ptr = icons18.image;
9643 leency 225
 
226
	int w = 32; //default width: icon only
227
	if (_text) {
228
		w = strlen(_text) * 8 + 15;
229
		if (_icon_n!=-1) w += 26;
230
	}
231
 
9633 leency 232
	if (_active==-1) {
9634 leency 233
		$push COL_LIGHT
9633 leency 234
		EDX = COL_LINE;
235
	} else if (_active) {
9632 leency 236
		img_ptr = icons18a.image;
9634 leency 237
		$push COL_BUTTON_TEXT
9632 leency 238
		EDX = COL_BUTTON;
9633 leency 239
 
9632 leency 240
	} else {
9633 leency 241
		$push COL_WORK_TEXT
9632 leency 242
		EDX = COL_LIGHT;
9633 leency 243
	}
9597 leency 244
	DrawBar(_x, _y, w, TOOLBAR_ITEM_H+1, EDX);
9632 leency 245
	PutPixel(_x,_y,COL_WORK);
246
	PutPixel(_x,_y+TOOLBAR_ITEM_H,COL_WORK);
247
	PutPixel(_x+w-1,_y,COL_WORK);
248
	PutPixel(_x+w-1,_y+TOOLBAR_ITEM_H,COL_WORK);
9396 leency 249
	if (_event) DefineHiddenButton(_x, _y, w, TOOLBAR_ITEM_H, button.add(_event));
9597 leency 250
	if (_hotkey) key.add_n(_hotkey, _event);
251
	if (_icon_n!=-1) {
9632 leency 252
		#define ISIZE 18
253
		img_draw stdcall(img_ptr, _x+7, _y+4, ISIZE, ISIZE, 0, _icon_n*ISIZE);
9597 leency 254
		_x += PAD+ISIZE+2;
255
	} else {
256
		_x += 7;
257
	}
9633 leency 258
	$pop EDX
9597 leency 259
	if (_text) {
260
		WriteText(_x, _y+6, 0x90, EDX, _text);
261
	}
9633 leency 262
	return w;
9396 leency 263
}
264
 
9632 leency 265
void draw_canvas()
9396 leency 266
{
9632 leency 267
	int content_w = math.min(main_image.w, canvas.w-1);
268
	int content_h = math.min(main_image.h, canvas.h);
269
	if (main_image.image) {
270
		img_draw stdcall(main_image.image, CANVASX+1, CANVASY,
271
		content_w, content_h, scroll_h.position, scroll_v.position);
272
 	}
273
	DrawBar(CANVASX+1+content_w, CANVASY, canvas.w - content_w - 1, content_h, COL_DARK);
274
	DrawBar(CANVASX+1, CANVASY+content_h, canvas.w - 1, canvas.h - content_h, COL_DARK);
275
	//Draw scroll V
9396 leency 276
	scroll_v.max_area = main_image.h;
9632 leency 277
	scroll_v.cur_area = scroll_v.size_y = canvas.h + 1;
278
	scroll_v.start_x = CANVASX + canvas.w;
9396 leency 279
	if (main_image.h > canvas.h) scrollbar_v_draw stdcall (#scroll_v);
9632 leency 280
	//Draw scroll H
9396 leency 281
	scroll_h.max_area = main_image.w;
282
	scroll_h.cur_area = scroll_h.size_x = canvas.w;
9632 leency 283
	scroll_h.start_y = CANVASY + canvas.h;
9396 leency 284
	if (main_image.w > canvas.w) scrollbar_h_draw stdcall (#scroll_h);
285
 
286
}
287
 
9632 leency 288
void set_file_path(char* _new_title)
9396 leency 289
{
9632 leency 290
	strcpy(#param, _new_title);
291
	draw_status_bar();
9396 leency 292
}
293
 
294
void open_image(char* _path)
295
{
296
	main_image.load(_path);
9632 leency 297
	set_file_path(_path);
9396 leency 298
	scroll_v.position = 0;
299
	scroll_h.position = 0;
300
}
301
 
9633 leency 302
void event_set_color_depth() {
9643 leency 303
	img_convert stdcall(main_image.image, 0, pressed_button_id-color_depth_btnid_1, 0, 0);
9633 leency 304
	if (!EAX) {
9643 leency 305
		notify("'ImageEdit Pro\nNot possible to convert into specified color depth' -Et");
9633 leency 306
	} else {
307
		$push eax
9634 leency 308
		img_destroy stdcall(main_image.image);
309
		$pop eax
310
		main_image.image = EAX;
9633 leency 311
		main_image.set_vars();
312
		draw_acive_panel();
313
		draw_status_bar();
9635 leency 314
		draw_canvas();
9633 leency 315
	}
316
}
317
 
9644 leency 318
void WritePanelText(int _x, _text) { WriteText(_x, HEADER_TEXTY, 0x90, COL_WORK_TEXT, _text); }
9632 leency 319
void draw_acive_panel()
320
{
9633 leency 321
	int i, x = CANVASX + PAD;
322
	bool a;
9643 leency 323
	DrawBar(CANVASX+1, 2, Form.width-CANVASX-64, HEADERH-1, COL_WORK);
9632 leency 324
	switch(active_tool) {
9643 leency 325
		case TOOL_EXPORT:
326
			WritePanelText(CANVASX+PAD, "Format");
327
			x += 6*8 + PAD;
328
		 	x += draw_tool_btn(#event_save_png, 0, x, 7, -1, "PNG", saving_type & SAVE_AS_PNG) + PAD;
329
			x += draw_tool_btn(#event_save_pnm, 0, x, 7, -1, "PNM", saving_type & SAVE_AS_PNM) + PAD;
330
			x += draw_tool_btn(#event_save_bmp, 0, x, 7, -1, "BMP", saving_type & SAVE_AS_BMP) + PAD + PAD;
9644 leency 331
			if (saving_type) draw_tool_btn(#event_save, 0, x, 7, 53, "Export", false);
9643 leency 332
			break;
9632 leency 333
		case TOOL_CROP:
9643 leency 334
			WritePanelText(CANVASX+PAD, "Crop tool");
9632 leency 335
			break;
9644 leency 336
		case TOOL_SCALE:
337
			WritePanelText(CANVASX+PAD, "New size          x");
338
			DefineHiddenButton(edit_w.left-2, edit_w.top-2, 148, 25, 2+BT_NOFRAME);
339
			DrawEditBox(#edit_w);
340
			DrawEditBox(#edit_h);
341
			keep_ratio.draw(CANVASX + PAD + 233, HEADER_TEXTY);
342
			draw_tool_btn(#event_scale, SCAN_CODE_ENTER, CANVASX + PAD + 370, 7, -1, "Apply", false);
9632 leency 343
			break;
344
		case TOOL_COLOR_DEPTH:
9643 leency 345
			WritePanelText(CANVASX+PAD, "Color depth");
9633 leency 346
			x += 11*8 + PAD;
9643 leency 347
			color_depth_btnid_1 = button.new_id;
9633 leency 348
			for (i=1; i<11; i++) {
9643 leency 349
				DeleteButton(color_depth_btnid_1+i);
9633 leency 350
				if (main_image.type == i) {
9643 leency 351
					a = true; //this is current image depth
9633 leency 352
				} else {
9643 leency 353
					a = false; //this is image depth we can set
9633 leency 354
					//probe does libimg support converting current image gepth to i-one
355
					img_create stdcall(1, 1, main_image.type);
356
					img_convert stdcall(EAX, 0, i, 0, 0);
357
					if (EAX) {
358
						img_destroy stdcall(EAX);
359
					} else {
360
						a = -1;
9644 leency 361
						if (Form.width-CANVASX-64 < 600) {
9643 leency 362
							button.add(1);
363
							continue;
364
						}
9633 leency 365
					}
366
				}
9644 leency 367
				x += draw_tool_btn(#event_set_color_depth, SCAN_CODE_ENTER, x, 7, -1, libimg_bpp[i], a) + 6;
9633 leency 368
			}
9632 leency 369
			break;
370
		case TOOL_FLIP_ROTATE:
9643 leency 371
			WritePanelText(CANVASX+PAD, "Flip");
9632 leency 372
			draw_tool_btn(#event_flip_hor, ECTRL + SCAN_CODE_KEY_H, CANVASX + PAD + 040, 7, 34, NULL, false);
373
			draw_tool_btn(#event_flip_ver, ECTRL + SCAN_CODE_KEY_V, CANVASX + PAD + 080, 7, 35, NULL, false);
9643 leency 374
			WritePanelText(CANVASX+PAD + 142, "Rotate");
375
			draw_tool_btn(#event_rotate_left,  ECTRL + SCAN_CODE_KEY_L, CANVASX + PAD + 200, 7, 37, NULL, false);
376
			draw_tool_btn(#event_rotate_right, ECTRL + SCAN_CODE_KEY_R, CANVASX + PAD + 240, 7, 36, NULL, false);
377
			// WritePanelText(CANVASX+PAD + 142, "Move");
378
			//draw_tool_btn(#event_move_left,  ECTRL + SCAN_CODE_LEFT,  PAD, tx.inc(GAP_B), 30, false);
379
			//draw_tool_btn(#event_move_right, ECTRL + SCAN_CODE_RIGHT, PAD, tx.inc(GAP_S), 31, false);
380
			//draw_tool_btn(#event_move_up,    ECTRL + SCAN_CODE_UP,    PAD, tx.inc(GAP_S), 32, false);
381
			//draw_tool_btn(#event_move_down,  ECTRL + SCAN_CODE_DOWN,  PAD, tx.inc(GAP_S), 33, false);
9632 leency 382
			break;
383
		default:
9643 leency 384
			if (!param) WritePanelText(CANVASX+PAD, "Welcome to ImageEditor Pro! Try to open a file.");
9632 leency 385
	}
386
}
387
 
9396 leency 388
//===================================================//
389
//                                                   //
390
//                      EVENTS                       //
391
//                                                   //
392
//===================================================//
393
 
9643 leency 394
void event_save_png() { saving_type = SAVE_AS_PNG; draw_acive_panel(); }
395
void event_save_bmp() { saving_type = SAVE_AS_BMP; draw_acive_panel(); }
396
void event_save_raw() { saving_type = SAVE_AS_RAW; draw_acive_panel(); }
397
void event_save_pnm() { saving_type = SAVE_AS_PNM; draw_acive_panel(); }
398
void event_activate_export() { active_tool = TOOL_EXPORT; draw_content(); }
399
void event_activate_crop() { active_tool = TOOL_CROP; draw_content(); }
9644 leency 400
void event_activate_scale() { active_tool = TOOL_SCALE; set_text_scale_edits(); draw_content(); }
9643 leency 401
void event_activate_depth() { active_tool = TOOL_COLOR_DEPTH; draw_content(); }
402
void event_activate_flprot() { active_tool = TOOL_FLIP_ROTATE; draw_content(); }
403
 
9644 leency 404
void set_text_scale_edits()
405
{
406
	edit_box_set_text stdcall (#edit_w, itoa(main_image.w));
407
	edit_box_set_text stdcall (#edit_h, itoa(main_image.h));
408
}
409
 
410
/*
411
;;================================================================================================;;
412
proc img.scale _src, _crop_x, _crop_y, _crop_width, _crop_height, _dst, _scale, _inter, _param1, _param2 ;;
413
;;------------------------------------------------------------------------------------------------;;
414
;? scale _image                                                                                   ;;
415
;;------------------------------------------------------------------------------------------------;;
416
;> [_src]         = pointer to source image                                                       ;;
417
;> [_crop_x]      = left coord of cropping rect                                                   ;;
418
;> [_crop_y]      = top coord of cropping rect                                                    ;;
419
;> [_crop_width]  = width of cropping rect                                                        ;;
420
;> [_crop_height] = height of cropping rect                                                       ;;
421
;> [_dst]         = pointer to resulting image, 0 to create new one                               ;;
422
;> [_scale]       = scaling method, see libimg.inc (LIBIMG_SCALE_*)                               ;;
423
;> [_inter]       = interpolation algorithm, see libimg.inc (LIBIMG_INTER_*)                      ;;
424
;> [_param1]      = depends on _scale, see libimg.inc                                             ;;
425
;> [_param2]      = depends on _scale, see libimg.inc                                             ;;
426
;;------------------------------------------------------------------------------------------------;;
427
;< eax = 0 / pointer to scaled image                                                              ;;
428
;< ecx = error code / undefined                                                                   ;;
429
;;================================================================================================;;
430
*/
431
 
432
//invoke  img.scale, eax, 0, 0, [eax+Image.Width], [eax+Image.Height], 0, LIBIMG_SCALE_STRETCH, LIBIMG_INTER_DEFAULT, [view.width], [view.height]
433
 
434
void event_scale()
435
{
436
	img_scale stdcall (main_image.image, 0, 0, main_image.w, main_image.h, 0,
437
		LIBIMG_SCALE_STRETCH, LIBIMG_INTER_DEFAULT, atoi(#text_w), atoi(#text_h));
438
	if (!EAX) {
439
		if (ECX == 4) {
440
			notify("'ImageEdit Pro\nThis color depth is not supported by Scale feature.\nPlease change color depth to 24 / 32 / 8grey.' -Et");
441
		} else {
442
			debugval("Error code", ECX);
443
			notify("'ImageEdit Pro\nImage scale failed :(' -Et");
444
		}
445
	} else {
446
		$push eax
447
		img_destroy stdcall (main_image.image);
448
		$pop eax
449
		main_image.image = EAX;
450
		main_image.set_vars();
451
		draw_canvas();
452
	}
453
}
454
 
9396 leency 455
void event_open()
456
{
457
	o_dialog.type = 0; //open file
458
	OpenDialog_start stdcall (#o_dialog);
459
	if (o_dialog.status) {
460
		open_image(#openfile_path);
9644 leency 461
		active_tool = NULL;
9635 leency 462
		draw_window();
9396 leency 463
	}
464
}
465
 
466
void event_flip_hor()
467
{
468
	img_flip stdcall (main_image.image, FLIP_HORIZONTAL);
469
	draw_canvas();
470
}
471
 
472
void event_flip_ver()
473
{
474
	img_flip stdcall (main_image.image, FLIP_VERTICAL);
475
	draw_canvas();
476
}
477
 
9632 leency 478
void event_rotate_left()
9396 leency 479
{
9632 leency 480
	img_rotate stdcall (main_image.image, ROTATE_270_CW);
481
	main_image.w >< main_image.h;
482
	draw_content();
483
}
484
 
485
void event_rotate_right()
486
{
9396 leency 487
	img_rotate stdcall (main_image.image, ROTATE_90_CW);
488
	main_image.w >< main_image.h;
9632 leency 489
	draw_content();
9396 leency 490
}
491
 
492
void event_save()
493
{
9643 leency 494
	dword _image_format, _image_depth;
495
	strcpy(#filename_area, #param + strrchr(#param, '/'));
496
	if (EAX = strrchr(#filename_area, '.'))	filename_area[EAX-1] = '\0';
9597 leency 497
	switch (saving_type) {
498
		case SAVE_AS_PNG:
9643 leency 499
				strcat(#filename_area, "_IEP.png");
500
				_image_format = LIBIMG_FORMAT_PNG;
501
				_image_depth = IMAGE_BPP24;
9597 leency 502
				break;
503
		case SAVE_AS_BMP:
9643 leency 504
				strcat(#filename_area, "_IEP.bmp");
505
				_image_format = LIBIMG_FORMAT_BMP;
506
				_image_depth = IMAGE_BPP24;
9597 leency 507
				break;
9643 leency 508
		case SAVE_AS_PNM:
509
				strcat(#filename_area, "_IEP.pnm");
510
				_image_format = LIBIMG_FORMAT_PNM;
511
				_image_depth = IMAGE_BPP24;
512
				break;
9597 leency 513
		case SAVE_AS_RAW:
514
				notify("Not implemented yet.");
9643 leency 515
				return;
9396 leency 516
	}
9643 leency 517
	o_dialog.type = 1; //save file
518
	OpenDialog_start stdcall (#o_dialog);
519
	if (o_dialog.status) {
520
		set_file_path(#openfile_path);
521
		img_convert stdcall(main_image.image, 0, _image_depth, 0, 0);
522
		if (!EAX) {
523
			notify("'ImageEdit Pro\nCan not convert image into specified color depth' -Et");
524
		} else {
525
			$push eax //converted data
526
			img_encode stdcall(EAX, _image_format, 0); //<=EAX data, ECX size
527
			$push eax //encoded data
528
			CreateFile(ECX, EAX, #openfile_path);
529
			$pop ecx
530
			free(ECX);
531
			$pop eax
532
			img_destroy stdcall(EAX);
533
		}
534
	}
9396 leency 535
}
536
 
9597 leency 537
void event_scroll_canvas(int _direction)
538
{
539
	switch(_direction) {
540
		case SCAN_CODE_DOWN:
541
			scroll_v.position = math.min(scroll_v.position+25,
542
				scroll_v.max_area - scroll_v.cur_area);
543
			break;
544
		case SCAN_CODE_UP:
545
			scroll_v.position = math.max(scroll_v.position-25, 0);
546
			break;
547
		case SCAN_CODE_RIGHT:
548
			scroll_h.position = math.min(scroll_h.position+25,
549
				scroll_h.max_area - scroll_h.cur_area);
550
			break;
551
		case SCAN_CODE_LEFT:
552
			scroll_h.position = math.max(scroll_h.position-25, 0);
553
	}
554
	draw_canvas();
555
}
556
 
9396 leency 557
stop:
558