MyGUI  3.0.1
MyGUI_InputManager.h
Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #ifndef __MYGUI_INPUT_MANAGER_H__
00024 #define __MYGUI_INPUT_MANAGER_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Macros.h"
00028 #include "MyGUI_Instance.h"
00029 #include "MyGUI_WidgetDefines.h"
00030 #include "MyGUI_IUnlinkWidget.h"
00031 #include "MyGUI_WidgetDefines.h"
00032 #include "MyGUI_XmlDocument.h"
00033 #include "MyGUI_InputDefine.h"
00034 #include "MyGUI_Timer.h"
00035 #include "MyGUI_ILayer.h"
00036 #include "MyGUI_Delegate.h"
00037 
00038 namespace MyGUI
00039 {
00040 
00041     class MYGUI_EXPORT InputManager : public IUnlinkWidget
00042     {
00043         MYGUI_INSTANCE_HEADER( InputManager )
00044 
00045     public:
00046         void initialise();
00047         void shutdown();
00048 
00052         bool injectMouseMove(int _absx, int _absy, int _absz);
00056         bool injectMousePress(int _absx, int _absy, MouseButton _id);
00060         bool injectMouseRelease(int _absx, int _absy, MouseButton _id);
00061 
00065         bool injectKeyPress(KeyCode _key, Char _text = 0);
00069         bool injectKeyRelease(KeyCode _key);
00070 
00072         bool isFocusMouse() { return mWidgetMouseFocus != nullptr; }
00074         bool isFocusKey() { return mWidgetKeyFocus != nullptr; }
00076         bool isCaptureMouse() { return mIsWidgetMouseCapture; }
00077 
00079         void setKeyFocusWidget(Widget* _widget);
00081         void resetKeyFocusWidget(Widget* _widget);
00083         void resetKeyFocusWidget() { setKeyFocusWidget(nullptr); }
00084 
00086         Widget* getMouseFocusWidget() { return mWidgetMouseFocus; }
00088         Widget* getKeyFocusWidget() { return mWidgetKeyFocus; }
00090         const IntPoint& getLastLeftPressed() { return mLastLeftPressed; }
00092         const IntPoint& getMousePosition() { return mMousePosition; }
00093 
00094         IntPoint getMousePositionByLayer();
00095 
00096         // тестовый вариант, очистка фокуса мыши
00098         void resetMouseFocusWidget();
00099 
00100         // работа с модальными окнами
00102         void addWidgetModal(Widget* _widget);
00104         void removeWidgetModal(Widget* _widget);
00105 
00107         bool isModalAny() { return !mVectorModalRootWidget.empty(); }
00108 
00110         bool isControlPressed() { return mIsControlPressed; }
00112         bool isShiftPressed() { return mIsShiftPressed; }
00113 
00117         void resetMouseCaptureWidget() { mIsWidgetMouseCapture = false; }
00118 
00119         void unlinkWidget(Widget* _widget) { _unlinkWidget(_widget); }
00120 
00125         delegates::CMultiDelegate1<Widget*>
00126             eventChangeMouseFocus;
00127 
00132         delegates::CMultiDelegate1<Widget*>
00133             eventChangeKeyFocus;
00134 
00135     private:
00136         // удаляем данный виджет из всех возможных мест
00137         void _unlinkWidget(Widget* _widget);
00138 
00139         void frameEntered(float _frame);
00140 
00141         void firstEncoding(KeyCode _key, bool bIsKeyPressed);
00142 
00143         // запоминает клавишу для поддержки повторения
00144         void storeKey(KeyCode _key, Char _text);
00145 
00146         // сбрасывает клавишу повторения
00147         void resetKey();
00148 
00149     private:
00150         // виджеты которым принадлежит фокус
00151         Widget* mWidgetMouseFocus;
00152         Widget* mWidgetKeyFocus;
00153         ILayer* mLayerMouseFocus;
00154         // захватил ли мышь активный виджет
00155         bool mIsWidgetMouseCapture;
00156         // таймер для двойного клика
00157         Timer mTimer; //used for double click timing
00158 
00159         // нажат ли шифт
00160         bool mIsShiftPressed;
00161         // нажат ли контрол
00162         bool mIsControlPressed;
00163         // там где была последний раз нажата левая кнопка
00164         IntPoint mLastLeftPressed;
00165         IntPoint mMousePosition;
00166         // клавиша для повтора
00167         KeyCode mHoldKey;
00168         Char mHoldChar;
00169         bool mFirstPressKey;
00170         float mTimerKey;
00171         int mOldAbsZ;
00172 
00173         // список виджетов с модальным режимом
00174         VectorWidgetPtr mVectorModalRootWidget;
00175 
00176     };
00177 
00178 } // namespace MyGUI
00179 
00180 #endif // __MYGUI_INPUT_MANAGER_H__