Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
7089 leency 1
/*
7154 leency 2
 * Icon Editor for KolibriOS
7187 leency 3
 * Authors: Leency, Nicolas
7089 leency 4
 * Licence: GPL v2
5
*/
6
 
7151 leency 7
/*
7156 leency 8
TODO:
9
window colors
10
enhance icon
7194 leency 11
pipet aside color view
7151 leency 12
*/
13
 
7260 leency 14
#define MEMSIZE 4096*250
7089 leency 15
 
16
#include "../lib/gui.h"
7151 leency 17
#include "../lib/random.h"
18
#include "../lib/mem.h"
7262 leency 19
#include "../lib/cursor.h"
7255 leency 20
 
7096 leency 21
#include "../lib/obj/libimg.h"
7255 leency 22
#include "../lib/obj/box_lib.h"
23
 
7089 leency 24
#include "../lib/patterns/rgb.h"
7253 leency 25
#include "../lib/patterns/libimg_load_skin.h"
7089 leency 26
 
7151 leency 27
#include "colors_mas.h"
28
 
7089 leency 29
//===================================================//
30
//                                                   //
31
//                       DATA                        //
32
//                                                   //
33
//===================================================//
34
 
7265 leency 35
#define T_TITLE "Icon Editor 0.53 Alpha"
7096 leency 36
 
7152 leency 37
#define TOOLBAR_H    24+8
7187 leency 38
#define PANEL_LEFT_W 16+5+5+3+3
7096 leency 39
#define PALLETE_SIZE 116
7187 leency 40
#define TB_ICON_PADDING 26
7089 leency 41
 
7194 leency 42
#define PAL_ITEMS_X_COUNT 13
43
#define COLSIZE 18
7200 leency 44
#define RIGHT_BAR_W PAL_ITEMS_X_COUNT*COLSIZE
7187 leency 45
 
7253 leency 46
#define TO_CANVAS_X(xval) xval - canvas.x/zoom.value
47
#define TO_CANVAS_Y(yval) yval - canvas.y/zoom.value
48
 
7200 leency 49
block canvas = { NULL, NULL, NULL, NULL };
50
block wrapper = { PANEL_LEFT_W, TOOLBAR_H, NULL, NULL };
7255 leency 51
block right_bar = { NULL, 10+TOOLBAR_H, RIGHT_BAR_W+10, NULL };
7200 leency 52
 
7255 leency 53
block b_color_gradient = {NULL, 40+TOOLBAR_H, RIGHT_BAR_W, 30};
54
block b_last_colors = {NULL, 80+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*2};
55
block b_default_palette = {NULL, COLSIZE*2+10+80+TOOLBAR_H, RIGHT_BAR_W, COLSIZE*9};
7200 leency 56
 
7207 leency 57
dword color1 = 0x000000;
7255 leency 58
dword color2 = 0xBFCAD2;
7207 leency 59
dword tool_color;
7089 leency 60
 
7257 leency 61
signed hoverX;
62
signed hoverY;
63
signed priorHoverX;
64
signed priorHoverY;
65
bool canvasMouseMoved = false;
66
 
7089 leency 67
enum {
7096 leency 68
	BTN_NEW = 40,
69
	BTN_OPEN,
70
	BTN_SAVE,
71
	BTN_MOVE_LEFT,
72
	BTN_MOVE_RIGHT,
73
	BTN_MOVE_UP,
74
	BTN_MOVE_DOWN,
75
	BTN_FLIP_HOR,
76
	BTN_FLIP_VER,
77
	BTN_ROTATE_LEFT,
78
	BTN_ROTATE_RIGHT,
7265 leency 79
	BTN_TEST_ICON,
7187 leency 80
	BTN_PENCIL,
7096 leency 81
	BTN_PICK,
7156 leency 82
	BTN_FILL,
7186 leency 83
	BTN_LINE,
84
	BTN_RECT,
7259 leency 85
	BTN_BAR,
7253 leency 86
	BTN_SELECT,
7260 leency 87
	BTN_SCREEN_COPY,
7253 leency 88
	BTN_ZOOM_IN,
89
	BTN_ZOOM_OUT,
7155 leency 90
	BTNS_PALETTE_COLOR_MAS = 100,
91
	BTNS_LAST_USED_COLORS = 400
7089 leency 92
};
93
 
94
proc_info Form;
7255 leency 95
dword semi_white;
7089 leency 96
 
7243 leency 97
more_less_box zoom = { 11, 1, 40, "Zoom" };
7150 leency 98
 
7152 leency 99
dword default_palette[] = {
7190 leency 100
0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033,
101
0x330033,0x330019,0x000000,0x660000,0x663300,0x666600,0x336600,0x006600,0x006633,0x006666,
102
0x003366,0x000066,0x330066,0x660066,0x660033,0x202020,0x990000,0x994C00,0x999900,0x4C9900,
103
0x009900,0x00994C,0x009999,0x004C99,0x000099,0x4C0099,0x990099,0x99004C,0x404040,0xCC0000,
104
0xCC6600,0xCCCC00,0x66CC00,0x00CC00,0x00CC66,0x00CCCC,0x0066CC,0x0000CC,0x6600CC,0xCC00CC,
105
0xCC0066,0x606060,0xFF0000,0xFF8000,0xFFFF00,0x80FF00,0x00FF00,0x00FF80,0x00FFFF,0x0080FF,
106
0x0000FF,0x7F00FF,0xFF00FF,0xFF007F,0x808080,0xFF3333,0xFF9933,0xFFFF33,0x99FF33,0x33FF33,
107
0x33FF99,0x33FFFF,0x3399FF,0x3333FF,0x9933FF,0xFF33FF,0xFF3399,0xA0A0A0,0xFF6666,0xFFB266,
108
0xFFFF66,0xB2FF66,0x66FF66,0x66FFB2,0x66FFFF,0x66B2FF,0x6666FF,0xB266FF,0xFF66FF,0xFF66B2,
109
0xC0C0C0,0xFF9999,0xFFCC99,0xFFFF99,0xCCFF99,0x99FF99,0x99FFCC,0x99FFFF,0x99CCFF,0x9999FF,
110
0xCC99FF,0xFF99FF,0xFF99CC,0xE0E0E0,0xFFCCCC,0xFFE5CC,0xFFFFCC,0xE5FFCC,0xCCFFCC,0xCCFFE5,
111
0xCCFFFF,0xCCE5FF,0xCCCCFF,0xE5CCFF,0xFFCCFF,0xFFCCE5,0xFFFFFF
7089 leency 112
};
7155 leency 113
dword last_used_colors[13*2] = {
7190 leency 114
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,
115
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,
116
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF
7155 leency 117
};
7089 leency 118
 
7262 leency 119
CustomCursor Cursor;
120
dword CursorBar = FROM "cursors/bar.cur";
121
dword CursorFill = FROM "cursors/fill.cur";
122
dword CursorLine = FROM "cursors/line.cur";
123
dword CursorPencil = FROM "cursors/pencil.cur";
124
dword CursorPipette = FROM "cursors/pipette.cur";
125
dword CursorRectangle = FROM "cursors/rectangle.cur";
126
dword CursorSelect = FROM "cursors/select.cur";
127
 
7155 leency 128
_image image;
7148 leency 129
 
7204 leency 130
#include "actions_history.h"
131
 
132
_ActionsHistory actionsHistory;
7151 leency 133
 
7254 leency 134
#include "tools.h"
7156 leency 135
 
7089 leency 136
//===================================================//
137
//                                                   //
138
//                       CODE                        //
139
//                                                   //
140
//===================================================//
141
 
142
void main()
143
{
144
	word btn;
7257 leency 145
	libimg_image open_image;
7089 leency 146
 
7096 leency 147
	load_dll(libio,  #libio_init,  1);
148
	load_dll(libimg, #libimg_init, 1);
7255 leency 149
	load_dll(boxlib, #box_lib_init,0);
150
 
7096 leency 151
	Libimg_LoadImage(#skin, "/sys/icons16.png");
7255 leency 152
	system.color.get();
153
	semi_white = MixColors(system.color.work, 0xFFFfff, 64);
154
	Libimg_ReplaceColor(skin.image, skin.w, skin.h,
155
		0xffFFFfff, semi_white);
7089 leency 156
 
7254 leency 157
	if (!param[0]) {
158
		image.create(32, 32);
159
	}
160
	else
161
	{
7151 leency 162
		Libimg_LoadImage(#open_image, #param);
7254 leency 163
 
164
		if (open_image.w*open_image.h>MAX_CELL_SIZE*MAX_CELL_SIZE) {
165
			notify("'Hey, this is just an icon editor,\nselected image is too big to open!' -E");
166
			ExitProcess();
7151 leency 167
		}
168
		else {
7254 leency 169
			image.create(open_image.w, open_image.h);
170
			image.set_image(open_image.imgsrc);
7151 leency 171
		}
172
	}
173
 
7204 leency 174
	actionsHistory.init();
175
 
7186 leency 176
	initTools();
177
	setCurrentTool(TOOL_PENCIL);
178
 
7096 leency 179
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
180
 
7089 leency 181
	loop() switch(WaitEvent())
182
	{
7096 leency 183
		case evMouse:
184
			mouse.get();
7186 leency 185
 
7207 leency 186
			if (mouse.lkm) tool_color = color1;
187
			if (mouse.pkm) tool_color = color2;
188
			if (mouse.mkm) break;
189
 
7257 leency 190
			hoverX = mouse.x - canvas.x / zoom.value;
191
			hoverY = mouse.y - canvas.y / zoom.value;
192
			if (hoverX<0) hoverX = 0;
193
			if (hoverY<0) hoverY = 0;
194
			if (hoverX>image.columns-1) hoverX = image.columns-1;
195
			if (hoverY>image.rows-1) hoverY = image.rows-1;
196
			canvasMouseMoved = false;
197
			if (priorHoverX != hoverX) canvasMouseMoved = true;
198
			if (priorHoverY != hoverY) canvasMouseMoved = true;
199
			priorHoverX = hoverX;
200
			priorHoverY = hoverY;
201
			//DrawBar(Form.cwidth-100, 3, 80, 12, 0xFFFfff);
202
			//WriteText(Form.cwidth-100, 3, 0x80, 0x000000,
203
			//	sprintf(#param, "%i %i", hoverX, hoverY));
204
 
7186 leency 205
			if (currentTool != TOOL_NONE)
206
				tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm);
207
 
7156 leency 208
			if (mouse.vert) {
7243 leency 209
				if (mouse.vert==65535) zoom.inc();
210
				if (mouse.vert==1) zoom.dec();
7152 leency 211
				DrawEditArea();
212
			}
7186 leency 213
 
7262 leency 214
			if (wrapper.hovered()) SetCursor();
215
			else Cursor.Restore();
216
 
7200 leency 217
			if (mouse.down) {
218
				if (b_color_gradient.hovered())
219
				|| (b_last_colors.hovered())
220
				|| (b_default_palette.hovered()) {
221
					if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, GetPixelUnderMouse());
222
					if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, GetPixelUnderMouse());
223
				}
224
			}
225
 
7148 leency 226
			break;
7096 leency 227
 
7089 leency 228
		case evButton:
7148 leency 229
			btn = GetButtonID();
7253 leency 230
 
7255 leency 231
			if (zoom.click(btn)) DrawEditArea();
232
 
7096 leency 233
			switch(btn)
234
			{
7151 leency 235
				case BTN_NEW:
7257 leency 236
					EventCleanCanvas();
7151 leency 237
					break;
238
				case BTN_OPEN:
7190 leency 239
					RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path));
7151 leency 240
					break;
241
				case BTN_SAVE:
7257 leency 242
					EventSaveIconToFile();
7151 leency 243
					break;
7096 leency 244
				case BTN_MOVE_LEFT:
7151 leency 245
					image.move(MOVE_LEFT);
246
					DrawCanvas();
7096 leency 247
					break;
248
				case BTN_MOVE_RIGHT:
7151 leency 249
					image.move(MOVE_RIGHT);
250
					DrawCanvas();
7096 leency 251
					break;
7147 leency 252
				case BTN_MOVE_UP:
7151 leency 253
					image.move(MOVE_UP);
254
					DrawCanvas();
7147 leency 255
					break;
256
				case BTN_MOVE_DOWN:
7151 leency 257
					image.move(MOVE_DOWN);
258
					DrawCanvas();
7147 leency 259
					break;
7151 leency 260
				case BTN_FLIP_VER:
261
					image.move(FLIP_VER);
262
					DrawCanvas();
263
					break;
264
				case BTN_FLIP_HOR:
265
					image.move(FLIP_HOR);
266
					DrawCanvas();
267
					break;
7265 leency 268
				case BTN_TEST_ICON:
269
					EventTestIcon();
270
					break;
7187 leency 271
				case BTN_PENCIL:
272
					setCurrentTool(TOOL_PENCIL);
273
					break;
7096 leency 274
				case BTN_PICK:
7186 leency 275
					setCurrentTool(TOOL_PIPETTE);
7096 leency 276
					break;
7156 leency 277
				case BTN_FILL:
7186 leency 278
					setCurrentTool(TOOL_FILL);
7156 leency 279
					break;
7186 leency 280
				case BTN_LINE:
281
					setCurrentTool(TOOL_LINE);
282
					break;
283
				case BTN_RECT:
284
					setCurrentTool(TOOL_RECT);
285
					break;
7259 leency 286
				case BTN_BAR:
287
					setCurrentTool(TOOL_BAR);
288
					break;
7253 leency 289
				case BTN_SELECT:
290
					setCurrentTool(TOOL_SELECT);
291
					break;
7260 leency 292
				case BTN_SCREEN_COPY:
293
					setCurrentTool(TOOL_SCREEN_COPY);
294
					break;
7152 leency 295
				case CLOSE_BTN:
7257 leency 296
					EventExitIconEdit();
7152 leency 297
					break;
7089 leency 298
			}
299
			break;
300
 
301
		case evKey:
302
			GetKeys();
7253 leency 303
 
304
			if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0)
305
				tools[currentTool].onKeyEvent(key_scancode);
306
 
7186 leency 307
			if (key_scancode == SCAN_CODE_ESC) setCurrentTool(TOOL_PENCIL);
7187 leency 308
			if (key_scancode == SCAN_CODE_KEY_P) setCurrentTool(TOOL_PENCIL);
7186 leency 309
			if (key_scancode == SCAN_CODE_KEY_I) setCurrentTool(TOOL_PIPETTE);
7187 leency 310
			if (key_scancode == SCAN_CODE_KEY_F) setCurrentTool(TOOL_FILL);
311
			if (key_scancode == SCAN_CODE_KEY_L) setCurrentTool(TOOL_LINE);
312
			if (key_scancode == SCAN_CODE_KEY_R) setCurrentTool(TOOL_RECT);
7260 leency 313
			if (key_scancode == SCAN_CODE_KEY_B) setCurrentTool(TOOL_BAR);
314
			if (key_scancode == SCAN_CODE_KEY_S) setCurrentTool(TOOL_SELECT);
7204 leency 315
 
7265 leency 316
			if (key_scancode == SCAN_CODE_KEY_T) EventTestIcon();
317
 
7253 leency 318
			if (key_scancode == SCAN_CODE_KEY_Z) && (key_modifier&KEY_LCTRL) actionsHistory.undoLastAction();
319
			if (key_scancode == SCAN_CODE_KEY_Y) && (key_modifier&KEY_LCTRL) actionsHistory.redoLastAction();
7204 leency 320
 
7253 leency 321
			if (key_scancode == SCAN_CODE_MINUS) {zoom.dec(); DrawEditArea();}
322
			if (key_scancode == SCAN_CODE_PLUS)  {zoom.inc();  DrawEditArea();}
323
 
7089 leency 324
			break;
325
 
326
		case evReDraw:
327
			draw_window();
328
			break;
329
	}
330
}
331
 
7096 leency 332
void DrawToolbarButton(dword _id, _x, _icon_n)
333
{
7255 leency 334
	DrawWideRectangle(_x, 4, 22, 22, 3, semi_white);
7152 leency 335
	DefineHiddenButton(_x, 4, 21, 21, _id);
336
	img_draw stdcall(skin.image, _x+3, 7, 16, 16, 0, _icon_n*16);
7096 leency 337
}
338
 
7187 leency 339
void DrawLeftPanelButton(dword _id, _y, _icon_n)
340
{
341
	int x = 5;
7255 leency 342
	DrawWideRectangle(x, _y, 22, 22, 3, semi_white);
7187 leency 343
	DefineHiddenButton(x, _y, 21, 21, _id);
344
	img_draw stdcall(skin.image, x+3, _y+3, 16, 16, 0, _icon_n*16);
345
}
346
 
7148 leency 347
void DrawStatusBar()
348
{
7243 leency 349
	zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6);
7150 leency 350
 
7151 leency 351
	sprintf(#param,"Canvas: %ix%i", image.rows, image.columns);
7150 leency 352
	WriteText(wrapper.x+wrapper.w-calc(strlen(#param)*8), zoom.y+2, 0x90, system.color.work_text, #param);
7148 leency 353
}
354
 
7089 leency 355
void draw_window()
356
{
7096 leency 357
	incn tx;
7089 leency 358
	system.color.get();
7151 leency 359
	DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x33, system.color.work, T_TITLE, 0);
7089 leency 360
	GetProcessInfo(#Form, SelfInfo);
7152 leency 361
	if (Form.status_window>2) return;
362
	if (Form.width  < 560) { MoveSize(OLD,OLD,560,OLD); return; }
363
	if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
364
 
7150 leency 365
	right_bar.x = Form.cwidth - right_bar.w;
7200 leency 366
	b_color_gradient.x = b_last_colors.x = b_default_palette.x = right_bar.x;
7255 leency 367
	DrawBar(0, TOOLBAR_H-1, Form.cwidth, 1, system.color.work_graph);
7089 leency 368
 
7255 leency 369
	tx.n = 5-TB_ICON_PADDING;
7148 leency 370
	DrawToolbarButton(BTN_NEW,    tx.inc(TB_ICON_PADDING), 2); //not implemented
371
	DrawToolbarButton(BTN_OPEN,   tx.inc(TB_ICON_PADDING), 0); //not implemented
7151 leency 372
	DrawToolbarButton(BTN_SAVE,   tx.inc(TB_ICON_PADDING), 5);
7207 leency 373
	DrawToolbarButton(BTN_MOVE_LEFT,  tx.inc(TB_ICON_PADDING+8), 30);
7096 leency 374
	DrawToolbarButton(BTN_MOVE_RIGHT, tx.inc(TB_ICON_PADDING),   31);
7147 leency 375
	DrawToolbarButton(BTN_MOVE_UP,    tx.inc(TB_ICON_PADDING),   32);
376
	DrawToolbarButton(BTN_MOVE_DOWN,  tx.inc(TB_ICON_PADDING),   33);
377
 
7155 leency 378
	DrawToolbarButton(BTN_FLIP_HOR,   tx.inc(TB_ICON_PADDING+8), 34);
379
	DrawToolbarButton(BTN_FLIP_VER,   tx.inc(TB_ICON_PADDING),   35);
7265 leency 380
 
381
	DrawToolbarButton(BTN_TEST_ICON,  tx.inc(TB_ICON_PADDING+8), 12);
7155 leency 382
	// DrawToolbarButton(BTN_ROTATE_LEFT,   tx.inc(TB_ICON_PADDING), 36); //not implemented
383
	// DrawToolbarButton(BTN_ROTATE_RIGHT,  tx.inc(TB_ICON_PADDING), 37); //not implemented
7148 leency 384
 
7187 leency 385
	DrawLeftPanel();
7186 leency 386
 
7150 leency 387
	DrawEditArea();
7096 leency 388
 
7155 leency 389
	DrawActiveColor(right_bar.y);
7200 leency 390
	DrawColorPallets();
7089 leency 391
 
7148 leency 392
	DrawStatusBar();
7089 leency 393
}
394
 
7187 leency 395
void DrawLeftPanel()
396
{
397
	incn ty;
7255 leency 398
	ty.n = right_bar.y - TB_ICON_PADDING;
7187 leency 399
	DrawLeftPanelButton(BTN_PENCIL, ty.inc(TB_ICON_PADDING), 38);
400
	DrawLeftPanelButton(BTN_PICK,   ty.inc(TB_ICON_PADDING), 39);
401
	DrawLeftPanelButton(BTN_FILL,   ty.inc(TB_ICON_PADDING), 40);
402
	DrawLeftPanelButton(BTN_LINE,   ty.inc(TB_ICON_PADDING), 41);
403
	DrawLeftPanelButton(BTN_RECT,   ty.inc(TB_ICON_PADDING), 42);
7259 leency 404
	DrawLeftPanelButton(BTN_BAR,    ty.inc(TB_ICON_PADDING), 43);
405
	DrawLeftPanelButton(BTN_SELECT, ty.inc(TB_ICON_PADDING), 44);
7260 leency 406
	DrawLeftPanelButton(BTN_SCREEN_COPY, ty.inc(TB_ICON_PADDING), 45);
7255 leency 407
	DrawRectangle3D(5, currentTool*TB_ICON_PADDING+right_bar.y, 16+3+2, 16+3+2, 0x333333, 0x777777);
7187 leency 408
}
409
 
7151 leency 410
void DrawEditArea()
7089 leency 411
{
7150 leency 412
	dword color1=0xC0C0C0;
7155 leency 413
	int top_side;
414
	int left_side;
7089 leency 415
 
7194 leency 416
	wrapper.w = Form.cwidth - right_bar.w - 10 - wrapper.x;
7150 leency 417
	wrapper.h = Form.cheight - TOOLBAR_H - 35;
7148 leency 418
 
7150 leency 419
	//canvas{
7151 leency 420
	canvas.w = image.columns * zoom.value;
421
	canvas.h = image.rows * zoom.value;
422
	if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) {
7254 leency 423
		zoom.value--;
7151 leency 424
		DrawEditArea();
425
		return;
426
	}
427
	canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x;
428
	canvas.y = -zoom.value*image.rows+wrapper.h/2 + wrapper.y;
429
	DrawCanvas();
7150 leency 430
	//}
7089 leency 431
 
7155 leency 432
	left_side = canvas.x-wrapper.x-1;
433
	top_side = canvas.y-wrapper.y-1;
7148 leency 434
 
7155 leency 435
	DrawRectangle(wrapper.x-1, wrapper.y-1, wrapper.w, wrapper.h, system.color.work_graph);
7150 leency 436
 
7155 leency 437
	if (left_side>0)
7150 leency 438
	{
7155 leency 439
		DrawBar(wrapper.x, wrapper.y, wrapper.w-1, top_side, color1); //top
440
		DrawBar(wrapper.x, wrapper.y+wrapper.h-top_side-1, wrapper.w-1, top_side, color1); //bottom
7150 leency 441
	}
7155 leency 442
	if (top_side>0)
7150 leency 443
	{
7190 leency 444
		//left
445
		DrawBar(wrapper.x, wrapper.y+top_side, left_side,
446
			wrapper.h-top_side-top_side, color1);
447
		//right
448
		DrawBar(wrapper.x+wrapper.w-left_side-1, wrapper.y+top_side, left_side,
449
			wrapper.h-top_side-top_side, color1);
7150 leency 450
	}
7194 leency 451
	DrawRectangle(canvas.x-1, canvas.y-1, canvas.w+1, canvas.h+1, 0x808080);
7089 leency 452
}
453
 
454
void DrawActiveColor(dword iny)
455
{
7255 leency 456
	#define CELL 20
7089 leency 457
	static dword outy;
458
	if (iny != NULL) outy = iny;
7255 leency 459
	DrawFrame(right_bar.x, outy, CELL, CELL, NULL);
460
	DrawBar(right_bar.x+2, outy+2, CELL-4, CELL-4, color1);
7207 leency 461
	sprintf(#param, "%A", color1);
7089 leency 462
	EDI = system.color.work;
7148 leency 463
	WriteText(right_bar.x + 30, outy + 3, 0xD0, system.color.work_text, #param+4);
7151 leency 464
 
7255 leency 465
	DrawFrame(right_bar.x+110, outy, CELL, CELL, NULL);
466
	DrawBar(right_bar.x+110+2, outy+2, CELL-4, CELL-4, color2);
7207 leency 467
	sprintf(#param, "%A", color2);
7151 leency 468
	EDI = system.color.work;
469
	WriteText(right_bar.x+110 + 30, outy + 3, 0xD0, system.color.work_text, #param+4);
7200 leency 470
	DrawCurrentColorGradientByLightness();
7089 leency 471
}
472
 
7200 leency 473
void DrawCurrentColorGradientByLightness()
7194 leency 474
{
475
	int i;
476
	int w = right_bar.w-10/2;
477
	for (i=0; i
7200 leency 478
		DrawBar(b_color_gradient.x+i, b_color_gradient.y,
7207 leency 479
			1, b_color_gradient.h, MixColors(color1,0xFFFfff,255*i/w));
7194 leency 480
	for (i=0 ; i<=w; i++)
7200 leency 481
		DrawBar(b_color_gradient.x+w+w-i, b_color_gradient.y,
7207 leency 482
			1, b_color_gradient.h, MixColors(color1,0x000000,255*i/w));
7194 leency 483
}
484
 
7200 leency 485
void DrawColorPallets()
7089 leency 486
{
7155 leency 487
	int r, c, i=0;
488
	//Last used colors
489
	for (r = 0; r < 2; r++)
490
	{
7194 leency 491
		for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++)
7155 leency 492
		{
7200 leency 493
			DrawBar(c*COLSIZE + b_last_colors.x, r*COLSIZE + b_last_colors.y,
494
				COLSIZE, COLSIZE, last_used_colors[i]);
7155 leency 495
		}
496
	}
497
	i=0;
498
	//Default colors
7089 leency 499
	for (r = 0; r < 9; r++)
500
	{
7194 leency 501
		for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++)
7089 leency 502
		{
7200 leency 503
			DrawBar(c*COLSIZE + b_default_palette.x, r*COLSIZE + b_default_palette.y,
504
				COLSIZE, COLSIZE, default_palette[PALLETE_SIZE-i]);
7089 leency 505
		}
506
	}
507
}
508
 
7257 leency 509
void DrawCanvasPixel(dword _r,_c,_color)
510
{
511
	DrawBar(_c*zoom.value + canvas.x, _r*zoom.value + canvas.y,
512
	zoom.value, zoom.value, _color);
513
}
514
 
7155 leency 515
void DrawCanvas()
516
{
517
	int r, c;
7257 leency 518
	dword color;
519
 
520
	if ((currentTool != TOOL_NONE) && (tools[currentTool].onCanvasDraw != 0))
521
	{
522
		tools[currentTool].onCanvasDraw();
523
	}
524
 
7155 leency 525
	for (r = 0; r < image.rows; r++)
526
	{
527
		for (c = 0; c < image.columns; c++)
528
		{
7257 leency 529
			if (image.pixel_state.is_drawable(r,c))
530
				DrawCanvasPixel(r, c, image.get_pixel(r,c));
7155 leency 531
		}
532
	}
7257 leency 533
	image.pixel_state.reset_and_set_all_drawable();
7186 leency 534
 
7200 leency 535
	DrawPreview();
7155 leency 536
}
537
 
7200 leency 538
void DrawPreview()
539
{
540
	int x = right_bar.x;
541
	int y = wrapper.y + wrapper.h - image.rows-2;
542
	DrawRectangle(x, y, image.columns+1, image.rows+1, system.color.work_graph);
543
	_PutImage(x+1,y+1, image.columns, image.rows, image.get_image());
544
}
7155 leency 545
 
7200 leency 546
dword GetPixelUnderMouse()
547
{
548
	return GetPixelColorFromScreen(mouse.x + Form.left + 5, mouse.y + Form.top + skin_height);
549
}
550
 
7265 leency 551
int preview_size = 128;
552
void DrawImageWithBg(dword _x, _y, _col_to)
553
{
554
	_x *= preview_size;
555
	_y *= preview_size;
556
	DrawWideRectangle(_x,_y, preview_size, preview_size, preview_size-image.columns/2, _col_to);
557
	_PutImage(preview_size - image.columns / 2 + _x, preview_size - image.rows / 2 + _y,
558
		image.columns, image.rows, image.get_image_with_replaced_color(color2, _col_to));
559
}
560
 
561
void ShowWindow_TestIcon()
562
{
563
	loop() switch(WaitEvent())
564
	{
565
		case evButton:
566
			if (GetButtonID()) ExitProcess();
567
			break;
568
 
569
		case evKey:
570
			GetKeys();
571
			if (key_scancode == SCAN_CODE_ESC) ExitProcess();
572
			break;
573
 
574
		case evReDraw:
575
			DefineAndDrawWindow(Form.left+100, Form.top+100, preview_size*2+9,
576
				preview_size*2+skin_height+4, 0x74, NULL, "Test Icon", 0);
577
			DrawImageWithBg(0, 0, 0x000000);
578
			DrawImageWithBg(1, 0, 0xFFFfff);
579
			DrawImageWithBg(0, 1, GetPixelColorFromScreen(0, 0));
580
			DrawImageWithBg(1, 1, system.color.work);
581
			break;
582
	}
583
}
584
 
7089 leency 585
//===================================================//
586
//                                                   //
587
//                      EVENTS                       //
588
//                                                   //
589
//===================================================//
590
 
7257 leency 591
void EventSaveIconToFile()
7150 leency 592
{
7257 leency 593
	int i=0;
594
	char save_file_name[4096];
595
	char save_path_stable[4096];
596
	strcpy(#save_path_stable, "/tmp0/1");
597
	do {
598
		i++;
599
		sprintf(#save_file_name, "%s/saved_icon_%i.png", #save_path_stable, i);
600
	} while (file_exists(#save_file_name));
601
	save_image(image.get_image(), image.columns, image.rows, #save_file_name);
7150 leency 602
}
7151 leency 603
 
7257 leency 604
void EventCleanCanvas()
605
{
606
	EventSaveIconToFile();
607
	image.create(32, 32);
608
	DrawCanvas();
609
}
610
 
611
void EventExitIconEdit()
612
{
613
	EventSaveIconToFile();
614
	ExitProcess();
615
}
616
 
7155 leency 617
void EventSetActiveColor(int _number, _color)
7151 leency 618
{
619
	int i;
7155 leency 620
	for (i=13*2-1; i>0; i--) {
621
		last_used_colors[i] = last_used_colors[i-1];
622
	}
623
	last_used_colors[0] = _color;
7151 leency 624
 
7207 leency 625
	if (_number == 1) color1 = _color;
626
	if (_number == 2) color2 = _color;
7155 leency 627
 
628
	DrawActiveColor(NULL);
7200 leency 629
	DrawColorPallets();
7156 leency 630
}
7257 leency 631
 
7265 leency 632
void EventTestIcon()
633
{
634
	CreateThread(#ShowWindow_TestIcon, #test_icon_stak+4092);
635
}
636
 
637
stop:
638
 
639
char test_icon_stak[4096];