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

PG_Button Class Reference

Inheritance diagram for PG_Button:

Inheritance graph
[legend]
Collaboration diagram for PG_Button:

Collaboration graph
[legend]
List of all members.

Detailed Description

Button that uses themes.

Author:
Alexander Pipelka

pgbutton.png

button screenshot

Several predefined button IDs exist. All of them are associated with default icons used automatically when the given ID is assigned to a button:

button_ok_icon.png

PG_Button::OK

button_yes_icon.png

PG_Button::YES

button_no_icon.png

PG_Button::NO

button_apply_icon.png

PG_Button::APPLY

button_cancel_icon.png

PG_Button::CANCEL

button_close_icon.png

PG_Button::CLOSE

button_help_icon.png

PG_Button::HELP

Theme support

widget type: Button (default)
object name: Button

Parent theme:

PG_Widget theme

Theme sample:

<widget> <type value="Button"/> <object> <name value="Button"/> <filename name="background0" value="default/button_unpressed.png"/> <filename name="background1" value="default/button_pressed.png"/> <filename name="background2" value="default/button_highlighted.png"/> <color name="textcolor" value="0x00ff9807"/> <property name="backmode0" value="TILE"/> <property name="backmode1" value="TILE"/> <property name="backmode2" value="TILE"/> <gradient name="gradient0" color0="0x000000FF" color1="0x000000FF" color2="0x000000FF" color3="0x000000FF"/> <gradient name="gradient1" color0="0x000000FF" color1="0x000000FF" color2="0x000000FF" color3="0x000000FF"/> <gradient name="gradient2" color0="0x000000FF" color1="0x000000FF" color2="0x000000FF" color3="0x000000FF"/> <property name="blend0" value="0"/> <property name="blend1" value="0"/> <property name="blend2" value="0"/> <property name="bordersize0" value="0"/> <property name="bordersize1" value="0"/> <property name="bordersize2" value="0"/> <property name="transparency0" value="0"/> <property name="transparency1" value="0"/> <property name="transparency2" value="0"/> <filename name="iconup" value="none"/> <filename name="icondown" value="none"/> </object> </widget>

Code:

Examples:

dblbuffer.cpp, and paratest.cpp.


Public Types

enum  {
  OK = 0x80000001, YES = 0x80000002, NO = 0x80000003, APPLY = 0x80000004,
  CANCEL = 0x80000005, CLOSE = 0x80000006, HELP = 0x80000007
}
 Standard button IDs. More...

enum  STATE { PRESSED, UNPRESSED, HIGHLITED }
 Button states. More...


Public Member Functions

 PG_Button (PG_Widget *parent, const PG_Rect &r=PG_Rect::null, const char *text=NULL, int id=-1, const char *style="Button")
 Constructor for the PG_Button class.

virtual ~PG_Button ()
void LoadThemeStyle (const char *widgettype)
 Load a style from the theme definition.

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

void SetGradient (STATE state, const PG_Gradient &gradient)
 Set the gradient.

void SetBackground (STATE state, SDL_Surface *background, int mode=BKMODE_TILE)
 Set the background.

void SetBorderColor (int b, const PG_Color &color)
 Set the color of the border.

bool SetIcon (const char *filenameup=NULL, const char *filenamedown=NULL, const char *filenameover=NULL)
 Set icons for the button.

bool SetIcon (const char *filenameup, const char *filenamedown, const char *filenameover, const PG_Color &colorkey)
 Set icons for the button.

bool SetIcon (SDL_Surface *icon_up, SDL_Surface *icon_down=NULL, SDL_Surface *icon_over=NULL)
 Set icons for the buttons.

SDL_Surface * GetIcon (STATE num)
 Returns an image for a given button state.

void SetIconIndent (Uint16 indent)
 Set the distance between the left border of the button and the icon.

void SetBorderSize (int norm, int pressed, int high)
 Set the bordersize of the button.

void SetToggle (bool bToggle)
 Make the button a toggle button.

void SetPressed (bool pressed)
 If the button is a toggle button you can modify the status of the button with this function.

void SetTransparency (Uint8 t, bool bRecursive=false)
 Set the transparency of the button.

void SetTransparency (Uint8 norm, Uint8 pressed, Uint8 high)
 Set the transparency for the single button states.

void SetShift (int pixelshift)
 Set the moving distance of the image when we press on it.

bool GetPressed ()
 Determine whether a given button is pressed.

void SetBlendLevel (STATE mode, Uint8 blend)
 Set the blend-level of gradient and background image.

Uint8 GetBlendLevel (STATE mode)
 Get the current blend level.

void SetSizeByText (int Width=0, int Height=0, const char *Text=NULL)
 Resizes the button so that a specified text fits on it.


Public Attributes

SignalButtonClick sigClick

Protected Member Functions

virtual void eventButtonSurface (SDL_Surface **surface, STATE newstate, Uint16 w, Uint16 h)
void eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
 overridable eventhandler to blit the widget contents to the screen

void eventSizeWidget (Uint16 w, Uint16 h)
 Callback for the SizeWidget event.

void eventMouseLeave ()
 eventhandler for mouse movements.

void eventMouseEnter ()
 eventhandler for mouse movements.

bool eventMouseButtonUp (const SDL_MouseButtonEvent *button)
 Overridable Eventhandler for a SDL_MouseButtonEvent message.

bool eventMouseButtonDown (const SDL_MouseButtonEvent *button)
 Overridable Eventhandler for a SDL_MouseButtonEvent message.


Member Enumeration Documentation

anonymous enum
 

Standard button IDs.

Enumeration values:
OK 
YES 
NO 
APPLY 
CANCEL 
CLOSE 
HELP 

enum PG_Button::STATE
 

Button states.

Enumeration values:
PRESSED 
UNPRESSED 
HIGHLITED 


Constructor & Destructor Documentation

PG_Button::PG_Button PG_Widget parent,
const PG_Rect r = PG_Rect::null,
const char *  text = NULL,
int  id = -1,
const char *  style = "Button"
 

Constructor for the PG_Button class.

Parameters:
parent pointer to the parent widget or NULL
r screen position of the button
id id of the button (can be used in callbacks)
text button label
style themestyle of the button

virtual PG_Button::~PG_Button  )  [virtual]
 


Member Function Documentation

void PG_Button::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.

virtual void PG_Button::eventButtonSurface SDL_Surface **  surface,
STATE  newstate,
Uint16  w,
Uint16  h
[protected, virtual]
 

bool PG_Button::eventMouseButtonDown const SDL_MouseButtonEvent *  button  )  [protected, virtual]
 

Overridable Eventhandler for a SDL_MouseButtonEvent message.

This handler is called when a mouse button is pressed. The default implementation returns 'false' which indicates that this message is not processed by this object.

Parameters:
button SDL_MouseButtonEvent message
Returns:
Notifies the message pump if this message is processed by this object or it should be routed to the next message receiver.

Reimplemented from PG_MessageObject.

bool PG_Button::eventMouseButtonUp const SDL_MouseButtonEvent *  button  )  [protected, virtual]
 

Overridable Eventhandler for a SDL_MouseButtonEvent message.

This handler is called when a mouse button is released. The default implementation returns 'false' which indicates that this message is not processed by this object.

Parameters:
button SDL_MouseButtonEvent message
Returns:
Notifies the message pump if this message is processed by this object or it should be routed to the next message receiver.

Reimplemented from PG_MessageObject.

void PG_Button::eventMouseEnter  )  [protected, virtual]
 

eventhandler for mouse movements.

This overrideable handler is called everytime the mouse cursor is entering the widget area.

Reimplemented from PG_Widget.

void PG_Button::eventMouseLeave  )  [protected, virtual]
 

eventhandler for mouse movements.

This overrideable handler is called everytime the mouse cursor is leaving the widget area.

Reimplemented from PG_Widget.

void PG_Button::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.

Uint8 PG_Button::GetBlendLevel STATE  mode  ) 
 

Get the current blend level.

Parameters:
mode button mode
Returns:
the current blend level

SDL_Surface* PG_Button::GetIcon STATE  num  ) 
 

Returns an image for a given button state.

Parameters:
num (NORM = icon for unpressed state | PRESSED = icon for pressed state | HIGH = icon for highlighted state)
Returns:
a pointer to an SDL_Surface for the given icon

bool PG_Button::GetPressed  ) 
 

Determine whether a given button is pressed.

This can either mean that the user is clicking the button in the case of a push button, or that the button is toggled in the case of a toggle button.

Returns:
bool is the button pressed
Examples:
paratest.cpp.

void PG_Button::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.

void PG_Button::LoadThemeStyle const char *  widgettype  ) 
 

Load a style from the theme definition.

Parameters:
widgettype name of the widgettype
Loads the defined style for a given widgettype

Reimplemented from PG_Widget.

void PG_Button::SetBackground STATE  state,
SDL_Surface *  background,
int  mode = BKMODE_TILE
 

Set the background.

Parameters:
state buttonstate to set
background pointer to background surface
mode background tiling mode
This member function set's the buttons background and tiling mode for a specific state.

void PG_Button::SetBlendLevel STATE  mode,
Uint8  blend
 

Set the blend-level of gradient and background image.

Parameters:
blend blend-level
mode one of BTN_STATE_NORMAL, BTN_STATE_PRESSED, BTN_STATE_HIGH This function sets the blend level of gradient and background image.
If the blend-level is 0 only the background image is visible. At a level of 255 only the gradient is visible.

void PG_Button::SetBorderColor int  b,
const PG_Color color
 

Set the color of the border.

Parameters:
b borderindex 0 = upper-left / 1 = lower-right
color border color (e.g. 0xRRGGBB)

void PG_Button::SetBorderSize int  norm,
int  pressed,
int  high
 

Set the bordersize of the button.

Parameters:
norm bordersize for unpressed state
pressed bordersize for pressed state
high bordersize for highlighted state
Returns:
a pointer to an SDL_Surface for the given icon
If you don't want to set the bordersize for one of the states, set it to -1.

void PG_Button::SetGradient STATE  state,
const PG_Gradient gradient
 

Set the gradient.

Parameters:
state buttonstate to set
gradient gradient to set
This member function set's the buttons gradient for a specific state.

bool PG_Button::SetIcon SDL_Surface *  icon_up,
SDL_Surface *  icon_down = NULL,
SDL_Surface *  icon_over = NULL
 

Set icons for the buttons.

Parameters:
icon_up the icon surface for the unpressed state
icon_down the icon for the pressed state
icon_over the icon for the highlited state
Returns:
true on success
Note:
The user has to care for freeing the surfaces after the button is deleted!

bool PG_Button::SetIcon const char *  filenameup,
const char *  filenamedown,
const char *  filenameover,
const PG_Color colorkey
 

Set icons for the button.

Parameters:
filenameup icon for unpressed state
filenamedown icon for pressed state
filenameover icon for highlited state
colorkey the colorkey assigned to the icons
Returns:
true on success

bool PG_Button::SetIcon const char *  filenameup = NULL,
const char *  filenamedown = NULL,
const char *  filenameover = NULL
 

Set icons for the button.

Parameters:
filenameup icon for unpressed state
filenamedown icon for pressed state
filenameover icon for highlited state
Returns:
true on success

void PG_Button::SetIconIndent Uint16  indent  ) 
 

Set the distance between the left border of the button and the icon.

Parameters:
indent spacing between widget border and icon

void PG_Button::SetPressed bool  pressed  ) 
 

If the button is a toggle button you can modify the status of the button with this function.

void PG_Button::SetShift int  pixelshift  ) 
 

Set the moving distance of the image when we press on it.

Parameters:
pixelshift int number of pixels to shift

void PG_Button::SetSizeByText int  Width = 0,
int  Height = 0,
const char *  Text = NULL
 

Resizes the button so that a specified text fits on it.

Parameters:
Width additional width apart from the width required by the text
Height additional height apart from the one required by the text
text the text which is to fit on the button

Reimplemented from PG_Widget.

void PG_Button::SetToggle bool  bToggle  ) 
 

Make the button a toggle button.

A normal (push) button will return to an unpressed state when the user stops clicking it (releases the mouse button). A toggle button will stay pressed once it is pressed. The user must click the button a second time in order to unpress it.

Examples:
paratest.cpp.

void PG_Button::SetTransparency Uint8  norm,
Uint8  pressed,
Uint8  high
 

Set the transparency for the single button states.

Parameters:
norm the transparency of the normal (unpressed) state
pressed the transparency of the pressed state
high the transparency of the highlited state

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

Set the transparency of the button.

Parameters:
t the transparency you want to assign
bRecursive if set to true, apply the transparency to all child widgets

Reimplemented from PG_Widget.


Member Data Documentation

SignalButtonClick PG_Button::sigClick
 

Examples:
dblbuffer.cpp, and paratest.cpp.


The ParaGUI Project - Alexander Pipelka