Subversion Repositories Kolibri OS

Rev

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

Rev 7268 Rev 7271
Line 35... Line 35...
35
	if (selection_end_y < selection_start_y) {
35
	if (selection_end_y < selection_start_y) {
36
		selection_end_y >< selection_start_y;
36
		selection_end_y >< selection_start_y;
37
	}
37
	}
38
}
38
}
Line -... Line 39...
-
 
39
 
-
 
40
void SelectTool_drawBufferToImage(int insert_x, int insert_y) {
-
 
41
	dword r, c;
-
 
42
	dword insert_to_x, insert_to_y;
-
 
43
	
-
 
44
		insert_to_x = math.min(insert_x + selection.columns - 1, image.columns-1);
-
 
45
		insert_to_y = math.min(insert_y + selection.rows - 1, image.rows-1);
-
 
46
 
-
 
47
		for (r = insert_y; r <= insert_to_y; r++) {
-
 
48
			for (c = insert_x; c <= insert_to_x; c++) {
-
 
49
					image.set_pixel(r, c, selection.get_pixel(r - insert_y, c - insert_x) );
-
 
50
			}
-
 
51
		}	
-
 
52
}
39
 
53
 
40
void reset_selection_moving() {
54
void ApplySelectionToImage() {
-
 
55
	if (STATE_SELECTED != selection_state) return;
41
	if (STATE_SELECTED == selection_state) {
56
 
Line 42... Line 57...
42
		SelectTool_drawBuffer(selection_start_x, selection_start_y, 1);
57
	SelectTool_drawBufferToImage(selection_start_x, selection_start_y);
43
 
58
 
Line 44... Line -...
44
		selection_pivot_x = -1;
-
 
45
		selection_pivot_y = -1;
-
 
46
		
59
	selection_pivot_x = -1;
47
		selection_state = STATE_SELECTED;
60
	selection_pivot_y = -1;
48
		
61
	
49
		actionsHistory.saveCurrentState();
-
 
Line 50... Line 62...
50
		DrawCanvas();
62
	actionsHistory.saveCurrentState();
51
	}
63
	DrawCanvas();
52
}
64
}
53
 
65
 
Line 54... Line 66...
54
bool is_selection_moving() {
66
bool is_selection_moving() {
55
	if (STATE_SELECTED == selection_state) return true;
67
	if (STATE_SELECTED == selection_state) return true;
Line 56... Line 68...
56
	return false;
68
	return false;
57
}
69
}
58
 
70
 
59
void reset_selection() {
71
void reset_selection() {
Line 69... Line 81...
69
	reset_selection();
81
	reset_selection();
70
	selection_state = STATE_INACTIVE;
82
	selection_state = STATE_INACTIVE;
71
}
83
}
Line 72... Line 84...
72
 
84
 
73
void SelectTool_deactivate() {
85
void SelectTool_deactivate() {
74
	reset_selection_moving();
86
	ApplySelectionToImage();
75
	selection_state = STATE_INACTIVE;
87
	selection_state = STATE_INACTIVE;
Line 76... Line 88...
76
}
88
}
77
 
89
 
Line 109... Line 121...
109
			if (selection_pivot_x == -1) {
121
			if (selection_pivot_x == -1) {
110
				selection_pivot_x = m_x;
122
				selection_pivot_x = m_x;
111
				selection_pivot_y = m_y;
123
				selection_pivot_y = m_y;
Line 112... Line 124...
112
				
124
				
113
				GetKeys();
-
 
114
				
125
				GetKeys();
115
				if ( !(key_modifier&KEY_LSHIFT) ) {
126
				if ( (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) ) {
-
 
127
					DrawBarIcon(selection_start_x, selection_start_y, selection_end_x, 
116
					DrawBarIcon(selection_start_x, selection_start_y, selection_end_x, selection_end_y, color2, TOIMAGE);
128
						selection_end_y, color2, TOIMAGE);
Line 117... Line 129...
117
				}
129
				}
118
 
130
 
119
				selection_state = STATE_SELECTED;
131
				selection_state = STATE_SELECTED;
Line 139... Line 151...
139
			dy = selection_start_y;
151
			dy = selection_start_y;
Line 140... Line 152...
140
		
152
		
141
		if (selection_end_y + dy >= image.rows)
153
		if (selection_end_y + dy >= image.rows)
Line 142... Line -...
142
			dy = image.rows-1 - selection_end_y;
-
 
143
		
154
			dy = image.rows-1 - selection_end_y;
144
		
155
		
Line 145... Line 156...
145
		selection_start_x += dx;
156
		selection_start_x += dx;
146
		selection_end_x += dx;
157
		selection_end_x += dx;
Line 154... Line 165...
154
		DrawCanvas();
165
		DrawCanvas();
155
	}
166
	}
Line 156... Line 167...
156
	
167
	
157
	if (STATE_CHOSING == selection_state)
168
	if (STATE_CHOSING == selection_state)
158
	{
169
	{
159
		if (mouseX>canvas.x+canvas.w-zoom.value) mouseX = canvas.x+canvas.w-zoom.value;
170
		mouseX = math.in(mouseX, canvas.x, canvas.x+canvas.w-zoom.value);
160
		if (mouseY>canvas.y+canvas.h-zoom.value) mouseY = canvas.y+canvas.h-zoom.value;
-
 
161
 
-
 
162
		if (mouseX
-
 
Line 163... Line 171...
163
		if (mouseY
171
		mouseY = math.in(mouseY, canvas.y, canvas.y+canvas.h-zoom.value);
164
 
172
 
165
		if (mouse.key) {
173
		if (mouse.key) {
Line 170... Line 178...
170
				selection_start_x = TO_CANVAS_X(mouseX);
178
				selection_start_x = TO_CANVAS_X(mouseX);
171
				selection_start_y = TO_CANVAS_Y(mouseY);
179
				selection_start_y = TO_CANVAS_Y(mouseY);
172
			}
180
			}
173
			else {
181
			else {
174
				DrawCanvas();
182
				DrawCanvas();
175
 
-
 
176
				/**if ((calc(TO_CANVAS_X(mouseX)) != selection_end_x)
-
 
177
					|| (calc(TO_CANVAS_Y(mouseY)) != selection_end_y)) 
-
 
178
				{
-
 
179
					DrawCanvas();
-
 
180
				}*/
-
 
181
			}
183
			}
Line 182... Line 184...
182
 
184
 
Line 183... Line 185...
183
		}
185
		}
Line 194... Line 196...
194
			selection_pivot_y = -1;
196
			selection_pivot_y = -1;
195
		}
197
		}
196
	}
198
	}
197
}
199
}
Line 198... Line 200...
198
 
200
 
199
void SelectTool_onCanvasDraw() {	
-
 
200
	if ((selection_start_x >= 0) && (selection_start_y >= 0) && (selection_end_x >= 0) && (selection_end_y >= 0)) {
-
 
201
		DrawSelection();
-
 
202
	}	
-
 
203
}
-
 
204
 
-
 
205
void SelectTool_drawBuffer(int insert_x, int insert_y, int target) {
-
 
206
	dword color;
201
void SelectTool_onKeyEvent(dword keycode) {
207
	dword r, c;
-
 
208
	dword insert_to_x, insert_to_y;
-
 
209
	
-
 
210
	if (STATE_INACTIVE != selection_state) {
-
 
211
		insert_to_x = insert_x + selection.columns - 1;
-
 
212
			
-
 
213
		if (insert_to_x >= image.columns)
-
 
214
			insert_to_x = image.columns-1;
-
 
215
 
-
 
216
		insert_to_y = insert_y + selection.rows - 1;
-
 
217
			
-
 
218
		if (insert_to_y >= image.rows)
-
 
219
			insert_to_y = image.rows-1;
-
 
220
 
-
 
221
		for (r = insert_y; r <= insert_to_y; r++) {
-
 
Line -... Line 202...
-
 
202
	dword r, c;
222
			for (c = insert_x; c <= insert_to_x; c++) {
203
 
223
 
-
 
224
					color = selection.get_pixel(r - insert_y, c - insert_x);
204
	if (SCAN_CODE_DEL == keycode) {
225
					
205
		selection_start_x = -1;
226
					if (TOIMAGE == target)
206
		selection_start_y = -1;
227
						image.set_pixel(r, c, color);
207
		selection_end_x = -1;
228
					else
208
		selection_end_y = -1;
229
						DrawCanvasPixel(r, c, color);
-
 
230
			}
-
 
231
		}	
209
		selection_state = STATE_INACTIVE;
Line 232... Line 210...
232
	}	
210
		DrawCanvas();
-
 
211
	}
233
}
212
 
-
 
213
	if (SCAN_CODE_ESC == keycode) {
Line 234... Line 214...
234
 
214
		reset_selection();
235
void SelectTool_onKeyEvent(dword keycode) {
215
		DrawCanvas();
236
	dword r, c;
-
 
Line 237... Line -...
237
 
-
 
238
	if (keycode == SCAN_CODE_KEY_V) {
216
	}
239
		if (STATE_SELECTED == selection_state) {
-
 
240
			reset_selection();
-
 
241
			
217
 
-
 
218
	if (SCAN_CODE_KEY_V == keycode) {
242
			selection_state = STATE_SELECTED;
219
		if (STATE_SELECTED == selection_state) {
Line 243... Line 220...
243
			selection_start_x = 0;
220
 
244
			selection_end_x = selection.columns - 1;
221
			selection_start_x = 0;
245
			
222
			selection_start_y = 0;
246
			selection_start_y = 0;
223
			selection_end_x = selection.columns - 1;			
Line 247... Line 224...
247
			selection_end_y = selection.rows - 1;
224
			selection_end_y = selection.rows - 1;
-
 
225
			
248
			
226
			DrawCanvas();
249
			DrawCanvas();
227
		}
Line 250... Line 228...
250
		}
228
	}
251
	}
-
 
252
}
-
 
253
 
-
 
254
void DrawSelection() {
-
 
255
	#define SELECTION_COLOR 0xAAE5EF
-
 
256
	int p1x, p1y, p2x, p2y, r, c, old_color, new_color;
-
 
257
 
-
 
Line 258... Line 229...
258
	if (selection_start_x <= selection_end_x) {
229
}
259
		p1x = selection_start_x;
230
 
260
		p2x = selection_end_x;
-
 
261
	}
-
 
262
	else {
-
 
263
		p1x = selection_end_x;
-
 
264
		p2x = selection_start_x;
-
 
265
	}
-
 
Line -... Line 231...
-
 
231
void SelectTool_onCanvasDraw() 
-
 
232
{	
-
 
233
	#define SELECTION_COLOR 0xAAE5EF
266
 
234
	int p1x, p1y, p2x, p2y, r, c, old_color, new_color;
267
	if (selection_start_y <= selection_end_y) {
235
 
268
		p2y = selection_start_y;
236
	if ((selection_start_x >= 0) && (selection_start_y >= 0) && (selection_end_x >= 0) && (selection_end_y >= 0)) {
Line 269... Line 237...
269
		p1y = selection_end_y;
237
 
270
	}
238
		p1x = math.min(selection_start_x, selection_end_x);
Line 288... Line 256...
288
 
256
 
289
			DrawCanvasPixel(r, c, new_color);
257
				DrawCanvasPixel(r, c, new_color);
290
		}
258
			}
291
	}
259
		}
292
}
260
	}	
-
 
261
}
-
 
262
-
 
263