window.hpp

Go to the documentation of this file.
00001 /* $Id: window.hpp 26681 2008-05-18 06:05:59Z mordante $ */
00002 /*
00003    Copyright (C) 2007 - 2008 by Mark de Wever <koraq@xs4all.nl>
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 
00015 //! @file window.hpp
00016 //! This file contains the window object, this object is a top level container 
00017 //! which has the event management as well.
00018 
00019 #ifndef __GUI_WIDGETS_WINDOW_HPP_INCLUDED__
00020 #define __GUI_WIDGETS_WINDOW_HPP_INCLUDED__
00021 
00022 #include "gui/widgets/canvas.hpp"
00023 #include "gui/widgets/event_handler.hpp"
00024 #include "gui/widgets/helper.hpp" 
00025 #include "gui/widgets/panel.hpp"
00026 #include "gui/widgets/settings.hpp"
00027 #include "gui/widgets/tooltip.hpp"
00028 
00029 #include "sdl_utils.hpp"
00030 #include "video.hpp"
00031 
00032 #include "tstring.hpp"
00033 #include "config.hpp"
00034 #include "variable.hpp"
00035 
00036 #include "events.hpp"
00037 #include "SDL.h"
00038 
00039 #include <string>
00040 #include <map>
00041 
00042 namespace gui2{
00043 /**
00044  * base class of top level items, the only item 
00045  * which needs to store the final canvase to draw on
00046  */
00047 
00048 // we kunnen de timer gebruiken om een http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fAddTimer
00049 // event aan ons te sturen, oftewel een movemove can dit genereren indien gewenst
00050 //
00051 // mogelijk dit ook gebruiken in de toekomst als aansturing van flip()
00052 class twindow : public tpanel, public tevent_handler
00053 {
00054 public:
00055     twindow(CVideo& video, 
00056         const int x, const int y, const int w, const int h,
00057         const bool automatic_placement, 
00058         const unsigned horizontal_placement,
00059         const unsigned vertical_placement);
00060 
00061     // show the window
00062     // The flip function is the disp_.flip() if ommitted the video_flip() is used
00063     int show(const bool restore = true, void* flip_function = 0);
00064 
00065     // layout the window
00066     void layout(const SDL_Rect position);
00067 
00068     enum tstatus{ NEW, SHOWING, REQUEST_CLOSE, CLOSED };
00069 
00070     void close() { status_ = REQUEST_CLOSE; }
00071 
00072     void set_retval(const int retval, const bool close_window = true)
00073         { retval_ = retval; if(close_window) close(); }
00074 
00075     //! Inherited from tevent_handler.
00076     twindow& get_window() { return *this; }
00077     const twindow& get_window() const { return *this; }
00078 
00079     /** Inherited from tevent_handler. */
00080     twidget* find_widget(const tpoint& coordinate, const bool must_be_active) 
00081         { return tpanel::find_widget(coordinate, must_be_active); }
00082 
00083     /** Inherited from tevent_handler. */
00084     const twidget* find_widget(const tpoint& coordinate, 
00085             const bool must_be_active) const
00086         { return tpanel::find_widget(coordinate, must_be_active); }
00087 
00088     /** Inherited from tpanel. */
00089     twidget* find_widget(const std::string& id, const bool must_be_active) 
00090         { return tpanel::find_widget(id, must_be_active); }
00091     
00092     /** Inherited from tpanel. */
00093     const twidget* find_widget(const std::string& id, 
00094             const bool must_be_active) const 
00095         { return tpanel::find_widget(id, must_be_active); }
00096     
00097     tpoint client_position(const tpoint& screen_position) const
00098         { return tpoint(screen_position.x - get_x(), screen_position.y - get_y()); }
00099 
00100     tpoint screen_position(const tpoint& client_position) const
00101         { return tpoint(client_position.x + get_x(), client_position.y + get_y()); }
00102 
00103 
00104     void window_resize(tevent_handler&, 
00105         const unsigned new_width, const unsigned new_height);
00106 
00107     //! A window is always active atm so ignore the request.
00108     void set_active(const bool /*active*/) {}
00109     bool get_active() const { return true; }
00110     unsigned get_state() const { return 0; }
00111     bool full_redraw() const { return false; /* FIXME IMPLEMENT */ }
00112 
00113     //! Inherited from tpanel.
00114     void draw(surface& surface);
00115 
00116     //! Gets the coordinates of the client area, for external use the height
00117     //! and the width are the most interesting things.
00118     //FIXME this can be removed it the panel defintion inherites from panel defintion
00119     SDL_Rect get_client_rect() const;
00120 
00121     /** 
00122      * Updates the size of the window.
00123      * 
00124      * If the window has automatic placement set this function recacluates the
00125      * window. To be used after creation and after modification or items which
00126      * can have different sizes eg listboxes.
00127      */
00128     void recalculate_size();
00129 
00130 protected:
00131 private:
00132 
00133 
00134     void flip();
00135 
00136     CVideo& video_;
00137 
00138     tstatus status_;
00139 
00140     // return value of the window, 0 default.
00141     int retval_;
00142 
00143     //! When set the form needs a full layout redraw cycle.
00144     bool need_layout_;
00145 
00146 
00147     //! Inherited from tevent_handler.
00148     void do_show_tooltip(const tpoint& location, const t_string& tooltip);
00149     void do_remove_tooltip() { tooltip_.set_visible(false); }
00150     void do_show_help_popup(const tpoint& location, const t_string& help_popup);
00151     void do_remove_help_popup() { help_popup_.set_visible(false); }
00152 
00153     //! Widget for the tooltip.
00154     ttooltip tooltip_;
00155 
00156     //! Widget for the help popup FIXME should be thelp_popup.
00157     ttooltip help_popup_;
00158 
00159     //! Inherited from tcontrol.
00160     const std::string& get_control_type() const 
00161         { static const std::string type = "window"; return type; }
00162 
00163 
00164     /** Do we wish to place the widget automatically? */
00165     const bool automatic_placement_;
00166 
00167     /**
00168      * Sets the horizontal placement.
00169      *
00170      * Only used if automatic_placement_ is true.
00171      * The value should be a tgrid placement flag.
00172      */
00173     const unsigned horizontal_placement_;
00174 
00175     /**
00176      * Sets the vertical placement.
00177      *
00178      * Only used if automatic_placement_ is true.
00179      * The value should be a tgrid placement flag.
00180      */
00181     const unsigned vertical_placement_;
00182 
00183 };
00184 
00185 } // namespace gui2
00186 
00187 #endif

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