button.hpp

Go to the documentation of this file.
00001 /* $Id: button.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 BUTTON_H_INCLUDED
00015 #define BUTTON_H_INCLUDED
00016 
00017 #include "SDL.h"
00018 
00019 #include "widget.hpp"
00020 
00021 #include "../sdl_utils.hpp"
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <string>
00026 
00027 namespace gui {
00028 
00029 class button : public widget
00030 {
00031 public:
00032     struct error {};
00033 
00034     enum TYPE { TYPE_PRESS, TYPE_CHECK, TYPE_TURBO, TYPE_IMAGE };
00035 
00036     enum SPACE_CONSUMPTION { DEFAULT_SPACE, MINIMUM_SPACE };
00037 
00038     button(CVideo& video, const std::string& label, TYPE type=TYPE_PRESS,
00039            std::string button_image="", SPACE_CONSUMPTION spacing=DEFAULT_SPACE,
00040            const bool auto_join=true);
00041 
00042     virtual ~button() {}
00043     void set_check(bool check);
00044     bool checked() const;
00045 
00046     void set_label(const std::string& val);
00047 
00048     bool pressed();
00049     bool hit(int x, int y) const;
00050     virtual void enable(bool new_val=true);
00051     void release();
00052 
00053 protected:
00054     virtual void handle_event(const SDL_Event& event);
00055     virtual void mouse_motion(const SDL_MouseMotionEvent& event);
00056     virtual void mouse_down(const SDL_MouseButtonEvent& event);
00057     virtual void mouse_up(const SDL_MouseButtonEvent& event);
00058     virtual void draw_contents();
00059 
00060     TYPE type_;
00061 
00062 private:
00063 
00064     void calculate_size();
00065 
00066     std::string label_;
00067     surface image_, pressedImage_, activeImage_, pressedActiveImage_;
00068     SDL_Rect textRect_;
00069 
00070     bool button_;
00071 
00072     enum STATE { UNINIT, NORMAL, ACTIVE, PRESSED, PRESSED_ACTIVE };
00073     STATE state_;
00074 
00075     bool pressed_;
00076 
00077     SPACE_CONSUMPTION spacing_;
00078 
00079     int base_height_, base_width_;
00080 
00081 }; //end class button
00082 
00083 }
00084 
00085 #endif

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