Subversion Repositories Kolibri OS

Rev

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