nux-0.9.48

NuxGraphics/GraphicsDisplayWin.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef GRAPHICSDISPLAYWIN_H
00024 #define GRAPHICSDISPLAYWIN_H
00025 
00026 #include "Gfx_Interface.h"
00027 #include "GLTimer.h"
00028 #include "GLDeviceObjects.h"
00029 #include "GLRenderStates.h"
00030 
00031 namespace nux
00032 {
00033 
00034   class Event;
00035   class MainFBO;
00036   class GpuDevice;
00037   class GraphicsEngine;
00038   class IOpenGLFrameBufferObject;
00039 
00040   enum WindowStyle
00041   {
00042     WINDOWSTYLE_NORMAL,
00043     WINDOWSTYLE_PANEL,
00044     WINDOWSTYLE_DIALOG,
00045     WINDOWSTYLE_TOOL,
00046     WINDOWSTYLE_NOBORDER,
00047   };
00048 
00049 #define NUX_THREADMSG                           (WM_APP+0)
00050 #define NUX_THREADMSG_START_RENDERING           (WM_APP+1)  // Connection established // start at WM_APP
00051 #define NUX_THREADMSG_CHILD_WINDOW_TERMINATED   (WM_APP+2)  // General failure - Wait Connection failed
00052 #define NUX_THREADMSG_THREAD_TERMINATED         (WM_APP+3)  // Set wParam = Thread ID, lParam = 0
00053 
00054 // This will become GLWindow
00055   class GraphicsDisplay : public GraphicSystem
00056   {
00057     friend class GraphicsEngine;
00058 
00059   private:
00060 #ifdef WIN32
00061     // WIN32 system variables
00062     HGLRC       _opengl_rendering_context;  
00063     HDC         _device_context;            
00064     HWND        m_hWnd;                     
00065     HWND        m_ParentWindow;
00066 
00067     TCHAR m_WindowClassName[256];
00068     GLuint      m_PixelFormat;      // Holds The Results After Searching For A Match
00069     DWORD       m_dwExStyle;        // Window Extended Style
00070     DWORD       m_dwStyle;          // Window Style
00071     NString     m_WindowTitle;
00072 #endif
00073 
00074     static HGLRC sMainGLRC;         // Used as the first argument of wglShareLists to make all successive OpenGL  context share their objects
00075     static HDC   sMainDC;           // Used as the first argument of wglShareLists to make all successive OpenGL  context share their objects
00076 
00077     // size, position
00078     Size  m_ViewportSize;
00079     Size m_WindowSize;
00080 
00081     // surface attibute;
00082     bool m_fullscreen;
00083     unsigned int m_ScreenBitDepth;
00084 
00085     // verifiy that the interface is properly created
00086     bool m_GfxInterfaceCreated;
00087 
00088     // Device information
00089     void GetDisplayInfo();
00090     int m_index_of_current_mode;
00091 
00092     bool m_is_window_minimized;
00093 
00094     HCURSOR m_Cursor;
00095 
00096     static int Win32KeySymToINL (int Keysym);
00097     static int Win32VKToNuxKey (int vk);
00098   public:
00099 
00100     // Device
00101     int m_num_device_modes;
00102 
00103     // Event object
00104     IEvent *m_pEvent;
00105 
00106     // Creation
00107     bool IsGfxInterfaceCreated();
00108 
00110 
00118     bool CreateOpenGLWindow (
00119       const TCHAR *WindowTitle,
00120       unsigned int WindowWidth,
00121       unsigned int WindowHeight,
00122       WindowStyle Style,
00123       const GraphicsDisplay *Parent,
00124       bool FullscreenFlag = false,
00125       bool create_rendering_data = true);
00126 
00128 
00133     bool CreateFromOpenGLWindow (HWND WindowHandle, HDC WindowDCHandle, HGLRC OpenGLRenderingContext);
00134 
00135     void DestroyOpenGLWindow();
00136 
00137     void SetWindowTitle (const TCHAR *Title);
00138     void SetWindowSize (int width, int height);
00139     void SetViewPort (int x, int y, int width, int height);
00140     Point GetMouseScreenCoord();
00141     Point GetMouseWindowCoord();
00142     Point GetWindowCoord();
00143     Rect GetWindowGeometry();
00144     Rect GetNCWindowGeometry();
00145     void MakeGLContextCurrent (bool b = true);
00146     void SwapBuffer (bool glswap = true);
00147 
00148     // Event methods
00149     void GetSystemEvent (IEvent *evt);
00150     IEvent &GetCurrentEvent();
00151 
00152     bool isWindowMinimized() const
00153     {
00154       return m_is_window_minimized;
00155     }
00156 
00157     void ShowWindow();
00158     void HideWindow();
00159     bool IsWindowVisible ();
00160 
00161     void EnterMaximizeWindow();
00162     void ExitMaximizeWindow();
00163 
00164     HWND GetWindowHandle() const
00165     {
00166       return m_hWnd;
00167     }
00168     HWND GetParentWindowHandle() const
00169     {
00170       return m_ParentWindow;
00171     }
00172     HDC GetWindowHDC() const
00173     {
00174       return _device_context;
00175     }
00176     bool IsChildWindow() const
00177     {
00178       return m_ParentWindow != 0;
00179     }
00180 
00181     // Return true if VSync swap control is available
00182     bool HasVSyncSwapControl() const;
00183     void EnableVSyncSwapControl();
00184     void DisableVSyncSwapControl();
00185 
00186     // m_FrameRate
00187     float GetFrameTime() const;
00188     void ResetFrameTime();
00189 
00190     GraphicsEngine *GetGraphicsEngine() const
00191     {
00192       return m_GraphicsContext;
00193     }
00194     GpuDevice *GetGpuDevice () const
00195     {
00196       return m_DeviceFactory;
00197     }
00198     // Dialog
00199     bool StartOpenFileDialog (FileDialogOption &fdo);
00200     bool StartSaveFileDialog (FileDialogOption &fdo);
00201     bool StartColorDialog (ColorDialogOption &cdo);
00202 
00203 
00204     void GetWindowSize (int &w, int &h);
00205     int GetWindowWidth();
00206     int GetWindowHeight();
00207 
00209 
00213     void ResetWindowSize ();
00214 
00215     bool HasFrameBufferSupport();
00216     void SetWindowCursor (HCURSOR cursor);
00217     HCURSOR GetWindowCursor() const;
00218 
00219     void ProcessForeignWin32Event (HWND hWnd, MSG msg, WPARAM wParam, LPARAM lParam, IEvent *event);
00220     LRESULT ProcessWin32Event (HWND hWnd, t_u32 uMsg, WPARAM wParam, LPARAM lParam);
00221 
00223 
00232     void PauseThreadGraphicsRendering();
00233     bool IsPauseThreadGraphicsRendering() const;
00234 
00235     // Pointer and keyboard grab API
00236     typedef void (*GrabReleaseCallback) (bool replaced, void *user_data);
00237 
00238     bool GrabPointer   (GrabReleaseCallback callback, void *data, bool replace_existing);
00239     bool UngrabPointer (void *data);
00240     bool PointerIsGrabbed ();
00241 
00242     bool GrabKeyboard   (GrabReleaseCallback callback, void *data, bool replace_existing);
00243     bool UngrabKeyboard (void *data);
00244     bool KeyboardIsGrabbed ();
00245 
00246     void * KeyboardGrabData () { return _global_keyboard_grab_data; }
00247     void * PointerGrabData () { return _global_pointer_grab_data; }
00248 
00249   private:
00250     void InitGlobalGrabWindow ();
00251 
00252     bool m_PauseGraphicsRendering;
00253     GLTimer m_Timer;
00254     float m_FrameTime;
00255     GpuDevice *m_DeviceFactory;
00256     GraphicsEngine *m_GraphicsContext;
00257     WindowStyle m_Style;
00258 
00259     HWND                _global_grab_window;
00260 
00261     void               *_global_pointer_grab_data;
00262     bool                _global_pointer_grab_active;
00263     GrabReleaseCallback _global_pointer_grab_callback;
00264 
00265     void               *_global_keyboard_grab_data;
00266     bool                _global_keyboard_grab_active;
00267     GrabReleaseCallback _global_keyboard_grab_callback;
00268 
00269 
00270   public:
00271     ~GraphicsDisplay();
00272     GLEWContext *GetGLEWContext()
00273     {
00274       return &m_GLEWContext;
00275     }
00276     WGLEWContext *GetWGLEWContext()
00277     {
00278       return &m_WGLEWContext;
00279     }
00280 
00281   private:
00282     GraphicsDisplay();
00283     GraphicsDisplay (const GraphicsDisplay &);
00284     // Does not make sense for a singleton. This is a self assignment.
00285     GraphicsDisplay &operator= (const GraphicsDisplay &);
00286 
00287 
00288     GLEWContext m_GLEWContext;
00289     WGLEWContext m_WGLEWContext;
00290     friend class DisplayAccessController;
00291   };
00292 
00293   LRESULT CALLBACK WndProcManager (HWND    hWnd,          // Handle For This Window
00294                                    t_u32   uMsg,           // Message For This Window
00295                                    WPARAM  wParam,         // Additional Message Information
00296                                    LPARAM  lParam);        // Additional Message Information
00297 
00298 }
00299 
00300 #endif //GRAPHICSDISPLAYWIN_H
00301