DUDS
Distributed Update of Data from Something
TextDisplay.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
10 #ifndef TEXTDISPLAY_HPP
11 #define TEXTDISPLAY_HPP
12 
13 #include <boost/noncopyable.hpp>
15 
16 namespace duds { namespace hardware {
17 
21 namespace display {
22 
31 class TextDisplay : boost::noncopyable {
32 protected:
36  std::uint8_t columnsize;
40  std::uint8_t rowsize;
44  std::uint8_t cpos;
48  std::uint8_t rpos;
57  virtual bool advance();
64  virtual void moveImpl(unsigned int c, unsigned int r) = 0;
70  virtual void writeImpl(int c) = 0;
77  virtual void writeImpl(const std::string &text);
83  virtual void writeImpl(
84  const std::string &text,
85  unsigned int c,
86  unsigned int r
87  );
91  TextDisplay();
99  unsigned int c,
100  unsigned int r
101  );
102 public:
107  virtual ~TextDisplay() = 0;
115  void move(unsigned int c, unsigned int r);
122  void write(int c);
131  void write(const std::string &text);
144  void write(const std::string &text, unsigned int c, unsigned int r);
150  virtual void clear() = 0;
161  void clearTo(unsigned int c, unsigned int r);
166  unsigned int columns() const {
167  return columnsize;
168  }
173  unsigned int rows() const {
174  return rowsize;
175  }
179  unsigned int columnPos() const {
180  return cpos;
181  }
185  unsigned int rowPos() const {
186  return rpos;
187  }
188 };
189 
190 } } }
191 
192 #endif // #ifndef TEXTDISPLAY_HPP
unsigned int columnPos() const
The current column position of the cursor.
void move(unsigned int c, unsigned int r)
Moves the cursor to the given location.
Definition: TextDisplay.cpp:36
virtual void clear()=0
Removes all text from the display and moves the cursor to the upper left corner.
unsigned int columns() const
Returns the number of columns on the display.
std::uint8_t cpos
Cursor column position.
Definition: TextDisplay.hpp:44
virtual void writeImpl(int c)=0
Writes a single character onto the display at the current cursor location.
std::uint8_t columnsize
Number of columns on the display.
Definition: TextDisplay.hpp:36
std::uint8_t rowsize
Number of rows on the display.
Definition: TextDisplay.hpp:40
std::uint8_t rpos
Cursor row position.
Definition: TextDisplay.hpp:48
virtual ~TextDisplay()=0
Allows destruction of a pointer of this base class to properly destruct the derived object...
Definition: TextDisplay.cpp:22
unsigned int rows() const
Returns the number of rows on the display.
TextDisplay()
Initializes the object with an invalid display size and cursor position.
Definition: TextDisplay.cpp:16
A fairly generic interface to a character based display that lacks color.
Definition: TextDisplay.hpp:31
virtual void moveImpl(unsigned int c, unsigned int r)=0
Moves the display&#39;s cursor to the indicated position.
void clearTo(unsigned int c, unsigned int r)
Clear text from the current cursor position to the given position, inclusive.
void write(int c)
Writes a single character onto the display at the current cursor location and advances the cursor...
Definition: TextDisplay.cpp:53
unsigned int rowPos() const
The current row position of the cursor.
virtual bool advance()
Advances the column position, and if it goes off the visible portion of the display, updates the row position.
Definition: TextDisplay.cpp:24