scrollbar.hpp

Go to the documentation of this file.
00001 /* $Id: scrollbar.hpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 by David White <dave@whitevine.net>
00004                  2004 - 2008 by Guillaume Melquiond <guillaume.melquiond@gmail.com>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License version 2
00009    or 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 //! @file widgets/scrollbar.hpp
00017 //!
00018 
00019 #ifndef SCROLLBAR_HPP_INCLUDED
00020 #define SCROLLBAR_HPP_INCLUDED
00021 
00022 #include "SDL.h"
00023 #include "../sdl_utils.hpp"
00024 #include "button.hpp"
00025 #include "widget.hpp"
00026 
00027 namespace gui {
00028 
00029 class scrollarea;
00030 
00031 //! Scrollbar
00032 class scrollbar : public widget
00033 {
00034 public:
00035     //! Create a scrollbar.
00036 //! @todo FIXME: parameterlist ??
00037     //- @param d         the display object
00038     //- @param pane      the widget where wheel events take place
00039     //- @param callback  a callback interface for warning that the grip has been moved
00040     scrollbar(CVideo &video);
00041 
00042     virtual void hide(bool value = true);
00043 
00044     //! Determine where the scrollbar is.
00045     //!
00046     //! @return  the position.
00047     //! @retval  returns 0 if the scrollbar is at the top,
00048     //! @retval  returns (full_size - shown_size) if it is at the bottom.
00049     //!
00050     unsigned get_position() const;
00051 
00052     unsigned get_max_position() const;
00053 
00054     //! Manually update the scrollbar.
00055     void set_position(unsigned pos);
00056 
00057     //! Ensure the viewport contains the position.
00058     void adjust_position(unsigned pos);
00059 
00060     //! Move the scrollbar.
00061     void move_position(int dep);
00062 
00063     //! Set the relative size of the grip.
00064     void set_shown_size(unsigned h);
00065 
00066     //! Set the relative size of the scrollbar.
00067     void set_full_size(unsigned h);
00068 
00069     //! Set scroll rate.
00070     void set_scroll_rate(unsigned r);
00071 
00072     //! Return true if the scrollbar has a valid size.
00073     bool is_valid_height(int height) const;
00074 
00075     //! Scrolls down one step
00076     void scroll_down();
00077 
00078     //! Scrolls up one step
00079     void scroll_up();
00080 
00081 protected:
00082     virtual handler_vector handler_members();
00083     virtual void update_location(SDL_Rect const &rect);
00084     virtual void handle_event(const SDL_Event& event);
00085     virtual void process_event();
00086     virtual void draw_contents();
00087 
00088 private:
00089     SDL_Rect grip_area() const;
00090     SDL_Rect groove_area() const;
00091     surface mid_scaled_, groove_scaled_;
00092 
00093     button uparrow_, downarrow_;
00094 
00095     enum STATE { UNINIT, NORMAL, ACTIVE, DRAGGED };
00096     STATE state_;
00097 
00098     int minimum_grip_height_, mousey_on_grip_;
00099     // Relative data
00100     unsigned int grip_position_, grip_height_, old_position_, full_height_;
00101     int scroll_rate_;
00102 
00103 };
00104 
00105 } // end namespace gui
00106 
00107 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs