00001 /* $Id: horizontal_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/horizontal_scrollbar.hpp" 00019 00020 #include "gui/widgets/settings.hpp" 00021 #include "gui/auxiliary/widget_definition/horizontal_scrollbar.hpp" 00022 #include "gui/auxiliary/window_builder/horizontal_scrollbar.hpp" 00023 00024 #include <boost/bind.hpp> 00025 00026 namespace gui2 { 00027 00028 REGISTER_WIDGET(horizontal_scrollbar) 00029 00030 unsigned thorizontal_scrollbar::minimum_positioner_length() const 00031 { 00032 boost::intrusive_ptr 00033 <const thorizontal_scrollbar_definition::tresolution> conf = 00034 boost::dynamic_pointer_cast 00035 <const thorizontal_scrollbar_definition::tresolution>(config()); 00036 00037 assert(conf); 00038 return conf->minimum_positioner_length; 00039 } 00040 00041 unsigned thorizontal_scrollbar::maximum_positioner_length() const 00042 { 00043 boost::intrusive_ptr 00044 <const thorizontal_scrollbar_definition::tresolution> conf = 00045 boost::dynamic_pointer_cast 00046 <const thorizontal_scrollbar_definition::tresolution>(config()); 00047 00048 assert(conf); 00049 return conf->maximum_positioner_length; 00050 } 00051 00052 unsigned thorizontal_scrollbar::offset_before() const 00053 { 00054 boost::intrusive_ptr 00055 <const thorizontal_scrollbar_definition::tresolution> conf = 00056 boost::dynamic_pointer_cast 00057 <const thorizontal_scrollbar_definition::tresolution>(config()); 00058 00059 assert(conf); 00060 return conf->left_offset; 00061 } 00062 00063 unsigned thorizontal_scrollbar::offset_after() const 00064 { 00065 boost::intrusive_ptr 00066 <const thorizontal_scrollbar_definition::tresolution> conf = 00067 boost::dynamic_pointer_cast 00068 <const thorizontal_scrollbar_definition::tresolution>(config()); 00069 assert(conf); 00070 00071 return conf->right_offset; 00072 } 00073 00074 bool thorizontal_scrollbar::on_positioner(const tpoint& coordinate) const 00075 { 00076 // Note we assume the positioner is over the entire height of the widget. 00077 return coordinate.x >= static_cast<int>(get_positioner_offset()) 00078 && coordinate.x < static_cast<int>(get_positioner_offset() 00079 + get_positioner_length()) 00080 && coordinate.y > 0 00081 && coordinate.y < static_cast<int>(get_height()); 00082 } 00083 00084 int thorizontal_scrollbar::on_bar(const tpoint& coordinate) const 00085 { 00086 // Not on the widget, leave. 00087 if(static_cast<size_t>(coordinate.x) > get_width() 00088 || static_cast<size_t>(coordinate.y) > get_height()) { 00089 return 0; 00090 } 00091 00092 // we also assume the bar is over the entire width of the widget. 00093 if(static_cast<size_t>(coordinate.x) < get_positioner_offset()) { 00094 return -1; 00095 } else if(static_cast<size_t>(coordinate.x) > 00096 get_positioner_offset() + get_positioner_length()) { 00097 00098 return 1; 00099 } else { 00100 return 0; 00101 } 00102 } 00103 00104 const std::string& thorizontal_scrollbar::get_control_type() const 00105 { 00106 static const std::string type = "horizontal_scrollbar"; 00107 return type; 00108 } 00109 00110 } // namespace gui2 00111
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:54 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |