Subversion Repositories Kolibri OS

Rev

Rev 7921 | Rev 7941 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7921 leency 1
struct SELECTION {
2
	dword start_x, start_y, start_offset;
3
	dword end_x, end_y, end_offset;
4
	dword color;
5
	bool is_active();
6
	void set_start();
7
	void set_end();
8
	void draw();
9
	void draw_line();
10
	void cancel();
11
	bool swap_start_end();
12
	void normalize();
13
	void select_all();
14
} selection;
15
 
16
bool SELECTION::is_active()
17
{
18
	if (start_offset) && (end_offset) && (start_offset != end_offset) {
19
		return true;
20
	} else {
21
		return false;
22
	}
23
}
24
 
25
void SELECTION::draw_line(dword x,y,w)
26
{
7924 leency 27
	DrawBuf.DrawBar(x, y - list.first * list.item_h, w, list.item_h, color);
7921 leency 28
}
29
 
30
void SELECTION::draw(int i)
31
{
32
	if (is_active()) {
7924 leency 33
		if (start_y == i) && (end_y == i) draw_line(start_x * list.font_w+2, start_y, end_x - start_x * list.font_w);
34
		else if (start_y == i) draw_line(start_x * list.font_w+2, start_y, list.w -2- calc(start_x * list.font_w));
35
		else if (end_y == i) draw_line(0, end_y, end_x * list.font_w+2);
7921 leency 36
		//DrawBuf.DrawBar(start_x * list.font_w + 2,  start_y * list.item_h, 2, list.item_h, 0x00FF00);
37
		//DrawBuf.DrawBar(end_x * list.font_w + 0,  end_y * list.item_h, 2, list.item_h, 0xFF00FF);
38
	}
7924 leency 39
	//DrawCursor
40
	if (list.cur_y >= list.first) && (list.cur_y <= list.first+list.visible) {
41
		DrawBuf.DrawBar(list.cur_x * list.font_w + 2,  list.cur_y - list.first * list.item_h, 2, list.item_h, theme.cursor);
42
	}
7921 leency 43
}
44
 
45
void SELECTION::cancel()
46
{
47
	start_offset = end_offset = lines.get(list.cur_y) + list.cur_x;
48
	start_x = end_x = list.cur_x;
49
	start_y = end_y = list.cur_y;
50
	normalize();
51
}
52
 
53
void SELECTION::set_start()
54
{
7924 leency 55
	if (selection.is_active()) return;
7921 leency 56
	start_x = list.cur_x;
57
	start_y = list.cur_y;
58
	normalize();
59
	start_offset = lines.get(start_y) + start_x;
60
}
61
 
62
void SELECTION::set_end()
63
{
64
	end_x = list.cur_x;
65
	end_y = list.cur_y;
66
	normalize();
67
	end_offset = lines.get(end_y) + end_x;
7924 leency 68
	//debugval("end_x", end_x);
69
	//debugval("end_y", end_y);
7921 leency 70
}
71
 
72
 
73
void SELECTION::normalize()
74
{
75
	start_x = math.min(start_x, lines.get(start_y+1) - lines.get(start_y));
76
	end_x   = math.min(end_x,   lines.get(end_y+1) - lines.get(end_y));
77
}
78
 
79
void SELECTION::select_all()
80
{
81
	start_y = 0;
82
	start_x = 0;
83
	end_y = lines.count-2;
84
	end_x = lines.get(end_y+1) - lines.get(end_y);
85
	start_offset = lines.get(start_y) + start_x;
86
	end_offset = lines.get(end_y) + end_x;
7924 leency 87
	//debugval("end_x__", end_x);
88
	//debugval("end_y__", end_y);
7921 leency 89
}
90
 
91
bool SELECTION::swap_start_end()
92
{
93
	start_offset >< end_offset;
94
	start_x >< end_x;
95
	start_y >< end_y;
96
	return true;
97
}