/*************************************************************************** * 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 "borderwidget.h" #include "graphics.h" namespace SDLwidgets { BorderWidget::BorderWidget( Widget* widget ) : WidgetDecorator( widget ) { // new relative position for contained widget widget->setPosition( 1, 1 ); _min_width = widget->getMinWidth() + 2; _width = widget->getWidth() + 2; _min_height = widget->getMinHeight() + 2; _height = widget->getHeight() + 2; // default color for a border is white _color.r = 255; _color.g = 255; _color.b = 255; } void BorderWidget::draw( SDL_Surface* surface ) { _widget->draw( surface ); Sint16 offset_x, offset_y; getOffset( offset_x, offset_y ); Graphics::drawLine( surface, offset_x, offset_y, offset_x, offset_y + _height - 1, &_color ); Graphics::drawLine( surface, offset_x, offset_y, offset_x + _width - 1, offset_y, &_color ); Graphics::drawLine( surface, offset_x + _width - 1, offset_y, offset_x + _width - 1, offset_y + _height - 1, &_color ); Graphics::drawLine( surface, offset_x, offset_y + _height - 1, offset_x + _width - 1, offset_y + _height - 1, &_color ); } void BorderWidget::setWidth( const Uint16 width ) { _width = width; // _widget->setWidth( _width - 2 ); _widget->setPosition( ( _width - _widget->getWidth() ) / 2, ( _height - _widget->getHeight() ) / 2 ); } void BorderWidget::setMinWidth( const Uint16 min_width ) { _min_width = min_width; // _widget->setMinWidth( _min_width - 2 ); setWidth( _min_width ); } void BorderWidget::setHeight( const Uint16 height ) { _height = height; _widget->setHeight( _height - 2 ); _widget->setPosition( ( _width - _widget->getWidth() ) / 2, ( _height - _widget->getHeight() ) / 2 ); } void BorderWidget::doLayout() { _width = _widget->getWidth() + 2; _height = _widget->getHeight() + 2; Widget::doLayout(); } void BorderWidget::layoutContent() { _widget->setPosition( ( _width - _widget->getWidth() ) / 2, ( _height - _widget->getHeight() ) / 2 ); } Border3DWidget::Border3DWidget( Widget* widget ) : WidgetDecorator( widget ) { // new relative position for contained widget widget->setPosition( 2, 2 ); _width = widget->getWidth() + 4; _min_width = widget->getMinWidth() + 4; _height = widget->getHeight() + 4; _min_height = widget->getMinHeight() + 4; // default color for a border is white _color.r = 255; _color.g = 255; _color.b = 255; _shaded_color.r = _color.r / 2; _shaded_color.g = _color.g / 2; _shaded_color.b = _color.b / 2; } void Border3DWidget::draw( SDL_Surface* surface ) { _widget->draw( surface ); Sint16 offset_x, offset_y; getOffset( offset_x, offset_y ); Graphics::drawLine( surface, offset_x, offset_y, offset_x, offset_y + _height - 1, &_color ); Graphics::drawLine( surface, offset_x+1, offset_y+1, offset_x+1, offset_y + _height - 2, &_color ); Graphics::drawLine( surface, offset_x, offset_y, offset_x + _width - 1, offset_y, &_color ); Graphics::drawLine( surface, offset_x+1, offset_y+1, offset_x + _width - 2, offset_y+1, &_color ); Graphics::drawLine( surface, offset_x + _width - 1, offset_y, offset_x + _width - 1, offset_y + _height - 1, &_shaded_color ); Graphics::drawLine( surface, offset_x + _width - 2, offset_y+1, offset_x + _width - 2, offset_y + _height - 2, &_shaded_color ); Graphics::drawLine( surface, offset_x, offset_y + _height - 1, offset_x + _width - 1, offset_y + _height - 1, &_shaded_color ); Graphics::drawLine( surface, offset_x+1, offset_y + _height - 2, offset_x + _width - 2, offset_y + _height - 2, &_shaded_color ); } void Border3DWidget::setWidth( const Uint16 width ) { _width = width; _widget->setWidth( _width - 4 ); _widget->setPosition( ( _width - _widget->getWidth() ) / 2, ( _height - _widget->getHeight() ) / 2 ); } void Border3DWidget::setMinWidth( const Uint16 min_width ) { _min_width = min_width; _widget->setMinWidth( _min_width - 4 ); } void Border3DWidget::setHeight( const Uint16 height ) { _height = height; _widget->setHeight( _height - 4 ); _widget->setPosition( ( _width - _widget->getWidth() ) / 2, ( _height - _widget->getHeight() ) / 2 ); } void Border3DWidget::doLayout() { _width = _widget->getWidth() + 4; _height = _widget->getHeight() + 4; Widget::doLayout(); } }