00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #include "Teddy/PhysicalComponents/ActionButton.h"
00026 #include "Teddy/PhysicalComponents/Style.h"
00027 #include "Teddy/PhysicalComponents/WindowManager.h"
00028 #include "Teddy/Graphics/Font.h"
00029 #include "Teddy/Graphics/View.h"
00030 #include "Teddy/SysSupport/Messages.h"
00031 #include <cstring>
00032 using namespace Teddy::Graphics;
00033 using namespace Teddy::SysSupport;
00034 
00035 
00036 namespace Teddy              {
00037 namespace PhysicalComponents {
00038 
00039 
00041 ActionButton::ActionButton( std::string name, Teddy::Signals::Functor0<bool> *f, const int type )
00042 :
00043 EventListener(),
00044 Area         (name),
00045 label        (name)
00046 {
00047     fill_base_pixels[0]    = 4 + name.size() * style->button_font->getWidth() + style->border[0] * 2; 
00048     fill_base_pixels[1]    = 4 + style->button_font->getHeight() + style->border[1] * 2;
00049     drawing_ordering       = pre_self;
00050     event_ordering         = post_self;
00051     this->v_type           = type;
00052     this->e_type           = 0;
00053     this->d_type           = 0;
00054     this->v_holder.functor = f;
00055     this->d_data           = NULL;
00056     
00057 }
00058 
00059 
00060 ActionButton::ActionButton( std::string name, Teddy::Signals::Functor1<bool,const Event &> *f, const int type )
00061 :
00062 EventListener(),
00063 Area (name),
00064 label(name)
00065 {
00066     fill_base_pixels[0]    = 4 + name.size() * style->button_font->getWidth() + style->border[0] * 2; 
00067     fill_base_pixels[1]    = 4 + style->button_font->getHeight() + style->border[1] * 2;
00068     drawing_ordering       = pre_self;
00069     event_ordering         = post_self;
00070     this->v_type           = 0;
00071     this->e_type           = type;
00072     this->d_type           = 0;
00073     this->e_holder.functor = f;
00074     this->d_data           = NULL;
00075     
00076 }
00077 
00078 
00079 ActionButton::ActionButton( std::string name, Teddy::Signals::Functor1<bool,void *> *f, void *data, const int type )
00080 :
00081 EventListener(),
00082 Area (name),
00083 label(name)
00084 {
00085     fill_base_pixels[0]    = 4 + name.size() * style->button_font->getWidth() + style->border[0] * 2; 
00086     fill_base_pixels[1]    = 4 + style->button_font->getHeight() + style->border[1] * 2;
00087     drawing_ordering       = pre_self;
00088     event_ordering         = post_self;
00089     this->v_type           = 0;
00090     this->e_type           = 0;
00091     this->d_type           = type;
00092     this->d_holder.functor = f;
00093     this->d_data           = data;
00094     
00095 }
00096 
00097 
00098  void ActionButton::event( const Event &e ){
00099     if( v_type == e.type ){
00100         v_holder();
00101     }
00102     if( e_type == e.type ){
00103         e_holder( e );
00104     }
00105     if( d_type == e.type ){
00106         d_holder( d_data );
00107     }
00108 }
00109 
00110  bool ActionButton::doesEvent( int type ){
00111     return
00112         ( v_type == type ) ||
00113         ( e_type == type ) ||
00114         ( d_type == type );
00115 }
00116 
00117 
00119 ActionButton::~ActionButton(){
00120 }
00121 
00122 
00124 void ActionButton::drawSelf(){
00125     view->disable( View::TEXTURE_2D );
00126 
00127 #   if !defined( USE_TINY_GL )
00128     Color( 0.80f,0.80f,0.80f,1.0f ).glApply();
00129     drawFillRect( 2, 2, size[0]-2, size[1]-2 );
00130     drawBiColRect( 1,  1, size[0]-1, size[1]-1, style->hilight_color, style->shadow_color );
00131     drawBiColRect( 0,  0, size[0]  , size[1]  , style->shadow_color,  style->shadow_color );
00132 #   endif
00133 
00134     view->setPolygonMode( GL_FILL );
00135     view->enable( View::BLEND );
00136     view->enable( View::TEXTURE_2D );
00137     view->setBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00138     style->text_color.glApply();
00139     drawString( style->border + Vector2(2.0f,2.0f), label.c_str(), style->button_font );
00140 }
00141 
00142 
00143 };  
00144 };  
00145