Subversion Repositories Kolibri OS

Rev

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