00001 /* $Id: vertical_scrollbar.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2008 - 2012 by Mark de Wever <koraq@xs4all.nl> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #define GETTEXT_DOMAIN "wesnoth-lib" 00017 00018 #include "gui/widgets/vertical_scrollbar.hpp" 00019 00020 #include "gui/auxiliary/widget_definition/vertical_scrollbar.hpp" 00021 #include "gui/auxiliary/window_builder/vertical_scrollbar.hpp" 00022 #include "gui/widgets/settings.hpp" 00023 00024 #include <boost/bind.hpp> 00025 00026 namespace gui2 { 00027 00028 REGISTER_WIDGET(vertical_scrollbar) 00029 00030 unsigned tvertical_scrollbar::minimum_positioner_length() const 00031 { 00032 boost::intrusive_ptr<const tvertical_scrollbar_definition::tresolution> conf = 00033 boost::dynamic_pointer_cast<const tvertical_scrollbar_definition::tresolution>(config()); 00034 assert(conf); 00035 return conf->minimum_positioner_length; 00036 } 00037 00038 unsigned tvertical_scrollbar::maximum_positioner_length() const 00039 { 00040 boost::intrusive_ptr<const tvertical_scrollbar_definition::tresolution> conf = 00041 boost::dynamic_pointer_cast<const tvertical_scrollbar_definition::tresolution>(config()); 00042 assert(conf); 00043 return conf->maximum_positioner_length; 00044 } 00045 00046 unsigned tvertical_scrollbar::offset_before() const 00047 { 00048 boost::intrusive_ptr<const tvertical_scrollbar_definition::tresolution> conf = 00049 boost::dynamic_pointer_cast<const tvertical_scrollbar_definition::tresolution>(config()); 00050 assert(conf); 00051 return conf->top_offset; 00052 } 00053 00054 unsigned tvertical_scrollbar::offset_after() const 00055 { 00056 boost::intrusive_ptr<const tvertical_scrollbar_definition::tresolution> conf = 00057 boost::dynamic_pointer_cast<const tvertical_scrollbar_definition::tresolution>(config()); 00058 assert(conf); 00059 return conf->bottom_offset; 00060 } 00061 00062 bool tvertical_scrollbar::on_positioner(const tpoint& coordinate) const 00063 { 00064 // Note we assume the positioner is over the entire width of the widget. 00065 return coordinate.y >= static_cast<int>(get_positioner_offset()) 00066 && coordinate.y < static_cast<int>(get_positioner_offset() + get_positioner_length()) 00067 && coordinate.x > 0 00068 && coordinate.x < static_cast<int>(get_width()); 00069 } 00070 00071 int tvertical_scrollbar::on_bar(const tpoint& coordinate) const 00072 { 00073 // Not on the widget, leave. 00074 if(static_cast<size_t>(coordinate.x) > get_width() 00075 || static_cast<size_t>(coordinate.y) > get_height()) { 00076 return 0; 00077 } 00078 00079 // we also assume the bar is over the entire width of the widget. 00080 if(static_cast<size_t>(coordinate.y) < get_positioner_offset()) { 00081 return -1; 00082 } else if(static_cast<size_t>(coordinate.y) >get_positioner_offset() + get_positioner_length()) { 00083 return 1; 00084 } else { 00085 return 0; 00086 } 00087 } 00088 00089 const std::string& tvertical_scrollbar::get_control_type() const 00090 { 00091 static const std::string type = "vertical_scrollbar"; 00092 return type; 00093 } 00094 00095 } // namespace gui2 00096 00097
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:56 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |