This repository was archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregion.cpp
More file actions
71 lines (61 loc) · 1.38 KB
/
region.cpp
File metadata and controls
71 lines (61 loc) · 1.38 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
#include "stdafx.hpp"
#include "region.hpp"
namespace curses {
// region
region::region(const rectangle& limit):
limit_(limit),
visible_(false)
{
bounds bds = limit_.get_bounds();
visible_ = bds.width > 0 || bds.height > 0;
}
region::region(int8_t l, int8_t t, int8_t w, int8_t h):
limit_(l,t,w,h),
visible_(false)
{
bounds bds = limit_.get_bounds();
visible_ = bds.width > 0 || bds.height > 0;
}
uint8_t region::visible_line_len(const position& pos, uint8_t lenght) const
{
uint8_t result = 0;
if(is_pos_visible(pos)) {
uint8_t maxlen = limit_.right()+1 - pos.x;
if(lenght <= maxlen) {
result = lenght;
} else {
result = maxlen;
}
}
return result;
}
uint8_t region::visible_text_len(const position& pos, const char_t* str) const
{
uint8_t result = 0;
if(is_pos_visible(pos)) {
uint8_t limit = limit_.get_bounds().width;
char_t *ch = const_cast<char_t*>(str);
while( (*ch != 0) && (result < limit) ) {
++result;
++ch;
}
}
return result;
}
rectangle region::get_visible_box(uint8_t x,uint8_t y, uint8_t w, uint8_t h) const {
position lt = current_to_parent(x,y);
if(is_pos_visible(lt)) {
position rb;
rb.x = lt.x + (w-1);
if(rb.x > limit_.right()) {
rb.x = limit_.right();
}
rb.y = lt.y + (h-1);
if(rb.y > limit_.bottom()) {
rb.y = limit_.bottom();
}
return rectangle(lt,rb);
}
return rectangle(0,0,0,0);
}
} // namespace curses