source: trunk/source/visualization/OpenGL/src/G4OpenGLXmWindowHandlingCallbacks.cc@ 1074

Last change on this file since 1074 was 1049, checked in by garnier, 17 years ago

update pas dans CVS

  • Property svn:mime-type set to text/cpp
File size: 7.8 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4OpenGLXmWindowHandlingCallbacks.cc,v 1.11 2009/05/13 10:28:00 lgarnier Exp $
28// GEANT4 tag $Name: $
29//
30//
31// Andrew Walkden 16th June 1997
32// G4OpenGLXmWindowHandlingCallbacks : Callback functions for
33// (Motif) widgets to use.
34// in handling (Xm) windows
35
36#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
37//#define RESIZE_TEST
38#include "G4OpenGLXmViewer.hh"
39
40
41
42// L. Garnier 20 May 2009
43// Each resize event send 2-3-4 expose events. Sequence on MacOsX 10.5 is :
44// - Expose(s) callback for pixels top/left from resize button
45// - Resize callback
46// - Expose for main part of content
47// - Expose(s) for new part of content
48//
49// BUT we want to redraw things only ONE time.
50// First expose is send with size=="before resize" size and x,y !=0
51// and x+dw!=w || y+dh !=h
52void G4OpenGLXmViewer::resize_callback (Widget w,
53 XtPointer clientData,
54 XtPointer callData)
55{
56#ifdef G4DEBUG_VIS_OGL
57 printf("G4OpenGLXmViewer::resize_callback \n");
58#endif
59 XmDrawingAreaCallbackStruct *data = (XmDrawingAreaCallbackStruct *)callData;
60
61 XEvent event;
62
63 // flush others resize events
64#ifdef G4DEBUG_VIS_OGL
65 while (XCheckWindowEvent(XtDisplay(w), data->window,
66 ResizeRedirectMask, &event)) {
67 printf("G4OpenGLXmViewer::resize_callback ------ next RESIZE ! %d\n");
68 }
69#endif
70#ifdef RESIZE_TEST
71 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
72 Dimension width, height;
73
74 XtVaGetValues (w,
75 XmNwidth, &width,
76 XmNheight, &height,
77 NULL);
78 pView->ResizeWindow(width,height);
79#endif
80}
81
82
83void G4OpenGLXmViewer::activate_callback (Widget w,
84 XtPointer clientData,
85 XtPointer callData)
86{
87#ifdef G4DEBUG_VIS_OGL
88 printf("G4OpenGLXmViewer::activate_callback \n");
89#endif
90}
91
92void G4OpenGLXmViewer::expose_callback (Widget w,
93 XtPointer clientData,
94 XtPointer callData)
95{
96 /* ensure last expose event in sequence */
97#ifdef G4DEBUG_VIS_OGL
98 printf("G4OpenGLXmViewer::expose_callback ?\n");
99#endif
100 XmDrawingAreaCallbackStruct *data = (XmDrawingAreaCallbackStruct *)callData;
101
102 XEvent event;
103
104 Dimension width, height;
105 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData;
106
107 XtVaGetValues (w,
108 XmNwidth, &width,
109 XmNheight, &height,
110 NULL);
111
112 XSetWindowAttributes xswa;
113 xswa.bit_gravity = ForgetGravity ;
114 XChangeWindowAttributes(XtDisplay(w), XtWindow(w),
115 CWBitGravity, &xswa);
116
117 // look for next
118 // while (XCheckTypedWindowEvent(XtDisplay(w), XtWindow(w), ResizeRequest, &event)) {
119 // printf("G4OpenGLXmViewer::expose_callback --- event type :%d\n",event.type);
120 // printf("G4OpenGLXmViewer::expose_callback --- resize %d\n",event.type);
121 // }
122
123 // Several expose events are send for each area to be redraw.
124 // Because we want to optimise redrawing, we only need to redraw once.
125 if (((XExposeEvent *) data->event)->count != 0) {
126#ifdef G4DEBUG_VIS_OGL
127 printf("G4OpenGLXmViewer::expose_callback NOOOOO %d %d type:%d number:%d send:%d x:%d y:%d w:%d h:%d c:%d\n",width,height,
128 ((XExposeEvent *) data->event)->type,
129 ((XExposeEvent *) data->event)->serial,
130 ((XExposeEvent *) data->event)->send_event,
131 ((XExposeEvent *) data->event)->x,
132 ((XExposeEvent *) data->event)->y,
133 ((XExposeEvent *) data->event)->width,
134 ((XExposeEvent *) data->event)->height,
135 ((XExposeEvent *) data->event)->count);
136
137
138#endif
139 return;
140 }
141#ifdef G4DEBUG_VIS_OGL
142 printf("G4OpenGLXmViewer::expose_callback Should redraw %d %d type:%d number:%d send:%d x:%d y:%d w:%d h:%d c:%d\n",width,height,
143 ((XExposeEvent *) data->event)->type,
144 ((XExposeEvent *) data->event)->serial,
145 ((XExposeEvent *) data->event)->send_event,
146 ((XExposeEvent *) data->event)->x,
147 ((XExposeEvent *) data->event)->y,
148 ((XExposeEvent *) data->event)->width,
149 ((XExposeEvent *) data->event)->height,
150 ((XExposeEvent *) data->event)->count);
151#endif
152
153#ifdef G4DEBUG_VIS_OGL
154 while (XCheckMaskEvent(XtDisplay(w), ResizeRedirectMask, &event)) {
155 // printf("G4OpenGLXmViewer::expose_callback ------ next EXPOSE ! %d\n");
156 // }
157 // while (XCheckWindowEvent(XtDisplay(w), data->window,
158 // ResizeRedirectMask, &event)) {
159 printf("G4OpenGLXmViewer::expose_callback ------ next RESIZE ! \n");
160 }
161#endif
162
163#ifdef RESIZE_TEST
164 glXMakeCurrent (pView->dpy, XtWindow(pView->glxarea), pView->cx);
165#ifdef G4DEBUG_VIS_OGL
166 G4cout << "G4OpenGLXmViewer::expose_callback" << G4endl;
167 printf("G4OpenGLXmViewer::expose_callback Call SetView()\n");
168#endif
169 pView->SetView ();
170#ifdef G4DEBUG_VIS_OGL
171 printf("G4OpenGLXmViewer::expose_callback Call SetView() END \n");
172 printf("G4OpenGLXmViewer::expose_callback Call ClearView() \n");
173#endif
174 pView->ClearView ();
175#ifdef G4DEBUG_VIS_OGL
176 printf("G4OpenGLXmViewer::expose_callback Call ClearView() END \n");
177 printf("G4OpenGLXmViewer::expose_callback Call DrawView() \n");
178#endif
179 pView->DrawView ();
180#ifdef G4DEBUG_VIS_OGL
181 printf("G4OpenGLXmViewer::expose_callback Call DrawView() END \n");
182 G4cout << "G4OpenGLXmViewer::expose_callback END" << G4endl;
183#endif
184#endif
185 return;
186
187
188}
189
190void G4OpenGLXmViewer::print_callback (Widget,
191 XtPointer clientData,
192 XtPointer)
193{
194 G4OpenGLXViewer* pView = (G4OpenGLXmViewer*) clientData;
195 pView->printEPS();
196}
197
198void G4OpenGLXmViewer::set_print_colour_callback (Widget w,
199 XtPointer clientData,
200 XtPointer)
201{
202 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
203
204 G4int choice = get_int_userData (w);
205
206 pView->fPrintColour=(G4bool)choice;
207 G4cout << "Print colour set to " << pView->fPrintColour;
208
209}
210
211void G4OpenGLXmViewer::set_print_style_callback (Widget w,
212 XtPointer clientData,
213 XtPointer)
214{
215 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*)clientData;
216
217 G4int choice = get_int_userData (w);
218
219 pView->fVectoredPs=(G4bool)choice;
220 G4cout << "`Produce vectored PostScript ?' set to : " << pView->fPrintColour;
221
222}
223
224#endif
Note: See TracBrowser for help on using the repository browser.