/*************************************************************************** * Copyright (C) 2004 by Christoph Freundl * * Christoph.Freundl@informatik.uni-erlangen.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef SDLWIDGETS_BUTTON_H #define SDLWIDGETS_BUTTON_H #include "widget.h" #include "action.h" #include "textlabel.h" #include "backgroundwidget.h" #include "borderwidget.h" namespace SDLwidgets { class Button : public WidgetLeaf, public ActionWidget { public: enum Action { BUTTON_PRESSED }; public: virtual ~Button() { } virtual bool handleEvent( SDL_Event* event ); }; class TextButton : public Button { private: TextLabel _label; BackgroundWidget* _background; BorderWidget* _border; // highlight background bool _is_highlightable; SDL_Color _highlight_color; Uint8 _highlight_alpha; static SDL_Color _default_color; static SDL_Color _default_highlight_color; static Uint8 _default_highlight_alpha; public: TextButton( std::string text ); virtual ~TextButton(); virtual bool handleEvent( SDL_Event* event ); virtual void draw( SDL_Surface* surface ); virtual int getWidth() const { return _border->getWidth(); } virtual void setWidth( const Uint16 width ) { _border->setWidth( width ); _background->setWidth( width - 2 ); _width = width; } virtual void setMinWidth( const Uint16 width ) { _border->setMinWidth( width ); _background->setMinWidth( width - 2 ); _width = width; } virtual int getHeight() const { return _border->getHeight(); } virtual void setHeight( const Uint16 height ) { _border->setHeight( height ); _background->setHeight( height - 2 ); _height = height; } virtual void setMinHeight( const Uint16 height ) { _border->setMinHeight( height ); _background->setMinHeight( height - 2 ); _height = height; } virtual void setColor( const SDL_Color& color ) { _border->setColor( color ); _label.setColor( color ); } void setHighlightable( bool flag ) { _is_highlightable = flag; } void setHighlightColor( const SDL_Color& color ) { _highlight_color = color; } void setHighlightAlpha( const Uint8 alpha ) { _highlight_alpha = alpha; } static void setDefaultColor( SDL_Color color ) { _default_color = color; } static void setDefaultHighlightColor( SDL_Color color ) { _default_highlight_color = color; } static void setDefaultHighlightAlpha( Uint8 alpha ) { _default_highlight_alpha = alpha; } }; }; #endif // SDLWIDGETS_BUTTON_H