Button Class Reference

#include <button.h>

Inheritance diagram for Button:

Inheritance graph
[legend]
Collaboration diagram for Button:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Button (const Rectanglei &rect, const Profile *res_profile, const std::string &resource_id, bool img_scale=true)
 Button (const Point2i &position, const Profile *res_profile, const std::string &resource_id, bool img_scale=false)
virtual ~Button ()
virtual void Draw (const Point2i &mousePosition, Surface &surf) const
virtual void SetSizePosition (const Rectanglei &rect)
SpriteGetSprite ()

Protected Attributes

bool img_scale
Spriteimage

Detailed Description

Definition at line 30 of file button.h.


Constructor & Destructor Documentation

Button::Button ( const Rectanglei rect,
const Profile res_profile,
const std::string &  resource_id,
bool  img_scale = true 
)

Definition at line 27 of file button.cpp.

00028                                                                : Widget(rect)
00029 {
00030   image = resource_manager.LoadSprite(res_profile,resource_id);
00031   image->cache.EnableLastFrameCache();
00032 
00033   // image scalling or not
00034   img_scale = _img_scale;
00035   
00036   if (img_scale)
00037     image->ScaleSize(rect.GetSize());
00038 }

Here is the call graph for this function:

Button::Button ( const Point2i position,
const Profile res_profile,
const std::string &  resource_id,
bool  img_scale = false 
)

Definition at line 40 of file button.cpp.

00042 {
00043   image = resource_manager.LoadSprite(res_profile, resource_id);
00044   position = m_position;
00045   size = image->GetSize();
00046 
00047   // image scalling on resize
00048   img_scale = _img_scale;
00049 }

Here is the call graph for this function:

Button::~Button (  )  [virtual]

Definition at line 51 of file button.cpp.

00052 {
00053   delete image;
00054 }


Member Function Documentation

void Button::Draw ( const Point2i mousePosition,
Surface surf 
) const [virtual]

Implements Widget.

Reimplemented in ButtonText.

Definition at line 56 of file button.cpp.

00057 {
00058   uint frame = Contains(mousePosition)?1:0;
00059 
00060   image->SetCurrentFrame(frame);
00061 
00062   if (img_scale) {
00063     // image scalling : easy to place image
00064     image->Blit(surf, position);
00065   } else {
00066     // centering image
00067     Point2i pos = position;
00068 
00069     pos.x += (GetSizeX()/2) - (image->GetWidth()/2);
00070     pos.y += (GetSizeY()/2) - (image->GetHeight()/2);
00071 
00072     image->Blit(surf, pos);
00073   }
00074 }

Here is the call graph for this function:

Here is the caller graph for this function:

Sprite* Button::GetSprite (  )  [inline]

Definition at line 48 of file button.h.

00048 { return image; };

void Button::SetSizePosition ( const Rectanglei rect  )  [virtual]

Implements Widget.

Definition at line 76 of file button.cpp.

00077 {
00078   StdSetSizePosition(rect);
00079 
00080   if (img_scale)
00081     image->ScaleSize(size);
00082 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Sprite* Button::image [protected]

Definition at line 34 of file button.h.

bool Button::img_scale [protected]

Definition at line 33 of file button.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:37:56 2007 for Wormux by  doxygen 1.4.7