Subversion Repositories Kolibri OS

Rev

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