| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2.1 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* Further, this software is distributed without any warranty that it is |
| 16 |
* free of the rightful claim of any third person regarding infringement |
| 17 |
* or the like. Any license provided herein, whether implied or |
| 18 |
* otherwise, applies only to this software file. Patent licenses, if |
| 19 |
* any, provided herein do not apply to combinations of this program with |
| 20 |
* other software, or any other product whatsoever. |
| 21 |
* |
| 22 |
* You should have received a copy of the GNU Lesser General Public |
| 23 |
* License along with this library; if not, write to the Free Software |
| 24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 |
* |
| 26 |
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 |
* Mountain View, CA 94043, or: |
| 28 |
* |
| 29 |
* http://www.sgi.com |
| 30 |
* |
| 31 |
* For further information regarding this notice, see: |
| 32 |
* |
| 33 |
* http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 |
* |
| 35 |
*/ |
| 36 |
|
| 37 |
/* |
| 38 |
* Copyright (C) 1990-93 Silicon Graphics, Inc. |
| 39 |
* |
| 40 |
_______________________________________________________________________ |
| 41 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 |
| |
| 43 |
| $Revision: 1.5 $ |
| 44 |
| |
| 45 |
| Classes: |
| 46 |
| SoXtRenderArea |
| 47 |
| |
| 48 |
| Author(s): David Mott, Alain Dumesny |
| 49 |
| |
| 50 |
______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 |
_______________________________________________________________________ |
| 52 |
*/ |
| 53 |
|
| 54 |
|
| 55 |
#include <Inventor/SoDB.h> |
| 56 |
#include <Inventor/SbLinear.h> |
| 57 |
#include <Inventor/errors/SoDebugError.h> |
| 58 |
#include <Inventor/elements/SoWindowElement.h> |
| 59 |
#include <Inventor/nodes/SoNode.h> |
| 60 |
#include <Inventor/nodes/SoSelection.h> |
| 61 |
#include <Inventor/nodes/SoLocateHighlight.h> |
| 62 |
#include <Inventor/actions/SoHandleEventAction.h> |
| 63 |
#include <Inventor/Xt/SoXtResource.h> |
| 64 |
#include <Inventor/Xt/SoXtRenderArea.h> |
| 65 |
#include <Inventor/Xt/devices/SoXtKeyboard.h> |
| 66 |
#include <Inventor/Xt/devices/SoXtMouse.h> |
| 67 |
#include <GL/gl.h> |
| 68 |
#include <GL/glx.h> |
| 69 |
#include <cstdlib> |
| 70 |
|
| 71 |
#include <X11/Intrinsic.h> |
| 72 |
#include <X11/StringDefs.h> |
| 73 |
|
| 74 |
#include <Xm/Xm.h> |
| 75 |
|
| 76 |
static char *thisClassName = "SoXtRenderArea"; |
| 77 |
|
| 78 |
|
| 79 |
//////////////////////////////////////////////////////////////////////// |
| 80 |
// |
| 81 |
// Public constructor - build the widget right now |
| 82 |
// |
| 83 |
SoXtRenderArea::SoXtRenderArea( |
| 84 |
Widget parent, |
| 85 |
const char *name, |
| 86 |
SbBool buildInsideParent, |
| 87 |
SbBool getMouseInput, |
| 88 |
SbBool getKeyboardInput) |
| 89 |
: SoXtGLWidget( |
| 90 |
parent, |
| 91 |
name, |
| 92 |
buildInsideParent, |
| 93 |
SO_GLX_RGB | SO_GLX_DOUBLE | SO_GLX_ZBUFFER | SO_GLX_OVERLAY, |
| 94 |
FALSE) // tell GLWidget not to build just yet |
| 95 |
// |
| 96 |
//////////////////////////////////////////////////////////////////////// |
| 97 |
{ |
| 98 |
// In this case, render area is what the app wants, so buildNow = TRUE |
| 99 |
constructorCommon(getMouseInput, getKeyboardInput, TRUE); |
| 100 |
} |
| 101 |
|
| 102 |
//////////////////////////////////////////////////////////////////////// |
| 103 |
// |
| 104 |
// SoEXTENDER constructor - the subclass tells us whether to build or not |
| 105 |
// |
| 106 |
SoXtRenderArea::SoXtRenderArea( |
| 107 |
Widget parent, |
| 108 |
const char *name, |
| 109 |
SbBool buildInsideParent, |
| 110 |
SbBool getMouseInput, |
| 111 |
SbBool getKeyboardInput, |
| 112 |
SbBool buildNow) |
| 113 |
: SoXtGLWidget( |
| 114 |
parent, |
| 115 |
name, |
| 116 |
buildInsideParent, |
| 117 |
SO_GLX_RGB | SO_GLX_DOUBLE | SO_GLX_ZBUFFER | SO_GLX_OVERLAY, |
| 118 |
FALSE) // tell GLWidget not to build just yet |
| 119 |
// |
| 120 |
//////////////////////////////////////////////////////////////////////// |
| 121 |
{ |
| 122 |
// In this case, render area may be what the app wants, |
| 123 |
// or it may want a subclass of render area. Pass along buildNow |
| 124 |
// as it was passed to us. |
| 125 |
constructorCommon(getMouseInput, getKeyboardInput, buildNow); |
| 126 |
} |
| 127 |
|
| 128 |
//////////////////////////////////////////////////////////////////////// |
| 129 |
// |
| 130 |
// Called by the constructors |
| 131 |
// |
| 132 |
// private |
| 133 |
// |
| 134 |
void |
| 135 |
SoXtRenderArea::constructorCommon( |
| 136 |
SbBool getMouseInput, |
| 137 |
SbBool getKeyboardInput, |
| 138 |
SbBool buildNow) |
| 139 |
// |
| 140 |
//////////////////////////////////////////////////////////////////////// |
| 141 |
{ |
| 142 |
addVisibilityChangeCallback(visibilityChangeCB, this); |
| 143 |
setClassName(thisClassName); |
| 144 |
firstEvent = TRUE; |
| 145 |
|
| 146 |
// set up the device list |
| 147 |
deviceList = new SbPList; |
| 148 |
|
| 149 |
// default devices |
| 150 |
if (getMouseInput) { |
| 151 |
mouseDevice = new SoXtMouse(); |
| 152 |
deviceList->append(mouseDevice); |
| 153 |
} |
| 154 |
else mouseDevice = NULL; |
| 155 |
|
| 156 |
if (getKeyboardInput) { |
| 157 |
keybdDevice = new SoXtKeyboard(); |
| 158 |
deviceList->append(keybdDevice); |
| 159 |
} |
| 160 |
else keybdDevice = NULL; |
| 161 |
|
| 162 |
// local vars |
| 163 |
clearFirst = TRUE; |
| 164 |
clearOverlayFirst = TRUE; |
| 165 |
autoRedraw = TRUE; |
| 166 |
selection = overlaySelection = NULL; |
| 167 |
deviceWidget = NULL; |
| 168 |
|
| 169 |
setSize(SbVec2s(400, 400)); // default size |
| 170 |
setBorder(TRUE); |
| 171 |
|
| 172 |
// inventor specific variables |
| 173 |
appEventHandler = NULL; |
| 174 |
|
| 175 |
// the scene manager can be supplied by a subclass., |
| 176 |
sceneMgr = new SoSceneManager(); |
| 177 |
sceneMgr->setRenderCallback(renderCB, this); |
| 178 |
|
| 179 |
// the overlay scene manager is supplied right here. |
| 180 |
|
| 181 |
overlaySceneMgr = new SoSceneManager(); |
| 182 |
overlaySceneMgr->setRenderCallback(renderOverlayCB, this); |
| 183 |
|
| 184 |
// color map variables |
| 185 |
mapColors = overlayMapColors = NULL; |
| 186 |
mapColorNum = overlayMapColorNum = 0; |
| 187 |
|
| 188 |
// Build the widget tree, and let SoXtComponent know about our base widget. |
| 189 |
if (buildNow) |
| 190 |
setBaseWidget(buildWidget(getParentWidget())); |
| 191 |
} |
| 192 |
|
| 193 |
//////////////////////////////////////////////////////////////////////// |
| 194 |
// |
| 195 |
// Destructor |
| 196 |
// |
| 197 |
SoXtRenderArea::~SoXtRenderArea() |
| 198 |
// |
| 199 |
//////////////////////////////////////////////////////////////////////// |
| 200 |
{ |
| 201 |
// Remove our callback from old selection node |
| 202 |
if (selection != NULL) { |
| 203 |
selection->removeChangeCallback(SoXtRenderArea::selectionChangeCB, this); |
| 204 |
|
| 205 |
// Unref the old selection node |
| 206 |
selection->unref(); |
| 207 |
} |
| 208 |
|
| 209 |
unregisterWidget(getGlxMgrWidget()); |
| 210 |
|
| 211 |
if (mapColors != NULL) |
| 212 |
free(mapColors); |
| 213 |
if (overlayMapColors != NULL) |
| 214 |
free(overlayMapColors); |
| 215 |
|
| 216 |
if (mouseDevice != NULL) delete mouseDevice; |
| 217 |
if (keybdDevice != NULL) delete keybdDevice; |
| 218 |
delete sceneMgr; |
| 219 |
delete overlaySceneMgr; |
| 220 |
delete deviceList; |
| 221 |
//??? delete the mouse and keybd if we created them! |
| 222 |
} |
| 223 |
|
| 224 |
//////////////////////////////////////////////////////////////////////// |
| 225 |
// |
| 226 |
// Description: |
| 227 |
// Make the new user supplied scene graph the rendering root. |
| 228 |
// |
| 229 |
// use: virtual public |
| 230 |
// |
| 231 |
void |
| 232 |
SoXtRenderArea::setSceneGraph(SoNode *newScene) |
| 233 |
// |
| 234 |
//////////////////////////////////////////////////////////////////////// |
| 235 |
{ |
| 236 |
// Deactivate while we change the scene so that our sensors |
| 237 |
// get unhooked before the data changes beneath us. |
| 238 |
sceneMgr->deactivate(); |
| 239 |
|
| 240 |
sceneMgr->setSceneGraph(newScene); |
| 241 |
|
| 242 |
// draw new scene graphs to the front buffer by default since |
| 243 |
// the scene will be different (we might has well see something |
| 244 |
// happening for the first redraw). |
| 245 |
if (isDrawToFrontBufferEnable()) |
| 246 |
drawToFrontBuffer = TRUE; |
| 247 |
|
| 248 |
// we activate only if we are visible. |
| 249 |
// after all, if we're not on screen, the visibility change |
| 250 |
// callback will invoke activate() once we are on screen. |
| 251 |
if (isVisible() && autoRedraw) { |
| 252 |
sceneMgr->activate(); |
| 253 |
sceneMgr->scheduleRedraw(); |
| 254 |
} |
| 255 |
} |
| 256 |
|
| 257 |
//////////////////////////////////////////////////////////////////////// |
| 258 |
// |
| 259 |
// Description: |
| 260 |
// sets the overlay plane scene graph. |
| 261 |
// |
| 262 |
// use: public |
| 263 |
// |
| 264 |
void |
| 265 |
SoXtRenderArea::setOverlaySceneGraph(SoNode *newScene) |
| 266 |
// |
| 267 |
//////////////////////////////////////////////////////////////////////// |
| 268 |
{ |
| 269 |
if (! getOverlayWidget()) |
| 270 |
return; |
| 271 |
|
| 272 |
// Deactivate while we change the scene so that our sensors |
| 273 |
// get unhooked before the data changes beneath us. |
| 274 |
overlaySceneMgr->deactivate(); |
| 275 |
|
| 276 |
overlaySceneMgr->setSceneGraph(newScene); |
| 277 |
|
| 278 |
// we activate only if we are visible. |
| 279 |
// after all, if we're not on screen, the visibility change |
| 280 |
// callback will invoke activate() once we are on screen. |
| 281 |
if (isVisible() && autoRedraw) { |
| 282 |
overlaySceneMgr->activate(); |
| 283 |
overlaySceneMgr->scheduleRedraw(); |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
//////////////////////////////////////////////////////////////////////// |
| 288 |
// |
| 289 |
// Description: |
| 290 |
// Return the rendering root. |
| 291 |
// |
| 292 |
// use: public, virtual |
| 293 |
// |
| 294 |
SoNode * |
| 295 |
SoXtRenderArea::getSceneGraph() |
| 296 |
// |
| 297 |
//////////////////////////////////////////////////////////////////////// |
| 298 |
{ |
| 299 |
return sceneMgr->getSceneGraph(); |
| 300 |
} |
| 301 |
|
| 302 |
//////////////////////////////////////////////////////////////////////// |
| 303 |
// |
| 304 |
// Description: |
| 305 |
// Loads the color map with the given colors. |
| 306 |
// |
| 307 |
// use: public |
| 308 |
// |
| 309 |
void |
| 310 |
SoXtRenderArea::setColorMap(int startIndex, int num, const SbColor *colors) |
| 311 |
// |
| 312 |
//////////////////////////////////////////////////////////////////////// |
| 313 |
{ |
| 314 |
// save those colors for future uses (if the widget hasn't been |
| 315 |
// built yet, or next time it gets built) |
| 316 |
if (mapColors != NULL) |
| 317 |
free(mapColors); |
| 318 |
mapColors = (XColor *) malloc(sizeof(XColor) * num); |
| 319 |
mapColorNum = num; |
| 320 |
XColor *xcol = mapColors; |
| 321 |
for (int i=0; i<num; i++, xcol++) { |
| 322 |
xcol->red = (unsigned short) (colors[i][0] * 65535); |
| 323 |
xcol->green = (unsigned short) (colors[i][1] * 65535); |
| 324 |
xcol->blue = (unsigned short) (colors[i][2] * 65535); |
| 325 |
xcol->flags = DoRed|DoGreen|DoBlue; |
| 326 |
xcol->pixel = startIndex + i; |
| 327 |
} |
| 328 |
|
| 329 |
// now load those colors into the color map |
| 330 |
if (colorMap != 0) |
| 331 |
XStoreColors(getDisplay(), colorMap, mapColors, mapColorNum); |
| 332 |
} |
| 333 |
|
| 334 |
//////////////////////////////////////////////////////////////////////// |
| 335 |
// |
| 336 |
// Description: |
| 337 |
// Loads the overlay color map with the given colors. |
| 338 |
// |
| 339 |
// use: public |
| 340 |
// |
| 341 |
void |
| 342 |
SoXtRenderArea::setOverlayColorMap(int startIndex, int num, const SbColor *colors) |
| 343 |
// |
| 344 |
//////////////////////////////////////////////////////////////////////// |
| 345 |
{ |
| 346 |
if (! getOverlayWidget()) |
| 347 |
return; |
| 348 |
|
| 349 |
// save those colors for future uses (if the widget hasn't been |
| 350 |
// built yet, or next time it gets built) |
| 351 |
if (overlayMapColors != NULL) |
| 352 |
free(overlayMapColors); |
| 353 |
overlayMapColors = (XColor *) malloc(sizeof(XColor) * num); |
| 354 |
overlayMapColorNum = num; |
| 355 |
XColor *xcol = overlayMapColors; |
| 356 |
for (int i=0; i<num; i++, xcol++) { |
| 357 |
xcol->red = (unsigned short) (colors[i][0] * 65535); |
| 358 |
xcol->green = (unsigned short) (colors[i][1] * 65535); |
| 359 |
xcol->blue = (unsigned short) (colors[i][2] * 65535); |
| 360 |
xcol->flags = DoRed|DoGreen|DoBlue; |
| 361 |
xcol->pixel = startIndex + i; |
| 362 |
} |
| 363 |
|
| 364 |
// now load those colors into the color map |
| 365 |
if (overlayColorMap != 0) |
| 366 |
XStoreColors(getDisplay(), overlayColorMap, overlayMapColors, overlayMapColorNum); |
| 367 |
} |
| 368 |
|
| 369 |
//////////////////////////////////////////////////////////////////////// |
| 370 |
// |
| 371 |
// Description: |
| 372 |
// Sets the transparency type |
| 373 |
// |
| 374 |
// use: public |
| 375 |
// |
| 376 |
void |
| 377 |
SoXtRenderArea::setTransparencyType(SoGLRenderAction::TransparencyType type) |
| 378 |
// |
| 379 |
//////////////////////////////////////////////////////////////////////// |
| 380 |
{ |
| 381 |
sceneMgr->getGLRenderAction()->setTransparencyType(type); |
| 382 |
sceneMgr->scheduleRedraw(); |
| 383 |
} |
| 384 |
|
| 385 |
//////////////////////////////////////////////////////////////////////// |
| 386 |
// |
| 387 |
// Just call buildWidget on the base class (SoXtGLWidget). |
| 388 |
// |
| 389 |
// use: protected |
| 390 |
// |
| 391 |
Widget |
| 392 |
SoXtRenderArea::buildWidget(Widget parent) |
| 393 |
// |
| 394 |
//////////////////////////////////////////////////////////////////////// |
| 395 |
{ |
| 396 |
// Have the parent class build the mgrWidget. |
| 397 |
// Register the class here, though, since this is where resources |
| 398 |
// are needed (other GL widgets don't have resources) |
| 399 |
SoXtGLWidget::buildWidget(parent); |
| 400 |
registerWidget(getGlxMgrWidget()); |
| 401 |
|
| 402 |
// get the resources for this component |
| 403 |
SoXtResource xr(getGlxMgrWidget()); |
| 404 |
SbColor c; |
| 405 |
if (xr.getResource("backgroundColor", "BackgroundColor", c)) |
| 406 |
setBackgroundColor(c); |
| 407 |
|
| 408 |
// get the transparent color index |
| 409 |
#ifdef GLX_TRANSPARENT_INDEX_VALUE_EXT |
| 410 |
XVisualInfo *vis = getOverlayVisual(); |
| 411 |
if (vis != NULL) { |
| 412 |
int index; |
| 413 |
glXGetConfig(XtDisplay(parent), vis, GLX_TRANSPARENT_INDEX_VALUE_EXT, |
| 414 |
&index); |
| 415 |
overlaySceneMgr->setBackgroundIndex(index); |
| 416 |
} |
| 417 |
#endif |
| 418 |
|
| 419 |
return getGlxMgrWidget(); |
| 420 |
} |
| 421 |
|
| 422 |
//////////////////////////////////////////////////////////////////////// |
| 423 |
// |
| 424 |
// Called by the base class when the frontmost widget changes |
| 425 |
// (i.e. from single -> double buffer or vice versa). |
| 426 |
// |
| 427 |
// use: virtual protected |
| 428 |
// |
| 429 |
void |
| 430 |
SoXtRenderArea::widgetChanged(Widget newWidget) |
| 431 |
// |
| 432 |
//////////////////////////////////////////////////////////////////////// |
| 433 |
{ |
| 434 |
// init the render actions whenever we change windows |
| 435 |
if (newWidget) |
| 436 |
sceneMgr->reinitialize(); |
| 437 |
|
| 438 |
// |
| 439 |
// Work around bug #164424 |
| 440 |
// if we don't use the overlay window, register the devices/handler |
| 441 |
// on the new normal widget. |
| 442 |
// |
| 443 |
if (! getOverlayWidget()) |
| 444 |
reinstallDevices(newWidget); |
| 445 |
} |
| 446 |
|
| 447 |
//////////////////////////////////////////////////////////////////////// |
| 448 |
// |
| 449 |
// Register interest to handle events for the passed device. |
| 450 |
// If device is already in the list, then make sure it's enabled. |
| 451 |
// |
| 452 |
// use: public |
| 453 |
// |
| 454 |
void |
| 455 |
SoXtRenderArea::registerDevice(SoXtDevice *device) |
| 456 |
// |
| 457 |
//////////////////////////////////////////////////////////////////////// |
| 458 |
{ |
| 459 |
// Add the device if it's not already in the list of devices |
| 460 |
int index = deviceList->find(device); |
| 461 |
// ??? mott, shouldn't we return if the device is found ? |
| 462 |
if (index == -1) |
| 463 |
deviceList->append(device); |
| 464 |
|
| 465 |
// tell the device the window size |
| 466 |
device->setWindowSize(getGlxSize()); |
| 467 |
|
| 468 |
// Tell the device to register event interest for our widget |
| 469 |
Widget w = getOverlayWidget() ? getOverlayWidget() : getNormalWidget(); |
| 470 |
if ((w != NULL) && (XtWindow(w) != (Window) NULL)) |
| 471 |
device->enable( |
| 472 |
w, |
| 473 |
(XtEventHandler) SoXtGLWidget::eventHandler, |
| 474 |
(XtPointer) this, |
| 475 |
XtWindow(w)); |
| 476 |
} |
| 477 |
|
| 478 |
//////////////////////////////////////////////////////////////////////// |
| 479 |
// |
| 480 |
// Unregister interest in the passed device. |
| 481 |
// |
| 482 |
// use: public |
| 483 |
// |
| 484 |
void |
| 485 |
SoXtRenderArea::unregisterDevice(SoXtDevice *device) |
| 486 |
// |
| 487 |
//////////////////////////////////////////////////////////////////////// |
| 488 |
{ |
| 489 |
// Find the device in our device list |
| 490 |
int index = deviceList->find(device); |
| 491 |
if (index == -1) |
| 492 |
return; |
| 493 |
|
| 494 |
// Remove the device from the list of devices |
| 495 |
deviceList->remove(index); |
| 496 |
|
| 497 |
// Tell the device to register event interest for our widget |
| 498 |
Widget w = getOverlayWidget() ? getOverlayWidget() : getNormalWidget(); |
| 499 |
if (w) |
| 500 |
device->disable( |
| 501 |
w, |
| 502 |
(XtEventHandler) SoXtGLWidget::eventHandler, |
| 503 |
(XtPointer) this); |
| 504 |
} |
| 505 |
|
| 506 |
//////////////////////////////////////////////////////////////////////// |
| 507 |
// |
| 508 |
// disable devices on the old widget, and enables them on the new widget. |
| 509 |
// |
| 510 |
// use: private |
| 511 |
// |
| 512 |
void |
| 513 |
SoXtRenderArea::reinstallDevices(Widget newWidget) |
| 514 |
// |
| 515 |
//////////////////////////////////////////////////////////////////////// |
| 516 |
{ |
| 517 |
for (int i = 0; i < deviceList->getLength(); i++) { |
| 518 |
SoXtDevice *device = (SoXtDevice *) (*deviceList)[i]; |
| 519 |
|
| 520 |
// disable on the old widget... |
| 521 |
if (deviceWidget) |
| 522 |
device->disable( |
| 523 |
deviceWidget, |
| 524 |
(XtEventHandler) SoXtGLWidget::eventHandler, |
| 525 |
(XtPointer) this); |
| 526 |
|
| 527 |
// enable on the new widget.... |
| 528 |
if (newWidget) { |
| 529 |
device->setWindowSize(getGlxSize()); |
| 530 |
device->enable( |
| 531 |
newWidget, |
| 532 |
(XtEventHandler) SoXtGLWidget::eventHandler, |
| 533 |
(XtPointer) this, |
| 534 |
XtWindow(newWidget)); |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
// ??? add an event handler to receive EnterNotify events to make |
| 539 |
// ??? sure the render area has the current keyboard focus, otherwise |
| 540 |
// ??? keyboard events will go to whichever text field has focus (black |
| 541 |
// ??? outline around widget). This is the prefered behavior since we |
| 542 |
// ??? don't want to force the keyboardFocus to be POINTER or require |
| 543 |
// ??? the user to press a mouse button down. |
| 544 |
// |
| 545 |
// We also need a EnterNotify and LeaveNotify to correctly update |
| 546 |
// stuff for SoLocateHighlight (keep track of current window). |
| 547 |
// |
| 548 |
if (deviceWidget) |
| 549 |
XtRemoveEventHandler(deviceWidget, (EnterWindowMask | LeaveWindowMask), FALSE, |
| 550 |
(XtEventHandler) SoXtRenderArea::windowEventCB, |
| 551 |
(XtPointer) this); |
| 552 |
if (newWidget) |
| 553 |
XtAddEventHandler(newWidget, (EnterWindowMask | LeaveWindowMask), FALSE, |
| 554 |
(XtEventHandler) SoXtRenderArea::windowEventCB, |
| 555 |
(XtPointer) this); |
| 556 |
|
| 557 |
deviceWidget = newWidget; |
| 558 |
} |
| 559 |
|
| 560 |
//////////////////////////////////////////////////////////////////////// |
| 561 |
// |
| 562 |
// Description: |
| 563 |
// Invoke the app callback and return what the callback returns. |
| 564 |
// |
| 565 |
// use: protected |
| 566 |
// |
| 567 |
SbBool |
| 568 |
SoXtRenderArea::invokeAppCB(XAnyEvent *anyevent) |
| 569 |
// |
| 570 |
//////////////////////////////////////////////////////////////////////// |
| 571 |
{ |
| 572 |
// if app wants event, send event to application |
| 573 |
if (appEventHandler != NULL) |
| 574 |
return (*appEventHandler)(appEventHandlerData, anyevent); |
| 575 |
else |
| 576 |
return FALSE; |
| 577 |
} |
| 578 |
|
| 579 |
//////////////////////////////////////////////////////////////////////// |
| 580 |
// |
| 581 |
// Description: |
| 582 |
// Process the passed X event. |
| 583 |
// |
| 584 |
// use: virtual protected |
| 585 |
// |
| 586 |
void |
| 587 |
SoXtRenderArea::processEvent(XAnyEvent *anyevent) |
| 588 |
// |
| 589 |
//////////////////////////////////////////////////////////////////////// |
| 590 |
{ |
| 591 |
// check if app wants the event... |
| 592 |
if (invokeAppCB(anyevent)) |
| 593 |
return; |
| 594 |
|
| 595 |
// ...else send it to the scene |
| 596 |
|
| 597 |
// to do this, translate the X event to an SoEvent |
| 598 |
// by finding a device to perform the translation |
| 599 |
const SoEvent *soevent = NULL; |
| 600 |
for (int i = 0; (soevent == NULL) && (i < deviceList->getLength()); i++) { |
| 601 |
SoXtDevice *device = (SoXtDevice *) (*deviceList)[i]; |
| 602 |
soevent = device->translateEvent(anyevent); |
| 603 |
} |
| 604 |
|
| 605 |
// no device found, so return... |
| 606 |
if (! soevent) |
| 607 |
return; |
| 608 |
|
| 609 |
// now send the event first to the overlay scene graph, elses to |
| 610 |
// the regular scene graph. |
| 611 |
SbBool handled = overlaySceneMgr->processEvent(soevent); |
| 612 |
if (! handled) { |
| 613 |
sceneMgr->processEvent(soevent); |
| 614 |
|
| 615 |
// now check to make sure that we updated the handle event action |
| 616 |
// with the current window the very first time. This is needed |
| 617 |
// because the SoState does not exists until the action is |
| 618 |
// applied, and we only update those during enter/leave notify. |
| 619 |
if (firstEvent) { |
| 620 |
SoState *state = sceneMgr->getHandleEventAction()->getState(); |
| 621 |
if (state) { |
| 622 |
SoWindowElement::set(state, getNormalWindow(), |
| 623 |
getNormalContext(), getDisplay(), getGLRenderAction()); |
| 624 |
firstEvent = FALSE; |
| 625 |
} |
| 626 |
} |
| 627 |
} |
| 628 |
} |
| 629 |
|
| 630 |
//////////////////////////////////////////////////////////////////////// |
| 631 |
// |
| 632 |
// Initialize the GLX window for rendering. |
| 633 |
// glXMakeCurrent() should have been called before invoking this routine. |
| 634 |
// |
| 635 |
// use: virtual protected |
| 636 |
// |
| 637 |
void |
| 638 |
SoXtRenderArea::initGraphic() |
| 639 |
// |
| 640 |
//////////////////////////////////////////////////////////////////////// |
| 641 |
{ |
| 642 |
sceneMgr->reinitialize(); |
| 643 |
sceneMgr->setRGBMode(isRGBMode()); |
| 644 |
|
| 645 |
SoGLRenderAction *ra = sceneMgr->getGLRenderAction(); |
| 646 |
ra->setCacheContext(getDisplayListShareGroup(getNormalContext())); |
| 647 |
ra->setRenderingIsRemote(!glXIsDirect(getDisplay(), getNormalContext())); |
| 648 |
|
| 649 |
// load the color map |
| 650 |
if (! isRGBMode() && colorMap != 0 && mapColorNum != 0) |
| 651 |
XStoreColors(getDisplay(), colorMap, mapColors, mapColorNum); |
| 652 |
} |
| 653 |
|
| 654 |
//////////////////////////////////////////////////////////////////////// |
| 655 |
// |
| 656 |
// Initialize the GLX window for rendering. |
| 657 |
// glXMakeCurrent() should have been called before invoking this routine. |
| 658 |
// |
| 659 |
// use: virtual protected |
| 660 |
// |
| 661 |
void |
| 662 |
SoXtRenderArea::initOverlayGraphic() |
| 663 |
// |
| 664 |
//////////////////////////////////////////////////////////////////////// |
| 665 |
{ |
| 666 |
overlaySceneMgr->reinitialize(); |
| 667 |
overlaySceneMgr->setRGBMode(FALSE); |
| 668 |
|
| 669 |
SoGLRenderAction *ra = overlaySceneMgr->getGLRenderAction(); |
| 670 |
ra->setCacheContext(getDisplayListShareGroup(getOverlayContext())); |
| 671 |
ra->setRenderingIsRemote(!glXIsDirect(getDisplay(), getOverlayContext())); |
| 672 |
|
| 673 |
// load the color map |
| 674 |
if (overlayColorMap != 0 && overlayMapColorNum != 0) |
| 675 |
XStoreColors(getDisplay(), overlayColorMap, overlayMapColors, overlayMapColorNum); |
| 676 |
|
| 677 |
// enable the devices on the overlay window |
| 678 |
reinstallDevices(getOverlayWidget()); |
| 679 |
} |
| 680 |
|
| 681 |
//////////////////////////////////////////////////////////////////////// |
| 682 |
// |
| 683 |
// Called by the base class (SoXtGLWidget) when the widget has changed size. |
| 684 |
// |
| 685 |
// use: virtual protected |
| 686 |
// |
| 687 |
void |
| 688 |
SoXtRenderArea::sizeChanged(const SbVec2s &newSize) |
| 689 |
// |
| 690 |
//////////////////////////////////////////////////////////////////////// |
| 691 |
{ |
| 692 |
sceneMgr->setWindowSize(newSize); |
| 693 |
overlaySceneMgr->setWindowSize(newSize); |
| 694 |
|
| 695 |
// tell each device the new window size |
| 696 |
for (int i = 0; i < deviceList->getLength(); i++) { |
| 697 |
SoXtDevice *device = (SoXtDevice *) (*deviceList)[i]; |
| 698 |
device->setWindowSize(newSize); |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
//////////////////////////////////////////////////////////////////////// |
| 703 |
// |
| 704 |
// Attach the sensor (if necessary). |
| 705 |
// |
| 706 |
// use: private |
| 707 |
// |
| 708 |
void |
| 709 |
SoXtRenderArea::activate() |
| 710 |
// |
| 711 |
//////////////////////////////////////////////////////////////////////// |
| 712 |
{ |
| 713 |
// if autoRedraw is off, then don't attach the scene sensor |
| 714 |
if (! autoRedraw) |
| 715 |
return; |
| 716 |
|
| 717 |
// Activate the scene manager |
| 718 |
sceneMgr->activate(); |
| 719 |
overlaySceneMgr->activate(); |
| 720 |
} |
| 721 |
|
| 722 |
//////////////////////////////////////////////////////////////////////// |
| 723 |
// |
| 724 |
// Detach the sensor. |
| 725 |
// |
| 726 |
// use: private |
| 727 |
// |
| 728 |
void |
| 729 |
SoXtRenderArea::deactivate() |
| 730 |
// |
| 731 |
//////////////////////////////////////////////////////////////////////// |
| 732 |
{ |
| 733 |
// detach sensors |
| 734 |
sceneMgr->deactivate(); |
| 735 |
overlaySceneMgr->deactivate(); |
| 736 |
} |
| 737 |
|
| 738 |
//////////////////////////////////////////////////////////////////////// |
| 739 |
// |
| 740 |
// Turn auto-redraw on or off. If turning on, then activate the scene |
| 741 |
// sensor. |
| 742 |
// |
| 743 |
// use: public |
| 744 |
// |
| 745 |
void |
| 746 |
SoXtRenderArea::setAutoRedraw(SbBool flag) |
| 747 |
// |
| 748 |
//////////////////////////////////////////////////////////////////////// |
| 749 |
{ |
| 750 |
if (flag == autoRedraw) |
| 751 |
return; |
| 752 |
|
| 753 |
autoRedraw = flag; |
| 754 |
|
| 755 |
if (autoRedraw) { |
| 756 |
if (isVisible()) |
| 757 |
activate(); |
| 758 |
} |
| 759 |
else |
| 760 |
deactivate(); |
| 761 |
} |
| 762 |
|
| 763 |
//////////////////////////////////////////////////////////////////////// |
| 764 |
// |
| 765 |
// Have the scene manager redraw the scene. |
| 766 |
// |
| 767 |
// use: virtual protected |
| 768 |
// |
| 769 |
void |
| 770 |
SoXtRenderArea::actualRedraw() |
| 771 |
// |
| 772 |
//////////////////////////////////////////////////////////////////////// |
| 773 |
{ |
| 774 |
sceneMgr->render(clearFirst); |
| 775 |
} |
| 776 |
|
| 777 |
//////////////////////////////////////////////////////////////////////// |
| 778 |
// |
| 779 |
// Have the scene manager redraw the overlay scene. |
| 780 |
// |
| 781 |
// use: virtual protected |
| 782 |
// |
| 783 |
void |
| 784 |
SoXtRenderArea::actualOverlayRedraw() |
| 785 |
// |
| 786 |
//////////////////////////////////////////////////////////////////////// |
| 787 |
{ |
| 788 |
overlaySceneMgr->render(clearOverlayFirst); |
| 789 |
} |
| 790 |
|
| 791 |
//////////////////////////////////////////////////////////////////////// |
| 792 |
// |
| 793 |
// This routine draws the scene graph (called by expose events and the |
| 794 |
// scene graph sensor) |
| 795 |
// |
| 796 |
// use: virtual protected |
| 797 |
// |
| 798 |
void |
| 799 |
SoXtRenderArea::redraw() |
| 800 |
// |
| 801 |
//////////////////////////////////////////////////////////////////////// |
| 802 |
{ |
| 803 |
// return if we are not visible or if we need to wait for an expose |
| 804 |
// event (case when the sensor triggers but we know that an expose |
| 805 |
// event will come along and we don't want 2 redraws). |
| 806 |
if (!isVisible() || waitForExpose) |
| 807 |
return; |
| 808 |
|
| 809 |
// set the window |
| 810 |
glXMakeCurrent(getDisplay(), getNormalWindow(), getNormalContext()); |
| 811 |
|
| 812 |
// see if we need to temporary draw to the front buffer (which |
| 813 |
// is set when we display a new scene or get an expose event) |
| 814 |
if (drawToFrontBuffer && isDrawToFrontBufferEnable() && isDoubleBuffer()) { |
| 815 |
|
| 816 |
// ??? workaround bug 301010 - it seems that redrawing to the front |
| 817 |
// ??? of a window that might not be on the screen ( isVisible() might |
| 818 |
// ??? be incorect in a few cases) will confuse the GFX hardware |
| 819 |
// ??? of some machine (Xtrem and Indy24). |
| 820 |
// |
| 821 |
// ??? Note: this also fixes 298058 (redrawing to the front window |
| 822 |
// ??? on indigo starter gfx, which happened all the time). |
| 823 |
// |
| 824 |
if (isRGBMode()) { |
| 825 |
SbColor color = getBackgroundColor(); |
| 826 |
glClearColor(color[0], color[1], color[2], 0); |
| 827 |
} else |
| 828 |
glClearIndex(getBackgroundIndex()); |
| 829 |
glClear(GL_COLOR_BUFFER_BIT); |
| 830 |
glXSwapBuffers(getDisplay(), getNormalWindow()); |
| 831 |
// ??? end of BUG workaround |
| 832 |
|
| 833 |
glReadBuffer(GL_FRONT); // Needed for acbuf antialiasing |
| 834 |
glDrawBuffer(GL_FRONT); |
| 835 |
} |
| 836 |
|
| 837 |
// draw that scene! (subclasses may redefine...) |
| 838 |
actualRedraw(); |
| 839 |
|
| 840 |
// swap those buffers! |
| 841 |
if (isDoubleBuffer()) { |
| 842 |
if (drawToFrontBuffer && isDrawToFrontBufferEnable()) { |
| 843 |
// no need to swap here - instead restore the buffer and |
| 844 |
// clear the flag now that we have drawn to the front buffer |
| 845 |
glReadBuffer(GL_BACK); // Needed for acbuf antialiasing |
| 846 |
glDrawBuffer(GL_BACK); |
| 847 |
glFlush(); |
| 848 |
} |
| 849 |
else |
| 850 |
glXSwapBuffers(getDisplay(), getNormalWindow()); |
| 851 |
} |
| 852 |
else |
| 853 |
glFlush(); |
| 854 |
|
| 855 |
// clear this flag now that we have drawn |
| 856 |
drawToFrontBuffer = FALSE; |
| 857 |
} |
| 858 |
|
| 859 |
//////////////////////////////////////////////////////////////////////// |
| 860 |
// |
| 861 |
// Description: |
| 862 |
// Sets antialiasing on GL rendering action. |
| 863 |
// |
| 864 |
// use: public |
| 865 |
// |
| 866 |
void |
| 867 |
SoXtRenderArea::setAntialiasing(SbBool smoothing, int numPasses) |
| 868 |
// |
| 869 |
//////////////////////////////////////////////////////////////////////// |
| 870 |
{ |
| 871 |
SoGLRenderAction *ra = getGLRenderAction(); |
| 872 |
|
| 873 |
if (smoothing == ra->isSmoothing() && numPasses == ra->getNumPasses()) |
| 874 |
return; |
| 875 |
|
| 876 |
// The visual needs to change if we are now enabling or disabling |
| 877 |
// the accumulation buffer |
| 878 |
SbBool needToChangeVisual = ((numPasses > 1 && ra->getNumPasses() == 1) || |
| 879 |
(numPasses == 1 && ra->getNumPasses() > 1)); |
| 880 |
|
| 881 |
// |
| 882 |
// now create a visual with the right info - this tries to |
| 883 |
// preserve as many setting as the original visual, with just |
| 884 |
// the antialiasing changed. |
| 885 |
// |
| 886 |
if (needToChangeVisual) { |
| 887 |
|
| 888 |
int n = 0; |
| 889 |
int attribList[20]; |
| 890 |
|
| 891 |
if (isRGBMode()) { |
| 892 |
attribList[n++] = GLX_RGBA; |
| 893 |
attribList[n++] = GLX_RED_SIZE; |
| 894 |
attribList[n++] = 1; |
| 895 |
attribList[n++] = GLX_GREEN_SIZE; |
| 896 |
attribList[n++] = 1; |
| 897 |
attribList[n++] = GLX_BLUE_SIZE; |
| 898 |
attribList[n++] = 1; |
| 899 |
} |
| 900 |
// there is always zbuffer... |
| 901 |
attribList[n++] = GLX_DEPTH_SIZE; |
| 902 |
attribList[n++] = 1; |
| 903 |
if (isDoubleBuffer()) |
| 904 |
attribList[n++] = GLX_DOUBLEBUFFER; |
| 905 |
|
| 906 |
// now add the antialiasing stuff |
| 907 |
if (numPasses > 1) { |
| 908 |
attribList[n++] = GLX_ACCUM_RED_SIZE; |
| 909 |
attribList[n++] = 1; |
| 910 |
attribList[n++] = GLX_ACCUM_GREEN_SIZE; |
| 911 |
attribList[n++] = 1; |
| 912 |
attribList[n++] = GLX_ACCUM_BLUE_SIZE; |
| 913 |
attribList[n++] = 1; |
| 914 |
} |
| 915 |
|
| 916 |
// check for stencil buffer |
| 917 |
Widget w = getWidget(); |
| 918 |
XVisualInfo *normalVis = getNormalVisual(); |
| 919 |
if (normalVis) { |
| 920 |
int val; |
| 921 |
glXGetConfig(XtDisplay(w), normalVis, GLX_STENCIL_SIZE, &val); |
| 922 |
if (val) { |
| 923 |
attribList[n++] = GLX_STENCIL_SIZE; |
| 924 |
attribList[n++] = val; |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
attribList[n++] = (int) None; |
| 929 |
|
| 930 |
// create the visual |
| 931 |
XVisualInfo *vis = glXChooseVisual(XtDisplay(w), |
| 932 |
XScreenNumberOfScreen(XtScreen(w)), attribList); |
| 933 |
|
| 934 |
if (! vis) { |
| 935 |
#ifdef DEBUG |
| 936 |
SoDebugError::post("SoXtRenderArea::setAntialiasing", |
| 937 |
"could not create ACCUM visual"); |
| 938 |
#endif |
| 939 |
return; |
| 940 |
} |
| 941 |
|
| 942 |
// now set this as the current visual |
| 943 |
setNormalVisual(vis); |
| 944 |
|
| 945 |
// GL widget made a copy - we can free this |
| 946 |
XFree(vis); |
| 947 |
} |
| 948 |
else // only the number of passes changed, so just redraw |
| 949 |
sceneMgr->scheduleRedraw(); |
| 950 |
|
| 951 |
// finally set the stuff on the render action |
| 952 |
sceneMgr->setAntialiasing(smoothing, numPasses); |
| 953 |
} |
| 954 |
|
| 955 |
//////////////////////////////////////////////////////////////////////// |
| 956 |
// |
| 957 |
// This routine draws the scene graph for the overlay bit planes (called |
| 958 |
// by the expose event and scene graph sensor). |
| 959 |
// |
| 960 |
// use: virtual protected |
| 961 |
// |
| 962 |
void |
| 963 |
SoXtRenderArea::redrawOverlay() |
| 964 |
// |
| 965 |
//////////////////////////////////////////////////////////////////////// |
| 966 |
{ |
| 967 |
if (!isVisible() || getOverlayWindow() == (Window) NULL) |
| 968 |
return; |
| 969 |
|
| 970 |
// set the window |
| 971 |
glXMakeCurrent(getDisplay(), getOverlayWindow(), getOverlayContext()); |
| 972 |
|
| 973 |
// draw that scene! (subclasses may redefine...) |
| 974 |
actualOverlayRedraw(); |
| 975 |
|
| 976 |
glFlush(); |
| 977 |
} |
| 978 |
|
| 979 |
//////////////////////////////////////////////////////////////////////// |
| 980 |
// |
| 981 |
// Schedule a redraw to happen sometime soon. |
| 982 |
// |
| 983 |
// use: public |
| 984 |
// |
| 985 |
void |
| 986 |
SoXtRenderArea::scheduleRedraw() |
| 987 |
// |
| 988 |
//////////////////////////////////////////////////////////////////////// |
| 989 |
{ |
| 990 |
if (isAutoRedraw()) |
| 991 |
sceneMgr->scheduleRedraw(); |
| 992 |
else |
| 993 |
redraw(); |
| 994 |
} |
| 995 |
|
| 996 |
//////////////////////////////////////////////////////////////////////// |
| 997 |
// |
| 998 |
// Schedule a redraw to happen sometime soon. |
| 999 |
// |
| 1000 |
// use: public |
| 1001 |
// |
| 1002 |
void |
| 1003 |
SoXtRenderArea::scheduleOverlayRedraw() |
| 1004 |
// |
| 1005 |
//////////////////////////////////////////////////////////////////////// |
| 1006 |
{ |
| 1007 |
if (isAutoRedraw()) |
| 1008 |
overlaySceneMgr->scheduleRedraw(); |
| 1009 |
else |
| 1010 |
redrawOverlay(); |
| 1011 |
} |
| 1012 |
|
| 1013 |
//////////////////////////////////////////////////////////////////////// |
| 1014 |
// |
| 1015 |
// Convenience to set up the redraw mechansim whenever the selection |
| 1016 |
// changes. |
| 1017 |
// |
| 1018 |
// public |
| 1019 |
// |
| 1020 |
void |
| 1021 |
SoXtRenderArea::redrawOnSelectionChange(SoSelection *s) |
| 1022 |
// |
| 1023 |
//////////////////////////////////////////////////////////////////////// |
| 1024 |
{ |
| 1025 |
// Ref the new selection node |
| 1026 |
if (s != NULL) |
| 1027 |
s->ref(); |
| 1028 |
|
| 1029 |
// Remove our callback from old selection node |
| 1030 |
if (selection != NULL) { |
| 1031 |
selection->removeChangeCallback(SoXtRenderArea::selectionChangeCB, this); |
| 1032 |
|
| 1033 |
// Unref the old selection node |
| 1034 |
selection->unref(); |
| 1035 |
} |
| 1036 |
|
| 1037 |
selection = s; |
| 1038 |
|
| 1039 |
// Add our callback to this selection node. (We've already ref'd this new sel node) |
| 1040 |
if (selection != NULL) |
| 1041 |
selection->addChangeCallback(SoXtRenderArea::selectionChangeCB, this); |
| 1042 |
} |
| 1043 |
|
| 1044 |
//////////////////////////////////////////////////////////////////////// |
| 1045 |
// |
| 1046 |
// Convenience to set up the redraw mechansim whenever the selection |
| 1047 |
// changes. |
| 1048 |
// |
| 1049 |
// public |
| 1050 |
// |
| 1051 |
void |
| 1052 |
SoXtRenderArea::redrawOverlayOnSelectionChange(SoSelection *s) |
| 1053 |
// |
| 1054 |
//////////////////////////////////////////////////////////////////////// |
| 1055 |
{ |
| 1056 |
// Remove our callback from old selection node |
| 1057 |
if (overlaySelection != NULL) |
| 1058 |
overlaySelection->removeChangeCallback(SoXtRenderArea::overlaySelectionChangeCB, this); |
| 1059 |
|
| 1060 |
overlaySelection = s; |
| 1061 |
|
| 1062 |
// Add our callback to this selection node |
| 1063 |
if (overlaySelection != NULL) |
| 1064 |
overlaySelection->addChangeCallback(SoXtRenderArea::overlaySelectionChangeCB, this); |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
// |
| 1070 |
// redefine those generic virtual functions |
| 1071 |
// |
| 1072 |
const char * |
| 1073 |
SoXtRenderArea::getDefaultWidgetName() const |
| 1074 |
{ return thisClassName; } |
| 1075 |
|
| 1076 |
const char * |
| 1077 |
SoXtRenderArea::getDefaultTitle() const |
| 1078 |
{ return "Xt RenderArea"; } |
| 1079 |
|
| 1080 |
const char * |
| 1081 |
SoXtRenderArea::getDefaultIconTitle() const |
| 1082 |
{ return "Xt RenderArea"; } |
| 1083 |
|
| 1084 |
|
| 1085 |
// |
| 1086 |
//////////////////////////////////////////////////////////////////////// |
| 1087 |
// static callbacks stubs |
| 1088 |
//////////////////////////////////////////////////////////////////////// |
| 1089 |
// |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
#include <Inventor/Xt/SoXt.h> |
| 1095 |
// |
| 1096 |
// Called whenever an enter/leave window event occurs. This forces the |
| 1097 |
// render area to get/loose keyboard Focus (as opposed to requiring |
| 1098 |
// POINTER focus policy, or requiring the user to press a mouse |
| 1099 |
// button down). |
| 1100 |
// |
| 1101 |
// We also need a EnterNotify and LeaveNotify to correctly update |
| 1102 |
// stuff for SoLocateHighlight (keep track of current window). |
| 1103 |
// |
| 1104 |
void |
| 1105 |
SoXtRenderArea::windowEventCB(Widget w, SoXtRenderArea *p, XAnyEvent *xe, Boolean *) |
| 1106 |
{ |
| 1107 |
if (xe->type == EnterNotify) { |
| 1108 |
// get keyboard focus.... |
| 1109 |
if (p->getOverlayWidget()) |
| 1110 |
XmProcessTraversal(p->getOverlayWidget(), XmTRAVERSE_CURRENT); |
| 1111 |
else |
| 1112 |
XmProcessTraversal(p->getNormalWidget(), XmTRAVERSE_CURRENT); |
| 1113 |
|
| 1114 |
// |
| 1115 |
// update the windowElement for the handleEventAction as well |
| 1116 |
// as the GLRenderAction to point to this window. |
| 1117 |
// |
| 1118 |
// Note: don't touch the windowElement if we are in the middle |
| 1119 |
// of rendering (if we process event during render abort). |
| 1120 |
// |
| 1121 |
|
| 1122 |
SoState *state = p->sceneMgr->getHandleEventAction()->getState(); |
| 1123 |
if (state) |
| 1124 |
SoWindowElement::set(state, p->getNormalWindow(), |
| 1125 |
p->getNormalContext(), p->getDisplay(), p->getGLRenderAction()); |
| 1126 |
state = p->sceneMgr->getGLRenderAction()->getState(); |
| 1127 |
if (state && state->getDepth() == 1) |
| 1128 |
SoWindowElement::set(state, p->getNormalWindow(), |
| 1129 |
p->getNormalContext(), p->getDisplay(), p->getGLRenderAction()); |
| 1130 |
} |
| 1131 |
else if (xe->type == LeaveNotify) { |
| 1132 |
// loose keyboard focus... |
| 1133 |
XmProcessTraversal(SoXt::getShellWidget(w), XmTRAVERSE_CURRENT); |
| 1134 |
|
| 1135 |
// |
| 1136 |
// clear the windowElement from the actions now that we are |
| 1137 |
// leaving the window. |
| 1138 |
// |
| 1139 |
// Note: don't touch the windowElement if we are in the middle |
| 1140 |
// of rendering (if we process event during render abort). |
| 1141 |
// |
| 1142 |
|
| 1143 |
// but first clear any currently highlighted object |
| 1144 |
SoGLRenderAction *glAct = p->sceneMgr->getGLRenderAction(); |
| 1145 |
if (glAct) |
| 1146 |
SoLocateHighlight::turnOffCurrentHighlight(glAct); |
| 1147 |
|
| 1148 |
SoState *state = p->sceneMgr->getHandleEventAction()->getState(); |
| 1149 |
if (state) |
| 1150 |
SoWindowElement::set(state, (Window) NULL, NULL, NULL, NULL); |
| 1151 |
state = p->sceneMgr->getGLRenderAction()->getState(); |
| 1152 |
if (state && state->getDepth() == 1) |
| 1153 |
SoWindowElement::set(state, (Window) NULL, NULL, NULL, NULL); |
| 1154 |
} |
| 1155 |
} |
| 1156 |
|
| 1157 |
// |
| 1158 |
// called whenever the component becomes visible or not |
| 1159 |
// |
| 1160 |
void |
| 1161 |
SoXtRenderArea::visibilityChangeCB(void *pt, SbBool visible) |
| 1162 |
{ |
| 1163 |
SoXtRenderArea *p = (SoXtRenderArea *)pt; |
| 1164 |
|
| 1165 |
if (visible) |
| 1166 |
p->activate(); |
| 1167 |
else { |
| 1168 |
// we are becoming hidden - so wait for an expose event |
| 1169 |
// (which we now will come later) before enabling a redraw to |
| 1170 |
// prevent too many redraws (scene graph changes + expose) |
| 1171 |
p->waitForExpose = TRUE; |
| 1172 |
|
| 1173 |
p->deactivate(); |
| 1174 |
} |
| 1175 |
} |
| 1176 |
|
| 1177 |
|
| 1178 |
void |
| 1179 |
SoXtRenderArea::selectionChangeCB(void *p, SoSelection *) |
| 1180 |
{ |
| 1181 |
((SoXtRenderArea *)p)->scheduleRedraw(); |
| 1182 |
} |
| 1183 |
|
| 1184 |
void |
| 1185 |
SoXtRenderArea::overlaySelectionChangeCB(void *p, SoSelection *) |
| 1186 |
{ |
| 1187 |
((SoXtRenderArea *)p)->scheduleOverlayRedraw(); |
| 1188 |
} |
| 1189 |
|
| 1190 |
void |
| 1191 |
SoXtRenderArea::renderCB(void *p, SoSceneManager *) |
| 1192 |
{ |
| 1193 |
((SoXtRenderArea *)p)->redraw(); |
| 1194 |
} |
| 1195 |
|
| 1196 |
void |
| 1197 |
SoXtRenderArea::renderOverlayCB(void *p, SoSceneManager *) |
| 1198 |
{ |
| 1199 |
((SoXtRenderArea *)p)->redrawOverlay(); |
| 1200 |
} |