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

PG_ThemeWidget Class Reference

Inheritance diagram for PG_ThemeWidget:

Inheritance graph
[legend]
Collaboration diagram for PG_ThemeWidget:

Collaboration graph
[legend]
List of all members.

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:

Examples:

paratest.cpp.


Public Member Functions

 PG_ThemeWidget (PG_Widget *parent, const PG_Rect &r=PG_Rect::null, const char *style="ThemeWidget")
 Create a new PG_ThemeWidget object.

 PG_ThemeWidget (PG_Widget *parent, const PG_Rect &r, bool bCreateSurface, const char *style="ThemeWidget")
 Create a new PG_ThemeWidget object.

 ~PG_ThemeWidget ()
void LoadThemeStyle (const char *widgettype)
 Load a specific themestyle.

void LoadThemeStyle (const char *widgettype, const char *objectname)
 Load a style from the theme definition.

bool SetBackground (const char *filename, int mode=BKMODE_TILE)
bool SetBackground (const char *filename, int mode, const PG_Color &colorkey)
bool SetBackground (SDL_Surface *surface, int mode=BKMODE_TILE)
 Define a surface as background image (will not be freed).

void SetBackgroundBlend (Uint8 backblend)
 Defines the "blend-level" of gradient & background.

void SetGradient (PG_Gradient &grad)
 Set the background gradient.

PG_Gradient GetGradient ()
 Get the background gradient.

void SetBorderSize (int b)
 Set the bordersize of the widget.

int GetBorderSize ()
 Get the bordersize of the widget.

bool LoadImage (const char *filename)
 Display an image in the widget.

bool LoadImage (const char *filename, Uint32 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

SDL_Surface * CreateThemedSurface (const PG_Rect &r, PG_Gradient *gradient, SDL_Surface *background, int bkmode, Uint8 blend)
 Create a 'themed' surface.

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
int my_backgroundMode
int my_bordersize


Constructor & Destructor Documentation

PG_ThemeWidget::PG_ThemeWidget PG_Widget parent,
const PG_Rect r = PG_Rect::null,
const char *  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.

PG_ThemeWidget::PG_ThemeWidget PG_Widget parent,
const PG_Rect r,
bool  bCreateSurface,
const char *  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.

PG_ThemeWidget::~PG_ThemeWidget  ) 
 


Member Function Documentation

SDL_Surface* PG_ThemeWidget::CreateThemedSurface const PG_Rect r,
PG_Gradient gradient,
SDL_Surface *  background,
int  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)
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.

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

Delete a themed surface.

Parameters:
surface pointer to surface

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 PG_Image, PG_LineEdit, PG_PopupMenu, PG_ProgressBar, PG_RichEdit, and PG_Window.

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.

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_ScrollBar, PG_ScrollWidget, and PG_Window.

int PG_ThemeWidget::GetBorderSize  ) 
 

Get the bordersize of the widget.

Returns:
bordersize in pixels

PG_Gradient PG_ThemeWidget::GetGradient  ) 
 

Get the background gradient.

Returns:
the background gradient

bool PG_ThemeWidget::LoadImage const char *  filename,
Uint32  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.

bool PG_ThemeWidget::LoadImage const char *  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.

void PG_ThemeWidget::LoadThemeStyle const char *  widgettype,
const char *  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.

void PG_ThemeWidget::LoadThemeStyle const char *  widgettype  ) 
 

Load a specific themestyle.

Parameters:
widgettype name of widget type to load

Reimplemented from PG_Widget.

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

bool PG_ThemeWidget::SetBackground SDL_Surface *  surface,
int  mode = BKMODE_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

bool PG_ThemeWidget::SetBackground const char *  filename,
int  mode,
const PG_Color colorkey
 

bool PG_ThemeWidget::SetBackground const char *  filename,
int  mode = BKMODE_TILE
 

void PG_ThemeWidget::SetBackgroundBlend Uint8  backblend  ) 
 

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

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

void PG_ThemeWidget::SetBackgroundColor const PG_Color c  ) 
 

void PG_ThemeWidget::SetBorderSize int  b  ) 
 

Set the bordersize of the widget.

Parameters:
b bordersize in pixels (currently 0,1,2)

void PG_ThemeWidget::SetGradient PG_Gradient grad  ) 
 

Set the background gradient.

Parameters:
grad a PG_Gradient structure describing the gradient

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.

void PG_ThemeWidget::SetSimpleBackground bool  simple  ) 
 

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)

Reimplemented from PG_Widget.

Examples:
paratest.cpp.


Member Data Documentation

SDL_Surface* PG_ThemeWidget::my_background [protected]
 

bool PG_ThemeWidget::my_backgroundFree [protected]
 

int PG_ThemeWidget::my_backgroundMode [protected]
 

Uint8 PG_ThemeWidget::my_blendLevel [protected]
 

int PG_ThemeWidget::my_bordersize [protected]
 

PG_Gradient PG_ThemeWidget::my_gradient [protected]
 

bool PG_ThemeWidget::my_has_gradient [protected]
 

SDL_Surface* PG_ThemeWidget::my_image [protected]
 



The ParaGUI Project - Alexander Pipelka