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

PG_ThemeWidget Class Reference

Base class for themed widgets. More...

#include <pgthemewidget.h>

Inheritance diagram for PG_ThemeWidget:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 PG_ThemeWidget (PG_Widget *parent, const PG_Rect &r=PG_Rect::null, const std::string &style="ThemeWidget")
 Create a new PG_ThemeWidget object.
 PG_ThemeWidget (PG_Widget *parent, const PG_Rect &r, bool bCreateSurface, const std::string &style="ThemeWidget")
 Create a new PG_ThemeWidget object.
 ~PG_ThemeWidget ()
void LoadThemeStyle (const std::string &widgettype)
 Load a specific themestyle.
void LoadThemeStyle (const std::string &widgettype, const std::string &objectname)
 Load a style from the theme definition.
bool SetBackground (const std::string &filename, PG_Draw::BkMode mode=PG_Draw::TILE)
bool SetBackground (const std::string &filename, PG_Draw::BkMode mode, const PG_Color &colorkey)
bool SetBackground (SDL_Surface *surface, PG_Draw::BkMode mode=PG_Draw::TILE)
 Define a surface as background image (will not be freed).
void SetBackgroundBlend (Uint8 backblend)
 Defines the "blend-level" of gradient & background.
void SetGradient (const PG_Gradient &grad)
 Set the background gradient.
PG_Gradient GetGradient ()
 Get the background gradient.
bool LoadImage (const std::string &filename)
 Display an image in the widget.
bool LoadImage (const std::string &filename, const PG_Color &key)
 Display an image in the widget using a colorkey.
bool SetImage (SDL_Surface *image, bool bFreeImage=true)
 Display an image in the widget.
void SetTransparency (Uint8 t, bool bRecursive=false)
 Set the fransparency of the widget.
void SetSimpleBackground (bool simple)
void SetBackgroundColor (const PG_Color &c)

Static Public Member Functions

static SDL_Surface * CreateThemedSurface (const PG_Rect &r, PG_Gradient *gradient, SDL_Surface *background, PG_Draw::BkMode bkmode, Uint8 blend)
 Create a 'themed' surface.
static void DeleteThemedSurface (SDL_Surface *surface)
 Delete a themed surface.

Protected Member Functions

void eventSizeWidget (Uint16 w, Uint16 h)
 Callback for the SizeWidget event.
void eventDraw (SDL_Surface *surface, const PG_Rect &rect)
 overridable eventhandler to draw the object surface
void eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
 overridable eventhandler to blit the widget contents to the screen

Protected Attributes

bool my_has_gradient
PG_Gradient my_gradient
SDL_Surface * my_background
SDL_Surface * my_image
Uint8 my_blendLevel
bool my_backgroundFree
PG_Draw::BkMode my_backgroundMode

Detailed Description

Base class for themed widgets.

Author:
Alexander Pipelka
This class is the base class for all themed widgets.
It handles various combinations of gradients and background images.

Theme support

widget type: ThemeWidget (default)
object name: ThemeWidget

Parent theme:

PG_Widget theme

Theme sample:

	<widget>
		<type value="ThemeWidget"/>
			<object>
			<name value="ThemeWidget"/>
			<filename name="background" value="default/back.bmp"/>
			<property name="backmode" value="TILE"/>
			<gradient name="gradient"
				color0="0x00B0B1B6"
				color1="0x0083838D"
				color2="0x007B7B83"
				color3="0x00585765"/>
			<property name="blend" value="200"/>
			<property name="transparency" value="0"/>
			<property name="bordersize" value="1"/>
		</object>
	</widget>
	

Code:

Definition at line 84 of file pgthemewidget.h.


Constructor & Destructor Documentation

PG_ThemeWidget::PG_ThemeWidget PG_Widget parent,
const PG_Rect r = PG_Rect::null,
const std::string &  style = "ThemeWidget"
 

Create a new PG_ThemeWidget object.

Parameters:
parent Pointer to parent widget
r Position of the widget (related to parent or screen)
style Widgetstyle to load. This style should be defined at your theme file (default = "ThemeWidget") This constructor creates a themed widget without any drawing surface. All drawing operations can be done via the eventBlit() callback handler.

Definition at line 58 of file pgthemewidget.cpp.

Referenced by AllianceSetupWidget::AllianceSetupWidget(), AmmoTransferWindow::AmmoTransferWindow(), EmailSetupWidget::EmailSetupWidget(), InternalAmmoTransferWindow::InternalAmmoTransferWindow(), ASCGUI_Window::parsePanelASCTXT(), PG_ColorSelector::PG_ColorSelector(), PG_Window::PG_Window(), and PlayerSetupWidget::PlayerSetupWidget().

PG_ThemeWidget::PG_ThemeWidget PG_Widget parent,
const PG_Rect r,
bool  bCreateSurface,
const std::string &  style = "ThemeWidget"
 

Create a new PG_ThemeWidget object.

Parameters:
parent Pointer to parent widget
r Position of the widget (related to parent or screen)
bCreateSurface true - create a drawing surface for the widget.
style Widgetstyle to load. This style should be defined at your theme file (default = "ThemeWidget") This constructor creates a themed widget with an internal drawing surface. All drawing operations can be done via the eventDraw() callback handler. Additional blitting can be done via the eventBlit() callback. eventBlit() will NOT draw onto the internal drawing surface. Blitting will be done on the screen surface.

Definition at line 62 of file pgthemewidget.cpp.

PG_ThemeWidget::~PG_ThemeWidget  ) 
 

Definition at line 83 of file pgthemewidget.cpp.

References PG_ThemeWidgetDataInternal::cachesurface, and DeleteThemedSurface().


Member Function Documentation

SDL_Surface * PG_ThemeWidget::CreateThemedSurface const PG_Rect r,
PG_Gradient gradient,
SDL_Surface *  background,
PG_Draw::BkMode  bkmode,
Uint8  blend
[static]
 

Create a 'themed' surface.

Parameters:
r the dimensions of the surface to create
gradient pointer to a gradient structure (may be NULL)
background pointer to a background surface (may be NULL)
bkmode the mode how to fill in the background surface (BKMODE_TILE | BKMODE_STRETCH | BKMODE_3TILEH | BKMODE_3TILEV | BKMODE_9TILE)
blend the blend-level between gradient an background
Returns:
the newly created surface
The generated surface is managed by the surfacecache. Don't delete these surface with SDL_FreeSurface. Please use DeleteThemedSurface.

Definition at line 414 of file pgthemewidget.cpp.

References PG_SurfaceCache::AddSurface(), PG_SurfaceCache::CreateKey(), PG_Draw::DrawThemedSurface(), PG_SurfaceCache::FindSurface(), PG_Application::GetScreen(), PG_SurfaceCache::IncRef(), PG_Rect::my_height, PG_Rect::my_width, PG_Rect::PG_Rect(), and screen.

Referenced by eventBlit(), PG_ProgressBar::eventBlit(), PG_ListBoxItem::eventBlit(), PG_Image::eventBlit(), and PG_Button::eventButtonSurface().

void PG_ThemeWidget::DeleteThemedSurface SDL_Surface *  surface  )  [static]
 

Delete a themed surface.

Parameters:
surface pointer to surface

Definition at line 487 of file pgthemewidget.cpp.

References PG_SurfaceCache::DeleteSurface().

Referenced by eventBlit(), PG_ProgressBar::eventBlit(), PG_Button::eventButtonSurface(), eventSizeWidget(), PG_ListBoxItem::eventSizeWidget(), PG_Image::LoadImage(), PG_Image::SetColorKey(), PG_Image::SetDrawMode(), SetGradient(), PG_Image::SetImage(), SetSimpleBackground(), SetTransparency(), PG_Image::~PG_Image(), PG_ListBoxItem::~PG_ListBoxItem(), and ~PG_ThemeWidget().

void PG_ThemeWidget::eventBlit SDL_Surface *  surface,
const PG_Rect src,
const PG_Rect dst
[protected, virtual]
 

overridable eventhandler to blit the widget contents to the screen

Parameters:
surface pointer to SDL_Surface to be blitted
src source rectangle (client coordinates)
dst destination rectangle (screen coordinates) Override this eventhandler to perform custom blitting behaviour (without drawing onto the widget surface).

Reimplemented from PG_Widget.

Reimplemented in DamageBarWidget, PG_ColorSelector::PG_ColorBox, PG_Image, PG_LineEdit, PG_MultiLineEdit, PG_PopupMenu, PG_ProgressBar, PG_RichEdit, PG_Window, and BarGraphWidget.

Definition at line 355 of file pgthemewidget.cpp.

References PG_ThemeWidgetDataInternal::backgroundcolor, PG_ThemeWidgetDataInternal::cachesurface, CreateThemedSurface(), DeleteThemedSurface(), PG_Widget::DrawBorder(), PG_Widget::eventBlit(), PG_Widget::GetClipRects(), PG_Application::GetScreen(), PG_Widget::GetTransparency(), PG_Rect::Height(), PG_Color::MapRGBA(), my_background, my_backgroundMode, my_blendLevel, PG_Widget::my_bordersize, my_gradient, my_has_gradient, my_image, PG_Widget::my_srfObject, PG_ThemeWidgetDataInternal::nocache, PG_Rect::PG_Rect(), PG_ThemeWidgetDataInternal::simplebackground, and PG_Rect::Width().

Referenced by PG_Window::eventBlit(), PG_RichEdit::eventBlit(), PG_ProgressBar::eventBlit(), PG_PopupMenu::eventBlit(), PG_MultiLineEdit::eventBlit(), PG_LineEdit::eventBlit(), and PG_ColorSelector::PG_ColorBox::eventBlit().

void PG_ThemeWidget::eventDraw SDL_Surface *  surface,
const PG_Rect rect
[protected, virtual]
 

overridable eventhandler to draw the object surface

Parameters:
surface the widgets drawing surface.
rect rectangle to draw within. This eventhandler is called whenevener the widget contents should be redrawn.
Note:
Only widgets with drawing surfaces (see the constructor) will call this eventhandler.

Reimplemented from PG_Widget.

Reimplemented in PG_Image.

Definition at line 161 of file pgthemewidget.cpp.

References PG_Widget::DrawBorder(), PG_Draw::DrawThemedSurface(), my_background, my_backgroundMode, my_blendLevel, PG_Widget::my_bordersize, my_gradient, my_has_gradient, and PG_Widget::my_srfObject.

void PG_ThemeWidget::eventSizeWidget Uint16  w,
Uint16  h
[protected, virtual]
 

Callback for the SizeWidget event.

Parameters:
w new width
h new height This virtual function can be used to implement custom behavior for SizeWidget events.

Reimplemented from PG_Widget.

Reimplemented in PG_RichEdit, PG_ScrollBar, PG_ScrollWidget, and PG_Window.

Definition at line 328 of file pgthemewidget.cpp.

References PG_ThemeWidgetDataInternal::cachesurface, and DeleteThemedSurface().

Referenced by PG_Window::eventSizeWidget(), PG_ScrollWidget::eventSizeWidget(), and PG_ScrollBar::eventSizeWidget().

PG_Gradient PG_ThemeWidget::GetGradient  ) 
 

Get the background gradient.

Returns:
the background gradient

Definition at line 282 of file pgthemewidget.cpp.

References my_gradient.

Referenced by PG_ColorSelector::PG_ColorBox::GetBaseColor().

bool PG_ThemeWidget::LoadImage const std::string &  filename,
const PG_Color key
 

Display an image in the widget using a colorkey.

Parameters:
filename name of the image file to load
key the colorkey (0xRRGGBB)
Returns:
true on success With this function you can define an image with a colorkey to be displayed at the upper left corner of the widget. Image data will be erased when deleting the widget or loading / setting a new image.

Reimplemented in PG_Image.

Definition at line 314 of file pgthemewidget.cpp.

References LoadImage(), and my_image.

bool PG_ThemeWidget::LoadImage const std::string &  filename  ) 
 

Display an image in the widget.

Parameters:
filename name of the image file to load
Returns:
true on success With this function you can define an image to be displayed at the upper left corner of the widget. Image data will be erased when deleting the widget or loading / setting a new image.

Reimplemented in PG_Image.

Definition at line 323 of file pgthemewidget.cpp.

References PG_FileArchive::LoadSurface(), and SetImage().

Referenced by LoadImage(), and PG_Image::LoadImage().

void PG_ThemeWidget::LoadThemeStyle const std::string &  widgettype,
const std::string &  objectname
[virtual]
 

Load a style from the theme definition.

Parameters:
widgettype name of the widgettype
objectname name of the object
Loads the defined style of a given widgettype and objectname.

Reimplemented from PG_Widget.

Reimplemented in PG_LineEdit, and PG_PopupMenu.

Definition at line 103 of file pgthemewidget.cpp.

References PG_PropStr::background, PG_ThemeWidgetDataInternal::backgroundcolor, PG_PropStr::backgroundcolor, PG_PropStr::backmode, PG_PropStr::blend, PG_PropStr::bordersize, PG_Theme::FindFontName(), PG_Theme::FindFontSize(), PG_Theme::FindFontStyle(), PG_Theme::FindGradient(), PG_Theme::FindSurface(), PG_Theme::GetColor(), PG_Theme::GetProperty(), PG_Application::GetTheme(), PG_Widget::GetTransparency(), PG_PropStr::gradient, PG_PropStr::height, PG_Rect::Height(), PG_Widget::LoadThemeStyle(), LoadThemeStyle(), my_backgroundMode, my_blendLevel, PG_Widget::my_bordersize, PG_Widget::my_srfObject, PG_ThemeWidgetDataInternal::nocache, PG_PropStr::nocache, SetBackground(), PG_Widget::SetFontName(), PG_Widget::SetFontSize(), PG_Widget::SetFontStyle(), SetGradient(), SetTransparency(), PG_ThemeWidgetDataInternal::simplebackground, PG_PropStr::simplebackground, PG_Widget::SizeWidget(), PG_PropStr::ThemeWidget, PG_PropStr::transparency, PG_PropStr::width, and PG_Rect::Width().

void PG_ThemeWidget::LoadThemeStyle const std::string &  widgettype  ) 
 

Load a specific themestyle.

Parameters:
widgettype name of widget type to load

Reimplemented from PG_Widget.

Reimplemented in MessageDialog, PG_LineEdit, PG_MessageBox, PG_PopupMenu, PG_ProgressBar, PG_RadioButton, PG_ScrollBar, PG_ScrollWidget, PG_Slider, and PG_Window.

Definition at line 96 of file pgthemewidget.cpp.

References PG_PropStr::ThemeWidget.

Referenced by PG_Window::LoadThemeStyle(), LoadThemeStyle(), PG_Slider::LoadThemeStyle(), PG_ScrollWidget::LoadThemeStyle(), PG_ScrollBar::LoadThemeStyle(), PG_RadioButton::LoadThemeStyle(), PG_ProgressBar::LoadThemeStyle(), PG_PopupMenu::LoadThemeStyle(), PG_LineEdit::LoadThemeStyle(), and PG_ListBox::PG_ListBox().

bool PG_ThemeWidget::SetBackground SDL_Surface *  surface,
PG_Draw::BkMode  mode = PG_Draw::TILE
 

Define a surface as background image (will not be freed).

Parameters:
surface pointer to background surface
mode BKMODE_TILE | BKMODE_STRETCH | BKMODE_3TILEH | BKMODE_3TILEV | BKMODE_9TILE
Returns:
true on success

Definition at line 240 of file pgthemewidget.cpp.

References my_background, my_backgroundFree, my_backgroundMode, and PG_Widget::my_srfObject.

bool PG_ThemeWidget::SetBackground const std::string &  filename,
PG_Draw::BkMode  mode,
const PG_Color colorkey
 

Definition at line 179 of file pgthemewidget.cpp.

References PG_FileArchive::LoadSurface(), PG_Color::MapRGB(), my_background, my_backgroundFree, my_backgroundMode, and PG_Widget::my_srfObject.

bool PG_ThemeWidget::SetBackground const std::string &  filename,
PG_Draw::BkMode  mode = PG_Draw::TILE
 

Definition at line 210 of file pgthemewidget.cpp.

References PG_FileArchive::LoadSurface(), my_background, my_backgroundFree, my_backgroundMode, and PG_Widget::my_srfObject.

Referenced by LoadThemeStyle(), PG_ColorSelector::PG_ColorBox::PG_ColorBox(), PG_ColorSelector::PG_ColorSelector(), and StartupScreen::StartupScreen().

void PG_ThemeWidget::SetBackgroundBlend Uint8  backblend  ) 
 

Defines the "blend-level" of gradient & background.

Parameters:
backblend 0 - background image fully visible / 255 - gradient fully visible

Definition at line 259 of file pgthemewidget.cpp.

References my_blendLevel.

Referenced by ColoredBar::ColoredBar().

void PG_ThemeWidget::SetBackgroundColor const PG_Color c  ) 
 

Definition at line 501 of file pgthemewidget.cpp.

References PG_ThemeWidgetDataInternal::backgroundcolor.

Referenced by AllianceSetupWidget::AllianceSetupWidget(), EmailSetupWidget::EmailSetupWidget(), PlayerSetupWidget::PlayerSetupWidget(), PG_ColorSelector::SetBaseColor(), and StartupScreen::StartupScreen().

void PG_ThemeWidget::SetGradient const PG_Gradient grad  ) 
 

Set the background gradient.

Parameters:
grad a PG_Gradient structure describing the gradient

Definition at line 274 of file pgthemewidget.cpp.

References PG_ThemeWidgetDataInternal::cachesurface, DeleteThemedSurface(), my_gradient, my_has_gradient, and PG_Widget::Redraw().

Referenced by ColoredBar::ColoredBar(), LoadThemeStyle(), PG_ColorSelector::PG_ColorSelector(), PG_ColorSelector::SetBaseColor(), and PG_ColorSelector::SetColorGradient().

bool PG_ThemeWidget::SetImage SDL_Surface *  image,
bool  bFreeImage = true
 

Display an image in the widget.

Parameters:
image pointer to surface to display
bFreeImage true if the image should be freed by the widget (default = true)
Returns:
true on success With this function you can define an image to be displayed at the upper left corner of the widget.

Reimplemented in PG_Image.

Definition at line 297 of file pgthemewidget.cpp.

References PG_ThemeWidgetDataInternal::freeimage, my_image, and PG_Widget::Update().

Referenced by LoadImage(), and PG_Image::SetImage().

void PG_ThemeWidget::SetSimpleBackground bool  simple  ) 
 

Definition at line 494 of file pgthemewidget.cpp.

References PG_ThemeWidgetDataInternal::cachesurface, DeleteThemedSurface(), PG_Widget::Redraw(), and PG_ThemeWidgetDataInternal::simplebackground.

Referenced by AllianceSetupWidget::AllianceSetupWidget(), EmailSetupWidget::EmailSetupWidget(), PG_ColorSelector::PG_ColorBox::PG_ColorBox(), PG_ColorSelector::PG_ColorSelector(), PlayerSetupWidget::PlayerSetupWidget(), and StartupScreen::StartupScreen().

void PG_ThemeWidget::SetTransparency Uint8  t,
bool  bRecursive = false
[virtual]
 

Set the fransparency of the widget.

Parameters:
t transparency value (0 - opaque / 255 - fully transparent)
bRecursive if child widget's transparency should be set the same as widget

Reimplemented from PG_Widget.

Definition at line 399 of file pgthemewidget.cpp.

References PG_ThemeWidgetDataInternal::cachesurface, DeleteThemedSurface(), PG_Widget::GetTransparency(), PG_ThemeWidgetDataInternal::nocache, PG_Widget::SetTransparency(), and PG_ThemeWidgetDataInternal::simplebackground.

Referenced by AdminGameWindow::AdminGameWindow(), AllianceSetupWidget::AllianceSetupWidget(), AmmoTransferWindow::AmmoTransferWindow(), ASC_PG_Dialog::ASC_PG_Dialog(), CargoWidget::CargoWidget(), EmailSetupWidget::EmailSetupWidget(), EventList::EventList(), PG_RadioButton::eventMouseEnter(), PG_RadioButton::eventMouseLeave(), IngameMessageViewer::IngameMessageViewer(), InternalAmmoTransferWindow::InternalAmmoTransferWindow(), ItemSelectorWindow::ItemSelectorWindow(), LoadThemeStyle(), NewGuiHost::NewGuiHost(), NonEditableLineEdit::NonEditableLineEdit(), PG_RadioButton::PG_RadioButton(), PlayerSetupWidget::PlayerSetupWidget(), ItemSelectorWidget::reLoad(), TextRenderer::TextRenderer(), and VehicleProduction_SelectionWindow::VehicleProduction_SelectionWindow().


Member Data Documentation

SDL_Surface* PG_ThemeWidget::my_background [protected]
 

Definition at line 243 of file pgthemewidget.h.

Referenced by eventBlit(), PG_Image::eventBlit(), eventDraw(), and SetBackground().

bool PG_ThemeWidget::my_backgroundFree [protected]
 

Definition at line 249 of file pgthemewidget.h.

Referenced by SetBackground().

PG_Draw::BkMode PG_ThemeWidget::my_backgroundMode [protected]
 

Definition at line 251 of file pgthemewidget.h.

Referenced by eventBlit(), eventDraw(), LoadThemeStyle(), and SetBackground().

Uint8 PG_ThemeWidget::my_blendLevel [protected]
 

Definition at line 247 of file pgthemewidget.h.

Referenced by eventBlit(), PG_Image::eventBlit(), eventDraw(), LoadThemeStyle(), and SetBackgroundBlend().

PG_Gradient PG_ThemeWidget::my_gradient [protected]
 

Definition at line 241 of file pgthemewidget.h.

Referenced by eventBlit(), eventDraw(), GetGradient(), and SetGradient().

bool PG_ThemeWidget::my_has_gradient [protected]
 

Definition at line 239 of file pgthemewidget.h.

Referenced by eventBlit(), eventDraw(), and SetGradient().

SDL_Surface* PG_ThemeWidget::my_image [protected]
 

Definition at line 245 of file pgthemewidget.h.

Referenced by eventBlit(), PG_Image::eventBlit(), LoadImage(), PG_Image::PG_Image(), PG_Image::SetColorKey(), and SetImage().


The documentation for this class was generated from the following files:
Generated on Tue Jun 24 02:19:38 2008 for Advanced Strategic Command by  doxygen 1.4.2