COSA
An Object-Oriented Platform for Arduino Programming
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
Textbox.cpp
Go to the documentation of this file.
1
21
#include <
Canvas.h
>
22
#include "
Canvas/Element/Textbox.hh
"
23
24
int
25
Textbox::putchar
(
char
c)
26
{
27
// Save the current context and setup our context
28
Canvas::Context
* saved =
m_canvas
->
set_context
(
this
);
29
30
// Handle some special characters, line-feed
31
uint16_t x, y;
32
get_cursor
(x, y);
33
uint8_t scale =
m_text_scale
;
34
uint16_t width = (x + (scale * (
m_font
->
WIDTH
+
m_font
->
SPACING
)) -
m_text_port
.
x
);
35
if
((c ==
'\n'
) || (width >
m_text_port
.
width
)) {
36
uint16_t font_height = scale * (
m_font
->
HEIGHT
);
37
uint16_t line_height = scale * (
m_font
->
HEIGHT
+
m_font
->
LINE_SPACING
);
38
uint16_t y =
m_cursor
.
y
+ line_height;
39
if
(y + font_height >
m_text_port
.
y
+
m_text_port
.
height
) {
40
y =
m_text_port
.
y
;
41
}
42
x =
m_text_port
.
x
;
43
Canvas::color16_t
saved =
set_pen_color
(
get_canvas_color
());
44
set_cursor
(x, y);
45
m_canvas
->
fill_rect
(
m_text_port
.
width
, line_height);
46
set_pen_color
(saved);
47
}
48
49
// Carriage return
50
else
if
(c ==
'\r'
) {
51
set_cursor
(
m_text_port
.
x
, y);
52
}
53
54
// Form-feed
55
else
if
(c ==
'\f'
) {
56
Canvas::color16_t
saved =
set_pen_color
(
get_canvas_color
());
57
set_cursor
(
m_text_port
.
x
,
m_text_port
.
y
);
58
m_canvas
->
fill_rect
(
m_text_port
.
width
,
m_text_port
.
height
);
59
set_pen_color
(saved);
60
}
61
62
// Draw other characters
63
else
m_canvas
->
draw_char
(c);
64
65
// Restore the previous canvas state; context
66
m_canvas
->
set_context
(saved);
67
return
(c);
68
}
Canvas::rect16_t::width
uint16_t width
Definition:
Canvas.hh:125
Canvas::Context::m_font
Font * m_font
Current font.
Definition:
Canvas.hh:304
Canvas::rect16_t::y
uint16_t y
Definition:
Canvas.hh:124
Canvas::Context::m_cursor
pos16_t m_cursor
Current cursor position.
Definition:
Canvas.hh:305
Canvas::draw_char
virtual void draw_char(uint16_t x, uint16_t y, char c)
Definition:
Canvas.cpp:378
Canvas::pos16_t::y
uint16_t y
Definition:
Canvas.hh:116
Font::SPACING
const uint8_t SPACING
Definition:
Font.hh:37
Canvas::color16_t
Definition:
Canvas.hh:49
Canvas.h
Canvas::rect16_t::x
uint16_t x
Definition:
Canvas.hh:123
Textbox.hh
Font::WIDTH
const uint8_t WIDTH
Definition:
Font.hh:35
Font::HEIGHT
const uint8_t HEIGHT
Definition:
Font.hh:36
Canvas::fill_rect
virtual void fill_rect(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
Definition:
Canvas.cpp:151
Font::LINE_SPACING
uint8_t LINE_SPACING
Definition:
Font.hh:38
Canvas::set_context
Context * set_context(Context *context)
Definition:
Canvas.hh:411
Canvas::Element::m_canvas
Canvas * m_canvas
Definition:
Canvas.hh:326
Textbox::m_text_port
Canvas::rect16_t m_text_port
Definition:
Textbox.hh:113
Canvas::Context::m_text_scale
uint8_t m_text_scale
Current text scale.
Definition:
Canvas.hh:303
Canvas::Context::get_canvas_color
color16_t get_canvas_color() const
Definition:
Canvas.hh:164
Canvas::Context::set_pen_color
color16_t set_pen_color(color16_t color)
Definition:
Canvas.hh:195
Canvas::Context
Definition:
Canvas.hh:141
Textbox::putchar
virtual int putchar(char c)
Definition:
Textbox.cpp:25
Canvas::Context::get_cursor
void get_cursor(uint16_t &x, uint16_t &y) const
Definition:
Canvas.hh:271
Canvas::Context::set_cursor
void set_cursor(uint16_t x, uint16_t y)
Definition:
Canvas.hh:282
Canvas::rect16_t::height
uint16_t height
Definition:
Canvas.hh:126
libraries
Canvas
Textbox.cpp
Generated on Thu Aug 31 2017 17:02:03 for COSA by
1.8.11