Subversion Repositories Kolibri OS

Rev

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

Rev 7267 Rev 7268
Line 7... Line 7...
7
_image selection;
7
_image selection;
Line 8... Line 8...
8
 
8
 
9
enum {
9
enum {
10
	STATE_INACTIVE=0,
10
	STATE_INACTIVE=0,
11
	STATE_CHOSING=1,
11
	STATE_CHOSING=1,
12
	STATE_SELECTED=2,
-
 
13
	STATE_MOVING=3
12
	STATE_SELECTED=2
14
};
13
};
Line 15... Line 14...
15
int selection_state = STATE_INACTIVE;
14
int selection_state = STATE_INACTIVE;
16
 
15
 
Line 27... Line 26...
27
//                       CODE                        //
26
//                       CODE                        //
28
//                                                   //
27
//                                                   //
29
//===================================================//
28
//===================================================//
Line 30... Line 29...
30
 
29
 
31
void SelectTool_normalizeSelection() {
-
 
32
	int t;
-
 
33
 
30
void SelectTool_normalizeSelection() {
34
	// Restructuring of the selection coordinates
31
	// Restructuring of the selection coordinates
35
	if (selection_end_x < selection_start_x) {
-
 
36
		t = selection_start_x;
32
	if (selection_end_x < selection_start_x) {
37
		selection_start_x = selection_end_x;
-
 
38
		selection_end_x = t;
33
		selection_start_x >< selection_end_x;
39
	} 
-
 
40
 
34
	} 
41
	if (selection_end_y < selection_start_y) {
-
 
42
		t = selection_end_y;
35
	if (selection_end_y < selection_start_y) {
43
		selection_end_y = selection_start_y;
-
 
44
		selection_start_y = t;
36
		selection_end_y >< selection_start_y;
45
	}
37
	}
Line 46... Line 38...
46
}
38
}
47
 
39
 
48
void reset_selection_moving() {
40
void reset_selection_moving() {
Line 49... Line 41...
49
	if (STATE_MOVING == selection_state) {
41
	if (STATE_SELECTED == selection_state) {
50
		SelectTool_drawBuffer(selection_start_x, selection_start_y, 1);
42
		SelectTool_drawBuffer(selection_start_x, selection_start_y, 1);
Line 58... Line 50...
58
		DrawCanvas();
50
		DrawCanvas();
59
	}
51
	}
60
}
52
}
Line 61... Line 53...
61
 
53
 
62
bool is_selection_moving() {
54
bool is_selection_moving() {
63
	if (STATE_MOVING == selection_state) return true;
55
	if (STATE_SELECTED == selection_state) return true;
64
	return false;
56
	return false;
Line 65... Line 57...
65
}
57
}
66
 
58
 
Line 104... Line 96...
104
		}
96
		}
105
	}
97
	}
106
}
98
}
Line 107... Line 99...
107
 
99
 
108
void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
100
void SelectTool_onMouseEvent(int mouseX, int mouseY, int lkm, int pkm) {
109
	int dx, dy, m_x, m_y, r, c;
-
 
Line 110... Line 101...
110
	dword pixel;
101
	int dx, dy, m_x, m_y;
111
	
102
	
Line 112... Line -...
112
	m_x = TO_CANVAS_X(mouseX);
-
 
113
	m_y = TO_CANVAS_Y(mouseY);
103
	m_x = TO_CANVAS_X(mouseX);
114
 
-
 
115
	if (mouse.down) 
104
	m_y = TO_CANVAS_Y(mouseY);
116
	&& (canvas.hovered()) 
105
 
117
	&& ((STATE_INACTIVE == selection_state) || (STATE_CHOSING == selection_state) || (STATE_SELECTED == selection_state) || (STATE_MOVING == selection_state))
106
	if (mouse.down) && (canvas.hovered()) 
118
	{
107
	{
119
		if (selection_start_x != -1) && (SelectTool_pointInSelection(m_x, m_y)) {
108
		if (selection_start_x != -1) && (SelectTool_pointInSelection(m_x, m_y)) {
Line 120... Line 109...
120
			if (selection_pivot_x == -1) {
109
			if (selection_pivot_x == -1) {
Line 121... Line 110...
121
				selection_pivot_x = m_x;
110
				selection_pivot_x = m_x;
122
				selection_pivot_y = m_y;
-
 
123
				
111
				selection_pivot_y = m_y;
124
				GetKeys();
-
 
125
				
-
 
126
				if (STATE_MOVING != selection_state) && ( !(key_modifier&KEY_LSHIFT) ) {
112
				
Line 127... Line 113...
127
					for (r = selection_start_y; r <= selection_end_y; r++)
113
				GetKeys();
128
						for (c = selection_start_x; c <= selection_end_x; c++) {
114
				
129
							image.set_pixel(r, c, color2);
115
				if ( !(key_modifier&KEY_LSHIFT) ) {
130
						}
116
					DrawBarIcon(selection_start_x, selection_start_y, selection_end_x, selection_end_y, color2, TOIMAGE);
131
				}
117
				}
132
 
118
 
Line 238... Line 224...
238
					color = selection.get_pixel(r - insert_y, c - insert_x);
224
					color = selection.get_pixel(r - insert_y, c - insert_x);
Line 239... Line 225...
239
					
225
					
240
					if (TOIMAGE == target)
226
					if (TOIMAGE == target)
241
						image.set_pixel(r, c, color);
227
						image.set_pixel(r, c, color);
242
					else
-
 
243
						DrawBar(c*zoom.value + canvas.x, r*zoom.value + canvas.y, 
228
					else
244
							zoom.value, zoom.value, color);
229
						DrawCanvasPixel(r, c, color);
245
			}
230
			}
246
		}	
231
		}	
247
	}	
232
	}	
Line 252... Line 237...
252
 
237
 
253
	if (keycode == SCAN_CODE_KEY_V) {
238
	if (keycode == SCAN_CODE_KEY_V) {
254
		if (STATE_SELECTED == selection_state) {
239
		if (STATE_SELECTED == selection_state) {
Line 255... Line 240...
255
			reset_selection();
240
			reset_selection();
256
			
241
			
257
			selection_state = STATE_MOVING;
242
			selection_state = STATE_SELECTED;
Line 258... Line 243...
258
			selection_start_x = 0;
243
			selection_start_x = 0;
259
			selection_end_x = selection.columns - 1;
244
			selection_end_x = selection.columns - 1;
Line 290... Line 275...
290
 
275
 
291
	for (r = p1y; r >= p2y; r--) {
276
	for (r = p1y; r >= p2y; r--) {
292
		for (c = p1x; c <= p2x; c++) {
277
		for (c = p1x; c <= p2x; c++) {
Line 293... Line 278...
293
			image.pixel_state.set_drawable_state(r, c, false);
278
			image.pixel_state.set_drawable_state(r, c, false);
294
			
279
			
295
			if (STATE_MOVING == selection_state) && (SelectTool_pointInSelection(c, r)) {
280
			if (STATE_SELECTED == selection_state) && (SelectTool_pointInSelection(c, r)) {
296
				old_color = selection.get_pixel(r - selection_start_y, c - selection_start_x);
281
				old_color = selection.get_pixel(r - selection_start_y, c - selection_start_x);
297
			}
282
			}
298
			else {
283
			else {