widgets/scrollpane.hpp

Go to the documentation of this file.
00001 /* $Id: scrollpane.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2004 - 2012 by Philippe Plantier <ayin@anathas.org>
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 /** @file */
00017 
00018 #ifndef SCROLLPANE_HPP_INCLUDED
00019 #define SCROLLPANE_HPP_INCLUDED
00020 
00021 #include <map>
00022 #include <vector>
00023 
00024 #include "SDL.h"
00025 #include "../sdl_utils.hpp"
00026 #include "scrollarea.hpp"
00027 
00028 namespace gui {
00029 
00030 /** Scrollpane. */
00031 class scrollpane : public scrollarea
00032 {
00033 public:
00034     struct scrollpane_widget {
00035         scrollpane_widget(widget* w, int x=0, int y=0, int z_order=0)
00036             : w(w), x(x), y(y), z_order(z_order) {};
00037 
00038         widget* w;
00039         int x;
00040         int y;
00041         int z_order;
00042     };
00043 
00044     /**
00045      * Create a scrollpane.
00046      * @todo FIXME: parameterlist ??
00047      */
00048     //- @param d the display object
00049     //- @param pane the widget where wheel events take place
00050     //- @param callback a callback interface for warning that the grip has been moved
00051     scrollpane(CVideo &video);
00052 
00053     virtual void set_location(SDL_Rect const &rect);
00054 
00055     // VC++ doesn't like a 'using scrollarea::set_location' directive here,
00056     // so we declare an inline forwarding function instead.
00057     void set_location(int x, int y) { widget::set_location(x,y); }
00058 
00059     virtual void hide(bool value=true);
00060 
00061     void add_widget(widget* w, int x, int y, int z_order = 0);
00062     void remove_widget(widget* w);
00063     void clear();
00064 
00065 protected:
00066     //virtual void handle_event(const SDL_Event& event);
00067     //virtual void process_event();
00068     virtual void draw();
00069     virtual void set_inner_location(SDL_Rect const &rect);
00070     virtual void scroll(unsigned int pos);
00071 
00072 private:
00073     void update_widget_positions();
00074     void position_widget(scrollpane_widget& spw);
00075     SDL_Rect client_area() const;
00076     void update_content_size();
00077 
00078     int border_;
00079     typedef std::multimap<int, scrollpane_widget> widget_map;
00080     widget_map content_;
00081     SDL_Rect content_pos_;
00082 };
00083 
00084 } // namespace gui
00085 
00086 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:15 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs