Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/OpenGL/src/G4OpenGLWin32Viewer.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/OpenGL/src/G4OpenGLWin32Viewer.cc (Version 11.3.0) and /visualization/OpenGL/src/G4OpenGLWin32Viewer.cc (Version 11.2.2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 // 
 26 // G4OpenGLWin32Viewer : Class to provide Wind     26 // G4OpenGLWin32Viewer : Class to provide Windows specific
 27 //                       functionality for Ope     27 //                       functionality for OpenGL
 28 //                                                 28 //
 29 // 27/06/2003 : G.Barrand : implementation (at     29 // 27/06/2003 : G.Barrand : implementation (at last !).
 30                                                    30 
 31 #include "G4OpenGLWin32Viewer.hh"                  31 #include "G4OpenGLWin32Viewer.hh"
 32 #include "G4VViewer.hh"                            32 #include "G4VViewer.hh"
 33 #include "G4VSceneHandler.hh"                      33 #include "G4VSceneHandler.hh"
 34 #include "G4OpenGLSceneHandler.hh"                 34 #include "G4OpenGLSceneHandler.hh"
 35 #include "G4Scene.hh"                              35 #include "G4Scene.hh"
 36                                                    36 
 37 #include "G4ios.hh"                                37 #include "G4ios.hh"
 38 #include "G4VisExtent.hh"                          38 #include "G4VisExtent.hh"
 39 #include "G4LogicalVolume.hh"                      39 #include "G4LogicalVolume.hh"
 40 #include "G4VSolid.hh"                             40 #include "G4VSolid.hh"
 41 #include "G4Point3D.hh"                            41 #include "G4Point3D.hh"
 42 #include "G4Normal3D.hh"                           42 #include "G4Normal3D.hh"
 43                                                    43 
 44 #include "G4SystemOfUnits.hh"                      44 #include "G4SystemOfUnits.hh"
 45                                                    45 
 46 //////////////////////////////////////////////     46 //////////////////////////////////////////////////////////////////////////////
 47 void G4OpenGLWin32Viewer::SetView (                47 void G4OpenGLWin32Viewer::SetView (
 48 )                                                  48 ) 
 49 //////////////////////////////////////////////     49 //////////////////////////////////////////////////////////////////////////////
 50 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     50 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 51 {                                                  51 {
 52   if(!fHDC) return;                                52   if(!fHDC) return;
 53   if(!fHGLRC) return;                              53   if(!fHGLRC) return;
 54   ::wglMakeCurrent(fHDC,fHGLRC);                   54   ::wglMakeCurrent(fHDC,fHGLRC);
 55   G4OpenGLViewer::SetView ();                      55   G4OpenGLViewer::SetView ();  
 56 }                                                  56 }
 57                                                    57 
 58 //////////////////////////////////////////////     58 //////////////////////////////////////////////////////////////////////////////
 59 void G4OpenGLWin32Viewer::ShowView (               59 void G4OpenGLWin32Viewer::ShowView (
 60 )                                                  60 ) 
 61 //////////////////////////////////////////////     61 //////////////////////////////////////////////////////////////////////////////
 62 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     62 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 63 {                                                  63 {
 64   if(!fHDC) return;                                64   if(!fHDC) return;
 65   glFlush ();                                      65   glFlush ();
 66   // Empty the Windows message queue :             66   // Empty the Windows message queue :
 67   MSG event;                                       67   MSG event;
 68   while ( ::PeekMessage(&event, NULL, 0, 0, PM     68   while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
 69     ::TranslateMessage(&event);                    69     ::TranslateMessage(&event);
 70     ::DispatchMessage (&event);                    70     ::DispatchMessage (&event);
 71   }                                                71   }
 72 }                                                  72 }
 73                                                    73 
 74 //////////////////////////////////////////////     74 //////////////////////////////////////////////////////////////////////////////
 75 void G4OpenGLWin32Viewer::GetWin32Connection (     75 void G4OpenGLWin32Viewer::GetWin32Connection (
 76 )                                                  76 ) 
 77 //////////////////////////////////////////////     77 //////////////////////////////////////////////////////////////////////////////
 78 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     78 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 79 {                                                  79 {
 80 }                                                  80 }
 81                                                    81 
 82 //////////////////////////////////////////////     82 //////////////////////////////////////////////////////////////////////////////
 83 void G4OpenGLWin32Viewer::CreateGLWin32Context     83 void G4OpenGLWin32Viewer::CreateGLWin32Context (
 84 )                                                  84 ) 
 85 //////////////////////////////////////////////     85 //////////////////////////////////////////////////////////////////////////////
 86 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     86 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 87 {                                                  87 {
 88 }                                                  88 }
 89                                                    89 
 90 //////////////////////////////////////////////     90 //////////////////////////////////////////////////////////////////////////////
 91 void G4OpenGLWin32Viewer::CreateMainWindow (       91 void G4OpenGLWin32Viewer::CreateMainWindow (
 92 )                                                  92 ) 
 93 //////////////////////////////////////////////     93 //////////////////////////////////////////////////////////////////////////////
 94 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!     94 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
 95 {                                                  95 {
 96   if(fWindow) return; //Done.                      96   if(fWindow) return; //Done.
 97                                                    97 
 98   // Bill Gates stuff...                           98   // Bill Gates stuff...
 99   static const char className[] = "G4OpenGLWin     99   static const char className[] = "G4OpenGLWin32";
100   static G4bool done = false;                     100   static G4bool done = false;
101   if(done==false) {                               101   if(done==false) {
102     WNDCLASS wc;                                  102     WNDCLASS wc;
103     wc.style = CS_HREDRAW | CS_VREDRAW;           103     wc.style = CS_HREDRAW | CS_VREDRAW;
104     wc.lpfnWndProc = (WNDPROC)WindowProc;         104     wc.lpfnWndProc = (WNDPROC)WindowProc;
105     wc.cbClsExtra = 0;                            105     wc.cbClsExtra = 0;
106     wc.cbWndExtra = 0;                            106     wc.cbWndExtra = 0;
107     wc.hInstance = ::GetModuleHandle(NULL);       107     wc.hInstance = ::GetModuleHandle(NULL);
108     wc.hIcon = LoadIcon  (NULL, IDI_APPLICATIO    108     wc.hIcon = LoadIcon  (NULL, IDI_APPLICATION);
109     wc.hCursor = LoadCursor(NULL,IDC_CROSS);      109     wc.hCursor = LoadCursor(NULL,IDC_CROSS);
110     wc.hbrBackground = NULL;                      110     wc.hbrBackground = NULL;
111     wc.lpszMenuName = className;                  111     wc.lpszMenuName = className;
112     wc.lpszClassName = className;                 112     wc.lpszClassName = className;
113     ::RegisterClass(&wc);                         113     ::RegisterClass(&wc);
114     done = true;                                  114     done = true;
115   }                                               115   }  
116                                                   116   
117   ResizeWindow(fVP.GetWindowSizeHintX(),fVP.Ge    117   ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
118                                                   118 
119   G4int x_res=GetSystemMetrics(SM_CXSCREEN);      119   G4int x_res=GetSystemMetrics(SM_CXSCREEN);
120   G4int y_res=GetSystemMetrics(SM_CYSCREEN);      120   G4int y_res=GetSystemMetrics(SM_CYSCREEN);
121                                                   121   
122   //FIXME : NOT tested !                          122   //FIXME : NOT tested !
123   fWindow = ::CreateWindowEx(0, className,fNam    123   fWindow = ::CreateWindowEx(0, className,fName.c_str(),
124          WS_OVERLAPPEDWINDOW,                     124          WS_OVERLAPPEDWINDOW,
125          //WS_CHILD | WS_VISIBLE,                 125          //WS_CHILD | WS_VISIBLE,
126                            //        0,0,         126                            //        0,0,
127                            fVP.GetWindowAbsolu    127                            fVP.GetWindowAbsoluteLocationHintX(x_res),
128                            fVP.GetWindowAbsolu    128                            fVP.GetWindowAbsoluteLocationHintY(y_res),
129          getWinWidth(), getWinHeight(),           129          getWinWidth(), getWinHeight(),
130          NULL, NULL,                              130          NULL, NULL, 
131          ::GetModuleHandle(NULL),                 131          ::GetModuleHandle(NULL),
132          NULL);                                   132          NULL);
133   if(!fWindow) return;                            133   if(!fWindow) return;
134                                                   134 
135   ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LON    135   ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG_PTR(this));
136                                                   136 
137   // initialize OpenGL rendering :                137   // initialize OpenGL rendering :
138   fHDC = ::GetDC(fWindow);                        138   fHDC = ::GetDC(fWindow);
139   if( fHDC && (SetWindowPixelFormat(fHDC)==TRU    139   if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) {
140     fHGLRC = ::wglCreateContext(fHDC);            140     fHGLRC = ::wglCreateContext(fHDC);
141   }                                               141   }
142                                                   142   
143   if(fHDC && fHGLRC) {                            143   if(fHDC && fHGLRC) {
144     ::wglMakeCurrent(fHDC,fHGLRC);                144     ::wglMakeCurrent(fHDC,fHGLRC);
145   }                                               145   }
146                                                   146 
147   //G.Barrand : avoid to indirectly pass in       147   //G.Barrand : avoid to indirectly pass in
148   //              WindowProc/[WM_SIZE,WM_PAINT    148   //              WindowProc/[WM_SIZE,WM_PAINT]/This->DrawView()
149   //            from this method. Else we have    149   //            from this method. Else we have crash.
150   fInCreateWindow = true;                         150   fInCreateWindow = true;
151                                                   151 
152   ::SetForegroundWindow(fWindow);                 152   ::SetForegroundWindow(fWindow);
153   ::ShowWindow(fWindow,SW_SHOWDEFAULT);           153   ::ShowWindow(fWindow,SW_SHOWDEFAULT);
154   ::UpdateWindow(fWindow);                        154   ::UpdateWindow(fWindow);
155   ::DrawMenuBar(fWindow);                         155   ::DrawMenuBar(fWindow);
156                                                   156 
157   fInCreateWindow = false;                        157   fInCreateWindow = false;
158 }                                                 158 }
159                                                   159 
160 //////////////////////////////////////////////    160 //////////////////////////////////////////////////////////////////////////////
161 G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (        161 G4OpenGLWin32Viewer::G4OpenGLWin32Viewer (
162  G4OpenGLSceneHandler& scene                      162  G4OpenGLSceneHandler& scene
163 )                                                 163 )
164 :G4VViewer (scene, -1)                            164 :G4VViewer (scene, -1)
165 ,G4OpenGLViewer (scene)                           165 ,G4OpenGLViewer (scene)
166 ,fMouseHovered(false)                             166 ,fMouseHovered(false)
167 ,fMousePressed(false)                             167 ,fMousePressed(false)
168 ,fMousePressedX(0)                                168 ,fMousePressedX(0)
169 ,fMousePressedY(0)                                169 ,fMousePressedY(0)
170 ,fHDC(0)                                          170 ,fHDC(0)
171 ,fWindow(0)                                       171 ,fWindow(0)
172 ,fHGLRC(0)                                        172 ,fHGLRC(0)
173 ,fInCreateWindow(false)                           173 ,fInCreateWindow(false)
174 //////////////////////////////////////////////    174 //////////////////////////////////////////////////////////////////////////////
175 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    175 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
176 {                                                 176 {
177 }                                                 177 }
178                                                   178 
179 //////////////////////////////////////////////    179 //////////////////////////////////////////////////////////////////////////////
180 G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer (       180 G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer (
181 )                                                 181 ) 
182 //////////////////////////////////////////////    182 //////////////////////////////////////////////////////////////////////////////
183 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    183 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
184 {                                                 184 {
185   // This is the end (Jim Morisson).              185   // This is the end (Jim Morisson).
186   if (fViewId >= 0) {                             186   if (fViewId >= 0) {
187     if(wglGetCurrentContext()!=NULL) wglMakeCu    187     if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL);
188     if(fHGLRC)  {                                 188     if(fHGLRC)  {
189       wglDeleteContext(fHGLRC);                   189       wglDeleteContext(fHGLRC);
190       fHGLRC = NULL;                              190       fHGLRC = NULL;
191     }                                             191     }
192                                                   192     
193     if(fWindow) {                                 193     if(fWindow) {
194       ::SetWindowLongPtr(fWindow,GWLP_USERDATA    194       ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG(NULL));
195       if(fHDC) ::ReleaseDC(fWindow,fHDC);         195       if(fHDC) ::ReleaseDC(fWindow,fHDC);
196       ::DestroyWindow(fWindow);                   196       ::DestroyWindow(fWindow);
197     }                                             197     }
198   }                                               198   }
199 }                                                 199 }
200                                                   200 
201 //////////////////////////////////////////////    201 //////////////////////////////////////////////////////////////////////////////
202 LRESULT CALLBACK G4OpenGLWin32Viewer::WindowPr    202 LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc(
203  HWND aWindow                                     203  HWND aWindow
204 ,UINT aMessage                                    204 ,UINT aMessage
205 ,WPARAM aWParam                                   205 ,WPARAM aWParam
206 ,LPARAM aLParam                                   206 ,LPARAM aLParam
207 )                                                 207 )
208 //////////////////////////////////////////////    208 //////////////////////////////////////////////////////////////////////////////
209 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    209 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
210 {                                                 210 {
211   switch (aMessage) {                             211   switch (aMessage) {
212     case WM_SIZE: {                               212     case WM_SIZE: {
213       //FIXME : have to handle WM_RESIZE          213       //FIXME : have to handle WM_RESIZE
214       // Seems to be done (ovidio.pena AT upm.    214       // Seems to be done (ovidio.pena AT upm.es, 2021/02/23)
215       auto* This = (G4OpenGLWin32Viewer*)         215       auto* This = (G4OpenGLWin32Viewer*)
216                    ::GetWindowLongPtr(aWindow,    216                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
217       if (This) {                                 217       if (This) {
218         This->fWinSize_x = (G4int) LOWORD(aLPa    218         This->fWinSize_x = (G4int) LOWORD(aLParam);
219         This->fWinSize_y = (G4int) HIWORD(aLPa    219         This->fWinSize_y = (G4int) HIWORD(aLParam);
220         if (!This->fInCreateWindow) {             220         if (!This->fInCreateWindow) {
221           This->SetView();                        221           This->SetView();
222           glViewport(0, 0, This->fWinSize_x, T    222           glViewport(0, 0, This->fWinSize_x, This->fWinSize_y);
223           This->DrawView();                       223           This->DrawView();
224         }                                         224         }
225       }                                           225       }
226       return 0;                                   226       return 0;
227     }                                             227     }
228                                                   228 
229     case WM_PAINT: {                              229     case WM_PAINT: {
230       PAINTSTRUCT ps;                             230       PAINTSTRUCT ps;
231       BeginPaint(aWindow, &ps);                   231       BeginPaint(aWindow, &ps);
232       auto* This = (G4OpenGLWin32Viewer*)         232       auto* This = (G4OpenGLWin32Viewer*)
233                    ::GetWindowLongPtr(aWindow,    233                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
234       if (This) {                                 234       if (This) {
235         //FIXME : To have an automatic refresh    235         //FIXME : To have an automatic refresh someone have to redraw here.
236         // Seems to be done (ovidio.pena AT up    236         // Seems to be done (ovidio.pena AT upm.es, 2021/02/23)
237         if(!This->fInCreateWindow) {              237         if(!This->fInCreateWindow) {
238           This->SetView();                        238           This->SetView();
239           This->ClearView();                      239           This->ClearView();
240           This->DrawView();                       240           This->DrawView();
241         }                                         241         }
242       }                                           242       }
243       EndPaint(aWindow, &ps);                     243       EndPaint(aWindow, &ps);
244       return 0;                                   244       return 0;
245     }                                             245     }
246                                                   246 
247     case WM_LBUTTONDOWN: {                        247     case WM_LBUTTONDOWN: {
248       auto* This = (G4OpenGLWin32Viewer*)         248       auto* This = (G4OpenGLWin32Viewer*)
249                    ::GetWindowLongPtr(aWindow,    249                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
250       This->TrackMouse(LOWORD(aLParam), HIWORD    250       This->TrackMouse(LOWORD(aLParam), HIWORD(aLParam));
251       return 0;                                   251       return 0;
252     }                                             252     }
253                                                   253 
254     case WM_RBUTTONDOWN: {                        254     case WM_RBUTTONDOWN: {
255       auto* This = (G4OpenGLWin32Viewer*)         255       auto* This = (G4OpenGLWin32Viewer*)
256                    ::GetWindowLongPtr(aWindow,    256                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
257       This->TrackMouse(LOWORD(aLParam), HIWORD    257       This->TrackMouse(LOWORD(aLParam), HIWORD(aLParam));
258       return 0;                                   258       return 0;
259     }                                             259     }
260                                                   260 
261     case WM_LBUTTONUP: {                          261     case WM_LBUTTONUP: {
262       auto* This = (G4OpenGLWin32Viewer*)         262       auto* This = (G4OpenGLWin32Viewer*)
263                    ::GetWindowLongPtr(aWindow,    263                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
264       This->ReleaseMouse();                       264       This->ReleaseMouse();
265       return 0;                                   265       return 0;
266     }                                             266     }
267                                                   267 
268     case WM_RBUTTONUP: {                          268     case WM_RBUTTONUP: {
269       auto* This = (G4OpenGLWin32Viewer*)         269       auto* This = (G4OpenGLWin32Viewer*)
270                    ::GetWindowLongPtr(aWindow,    270                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
271       This->ReleaseMouse();                       271       This->ReleaseMouse();
272       return 0;                                   272       return 0;
273     }                                             273     }
274                                                   274 
275     case WM_MOUSEHOVER: {                         275     case WM_MOUSEHOVER: {
276       auto* This = (G4OpenGLWin32Viewer*)         276       auto* This = (G4OpenGLWin32Viewer*)
277                    ::GetWindowLongPtr(aWindow,    277                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
278       This->fMouseHovered = true;                 278       This->fMouseHovered = true;
279             return 0;                             279             return 0;
280     }                                             280     }
281                                                   281 
282     case WM_MOUSELEAVE: {                         282     case WM_MOUSELEAVE: {
283       auto* This = (G4OpenGLWin32Viewer*)         283       auto* This = (G4OpenGLWin32Viewer*)
284                    ::GetWindowLongPtr(aWindow,    284                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
285       This->fMouseHovered = false;                285       This->fMouseHovered = false;
286       return 0;                                   286       return 0;
287     }                                             287     }
288                                                   288 
289     case WM_MOUSEMOVE: {                          289     case WM_MOUSEMOVE: {
290       auto* This = (G4OpenGLWin32Viewer*)         290       auto* This = (G4OpenGLWin32Viewer*)
291                    ::GetWindowLongPtr(aWindow,    291                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
292                                                   292 
293       if (!This->fMouseHovered) {                 293       if (!This->fMouseHovered) {
294         // mouse hover/leave tracking             294         // mouse hover/leave tracking
295         TRACKMOUSEEVENT tme;                      295         TRACKMOUSEEVENT tme;
296         tme.cbSize = sizeof(tme);                 296         tme.cbSize = sizeof(tme);
297         tme.dwFlags = TME_HOVER | TME_LEAVE;      297         tme.dwFlags = TME_HOVER | TME_LEAVE;
298         tme.hwndTrack = aWindow;                  298         tme.hwndTrack = aWindow;
299         tme.dwHoverTime = HOVER_DEFAULT;          299         tme.dwHoverTime = HOVER_DEFAULT;
300         ::TrackMouseEvent(&tme);                  300         ::TrackMouseEvent(&tme);
301         This->fMouseHovered = true;               301         This->fMouseHovered = true;
302       }                                           302       }
303                                                   303 
304       if (This->fMousePressed) {                  304       if (This->fMousePressed) {
305         G4int x = (G4int) LOWORD(aLParam);        305         G4int x = (G4int) LOWORD(aLParam);
306         G4int y = (G4int) HIWORD(aLParam);        306         G4int y = (G4int) HIWORD(aLParam);
307         G4int dx = x - This->fMousePressedX;      307         G4int dx = x - This->fMousePressedX;
308         G4int dy = y - This->fMousePressedY;      308         G4int dy = y - This->fMousePressedY;
309         This->fMousePressedX = x;                 309         This->fMousePressedX = x;
310         This->fMousePressedY = y;                 310         This->fMousePressedY = y;
311                                                   311 
312         if (aWParam == MK_LBUTTON) {  // Rotat    312         if (aWParam == MK_LBUTTON) {  // Rotation
313           This->SetRotation(dx, dy);              313           This->SetRotation(dx, dy);
314         }                                         314         }
315                                                   315 
316         if (aWParam == MK_RBUTTON) {  // Shift    316         if (aWParam == MK_RBUTTON) {  // Shift
317           This->SetShift(dx, dy);                 317           This->SetShift(dx, dy);
318         }                                         318         }
319                                                   319 
320         This->SetView();                          320         This->SetView();
321         This->ClearView();                        321         This->ClearView();
322         This->DrawView();                         322         This->DrawView();
323       }                                           323       }
324                                                   324 
325       return 0;                                   325       return 0;
326     }                                             326     }
327                                                   327 
328     case WM_MOUSEWHEEL: {                         328     case WM_MOUSEWHEEL: {
329       auto* This = (G4OpenGLWin32Viewer*)         329       auto* This = (G4OpenGLWin32Viewer*)
330                    ::GetWindowLongPtr(aWindow,    330                    ::GetWindowLongPtr(aWindow, GWLP_USERDATA);
331                                                   331 
332       G4int delta = (short) HIWORD(aWParam);      332       G4int delta = (short) HIWORD(aWParam);
333                                                   333 
334       This->SetZoom(delta);                       334       This->SetZoom(delta);
335                                                   335 
336       This->SetView();                            336       This->SetView();
337       This->ClearView();                          337       This->ClearView();
338       This->DrawView();                           338       This->DrawView();
339       return 0;                                   339       return 0;
340     }                                             340     }
341                                                   341 
342     default:                                      342     default:
343       return DefWindowProc(aWindow, aMessage,     343       return DefWindowProc(aWindow, aMessage, aWParam, aLParam);
344   }                                               344   }
345 //  return DefWindowProc(aWindow,aMessage,aWPa    345 //  return DefWindowProc(aWindow,aMessage,aWParam,aLParam);
346 }                                                 346 }
347                                                   347 
348 //////////////////////////////////////////////    348 //////////////////////////////////////////////////////////////////////////////
349 G4bool G4OpenGLWin32Viewer::SetWindowPixelForm    349 G4bool G4OpenGLWin32Viewer::SetWindowPixelFormat(
350  HDC aHdc                                         350  HDC aHdc
351 )                                                 351 )
352 //////////////////////////////////////////////    352 //////////////////////////////////////////////////////////////////////////////
353 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    353 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
354 {                                                 354 {
355   // The ungessable...                            355   // The ungessable...
356                                                   356 
357   PIXELFORMATDESCRIPTOR pfd;                      357   PIXELFORMATDESCRIPTOR pfd;
358   pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);      358   pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
359   pfd.nVersion = 1;                               359   pfd.nVersion = 1;
360   pfd.dwFlags =                                   360   pfd.dwFlags = 
361     PFD_DRAW_TO_WINDOW |                          361     PFD_DRAW_TO_WINDOW | 
362     PFD_SUPPORT_OPENGL |                          362     PFD_SUPPORT_OPENGL | 
363     PFD_DOUBLEBUFFER |                            363     PFD_DOUBLEBUFFER | 
364     PFD_STEREO_DONTCARE;                          364     PFD_STEREO_DONTCARE;  
365   pfd.iPixelType = PFD_TYPE_RGBA;                 365   pfd.iPixelType = PFD_TYPE_RGBA;
366   pfd.cColorBits = 32;                            366   pfd.cColorBits = 32;
367   pfd.cRedBits = 8;                               367   pfd.cRedBits = 8;
368   pfd.cRedShift = 16;                             368   pfd.cRedShift = 16;
369   pfd.cGreenBits = 8;                             369   pfd.cGreenBits = 8;
370   pfd.cGreenShift = 8;                            370   pfd.cGreenShift = 8;
371   pfd.cBlueBits = 8;                              371   pfd.cBlueBits = 8;
372   pfd.cBlueShift = 0;                             372   pfd.cBlueShift = 0;
373   pfd.cAlphaBits = 0;                             373   pfd.cAlphaBits = 0;
374   pfd.cAlphaShift = 0;                            374   pfd.cAlphaShift = 0;
375   pfd.cAccumBits = 64;                            375   pfd.cAccumBits = 64;  
376   pfd.cAccumRedBits = 16;                         376   pfd.cAccumRedBits = 16;
377   pfd.cAccumGreenBits = 16;                       377   pfd.cAccumGreenBits = 16;
378   pfd.cAccumBlueBits = 16;                        378   pfd.cAccumBlueBits = 16;
379   pfd.cAccumAlphaBits = 0;                        379   pfd.cAccumAlphaBits = 0;
380   pfd.cDepthBits = 32;                            380   pfd.cDepthBits = 32;
381   pfd.cStencilBits = 8;                           381   pfd.cStencilBits = 8;
382   pfd.cAuxBuffers = 0;                            382   pfd.cAuxBuffers = 0;
383   pfd.iLayerType = PFD_MAIN_PLANE;                383   pfd.iLayerType = PFD_MAIN_PLANE;
384   pfd.bReserved = 0;                              384   pfd.bReserved = 0;
385   pfd.dwLayerMask = 0;                            385   pfd.dwLayerMask = 0;
386   pfd.dwVisibleMask = 0;                          386   pfd.dwVisibleMask = 0;
387   pfd.dwDamageMask = 0;                           387   pfd.dwDamageMask = 0;
388                                                   388   
389   G4int pixelIndex = ::ChoosePixelFormat(aHdc,    389   G4int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd);
390   if (pixelIndex==0) {                            390   if (pixelIndex==0) {
391     pixelIndex = 1;                               391     pixelIndex = 1; 
392     if (::DescribePixelFormat(aHdc,               392     if (::DescribePixelFormat(aHdc, 
393             pixelIndex,                           393             pixelIndex, 
394             sizeof(PIXELFORMATDESCRIPTOR),        394             sizeof(PIXELFORMATDESCRIPTOR), 
395             &pfd)==0) {                           395             &pfd)==0) {
396       return false;                               396       return false;
397     }                                             397     }
398   }                                               398   }
399   if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==    399   if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false;
400   return true;                                    400   return true;
401 }                                                 401 }
402                                                   402 
403 //////////////////////////////////////////////    403 //////////////////////////////////////////////////////////////////////////////
404 void G4OpenGLWin32Viewer::TrackMouse(             404 void G4OpenGLWin32Viewer::TrackMouse(
405  G4int x                                          405  G4int x
406 ,G4int y                                          406 ,G4int y
407 )                                                 407 )
408 //////////////////////////////////////////////    408 //////////////////////////////////////////////////////////////////////////////
409 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    409 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
410 {                                                 410 {
411   fMousePressed = true;                           411   fMousePressed = true;
412   fMousePressedX = x;                             412   fMousePressedX = x;
413   fMousePressedY = y;                             413   fMousePressedY = y;
414 }                                                 414 }
415                                                   415 
416 //////////////////////////////////////////////    416 //////////////////////////////////////////////////////////////////////////////
417 void G4OpenGLWin32Viewer::ReleaseMouse(           417 void G4OpenGLWin32Viewer::ReleaseMouse(
418 )                                                 418 )
419 //////////////////////////////////////////////    419 //////////////////////////////////////////////////////////////////////////////
420 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    420 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
421 {                                                 421 {
422   fMousePressed = false;                          422   fMousePressed = false;
423   fMousePressedX = 0;                             423   fMousePressedX = 0;
424   fMousePressedY = 0;                             424   fMousePressedY = 0;
425 }                                                 425 }
426                                                   426 
427 //////////////////////////////////////////////    427 //////////////////////////////////////////////////////////////////////////////
428 void G4OpenGLWin32Viewer::SetShift(               428 void G4OpenGLWin32Viewer::SetShift(
429  G4int dx                                         429  G4int dx
430 ,G4int dy                                         430 ,G4int dy
431 )                                                 431 )
432 //////////////////////////////////////////////    432 //////////////////////////////////////////////////////////////////////////////
433 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    433 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
434 {                                                 434 {
435   const G4double sceneRadius = GetSceneHandler    435   const G4double sceneRadius = GetSceneHandler()->GetScene()
436                              ->GetExtent().Get    436                              ->GetExtent().GetExtentRadius();
437   const G4double scale = 300;  // Roughly pixe    437   const G4double scale = 300;  // Roughly pixels per window, empirically chosen
438   const G4double dxScene = dx*sceneRadius/scal    438   const G4double dxScene = dx*sceneRadius/scale;
439   const G4double dyScene = dy*sceneRadius/scal    439   const G4double dyScene = dy*sceneRadius/scale;
440   fVP.IncrementPan(-dxScene,dyScene);             440   fVP.IncrementPan(-dxScene,dyScene);
441 }                                                 441 }
442                                                   442 
443 //////////////////////////////////////////////    443 //////////////////////////////////////////////////////////////////////////////
444 void G4OpenGLWin32Viewer::SetRotation(            444 void G4OpenGLWin32Viewer::SetRotation(
445  G4int dx                                         445  G4int dx
446 ,G4int dy                                         446 ,G4int dy
447 )                                                 447 )
448 //////////////////////////////////////////////    448 //////////////////////////////////////////////////////////////////////////////
449 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    449 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
450 {                                                 450 {
451   // Simple ad-hoc algorithms (borrowed from G    451   // Simple ad-hoc algorithms (borrowed from G4Qt3DViewer)
452   const G4Vector3D& x_prime = fVP.GetViewpoint    452   const G4Vector3D& x_prime = fVP.GetViewpointDirection()
453                               .cross(fVP.GetUp    453                               .cross(fVP.GetUpVector());
454   const G4Vector3D& y_prime = x_prime.cross(fV    454   const G4Vector3D& y_prime = x_prime.cross(fVP.GetViewpointDirection());
455   const G4double scale = 200;  // Roughly pixe    455   const G4double scale = 200;  // Roughly pixels per window, empirically chosen
456   G4Vector3D newViewpointDirection = fVP.GetVi    456   G4Vector3D newViewpointDirection = fVP.GetViewpointDirection();
457   newViewpointDirection += dx*x_prime/scale;      457   newViewpointDirection += dx*x_prime/scale;
458   newViewpointDirection += dy*y_prime/scale;      458   newViewpointDirection += dy*y_prime/scale;
459   fVP.SetViewpointDirection(newViewpointDirect    459   fVP.SetViewpointDirection(newViewpointDirection.unit());
460                                                   460 
461   if (fVP.GetRotationStyle() == G4ViewParamete    461   if (fVP.GetRotationStyle() == G4ViewParameters::freeRotation) {
462       G4Vector3D newUpVector = fVP.GetUpVector    462       G4Vector3D newUpVector = fVP.GetUpVector();
463       newUpVector += dx*x_prime/scale;            463       newUpVector += dx*x_prime/scale;
464       newUpVector += dy*y_prime/scale;            464       newUpVector += dy*y_prime/scale;
465       fVP.SetUpVector(newUpVector.unit());        465       fVP.SetUpVector(newUpVector.unit());
466   }                                               466   }
467 }                                                 467 }
468                                                   468 
469 //////////////////////////////////////////////    469 //////////////////////////////////////////////////////////////////////////////
470 void G4OpenGLWin32Viewer::SetZoom(                470 void G4OpenGLWin32Viewer::SetZoom(
471  G4int delta                                      471  G4int delta
472 )                                                 472 )
473 //////////////////////////////////////////////    473 //////////////////////////////////////////////////////////////////////////////
474 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!    474 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
475 {                                                 475 {
476     if (fVP.GetFieldHalfAngle() == 0.) {  // O    476     if (fVP.GetFieldHalfAngle() == 0.) {  // Orthographic projection
477         const G4double scale = 500;  // Empiri    477         const G4double scale = 500;  // Empirically chosen
478         fVP.MultiplyZoomFactor(1. + delta/scal    478         fVP.MultiplyZoomFactor(1. + delta/scale);
479     } else {                              // P    479     } else {                              // Perspective projection
480         const G4double scale = fVP.GetFieldHal    480         const G4double scale = fVP.GetFieldHalfAngle()/(10.*deg);  // Empirical
481         fVP.SetDolly(fVP.GetDolly() + delta/sc    481         fVP.SetDolly(fVP.GetDolly() + delta/scale);
482     }                                             482     }
483 }                                                 483 }
484                                                   484 
485                                                   485