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

ActionButton.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: ActionButton.cpp,v 1.5 2002/03/12 10:46:06 tksuoran Exp $
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     //dmsg( M_INIT, "Registering void type %d to %s", type, name.c_str() );
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     //dmsg( M_INIT, "Registering event type %d to %s", type, name.c_str() );
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     //dmsg( M_INIT, "Registering data type %d to %s", type, name.c_str() );
00095 }
00096 
00097 
00098 /*virtual*/ 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 /*virtual*/ 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 };  //  namespace PhysicalComponents
00144 };  //  namespace Teddy
00145