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

pglistboxitem.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:03 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pglistboxitem.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #include "pglistboxitem.h"
00030 #include "pglistbox.h"
00031 #include "pgapplication.h"
00032 #include "pgtheme.h"
00033 
00034 #include "propstrings_priv.h"
00035 
00036 PG_ListBoxItem::PG_ListBoxItem(PG_Widget* parent, int height, const std::string& text, SDL_Surface* icon, void* userdata, const std::string& style) : PG_ListBoxBaseItem(parent, height, userdata) {
00037         my_srfHover = NULL;
00038         my_srfSelected = NULL;
00039 
00040         my_srfIcon = icon;
00041 
00042         for(int i=0; i<3; i++) {
00043                 my_background[i] = NULL;
00044                 my_bkmode[i] = PG_Draw::TILE;
00045                 my_blend[i] = 0;
00046                 my_gradient[i] = NULL;
00047         }
00048 
00049         LoadThemeStyle(style, PG_PropStr::ListBoxItem);
00050    SetText(text);
00051 
00052 }
00053 
00054 PG_ListBoxItem::~PG_ListBoxItem() {
00055         PG_ThemeWidget::DeleteThemedSurface(my_srfHover);
00056         PG_ThemeWidget::DeleteThemedSurface(my_srfSelected);
00057 }
00058 
00059 void PG_ListBoxItem::eventSizeWidget(Uint16 w, Uint16 h) {
00060         PG_ThemeWidget::DeleteThemedSurface(my_srfHover);
00061         PG_ThemeWidget::DeleteThemedSurface(my_srfSelected);
00062 
00063         // reset surface pointers, will be regenerated on next blit
00064         my_srfHover = NULL;
00065         my_srfSelected = NULL;
00066 }
00067 
00068 void PG_ListBoxItem::eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst) {
00069 
00070         if((dst.my_width == 0) || (dst.my_height == 0)) {
00071                 return;
00072         }
00073 
00074         if(my_srfHover == NULL) {
00075                 my_srfHover = PG_ThemeWidget::CreateThemedSurface(
00076                                   PG_Rect(0, 0, my_width, my_height),
00077                                   my_gradient[2],
00078                                   my_background[2],
00079                                   my_bkmode[2],
00080                                   my_blend[2]);
00081         }
00082 
00083         if(my_srfSelected == NULL) {
00084                 my_srfSelected = PG_ThemeWidget::CreateThemedSurface(
00085                                      PG_Rect(0, 0, my_width, my_height),
00086                                      my_gradient[1],
00087                                      my_background[1],
00088                                      my_bkmode[1],
00089                                      my_blend[1]);
00090         }
00091 
00092         if(my_selected) {
00093                 PG_Widget::eventBlit(my_srfSelected, src, dst);
00094         } else if(my_hover) {
00095                 PG_Widget::eventBlit(my_srfHover, src, dst);
00096         }
00097 
00098         PG_Label::eventBlit(NULL, src, dst);
00099 }
00100 
00101 void PG_ListBoxItem::LoadThemeStyle(const std::string& widgettype, const std::string& objectname) {
00102         PG_Theme* t = PG_Application::GetTheme();
00103         PG_Gradient* g = NULL;
00104 
00105         my_background[0] = t->FindSurface(widgettype, objectname, PG_PropStr::background0);
00106         my_background[1] = t->FindSurface(widgettype, objectname, PG_PropStr::background1);
00107         my_background[2] = t->FindSurface(widgettype, objectname, PG_PropStr::background2);
00108 
00109         t->GetProperty(widgettype, objectname, PG_PropStr::blend0, my_blend[0]);
00110         t->GetProperty(widgettype, objectname, PG_PropStr::blend1, my_blend[1]);
00111         t->GetProperty(widgettype, objectname, PG_PropStr::blend2, my_blend[2]);
00112 
00113         t->GetProperty(widgettype, objectname, PG_PropStr::backmode0, my_bkmode[0]);
00114         t->GetProperty(widgettype, objectname, PG_PropStr::backmode1, my_bkmode[1]);
00115         t->GetProperty(widgettype, objectname, PG_PropStr::backmode2, my_bkmode[2]);
00116 
00117         g = t->FindGradient(widgettype, objectname, PG_PropStr::gradient0);
00118         if(g)
00119                 my_gradient[0] = g;
00120         g = t->FindGradient(widgettype, objectname, PG_PropStr::gradient1);
00121         if(g)
00122                 my_gradient[1] = g;
00123         g = t->FindGradient(widgettype, objectname, PG_PropStr::gradient2);
00124         if(g)
00125                 my_gradient[2] = g;
00126 
00127         PG_Color fontcolor(0xFFFFFF);
00128         t->GetColor(widgettype, objectname, PG_PropStr::textcolor, fontcolor);
00129         SetFontColor(fontcolor);
00130 }

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