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 pathpen.cpp
More file actions
130 lines (115 loc) · 2.79 KB
/
pen.cpp
File metadata and controls
130 lines (115 loc) · 2.79 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "stdafx.hpp"
#include "pen.hpp"
namespace curses {
// pen
pen::pen(const terminal* trm, const rectangle& window):
term_(trm),
region_(window),
relative_()
{
relative_ = region_.get_visible_box(window);
}
pen::~pen() CURSES_NOEXCEPT
{
}
void pen::set_cursor(uint8_t x, uint8_t y) CURSES_NOEXCEPT
{
bool move_pos = region_.is_visible();
if(move_pos) {
position pos = region_.current_to_parent(x,y);
move_pos = region_.is_pos_visible(pos);
if(move_pos) {
term_->set_cursor_visibility(true);
term_->move_cursor(pos.x, pos.y);
}
}
if(!move_pos) {
term_->set_cursor_visibility(false);
}
}
void pen::outch(uint8_t x, uint8_t y, char_t ch) const
{
if(region_.is_visible()) {
position pos = region_.current_to_parent(x,y);
if(region_.is_pos_visible(pos)) {
term_->putch(pos,ch);
}
}
}
void pen::out_line(uint8_t x, uint8_t y, uint8_t l, char_t ch) const
{
if(region_.is_visible()) {
position pos = region_.current_to_parent(x,y);
if(region_.is_pos_visible(pos)) {
uint8_t vleng = region_.visible_line_len(pos,l);
if(vleng > 0) {
term_->put_line(pos,ch,vleng);
}
}
}
}
void pen::out_box(uint8_t x, uint8_t y, uint8_t w, uint8_t h, char_t ch) const
{
if(region_.is_visible()) {
position pos = region_.current_to_parent(x,y);
if(region_.is_pos_visible(pos)) {
rectangle displaybox = region_.get_visible_box(x,y,w,h);
term_->fill_rectangle(displaybox,ch);
}
}
}
uint8_t pen::out_text(uint8_t x, uint8_t y, const char_t* str) const
{
uint8_t result = 0;
if(region_.is_visible()) {
position pos = region_.current_to_parent(x,y);
if(region_.is_pos_visible(pos)) {
uint8_t len = region_.visible_text_len(pos,str);
char_t *s = const_cast<char_t*>(str);
for(int i = 0; i < len; i++) {
outch(x+i,y,*s);
++s;
++result;
}
}
}
return result;
}
texel* pen::clipt_rect(uint8_t x, uint8_t y, uint8_t &w, uint8_t &h) const
{
texel *result = NULL;
if( region_.is_visible() ) {
rectangle vrc = region_.get_visible_box(x,y,w,h);
bounds bds = vrc.get_bounds();
if(bds.size()) {
result = static_cast<texel*>( std::malloc(bds.size() * sizeof(texel) ) );
term_->clipt_rect(vrc,result);
w = bds.width;
h = bds.height;
}
}
return result;
}
void pen::paste_rect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, texel* const box) const
{
if( region_.is_visible() && NULL != box ) {
rectangle vrc = region_.get_visible_box( x, y, w, h);
bounds bds = vrc.get_bounds();
if( bds.size() ) {
term_->paste_rect( vrc, box);
}
std::free(box);
}
}
void pen::set_color(const text_color& cl) const
{
term_->set_color(cl);
}
text_color pen::current_color() const {
return term_->current_color();
}
sp_pen pen::sub_pen(const rectangle& rect) const
{
return sp_pen( new pen(term_, region_.get_visible_box(rect) ) );
}
} // namesapce curses