/*************************************************************************** * 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. * ***************************************************************************/ #include "button.h" namespace SDLwidgets { /////////// // Button /////////// bool Button::handleEvent( SDL_Event* event ) { if ( event->type == SDL_MOUSEBUTTONDOWN ) { if ( event->button.button == SDL_BUTTON_LEFT ) { if ( containsPoint( event->button.x, event->button.y ) ) { fireAction( BUTTON_PRESSED, this ); return true; } } } return false; } /////////////// // TextButton /////////////// SDL_Color TextButton::_default_color; SDL_Color TextButton::_default_highlight_color; Uint8 TextButton::_default_highlight_alpha; TextButton::TextButton( std::string text ) : _label( text ) { _background = new BackgroundWidget( &_label ); _border = new BorderWidget( _background ); _min_width = _border->getMinWidth(); _min_height = _border->getMinHeight(); _border->setPosition( 0, 0 ); _border->setParent( this ); _is_highlightable = false; _label.setColor( _default_color ); _border->setColor( _default_color ); _highlight_color = _default_highlight_color; _highlight_alpha = _default_highlight_alpha; } TextButton::~TextButton() { delete _border; _border = 0; delete _background; _background = 0; } bool TextButton::handleEvent( SDL_Event* event ) { if ( Button::handleEvent( event ) ) return true; if ( event->type == SDL_MOUSEMOTION ) { if ( containsPoint( event->motion.x, event->motion.y ) ) { if ( _is_highlightable ) { _background->setColor( _highlight_color ); _background->setAlpha( _highlight_alpha ); } } else { if ( _is_highlightable ) { _background->setColor( _color ); _background->setAlpha( SDL_ALPHA_TRANSPARENT ); } } } return false; } void TextButton::draw( SDL_Surface* surface ) { _border->draw( surface ); } };