EV3RT CXX API Reference [English]
An RTOS-based development platform for LEGO Mindstorms EV3.
ev3cxx_display.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include "ev3api.h"
10 #include "ev3cxx_format.h"
11 
12 namespace ev3cxx {
13 
14 namespace detail {
15 
20 class Display
21 {
22 public:
23  static const uint8_t width = EV3_LCD_WIDTH;
24  static const uint8_t height = EV3_LCD_HEIGHT;
25 
26  static const bool_t white = EV3_LCD_WHITE;
27  static const bool_t black = EV3_LCD_BLACK;
28 
34  Display(lcdfont_t font = EV3_FONT_MEDIUM)
35  :m_x(0), m_y(0)
36  {
37  setFont(font);
38  }
39 
44  ~Display() {}
45 
53  *this, detail::string_literal_range(pattern));
54  }
55 
63  char const *pattern) {
64  setTextLine(line);
66  *this, detail::string_literal_range(pattern));
67  }
68 
74  virtual void write(char ch) {
75  if(ch == '\n') {
76  setTextLine(getTextLine() + 1);
77  } else if(ch == '\t') {
78  write_raw(' ');
79  write_raw(' ');
80  write(' ');
81  } else if(ch == '\r') {
82  setTextLine(getTextLine(), 0);
83  }
84  else {
85  write_raw(ch);
86  }
87  }
88 
93  void write_raw(char ch, bool clear = false) {
94  if (clear)
95  clearTextLine(getTextLine(), white, m_x, 1);
96  ev3_lcd_draw_character(ch, m_x, m_y);
97  m_x += getFontWidth();
98  if(m_x >= width) {
99  m_y += getFontHeight();
100  m_x = 0;
101 
102  if(m_y >= height)
103  m_y = 0;
104  }
105  }
106 
112  int32_t getTextLine() const { return m_y / getFontHeight(); }
113 
123  void setTextLine(uint8_t line, int32_t x_offset = 0, bool clear = true) {
124  if(clear && (line * getFontHeight()) < height) {
125  clearTextLine(line, white, x_offset);
126  }
127  m_y = (line * getFontHeight()) % height;
128  m_x = x_offset;
129  }
130 
140  void clearTextLine(uint8_t line, bool_t color = white, int32_t x_offset = 0, int32_t line_length = 0) {
141  if (line_length == 0)
142  line_length = width - x_offset;
143  else
144  line_length *= getFontWidth();
145  ev3_lcd_fill_rect(x_offset,
146  (line * getFontHeight()) % height,
147  line_length,
148  getFontHeight(),
149  static_cast<lcdcolor_t>(color));
150  }
151 
157  void resetScreen(bool_t color = white) {
158  ev3_lcd_fill_rect(0, 0, width, height, static_cast<lcdcolor_t>(color));
159  setTextLine(0);
160  }
161 
168  void setFont(lcdfont_t font) {
169  m_font = font;
170  ev3_lcd_set_font(font);
171  ev3_font_get_size(font, &m_font_width, &m_font_height);
174  }
175 
180  lcdfont_t getFont() const { return m_font; }
181 
186  int32_t getFontWidth() const { return m_font_width; }
187 
192  int32_t getFontHeight() const { return m_font_height; }
193 
198  int32_t getX() const { return m_x; }
199 
204  int32_t getY() const { return m_y; }
205 
206 private:
207  lcdfont_t m_font;
208  int32_t m_font_width;
209  int32_t m_font_height;
212  int32_t m_x;
213  int32_t m_y;
214 }; // class Display
215 
216 } // namespace detail
217 
218 } // namespace ev3cxx
lcdfont_t m_font
actual font
int32_t m_max_line_on_height
max number of line on screen
static const bool_t black
Black color of write to LCD.
static const bool_t white
White color of write to LCD.
detail::format_impl< Display, detail::string_literal_range > format(char const *pattern)
Write formated text to LCD.
Definition: ev3cxx.h:35
void clearTextLine(uint8_t line, bool_t color=white, int32_t x_offset=0, int32_t line_length=0)
Clear a line.
int32_t m_font_width
width of actual font
void write_raw(char ch, bool clear=false)
Write one character on screen of class Display.
Class Display. API for working with text on display.
API for formating data to output (display, bluetooth, file)
void setTextLine(uint8_t line, int32_t x_offset=0, bool clear=true)
Set actual text line index of cursor for next write.
int32_t m_font_height
height of actual font
int32_t getTextLine() const
Get actual text line index.
int32_t m_max_char_on_line
max number of character on one line
virtual void write(char ch)
Write one character on screen of class Display.
int32_t m_x
actual horizontal coordinate from upper left corner
void setFont(lcdfont_t font)
Set font type.
int32_t getFontWidth() const
Get actual font width.
int32_t m_y
actual vertical coordinate from upper left corner
static const uint8_t height
Height of LCD in pixels.
int32_t getFontHeight() const
Get actual font height.
int32_t getX() const
Get actual X coordinates.
~Display()
Destructor of class Display.
static const uint8_t width
Width of LCD in pixels.
detail::format_impl< Display, detail::string_literal_range > format(int8_t line, char const *pattern)
Write formated text to LCD.
void resetScreen(bool_t color=white)
Clear whole LCD.
Display(lcdfont_t font=EV3_FONT_MEDIUM)
Constructor of class Display.
lcdfont_t getFont() const
Get actual font type.
int32_t getY() const
Get actual Y coordinates.