Phoenard
Public Member Functions | List of all members
PHN_Display Class Reference

Simplifies the use of the display with drawing, touch input and widgets . More...

#include <PHNDisplay.h>

Inheritance diagram for PHN_Display:
PHN_WidgetContainer

Public Member Functions

 PHN_Display ()
 Is constructed globally, do not use (?), use 'display' global variable instead.
 
void setSleeping (bool sleeping)
 Put the LCD-screen to sleep or wake it up again for reducing power consumption.
 
void setBacklight (int level)
 Changes the brightness of the LCD LED backlight, level being 0 - 256.
 
void update ()
 Updates the touch input, then all widgets attached to the display.
 
void updateTouch ()
 Updates only the touch input, use this instead of update() to save code if not using widgets.
 
void updateWidgets ()
 Updates only the widgets, assuming no touch. Use this when the ADC is used for something else.
 
void invalidate (void)
 Invalidates all added widgets, forcing them to redraw upon the next update.
 
uint16_t width ()
 Gets the width of the display - height when screen is rotated 90/270 degrees.
 
uint16_t height ()
 Gets the height of the display - width when screen is rotated 90/270 degrees.
 
bool isWidescreen (void)
 Gets whether the width is greater than the height, and the screen is a widescreen.
 
void setScreenRotation (uint8_t rotation)
 Gets or sets the screen rotation transform. More...
 
uint8_t getScreenRotation (void)
 Gets the screen rotation transform ranging [0..3].
 
void setWrapMode (uint8_t mode)
 Sets the wrap-around mode when reaching screen/viewport borders. More...
 
void goTo (uint16_t x, uint16_t y)
 Sets drawn pixel position to [x,y] and a horizontal direction. More...
 
void goTo (uint16_t x, uint16_t y, uint8_t direction)
 Sets drawn pixel position to [x,y] with a direction to draw in specified. More...
 
void setViewport (Viewport viewport)
 Sets a viewport (rectangular area) to draw in.
 
void setViewport (uint16_t x, uint16_t y, uint16_t w, uint16_t h)
 Sets a viewport (rectangular area) to draw in.
 
void setViewportRelative (uint16_t x, uint16_t y, uint16_t w, uint16_t h)
 Sets a viewport (rectangular area) to draw in.
 
void resetViewport (void)
 Resets the viewport to draw in the entire screen.
 
Viewport getViewport (void)
 Gets the current viewport that is applied.
 
uint32_t getViewportArea (void)
 Gets the total amount of pixels the viewport area currently occupies.
 
PressPoint getTouchLast (void)
 Gets the location and pressure of the previous touch state.
 
PressPoint getTouch (void)
 Gets the location and pressure of the current touch state.
 
PressPoint getTouchStart (void)
 Gets the location and pressure of the last time the screen was touched down.
 
bool isTouched (void)
 Gets whether the screen is touched down on.
 
bool isTouchDown (void)
 Gets whether the screen was previously not touched but now is.
 
bool isTouchUp (void)
 Gets whether the screen was previously touched but now no more.
 
bool isTouched (uint16_t x, uint16_t y, uint16_t width, uint16_t height)
 Gets whether a particular area is touched down on.
 
bool isTouchEnter (uint16_t x, uint16_t y, uint16_t width, uint16_t height)
 Gets whether a particular area was previously not touched but now is.
 
bool isTouchLeave (uint16_t x, uint16_t y, uint16_t width, uint16_t height)
 Gets whether a particular area was previously touched but is now no more.
 
bool isTouchClicked (uint16_t x, uint16_t y, uint16_t width, uint16_t height)
 Gets whether a particular area was previously touched and was then released shortly to engage a click.
 
bool isTouchChange (uint16_t x, uint16_t y, uint16_t width, uint16_t height)
 Gets whether a touch change occurred for an area, such as entering/leaving/clicking.
 
float getSlider (void)
 Gets the current slider value ranging [0..1].
 
float getSliderStart (void)
 Gets the slider value ranging [0..1] obtained at the start of a press.
 
bool isSliderTouched (void)
 Gets whether the slider is touched.
 
bool isSliderTouchDown (void)
 Gets whether the slider is touched and was not before.
 
bool isSliderTouchUp (void)
 Gets whether the slider is no longer touched and was before.
 
void drawPixel (uint16_t x, uint16_t y, color_t color)
 Draws a single pixel to the screen.
 
void fill (color_t color)
 Fills the entire screen or viewport.
 
void drawLine (int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color)
 Draws a line from one point to another.
 
void drawStraightLine (uint16_t x, uint16_t y, uint16_t length, uint8_t direction, color_t color)
 Draws a straight line starting at [x, y], moving into the direction. More...
 
void drawLineAngle (int x, int y, int r1, int r2, float angle, color_t color)
 Draws a line at an angle between two radius's around the center point [x, y]. More...
 
void drawVerticalLine (uint16_t x, uint16_t y, uint16_t length, color_t color)
 Draws a straight line down starting at [x, y].
 
void drawHorizontalLine (uint16_t x, uint16_t y, uint16_t length, color_t color)
 Draws a straight line to the right starting at [x, y].
 
void drawTriangle (uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, color_t color)
 Draws a triangle connecting the three points specified.
 
void fillTriangle (int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, color_t color)
 Fills in a triangle connecting the three points specified.
 
void drawRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, color_t color)
 Draws a rectangle at [x, y] with dimensions [w, h].
 
void fillRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, color_t color)
 Fills a rectangle at [x, y] with dimensions [w, h].
 
void fillBorderRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, color_t color, color_t borderColor)
 Fills a rectangle at [x, y] with dimensions [w, h], the outside set to a 1-pixel wide border.
 
void drawRoundRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t radius, color_t color)
 Draws a rounded rectangle at [x, y] with dimensions [w, h] with the rounded radius.
 
void fillRoundRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t radius, color_t color)
 Fills a rounded rectangle at [x, y] with dimensions [w, h] with the rounded radius.
 
void fillBorderRoundRect (uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t radius, color_t color, color_t borderColor)
 Fills a rounded rectangle at [x, y] with dimensions [w, h], the outside set to a 1-pixel wide border.
 
void drawCircle (uint16_t x, uint16_t y, uint16_t r, color_t color)
 Draws a circle at [x, y] of radius [r].
 
void fillCircle (uint16_t x, uint16_t y, uint16_t r, color_t color)
 Fills a circle at [x, y] of radius [r].
 
void fillBorderCircle (uint16_t x, uint16_t y, uint16_t r, color_t color, color_t borderColor)
 Fills a circle at [x, y] of radius [r] with a 1-pixel wide border.
 
const uint16_t getCursorX (void)
 Gets the current text-drawing cursor x-coordinate.
 
const uint16_t getCursorY (void)
 Gets the current text-drawing cursor y-coordinate.
 
void setCursor (uint16_t x, uint16_t y)
 Sets the current text-drawing cursor [x,y] coordinate.
 
void setCursorDown (uint16_t x)
 Sets the current text-drawing cursor one newline down at the x-coordinate specified.
 
void setScroll (int value)
 Sets the absolute horizontal scrolling value.
 
uint16_t getScroll () const
 Gets the absolute horizontal scrolling value.
 
void scroll (int offset)
 Scrolls the screen horizontally by an offset.
 
void setTextColor (color_t c)
 Sets the text color to a color, with a transparent background.
 
void setTextColor (color_t c, color_t bg)
 Sets the text color to a color, with a specified background color.
 
void setTextSize (uint8_t s)
 Sets the text size ranging [1..20].
 
color_t getTextBackground (void)
 Gets the current text background color set.
 
color_t getTextColor (void)
 Gets the current text foreground color set.
 
uint8_t getTextSize (void)
 Gets the current text size set.
 
TextOptions getTextOptions (void)
 Gets all current text rendering options.
 
void setTextOptions (TextOptions opt)
 Sets all current text rendering options.
 
void drawChar (uint16_t x, uint16_t y, char c, uint8_t s=1)
 Draws a single character at [x, y] of an optional size specified.
 
void drawCharMem (uint16_t x, uint16_t y, const uint8_t *font_char, uint8_t s=1)
 Draws character data stored in FLASH (8x5 size) at [x, y] of an optional size scaling specified.
 
void drawCharRAM (uint16_t x, uint16_t y, const uint8_t *font_data, uint8_t s=1)
 Draws character data (8x5 size) at [x, y] of an optional size scaling specified.
 
void drawString (uint16_t x, uint16_t y, const char *text, uint8_t s=1)
 Draws a String of characters at [x, y] of an optional size specified.
 
TextBounds computeMiddleBounds (uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char *text)
 Computes the bounds of a piece of text to fit it inside an area. More...
 
void drawStringMiddle (uint16_t x, uint16_t y, uint16_t width, uint16_t height, const char *text)
 Draws a String of characters in the area [x, y, width, height]. More...
 
void printShortTime (Date date)
 Prints hours and minutes part of a date.
 
void printTime (Date date)
 Prints hours, minutes and seconds part of a date.
 
void printDate (Date date)
 Prints the month and day of a date.
 
void printMem (const uint8_t *font_char)
 Prints a character stored in memory in 7x5 size format.
 
void printPadding (int nrChars)
 Pads the space up until some amount of characters with white spaces.
 
void debugPrint (uint16_t x, uint16_t y, uint8_t size, const char *text, uint8_t padding=0)
 Prints out text in a convenient short way.
 
void debugPrint (uint16_t x, uint16_t y, uint8_t size, int value)
 Prints out a number to the screen in a convenient short way.
 
void debugPrint (uint16_t x, uint16_t y, uint8_t size, float value)
 Prints out a float to the screen in a convenient short way.
 
Printing and writing functions

Functions imported from Print.h

Inheriting Print.h means the virtual write function is always compiled. This resulted in a significant increase of the final binary. For this reason these functions are instead copied here.

The exact same Arduino Print documentation applies here.

size_t printNumber (unsigned long, uint8_t)
 
size_t printFloat (double, uint8_t)
 
size_t write (const uint8_t *buffer, size_t size)
 
size_t write (const char *str)
 
size_t write (uint8_t c)
 
size_t print (const __FlashStringHelper *)
 
size_t print (const String &)
 
size_t print (const char[])
 
size_t print (char)
 
size_t print (unsigned char, int=DEC)
 
size_t print (int, int=DEC)
 
size_t print (unsigned int, int=DEC)
 
size_t print (long, int=DEC)
 
size_t print (unsigned long, int=DEC)
 
size_t print (double, int=2)
 
size_t println (const __FlashStringHelper *)
 
size_t println (const String &s)
 
size_t println (const char[])
 
size_t println (char)
 
size_t println (unsigned char, int=DEC)
 
size_t println (int, int=DEC)
 
size_t println (unsigned int, int=DEC)
 
size_t println (long, int=DEC)
 
size_t println (unsigned long, int=DEC)
 
size_t println (double, int=2)
 
size_t println (void)
 
Image Drawing Functions

Draws .BMP or .LCD image data to the screen

Send in a stream of data containing the .BMP or .LCD image contents. For this you can make use of the SD File, FlashMemoryStream and MemoryStream. This way images can be stored on a variety of media, even Serial!

You can draw the image with a r/g/b/brightness modifier, you can use a list of colors (colormap) or you can write your own color-converting function to use. If you wish to alter the colors of an image, or in general re-use the same image for different styles, you can use these extra functions.

Be aware that reading image data can be fairly slow, so 'compress' your images into 1-bit (2 colors), 2-bit (4 colors), 4-bit (16 colors) or 8-bit (256 colors) before use.

The .BMP format only supports 8-bit and 24-bit color formats. It is recommended to convert your images into .LCD using the Phoenard toolkit before use.

void drawImage (Stream &imageStream, int x, int y)
 
void drawImage (Stream &imageStream, int x, int y, float brightness)
 
void drawImage (Stream &imageStream, int x, int y, float cr, float cg, float cb)
 
void drawImage (Stream &imageStream, int x, int y, void(*color)(uint8_t *, uint8_t *, uint8_t *))
 
void drawImage (Stream &imageStream, int x, int y, const color_t *colorMapInput)
 
- Public Member Functions inherited from PHN_WidgetContainer
 PHN_WidgetContainer (void)
 Constructor for a new widget container.
 
void updateWidgets (bool update, bool draw, bool forceRedraw)
 Updates all the widgets contained. More...
 
void addWidget (PHN_Widget &widget)
 Adds a single widget. More...
 
void removeWidget (PHN_Widget &widget)
 Removes a single widget. More...
 
void clearWidgets ()
 Removes all contained widgets. More...
 
PHN_Widgetwidget (int index)
 Gets the widget stored at an index.
 
const int widgetCount ()
 Gets how many widgets are stored.
 

Additional Inherited Members

- Protected Member Functions inherited from PHN_WidgetContainer
void clearSilent ()
 Removes all child widgets from this container without handling proper redrawing. More...
 
void setWidgetCapacity (int capacity)
 Resizes the internal array of widgets to a new capacity. More...
 
- Protected Attributes inherited from PHN_WidgetContainer
bool deleteAddedWidgets
 Sets whether added widgets are deleted (were added with new)
 

Detailed Description

Simplifies the use of the display with drawing, touch input and widgets .

Includes a display instance which communicates with the LCD hardware. With this class drawing shapes, text, images and other content is simplified. In addition it hosts widgets which are automatically updated and drawn to screen. Calling update() will update the touch input and then all widgets added. This way a lively user interface can be easily implemented.

Member Function Documentation

TextBounds PHN_Display::computeMiddleBounds ( uint16_t  x,
uint16_t  y,
uint16_t  width,
uint16_t  height,
const char *  text 
)

Computes the bounds of a piece of text to fit it inside an area.

This function is used by the drawStringMiddle() function to find the bounds. If you need to do something special with this data aside from just drawing text, you can make use of this function.

void PHN_Display::drawLineAngle ( int  x,
int  y,
int  r1,
int  r2,
float  angle,
color_t  color 
)

Draws a line at an angle between two radius's around the center point [x, y].

Two points at r1 and r2 radius away from [x, y] are taken that form a line angled at the (radian) degree. This function can commonly be used to draw rotary dials, pointers or other rotating bars. Using a r1 of 0 results in a line drawn from the center. Using a negative value of r1 or r2 will draw the line in inverse of the angle.

void PHN_Display::drawStraightLine ( uint16_t  x,
uint16_t  y,
uint16_t  length,
uint8_t  direction,
color_t  color 
)

Draws a straight line starting at [x, y], moving into the direction.

An alternative to drawLine that can draw just a little faster. The direction ranges [0...3] and specifies in 90-degree angles. A direction of 0 is to the right, 1 down, 2 left and 3 up.

void PHN_Display::drawStringMiddle ( uint16_t  x,
uint16_t  y,
uint16_t  width,
uint16_t  height,
const char *  text 
)

Draws a String of characters in the area [x, y, width, height].

Draws the text in the middle of the rectangular area specified. The size to draw at is automatically calculated to fit the text.

void PHN_Display::goTo ( uint16_t  x,
uint16_t  y 
)

Sets drawn pixel position to [x,y] and a horizontal direction.

Is mainly for internal use, but can be used with the hardware LCD for custom use.

void PHN_Display::goTo ( uint16_t  x,
uint16_t  y,
uint8_t  direction 
)

Sets drawn pixel position to [x,y] with a direction to draw in specified.

Is mainly for internal use, but can be used with the hardware LCD for custom use. The direction ranges [0...3] and specifies in 90-degree angles. A direction of 0 is to the right, 1 down, 2 left and 3 up.

void PHN_Display::setScreenRotation ( uint8_t  rotation)

Gets or sets the screen rotation transform.

Possible values are 0, 1, 2 and 3 where 4 becomes 0 (wraps around)

void PHN_Display::setWrapMode ( uint8_t  mode)

Sets the wrap-around mode when reaching screen/viewport borders.

Possible values: WRAPMODE_UP and WRAPMODE_DOWN


The documentation for this class was generated from the following files: