widgets/slider.hpp

Go to the documentation of this file.
00001 /* $Id: slider.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 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 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 #ifndef SLIDER_HPP_INCLUDED
00016 #define SLIDER_HPP_INCLUDED
00017 
00018 #include "SDL.h"
00019 
00020 #include "../sdl_utils.hpp"
00021 
00022 #include "widget.hpp"
00023 
00024 #include <vector>
00025 
00026 namespace gui {
00027 
00028 class slider : public widget
00029 {
00030 public:
00031     slider(CVideo &video);
00032 
00033     void set_min(int value);
00034     void set_max(int value);
00035     void set_value(int value);
00036     void set_increment(int increment);
00037 
00038     int value() const;
00039     int max_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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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