Torque3D Documentation / _generateds / platformWindow.h

platformWindow.h

Engine/source/windowManager/platformWindow.h

More...

Classes:

class

Abstract representation of a native OS window.

Public Typedefs

ScreenResChangeSignal 

Detailed Description

Public Typedefs

typedef Signal< void(PlatformWindow *PlatformWindow, bool resize)> ScreenResChangeSignal 
  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _WINDOWMANAGER_PLATFORMWINDOW_H_
 25#define _WINDOWMANAGER_PLATFORMWINDOW_H_
 26
 27#include "math/mRect.h"
 28#include "core/util/journal/journaledSignal.h"
 29#include "core/util/safeDelete.h"
 30#include "windowManager/platformCursorController.h"
 31#include "windowManager/windowInputGenerator.h"
 32#ifndef _SIGNAL_H_ //Volumetric Fog
 33#include "core/util/tSignal.h"
 34#endif
 35
 36//forward decl's
 37class PlatformWindowManager;
 38class GFXDevice;
 39struct GFXVideoMode;
 40class GFXWindowTarget;
 41class IProcessInput;
 42typedef Signal<void(PlatformWindow *PlatformWindow, bool resize)> ScreenResChangeSignal;
 43/// Abstract representation of a native OS window.
 44///
 45/// Every windowing system has its own representations and conventions as
 46/// regards the windows on-screen. In order to provide Torque with means for
 47/// interfacing with multiple windows, tracking their state, etc. we provide
 48/// this interface.
 49///
 50/// This interface also allows the app to access the render target for the 
 51/// window it represents, as well as control mode switches, get mode info,
 52/// and so on.
 53///
 54/// @see PlatformWindowManager
 55class PlatformWindow
 56{
 57   friend class PlatformWindowManager;
 58protected:
 59
 60   /// Are we enabling IME or other keyboard input translation services,
 61   /// or concerned about raw input?
 62   bool mEnableKeyboardTranslation;
 63
 64   /// When Torque GuiText input controls have focus they need to
 65   /// disable native OS keyboard accelerator translation.
 66   bool mEnableAccelerators;
 67
 68   /// Minimum allowed size for this window. When possible, we will communicate
 69   /// this to the OS.
 70   Point2I mMinimumSize;
 71
 72   /// When the resize is locked, this will be used as both minimum and maximum window size
 73   Point2I mLockedSize;
 74
 75   /// When this is true, resizing is locked
 76   bool mResizeLocked;
 77
 78   /// Is Idle?
 79   bool mIsBackground;
 80
 81   /// Cursor Controller for this Window
 82   PlatformCursorController *mCursorController;
 83   
 84   /// An opaque ID used to resolve references to this Window
 85   WindowId mWindowId;
 86
 87   /// Window Mouse/Key input Controller for this Window
 88   WindowInputGenerator *mWindowInputGenerator;
 89
 90   /// Suppress device resets
 91   bool mSuppressReset;
 92
 93   /// Offscreen Render
 94   bool mOffscreenRender;
 95
 96   /// This is set as part of the canvas being shown, and flags that the windows should render as normal from now on.
 97   // Basically a flag that lets the window manager know that we've handled the splash screen, and to operate as normal.
 98   bool mDisplayWindow;
 99
100   /// Protected constructor so that the win
101   PlatformWindow()
102   {
103      mIsBackground = false; // This could be toggled to true to prefer performance.
104      mMinimumSize.set(0,0);
105      mLockedSize.set(0,0);
106      mResizeLocked = false;
107      mEnableKeyboardTranslation = false;
108      mEnableAccelerators = true;
109      mCursorController = NULL;
110      mSuppressReset = false;
111      mOffscreenRender = false;
112      mDisplayWindow = false;
113
114      // This controller maps window input (Mouse/Keyboard) to a generic input consumer
115      mWindowInputGenerator = new WindowInputGenerator( this );
116   }
117   static ScreenResChangeSignal smScreenResChangeSignal;
118public:
119
120   /// To get rid of a window, just delete it. Make sure the GFXDevice is
121   /// done with it first!
122   virtual ~PlatformWindow() 
123   {
124      SAFE_DELETE( mCursorController );
125      SAFE_DELETE( mWindowInputGenerator );
126   }
127
128   /// Get the WindowController associated with this window
129   virtual void setInputController( IProcessInput *controller ) { if( mWindowInputGenerator ) mWindowInputGenerator->setInputController( controller ); };
130
131   WindowInputGenerator* getInputGenerator() const { return mWindowInputGenerator; }
132
133   /// Get the ID that uniquely identifies this window in the context of its
134   /// window manager.
135   virtual WindowId getWindowId() { return 0; };
136
137   enum WindowSystem
138   {
139      WindowSystem_Unknown = 0,
140      WindowSystem_Windows,
141      WindowSystem_X11,
142   };
143
144   virtual void* getSystemWindow(const WindowSystem system) { return NULL; }
145
146   /// Set the flag that determines whether to suppress a GFXDevice reset
147   inline void setSuppressReset(bool suppress) { mSuppressReset = suppress; };
148
149   /// @name GFX State Management
150   ///
151   /// @{
152
153   /// Return a pointer to the GFX device this window is bound to. A GFX
154   /// device may use many windows, but a window can only be used by a
155   /// single GFX device.
156   virtual GFXDevice *getGFXDevice()=0;
157
158   /// Return a pointer to this window's render target.
159   ///
160   /// By setting window targets from different windows, we can effect
161   /// rendering to multiple windows from a single device.
162   virtual GFXWindowTarget *getGFXTarget()=0;
163
164   /// Set the video mode for this window.
165   virtual void setVideoMode(const GFXVideoMode &mode);
166
167   /// Get our current video mode - if the window has been resized, it will
168   /// reflect this.
169   virtual const GFXVideoMode &getVideoMode()=0;
170
171   /// If we're fullscreen, this function returns us to desktop mode.
172   ///
173   /// This will be either the last mode that we had that was not
174   /// fullscreen, or the equivalent mode, windowed.
175   virtual bool clearFullscreen()=0;
176
177   /// @return true if this window is fullscreen, false otherwise.
178   virtual bool isFullscreen()=0;
179
180   /// Acquire the entire screen
181   void setFullscreen(const bool fullscreen);
182
183   /// Set Idle State (Background)
184   /// 
185   /// This is called to put a window into idle state, which causes it's 
186   /// rendering priority to be toned down to prefer performance
187   virtual void setBackground( bool val ) { mIsBackground = val; };
188
189   /// Get Idle State (Background)
190   ///
191   /// This is called to poll the window as to it's idle state.  
192   virtual bool getBackground() { return mIsBackground; };
193
194   /// Set whether this window is intended for offscreen rendering
195   /// An offscreen window will never be shown or lose focus
196   virtual void setOffscreenRender(bool val ) { mOffscreenRender = val; };
197
198   /// Set whether this window is intended for offscreen rendering
199   ///
200   /// This is called to poll the window as to it's idle state.  
201   virtual bool getOffscreenRender() { return mOffscreenRender; };
202
203   /// Set whether this window is should display as normal
204   virtual void setDisplayWindow(bool val ) { mDisplayWindow = val; };
205
206   /// Set Focused State (Foreground)
207   ///
208   /// Claim OS input focus for this window
209   virtual void setFocus() { }
210   /// @}
211
212   /// @name Caption
213   ///
214   /// @{
215
216   /// Set the window's caption.
217   virtual bool setCaption(const char *cap)=0;
218
219   /// Get the window's caption.
220   virtual const char *getCaption()=0;
221
222   /// @}
223
224   /// @name Visibility
225   ///
226   /// Control how the window is displayed
227   /// @{
228
229   /// Minimize the window on screen
230   virtual void minimize()=0;
231
232   /// Maximize the window on screen
233   virtual void maximize()=0;
234
235   /// Hide the window on screen
236   virtual void hide()=0;
237
238   /// Show the window on screen
239   virtual void show()=0;
240
241   /// Destroy the window on screen
242   virtual void close()=0;
243
244   /// Restore the window from a Maximized or Minimized state
245   virtual void restore()=0;
246
247   /// @}
248
249      /// @name Window Bounds
250   ///
251   /// @{
252
253   /// The Client Rectangle or "Render Area" of a window is the area that 
254   /// is occupied by a given client that is rendering to that window.
255   /// This does not include the area occupied by a title-bar, menu, 
256   /// borders or other non-client elements.
257   /// @{
258
259   /// Set the Client Area Extent (Resolution) of this window
260   virtual void setClientExtent( const Point2I newExtent ) = 0;
261
262   /// Get the Client Area Extent (Resolution) of this window
263   virtual const Point2I getClientExtent() = 0;
264
265   /// @}
266   /// The bounds of a Window are defined as the entire area occupied by 
267   /// that Window.  This includes the area needed for a title-bar, menu,
268   /// borders, and other non-client elements.
269   /// 
270   /// @{
271
272   /// Resize the window to have some new bounds.
273   virtual void setBounds( const RectI &newBounds ) = 0;
274
275   /// Get the position and size (fullscreen windows are always at (0,0)).
276   virtual const RectI getBounds() const = 0;
277
278   /// @}
279   /// The Position of a window is always in relation to the very upper left 
280   /// of the window.  This means that saying setPosition at 0,0 will put the 
281   /// position of the window title-bar (if one exists) at 0,0 and the Client
282   /// area will be offset from that point by the space needed for the Non-Client
283   /// area.
284   /// @{
285
286   /// Set the position of this window
287   virtual void setPosition( const Point2I newPosition ) = 0;
288
289   /// Get the position of this window
290   virtual const Point2I getPosition() = 0;
291
292   virtual void centerWindow() {};
293
294   /// Resize the window to have a new size (but be in the same position).
295   virtual bool setSize(const Point2I &newSize)=0;
296
297   /// @}
298   
299   /// @name Coordinate Space Conversion
300   /// @{
301
302   /// Convert the coordinate given in this window space to screen coordinates.
303   virtual Point2I clientToScreen( const Point2I& point ) = 0;
304   
305   /// Convert the given screen coordinates to coordinates in this window space.
306   virtual Point2I screenToClient( const Point2I& point ) = 0;
307   
308   /// @}
309
310   /// @name Windowed state
311   ///
312   /// This is only really meaningful if the window is not fullscreen.
313   ///
314   /// @{
315
316   /// Returns true if the window is instantiated in the OS.
317   virtual bool isOpen() = 0;
318
319   /// Returns true if the window is visible.
320   virtual bool isVisible() = 0;
321
322   /// Returns true if the window has input focus
323   virtual bool isFocused() = 0;
324
325   /// Returns true if the window is minimized
326   virtual bool isMinimized() = 0;
327
328   /// Returns true if the window is maximized
329   virtual bool isMaximized() = 0;
330   
331   /// @name Keyboard Translation
332   ///
333   /// When keyboard translation is on, keypress events that correspond to character input
334   /// should be send as character input events rather than as raw key events *except* if
335   /// shouldNotTranslate() returns true for a specific keypress event.  This enables the
336   /// platform layer to perform platform-specific character input mapping.
337   ///
338   /// @{
339
340   /// Set if relevant keypress events should be translated into character input events.
341   virtual void setKeyboardTranslation(const bool enabled)
342   {
343      mEnableKeyboardTranslation = enabled;
344   }
345
346   /// Returns true if keyboard translation is enabled.
347   virtual bool getKeyboardTranslation() const
348   {
349      return mEnableKeyboardTranslation;
350   }
351   
352   /// Returns true if the given keypress event should not be translated.
353   virtual bool shouldNotTranslate( U32 modifiers, U32 keyCode ) const;
354   
355   /// @}
356
357   /// Used to disable native OS keyboard accelerators.
358   virtual void setAcceleratorsEnabled(const bool enabled)
359   {
360      mEnableAccelerators = enabled;
361   }
362
363   /// Returns true if native OS keyboard accelerators are enabled.
364   virtual bool getAcceleratorsEnabled() const
365   {
366      return mEnableAccelerators;
367   }
368
369   /// Sets a minimum window size. We'll work with the OS to prevent user
370   /// from sizing the window to less than this. Setting to (0,0) means
371   /// user has complete freedom of resize.
372   virtual void setMinimumWindowSize(Point2I minSize)
373   {
374      mMinimumSize = minSize;
375   }
376
377   /// Returns the current minimum window size for this window.
378   virtual Point2I getMinimumWindowSize()
379   {
380      return mMinimumSize;
381   }
382
383   /// Locks/unlocks window resizing
384   virtual void lockSize(bool locked)
385   {
386      mResizeLocked = locked;
387      if (mResizeLocked)
388         mLockedSize = getBounds().extent;
389   }
390
391   /// Returns true if the window size is locked
392   virtual bool isSizeLocked()
393   {
394      return mResizeLocked;
395   }
396
397   /// Returns the locked window size
398   virtual Point2I getLockedSize()
399   {
400      return mLockedSize;
401   }
402   /// @}
403
404
405   /// @name Window Cursor
406   ///
407   /// Accessors to control a windows cursor shape and visibility
408   ///
409   /// @{
410   /// Get the CursorController that this window owns.
411   virtual PlatformCursorController *getCursorController() { return mCursorController; };
412
413   /// Set the cursor position based on logical coordinates from the upper-right corner
414   ///
415   /// @param x The X position of the cursor
416   /// @param y The Y position of the cursor
417   virtual void setCursorPosition(S32 x, S32 y)
418   {
419      if( mCursorController != NULL )
420         mCursorController->setCursorPosition(x,y);
421   }
422
423   /// Get the cursor position based on logical coordinates from the upper-right corner
424   ///
425   /// @param point A reference to a Point2I to store the coordinates
426   virtual void getCursorPosition( Point2I &point )
427   {
428      if( mCursorController != NULL )
429         mCursorController->getCursorPosition(point);
430   }
431   
432   /// Set the cursor visibility on this window
433   /// 
434   /// @param visible Whether the cursor should be visible or not
435   virtual void setCursorVisible(bool visible)
436   {
437      if( mCursorController != NULL )
438         mCursorController->setCursorVisible(visible);
439   }
440
441   /// Get the cursor visibility on this window
442   /// 
443   /// @return true if the cursor is visible or false if it's hidden
444   virtual bool isCursorVisible()
445   {
446      if( mCursorController != NULL )
447         return mCursorController->isCursorVisible();
448      return false;
449   }
450
451   /// Lock the mouse to this window.
452   ///
453   /// When this is set, the mouse will always be returned to the center
454   /// of the client area after every mouse event. The mouse will also be
455   /// hidden while it is locked.
456   ///
457   /// The mouse cannot be moved out of the bounds of the window, but the
458   /// window may lose focus (for instance by an alt-tab or other event).
459   /// While the window lacks focus, no mouse events will be reported.
460   virtual void setMouseLocked( bool enable )=0;
461
462   /// Is the mouse locked ?
463   virtual bool isMouseLocked() const = 0;
464
465   /// Should the mouse be locked at the next opportunity ?
466   ///
467   /// This flag is set to the current state of the mouse lock
468   /// on a window, to specify the preferred lock status of the
469   /// mouse in a platform window.
470   /// 
471   /// This is important for situations where a call is made 
472   /// to setMouseLocked, and the window is not in a state that
473   /// it can be cleanly locked. Take for example if it was called
474   /// while the window is in the background, then it is not appropriate
475   /// to lock the window, but rather the window should query this
476   /// state at it's next opportunity and lock the mouse if requested.
477   virtual bool shouldLockMouse() const = 0;
478
479   /// @}
480
481   virtual PlatformWindow * getNextWindow() const = 0;
482
483   /// @name Event Handlers
484   ///
485   /// Various events that this window receives. These are all subclasses of
486   /// JournaledSignal, so you can subscribe to them and receive notifications
487   /// per the documentation for that class.
488   ///
489   /// @{
490
491   ///
492   AppEvent          appEvent;
493   MouseEvent        mouseEvent;
494   MouseWheelEvent   wheelEvent;
495   ButtonEvent       buttonEvent;
496   LinearEvent       linearEvent;
497   KeyEvent          keyEvent;
498   CharEvent         charEvent;
499   DisplayEvent      displayEvent;
500   ResizeEvent       resizeEvent;
501   IdleEvent         idleEvent;
502
503   /// @}
504   static ScreenResChangeSignal& getScreenResChangeSignal() { return smScreenResChangeSignal; }
505   
506   /// Get the platform specific object needed to create or attach an accelerated
507   /// graohics drawing context on or to the window
508   /// Win32 D3D and OpenGL typically needs an HWND
509   /// Mac Cocoa OpenGL typically needs an NSOpenGLView
510   /// Mac Carbon OpenGL typically needs a WindowRef
511   ///
512   virtual void* getPlatformDrawable() const = 0;
513protected:
514   virtual void _setFullscreen(const bool fullScreen) {};
515   virtual void _setVideoMode(const GFXVideoMode &mode) = 0;
516};
517
518#endif
519