Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

theme_priv.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:16:01 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/themes/theme_priv.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #include "theme_priv.h"
00030 #include "pgcolor.h"
00031 
00032 THEME_THEME::~THEME_THEME() {
00033         // clean up
00034         for(MAP_WIDGET::iterator i = widget.begin(); i != widget.end(); i++) {
00035                 delete (*i).second;
00036         }
00037         widget.clear();
00038 
00039         delete defaultfont;
00040 }
00041 
00042 THEME_WIDGET* THEME_THEME::FindWidget(const std::string& widgettype) {
00043         MAP_WIDGET::iterator i = widget.find(widgettype);
00044         if(i == widget.end()) {
00045                 return NULL;
00046         }
00047 
00048         return (*i).second;
00049 }
00050 
00051 THEME_OBJECT* THEME_THEME::FindObject(const std::string& widgettype, const std::string& objectname) {
00052         THEME_WIDGET* widget = FindWidget(widgettype);
00053 
00054         if(widget == NULL) {
00055                 return NULL;
00056         }
00057 
00058         THEME_OBJECT* object = widget->FindObject(objectname);
00059 
00060         return object;
00061 }
00062 
00063 SDL_Surface* THEME_THEME::FindSurface(const std::string& widgettype, const std::string& objectname, const std::string& name) {
00064         THEME_OBJECT* object = FindObject(widgettype, objectname);
00065 
00066         if(object == NULL) {
00067                 return NULL;
00068         }
00069 
00070         return object->FindSurface(name);
00071 }
00072 
00073 PG_Gradient* THEME_THEME::FindGradient(const std::string& widgettype, const std::string& objectname, const std::string& name) {
00074         THEME_OBJECT* object = FindObject(widgettype, objectname);
00075 
00076         if(object == NULL) {
00077                 return NULL;
00078         }
00079 
00080         return object->FindGradient(name);
00081 }
00082 
00083 void THEME_THEME::GetProperty(const std::string& widgettype, const std::string& objectname, const std::string& name, long& prop) {
00084         THEME_OBJECT* o = FindObject(widgettype, objectname);
00085 
00086         if(o == NULL) {
00087                 return;
00088         }
00089 
00090         long n = o->FindProperty(name);
00091         if(n == -1) {
00092                 return;
00093         }
00094 
00095         prop = n;
00096 }
00097 
00098 void THEME_THEME::GetProperty(const std::string& widgettype, const std::string& objectname, const std::string& name, Uint8& prop) {
00099         THEME_OBJECT* o = FindObject(widgettype, objectname);
00100 
00101         if(o == NULL) {
00102                 return;
00103         }
00104 
00105         long n = o->FindProperty(name);
00106         if(n == -1) {
00107                 return;
00108         }
00109 
00110         prop = (Uint8)n;
00111 }
00112 
00113 void THEME_THEME::GetProperty(const std::string& widgettype, const std::string& objectname, const std::string& name, bool& prop) {
00114         THEME_OBJECT* o = FindObject(widgettype, objectname);
00115 
00116         if(o == NULL) {
00117                 return;
00118         }
00119 
00120         long n = o->FindProperty(name);
00121         if(n == -1) {
00122                 return;
00123         }
00124 
00125         prop = (n == 1);
00126 }
00127 
00128 void THEME_THEME::GetProperty(const std::string& widgettype, const std::string& objectname, const std::string& name, int& prop) {
00129         THEME_OBJECT* o = FindObject(widgettype, objectname);
00130 
00131         if(o == NULL) {
00132                 return;
00133         }
00134 
00135         long n = o->FindProperty(name);
00136         if(n == -1) {
00137                 return;
00138         }
00139 
00140         prop = (int)n;
00141 }
00142 
00143 void THEME_THEME::GetProperty(const std::string& widgettype, const std::string& objectname, const std::string& name, PG_Draw::BkMode& prop) {
00144         THEME_OBJECT* o = FindObject(widgettype, objectname);
00145 
00146         if(o == NULL) {
00147                 return;
00148         }
00149 
00150         long n = o->FindProperty(name);
00151         if(n == -1) {
00152                 return;
00153         }
00154 
00155         prop = (PG_Draw::BkMode)n;
00156 }
00157 
00158 const std::string& THEME_THEME::FindString(const std::string& widgettype, const std::string& objectname, const std::string& name) {
00159         THEME_OBJECT* object = FindObject(widgettype, objectname);
00160 
00161         if(object == NULL) {
00162                 return PG_NULLSTR;
00163         }
00164 
00165         return object->FindString(name);
00166 }
00167 
00168 const std::string& THEME_THEME::FindDefaultFontName() {
00169         return defaultfont->value;
00170 }
00171 
00172 int THEME_THEME::FindDefaultFontSize() {
00173         if(!defaultfont) {
00174                 return 14;
00175         }
00176 
00177         return defaultfont->size;
00178 }
00179 
00180 PG_Font::Style THEME_THEME::FindDefaultFontStyle() {
00181         if(!defaultfont) {
00182                 return PG_Font::NORMAL;
00183         }
00184 
00185         return defaultfont->style;
00186 }
00187 
00188 const std::string& THEME_THEME::FindFontName(const std::string& widgettype, const std::string& objectname) {
00189         THEME_OBJECT* o = FindObject(widgettype, objectname);
00190 
00191         if(o == NULL) {
00192                 return PG_NULLSTR;
00193         }
00194 
00195         if(!o->font) {
00196                 return PG_NULLSTR;
00197         }
00198 
00199         return o->font->value;
00200 }
00201 
00202 int THEME_THEME::FindFontSize(const std::string& widgettype, const std::string& objectname) {
00203         THEME_OBJECT* o = FindObject(widgettype, objectname);
00204 
00205         if(o == NULL) {
00206                 return 0;
00207         }
00208 
00209         if(!o->font) {
00210                 return 0;
00211         }
00212 
00213         return o->font->size;
00214 }
00215 
00216 PG_Font::Style THEME_THEME::FindFontStyle(const std::string& widgettype, const std::string& objectname) {
00217         THEME_OBJECT* o = FindObject(widgettype, objectname);
00218 
00219         if(o == NULL) {
00220                 return PG_Font::NORMAL;
00221         }
00222 
00223         if(!o->font) {
00224                 return PG_Font::NORMAL;
00225         }
00226 
00227         return o->font->style;
00228 }
00229 
00230 THEME_WIDGET::~THEME_WIDGET() {
00231         for(MAP_OBJECT::iterator i = object.begin(); i != object.end(); i++) {
00232                 delete (*i).second;
00233         }
00234         object.clear();
00235 }
00236 
00237 inline THEME_OBJECT* THEME_WIDGET::FindObject(const std::string& objectname) {
00238         MAP_OBJECT::iterator i = object.find(objectname);
00239         if(i == object.end()) {
00240                 return NULL;
00241         }
00242 
00243         return (*i).second;
00244 }
00245 
00246 THEME_OBJECT::THEME_OBJECT() {
00247         font = NULL;
00248 }
00249 
00250 THEME_OBJECT::~THEME_OBJECT() {
00251         for(MAP_FILENAME::iterator f = filename.begin(); f != filename.end(); f++) {
00252                 delete (*f).second;
00253         }
00254         filename.clear();
00255 
00256         for(MAP_GRADIENT::iterator g = gradient.begin(); g != gradient.end(); g++) {
00257                 delete (*g).second;
00258         }
00259         gradient.clear();
00260 
00261         for(MAP_PROPERTY::iterator p = property.begin(); p != property.end(); p++) {
00262                 delete (*p).second;
00263         }
00264         property.clear();
00265 
00266         for(Uint32 i=0; i<strings.size(); i++) {
00267                 delete strings[i];
00268                 strings[i] = NULL;
00269         }
00270         strings.clear();
00271 
00272         delete font;
00273 }
00274 
00275 SDL_Surface* THEME_OBJECT::FindSurface(const std::string& name) {
00276         MAP_FILENAME::iterator result = filename.find(name);
00277 
00278         if(result == filename.end()) {
00279                 return NULL;
00280         }
00281 
00282         return (*result).second->surface;
00283 }
00284 
00285 PG_Gradient* THEME_OBJECT::FindGradient(const std::string& name) {
00286         MAP_GRADIENT::iterator result = gradient.find(name);
00287 
00288         if(result == gradient.end()) {
00289                 return NULL;
00290         }
00291 
00292         return static_cast<PG_Gradient*>((*result).second);
00293 }
00294 
00295 void THEME_THEME::GetAlignment(const std::string& widgettype, const std::string& object, const std::string& name, PG_Label::TextAlign& align) {
00296         long b = -1;
00297         GetProperty(widgettype, object, name, b);
00298 
00299         if(b == -1) {
00300                 return;
00301         }
00302 
00303         switch(b) {
00304                 case 0:
00305                         align = PG_Label::LEFT;
00306                         break;
00307                 case 1:
00308                         align = PG_Label::CENTER;
00309                         break;
00310                 case 2:
00311                         align = PG_Label::RIGHT;
00312                         break;
00313         }
00314 
00315         return;
00316 }
00317 
00318 void THEME_THEME::GetColor(const std::string& widgettype, const std::string& object, const std::string& name, PG_Color& color) {
00319         long b = -1;
00320         GetProperty(widgettype, object, name, b);
00321 
00322         if(b == -1) {
00323                 return;
00324         }
00325 
00326         color = (Uint32)b;
00327 }
00328 
00329 long THEME_OBJECT::FindProperty(const std::string& name) {
00330         MAP_PROPERTY::iterator result = property.find(name);
00331 
00332         if(result == property.end()) {
00333                 return -1;
00334         }
00335 
00336         return (*result).second->value;
00337 }
00338 
00339 const std::string& THEME_OBJECT::FindString(const std::string& name) {
00340         for(Uint32 i=0; i<strings.size(); i++) {
00341                 if(strings[i]->name == name) {
00342                         return strings[i]->value;
00343                 }
00344         }
00345 
00346         return PG_NULLSTR;
00347 }

Generated on Tue Jun 24 01:27:53 2008 for Advanced Strategic Command by  doxygen 1.4.2