00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
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 }