Subversion Repositories Kolibri OS

Rev

Rev 7373 | Rev 7444 | 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
 
7267 leency 7
#define MEMSIZE 4096*500
7089 leency 8
 
9
#include "../lib/gui.h"
7151 leency 10
#include "../lib/random.h"
11
#include "../lib/mem.h"
7262 leency 12
#include "../lib/cursor.h"
7255 leency 13
 
7096 leency 14
#include "../lib/obj/libimg.h"
7255 leency 15
#include "../lib/obj/box_lib.h"
16
 
7089 leency 17
#include "../lib/patterns/rgb.h"
7253 leency 18
#include "../lib/patterns/libimg_load_skin.h"
7089 leency 19
 
7151 leency 20
#include "colors_mas.h"
21
 
7359 leency 22
#ifndef AUTOBUILD
7358 leency 23
#include "lang.h--"
7359 leency 24
#endif
7358 leency 25
 
7089 leency 26
//===================================================//
27
//                                                   //
28
//                       DATA                        //
29
//                                                   //
30
//===================================================//
31
 
7358 leency 32
#ifdef LANG_RUS
33
#define T_NOTIFY_OPEN "'IconEdit
7422 leency 34
‚ ¤ ­­ë© ¬®¬¥­â IconEdit ¬®¦¥â ®âªà뢠âì ⮫쪮 ¨ª®­ª¨, ᮧ¤ ­­ë¥ ¢ á ¬®¬ । ªâ®à¥.
35
…᫨ ­ã¦­® ®âªàëâì ¤à㣮¥ ¨§®¡à ¦¥­¨¥, ¢®á¯®«ì§ã©â¥áì ¨­áâà㬥­â®¬ <”®â® ¯¯ à â>
36
¤«ï § å¢ â  ª à⨭ª¨ á íªà ­ .' -Wt"
7358 leency 37
#else
38
#define T_NOTIFY_OPEN "'IconEdit
39
You can open only files created in IconEdit for now!
40
In other case please use  tool to get an image from screen.' -Wt"
41
#endif
42
 
43
 
7422 leency 44
#define T_TITLE "Icon Editor 0.57b Alpha"
7096 leency 45
 
7271 leency 46
#define TOPBAR_H    24+8
47
#define LEFTBAR_W 16+5+5+3+3
7096 leency 48
#define PALLETE_SIZE 116
7089 leency 49
 
7194 leency 50
#define PAL_ITEMS_X_COUNT 13
51
#define COLSIZE 18
7200 leency 52
#define RIGHT_BAR_W PAL_ITEMS_X_COUNT*COLSIZE
7187 leency 53
 
7253 leency 54
#define TO_CANVAS_X(xval) xval - canvas.x/zoom.value
55
#define TO_CANVAS_Y(yval) yval - canvas.y/zoom.value
56
 
7200 leency 57
block canvas = { NULL, NULL, NULL, NULL };
7271 leency 58
block wrapper = { LEFTBAR_W, TOPBAR_H, NULL, NULL };
59
block right_bar = { NULL, 10+TOPBAR_H, RIGHT_BAR_W+10, NULL };
7200 leency 60
 
7422 leency 61
dword linear_gradient[RIGHT_BAR_W];
62
block b_color_gradient = {NULL, 40+TOPBAR_H, RIGHT_BAR_W, 25};
63
//block b_opacity_gradient = {NULL, 75+TOPBAR_H, RIGHT_BAR_W, 15};
64
block b_last_colors = {NULL, 75+TOPBAR_H, RIGHT_BAR_W, COLSIZE};
65
block b_default_palette = {NULL, COLSIZE+10+75+TOPBAR_H, RIGHT_BAR_W, COLSIZE*9};
7200 leency 66
 
7422 leency 67
dword transparent = 0xBFCAD2;
7207 leency 68
dword color1 = 0x000000;
7255 leency 69
dword color2 = 0xBFCAD2;
7207 leency 70
dword tool_color;
7089 leency 71
 
7257 leency 72
signed hoverX;
73
signed hoverY;
74
signed priorHoverX;
75
signed priorHoverY;
76
bool canvasMouseMoved = false;
77
 
7089 leency 78
enum {
7096 leency 79
	BTN_NEW = 40,
80
	BTN_OPEN,
81
	BTN_SAVE,
82
	BTN_MOVE_LEFT,
83
	BTN_MOVE_RIGHT,
84
	BTN_MOVE_UP,
85
	BTN_MOVE_DOWN,
86
	BTN_FLIP_HOR,
87
	BTN_FLIP_VER,
88
	BTN_ROTATE_LEFT,
89
	BTN_ROTATE_RIGHT,
7265 leency 90
	BTN_TEST_ICON,
7187 leency 91
	BTN_PENCIL,
7096 leency 92
	BTN_PICK,
7156 leency 93
	BTN_FILL,
7186 leency 94
	BTN_LINE,
95
	BTN_RECT,
7259 leency 96
	BTN_BAR,
7253 leency 97
	BTN_SELECT,
7260 leency 98
	BTN_SCREEN_COPY,
7253 leency 99
	BTN_ZOOM_IN,
100
	BTN_ZOOM_OUT,
7274 leency 101
	BTN_CANVAS_RESIZE,
7275 leency 102
	BTN_CROP,
7155 leency 103
	BTNS_PALETTE_COLOR_MAS = 100,
104
	BTNS_LAST_USED_COLORS = 400
7089 leency 105
};
106
 
107
proc_info Form;
7255 leency 108
dword semi_white;
7422 leency 109
bool bg_dark=false;
7089 leency 110
 
7243 leency 111
more_less_box zoom = { 11, 1, 40, "Zoom" };
7150 leency 112
 
7152 leency 113
dword default_palette[] = {
7190 leency 114
0x330000,0x331900,0x333300,0x193300,0x003300,0x003319,0x003333,0x001933,0x000033,0x190033,
115
0x330033,0x330019,0x000000,0x660000,0x663300,0x666600,0x336600,0x006600,0x006633,0x006666,
116
0x003366,0x000066,0x330066,0x660066,0x660033,0x202020,0x990000,0x994C00,0x999900,0x4C9900,
117
0x009900,0x00994C,0x009999,0x004C99,0x000099,0x4C0099,0x990099,0x99004C,0x404040,0xCC0000,
118
0xCC6600,0xCCCC00,0x66CC00,0x00CC00,0x00CC66,0x00CCCC,0x0066CC,0x0000CC,0x6600CC,0xCC00CC,
119
0xCC0066,0x606060,0xFF0000,0xFF8000,0xFFFF00,0x80FF00,0x00FF00,0x00FF80,0x00FFFF,0x0080FF,
120
0x0000FF,0x7F00FF,0xFF00FF,0xFF007F,0x808080,0xFF3333,0xFF9933,0xFFFF33,0x99FF33,0x33FF33,
121
0x33FF99,0x33FFFF,0x3399FF,0x3333FF,0x9933FF,0xFF33FF,0xFF3399,0xA0A0A0,0xFF6666,0xFFB266,
122
0xFFFF66,0xB2FF66,0x66FF66,0x66FFB2,0x66FFFF,0x66B2FF,0x6666FF,0xB266FF,0xFF66FF,0xFF66B2,
123
0xC0C0C0,0xFF9999,0xFFCC99,0xFFFF99,0xCCFF99,0x99FF99,0x99FFCC,0x99FFFF,0x99CCFF,0x9999FF,
124
0xCC99FF,0xFF99FF,0xFF99CC,0xE0E0E0,0xFFCCCC,0xFFE5CC,0xFFFFCC,0xE5FFCC,0xCCFFCC,0xCCFFE5,
125
0xCCFFFF,0xCCE5FF,0xCCCCFF,0xE5CCFF,0xFFCCFF,0xFFCCE5,0xFFFFFF
7089 leency 126
};
7422 leency 127
 
128
#define LAST_USED_MAX 13
129
dword last_used_colors[LAST_USED_MAX] = {
7190 leency 130
0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,
7422 leency 131
0xFFFFFF,0xFFFFFF,0xFFFFFF
7155 leency 132
};
7089 leency 133
 
7262 leency 134
CustomCursor Cursor;
135
dword CursorBar = FROM "cursors/bar.cur";
136
dword CursorFill = FROM "cursors/fill.cur";
137
dword CursorLine = FROM "cursors/line.cur";
138
dword CursorPencil = FROM "cursors/pencil.cur";
139
dword CursorPipette = FROM "cursors/pipette.cur";
140
dword CursorRectangle = FROM "cursors/rectangle.cur";
141
dword CursorSelect = FROM "cursors/select.cur";
142
 
7155 leency 143
_image image;
7148 leency 144
 
7204 leency 145
#include "actions_history.h"
146
 
147
_ActionsHistory actionsHistory;
7151 leency 148
 
7254 leency 149
#include "tools.h"
7274 leency 150
#include "canvas_resize.h"
7156 leency 151
 
7089 leency 152
//===================================================//
153
//                                                   //
154
//                       CODE                        //
155
//                                                   //
156
//===================================================//
157
 
7266 leency 158
libimg_image top_icons;
159
libimg_image left_icons;
160
 
7089 leency 161
void main()
162
{
163
	word btn;
7257 leency 164
	libimg_image open_image;
7422 leency 165
	dword tmp_bg_col;
7089 leency 166
 
7096 leency 167
	load_dll(libio,  #libio_init,  1);
168
	load_dll(libimg, #libimg_init, 1);
7255 leency 169
	load_dll(boxlib, #box_lib_init,0);
170
 
7266 leency 171
	Libimg_LoadImage(#top_icons, "/sys/icons16.png");
172
	Libimg_LoadImage(#left_icons, "/sys/icons16.png");
173
 
7255 leency 174
	system.color.get();
7422 leency 175
 
7266 leency 176
	semi_white = MixColors(system.color.work, 0xFFFfff, 96);
177
	Libimg_ReplaceColor(top_icons.image, top_icons.w, top_icons.h, 0xffFFFfff, semi_white);
178
	Libimg_ReplaceColor(top_icons.image, top_icons.w, top_icons.h, 0xffCACBD6, MixColors(semi_white, 0, 220));
7089 leency 179
 
7266 leency 180
	Libimg_ReplaceColor(left_icons.image, left_icons.w, left_icons.h, 0xffFFFfff, system.color.work);
181
	Libimg_ReplaceColor(left_icons.image, left_icons.w, left_icons.h, 0xffCACBD6, MixColors(system.color.work, 0, 200));
182
 
7422 leency 183
	//fix line and rectandle color for dark skins
184
	if (GrayScaleImage(#system.color.work,1,1)<65) bg_dark=true; else bg_dark=false;
185
	if (bg_dark) Libimg_ReplaceColor(left_icons.image, left_icons.w, left_icons.h, 0xff545454, 0xffD3D3D4);
186
 
187
	EventSetActiveColor(1, color1);
188
 
7254 leency 189
	if (!param[0]) {
190
		image.create(32, 32);
191
	}
192
	else
193
	{
7151 leency 194
		Libimg_LoadImage(#open_image, #param);
7254 leency 195
 
196
		if (open_image.w*open_image.h>MAX_CELL_SIZE*MAX_CELL_SIZE) {
197
			notify("'Hey, this is just an icon editor,\nselected image is too big to open!' -E");
198
			ExitProcess();
7151 leency 199
		}
200
		else {
7422 leency 201
			image.create(open_image.h, open_image.w);
7254 leency 202
			image.set_image(open_image.imgsrc);
7151 leency 203
		}
204
	}
205
 
7204 leency 206
	actionsHistory.init();
207
 
7186 leency 208
	initTools();
209
	setCurrentTool(TOOL_PENCIL);
210
 
7096 leency 211
	SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER);
212
 
7089 leency 213
	loop() switch(WaitEvent())
214
	{
7096 leency 215
		case evMouse:
7274 leency 216
			if (Window_CanvasReSize.thread_exists()) break;
7096 leency 217
			mouse.get();
7186 leency 218
 
7207 leency 219
			if (mouse.lkm) tool_color = color1;
220
			if (mouse.pkm) tool_color = color2;
221
			if (mouse.mkm) break;
222
 
7257 leency 223
			hoverX = mouse.x - canvas.x / zoom.value;
224
			hoverY = mouse.y - canvas.y / zoom.value;
225
			if (hoverX<0) hoverX = 0;
226
			if (hoverY<0) hoverY = 0;
227
			if (hoverX>image.columns-1) hoverX = image.columns-1;
228
			if (hoverY>image.rows-1) hoverY = image.rows-1;
229
			canvasMouseMoved = false;
230
			if (priorHoverX != hoverX) canvasMouseMoved = true;
231
			if (priorHoverY != hoverY) canvasMouseMoved = true;
232
			priorHoverX = hoverX;
233
			priorHoverY = hoverY;
234
			//DrawBar(Form.cwidth-100, 3, 80, 12, 0xFFFfff);
235
			//WriteText(Form.cwidth-100, 3, 0x80, 0x000000,
236
			//	sprintf(#param, "%i %i", hoverX, hoverY));
237
 
7186 leency 238
			if (currentTool != TOOL_NONE)
239
				tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm);
240
 
7156 leency 241
			if (mouse.vert) {
7243 leency 242
				if (mouse.vert==65535) zoom.inc();
243
				if (mouse.vert==1) zoom.dec();
7152 leency 244
				DrawEditArea();
245
			}
7186 leency 246
 
7262 leency 247
			if (wrapper.hovered()) SetCursor();
248
			else Cursor.Restore();
249
 
7200 leency 250
			if (mouse.down) {
251
				if (b_color_gradient.hovered())
252
				|| (b_last_colors.hovered())
253
				|| (b_default_palette.hovered()) {
254
					if (mouse.key&MOUSE_LEFT) EventSetActiveColor(1, GetPixelUnderMouse());
255
					if (mouse.key&MOUSE_RIGHT) EventSetActiveColor(2, GetPixelUnderMouse());
256
				}
257
			}
258
 
7148 leency 259
			break;
7096 leency 260
 
7089 leency 261
		case evButton:
7274 leency 262
			if (Window_CanvasReSize.thread_exists()) break;
7148 leency 263
			btn = GetButtonID();
7253 leency 264
 
7255 leency 265
			if (zoom.click(btn)) DrawEditArea();
266
 
7096 leency 267
			switch(btn)
268
			{
7151 leency 269
				case BTN_NEW:
7274 leency 270
					EventCreateNewIcon();
7151 leency 271
					break;
272
				case BTN_OPEN:
7422 leency 273
					EventOpenIcon();
7151 leency 274
					break;
275
				case BTN_SAVE:
7257 leency 276
					EventSaveIconToFile();
7151 leency 277
					break;
7096 leency 278
				case BTN_MOVE_LEFT:
7267 leency 279
					EventMove(MOVE_LEFT);
7096 leency 280
					break;
281
				case BTN_MOVE_RIGHT:
7267 leency 282
					EventMove(MOVE_RIGHT);
7096 leency 283
					break;
7147 leency 284
				case BTN_MOVE_UP:
7267 leency 285
					EventMove(MOVE_UP);
7147 leency 286
					break;
287
				case BTN_MOVE_DOWN:
7267 leency 288
					EventMove(MOVE_DOWN);
7147 leency 289
					break;
7151 leency 290
				case BTN_FLIP_VER:
7267 leency 291
					EventMove(FLIP_VER);
7151 leency 292
					break;
293
				case BTN_FLIP_HOR:
7267 leency 294
					EventMove(FLIP_HOR);
7151 leency 295
					break;
7265 leency 296
				case BTN_TEST_ICON:
297
					EventTestIcon();
298
					break;
7187 leency 299
				case BTN_PENCIL:
300
					setCurrentTool(TOOL_PENCIL);
301
					break;
7096 leency 302
				case BTN_PICK:
7186 leency 303
					setCurrentTool(TOOL_PIPETTE);
7096 leency 304
					break;
7156 leency 305
				case BTN_FILL:
7186 leency 306
					setCurrentTool(TOOL_FILL);
7156 leency 307
					break;
7186 leency 308
				case BTN_LINE:
309
					setCurrentTool(TOOL_LINE);
310
					break;
311
				case BTN_RECT:
312
					setCurrentTool(TOOL_RECT);
313
					break;
7259 leency 314
				case BTN_BAR:
315
					setCurrentTool(TOOL_BAR);
316
					break;
7253 leency 317
				case BTN_SELECT:
318
					setCurrentTool(TOOL_SELECT);
319
					break;
7260 leency 320
				case BTN_SCREEN_COPY:
321
					setCurrentTool(TOOL_SCREEN_COPY);
322
					break;
7274 leency 323
				case BTN_CANVAS_RESIZE:
324
					notify("Sorry, not implemented yet.");
325
					break;
7275 leency 326
				case BTN_CROP:
327
					EventCrop();
328
					break;
7152 leency 329
				case CLOSE_BTN:
7257 leency 330
					EventExitIconEdit();
7152 leency 331
					break;
7089 leency 332
			}
333
			break;
334
 
335
		case evKey:
336
			GetKeys();
7253 leency 337
 
7422 leency 338
			if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL)
339
			{
340
				switch(key_scancode)
341
				{
342
					case SCAN_CODE_KEY_S:
343
						EventSaveIconToFile();
344
						break;
345
					case SCAN_CODE_KEY_O:
346
						EventOpenIcon();
347
						break;
348
				}
349
			}
350
 
351
			if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) {
352
				if (key_scancode == SCAN_CODE_DEL) EventCleanCanvas();
353
			}
354
 
7253 leency 355
			if (currentTool != TOOL_NONE) && (tools[currentTool].onKeyEvent != 0)
356
				tools[currentTool].onKeyEvent(key_scancode);
357
 
7187 leency 358
			if (key_scancode == SCAN_CODE_KEY_P) setCurrentTool(TOOL_PENCIL);
7186 leency 359
			if (key_scancode == SCAN_CODE_KEY_I) setCurrentTool(TOOL_PIPETTE);
7187 leency 360
			if (key_scancode == SCAN_CODE_KEY_F) setCurrentTool(TOOL_FILL);
361
			if (key_scancode == SCAN_CODE_KEY_L) setCurrentTool(TOOL_LINE);
362
			if (key_scancode == SCAN_CODE_KEY_R) setCurrentTool(TOOL_RECT);
7260 leency 363
			if (key_scancode == SCAN_CODE_KEY_B) setCurrentTool(TOOL_BAR);
364
			if (key_scancode == SCAN_CODE_KEY_S) setCurrentTool(TOOL_SELECT);
7204 leency 365
 
7265 leency 366
			if (key_scancode == SCAN_CODE_KEY_T) EventTestIcon();
367
 
7267 leency 368
			if (key_scancode == SCAN_CODE_KEY_Z) actionsHistory.undoLastAction();
369
			if (key_scancode == SCAN_CODE_KEY_Y) actionsHistory.redoLastAction();
7204 leency 370
 
7253 leency 371
			if (key_scancode == SCAN_CODE_MINUS) {zoom.dec(); DrawEditArea();}
7274 leency 372
			if (key_scancode == SCAN_CODE_PLUS)  {zoom.inc(); DrawEditArea();}
7253 leency 373
 
7089 leency 374
			break;
375
 
376
		case evReDraw:
7274 leency 377
			Window_CanvasReSize.thread_exists();
7275 leency 378
			DrawWindow();
7089 leency 379
			break;
380
	}
381
}
382
 
7266 leency 383
void DrawTopPanelButton(dword _id, _x, _icon_n)
7096 leency 384
{
7255 leency 385
	DrawWideRectangle(_x, 4, 22, 22, 3, semi_white);
7271 leency 386
	PutPixel(_x,4,system.color.work);
387
	PutPixel(_x,4+21,system.color.work);
388
	PutPixel(_x+21,4,system.color.work);
389
	PutPixel(_x+21,4+21,system.color.work);
7152 leency 390
	DefineHiddenButton(_x, 4, 21, 21, _id);
7266 leency 391
	img_draw stdcall(top_icons.image, _x+3, 7, 16, 16, 0, _icon_n*16);
7096 leency 392
}
393
 
7187 leency 394
void DrawLeftPanelButton(dword _id, _y, _icon_n)
395
{
396
	int x = 5;
7266 leency 397
	DrawRectangle(x, _y, 22-1, 22-1, system.color.work);
7187 leency 398
	DefineHiddenButton(x, _y, 21, 21, _id);
7266 leency 399
	img_draw stdcall(left_icons.image, x+3, _y+3, 16, 16, 0, _icon_n*16);
7187 leency 400
}
401
 
7148 leency 402
void DrawStatusBar()
403
{
7243 leency 404
	zoom.draw(wrapper.x, wrapper.y + wrapper.h + 6);
7150 leency 405
 
7275 leency 406
	sprintf(#param,"%i x %i", image.columns, image.rows);
7274 leency 407
	DrawCaptButton(
7275 leency 408
		wrapper.x+wrapper.w-calc(strlen(#param)*8) -6 - 1,
7274 leency 409
		zoom.y,
7275 leency 410
		calc(strlen(#param)*8)+6,
7274 leency 411
		18,
412
		BTN_CANVAS_RESIZE,
413
		system.color.work_button,
414
		system.color.work_button_text,
7275 leency 415
		#param
7274 leency 416
		);
7148 leency 417
}
418
 
7275 leency 419
void DrawWindow()
7089 leency 420
{
7266 leency 421
	#define GAP 27
422
	#define BLOCK_SPACE 10
7096 leency 423
	incn tx;
7089 leency 424
	system.color.get();
7271 leency 425
	DefineAndDrawWindow(115+random(100), 50+random(100), 700, 540, 0x73, NULL, T_TITLE, 0);
7089 leency 426
	GetProcessInfo(#Form, SelfInfo);
7152 leency 427
	if (Form.status_window>2) return;
428
	if (Form.width  < 560) { MoveSize(OLD,OLD,560,OLD); return; }
429
	if (Form.height < 430) { MoveSize(OLD,OLD,OLD,430); return; }
430
 
7150 leency 431
	right_bar.x = Form.cwidth - right_bar.w;
7200 leency 432
	b_color_gradient.x = b_last_colors.x = b_default_palette.x = right_bar.x;
7271 leency 433
	DrawBar(0, 0, Form.cwidth, TOPBAR_H-1, system.color.work);
434
	DrawBar(0, TOPBAR_H-1, Form.cwidth, 1, system.color.work_graph);
7089 leency 435
 
7266 leency 436
	tx.n = 5-GAP;
437
	DrawTopPanelButton(BTN_NEW,    tx.inc(GAP), 2); //not implemented
438
	DrawTopPanelButton(BTN_OPEN,   tx.inc(GAP), 0); //not implemented
439
	DrawTopPanelButton(BTN_SAVE,   tx.inc(GAP), 5);
440
	DrawTopPanelButton(BTN_MOVE_LEFT,  tx.inc(GAP+BLOCK_SPACE), 30);
441
	DrawTopPanelButton(BTN_MOVE_RIGHT, tx.inc(GAP),   31);
442
	DrawTopPanelButton(BTN_MOVE_UP,    tx.inc(GAP),   32);
443
	DrawTopPanelButton(BTN_MOVE_DOWN,  tx.inc(GAP),   33);
7147 leency 444
 
7266 leency 445
	DrawTopPanelButton(BTN_FLIP_HOR,   tx.inc(GAP+BLOCK_SPACE), 34);
446
	DrawTopPanelButton(BTN_FLIP_VER,   tx.inc(GAP),   35);
7265 leency 447
 
7266 leency 448
	DrawTopPanelButton(BTN_TEST_ICON,  tx.inc(GAP+BLOCK_SPACE), 12);
7275 leency 449
 
450
	DrawTopPanelButton(BTN_CROP,  tx.inc(GAP+BLOCK_SPACE), 46);
7266 leency 451
	// DrawTopPanelButton(BTN_ROTATE_LEFT,   tx.inc(GAP), 36); //not implemented
452
	// DrawTopPanelButton(BTN_ROTATE_RIGHT,  tx.inc(GAP), 37); //not implemented
7186 leency 453
 
7150 leency 454
	DrawEditArea();
7096 leency 455
 
7271 leency 456
	DrawBar(0, TOPBAR_H, LEFTBAR_W-1, Form.cheight - TOPBAR_H, system.color.work);
7274 leency 457
	DrawLeftPanel();
458
 
7271 leency 459
	DrawBar(wrapper.x+wrapper.w, TOPBAR_H, Form.cwidth-wrapper.x-wrapper.w,
460
		Form.cheight - TOPBAR_H, system.color.work);
7274 leency 461
	DrawActiveColor(right_bar.y);
462
	DrawColorPallets();
463
	DrawPreview();
464
 
7271 leency 465
	DrawBar(LEFTBAR_W-1, wrapper.y + wrapper.h, wrapper.w+1,
466
		Form.cheight - wrapper.y - wrapper.h, system.color.work);
7148 leency 467
	DrawStatusBar();
7089 leency 468
}
469
 
7187 leency 470
void DrawLeftPanel()
471
{
7266 leency 472
	#define GAP 28
7187 leency 473
	incn ty;
7266 leency 474
	ty.n = right_bar.y - GAP - 2;
475
	DrawLeftPanelButton(BTN_PENCIL, ty.inc(GAP), 38);
476
	DrawLeftPanelButton(BTN_PICK,   ty.inc(GAP), 39);
477
	DrawLeftPanelButton(BTN_FILL,   ty.inc(GAP), 40);
478
	DrawLeftPanelButton(BTN_LINE,   ty.inc(GAP), 41);
479
	DrawLeftPanelButton(BTN_RECT,   ty.inc(GAP), 42);
480
	DrawLeftPanelButton(BTN_BAR,    ty.inc(GAP), 43);
481
	DrawLeftPanelButton(BTN_SELECT, ty.inc(GAP), 44);
482
	DrawLeftPanelButton(BTN_SCREEN_COPY, ty.inc(GAP), 45);
483
	DrawRectangle3D(5, currentTool*GAP+right_bar.y-2, 16+3+2, 16+3+2, 0x333333, 0x777777);
7187 leency 484
}
485
 
7151 leency 486
void DrawEditArea()
7089 leency 487
{
7150 leency 488
	dword color1=0xC0C0C0;
7155 leency 489
	int top_side;
490
	int left_side;
7089 leency 491
 
7194 leency 492
	wrapper.w = Form.cwidth - right_bar.w - 10 - wrapper.x;
7271 leency 493
	wrapper.h = Form.cheight - TOPBAR_H - 35;
7148 leency 494
 
7150 leency 495
	//canvas{
7151 leency 496
	canvas.w = image.columns * zoom.value;
497
	canvas.h = image.rows * zoom.value;
498
	if (canvas.w+2 > wrapper.w) || (canvas.h+2 > wrapper.h) {
7254 leency 499
		zoom.value--;
7422 leency 500
		if (zoom.x) zoom.redraw();
7151 leency 501
		DrawEditArea();
502
		return;
503
	}
504
	canvas.x = -zoom.value*image.columns+wrapper.w/2 + wrapper.x;
505
	canvas.y = -zoom.value*image.rows+wrapper.h/2 + wrapper.y;
506
	DrawCanvas();
7150 leency 507
	//}
7089 leency 508
 
7155 leency 509
	left_side = canvas.x-wrapper.x-1;
510
	top_side = canvas.y-wrapper.y-1;
7148 leency 511
 
7155 leency 512
	DrawRectangle(wrapper.x-1, wrapper.y-1, wrapper.w, wrapper.h, system.color.work_graph);
7150 leency 513
 
7155 leency 514
	if (left_side>0)
7150 leency 515
	{
7155 leency 516
		DrawBar(wrapper.x, wrapper.y, wrapper.w-1, top_side, color1); //top
517
		DrawBar(wrapper.x, wrapper.y+wrapper.h-top_side-1, wrapper.w-1, top_side, color1); //bottom
7150 leency 518
	}
7155 leency 519
	if (top_side>0)
7150 leency 520
	{
7190 leency 521
		//left
522
		DrawBar(wrapper.x, wrapper.y+top_side, left_side,
523
			wrapper.h-top_side-top_side, color1);
524
		//right
525
		DrawBar(wrapper.x+wrapper.w-left_side-1, wrapper.y+top_side, left_side,
526
			wrapper.h-top_side-top_side, color1);
7150 leency 527
	}
7194 leency 528
	DrawRectangle(canvas.x-1, canvas.y-1, canvas.w+1, canvas.h+1, 0x808080);
7089 leency 529
}
530
 
531
void DrawActiveColor(dword iny)
532
{
7255 leency 533
	#define CELL 20
7089 leency 534
	static dword outy;
535
	if (iny != NULL) outy = iny;
7255 leency 536
	DrawFrame(right_bar.x, outy, CELL, CELL, NULL);
537
	DrawBar(right_bar.x+2, outy+2, CELL-4, CELL-4, color1);
7151 leency 538
 
7422 leency 539
	DrawFrame(right_bar.x+CELL+5, outy, CELL, CELL, NULL);
540
	DrawBar(right_bar.x+CELL+5+2, outy+2, CELL-4, CELL-4, color2);
541
 
542
	//sprintf(#param, "%A", color1);
543
	//WriteTextWithBg(right_bar.x+30, outy+3, 0xD0, system.color.work_text, #param+4, system.color.work);
544
	DrawCurrentColorGradient();
7089 leency 545
}
546
 
7422 leency 547
int lmax;
548
void GenerateCurrentColorGradient()
7194 leency 549
{
7422 leency 550
	int i, avg, rmax;
551
 
552
	rgb.DwordToRgb(color1);
553
	avg = 255 - calc(rgb.r + rgb.g + rgb.b / 3);
554
 
555
	lmax = b_color_gradient.w *avg/255 | 1;
556
	rmax = b_color_gradient.w - lmax | 1;
557
	if (lmax == 0) lmax=1;
558
	if (rmax == 0) rmax=1;
559
 
560
	for (i=0; i
561
		linear_gradient[i] = MixColors(color1,0xFFFfff,255*i/lmax);
562
	}
563
 
564
	for (i=0 ; i<=rmax; i++) {
565
		linear_gradient[lmax+rmax - i] = MixColors(color1,0x000000,255*i/rmax);
566
	}
567
}
568
 
569
void DrawCurrentColorGradient()
570
{
7194 leency 571
	int i;
7422 leency 572
	dword hitch_color=system.color.work;
573
	int hitch_x = b_color_gradient.x+lmax-1;
574
	if (lmax>b_color_gradient.w-2) hitch_x=b_color_gradient.x+b_color_gradient.w-3;
7271 leency 575
 
7422 leency 576
	for (i=0 ; i
577
		DrawBar(b_color_gradient.x+i, b_color_gradient.y, 1, b_color_gradient.h, linear_gradient[i]);
578
	}
7271 leency 579
	//current color marker
7422 leency 580
	DrawBar( b_color_gradient.x-1, b_color_gradient.y-2, b_color_gradient.w+4, 2, system.color.work);
581
 
582
	if (bg_dark) hitch_color=0xFFFfff; else hitch_color=0;
583
	DrawBar(hitch_x, b_color_gradient.y-2, 3,2, hitch_color);
7194 leency 584
}
585
 
7200 leency 586
void DrawColorPallets()
7089 leency 587
{
7155 leency 588
	int r, c, i=0;
589
	//Last used colors
7422 leency 590
	for (r = 0; r < LAST_USED_MAX/PAL_ITEMS_X_COUNT; r++)
7155 leency 591
	{
7194 leency 592
		for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++)
7155 leency 593
		{
7200 leency 594
			DrawBar(c*COLSIZE + b_last_colors.x, r*COLSIZE + b_last_colors.y,
595
				COLSIZE, COLSIZE, last_used_colors[i]);
7155 leency 596
		}
597
	}
598
	i=0;
599
	//Default colors
7089 leency 600
	for (r = 0; r < 9; r++)
601
	{
7194 leency 602
		for (c = 0; c < PAL_ITEMS_X_COUNT; c++, i++)
7089 leency 603
		{
7200 leency 604
			DrawBar(c*COLSIZE + b_default_palette.x, r*COLSIZE + b_default_palette.y,
605
				COLSIZE, COLSIZE, default_palette[PALLETE_SIZE-i]);
7089 leency 606
		}
607
	}
608
}
609
 
7257 leency 610
void DrawCanvasPixel(dword _r,_c,_color)
611
{
612
	DrawBar(_c*zoom.value + canvas.x, _r*zoom.value + canvas.y,
613
	zoom.value, zoom.value, _color);
614
}
615
 
7155 leency 616
void DrawCanvas()
617
{
618
	int r, c;
7257 leency 619
	dword color;
620
 
621
	if ((currentTool != TOOL_NONE) && (tools[currentTool].onCanvasDraw != 0))
622
	{
623
		tools[currentTool].onCanvasDraw();
624
	}
625
 
7155 leency 626
	for (r = 0; r < image.rows; r++)
627
	{
628
		for (c = 0; c < image.columns; c++)
629
		{
7257 leency 630
			if (image.pixel_state.is_drawable(r,c))
631
				DrawCanvasPixel(r, c, image.get_pixel(r,c));
7155 leency 632
		}
633
	}
7257 leency 634
	image.pixel_state.reset_and_set_all_drawable();
7186 leency 635
 
7200 leency 636
	DrawPreview();
7155 leency 637
}
638
 
7200 leency 639
void DrawPreview()
640
{
641
	int x = right_bar.x;
642
	int y = wrapper.y + wrapper.h - image.rows-2;
643
	DrawRectangle(x, y, image.columns+1, image.rows+1, system.color.work_graph);
644
	_PutImage(x+1,y+1, image.columns, image.rows, image.get_image());
645
}
7155 leency 646
 
7200 leency 647
dword GetPixelUnderMouse()
648
{
649
	return GetPixelColorFromScreen(mouse.x + Form.left + 5, mouse.y + Form.top + skin_height);
650
}
651
 
7265 leency 652
int preview_size = 128;
653
void DrawImageWithBg(dword _x, _y, _col_to)
654
{
655
	_x *= preview_size;
656
	_y *= preview_size;
657
	DrawWideRectangle(_x,_y, preview_size, preview_size, preview_size-image.columns/2, _col_to);
658
	_PutImage(preview_size - image.columns / 2 + _x, preview_size - image.rows / 2 + _y,
659
		image.columns, image.rows, image.get_image_with_replaced_color(color2, _col_to));
660
}
661
 
662
void ShowWindow_TestIcon()
663
{
7422 leency 664
	if (image.rows>=preview_size) || (image.columns>=preview_size) {
665
		notify("'IconEdit\nImage is too big for preview!' -tE");
666
		return;
667
	}
7265 leency 668
	loop() switch(WaitEvent())
669
	{
670
		case evButton:
671
			if (GetButtonID()) ExitProcess();
672
			break;
673
 
674
		case evKey:
675
			GetKeys();
676
			if (key_scancode == SCAN_CODE_ESC) ExitProcess();
677
			break;
678
 
679
		case evReDraw:
680
			DefineAndDrawWindow(Form.left+100, Form.top+100, preview_size*2+9,
681
				preview_size*2+skin_height+4, 0x74, NULL, "Test Icon", 0);
682
			DrawImageWithBg(0, 0, 0x000000);
683
			DrawImageWithBg(1, 0, 0xFFFfff);
684
			DrawImageWithBg(0, 1, GetPixelColorFromScreen(0, 0));
685
			DrawImageWithBg(1, 1, system.color.work);
686
			break;
687
	}
688
}
689
 
7089 leency 690
//===================================================//
691
//                                                   //
692
//                      EVENTS                       //
693
//                                                   //
694
//===================================================//
695
 
7274 leency 696
void EventCreateNewIcon()
697
{
698
	EventSaveIconToFile();
699
	Window_CanvasReSize.create();
700
}
701
 
7422 leency 702
void EventOpenIcon()
703
{
704
	//notify(T_NOTIFY_OPEN);
705
	RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path));
706
}
707
 
7257 leency 708
void EventSaveIconToFile()
7150 leency 709
{
7257 leency 710
	int i=0;
711
	char save_file_name[4096];
712
	char save_path_stable[4096];
713
	strcpy(#save_path_stable, "/tmp0/1");
714
	do {
715
		i++;
716
		sprintf(#save_file_name, "%s/saved_icon_%i.png", #save_path_stable, i);
717
	} while (file_exists(#save_file_name));
718
	save_image(image.get_image(), image.columns, image.rows, #save_file_name);
7150 leency 719
}
7151 leency 720
 
7257 leency 721
void EventCleanCanvas()
722
{
7274 leency 723
	image.create(image.rows, image.columns);
724
	actionsHistory.saveCurrentState();
7257 leency 725
	DrawCanvas();
726
}
727
 
728
void EventExitIconEdit()
729
{
730
	EventSaveIconToFile();
731
	ExitProcess();
732
}
733
 
7155 leency 734
void EventSetActiveColor(int _number, _color)
7151 leency 735
{
736
	int i;
7422 leency 737
	if (last_used_colors[0] == _color) return;
738
	for (i=LAST_USED_MAX-1; i>0; i--) {
7155 leency 739
		last_used_colors[i] = last_used_colors[i-1];
740
	}
741
	last_used_colors[0] = _color;
7151 leency 742
 
7207 leency 743
	if (_number == 1) color1 = _color;
744
	if (_number == 2) color2 = _color;
7155 leency 745
 
7422 leency 746
	if (b_color_gradient.hovered()) {
747
		lmax = mouse.x - b_color_gradient.x;
748
	}
749
	else {
750
		GenerateCurrentColorGradient();
751
	}
7155 leency 752
	DrawActiveColor(NULL);
7200 leency 753
	DrawColorPallets();
7156 leency 754
}
7257 leency 755
 
7265 leency 756
void EventTestIcon()
757
{
758
	CreateThread(#ShowWindow_TestIcon, #test_icon_stak+4092);
759
}
760
 
7267 leency 761
void EventMove(dword _action)
762
{
7273 leency 763
	if (selection.state) {
764
		selection.buf.move(_action);
7271 leency 765
		SelectTool_onCanvasDraw();
7267 leency 766
	}
767
	else {
768
		image.move(_action);
769
		DrawCanvas();
7271 leency 770
	}
771
	actionsHistory.saveCurrentState();
7267 leency 772
}
773
 
7275 leency 774
void EventCrop()
775
{
776
	if (selection.state) {
777
		EventSaveIconToFile();
778
		image.create(selection.buf.rows, selection.buf.columns);
779
		selection.move_to_point(0,0);
780
		selection.apply_to_image();
781
		selection.reset();
782
		actionsHistory.init();
783
		DrawWindow();
784
	}
785
	else {
786
		notify("'You need to select something before usnig crop tool.' -W");
787
	}
788
}
789
 
7265 leency 790
stop:
791
 
792
char test_icon_stak[4096];