Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Control.cpp
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 #include "Control.h" 00018 00019 Control::Control(int x, int y, int w, int h) 00020 { 00021 m_X = x; 00022 m_Y = y; 00023 m_Width = w; 00024 m_Height = h; 00025 m_Margin = 0; 00026 m_Border = 0; 00027 m_Padding = 0; 00028 m_FgColor = 0xFFFFFFFF; 00029 m_BgColor = 0xFF000000; 00030 m_Text = NULL; 00031 m_Font = NULL; 00032 m_Invalid = true; 00033 } 00034 00035 void Control::paint(Canvas* canvas) 00036 { 00037 //Fill the control's content and padding area 00038 canvas->fillRect(contentPosX() - m_Padding, contentPosY() - m_Padding , contentWidth() + m_Padding * 2, contentHeight() + m_Padding * 2, m_BgColor); 00039 00040 //Check if we need to draw a border 00041 if (m_Border > 0) { 00042 //Draw the border 00043 for (int i = 0; i < border(); i++) { 00044 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); 00045 } 00046 } 00047 00048 //We're no longer invalid 00049 m_Invalid = false; 00050 } 00051 00052 int Control::posX() 00053 { 00054 return m_X; 00055 } 00056 00057 void Control::posX(int x) 00058 { 00059 //Set the new value 00060 m_X = x; 00061 00062 //Force a repaint 00063 m_Invalid = true; 00064 } 00065 00066 int Control::posY() 00067 { 00068 return m_Y; 00069 } 00070 00071 void Control::posY(int y) 00072 { 00073 //Set the new value 00074 m_Y = y; 00075 00076 //Force a repaint 00077 m_Invalid = true; 00078 } 00079 00080 int Control::width() 00081 { 00082 return m_Width; 00083 } 00084 00085 void Control::width(int w) 00086 { 00087 //Set the new value 00088 m_Width = w; 00089 00090 //Force a repaint 00091 m_Invalid = true; 00092 } 00093 00094 int Control::height() 00095 { 00096 return m_Height; 00097 } 00098 00099 void Control::height(int h) 00100 { 00101 //Set the new value 00102 m_Height = h; 00103 00104 //Force a repaint 00105 m_Invalid = true; 00106 } 00107 00108 int Control::margin() 00109 { 00110 return m_Margin; 00111 } 00112 00113 void Control::margin(int m) 00114 { 00115 //Update the value 00116 m_Margin = m; 00117 00118 //Need to repaint 00119 m_Invalid = true; 00120 } 00121 00122 int Control::border() 00123 { 00124 return m_Border; 00125 } 00126 00127 void Control::border(int b) 00128 { 00129 //Update the value 00130 m_Border = b; 00131 00132 //Need to repaint 00133 m_Invalid = true; 00134 } 00135 00136 int Control::padding() 00137 { 00138 return m_Padding; 00139 } 00140 00141 void Control::padding(int p) 00142 { 00143 //Update the value 00144 m_Padding = p; 00145 00146 //Need to repaint 00147 m_Invalid = true; 00148 } 00149 00150 int Control::contentPosX() 00151 { 00152 return m_X + m_Margin + m_Border + m_Padding; 00153 } 00154 00155 int Control::contentPosY() 00156 { 00157 return m_Y + m_Margin + m_Border + m_Padding; 00158 } 00159 00160 int Control::contentWidth() 00161 { 00162 return m_Width - (m_Margin + m_Border + m_Padding) * 2; 00163 } 00164 00165 int Control::contentHeight() 00166 { 00167 return m_Height - (m_Margin + m_Border + m_Padding) * 2; 00168 } 00169 00170 unsigned int Control::foreColor() 00171 { 00172 return m_FgColor; 00173 } 00174 00175 void Control::foreColor(unsigned int c) 00176 { 00177 //Update the value 00178 m_FgColor = c; 00179 00180 //Need to repaint 00181 m_Invalid = true; 00182 } 00183 00184 unsigned int Control::backColor() 00185 { 00186 return m_BgColor; 00187 } 00188 00189 void Control::backColor(unsigned int c) 00190 { 00191 //Update the value 00192 m_BgColor = c; 00193 00194 //Need to repaint 00195 m_Invalid = true; 00196 } 00197 00198 const char* Control::text() 00199 { 00200 return m_Text; 00201 } 00202 00203 void Control::text(const char* text) 00204 { 00205 //Update the value 00206 m_Text = text; 00207 00208 //Need to repaint 00209 m_Invalid = true; 00210 } 00211 00212 Font* Control::font() 00213 { 00214 return m_Font; 00215 } 00216 00217 void Control::font(Font* fnt) 00218 { 00219 //Update the value 00220 m_Font = fnt; 00221 00222 //Need to repaint 00223 m_Invalid = true; 00224 } 00225 00226 bool Control::invalid() 00227 { 00228 return m_Invalid; 00229 } 00230 00231 void Control::invalidate() 00232 { 00233 m_Invalid = true; 00234 }
Generated on Tue Jul 12 2022 21:38:03 by
1.7.2