00001 #ifndef WinGL_H_
00002 #define WinGL_H_
00003
00004 #include"WinApp.h"
00005 #include"ViewManager.h"
00006
00007 namespace FemViewer {
00008 namespace Win {
00009
00010 class WinGL : public CWindowImpl<WinGL, CWindow, CControlWinTraits>
00011 {
00012 public:
00013
00014 WinGL(FemViewer::ViewManager& pVmgr, HWND hWnd);
00015 ~WinGL(void);
00016
00017 void Render(void);
00018 BEGIN_MSG_MAP(WinGL)
00019 MESSAGE_HANDLER(WM_PAINT, OnPaint)
00020 MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLBttnDown)
00021 MESSAGE_HANDLER(WM_LBUTTONUP, OnLBttnUp)
00022 MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRBttnDown)
00023 MESSAGE_HANDLER(WM_RBUTTONUP, OnRBttnUp)
00024 MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
00025 MESSAGE_HANDLER(WM_SIZE, OnSize)
00026 MESSAGE_HANDLER(WM_CHAR, OnChar )
00027 END_MSG_MAP()
00028
00029 private:
00030 enum {
00031 MBTN_DOWN = 0,
00032 MBTN_UP = 1
00033 };
00034
00035 LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
00036 LRESULT OnLBttnDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
00037 LRESULT OnLBttnUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
00038 LRESULT OnRBttnDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
00039 LRESULT OnRBttnUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
00040 LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
00041 LRESULT OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
00042 LRESULT OnChar(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
00043
00044 void InitGL(int width,int height);
00045 void InitData();
00046 bool SetPixelFormat(HDC hdc, int colorBits, int depthBits, int stencilBits);
00047 int FindPixelFormat(HDC hdc, int colorBits, int depthBits, int stencilBits);
00048 bool CreateContext(int colorBits,int depthBits,int stencilBits1);
00049 void DestroyContext();
00050 void ResetView(void) { if(IsWindow()) Invalidate(FALSE); }
00051 void Refresh(BOOL bflag = FALSE) { Invalidate(bflag); }
00052 unsigned GetModifires() const;
00053 HDC m_hDC;
00054 HGLRC m_hRC;
00055 FemViewer::ViewManager& m_Vmgr;
00056 public:
00057 LRESULT OnMenu(UINT nMsg, WPARAM wParam, LPARAM lParam);
00058 };
00059
00060 inline void WinGL::Render(void)
00061 {
00062
00063 Invalidate(TRUE);
00064 }
00065
00066 inline LRESULT WinGL::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
00067 {
00068 nMsg; wParam; lParam; bHandled;
00069
00070 BOOL bRet = wglMakeCurrent( m_hDC, m_hRC );
00071 ATLASSERT(bRet); bRet;
00072 m_Vmgr.DisplayCallback();
00073 ATLASSERT(SwapBuffers( m_hDC ));
00074 ATLASSERT(wglMakeCurrent( NULL, NULL ));
00075 ATLASSERT(ValidateRect( NULL ));
00076 return 0L;
00077 }
00078
00079 inline LRESULT WinGL::OnLBttnDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
00080 {
00081 nMsg; bHandled;
00082
00083 int posx = LOWORD(lParam);
00084 int posy = HIWORD(lParam);
00085 m_Vmgr.MouseButtonCallback(0,MBTN_DOWN,GetModifires(),posx,posy);
00086 SetCapture();
00087 Refresh();
00088 return 0L;
00089 }
00090
00091 inline LRESULT WinGL::OnLBttnUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
00092 {
00093 nMsg; wParam; lParam; bHandled;
00094
00095 UINT nFlags = (UINT) wParam;
00096 int posx = LOWORD(lParam);
00097 int posy = HIWORD(lParam);
00098 int modif = 0;
00099 m_Vmgr.MouseButtonCallback(0,MBTN_UP,GetModifires(),posx,posy);
00100 ReleaseCapture();
00101 Refresh();
00102 return 0L;
00103 }
00104
00105 inline LRESULT WinGL::OnRBttnDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
00106 {
00107 nMsg; bHandled;
00108
00109 int posx = LOWORD(lParam);
00110 int posy = HIWORD(lParam);
00111 BOOL bRet = wglMakeCurrent( m_hDC, m_hRC );
00112 ATLASSERT(bRet); bRet;
00113 m_Vmgr.MouseButtonCallback(1,MBTN_DOWN,GetModifires(),posx,posy);
00114 ATLASSERT(wglMakeCurrent( NULL, NULL ));
00115 SetCapture();
00116 Refresh();
00117 return 0L;
00118 }
00119
00120 inline LRESULT WinGL::OnRBttnUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
00121 {
00122 nMsg; wParam; lParam; bHandled;
00123
00124 int posx = LOWORD(lParam);
00125 int posy = HIWORD(lParam);
00126 m_Vmgr.MouseButtonCallback(1,MBTN_UP,GetModifires(),posx,posy);
00127 ReleaseCapture();
00128 Refresh();
00129 return 0L;
00130 }
00131
00132 inline LRESULT WinGL::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
00133 {
00134 nMsg; bHandled;
00135
00136 int posx = LOWORD(lParam);
00137 int posy = HIWORD(lParam);
00138 m_Vmgr.MouseMotionCallback(posx,posy);
00139 Refresh();
00140 return 0L;
00141 }
00142
00143 inline LRESULT WinGL::OnSize(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
00144 {
00145 nMsg; wParam; bHandled;
00146 int cx = LOWORD(lParam);
00147 int cy = HIWORD(lParam);
00148 ::SendMessage(MainApp::GetInstance()->GetStatusBar(),WM_SIZE,0,0);
00149 if (!m_hWnd || !cy) return 0L;
00150 HDC hDC = ::GetDC(m_hWnd);
00151 ATLASSERT(hDC);
00152 ATLASSERT(m_hRC);
00153 ATLVERIFY(::wglMakeCurrent( hDC, m_hRC ));
00154 m_Vmgr.ReshapeCallback(cx,cy);
00155 ATLVERIFY(ReleaseDC(hDC));
00156 return 0L;
00157 }
00158
00159 inline LRESULT WinGL::OnChar(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
00160 {
00161 nMsg; lParam; bHandled;
00162
00163 switch (wParam)
00164 {
00165 case ' ': ResetView();
00166 }
00167 return 0L;
00168 }
00169
00170 inline LRESULT WinGL::OnMenu(UINT nMsg, WPARAM wParam, LPARAM lParam)
00171 {
00172 nMsg, wParam, lParam;
00173 int wmId = LOWORD(wParam);
00174 m_Vmgr.MenuCallback(wmId);
00175 Refresh();
00176 return 0L;
00177 }
00178
00179 inline unsigned WinGL::GetModifires() const
00180 {
00181 unsigned int modif = 0;
00182 static bool btn_state;
00183 if(GetAsyncKeyState(VK_LSHIFT) & 0x8000)
00184 modif |= 0x1;
00185 if(GetAsyncKeyState(VK_LCONTROL) & 0x8000)
00186 modif |= 0x2;
00187 if(GetAsyncKeyState(VK_RMENU) & 0x8000)
00188 modif |= 0x4;
00189
00190
00191
00192
00193 ;
00194 return modif;
00195 }
00196
00197 }
00198 }
00199
00200 #endif
00201