33 |
|
|
34 |
static PG_SurfaceCache my_SurfaceCache; |
static PG_SurfaceCache my_SurfaceCache; |
35 |
|
|
36 |
struct PG_WidgetDataInternal{ |
class PG_WidgetDataInternal { |
37 |
|
public: |
38 |
|
PG_WidgetDataInternal() : |
39 |
|
cachesurface(NULL), |
40 |
|
backgroundcolor(128,128,128), |
41 |
|
freeimage(false), |
42 |
|
simplebackground(false), |
43 |
|
nocache(false) {}; |
44 |
|
|
45 |
SDL_Surface* cachesurface; |
SDL_Surface* cachesurface; |
46 |
SDL_Color backgroundcolor; |
PG_Color backgroundcolor; |
47 |
|
|
48 |
bool freeimage; |
bool freeimage; |
49 |
bool simplebackground; |
bool simplebackground; |
62 |
void PG_ThemeWidget::Init(const char* style) { |
void PG_ThemeWidget::Init(const char* style) { |
63 |
SetDirtyUpdate(true); |
SetDirtyUpdate(true); |
64 |
|
|
65 |
my_internaldata = new PG_WidgetDataInternal; |
_mid = new PG_WidgetDataInternal; |
66 |
|
|
67 |
my_backgroundFree = false; |
my_backgroundFree = false; |
68 |
my_background = NULL; |
my_background = NULL; |
72 |
my_has_gradient = false; |
my_has_gradient = false; |
73 |
|
|
74 |
my_image = NULL; |
my_image = NULL; |
75 |
my_internaldata->freeimage = false; |
/*_mid->freeimage = false; |
76 |
my_internaldata->simplebackground = false; |
_mid->simplebackground = false; |
77 |
my_internaldata->nocache = false; |
_mid->nocache = false; |
|
|
|
|
my_internaldata->backgroundcolor.r = 128; |
|
|
my_internaldata->backgroundcolor.g = 128; |
|
|
my_internaldata->backgroundcolor.b = 128; |
|
78 |
|
|
79 |
my_internaldata->cachesurface = NULL; |
_mid->cachesurface = NULL;*/ |
80 |
|
|
81 |
LoadThemeStyle(style); |
LoadThemeStyle(style); |
82 |
} |
} |
88 |
FreeImage(); |
FreeImage(); |
89 |
|
|
90 |
// remove the cachesurface |
// remove the cachesurface |
91 |
DeleteThemedSurface(my_internaldata->cachesurface); |
DeleteThemedSurface(_mid->cachesurface); |
92 |
|
|
93 |
// delete internal data |
// delete internal data |
94 |
delete my_internaldata; |
delete _mid; |
95 |
} |
} |
96 |
|
|
97 |
void PG_ThemeWidget::LoadThemeStyle(const char* widgettype) { |
void PG_ThemeWidget::LoadThemeStyle(const char* widgettype) { |
102 |
} |
} |
103 |
|
|
104 |
void PG_ThemeWidget::LoadThemeStyle(const char* widgettype, const char* objectname) { |
void PG_ThemeWidget::LoadThemeStyle(const char* widgettype, const char* objectname) { |
|
int b; |
|
105 |
PG_Theme* t = PG_Application::GetTheme(); |
PG_Theme* t = PG_Application::GetTheme(); |
106 |
|
|
107 |
if(my_srfObject == NULL) { |
if(my_srfObject == NULL) { |
109 |
PG_ThemeWidget::LoadThemeStyle(widgettype, "ThemeWidget"); |
PG_ThemeWidget::LoadThemeStyle(widgettype, "ThemeWidget"); |
110 |
} |
} |
111 |
|
|
112 |
b = t->FindProperty(widgettype, objectname, "simplebackground"); |
t->GetProperty(widgettype, objectname, "simplebackground", _mid->simplebackground); |
113 |
if(b != -1) { |
t->GetProperty(widgettype, objectname, "nocache", _mid->nocache); |
114 |
SetSimpleBackground(b); |
t->GetColor(widgettype, objectname, "backgroundcolor", _mid->backgroundcolor); |
|
} |
|
|
//my_internaldata->simplebackground = (b != -1) ? b : my_internaldata->simplebackground; |
|
|
|
|
|
b = t->FindProperty(widgettype, objectname, "nocache"); |
|
|
my_internaldata->nocache = (b != -1) ? b : my_internaldata->nocache; |
|
|
|
|
|
SDL_Color* c = t->FindColor(widgettype, objectname, "backgroundcolor"); |
|
|
if(c != NULL) { |
|
|
my_internaldata->backgroundcolor = *c; |
|
|
} |
|
115 |
} |
} |
116 |
|
|
117 |
const char *font = t->FindFontName(widgettype, objectname); |
const char *font = t->FindFontName(widgettype, objectname); |
127 |
|
|
128 |
SetBackground(t->FindSurface(widgettype, objectname, "background")); |
SetBackground(t->FindSurface(widgettype, objectname, "background")); |
129 |
|
|
130 |
b = t->FindProperty(widgettype, objectname, "blend"); |
t->GetProperty(widgettype, objectname, "blend", my_blendLevel); |
131 |
|
t->GetProperty(widgettype, objectname, "bordersize", my_bordersize); |
132 |
if(b != -1) { |
t->GetProperty(widgettype, objectname, "backmode", my_backgroundMode); |
|
SetBackgroundBlend(b); |
|
|
} |
|
|
|
|
|
b = t->FindProperty(widgettype, objectname, "bordersize"); |
|
|
|
|
|
if(b != -1) { |
|
|
my_bordersize = b; |
|
|
} |
|
|
|
|
|
b = t->FindProperty(widgettype, objectname, "backmode"); |
|
|
|
|
|
if(b != -1) { |
|
|
my_backgroundMode = b; |
|
|
} |
|
133 |
|
|
134 |
PG_Gradient* g = t->FindGradient(widgettype, objectname, "gradient"); |
PG_Gradient* g = t->FindGradient(widgettype, objectname, "gradient"); |
135 |
|
|
137 |
SetGradient(*g); |
SetGradient(*g); |
138 |
my_has_gradient = true; |
my_has_gradient = true; |
139 |
} |
} |
|
|
|
|
b = t->FindProperty(widgettype, objectname, "transparency"); |
|
|
if(b != -1) |
|
|
SetTransparency((Uint32)b); |
|
140 |
|
|
141 |
PG_Widget::LoadThemeStyle(widgettype, objectname); |
Uint8 trans = GetTransparency(); |
142 |
|
t->GetProperty(widgettype, objectname, "transparency", trans); |
143 |
|
SetTransparency(trans); |
144 |
|
|
145 |
int w = t->FindProperty(widgettype, objectname, "width"); |
PG_Widget::LoadThemeStyle(widgettype, objectname); |
|
if (w==-1) |
|
|
w=Width(); |
|
|
int h = t->FindProperty(widgettype, objectname, "height"); |
|
|
if (h==-1) |
|
|
h=Height(); |
|
146 |
|
|
147 |
if(w <=0 || h <= 0) { |
int w = Width(); |
148 |
return; |
t->GetProperty(widgettype, objectname, "width", w); |
149 |
} |
int h = Height(); |
150 |
|
t->GetProperty(widgettype, objectname, "height", h); |
151 |
|
|
152 |
if((w != Width()) || (h != Height())) { |
if((w != Width()) || (h != Height())) { |
153 |
SizeWidget(w, h); |
SizeWidget(w, h); |
172 |
} |
} |
173 |
} |
} |
174 |
|
|
175 |
bool PG_ThemeWidget::SetBackground(const char* filename, int mode, Uint32 colorkey) { |
bool PG_ThemeWidget::SetBackground(const char* filename, int mode, const PG_Color &colorkey) { |
176 |
// try to load the file |
// try to load the file |
177 |
SDL_Surface* temp = PG_Application::LoadSurface(filename, true); |
SDL_Surface* temp = PG_Application::LoadSurface(filename, true); |
178 |
|
|
193 |
return false; |
return false; |
194 |
} |
} |
195 |
|
|
196 |
Uint32 c = SDL_MapRGB( |
Uint32 c = colorkey.MapRGB(my_background->format); |
|
my_background->format, |
|
|
(colorkey>>16) & 0xFF, |
|
|
(colorkey>>8) & 0xFF, |
|
|
colorkey & 0xFF); |
|
|
|
|
197 |
SDL_SetColorKey(my_background, SDL_SRCCOLORKEY, c); |
SDL_SetColorKey(my_background, SDL_SRCCOLORKEY, c); |
198 |
|
|
199 |
if(my_srfObject == NULL) { |
if(my_srfObject == NULL) { |
266 |
void PG_ThemeWidget::SetGradient(PG_Gradient& grad) { |
void PG_ThemeWidget::SetGradient(PG_Gradient& grad) { |
267 |
my_gradient = grad; |
my_gradient = grad; |
268 |
my_has_gradient = true; |
my_has_gradient = true; |
269 |
DeleteThemedSurface(my_internaldata->cachesurface); |
DeleteThemedSurface(_mid->cachesurface); |
270 |
my_internaldata->cachesurface = NULL; |
_mid->cachesurface = NULL; |
271 |
Redraw(); |
Redraw(); |
272 |
} |
} |
273 |
|
|
281 |
|
|
282 |
void PG_ThemeWidget::FreeImage() { |
void PG_ThemeWidget::FreeImage() { |
283 |
|
|
284 |
if(my_internaldata->freeimage) { |
if(_mid->freeimage) { |
285 |
PG_Application::UnloadSurface(my_image); // false |
PG_Application::UnloadSurface(my_image); // false |
286 |
} |
} |
287 |
|
|
288 |
my_internaldata->freeimage = false; |
_mid->freeimage = false; |
289 |
my_image = NULL; |
my_image = NULL; |
290 |
return; |
return; |
291 |
} |
} |
300 |
} |
} |
301 |
|
|
302 |
FreeImage(); |
FreeImage(); |
303 |
my_internaldata->freeimage = bFreeImage; |
_mid->freeimage = bFreeImage; |
304 |
my_image = image; |
my_image = image; |
305 |
|
|
306 |
Update(); |
Update(); |
331 |
} |
} |
332 |
|
|
333 |
void PG_ThemeWidget::CreateSurface(Uint16 w, Uint16 h) { |
void PG_ThemeWidget::CreateSurface(Uint16 w, Uint16 h) { |
334 |
if(my_internaldata->simplebackground) { |
if(_mid->simplebackground) { |
335 |
return; |
return; |
336 |
} |
} |
337 |
|
|
338 |
DeleteThemedSurface(my_internaldata->cachesurface); |
DeleteThemedSurface(_mid->cachesurface); |
339 |
|
|
340 |
if(w == 0 || h == 0) { |
if(w == 0 || h == 0) { |
341 |
my_internaldata->cachesurface = NULL; |
_mid->cachesurface = NULL; |
342 |
return; |
return; |
343 |
} |
} |
344 |
|
|
345 |
PG_Rect r(my_xpos, my_ypos, w, h); |
PG_Rect r(my_xpos, my_ypos, w, h); |
346 |
|
|
347 |
my_internaldata->cachesurface = CreateThemedSurface( |
_mid->cachesurface = CreateThemedSurface( |
348 |
r, |
r, |
349 |
my_has_gradient ? &my_gradient : 0, |
my_has_gradient ? &my_gradient : 0, |
350 |
my_background, |
my_background, |
359 |
return; |
return; |
360 |
} |
} |
361 |
|
|
362 |
if(!my_internaldata->simplebackground && !my_internaldata->nocache) { |
if(!_mid->simplebackground && !_mid->nocache) { |
363 |
if(my_internaldata->cachesurface == NULL) { |
if(_mid->cachesurface == NULL) { |
364 |
CreateSurface(Width(), Height()); |
CreateSurface(Width(), Height()); |
365 |
} |
} |
366 |
PG_Widget::eventBlit(my_internaldata->cachesurface, src, dst); |
PG_Widget::eventBlit(_mid->cachesurface, src, dst); |
367 |
} else if (my_internaldata->simplebackground) { |
} else if (_mid->simplebackground) { |
368 |
if(GetTransparency() < 255) { |
if(GetTransparency() < 255) { |
369 |
Uint32 c = SDL_MapRGBA( |
Uint32 c = _mid->backgroundcolor.MapRGBA( |
370 |
my_srfScreen->format, |
my_srfScreen->format, |
371 |
my_internaldata->backgroundcolor.r, |
255-GetTransparency()); |
|
my_internaldata->backgroundcolor.g, |
|
|
my_internaldata->backgroundcolor.b, |
|
|
255-GetTransparency()); |
|
372 |
SDL_FillRect(my_srfScreen, (SDL_Rect*)&dst, c); |
SDL_FillRect(my_srfScreen, (SDL_Rect*)&dst, c); |
373 |
} |
} |
374 |
} else if (my_internaldata->nocache) { |
} else if (_mid->nocache) { |
375 |
my_internaldata->cachesurface = CreateThemedSurface( |
_mid->cachesurface = CreateThemedSurface( |
376 |
*this, |
*this, |
377 |
my_has_gradient ? &my_gradient : 0, |
my_has_gradient ? &my_gradient : 0, |
378 |
my_background, |
my_background, |
379 |
my_backgroundMode, |
my_backgroundMode, |
380 |
my_blendLevel); |
my_blendLevel); |
381 |
PG_Widget::eventBlit(my_internaldata->cachesurface, src, dst); |
PG_Widget::eventBlit(_mid->cachesurface, src, dst); |
382 |
DeleteThemedSurface(my_internaldata->cachesurface); |
DeleteThemedSurface(_mid->cachesurface); |
383 |
my_internaldata->cachesurface = NULL; |
_mid->cachesurface = NULL; |
384 |
} |
} |
385 |
|
|
386 |
if(my_bordersize > 0) { |
if(my_bordersize > 0) { |
397 |
} |
} |
398 |
|
|
399 |
void PG_ThemeWidget::SetTransparency(Uint8 t) { |
void PG_ThemeWidget::SetTransparency(Uint8 t) { |
400 |
if(my_internaldata->simplebackground || my_internaldata->nocache) { |
if(_mid->simplebackground || _mid->nocache) { |
401 |
PG_Widget::SetTransparency(t); |
PG_Widget::SetTransparency(t); |
402 |
return; |
return; |
403 |
} |
} |
404 |
|
|
405 |
if(t == 255) { |
if(t == 255) { |
406 |
DeleteThemedSurface(my_internaldata->cachesurface); |
DeleteThemedSurface(_mid->cachesurface); |
407 |
my_internaldata->cachesurface = NULL; |
_mid->cachesurface = NULL; |
408 |
} else if(GetTransparency() == 255) { |
} else if(GetTransparency() == 255) { |
409 |
CreateSurface(); |
CreateSurface(); |
410 |
} |
} |
491 |
} |
} |
492 |
|
|
493 |
void PG_ThemeWidget::SetSimpleBackground(bool simple) { |
void PG_ThemeWidget::SetSimpleBackground(bool simple) { |
494 |
my_internaldata->simplebackground = simple; |
_mid->simplebackground = simple; |
495 |
DeleteThemedSurface(my_internaldata->cachesurface); |
DeleteThemedSurface(_mid->cachesurface); |
496 |
my_internaldata->cachesurface = NULL; |
_mid->cachesurface = NULL; |
497 |
Redraw(); |
Redraw(); |
498 |
} |
} |
499 |
|
|
500 |
void PG_ThemeWidget::SetBackgroundColor(const SDL_Color& c) { |
void PG_ThemeWidget::SetBackgroundColor(const PG_Color& c) { |
501 |
my_internaldata->backgroundcolor = c; |
_mid->backgroundcolor = c; |
502 |
} |
} |