Subversion Repositories Kolibri OS

Rev

Rev 7255 | Rev 7259 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7255 Rev 7257
Line 9... Line 9...
9
window colors
9
window colors
10
enhance icon
10
enhance icon
11
pipet aside color view
11
pipet aside color view
12
*/
12
*/
Line 13... Line 13...
13
 
13
 
Line 14... Line 14...
14
#define MEMSIZE 4096*100
14
#define MEMSIZE 4096*200
15
 
15
 
16
#include "../lib/gui.h"
16
#include "../lib/gui.h"
Line 29... Line 29...
29
//                                                   //
29
//                                                   //
30
//                       DATA                        //
30
//                       DATA                        //
31
//                                                   //
31
//                                                   //
32
//===================================================//
32
//===================================================//
Line 33... Line 33...
33
 
33
 
Line 34... Line 34...
34
#define T_TITLE "Icon Editor 0.47 Alpha"
34
#define T_TITLE "Icon Editor 0.48 Alpha"
35
 
35
 
36
#define TOOLBAR_H    24+8
36
#define TOOLBAR_H    24+8
37
#define PANEL_LEFT_W 16+5+5+3+3
37
#define PANEL_LEFT_W 16+5+5+3+3
Line 55... Line 55...
55
 
55
 
56
dword color1 = 0x000000;
56
dword color1 = 0x000000;
57
dword color2 = 0xBFCAD2;
57
dword color2 = 0xBFCAD2;
Line -... Line 58...
-
 
58
dword tool_color;
-
 
59
 
-
 
60
signed hoverX;
-
 
61
signed hoverY;
-
 
62
signed priorHoverX;
-
 
63
signed priorHoverY;
58
dword tool_color;
64
bool canvasMouseMoved = false;
59
 
65
 
60
enum {
66
enum {
61
	BTN_NEW = 40,
67
	BTN_NEW = 40,
62
	BTN_OPEN,
68
	BTN_OPEN,
Line 108... Line 114...
108
 
114
 
Line 109... Line 115...
109
_image image;
115
_image image;
Line 110... Line -...
110
 
-
 
111
#include "actions_history.h"
116
 
Line 112... Line 117...
112
 
117
#include "actions_history.h"
Line 113... Line 118...
113
libimg_image open_image;
118
 
114
_ActionsHistory actionsHistory;
119
_ActionsHistory actionsHistory;
115
 
120
 
116
#include "tools.h"
121
#include "tools.h"
117
 
122
 
Line 118... Line -...
118
//===================================================//
-
 
119
//                                                   //
-
 
120
//                       CODE                        //
-
 
121
//                                                   //
-
 
122
//===================================================//
-
 
123
 
-
 
124
 
-
 
125
void initTools() 
-
 
126
{
-
 
127
	tools[0].id = TOOL_PENCIL;
-
 
128
	tools[0].onMouseEvent = #PencilTool_onMouseEvent;
-
 
129
	tools[0].deactivate = #PencilTool_reset;
-
 
130
	
-
 
131
	tools[1].id = TOOL_PIPETTE;
-
 
132
	tools[1].activate = #PipetteTool_activate;
-
 
133
	tools[1].onMouseEvent = #PipetteTool_onMouseEvent;
-
 
134
	
-
 
135
	tools[2].id = TOOL_FILL;
-
 
136
	tools[2].onMouseEvent = #FillTool_onMouseEvent;
-
 
137
	
-
 
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;
-
 
143
	
-
 
144
	tools[4].id = TOOL_RECT;
-
 
145
	tools[4].activate = #SimpleFigureTool_Reset;
-
 
146
	tools[4].deactivate = #SimpleFigureTool_Reset;
-
 
147
	tools[4].onMouseEvent = #SimpleFigureTool_onMouseEvent;
-
 
148
	tools[4].onCanvasDraw = #SimpleFigureTool_onCanvasDraw;	
-
 
149
 
-
 
150
	tools[5].id = TOOL_SELECT;
-
 
151
	tools[5].activate = #SelectTool_activate;
-
 
152
	tools[5].deactivate = #SelectTool_deactivate;
123
//===================================================//
153
	tools[5].onMouseEvent = #SelectTool_onMouseEvent;
124
//                                                   //
154
	tools[5].onCanvasDraw = #SelectTool_onCanvasDraw;	
125
//                       CODE                        //
-
 
126
//                                                   //
Line 155... Line 127...
155
	tools[5].onKeyEvent = #SelectTool_onKeyEvent;	
127
//===================================================//
156
}
128
 
157
 
129
void main()
Line 200... Line 172...
200
			
172
			
201
			if (mouse.lkm) tool_color = color1;
173
			if (mouse.lkm) tool_color = color1;
202
			if (mouse.pkm) tool_color = color2;
174
			if (mouse.pkm) tool_color = color2;
Line -... Line 175...
-
 
175
			if (mouse.mkm) break;
-
 
176
 
-
 
177
			hoverX = mouse.x - canvas.x / zoom.value;
-
 
178
			hoverY = mouse.y - canvas.y / zoom.value;
-
 
179
			if (hoverX<0) hoverX = 0;
-
 
180
			if (hoverY<0) hoverY = 0;
-
 
181
			if (hoverX>image.columns-1) hoverX = image.columns-1;
-
 
182
			if (hoverY>image.rows-1) hoverY = image.rows-1;
-
 
183
			canvasMouseMoved = false;
-
 
184
			if (priorHoverX != hoverX) canvasMouseMoved = true;
-
 
185
			if (priorHoverY != hoverY) canvasMouseMoved = true;
-
 
186
			priorHoverX = hoverX;
-
 
187
			priorHoverY = hoverY;
-
 
188
			//DrawBar(Form.cwidth-100, 3, 80, 12, 0xFFFfff);
-
 
189
			//WriteText(Form.cwidth-100, 3, 0x80, 0x000000, 
203
			if (mouse.mkm) break;
190
			//	sprintf(#param, "%i %i", hoverX, hoverY));
204
 
191
 
Line 205... Line 192...
205
			if (currentTool != TOOL_NONE)
192
			if (currentTool != TOOL_NONE)
206
				tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm);
193
				tools[currentTool].onMouseEvent(mouse.x, mouse.y, mouse.lkm, mouse.pkm);
Line 228... Line 215...
228
			if (zoom.click(btn)) DrawEditArea();
215
			if (zoom.click(btn)) DrawEditArea();
Line 229... Line 216...
229
 
216
 
230
			switch(btn)
217
			switch(btn)
231
			{
218
			{
232
				case BTN_NEW:
-
 
233
					image.create(32, 32);
219
				case BTN_NEW:
234
					DrawCanvas();
220
					EventCleanCanvas();
235
					break;
221
					break;
236
				case BTN_OPEN:
222
				case BTN_OPEN:
237
					RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path));
223
					RunProgram("/sys/lod", sprintf(#param, "*png* %s",#program_path));
238
					break;
224
					break;
239
				case BTN_SAVE:
225
				case BTN_SAVE:
240
					EventSave();
226
					EventSaveIconToFile();
241
					break;
227
					break;
242
				case BTN_MOVE_LEFT:
228
				case BTN_MOVE_LEFT:
243
					image.move(MOVE_LEFT);
229
					image.move(MOVE_LEFT);
244
					DrawCanvas();
230
					DrawCanvas();
Line 282... Line 268...
282
					break;
268
					break;
283
				case BTN_SELECT:
269
				case BTN_SELECT:
284
					setCurrentTool(TOOL_SELECT);
270
					setCurrentTool(TOOL_SELECT);
285
					break;
271
					break;
286
				case CLOSE_BTN:
272
				case CLOSE_BTN:
287
					ExitProcess();
273
					EventExitIconEdit();
288
					break;
274
					break;
289
			}
275
			}
290
			break;
276
			break;
Line 291... Line 277...
291
	  
277
	  
Line 487... Line 473...
487
				COLSIZE, COLSIZE, default_palette[PALLETE_SIZE-i]);
473
				COLSIZE, COLSIZE, default_palette[PALLETE_SIZE-i]);
488
		}
474
		}
489
	}
475
	}
490
}
476
}
Line -... Line 477...
-
 
477
 
-
 
478
void DrawCanvasPixel(dword _r,_c,_color)
-
 
479
{
-
 
480
	DrawBar(_c*zoom.value + canvas.x, _r*zoom.value + canvas.y, 
-
 
481
	zoom.value, zoom.value, _color);
-
 
482
}
491
 
483
 
492
void DrawCanvas()
484
void DrawCanvas()
493
{
485
{
-
 
486
	int r, c;
-
 
487
	dword color;
-
 
488
 
-
 
489
	if ((currentTool != TOOL_NONE) && (tools[currentTool].onCanvasDraw != 0))
-
 
490
	{
-
 
491
		tools[currentTool].onCanvasDraw();
-
 
492
	}
494
	int r, c;
493
 
495
	for (r = 0; r < image.rows; r++)
494
	for (r = 0; r < image.rows; r++)
496
	{
495
	{
497
		for (c = 0; c < image.columns; c++)
496
		for (c = 0; c < image.columns; c++)
498
		{
497
		{
499
			DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y, 
498
			if (image.pixel_state.is_drawable(r,c)) 
500
				zoom.value, zoom.value, image.get_pixel(r, c));
499
				DrawCanvasPixel(r, c, image.get_pixel(r,c));
501
		}
500
		}
502
	}
-
 
503
	
-
 
504
	if ((currentTool != TOOL_NONE) && (tools[currentTool].onCanvasDraw != 0))
501
	}
Line 505... Line 502...
505
		tools[currentTool].onCanvasDraw();
502
	image.pixel_state.reset_and_set_all_drawable();
506
 
503
 
Line 507... Line 504...
507
	DrawPreview();
504
	DrawPreview();
Line 524... Line 521...
524
//                                                   //
521
//                                                   //
525
//                      EVENTS                       //
522
//                      EVENTS                       //
526
//                                                   //
523
//                                                   //
527
//===================================================//
524
//===================================================//
Line -... Line 525...
-
 
525
 
-
 
526
void EventSaveIconToFile()
-
 
527
{
-
 
528
	int i=0;
-
 
529
	char save_file_name[4096];
-
 
530
	char save_path_stable[4096];
-
 
531
	strcpy(#save_path_stable, "/tmp0/1");
-
 
532
	do {
-
 
533
		i++;
-
 
534
		sprintf(#save_file_name, "%s/saved_icon_%i.png", #save_path_stable, i);
-
 
535
	} while (file_exists(#save_file_name));
-
 
536
	save_image(image.get_image(), image.columns, image.rows, #save_file_name);
-
 
537
}
528
 
538
 
-
 
539
void EventCleanCanvas()
-
 
540
{
-
 
541
	EventSaveIconToFile();
-
 
542
	image.create(32, 32);
-
 
543
	DrawCanvas();
-
 
544
}
-
 
545
 
529
void EventSave()
546
void EventExitIconEdit()
530
{
547
{
-
 
548
	EventSaveIconToFile();
531
	save_image(image.get_image(), image.columns, image.rows, "/rd/1/saved_image.png");
549
	ExitProcess();
Line 532... Line 550...
532
}
550
}
533
 
551
 
534
void EventSetActiveColor(int _number, _color)
552
void EventSetActiveColor(int _number, _color)
Line 543... Line 561...
543
	if (_number == 2) color2 = _color;
561
	if (_number == 2) color2 = _color;
Line 544... Line 562...
544
 
562
 
545
	DrawActiveColor(NULL);
563
	DrawActiveColor(NULL);
546
	DrawColorPallets();
564
	DrawColorPallets();
-
 
565
}