Crazy Eddie's GUI System  0.8.4
GUIContext.h
00001 /***********************************************************************
00002     created:    Mon Jan 12 2009
00003     author:     Paul D Turner
00004 *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
00007  *
00008  *   Permission is hereby granted, free of charge, to any person obtaining
00009  *   a copy of this software and associated documentation files (the
00010  *   "Software"), to deal in the Software without restriction, including
00011  *   without limitation the rights to use, copy, modify, merge, publish,
00012  *   distribute, sublicense, and/or sell copies of the Software, and to
00013  *   permit persons to whom the Software is furnished to do so, subject to
00014  *   the following conditions:
00015  *
00016  *   The above copyright notice and this permission notice shall be
00017  *   included in all copies or substantial portions of the Software.
00018  *
00019  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00023  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00024  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  *   OTHER DEALINGS IN THE SOFTWARE.
00026  ***************************************************************************/
00027 #ifndef _CEGUIGUIContext_h_
00028 #define _CEGUIGUIContext_h_
00029 
00030 #include "CEGUI/RenderingSurface.h"
00031 #include "CEGUI/InjectedInputReceiver.h"
00032 #include "CEGUI/MouseCursor.h"
00033 #include "CEGUI/SystemKeys.h"
00034 
00035 #if defined (_MSC_VER)
00036 #   pragma warning(push)
00037 #   pragma warning(disable : 4251)
00038 #endif
00039 
00040 namespace CEGUI
00041 {
00042 struct MouseClickTracker;
00043 
00045 class CEGUIEXPORT GUIContextEventArgs : public EventArgs
00046 {
00047 public:
00048     GUIContextEventArgs(GUIContext* context):
00049         context(context)
00050     {}
00051 
00053     GUIContext* context;
00054 };
00055 
00057 class CEGUIEXPORT GUIContextRenderTargetEventArgs : public GUIContextEventArgs
00058 {
00059 public:
00060     GUIContextRenderTargetEventArgs(GUIContext* context, RenderTarget* target) :
00061         GUIContextEventArgs(context),
00062         renderTarget(target)
00063     {}
00064 
00065     RenderTarget* renderTarget;
00066 };
00067 
00068 class CEGUIEXPORT GUIContext : public RenderingSurface,
00069                                public InjectedInputReceiver
00070 {
00071 public:
00072     static const float DefaultMouseButtonClickTimeout;
00073     static const float DefaultMouseButtonMultiClickTimeout;
00074     static const Sizef DefaultMouseButtonMultiClickTolerance;
00075 
00082     static const String EventRootWindowChanged;
00086     static const String EventMouseMoveScalingFactorChanged;
00090     static const String EventMouseButtonClickTimeoutChanged;
00094     static const String EventMouseButtonMultiClickTimeoutChanged;
00099     static const String EventMouseButtonMultiClickToleranceChanged;
00104     static const String EventRenderTargetChanged;
00108         static const String EventDefaultFontChanged;
00109 
00110     GUIContext(RenderTarget& target);
00111     ~GUIContext();
00112 
00113     Window* getRootWindow() const;
00114     void setRootWindow(Window* new_root);
00115 
00124     void setModalWindow(Window* window);
00125 
00127     Window* getModalWindow() const;
00128 
00129     Window* getWindowContainingMouse() const;
00130 
00131     const Sizef& getSurfaceSize() const;
00132 
00133     const SystemKeys& getSystemKeys() const;
00134 
00136     void markAsDirty();
00137     bool isDirty() const;
00138 
00150     MouseCursor& getMouseCursor();
00151     const MouseCursor& getMouseCursor() const;
00152 
00153     void setMouseMoveScalingFactor(float factor);
00154     float getMouseMoveScalingFactor() const;
00155 
00156     void setMouseButtonClickTimeout(float seconds);
00157     float getMouseButtonClickTimeout() const;
00158 
00159     void setMouseButtonMultiClickTimeout(float seconds);
00160     float getMouseButtonMultiClickTimeout() const;
00161 
00162     void setMouseButtonMultiClickTolerance(const Sizef& sz);
00163     const Sizef& getMouseButtonMultiClickTolerance() const;
00164 
00178     void setMouseClickEventGenerationEnabled(const bool enable);
00179 
00193     bool isMouseClickEventGenerationEnabled() const;
00194 
00196     void updateWindowContainingMouse();
00197 
00198     Window* getInputCaptureWindow() const;
00199     void setInputCaptureWindow(Window* window);
00200 
00215     void setDefaultTooltipObject(Tooltip* tooltip);
00216 
00229     void setDefaultTooltipType(const String& tooltip_type);
00230 
00232     Tooltip* getDefaultTooltipObject() const;
00233 
00234     void setRenderTarget(RenderTarget& target);
00235 
00244     void setDefaultFont(const String& name);
00245 
00253     void setDefaultFont(Font* font);
00254 
00262     Font* getDefaultFont() const;
00263 
00264     // Implementation of InjectedInputReceiver interface
00265     bool injectMouseMove(float delta_x, float delta_y);
00266     bool injectMouseLeaves(void);
00267     bool injectMouseButtonDown(MouseButton button);
00268     bool injectMouseButtonUp(MouseButton button);
00269     bool injectKeyDown(Key::Scan scan_code);
00270     bool injectKeyUp(Key::Scan scan_code);
00271     bool injectChar(String::value_type code_point);
00272     bool injectMouseWheelChange(float delta);
00273     bool injectMousePosition(float x_pos, float y_pos);
00274     bool injectTimePulse(float timeElapsed);
00275     bool injectMouseButtonClick(const MouseButton button);
00276     bool injectMouseButtonDoubleClick(const MouseButton button);
00277     bool injectMouseButtonTripleClick(const MouseButton button);
00278     bool injectCopyRequest();
00279     bool injectCutRequest();
00280     bool injectPasteRequest();
00281 
00282     // public overrides
00283     void draw();
00284 
00285 protected:
00286     void updateRootWindowAreaRects() const;
00287     void drawWindowContentToTarget();
00288     void renderWindowHierarchyToSurfaces();
00289 
00290     void createDefaultTooltipWindowInstance() const;
00291     void destroyDefaultTooltipWindowInstance();
00292 
00294     void notifyDefaultFontChanged(Window* hierarchy_root) const;
00295 
00296     bool mouseMoveInjection_impl(MouseEventArgs& ma);
00297     Window* getTargetWindow(const Vector2f& pt, const bool allow_disabled) const;
00298     Window* getKeyboardTargetWindow() const;
00299     Window* getCommonAncestor(Window* w1, Window* w2) const;
00301     void notifyMouseTransition(Window* top, Window* bottom,
00302                                void (Window::*func)(MouseEventArgs&),
00303                                MouseEventArgs& args) const;
00304 
00305     bool areaChangedHandler(const EventArgs& args);
00306     bool windowDestroyedHandler(const EventArgs& args);
00307     
00309     bool updateWindowContainingMouse_impl() const;
00310     void resetWindowContainingMouse();
00311 
00312     // event trigger functions.
00313     virtual void onRootWindowChanged(WindowEventArgs& args);
00314     virtual void onMouseMoveScalingFactorChanged(GUIContextEventArgs& args);
00315     virtual void onMouseButtonClickTimeoutChanged(GUIContextEventArgs& args);
00316     virtual void onMouseButtonMultiClickTimeoutChanged(GUIContextEventArgs& args);
00317     virtual void onMouseButtonMultiClickToleranceChanged(GUIContextEventArgs& args);
00318     virtual void onRenderTargetChanged(GUIContextRenderTargetEventArgs& args);
00319     virtual void onDefaultFontChanged(EventArgs& args);
00320 
00321     // protected overrides
00322     void drawContent();
00323 
00324     Window* d_rootWindow;
00325     bool d_isDirty;
00326     MouseCursor d_mouseCursor;
00328     float d_mouseMovementScalingFactor;
00330     bool d_generateMouseClickEvents;
00332     float d_mouseButtonClickTimeout;
00334     float d_mouseButtonMultiClickTimeout;
00336     Sizef d_mouseButtonMultiClickTolerance;
00337 
00338     mutable Tooltip* d_defaultTooltipObject;
00339     mutable bool d_weCreatedTooltipObject;
00340     String d_defaultTooltipType;
00341 
00342     Font* d_defaultFont;
00343 
00345     Sizef d_surfaceSize;
00346 
00347     mutable Window* d_windowContainingMouse;
00348     mutable bool    d_windowContainingMouseIsUpToDate;
00349     Window* d_modalWindow;
00350     Window* d_captureWindow;
00351 
00352     SystemKeys d_systemKeys;
00353     MouseClickTracker* d_mouseClickTrackers;
00354 
00355     Event::ScopedConnection d_areaChangedEventConnection;
00356     Event::ScopedConnection d_windowDestroyedEventConnection;
00357 };
00358 
00359 }
00360 
00361 #if defined(_MSC_VER)
00362 #   pragma warning(pop)
00363 #endif
00364 
00365 #endif
00366 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends