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

NOTE: This library is in beta right now. As far as I know, everything here works, but there are many features that are lacking so far. Most notably containers, button handling, and display drivers other than the SSD1306.

Committer:
neilt6
Date:
Tue May 27 21:41:28 2014 +0000
Revision:
3:a8f72d4864e6
Parent:
2:bbfc18022ee5
Syntax improvements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neilt6 0:b876cf091464 1 /* NeatGUI Library
neilt6 0:b876cf091464 2 * Copyright (c) 2013 Neil Thiessen
neilt6 0:b876cf091464 3 *
neilt6 0:b876cf091464 4 * Licensed under the Apache License, Version 2.0 (the "License");
neilt6 0:b876cf091464 5 * you may not use this file except in compliance with the License.
neilt6 0:b876cf091464 6 * You may obtain a copy of the License at
neilt6 0:b876cf091464 7 *
neilt6 0:b876cf091464 8 * http://www.apache.org/licenses/LICENSE-2.0
neilt6 0:b876cf091464 9 *
neilt6 0:b876cf091464 10 * Unless required by applicable law or agreed to in writing, software
neilt6 0:b876cf091464 11 * distributed under the License is distributed on an "AS IS" BASIS,
neilt6 0:b876cf091464 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
neilt6 0:b876cf091464 13 * See the License for the specific language governing permissions and
neilt6 0:b876cf091464 14 * limitations under the License.
neilt6 0:b876cf091464 15 */
neilt6 0:b876cf091464 16
neilt6 0:b876cf091464 17 #ifndef CONTROL_H
neilt6 0:b876cf091464 18 #define CONTROL_H
neilt6 0:b876cf091464 19
neilt6 0:b876cf091464 20 #include "mbed.h"
neilt6 0:b876cf091464 21 #include "Canvas.h"
neilt6 0:b876cf091464 22
neilt6 0:b876cf091464 23 /** Control abstract class.
neilt6 0:b876cf091464 24 * Used as a base class for UI elements.
neilt6 0:b876cf091464 25 */
neilt6 0:b876cf091464 26 class Control
neilt6 0:b876cf091464 27 {
neilt6 0:b876cf091464 28 public:
neilt6 0:b876cf091464 29 /** Create a Control object with the specified size and location
neilt6 0:b876cf091464 30 *
neilt6 0:b876cf091464 31 * @param x The X coordinate of the control.
neilt6 0:b876cf091464 32 * @param y The Y coordinate of the control.
neilt6 0:b876cf091464 33 * @param w The width of the control.
neilt6 0:b876cf091464 34 * @param h The height of the control.
neilt6 0:b876cf091464 35 */
neilt6 0:b876cf091464 36 Control(int x, int y, int w, int h);
neilt6 0:b876cf091464 37
neilt6 0:b876cf091464 38 /** Paint the control on the specified canvas and mark as valid again
neilt6 2:bbfc18022ee5 39 *
neilt6 2:bbfc18022ee5 40 * @param canvas Pointer to the canvas to paint on.
neilt6 2:bbfc18022ee5 41 */
neilt6 0:b876cf091464 42 virtual void paint(Canvas *canvas);
neilt6 0:b876cf091464 43
neilt6 0:b876cf091464 44 /** Get the X coordinate of the control
neilt6 0:b876cf091464 45 *
neilt6 0:b876cf091464 46 * @returns The X coordinate of the control.
neilt6 0:b876cf091464 47 */
neilt6 1:f7003ec66a51 48 int posX();
neilt6 0:b876cf091464 49
neilt6 0:b876cf091464 50 /** Set the X coordinate of the control
neilt6 2:bbfc18022ee5 51 *
neilt6 2:bbfc18022ee5 52 * @param x The new X coordinate for the control.
neilt6 2:bbfc18022ee5 53 */
neilt6 0:b876cf091464 54 void posX(int x);
neilt6 0:b876cf091464 55
neilt6 0:b876cf091464 56 /** Get the Y coordinate of the control
neilt6 0:b876cf091464 57 *
neilt6 0:b876cf091464 58 * @returns The Y coordinate of the control.
neilt6 0:b876cf091464 59 */
neilt6 1:f7003ec66a51 60 int posY();
neilt6 0:b876cf091464 61
neilt6 0:b876cf091464 62 /** Set the Y coordinate of the control
neilt6 2:bbfc18022ee5 63 *
neilt6 2:bbfc18022ee5 64 * @param y The new Y coordinate for the control.
neilt6 2:bbfc18022ee5 65 */
neilt6 0:b876cf091464 66 void posY(int y);
neilt6 0:b876cf091464 67
neilt6 0:b876cf091464 68 /** Get the width of the control
neilt6 0:b876cf091464 69 *
neilt6 0:b876cf091464 70 * @returns The width of the control.
neilt6 0:b876cf091464 71 */
neilt6 1:f7003ec66a51 72 int width();
neilt6 0:b876cf091464 73
neilt6 0:b876cf091464 74 /** Set the width of the control
neilt6 2:bbfc18022ee5 75 *
neilt6 2:bbfc18022ee5 76 * @param w The new width for the control.
neilt6 2:bbfc18022ee5 77 */
neilt6 0:b876cf091464 78 void width(int w);
neilt6 0:b876cf091464 79
neilt6 0:b876cf091464 80 /** Get the height of the control
neilt6 0:b876cf091464 81 *
neilt6 0:b876cf091464 82 * @returns The height of the control.
neilt6 0:b876cf091464 83 */
neilt6 1:f7003ec66a51 84 int height();
neilt6 0:b876cf091464 85
neilt6 0:b876cf091464 86 /** Set the height of the control
neilt6 2:bbfc18022ee5 87 *
neilt6 2:bbfc18022ee5 88 * @param h The new height for the control.
neilt6 2:bbfc18022ee5 89 */
neilt6 0:b876cf091464 90 void height(int h);
neilt6 0:b876cf091464 91
neilt6 0:b876cf091464 92 /** Get the current margin width
neilt6 0:b876cf091464 93 *
neilt6 0:b876cf091464 94 * @returns The current margin width.
neilt6 0:b876cf091464 95 */
neilt6 1:f7003ec66a51 96 int margin();
neilt6 0:b876cf091464 97
neilt6 0:b876cf091464 98 /** Set the margin width
neilt6 2:bbfc18022ee5 99 *
neilt6 2:bbfc18022ee5 100 * @param m The new margin width.
neilt6 2:bbfc18022ee5 101 */
neilt6 0:b876cf091464 102 void margin(int m);
neilt6 0:b876cf091464 103
neilt6 0:b876cf091464 104 /** Get the current border width
neilt6 0:b876cf091464 105 *
neilt6 0:b876cf091464 106 * @returns The current border width.
neilt6 0:b876cf091464 107 */
neilt6 1:f7003ec66a51 108 int border();
neilt6 0:b876cf091464 109
neilt6 0:b876cf091464 110 /** Set the border width
neilt6 2:bbfc18022ee5 111 *
neilt6 2:bbfc18022ee5 112 * @param b The new border width.
neilt6 2:bbfc18022ee5 113 */
neilt6 0:b876cf091464 114 void border(int b);
neilt6 0:b876cf091464 115
neilt6 0:b876cf091464 116 /** Get the current padding width
neilt6 0:b876cf091464 117 *
neilt6 0:b876cf091464 118 * @returns The current padding width.
neilt6 0:b876cf091464 119 */
neilt6 1:f7003ec66a51 120 int padding();
neilt6 0:b876cf091464 121
neilt6 0:b876cf091464 122 /** Set the padding width
neilt6 2:bbfc18022ee5 123 *
neilt6 2:bbfc18022ee5 124 * @param p The new padding width.
neilt6 2:bbfc18022ee5 125 */
neilt6 0:b876cf091464 126 void padding(int p);
neilt6 0:b876cf091464 127
neilt6 0:b876cf091464 128 /** Get the X coordinate of the control's content area
neilt6 0:b876cf091464 129 *
neilt6 0:b876cf091464 130 * @returns The X coordinate of the control's content area.
neilt6 0:b876cf091464 131 */
neilt6 1:f7003ec66a51 132 int contentPosX();
neilt6 0:b876cf091464 133
neilt6 0:b876cf091464 134 /** Get the Y coordinate of the control's content area
neilt6 0:b876cf091464 135 *
neilt6 0:b876cf091464 136 * @returns The Y coordinate of the control's content area.
neilt6 0:b876cf091464 137 */
neilt6 1:f7003ec66a51 138 int contentPosY();
neilt6 0:b876cf091464 139
neilt6 0:b876cf091464 140 /** Get the width of the control's content area
neilt6 0:b876cf091464 141 *
neilt6 0:b876cf091464 142 * @returns The width of the control's content area.
neilt6 0:b876cf091464 143 */
neilt6 1:f7003ec66a51 144 int contentWidth();
neilt6 0:b876cf091464 145
neilt6 0:b876cf091464 146 /** Get the height of the control's content area
neilt6 0:b876cf091464 147 *
neilt6 0:b876cf091464 148 * @returns The height of the control's content area.
neilt6 0:b876cf091464 149 */
neilt6 1:f7003ec66a51 150 int contentHeight();
neilt6 0:b876cf091464 151
neilt6 0:b876cf091464 152 /** Get the foreground color
neilt6 2:bbfc18022ee5 153 *
neilt6 2:bbfc18022ee5 154 * @returns The foreground color as a 32-bit ARGB value.
neilt6 2:bbfc18022ee5 155 */
neilt6 1:f7003ec66a51 156 unsigned int foreColor();
neilt6 0:b876cf091464 157
neilt6 0:b876cf091464 158 /** Set the foreground color
neilt6 2:bbfc18022ee5 159 *
neilt6 2:bbfc18022ee5 160 * @param c The new foreground color as a 32-bit ARGB value.
neilt6 2:bbfc18022ee5 161 */
neilt6 0:b876cf091464 162 void foreColor(unsigned int c);
neilt6 0:b876cf091464 163
neilt6 0:b876cf091464 164 /** Get the background color
neilt6 2:bbfc18022ee5 165 *
neilt6 2:bbfc18022ee5 166 * @returns The background color as a 32-bit ARGB value.
neilt6 2:bbfc18022ee5 167 */
neilt6 1:f7003ec66a51 168 unsigned int backColor();
neilt6 0:b876cf091464 169
neilt6 0:b876cf091464 170 /** Set the background color
neilt6 2:bbfc18022ee5 171 *
neilt6 2:bbfc18022ee5 172 * @param c The new background color as a 32-bit ARGB value.
neilt6 2:bbfc18022ee5 173 */
neilt6 0:b876cf091464 174 void backColor(unsigned int c);
neilt6 0:b876cf091464 175
neilt6 0:b876cf091464 176 /** Get the current text of the control
neilt6 0:b876cf091464 177 *
neilt6 0:b876cf091464 178 * @returns The current text of the control.
neilt6 0:b876cf091464 179 */
neilt6 1:f7003ec66a51 180 const char* text();
neilt6 0:b876cf091464 181
neilt6 0:b876cf091464 182 /** Set the text of the control
neilt6 2:bbfc18022ee5 183 *
neilt6 2:bbfc18022ee5 184 * @param text The new text.
neilt6 2:bbfc18022ee5 185 */
neilt6 1:f7003ec66a51 186 void text(const char* text);
neilt6 0:b876cf091464 187
neilt6 0:b876cf091464 188 /** Get the current font of the control
neilt6 0:b876cf091464 189 *
neilt6 0:b876cf091464 190 * @returns The current font of the control.
neilt6 0:b876cf091464 191 */
neilt6 1:f7003ec66a51 192 Font* font();
neilt6 0:b876cf091464 193
neilt6 0:b876cf091464 194 /** Set the font of the control
neilt6 2:bbfc18022ee5 195 *
neilt6 2:bbfc18022ee5 196 * @param fnt The new font.
neilt6 2:bbfc18022ee5 197 */
neilt6 1:f7003ec66a51 198 void font(Font* fnt);
neilt6 0:b876cf091464 199
neilt6 0:b876cf091464 200 /** Determine whether the control needs to be repainted
neilt6 0:b876cf091464 201 *
neilt6 0:b876cf091464 202 * @returns Whether or not the control needs to be repainted.
neilt6 0:b876cf091464 203 */
neilt6 1:f7003ec66a51 204 bool invalid();
neilt6 0:b876cf091464 205
neilt6 0:b876cf091464 206 /** Mark this control as invalid
neilt6 0:b876cf091464 207 */
neilt6 1:f7003ec66a51 208 void invalidate();
neilt6 0:b876cf091464 209
neilt6 0:b876cf091464 210 protected:
neilt6 0:b876cf091464 211 int m_X, m_Y, m_Width, m_Height, m_Margin, m_Border, m_Padding;
neilt6 0:b876cf091464 212 unsigned int m_FgColor, m_BgColor;
neilt6 1:f7003ec66a51 213 const char* m_Text;
neilt6 1:f7003ec66a51 214 Font* m_Font;
neilt6 0:b876cf091464 215 bool m_Invalid;
neilt6 0:b876cf091464 216 };
neilt6 0:b876cf091464 217
neilt6 0:b876cf091464 218 #endif