Arduino style GUI

Committer:
jonebuckman
Date:
Wed Feb 27 22:34:06 2019 +0000
Revision:
4:d353b314d244
Parent:
0:90962b684403
Updated writeCommand and writeData.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jonebuckman 0:90962b684403 1 /* NeatGUI Library
jonebuckman 0:90962b684403 2 * Copyright (c) 2013 Neil Thiessen
jonebuckman 0:90962b684403 3 *
jonebuckman 0:90962b684403 4 * Licensed under the Apache License, Version 2.0 (the "License");
jonebuckman 0:90962b684403 5 * you may not use this file except in compliance with the License.
jonebuckman 0:90962b684403 6 * You may obtain a copy of the License at
jonebuckman 0:90962b684403 7 *
jonebuckman 0:90962b684403 8 * http://www.apache.org/licenses/LICENSE-2.0
jonebuckman 0:90962b684403 9 *
jonebuckman 0:90962b684403 10 * Unless required by applicable law or agreed to in writing, software
jonebuckman 0:90962b684403 11 * distributed under the License is distributed on an "AS IS" BASIS,
jonebuckman 0:90962b684403 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jonebuckman 0:90962b684403 13 * See the License for the specific language governing permissions and
jonebuckman 0:90962b684403 14 * limitations under the License.
jonebuckman 0:90962b684403 15 */
jonebuckman 0:90962b684403 16
jonebuckman 0:90962b684403 17 #ifndef CANVAS_H
jonebuckman 0:90962b684403 18 #define CANVAS_H
jonebuckman 0:90962b684403 19
jonebuckman 0:90962b684403 20 #include "mbed.h"
jonebuckman 0:90962b684403 21 #include "Image.h"
jonebuckman 0:90962b684403 22 #include "Font.h"
jonebuckman 0:90962b684403 23
jonebuckman 0:90962b684403 24 /** Canvas abstract class.
jonebuckman 0:90962b684403 25 * Used as a base class for objects that provide 2D drawing capabilities.
jonebuckman 0:90962b684403 26 */
jonebuckman 0:90962b684403 27 class Canvas
jonebuckman 0:90962b684403 28 {
jonebuckman 0:90962b684403 29 public:
jonebuckman 0:90962b684403 30 /** Create a Canvas object with the specified width and height
jonebuckman 0:90962b684403 31 *
jonebuckman 0:90962b684403 32 * @param w The canvas width.
jonebuckman 0:90962b684403 33 * @param h The canvas height.
jonebuckman 0:90962b684403 34 */
jonebuckman 0:90962b684403 35 Canvas(int w, int h);
jonebuckman 0:90962b684403 36
jonebuckman 0:90962b684403 37 /** Draw a single pixel at the specified coordinates
jonebuckman 0:90962b684403 38 *
jonebuckman 0:90962b684403 39 * @param x The X coordinate.
jonebuckman 0:90962b684403 40 * @param y The Y coordinate.
jonebuckman 0:90962b684403 41 * @param c The color of the pixel as a 32-bit ARGB value.
jonebuckman 0:90962b684403 42 */
jonebuckman 0:90962b684403 43 virtual void drawPixel(int x, int y, unsigned int c) = 0;
jonebuckman 0:90962b684403 44
jonebuckman 0:90962b684403 45 /** Fill the entire canvas with the specified color using a filled rectangle
jonebuckman 0:90962b684403 46 *
jonebuckman 0:90962b684403 47 * @param c The color to fill with as a 32-bit ARGB value (black by default).
jonebuckman 0:90962b684403 48 */
jonebuckman 0:90962b684403 49 virtual void clear(unsigned int c = 0xFF000000);
jonebuckman 0:90962b684403 50
jonebuckman 0:90962b684403 51 /** Draw a line between the specified coordinates using Bresenham's line algorithm
jonebuckman 0:90962b684403 52 *
jonebuckman 0:90962b684403 53 * @param x0 The starting X coordinate.
jonebuckman 0:90962b684403 54 * @param y0 The starting Y coordinate.
jonebuckman 0:90962b684403 55 * @param x1 The ending X coordinate.
jonebuckman 0:90962b684403 56 * @param y1 The ending Y coordinate.
jonebuckman 0:90962b684403 57 * @param c The color of the line as a 32-bit ARGB value.
jonebuckman 0:90962b684403 58 */
jonebuckman 0:90962b684403 59 virtual void drawLine(int x0, int y0, int x1, int y1, unsigned int c);
jonebuckman 0:90962b684403 60
jonebuckman 0:90962b684403 61 /** Draw a fast horizontal line of the specified width, at the specified coordinates
jonebuckman 0:90962b684403 62 *
jonebuckman 0:90962b684403 63 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 64 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 65 * @param w The width of the line.
jonebuckman 0:90962b684403 66 * @param c The color of the line as a 32-bit ARGB value.
jonebuckman 0:90962b684403 67 */
jonebuckman 0:90962b684403 68 virtual void drawHLine(int x, int y, int w, unsigned int c);
jonebuckman 0:90962b684403 69
jonebuckman 0:90962b684403 70 /** Draw a fast vertical line of the specified height, at the specified coordinates
jonebuckman 0:90962b684403 71 *
jonebuckman 0:90962b684403 72 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 73 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 74 * @param h The height of the line.
jonebuckman 0:90962b684403 75 * @param c The color of the line as a 32-bit ARGB value.
jonebuckman 0:90962b684403 76 */
jonebuckman 0:90962b684403 77 virtual void drawVLine(int x, int y, int h, unsigned int c);
jonebuckman 0:90962b684403 78
jonebuckman 0:90962b684403 79 /** Draw an unfilled rectangle of the specified width and height, at the specified coordinates using fast lines
jonebuckman 0:90962b684403 80 *
jonebuckman 0:90962b684403 81 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 82 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 83 * @param w The width of the rectangle.
jonebuckman 0:90962b684403 84 * @param h The height of the rectangle.
jonebuckman 0:90962b684403 85 * @param c The color of the rectangle as a 32-bit ARGB value.
jonebuckman 0:90962b684403 86 */
jonebuckman 0:90962b684403 87 virtual void drawRect(int x, int y, int w, int h, unsigned int c);
jonebuckman 0:90962b684403 88
jonebuckman 0:90962b684403 89 /** Draw a filled rectangle of the specified width and height, at the specified coordinates using fast lines
jonebuckman 0:90962b684403 90 *
jonebuckman 0:90962b684403 91 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 92 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 93 * @param w The width of the rectangle.
jonebuckman 0:90962b684403 94 * @param h The height of the rectangle.
jonebuckman 0:90962b684403 95 * @param c The color of the rectangle as a 32-bit ARGB value.
jonebuckman 0:90962b684403 96 */
jonebuckman 0:90962b684403 97 virtual void fillRect(int x, int y, int w, int h, unsigned int c);
jonebuckman 0:90962b684403 98
jonebuckman 0:90962b684403 99 /** Draw an unfilled triangle with the specified vertices using lines
jonebuckman 0:90962b684403 100 *
jonebuckman 0:90962b684403 101 * @param x0 The first vertex X coordinate.
jonebuckman 0:90962b684403 102 * @param y0 The first vertex Y coordinate.
jonebuckman 0:90962b684403 103 * @param x1 The second vertex X coordinate.
jonebuckman 0:90962b684403 104 * @param y1 The second vertex Y coordinate.
jonebuckman 0:90962b684403 105 * @param x2 The third vertex X coordinate.
jonebuckman 0:90962b684403 106 * @param y2 The third vertex Y coordinate.
jonebuckman 0:90962b684403 107 * @param c The color of the triangle as a 32-bit ARGB value.
jonebuckman 0:90962b684403 108 */
jonebuckman 0:90962b684403 109 void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int c);
jonebuckman 0:90962b684403 110
jonebuckman 0:90962b684403 111 /** Draw a filled triangle with the specified vertices using Adafruit's algorithm
jonebuckman 0:90962b684403 112 *
jonebuckman 0:90962b684403 113 * @param x0 The first vertex X coordinate.
jonebuckman 0:90962b684403 114 * @param y0 The first vertex Y coordinate.
jonebuckman 0:90962b684403 115 * @param x1 The second vertex X coordinate.
jonebuckman 0:90962b684403 116 * @param y1 The second vertex Y coordinate.
jonebuckman 0:90962b684403 117 * @param x2 The third vertex X coordinate.
jonebuckman 0:90962b684403 118 * @param y2 The third vertex Y coordinate.
jonebuckman 0:90962b684403 119 * @param c The color of the triangle as a 32-bit ARGB value.
jonebuckman 0:90962b684403 120 */
jonebuckman 0:90962b684403 121 void fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int c);
jonebuckman 0:90962b684403 122
jonebuckman 0:90962b684403 123 /** Draw an unfilled circle of the specified radius, at the specified coordinates using the midpoint circle algorithm
jonebuckman 0:90962b684403 124 *
jonebuckman 0:90962b684403 125 * @param x The center X coordinate.
jonebuckman 0:90962b684403 126 * @param y The center Y coordinate.
jonebuckman 0:90962b684403 127 * @param r The radius of the circle.
jonebuckman 0:90962b684403 128 * @param c The color of the circle as a 32-bit ARGB value.
jonebuckman 0:90962b684403 129 */
jonebuckman 0:90962b684403 130 void drawCircle(int x, int y, int r, unsigned int c);
jonebuckman 0:90962b684403 131
jonebuckman 0:90962b684403 132 /** Draw a filled circle of the specified radius, at the specified coordinates using Adafruit's modified midpoint circle algorithm
jonebuckman 0:90962b684403 133 *
jonebuckman 0:90962b684403 134 * @param x The center X coordinate.
jonebuckman 0:90962b684403 135 * @param y The center Y coordinate.
jonebuckman 0:90962b684403 136 * @param r The radius of the circle.
jonebuckman 0:90962b684403 137 * @param c The color of the circle as a 32-bit ARGB value.
jonebuckman 0:90962b684403 138 */
jonebuckman 0:90962b684403 139 void fillCircle(int x, int y, int r, unsigned int c);
jonebuckman 0:90962b684403 140
jonebuckman 0:90962b684403 141 /** Draw an unfilled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm
jonebuckman 0:90962b684403 142 *
jonebuckman 0:90962b684403 143 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 144 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 145 * @param w The width of the rectangle.
jonebuckman 0:90962b684403 146 * @param h The height of the rectangle.
jonebuckman 0:90962b684403 147 * @param r The radius of the corners.
jonebuckman 0:90962b684403 148 * @param c The color of the rectangle as a 32-bit ARGB value.
jonebuckman 0:90962b684403 149 */
jonebuckman 0:90962b684403 150 void drawRoundRect(int x, int y, int w, int h, int r, unsigned int c);
jonebuckman 0:90962b684403 151
jonebuckman 0:90962b684403 152 /** Draw a filled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm
jonebuckman 0:90962b684403 153 *
jonebuckman 0:90962b684403 154 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 155 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 156 * @param w The width of the rectangle.
jonebuckman 0:90962b684403 157 * @param h The height of the rectangle.
jonebuckman 0:90962b684403 158 * @param r The radius of the corners.
jonebuckman 0:90962b684403 159 * @param c The color of the rectangle as a 32-bit ARGB value.
jonebuckman 0:90962b684403 160 */
jonebuckman 0:90962b684403 161 void fillRoundRect(int x, int y, int w, int h, int r, unsigned int c);
jonebuckman 0:90962b684403 162
jonebuckman 0:90962b684403 163 /** Draw an Image object at the specified coordinates
jonebuckman 0:90962b684403 164 *
jonebuckman 0:90962b684403 165 * @param img Pointer to the image to draw.
jonebuckman 0:90962b684403 166 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 167 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 168 */
jonebuckman 0:90962b684403 169 void drawImage(Image* img, int x, int y);
jonebuckman 0:90962b684403 170
jonebuckman 0:90962b684403 171 /** Draw a character at the specified coordinates without wrapping
jonebuckman 0:90962b684403 172 *
jonebuckman 0:90962b684403 173 * @param c The character to draw.
jonebuckman 0:90962b684403 174 * @param fnt Pointer to the font to draw with.
jonebuckman 0:90962b684403 175 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 176 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 177 *
jonebuckman 0:90962b684403 178 * @returns The width of the drawn character.
jonebuckman 0:90962b684403 179 */
jonebuckman 0:90962b684403 180 int drawChar(char c, Font* fnt, int x, int y);
jonebuckman 0:90962b684403 181
jonebuckman 0:90962b684403 182 /** Draw a string at the specified coordinates without wrapping
jonebuckman 0:90962b684403 183 *
jonebuckman 0:90962b684403 184 * @param str Pointer to the string to draw.
jonebuckman 0:90962b684403 185 * @param fnt Pointer to the font to draw with.
jonebuckman 0:90962b684403 186 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 187 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 188 */
jonebuckman 0:90962b684403 189 void drawString(const char* str, Font* fnt, int x, int y);
jonebuckman 0:90962b684403 190
jonebuckman 0:90962b684403 191 /** Draw a string within the specified rectangle with wrapping
jonebuckman 0:90962b684403 192 *
jonebuckman 0:90962b684403 193 * @param str Pointer to the string to draw.
jonebuckman 0:90962b684403 194 * @param fnt Pointer to the font to draw with.
jonebuckman 0:90962b684403 195 * @param x The starting X coordinate.
jonebuckman 0:90962b684403 196 * @param y The starting Y coordinate.
jonebuckman 0:90962b684403 197 * @param w The width of the bounding rectangle.
jonebuckman 0:90962b684403 198 * @param h The height of the bounding rectangle.
jonebuckman 0:90962b684403 199 */
jonebuckman 0:90962b684403 200 void drawString(const char* str, Font* fnt, int x, int y, int w, int h);
jonebuckman 0:90962b684403 201
jonebuckman 0:90962b684403 202 /** Get the width of the canvas
jonebuckman 0:90962b684403 203 *
jonebuckman 0:90962b684403 204 * @returns The width of the canvas.
jonebuckman 0:90962b684403 205 */
jonebuckman 0:90962b684403 206 int width();
jonebuckman 0:90962b684403 207
jonebuckman 0:90962b684403 208 /** Get the height of the canvas
jonebuckman 0:90962b684403 209 *
jonebuckman 0:90962b684403 210 * @returns The height of the canvas.
jonebuckman 0:90962b684403 211 */
jonebuckman 0:90962b684403 212 int height();
jonebuckman 0:90962b684403 213
jonebuckman 0:90962b684403 214 protected:
jonebuckman 0:90962b684403 215 //The canvas width/height
jonebuckman 0:90962b684403 216 int m_Width, m_Height;
jonebuckman 0:90962b684403 217
jonebuckman 0:90962b684403 218 //Drawing helper functions
jonebuckman 0:90962b684403 219 void drawCircleHelper(int x, int y, int r, unsigned int corner, unsigned int color);
jonebuckman 0:90962b684403 220 void fillCircleHelper(int x, int y, int r, unsigned int corner, int delta, unsigned int color);
jonebuckman 0:90962b684403 221 };
jonebuckman 0:90962b684403 222
jonebuckman 0:90962b684403 223 #endif