Subversion Repositories Kolibri OS

Rev

Rev 9851 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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