-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathselection.cpp
More file actions
92 lines (74 loc) · 1.24 KB
/
selection.cpp
File metadata and controls
92 lines (74 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <QtAlgorithms>
#include "selection.h"
#include "debug.h"
selection selection::create_selection(int start, int size)
{
selection s;
s.set_start(start * 2);
s.set_end((start + size) * 2);
return s;
}
void selection::set_start(int s)
{
start = s;
}
void selection::set_end(int e)
{
end = e + 1;
active = true;
}
int selection::get_start()
{
return start > end ? end : start;
}
int selection::get_end()
{
return start < end ? end : (start + 2);
}
int selection::get_start_byte()
{
return get_start() / 2;
}
int selection::get_end_byte()
{
return get_end() / 2;
}
int selection::get_start_aligned()
{
return get_start() & ~1;
}
int selection::get_end_aligned()
{
return get_end() & ~1;
}
void selection::move_end(int amount)
{
end += amount;
}
int selection::range()
{
return end - start + 1; //selections are inclusive of the last byte
}
int selection::byte_range()
{
return (end - start + 1) / 2; //selections are inclusive of the last byte
}
bool selection::is_active()
{
return active && get_start_byte() != get_end_byte();
}
void selection::set_active(bool a)
{
active = a;
if(!active){
dragging = false;
}
}
bool selection::is_dragging()
{
return dragging;
}
void selection::set_dragging(bool d)
{
dragging = d;
}