slider.hpp

Go to the documentation of this file.
00001 /* $Id: slider.hpp 23842 2008-02-16 08:47:16Z mordante $ */
00002 /*
00003    Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
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 version 2
00008    or at your option any later version.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 #ifndef SLIDER_HPP_INCLUDED
00015 #define SLIDER_HPP_INCLUDED
00016 
00017 #include "SDL.h"
00018 
00019 #include "../sdl_utils.hpp"
00020 
00021 #include "widget.hpp"
00022 
00023 #include <vector>
00024 
00025 namespace gui {
00026 
00027 class slider : public widget
00028 {
00029 public:
00030     slider(CVideo &video);
00031 
00032     void set_min(int value);
00033     void set_max(int value);
00034     void set_value(int value);
00035     void set_increment(int increment);
00036 
00037     int value() const;
00038     int max_value() const;
00039     int min_value() const;
00040 
00041     bool value_change();
00042 
00043     virtual void enable(bool new_val=true);
00044 
00045     //VC++ doesn't like a 'using scrollarea::set_location' directive here, so we declare
00046     //an inline forwarding function instead
00047     void set_location(int x, int y) { widget::set_location(x,y); }
00048     virtual void set_location(SDL_Rect const &rect);
00049 
00050 protected:
00051     bool requires_event_focus(const SDL_Event *event=NULL) const;
00052     virtual void handle_event(const SDL_Event& event);
00053     virtual void draw_contents();
00054 
00055 private:
00056     void mouse_motion(const SDL_MouseMotionEvent& event);
00057     void mouse_down(const SDL_MouseButtonEvent& event);
00058     void set_slider_position(int x);
00059     SDL_Rect slider_area() const;
00060     surface image_, highlightedImage_;
00061 
00062     int min_;
00063     int max_;
00064     int value_;
00065     int increment_;
00066 
00067     bool value_change_;
00068 
00069     enum STATE { UNINIT, NORMAL, ACTIVE, CLICKED, DRAGGED };
00070     STATE state_;
00071 };
00072 
00073 
00074 template<typename T>
00075 class list_slider : public slider
00076 {
00077     public:
00078         list_slider(CVideo &video);
00079         list_slider(CVideo &video, const std::vector<T> &items);
00080         void set_items(const std::vector<T> &items);
00081         bool select_item(const T& item); //use select_item() instead of set_value()
00082         const T& item_selected() const; //use item_selected() instead of value()
00083     private:
00084         std::vector<T> items_;
00085 };
00086 
00087 }
00088 
00089 #endif

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