Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

Button.cpp

Go to the documentation of this file.
00001 00006 /* 00007 Copyright (C) 2004 Anders Hedstrom 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 */ 00023 #include <SDL.h> 00024 #include "guitypedefs.h" 00025 #include "guicolors.h" 00026 #ifdef _WIN32 00027 #pragma warning(push) 00028 00029 #include <yvals.h> // warning numbers get enabled in yvals.h 00030 00031 #pragma warning(disable: 4251) 00032 #pragma warning(disable: 4786) // identifier was truncated to 'number' characters in the debug information 00033 00034 // BUG: C4786 Warning Is Not Disabled with #pragma Warning 00035 // STATUS: Microsoft has confirmed this to be a bug in the Microsoft product. This warning can be ignored. 00036 // This occured only in the <map> container. 00037 00038 #include <sge.h> 00039 00040 #pragma warning(pop) 00041 #else 00042 #include <sge.h> 00043 #endif 00044 //#include <iotm/Mutex.h> 00045 #include "SDL_prim.h" 00046 00047 #include "TTFont.h" 00048 #include "SDLControl.h" 00049 #include "Surface.h" 00050 #include "Static.h" 00051 #include "Button.h" 00052 00053 00054 namespace gui 00055 { 00056 00057 00058 Button::Button(Surface *s,coord_t x,coord_t y,coord_t w,coord_t h,SurfaceHelper *pclHelper) 00059 :Surface(s,x,y,w,h,pclHelper) 00060 ,m_screen_inverted(NULL) 00061 ,m_screen_inactive(NULL) 00062 ,m_style(0) 00063 { 00064 SetBgColor(BUTTON_DEFAULT_BG_R,BUTTON_DEFAULT_BG_G,BUTTON_DEFAULT_BG_B); 00065 SetFgColor(BUTTON_DEFAULT_FG_R,BUTTON_DEFAULT_FG_G,BUTTON_DEFAULT_FG_B); 00066 SetFrameWidth(BUTTON_DEFAULT_FW); 00067 SetFrameColor(BUTTON_DEFAULT_FC_R,BUTTON_DEFAULT_FC_G,BUTTON_DEFAULT_FC_B); 00068 00069 m_screen_inverted = CreateSDLSurface(true); 00070 m_screen_inactive = CreateSDLSurface(true); 00071 } 00072 00073 00074 Button::Button(Surface *s,coord_t x,coord_t y,buttonstyle_t st,SurfaceHelper *pclHelper) 00075 :Surface(s,x,y,SBSIZE,SBSIZE,pclHelper) 00076 ,m_screen_inverted(NULL) 00077 ,m_screen_inactive(NULL) 00078 ,m_style(st) 00079 { 00080 SetBgColor(BUTTON_DEFAULT_BG_R,BUTTON_DEFAULT_BG_G,BUTTON_DEFAULT_BG_B); 00081 SetFgColor(BUTTON_DEFAULT_FG_R,BUTTON_DEFAULT_FG_G,BUTTON_DEFAULT_FG_B); 00082 SetFrameWidth(BUTTON_DEFAULT_FW); 00083 SetFrameColor(BUTTON_DEFAULT_FC_R,BUTTON_DEFAULT_FC_G,BUTTON_DEFAULT_FC_B); 00084 00085 m_screen_inverted = CreateSDLSurface(true); 00086 m_screen_inactive = CreateSDLSurface(true); 00087 } 00088 00089 00090 Button::~Button() 00091 { 00092 if (m_screen_inverted) 00093 { 00094 SDL_FreeSurface(m_screen_inverted); 00095 } 00096 if (m_screen_inactive) 00097 { 00098 SDL_FreeSurface(m_screen_inactive); 00099 } 00100 } 00101 00102 00103 void Button::Draw() 00104 { 00105 SDL_Rect *area = GetClientRectPtr(); 00106 // color_t color = GetBgColor(); 00107 TTFont *font = GetTTFont(); 00108 SDL_Color fg; 00109 SDL_Color bg; 00110 coord_t x1; 00111 coord_t y1; 00112 coord_t x2; 00113 coord_t y2; 00114 coord_t x3; 00115 coord_t y3; 00116 // bool bMinneInverted = IsInverted(); 00117 00118 // SetInverted(false); 00119 00120 DEB(printf(" ******** Button redraw\n");) 00121 00122 GetFgColor(fg); 00123 GetBgColor(bg); 00124 00125 #define SPACED 3 00126 00127 switch (m_style) 00128 { 00129 case BUTTONSTYLE_SBUP: // Scrollbar 00130 x1 = area -> w / 2; 00131 y1 = SPACED; 00132 x2 = SPACED; 00133 y2 = area -> h - SPACED; 00134 x3 = area -> w - SPACED; 00135 y3 = area -> h - SPACED; 00136 // m_screen 00137 SDL_FillRect(m_screen, area, GetBgColor()); 00138 SDL_fillTriangle(m_screen, x1,y1, x2,y2, x3,y3, GetFgColor()); 00139 // m_screen_inverted 00140 SDL_FillRect(m_screen_inverted, area, GetFgColor()); 00141 SDL_fillTriangle(m_screen_inverted, x1,y1, x2,y2, x3,y3, GetBgColor()); 00142 // m_screen_inactive 00143 break; 00144 case BUTTONSTYLE_SBDOWN: // Scrollbar 00145 x1 = SPACED; 00146 y1 = SPACED; 00147 x2 = area -> w - SPACED; 00148 y2 = SPACED; 00149 x3 = area -> w / 2; 00150 y3 = area -> h - SPACED; 00151 // m_screen 00152 SDL_FillRect(m_screen, area, GetBgColor()); 00153 SDL_fillTriangle(m_screen, x1,y1, x2,y2, x3,y3, GetFgColor()); 00154 // m_screen_inverted 00155 SDL_FillRect(m_screen_inverted, area, GetFgColor()); 00156 SDL_fillTriangle(m_screen_inverted, x1,y1, x2,y2, x3,y3, GetBgColor()); 00157 // m_screen_inactive 00158 break; 00159 case BUTTONSTYLE_SBRIGHT: // Scrollbar 00160 x1 = SPACED; 00161 y1 = SPACED; 00162 x2 = area -> w - SPACED; 00163 y2 = area -> h / 2; 00164 x3 = SPACED; 00165 y3 = area -> h - SPACED; 00166 // m_screen 00167 SDL_FillRect(m_screen, area, GetBgColor()); 00168 SDL_fillTriangle(m_screen, x1,y1, x2,y2, x3,y3, GetFgColor()); 00169 // m_screen_inverted 00170 SDL_FillRect(m_screen_inverted, area, GetFgColor()); 00171 SDL_fillTriangle(m_screen_inverted, x1,y1, x2,y2, x3,y3, GetBgColor()); 00172 // m_screen_inactive 00173 break; 00174 case BUTTONSTYLE_SBLEFT: // Scrollbar 00175 x1 = SPACED; 00176 y1 = area -> h / 2; 00177 x2 = area -> w - SPACED; 00178 y2 = SPACED; 00179 x3 = area -> w - SPACED; 00180 y3 = area -> h - SPACED; 00181 // m_screen 00182 SDL_FillRect(m_screen, area, GetBgColor()); 00183 SDL_fillTriangle(m_screen, x1,y1, x2,y2, x3,y3, GetFgColor()); 00184 // m_screen_inverted 00185 SDL_FillRect(m_screen, area, GetFgColor()); 00186 SDL_fillTriangle(m_screen, x1,y1, x2,y2, x3,y3, GetBgColor()); 00187 // m_screen_inactive 00188 break; 00189 00190 default: 00191 { 00192 // Normal 00193 SDL_FillRect(m_screen, area, GetBgColor()); 00194 00195 if (font && font -> GetFont()) 00196 { 00197 SDL_Rect rect = sge_TTF_TextSize(font -> GetFont(), (char *)GetText()); 00198 coord_t x = GetW() / 2 - rect.w / 2; 00199 coord_t y = GetH() / 2 + font -> GetH() / 2; 00200 00201 sge_tt_textoutf(m_screen, font -> GetFont(), 00202 x,y, 00203 fg.r,fg.g,fg.b, 00204 bg.r,bg.g,bg.b, 00205 SDL_ALPHA_OPAQUE, 00206 "%s",GetText() ); 00207 } 00208 DrawFrame(m_screen, GetFrameWidth(), GetFrameColor()); 00209 00210 // Inverted 00211 SDL_FillRect(m_screen_inverted, area, GetFgColor()); 00212 00213 if (font && font -> GetFont()) 00214 { 00215 SDL_Rect rect = sge_TTF_TextSize(font -> GetFont(), (char *)GetText()); 00216 coord_t x = GetW() / 2 - rect.w / 2; 00217 coord_t y = GetH() / 2 + font -> GetH() / 2; 00218 00219 sge_tt_textoutf(m_screen_inverted, font -> GetFont(), 00220 x,y, 00221 bg.r,bg.g,bg.b, 00222 fg.r,fg.g,fg.b, 00223 SDL_ALPHA_OPAQUE, 00224 "%s",GetText() ); 00225 } 00226 DrawFrame(m_screen_inverted, GetFrameWidth(), GetFrameColor()); 00227 00228 // Inactive 00229 } // case 0 00230 break; 00231 } // switch (m_style) 00232 // SetInverted(bMinneInverted); 00233 } 00234 00235 00236 SDL_Surface *Button::GetScreen() 00237 { 00238 if (IsInverted()) 00239 { 00240 return m_screen_inverted; 00241 } 00242 /* 00243 if (IsInactive()) 00244 { 00245 return m_screen_inactive; 00246 } 00247 */ 00248 return m_screen; 00249 } 00250 00251 00252 } // namespace 00253 00254 //sge_TTF_FontHeight 00255 //sge_TTF_TextSize

Generated for My SDL C++ Gui by doxygen 1.3.6

www.TV-friendship.com
The matchmaking service with an all new twist.

Quantum 'Teleportation'
Some thoughts
Page, code, and content Copyright (C) 2004 by Anders Hedström