controller_base.hpp

Go to the documentation of this file.
00001 /* $Id: controller_base.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2006 - 2012 by Joerg Hinrichs <joerg.hinrichs@alice-dsl.de>
00004    wesnoth playlevel Copyright (C) 2003 by David White <dave@whitevine.net>
00005    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2 of the License, or
00010    (at your option) any later version.
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY.
00013 
00014    See the COPYING file for more details.
00015 */
00016 
00017 #ifndef CONTROLLER_BASE_H_INCLUDED
00018 #define CONTROLLER_BASE_H_INCLUDED
00019 
00020 #include "global.hpp"
00021 
00022 #include "hotkeys.hpp"
00023 #include "key.hpp"
00024 
00025 #include "joystick.hpp"
00026 
00027 #include "map.hpp"
00028 
00029 class CVideo;
00030 
00031 namespace events {
00032 class mouse_handler_base;
00033 }
00034 
00035 class controller_base : public hotkey::command_executor, public events::handler
00036 {
00037 public:
00038     controller_base(int ticks, const config& game_config, CVideo& video);
00039     virtual ~controller_base();
00040 
00041     void play_slice(bool is_delay_enabled = true);
00042 
00043     int get_ticks();
00044 
00045 protected:
00046     /**
00047      * Called by play_slice after events:: calls, but before processing scroll
00048      * and other things like menu.
00049      */
00050     virtual void slice_before_scroll();
00051 
00052     /**
00053      * Called at the very end of play_slice
00054      */
00055     virtual void slice_end();
00056 
00057     /**
00058      * Get a reference to a mouse handler member a derived class uses
00059      */
00060     virtual events::mouse_handler_base& get_mouse_handler_base() = 0;
00061     /**
00062      * Get a reference to a display member a derived class uses
00063      */
00064     virtual display& get_display() = 0;
00065 
00066 
00067     /**
00068      * Derived classes should override this to return false when arrow keys
00069      * should not scroll the map, hotkeys not processed etc, for example
00070      * when a textbox is active
00071      * @returns true when arrow keys should scroll the map, false otherwise
00072      */
00073     virtual bool have_keyboard_focus();
00074 
00075 
00076     /**
00077      * Handle scrolling by keyboard, joystick and moving mouse near map edges
00078      * @see is_keyboard_scroll_active
00079      * @return true when there was any scrolling, false otherwise
00080      */
00081     bool handle_scroll(CKey& key, int mousex, int mousey, int mouse_flags, double joystickx, double joysticky);
00082 
00083     /**
00084      * Process mouse- and keypress-events from SDL.
00085      * Not virtual but calls various virtual function to allow specialized
00086      * behaviour of derived classes.
00087      */
00088     void handle_event(const SDL_Event& event);
00089 
00090     /**
00091      * Process keydown (only when the general map display does not have focus).
00092      */
00093     virtual void process_focus_keydown_event(const SDL_Event& event);
00094 
00095     /**
00096      * Process keydown (always).
00097      * Overridden in derived classes
00098      */
00099     virtual void process_keydown_event(const SDL_Event& event);
00100 
00101     /**
00102      * Process keyup (always).
00103      * Overridden in derived classes
00104      */
00105     virtual void process_keyup_event(const SDL_Event& event);
00106 
00107     /**
00108      * Called after processing a mouse button up or down event
00109      * Overridden in derived classes
00110      */
00111     virtual void post_mouse_press(const SDL_Event& event);
00112 
00113     virtual void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu);
00114 
00115     virtual bool in_context_menu(hotkey::HOTKEY_COMMAND command) const;
00116 
00117     const config &get_theme(const config& game_config, std::string theme_name);
00118     const config& game_config_;
00119     const int ticks_;
00120     CKey key_;
00121     bool browse_;
00122     bool scrolling_;
00123     joystick_manager joystick_manager_;
00124 
00125 };
00126 
00127 
00128 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:02:33 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs