widgets/button.hpp

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