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 #include "Control.h"
jonebuckman 0:90962b684403 18
jonebuckman 0:90962b684403 19 Control::Control(int x, int y, int w, int h)
jonebuckman 0:90962b684403 20 {
jonebuckman 0:90962b684403 21 m_X = x;
jonebuckman 0:90962b684403 22 m_Y = y;
jonebuckman 0:90962b684403 23 m_Width = w;
jonebuckman 0:90962b684403 24 m_Height = h;
jonebuckman 0:90962b684403 25 m_Margin = 0;
jonebuckman 0:90962b684403 26 m_Border = 0;
jonebuckman 0:90962b684403 27 m_Padding = 0;
jonebuckman 0:90962b684403 28 m_FgColor = 0xFFFFFFFF;
jonebuckman 0:90962b684403 29 m_BgColor = 0xFF000000;
jonebuckman 0:90962b684403 30 m_Text = NULL;
jonebuckman 0:90962b684403 31 m_Font = NULL;
jonebuckman 0:90962b684403 32 m_Invalid = true;
jonebuckman 0:90962b684403 33 }
jonebuckman 0:90962b684403 34
jonebuckman 0:90962b684403 35 void Control::paint(Canvas* canvas)
jonebuckman 0:90962b684403 36 {
jonebuckman 0:90962b684403 37 //Fill the control's content and padding area
jonebuckman 0:90962b684403 38 canvas->fillRect(contentPosX() - m_Padding, contentPosY() - m_Padding , contentWidth() + m_Padding * 2, contentHeight() + m_Padding * 2, m_BgColor);
jonebuckman 0:90962b684403 39
jonebuckman 0:90962b684403 40 //Check if we need to draw a border
jonebuckman 0:90962b684403 41 if (m_Border > 0) {
jonebuckman 0:90962b684403 42 //Draw the border
jonebuckman 0:90962b684403 43 for (int i = 0; i < border(); i++) {
jonebuckman 0:90962b684403 44 canvas->drawRect(m_X + m_Margin + i, m_Y + m_Margin + i, m_Width - 2 * (m_Margin + i), m_Height - 2 * (m_Margin + i), m_FgColor);
jonebuckman 0:90962b684403 45 }
jonebuckman 0:90962b684403 46 }
jonebuckman 0:90962b684403 47
jonebuckman 0:90962b684403 48 //We're no longer invalid
jonebuckman 0:90962b684403 49 m_Invalid = false;
jonebuckman 0:90962b684403 50 }
jonebuckman 0:90962b684403 51
jonebuckman 0:90962b684403 52 int Control::posX()
jonebuckman 0:90962b684403 53 {
jonebuckman 0:90962b684403 54 return m_X;
jonebuckman 0:90962b684403 55 }
jonebuckman 0:90962b684403 56
jonebuckman 0:90962b684403 57 void Control::posX(int x)
jonebuckman 0:90962b684403 58 {
jonebuckman 0:90962b684403 59 //Set the new value
jonebuckman 0:90962b684403 60 m_X = x;
jonebuckman 0:90962b684403 61
jonebuckman 0:90962b684403 62 //Force a repaint
jonebuckman 0:90962b684403 63 m_Invalid = true;
jonebuckman 0:90962b684403 64 }
jonebuckman 0:90962b684403 65
jonebuckman 0:90962b684403 66 int Control::posY()
jonebuckman 0:90962b684403 67 {
jonebuckman 0:90962b684403 68 return m_Y;
jonebuckman 0:90962b684403 69 }
jonebuckman 0:90962b684403 70
jonebuckman 0:90962b684403 71 void Control::posY(int y)
jonebuckman 0:90962b684403 72 {
jonebuckman 0:90962b684403 73 //Set the new value
jonebuckman 0:90962b684403 74 m_Y = y;
jonebuckman 0:90962b684403 75
jonebuckman 0:90962b684403 76 //Force a repaint
jonebuckman 0:90962b684403 77 m_Invalid = true;
jonebuckman 0:90962b684403 78 }
jonebuckman 0:90962b684403 79
jonebuckman 0:90962b684403 80 int Control::width()
jonebuckman 0:90962b684403 81 {
jonebuckman 0:90962b684403 82 return m_Width;
jonebuckman 0:90962b684403 83 }
jonebuckman 0:90962b684403 84
jonebuckman 0:90962b684403 85 void Control::width(int w)
jonebuckman 0:90962b684403 86 {
jonebuckman 0:90962b684403 87 //Set the new value
jonebuckman 0:90962b684403 88 m_Width = w;
jonebuckman 0:90962b684403 89
jonebuckman 0:90962b684403 90 //Force a repaint
jonebuckman 0:90962b684403 91 m_Invalid = true;
jonebuckman 0:90962b684403 92 }
jonebuckman 0:90962b684403 93
jonebuckman 0:90962b684403 94 int Control::height()
jonebuckman 0:90962b684403 95 {
jonebuckman 0:90962b684403 96 return m_Height;
jonebuckman 0:90962b684403 97 }
jonebuckman 0:90962b684403 98
jonebuckman 0:90962b684403 99 void Control::height(int h)
jonebuckman 0:90962b684403 100 {
jonebuckman 0:90962b684403 101 //Set the new value
jonebuckman 0:90962b684403 102 m_Height = h;
jonebuckman 0:90962b684403 103
jonebuckman 0:90962b684403 104 //Force a repaint
jonebuckman 0:90962b684403 105 m_Invalid = true;
jonebuckman 0:90962b684403 106 }
jonebuckman 0:90962b684403 107
jonebuckman 0:90962b684403 108 int Control::margin()
jonebuckman 0:90962b684403 109 {
jonebuckman 0:90962b684403 110 return m_Margin;
jonebuckman 0:90962b684403 111 }
jonebuckman 0:90962b684403 112
jonebuckman 0:90962b684403 113 void Control::margin(int m)
jonebuckman 0:90962b684403 114 {
jonebuckman 0:90962b684403 115 //Update the value
jonebuckman 0:90962b684403 116 m_Margin = m;
jonebuckman 0:90962b684403 117
jonebuckman 0:90962b684403 118 //Need to repaint
jonebuckman 0:90962b684403 119 m_Invalid = true;
jonebuckman 0:90962b684403 120 }
jonebuckman 0:90962b684403 121
jonebuckman 0:90962b684403 122 int Control::border()
jonebuckman 0:90962b684403 123 {
jonebuckman 0:90962b684403 124 return m_Border;
jonebuckman 0:90962b684403 125 }
jonebuckman 0:90962b684403 126
jonebuckman 0:90962b684403 127 void Control::border(int b)
jonebuckman 0:90962b684403 128 {
jonebuckman 0:90962b684403 129 //Update the value
jonebuckman 0:90962b684403 130 m_Border = b;
jonebuckman 0:90962b684403 131
jonebuckman 0:90962b684403 132 //Need to repaint
jonebuckman 0:90962b684403 133 m_Invalid = true;
jonebuckman 0:90962b684403 134 }
jonebuckman 0:90962b684403 135
jonebuckman 0:90962b684403 136 int Control::padding()
jonebuckman 0:90962b684403 137 {
jonebuckman 0:90962b684403 138 return m_Padding;
jonebuckman 0:90962b684403 139 }
jonebuckman 0:90962b684403 140
jonebuckman 0:90962b684403 141 void Control::padding(int p)
jonebuckman 0:90962b684403 142 {
jonebuckman 0:90962b684403 143 //Update the value
jonebuckman 0:90962b684403 144 m_Padding = p;
jonebuckman 0:90962b684403 145
jonebuckman 0:90962b684403 146 //Need to repaint
jonebuckman 0:90962b684403 147 m_Invalid = true;
jonebuckman 0:90962b684403 148 }
jonebuckman 0:90962b684403 149
jonebuckman 0:90962b684403 150 int Control::contentPosX()
jonebuckman 0:90962b684403 151 {
jonebuckman 0:90962b684403 152 return m_X + m_Margin + m_Border + m_Padding;
jonebuckman 0:90962b684403 153 }
jonebuckman 0:90962b684403 154
jonebuckman 0:90962b684403 155 int Control::contentPosY()
jonebuckman 0:90962b684403 156 {
jonebuckman 0:90962b684403 157 return m_Y + m_Margin + m_Border + m_Padding;
jonebuckman 0:90962b684403 158 }
jonebuckman 0:90962b684403 159
jonebuckman 0:90962b684403 160 int Control::contentWidth()
jonebuckman 0:90962b684403 161 {
jonebuckman 0:90962b684403 162 return m_Width - (m_Margin + m_Border + m_Padding) * 2;
jonebuckman 0:90962b684403 163 }
jonebuckman 0:90962b684403 164
jonebuckman 0:90962b684403 165 int Control::contentHeight()
jonebuckman 0:90962b684403 166 {
jonebuckman 0:90962b684403 167 return m_Height - (m_Margin + m_Border + m_Padding) * 2;
jonebuckman 0:90962b684403 168 }
jonebuckman 0:90962b684403 169
jonebuckman 0:90962b684403 170 unsigned int Control::foreColor()
jonebuckman 0:90962b684403 171 {
jonebuckman 0:90962b684403 172 return m_FgColor;
jonebuckman 0:90962b684403 173 }
jonebuckman 0:90962b684403 174
jonebuckman 0:90962b684403 175 void Control::foreColor(unsigned int c)
jonebuckman 0:90962b684403 176 {
jonebuckman 0:90962b684403 177 //Update the value
jonebuckman 0:90962b684403 178 m_FgColor = c;
jonebuckman 0:90962b684403 179
jonebuckman 0:90962b684403 180 //Need to repaint
jonebuckman 0:90962b684403 181 m_Invalid = true;
jonebuckman 0:90962b684403 182 }
jonebuckman 0:90962b684403 183
jonebuckman 0:90962b684403 184 unsigned int Control::backColor()
jonebuckman 0:90962b684403 185 {
jonebuckman 0:90962b684403 186 return m_BgColor;
jonebuckman 0:90962b684403 187 }
jonebuckman 0:90962b684403 188
jonebuckman 0:90962b684403 189 void Control::backColor(unsigned int c)
jonebuckman 0:90962b684403 190 {
jonebuckman 0:90962b684403 191 //Update the value
jonebuckman 0:90962b684403 192 m_BgColor = c;
jonebuckman 0:90962b684403 193
jonebuckman 0:90962b684403 194 //Need to repaint
jonebuckman 0:90962b684403 195 m_Invalid = true;
jonebuckman 0:90962b684403 196 }
jonebuckman 0:90962b684403 197
jonebuckman 0:90962b684403 198 const char* Control::text()
jonebuckman 0:90962b684403 199 {
jonebuckman 0:90962b684403 200 return m_Text;
jonebuckman 0:90962b684403 201 }
jonebuckman 0:90962b684403 202
jonebuckman 0:90962b684403 203 void Control::text(const char* text)
jonebuckman 0:90962b684403 204 {
jonebuckman 0:90962b684403 205 //Update the value
jonebuckman 0:90962b684403 206 m_Text = text;
jonebuckman 0:90962b684403 207
jonebuckman 0:90962b684403 208 //Need to repaint
jonebuckman 0:90962b684403 209 m_Invalid = true;
jonebuckman 0:90962b684403 210 }
jonebuckman 0:90962b684403 211
jonebuckman 0:90962b684403 212 Font* Control::font()
jonebuckman 0:90962b684403 213 {
jonebuckman 0:90962b684403 214 return m_Font;
jonebuckman 0:90962b684403 215 }
jonebuckman 0:90962b684403 216
jonebuckman 0:90962b684403 217 void Control::font(Font* fnt)
jonebuckman 0:90962b684403 218 {
jonebuckman 0:90962b684403 219 //Update the value
jonebuckman 0:90962b684403 220 m_Font = fnt;
jonebuckman 0:90962b684403 221
jonebuckman 0:90962b684403 222 //Need to repaint
jonebuckman 0:90962b684403 223 m_Invalid = true;
jonebuckman 0:90962b684403 224 }
jonebuckman 0:90962b684403 225
jonebuckman 0:90962b684403 226 bool Control::invalid()
jonebuckman 0:90962b684403 227 {
jonebuckman 0:90962b684403 228 return m_Invalid;
jonebuckman 0:90962b684403 229 }
jonebuckman 0:90962b684403 230
jonebuckman 0:90962b684403 231 void Control::invalidate()
jonebuckman 0:90962b684403 232 {
jonebuckman 0:90962b684403 233 m_Invalid = true;
jonebuckman 0:90962b684403 234 }