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

MenuItem.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 00045 #include "TTFont.h" 00046 #include "Surface.h" 00047 #include "Hotspot.h" 00048 #include "MenuItem.h" 00049 #include "Xml.h" 00050 00051 using util::Xml; 00052 00053 00054 namespace gui 00055 { 00056 00057 00058 MenuItem::MenuItem(Surface *s,const string &txt,TTFont *pclFont,SurfaceHelper *pclHelper) 00059 :Surface(s,pclHelper) 00060 ,m_bClickCloses(true) 00061 { 00062 TTFont *font; 00063 SDL_Rect rect; 00064 00065 SetText(txt); 00066 if (pclFont) 00067 { 00068 SetTTFont(pclFont); 00069 } 00070 SetClickable(true); 00071 SetInverted(false); 00072 00073 font = GetTTFont(); 00074 font -> GetRect(txt, rect); 00075 00076 SetFrameWidth(0); 00077 SetW(rect.w + rect.h + 8, false); 00078 SetH(rect.h, false); 00079 } 00080 00081 00082 void MenuItem::CreateMenuItem() 00083 { 00084 RecreateSurfaces(); 00085 } 00086 00087 00088 MenuItem::~MenuItem() 00089 { 00090 } 00091 00092 00093 void MenuItem::Draw() 00094 { 00095 SDL_Rect *area = GetClientRectPtr(); 00096 Uint32 color; 00097 TTFont *font = GetTTFont(); 00098 SDL_Color fg; 00099 SDL_Color bg; 00100 00101 /* 00102 if (IsInverted()) 00103 { 00104 color = GetBgColor(); 00105 memmove(&fg,&color,4); 00106 color = GetFgColor(); 00107 memmove(&bg,&color,4); 00108 } 00109 else 00110 { 00111 */ 00112 color = GetFgColor(); 00113 memmove(&fg,&color,4); 00114 color = GetBgColor(); 00115 memmove(&bg,&color,4); 00116 // } 00117 00118 // color 0 - transparent 00119 SDL_FillRect(m_screen, area, color); 00120 00121 if (font && font -> GetFont()) 00122 { 00123 coord_t h = font -> GetH(); 00124 coord_t y = GetH() / 2 + h / 2; 00125 00126 sge_tt_textoutf(m_screen, font -> GetFont(), 00127 GetH() + 4,y, 00128 fg.r,fg.g,fg.b, 00129 bg.r,bg.g,bg.b, 00130 SDL_ALPHA_OPAQUE, 00131 "%s",GetText()); 00132 } 00133 } 00134 00135 00136 void MenuItem::OnMouseIn() 00137 { 00138 if (IsClickable()) 00139 { 00140 SetInverted(true); 00141 SetDirty(true); 00142 } 00143 } 00144 00145 00146 void MenuItem::OnMouseOut() 00147 { 00148 if (IsClickable()) 00149 { 00150 SetInverted(false); 00151 SetDirty(true); 00152 } 00153 } 00154 00155 00156 void MenuItem::OnClick(coord_t x,coord_t y) 00157 { 00158 if (m_bClickCloses) 00159 { 00160 Surface *head = GetParent(); 00161 00162 while (head -> GetBond()) 00163 { 00164 head = head -> GetBond(); 00165 } 00166 head -> CloseAll(); 00167 head -> RemoveAllBonds(); 00168 } 00169 OnButton(); 00170 } 00171 00172 00173 void MenuItem::SetClickCloses(bool b) 00174 { 00175 m_bClickCloses = b; 00176 } 00177 00178 00179 void MenuItem::DumpMembers(FILE *fil) 00180 { 00181 Xml xml(fil); 00182 00183 Surface::DumpMembers(fil); 00184 00185 xml.Write("CLICKCLOSES",m_bClickCloses); 00186 } 00187 00188 00189 } // namespace

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