A simple yet powerful library for controlling graphical displays. Multiple display controllers are supported using inheritance.
Dependents: mbed_rifletool Hexi_Bubble_Game Hexi_Catch-the-dot_Game Hexi_Acceleromagnetic_Synth
Canvas.h
00001 /* NeatGUI Library 00002 * Copyright (c) 2013 Neil Thiessen 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CANVAS_H 00018 #define CANVAS_H 00019 00020 #include "mbed.h" 00021 #include "Image.h" 00022 #include "Font.h" 00023 00024 /** Canvas abstract class. 00025 * Used as a base class for objects that provide 2D drawing capabilities. 00026 */ 00027 class Canvas 00028 { 00029 public: 00030 /** Create a Canvas object with the specified width and height 00031 * 00032 * @param w The canvas width. 00033 * @param h The canvas height. 00034 */ 00035 Canvas(int w, int h); 00036 00037 /** Draw a single pixel at the specified coordinates 00038 * 00039 * @param x The X coordinate. 00040 * @param y The Y coordinate. 00041 * @param c The color of the pixel as a 32-bit ARGB value. 00042 */ 00043 virtual void drawPixel(int x, int y, unsigned int c) = 0; 00044 00045 /** Fill the entire canvas with the specified color using a filled rectangle 00046 * 00047 * @param c The color to fill with as a 32-bit ARGB value (black by default). 00048 */ 00049 virtual void clear(unsigned int c = 0xFF000000); 00050 00051 /** Draw a line between the specified coordinates using Bresenham's line algorithm 00052 * 00053 * @param x0 The starting X coordinate. 00054 * @param y0 The starting Y coordinate. 00055 * @param x1 The ending X coordinate. 00056 * @param y1 The ending Y coordinate. 00057 * @param c The color of the line as a 32-bit ARGB value. 00058 */ 00059 virtual void drawLine(int x0, int y0, int x1, int y1, unsigned int c); 00060 00061 /** Draw a fast horizontal line of the specified width, at the specified coordinates 00062 * 00063 * @param x The starting X coordinate. 00064 * @param y The starting Y coordinate. 00065 * @param w The width of the line. 00066 * @param c The color of the line as a 32-bit ARGB value. 00067 */ 00068 virtual void drawHLine(int x, int y, int w, unsigned int c); 00069 00070 /** Draw a fast vertical line of the specified height, at the specified coordinates 00071 * 00072 * @param x The starting X coordinate. 00073 * @param y The starting Y coordinate. 00074 * @param h The height of the line. 00075 * @param c The color of the line as a 32-bit ARGB value. 00076 */ 00077 virtual void drawVLine(int x, int y, int h, unsigned int c); 00078 00079 /** Draw an unfilled rectangle of the specified width and height, at the specified coordinates using fast lines 00080 * 00081 * @param x The starting X coordinate. 00082 * @param y The starting Y coordinate. 00083 * @param w The width of the rectangle. 00084 * @param h The height of the rectangle. 00085 * @param c The color of the rectangle as a 32-bit ARGB value. 00086 */ 00087 virtual void drawRect(int x, int y, int w, int h, unsigned int c); 00088 00089 /** Draw a filled rectangle of the specified width and height, at the specified coordinates using fast lines 00090 * 00091 * @param x The starting X coordinate. 00092 * @param y The starting Y coordinate. 00093 * @param w The width of the rectangle. 00094 * @param h The height of the rectangle. 00095 * @param c The color of the rectangle as a 32-bit ARGB value. 00096 */ 00097 virtual void fillRect(int x, int y, int w, int h, unsigned int c); 00098 00099 /** Draw an unfilled triangle with the specified vertices using lines 00100 * 00101 * @param x0 The first vertex X coordinate. 00102 * @param y0 The first vertex Y coordinate. 00103 * @param x1 The second vertex X coordinate. 00104 * @param y1 The second vertex Y coordinate. 00105 * @param x2 The third vertex X coordinate. 00106 * @param y2 The third vertex Y coordinate. 00107 * @param c The color of the triangle as a 32-bit ARGB value. 00108 */ 00109 void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int c); 00110 00111 /** Draw a filled triangle with the specified vertices using Adafruit's algorithm 00112 * 00113 * @param x0 The first vertex X coordinate. 00114 * @param y0 The first vertex Y coordinate. 00115 * @param x1 The second vertex X coordinate. 00116 * @param y1 The second vertex Y coordinate. 00117 * @param x2 The third vertex X coordinate. 00118 * @param y2 The third vertex Y coordinate. 00119 * @param c The color of the triangle as a 32-bit ARGB value. 00120 */ 00121 void fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned int c); 00122 00123 /** Draw an unfilled circle of the specified radius, at the specified coordinates using the midpoint circle algorithm 00124 * 00125 * @param x The center X coordinate. 00126 * @param y The center Y coordinate. 00127 * @param r The radius of the circle. 00128 * @param c The color of the circle as a 32-bit ARGB value. 00129 */ 00130 void drawCircle(int x, int y, int r, unsigned int c); 00131 00132 /** Draw a filled circle of the specified radius, at the specified coordinates using Adafruit's modified midpoint circle algorithm 00133 * 00134 * @param x The center X coordinate. 00135 * @param y The center Y coordinate. 00136 * @param r The radius of the circle. 00137 * @param c The color of the circle as a 32-bit ARGB value. 00138 */ 00139 void fillCircle(int x, int y, int r, unsigned int c); 00140 00141 /** Draw an unfilled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm 00142 * 00143 * @param x The starting X coordinate. 00144 * @param y The starting Y coordinate. 00145 * @param w The width of the rectangle. 00146 * @param h The height of the rectangle. 00147 * @param r The radius of the corners. 00148 * @param c The color of the rectangle as a 32-bit ARGB value. 00149 */ 00150 void drawRoundRect(int x, int y, int w, int h, int r, unsigned int c); 00151 00152 /** Draw a filled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm 00153 * 00154 * @param x The starting X coordinate. 00155 * @param y The starting Y coordinate. 00156 * @param w The width of the rectangle. 00157 * @param h The height of the rectangle. 00158 * @param r The radius of the corners. 00159 * @param c The color of the rectangle as a 32-bit ARGB value. 00160 */ 00161 void fillRoundRect(int x, int y, int w, int h, int r, unsigned int c); 00162 00163 /** Draw an Image object at the specified coordinates 00164 * 00165 * @param img Pointer to the image to draw. 00166 * @param x The starting X coordinate. 00167 * @param y The starting Y coordinate. 00168 */ 00169 void drawImage(Image* img, int x, int y); 00170 00171 /** Draw a character at the specified coordinates without wrapping 00172 * 00173 * @param c The character to draw. 00174 * @param fnt Pointer to the font to draw with. 00175 * @param x The starting X coordinate. 00176 * @param y The starting Y coordinate. 00177 * 00178 * @returns The width of the drawn character. 00179 */ 00180 int drawChar(char c, Font* fnt, int x, int y); 00181 00182 /** Draw a string at the specified coordinates without wrapping 00183 * 00184 * @param str Pointer to the string to draw. 00185 * @param fnt Pointer to the font to draw with. 00186 * @param x The starting X coordinate. 00187 * @param y The starting Y coordinate. 00188 */ 00189 void drawString(const char* str, Font* fnt, int x, int y); 00190 00191 /** Draw a string within the specified rectangle with wrapping 00192 * 00193 * @param str Pointer to the string to draw. 00194 * @param fnt Pointer to the font to draw with. 00195 * @param x The starting X coordinate. 00196 * @param y The starting Y coordinate. 00197 * @param w The width of the bounding rectangle. 00198 * @param h The height of the bounding rectangle. 00199 */ 00200 void drawString(const char* str, Font* fnt, int x, int y, int w, int h); 00201 00202 /** Get the width of the canvas 00203 * 00204 * @returns The width of the canvas. 00205 */ 00206 int width(); 00207 00208 /** Get the height of the canvas 00209 * 00210 * @returns The height of the canvas. 00211 */ 00212 int height(); 00213 00214 protected: 00215 //The canvas width/height 00216 int m_Width, m_Height; 00217 00218 //Drawing helper functions 00219 void drawCircleHelper(int x, int y, int r, unsigned int corner, unsigned int color); 00220 void fillCircleHelper(int x, int y, int r, unsigned int corner, int delta, unsigned int color); 00221 }; 00222 00223 #endif
Generated on Tue Jul 12 2022 20:26:18 by 1.7.2