| 1 |
/* |
| 2 |
* (c) Copyright 1993, Silicon Graphics, Inc. |
| 3 |
* ALL RIGHTS RESERVED |
| 4 |
* Permission to use, copy, modify, and distribute this software for |
| 5 |
* any purpose and without fee is hereby granted, provided that the above |
| 6 |
* copyright notice appear in all copies and that both the copyright notice |
| 7 |
* and this permission notice appear in supporting documentation, and that |
| 8 |
* the name of Silicon Graphics, Inc. not be used in advertising |
| 9 |
* or publicity pertaining to distribution of the software without specific, |
| 10 |
* written prior permission. |
| 11 |
* |
| 12 |
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" |
| 13 |
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, |
| 14 |
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR |
| 15 |
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON |
| 16 |
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, |
| 17 |
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY |
| 18 |
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, |
| 19 |
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF |
| 20 |
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN |
| 21 |
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON |
| 22 |
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE |
| 23 |
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. |
| 24 |
* |
| 25 |
* |
| 26 |
* US Government Users Restricted Rights |
| 27 |
* Use, duplication, or disclosure by the Government is subject to |
| 28 |
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph |
| 29 |
* (c)(1)(ii) of the Rights in Technical Data and Computer Software |
| 30 |
* clause at DFARS 252.227-7013 and/or in similar or successor |
| 31 |
* clauses in the FAR or the DOD or NASA FAR Supplement. |
| 32 |
* Unpublished-- rights reserved under the copyright laws of the |
| 33 |
* United States. Contractor/manufacturer is Silicon Graphics, |
| 34 |
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. |
| 35 |
* |
| 36 |
* OpenGL(TM) is a trademark of Silicon Graphics, Inc. |
| 37 |
*/ |
| 38 |
|
| 39 |
/* |
| 40 |
* |
| 41 |
* This file has been slightly modified from the original for use with Mesa |
| 42 |
* |
| 43 |
* Jeroen van der Zijp |
| 44 |
* |
| 45 |
* [email protected] |
| 46 |
* |
| 47 |
*/ |
| 48 |
#include <X11/IntrinsicP.h> |
| 49 |
#include <X11/StringDefs.h> |
| 50 |
#include <GL/glx.h> |
| 51 |
#include <GL/gl.h> |
| 52 |
#include "GLwDrawAP.h" |
| 53 |
#include <assert.h> |
| 54 |
#include <stdio.h> |
| 55 |
|
| 56 |
#define ATTRIBLIST_SIZE 30 |
| 57 |
|
| 58 |
#define offset(field) XtOffset(GLwDrawingAreaWidget,glwDrawingArea.field) |
| 59 |
|
| 60 |
|
| 61 |
/* forward definitions */ |
| 62 |
static void createColormap(GLwDrawingAreaWidget w,int offset,XrmValue *value); |
| 63 |
static void Initialize(GLwDrawingAreaWidget req,GLwDrawingAreaWidget neww,ArgList args,Cardinal *num_args); |
| 64 |
static void Realize(Widget w,Mask *valueMask,XSetWindowAttributes *attributes); |
| 65 |
static void Redraw(GLwDrawingAreaWidget w,XEvent *event,Region region); |
| 66 |
static void Resize(GLwDrawingAreaWidget glw); |
| 67 |
static void Destroy(GLwDrawingAreaWidget glw); |
| 68 |
static void glwInput(GLwDrawingAreaWidget glw,XEvent *event,String *params,Cardinal *numParams); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
static char defaultTranslations[] = |
| 73 |
"<KeyDown>: glwInput() \n\ |
| 74 |
<KeyUp>: glwInput() \n\ |
| 75 |
<BtnDown>: glwInput() \n\ |
| 76 |
<BtnUp>: glwInput() \n\ |
| 77 |
<BtnMotion>: glwInput() "; |
| 78 |
|
| 79 |
|
| 80 |
static XtActionsRec actions[] = { |
| 81 |
{"glwInput",(XtActionProc)glwInput}, /* key or mouse input */ |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
/* |
| 86 |
* There is a bit of unusual handling of the resources here. |
| 87 |
* Because Xt insists on allocating the colormap resource when it is |
| 88 |
* processing the core resources (even if we redeclare the colormap |
| 89 |
* resource here, we need to do a little trick. When Xt first allocates |
| 90 |
* the colormap, we allow it to allocate the default one, since we have |
| 91 |
* not yet determined the appropriate visual (which is determined from |
| 92 |
* resources parsed after the colormap). We also let it allocate colors |
| 93 |
* in that default colormap. |
| 94 |
* |
| 95 |
* In the initialize proc we calculate the actual visual. Then, we |
| 96 |
* reobtain the colormap resource using XtGetApplicationResources in |
| 97 |
* the initialize proc. If requested, we also reallocate colors in |
| 98 |
* that colormap using the same method. |
| 99 |
*/ |
| 100 |
|
| 101 |
static XtResource resources[] = { |
| 102 |
/* The GLX attributes. Add any new attributes here */ |
| 103 |
|
| 104 |
{GLwNbufferSize, GLwCBufferSize, XtRInt, sizeof (int), |
| 105 |
offset(bufferSize), XtRImmediate, (XtPointer) 0}, |
| 106 |
|
| 107 |
{GLwNlevel, GLwCLevel, XtRInt, sizeof (int), |
| 108 |
offset(level), XtRImmediate, (XtPointer) 0}, |
| 109 |
|
| 110 |
{GLwNrgba, GLwCRgba, XtRBoolean, sizeof (Boolean), |
| 111 |
offset(rgba), XtRImmediate, (XtPointer) FALSE}, |
| 112 |
|
| 113 |
{GLwNdoublebuffer, GLwCDoublebuffer, XtRBoolean, sizeof (Boolean), |
| 114 |
offset(doublebuffer), XtRImmediate, (XtPointer) FALSE}, |
| 115 |
|
| 116 |
{GLwNstereo, GLwCStereo, XtRBoolean, sizeof (Boolean), |
| 117 |
offset(stereo), XtRImmediate, (XtPointer) FALSE}, |
| 118 |
|
| 119 |
{GLwNauxBuffers, GLwCAuxBuffers, XtRInt, sizeof (int), |
| 120 |
offset(auxBuffers), XtRImmediate, (XtPointer) 0}, |
| 121 |
|
| 122 |
{GLwNredSize, GLwCColorSize, XtRInt, sizeof (int), |
| 123 |
offset(redSize), XtRImmediate, (XtPointer) 1}, |
| 124 |
|
| 125 |
{GLwNgreenSize, GLwCColorSize, XtRInt, sizeof (int), |
| 126 |
offset(greenSize), XtRImmediate, (XtPointer) 1}, |
| 127 |
|
| 128 |
{GLwNblueSize, GLwCColorSize, XtRInt, sizeof (int), |
| 129 |
offset(blueSize), XtRImmediate, (XtPointer) 1}, |
| 130 |
|
| 131 |
{GLwNalphaSize, GLwCAlphaSize, XtRInt, sizeof (int), |
| 132 |
offset(alphaSize), XtRImmediate, (XtPointer) 0}, |
| 133 |
|
| 134 |
{GLwNdepthSize, GLwCDepthSize, XtRInt, sizeof (int), |
| 135 |
offset(depthSize), XtRImmediate, (XtPointer) 0}, |
| 136 |
|
| 137 |
{GLwNstencilSize, GLwCStencilSize, XtRInt, sizeof (int), |
| 138 |
offset(stencilSize), XtRImmediate, (XtPointer) 0}, |
| 139 |
|
| 140 |
{GLwNaccumRedSize, GLwCAccumColorSize, XtRInt, sizeof (int), |
| 141 |
offset(accumRedSize), XtRImmediate, (XtPointer) 0}, |
| 142 |
|
| 143 |
{GLwNaccumGreenSize, GLwCAccumColorSize, XtRInt, sizeof (int), |
| 144 |
offset(accumGreenSize), XtRImmediate, (XtPointer) 0}, |
| 145 |
|
| 146 |
{GLwNaccumBlueSize, GLwCAccumColorSize, XtRInt, sizeof (int), |
| 147 |
offset(accumBlueSize), XtRImmediate, (XtPointer) 0}, |
| 148 |
|
| 149 |
{GLwNaccumAlphaSize, GLwCAccumAlphaSize, XtRInt, sizeof (int), |
| 150 |
offset(accumAlphaSize), XtRImmediate, (XtPointer) 0}, |
| 151 |
|
| 152 |
/* the attribute list */ |
| 153 |
{GLwNattribList, GLwCAttribList, XtRPointer, sizeof(int *), |
| 154 |
offset(attribList), XtRImmediate, (XtPointer) NULL}, |
| 155 |
|
| 156 |
/* the visual info */ |
| 157 |
{GLwNvisualInfo, GLwCVisualInfo, GLwRVisualInfo, sizeof (XVisualInfo *), |
| 158 |
offset(visualInfo), XtRImmediate, (XtPointer) NULL}, |
| 159 |
|
| 160 |
/* miscellaneous resources */ |
| 161 |
{GLwNinstallColormap, GLwCInstallColormap, XtRBoolean, sizeof (Boolean), |
| 162 |
offset(installColormap), XtRImmediate, (XtPointer) TRUE}, |
| 163 |
|
| 164 |
{GLwNallocateBackground, GLwCAllocateColors, XtRBoolean, sizeof (Boolean), |
| 165 |
offset(allocateBackground), XtRImmediate, (XtPointer) FALSE}, |
| 166 |
|
| 167 |
{GLwNallocateOtherColors, GLwCAllocateColors, XtRBoolean, sizeof (Boolean), |
| 168 |
offset(allocateOtherColors), XtRImmediate, (XtPointer) FALSE}, |
| 169 |
|
| 170 |
{GLwNinstallBackground, GLwCInstallBackground, XtRBoolean, sizeof (Boolean), |
| 171 |
offset(installBackground), XtRImmediate, (XtPointer) TRUE}, |
| 172 |
|
| 173 |
{GLwNginitCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList), |
| 174 |
offset(ginitCallback), XtRImmediate, (XtPointer) NULL}, |
| 175 |
|
| 176 |
{GLwNinputCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList), |
| 177 |
offset(inputCallback), XtRImmediate, (XtPointer) NULL}, |
| 178 |
|
| 179 |
{GLwNresizeCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList), |
| 180 |
offset(resizeCallback), XtRImmediate, (XtPointer) NULL}, |
| 181 |
|
| 182 |
{GLwNexposeCallback, GLwCCallback, XtRCallback, sizeof (XtCallbackList), |
| 183 |
offset(exposeCallback), XtRImmediate, (XtPointer) NULL}, |
| 184 |
|
| 185 |
}; |
| 186 |
|
| 187 |
|
| 188 |
/* |
| 189 |
** The following resources are reobtained using XtGetApplicationResources |
| 190 |
** in the initialize proc. |
| 191 |
*/ |
| 192 |
|
| 193 |
/* The colormap */ |
| 194 |
static XtResource initializeResources[] = { |
| 195 |
/* reobtain the colormap with the new visual */ |
| 196 |
{XtNcolormap, XtCColormap, XtRColormap, sizeof(Colormap), |
| 197 |
XtOffset(GLwDrawingAreaWidget, core.colormap), |
| 198 |
XtRCallProc, (XtPointer)createColormap} }; |
| 199 |
|
| 200 |
|
| 201 |
/* reallocate any colors we need in the new colormap */ |
| 202 |
|
| 203 |
/* The background is obtained only if the allocateBackground resource is TRUE*/ |
| 204 |
static XtResource backgroundResources[] = { |
| 205 |
{XtNbackground,XtCBackground,XtRPixel,sizeof(Pixel), |
| 206 |
XtOffset(GLwDrawingAreaWidget,core.background_pixel), |
| 207 |
XtRString,(XtPointer)"lightgrey"}, |
| 208 |
/*XtRString,(XtPointer)"XtDefaultBackground"},*/ |
| 209 |
|
| 210 |
{XtNbackgroundPixmap, XtCPixmap, XtRPixmap, sizeof(Pixmap), |
| 211 |
XtOffset(GLwDrawingAreaWidget,core.background_pixmap), |
| 212 |
XtRImmediate,(XtPointer)XtUnspecifiedPixmap}, |
| 213 |
}; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
#undef offset |
| 218 |
|
| 219 |
|
| 220 |
GLwDrawingAreaClassRec glwDrawingAreaClassRec = { |
| 221 |
{ /* core fields */ |
| 222 |
/* superclass */ (WidgetClass) &widgetClassRec, |
| 223 |
/* class_name */ "GLwDrawingArea", |
| 224 |
/* widget_size */ sizeof(GLwDrawingAreaRec), |
| 225 |
/* class_initialize */ NULL, |
| 226 |
/* class_part_initialize */ NULL, |
| 227 |
/* class_inited */ FALSE, |
| 228 |
/* initialize */ (XtInitProc) Initialize, |
| 229 |
/* initialize_hook */ NULL, |
| 230 |
/* realize */ Realize, |
| 231 |
/* actions */ actions, |
| 232 |
/* num_actions */ XtNumber(actions), |
| 233 |
/* resources */ resources, |
| 234 |
/* num_resources */ XtNumber(resources), |
| 235 |
/* xrm_class */ NULLQUARK, |
| 236 |
/* compress_motion */ TRUE, |
| 237 |
/* compress_exposure */ TRUE, |
| 238 |
/* compress_enterleave */ TRUE, |
| 239 |
/* visible_interest */ TRUE, |
| 240 |
/* destroy */ (XtWidgetProc) Destroy, |
| 241 |
/* resize */ (XtWidgetProc) Resize, |
| 242 |
/* expose */ (XtExposeProc) Redraw, |
| 243 |
/* set_values */ NULL, |
| 244 |
/* set_values_hook */ NULL, |
| 245 |
/* set_values_almost */ XtInheritSetValuesAlmost, |
| 246 |
/* get_values_hook */ NULL, |
| 247 |
/* accept_focus */ NULL, |
| 248 |
/* version */ XtVersion, |
| 249 |
/* callback_private */ NULL, |
| 250 |
/* tm_table */ defaultTranslations, |
| 251 |
/* query_geometry */ XtInheritQueryGeometry, |
| 252 |
/* display_accelerator */ XtInheritDisplayAccelerator, |
| 253 |
/* extension */ NULL |
| 254 |
}, |
| 255 |
}; |
| 256 |
|
| 257 |
WidgetClass glwDrawingAreaWidgetClass=(WidgetClass)&glwDrawingAreaClassRec; |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
static void error(Widget w,char* string){ |
| 262 |
char buf[100]; |
| 263 |
sprintf(buf,"GLwDrawingArea: %s\n",string); |
| 264 |
XtAppError(XtWidgetToApplicationContext(w),buf); |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
static void warning(Widget w,char* string){ |
| 269 |
char buf[100]; |
| 270 |
sprintf (buf, "GLwDraw: %s\n", string); |
| 271 |
XtAppWarning(XtWidgetToApplicationContext(w), buf); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
/* Initialize the attribList based on the attributes */ |
| 277 |
static void createAttribList(GLwDrawingAreaWidget w){ |
| 278 |
int *ptr; |
| 279 |
w->glwDrawingArea.attribList = (int*)XtMalloc(ATTRIBLIST_SIZE*sizeof(int)); |
| 280 |
if(!w->glwDrawingArea.attribList){ |
| 281 |
error((Widget)w,"Unable to allocate attribute list"); |
| 282 |
} |
| 283 |
ptr = w->glwDrawingArea.attribList; |
| 284 |
*ptr++ = GLX_BUFFER_SIZE; |
| 285 |
*ptr++ = w->glwDrawingArea.bufferSize; |
| 286 |
*ptr++ = GLX_LEVEL; |
| 287 |
*ptr++ = w->glwDrawingArea.level; |
| 288 |
if(w->glwDrawingArea.rgba) *ptr++ = GLX_RGBA; |
| 289 |
if(w->glwDrawingArea.doublebuffer) *ptr++ = GLX_DOUBLEBUFFER; |
| 290 |
if(w->glwDrawingArea.stereo) *ptr++ = GLX_STEREO; |
| 291 |
*ptr++ = GLX_AUX_BUFFERS; |
| 292 |
*ptr++ = w->glwDrawingArea.auxBuffers; |
| 293 |
*ptr++ = GLX_RED_SIZE; |
| 294 |
*ptr++ = w->glwDrawingArea.redSize; |
| 295 |
*ptr++ = GLX_GREEN_SIZE; |
| 296 |
*ptr++ = w->glwDrawingArea.greenSize; |
| 297 |
*ptr++ = GLX_BLUE_SIZE; |
| 298 |
*ptr++ = w->glwDrawingArea.blueSize; |
| 299 |
*ptr++ = GLX_ALPHA_SIZE; |
| 300 |
*ptr++ = w->glwDrawingArea.alphaSize; |
| 301 |
*ptr++ = GLX_DEPTH_SIZE; |
| 302 |
*ptr++ = w->glwDrawingArea.depthSize; |
| 303 |
*ptr++ = GLX_STENCIL_SIZE; |
| 304 |
*ptr++ = w->glwDrawingArea.stencilSize; |
| 305 |
*ptr++ = GLX_ACCUM_RED_SIZE; |
| 306 |
*ptr++ = w->glwDrawingArea.accumRedSize; |
| 307 |
*ptr++ = GLX_ACCUM_GREEN_SIZE; |
| 308 |
*ptr++ = w->glwDrawingArea.accumGreenSize; |
| 309 |
*ptr++ = GLX_ACCUM_BLUE_SIZE; |
| 310 |
*ptr++ = w->glwDrawingArea.accumBlueSize; |
| 311 |
*ptr++ = GLX_ACCUM_ALPHA_SIZE; |
| 312 |
*ptr++ = w->glwDrawingArea.accumAlphaSize; |
| 313 |
*ptr++ = None; |
| 314 |
assert((ptr-w->glwDrawingArea.attribList)<ATTRIBLIST_SIZE); |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
/* Initialize the visualInfo based on the attribute list */ |
| 320 |
static void createVisualInfo(GLwDrawingAreaWidget w){ |
| 321 |
assert(w->glwDrawingArea.attribList); |
| 322 |
w->glwDrawingArea.visualInfo=glXChooseVisual(XtDisplay(w),XScreenNumberOfScreen(XtScreen(w)),w->glwDrawingArea.attribList); |
| 323 |
if(!w->glwDrawingArea.visualInfo) error((Widget)w,"requested visual not supported"); |
| 324 |
} |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
/* Initialize the colormap based on the visual info. |
| 329 |
* This routine maintains a cache of visual-infos to colormaps. If two |
| 330 |
* widgets share the same visual info, they share the same colormap. |
| 331 |
* This function is called by the callProc of the colormap resource entry. |
| 332 |
*/ |
| 333 |
static void createColormap(GLwDrawingAreaWidget w,int offset,XrmValue *value){ |
| 334 |
static struct cmapCache { Visual *visual; Colormap cmap; } *cmapCache; |
| 335 |
static int cacheEntries=0; |
| 336 |
static int cacheMalloced=0; |
| 337 |
register int i; |
| 338 |
|
| 339 |
assert(w->glwDrawingArea.visualInfo); |
| 340 |
|
| 341 |
/* see if we can find it in the cache */ |
| 342 |
for(i=0; i<cacheEntries; i++){ |
| 343 |
if(cmapCache[i].visual==w->glwDrawingArea.visualInfo->visual){ |
| 344 |
value->addr=(XtPointer)(&cmapCache[i].cmap); |
| 345 |
return; |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
/* not in the cache, create a new entry */ |
| 350 |
if(cacheEntries >= cacheMalloced){ |
| 351 |
/* need to malloc a new one. Since we are likely to have only a |
| 352 |
* few colormaps, we allocate one the first time, and double |
| 353 |
* each subsequent time. |
| 354 |
*/ |
| 355 |
if(cacheMalloced==0){ |
| 356 |
cacheMalloced=1; |
| 357 |
cmapCache=(struct cmapCache*)XtMalloc(sizeof(struct cmapCache)); |
| 358 |
} |
| 359 |
else{ |
| 360 |
cacheMalloced<<=1; |
| 361 |
cmapCache=(struct cmapCache*)XtRealloc((char*)cmapCache,sizeof(struct cmapCache)*cacheMalloced); |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
cmapCache[cacheEntries].cmap=XCreateColormap(XtDisplay(w), |
| 366 |
RootWindow(XtDisplay(w), |
| 367 |
w->glwDrawingArea.visualInfo->screen), |
| 368 |
w->glwDrawingArea.visualInfo->visual, |
| 369 |
AllocNone); |
| 370 |
cmapCache[cacheEntries].visual=w->glwDrawingArea.visualInfo->visual; |
| 371 |
value->addr=(XtPointer)(&cmapCache[cacheEntries++].cmap); |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
static void Initialize(GLwDrawingAreaWidget req,GLwDrawingAreaWidget neww,ArgList args,Cardinal *num_args){ |
| 377 |
|
| 378 |
/* fix size */ |
| 379 |
if(req->core.width==0) neww->core.width=100; |
| 380 |
if(req->core.height==0) neww->core.width=100; |
| 381 |
|
| 382 |
/* create the attribute list if needed */ |
| 383 |
neww->glwDrawingArea.myList=FALSE; |
| 384 |
if(neww->glwDrawingArea.attribList==NULL){ |
| 385 |
neww->glwDrawingArea.myList=TRUE; |
| 386 |
createAttribList(neww); |
| 387 |
} |
| 388 |
|
| 389 |
/* Gotta have it */ |
| 390 |
assert(neww->glwDrawingArea.attribList); |
| 391 |
|
| 392 |
/* determine the visual info if needed */ |
| 393 |
neww->glwDrawingArea.myVisual=FALSE; |
| 394 |
if(neww->glwDrawingArea.visualInfo==NULL){ |
| 395 |
neww->glwDrawingArea.myVisual=TRUE; |
| 396 |
createVisualInfo(neww); |
| 397 |
} |
| 398 |
|
| 399 |
/* Gotta have that too */ |
| 400 |
assert(neww->glwDrawingArea.visualInfo); |
| 401 |
|
| 402 |
neww->core.depth=neww->glwDrawingArea.visualInfo->depth; |
| 403 |
|
| 404 |
/* Reobtain the colormap and colors in it using XtGetApplicationResources*/ |
| 405 |
XtGetApplicationResources((Widget)neww,neww,initializeResources,XtNumber(initializeResources),args,*num_args); |
| 406 |
|
| 407 |
/* obtain the color resources if appropriate */ |
| 408 |
if(req->glwDrawingArea.allocateBackground){ |
| 409 |
XtGetApplicationResources((Widget)neww,neww,backgroundResources,XtNumber(backgroundResources),args,*num_args); |
| 410 |
} |
| 411 |
|
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
static void Realize(Widget w,Mask *valueMask,XSetWindowAttributes *attributes){ |
| 417 |
register GLwDrawingAreaWidget glw=(GLwDrawingAreaWidget)w; |
| 418 |
GLwDrawingAreaCallbackStruct cb; |
| 419 |
Widget parentShell; |
| 420 |
Status status; |
| 421 |
Window windows[2],*windowsReturn,*windowList; |
| 422 |
int countReturn,i; |
| 423 |
|
| 424 |
/* if we haven't requested that the background be both installed and |
| 425 |
* allocated, don't install it. |
| 426 |
*/ |
| 427 |
if(!(glw->glwDrawingArea.installBackground && glw->glwDrawingArea.allocateBackground)){ |
| 428 |
*valueMask&=~CWBackPixel; |
| 429 |
} |
| 430 |
|
| 431 |
XtCreateWindow(w,(unsigned int)InputOutput,glw->glwDrawingArea.visualInfo->visual,*valueMask,attributes); |
| 432 |
|
| 433 |
/* if appropriate, call XSetWMColormapWindows to install the colormap */ |
| 434 |
if(glw->glwDrawingArea.installColormap){ |
| 435 |
|
| 436 |
/* Get parent shell */ |
| 437 |
for(parentShell=XtParent(w); parentShell&&!XtIsShell(parentShell); parentShell=XtParent(parentShell)); |
| 438 |
|
| 439 |
if(parentShell && XtWindow(parentShell)){ |
| 440 |
|
| 441 |
/* check to see if there is already a property */ |
| 442 |
status=XGetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),&windowsReturn,&countReturn); |
| 443 |
|
| 444 |
/* if no property, just create one */ |
| 445 |
if(!status){ |
| 446 |
windows[0]=XtWindow(w); |
| 447 |
windows[1]=XtWindow(parentShell); |
| 448 |
XSetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),windows,2); |
| 449 |
} |
| 450 |
|
| 451 |
/* there was a property, add myself to the beginning */ |
| 452 |
else{ |
| 453 |
windowList=(Window *)XtMalloc((sizeof(Window))*(countReturn+1)); |
| 454 |
windowList[0]=XtWindow(w); |
| 455 |
for(i=0; i<countReturn; i++) windowList[i+1]=windowsReturn[i]; |
| 456 |
XSetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),windowList,countReturn+1); |
| 457 |
XtFree((char*)windowList); |
| 458 |
XtFree((char*)windowsReturn); |
| 459 |
} |
| 460 |
} |
| 461 |
else{ |
| 462 |
warning(w,"Could not set colormap property on parent shell"); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
/* Invoke callbacks */ |
| 467 |
cb.reason=GLwCR_GINIT; |
| 468 |
cb.event=NULL; |
| 469 |
cb.width=glw->core.width; |
| 470 |
cb.height=glw->core.height; |
| 471 |
XtCallCallbackList((Widget)glw,glw->glwDrawingArea.ginitCallback,&cb); |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
static void Redraw(GLwDrawingAreaWidget w,XEvent *event,Region region){ |
| 477 |
GLwDrawingAreaCallbackStruct cb; |
| 478 |
if(!XtIsRealized((Widget)w)) return; |
| 479 |
cb.reason=GLwCR_EXPOSE; |
| 480 |
cb.event=event; |
| 481 |
cb.width=w->core.width; |
| 482 |
cb.height=w->core.height; |
| 483 |
XtCallCallbackList((Widget)w,w->glwDrawingArea.exposeCallback,&cb); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
static void Resize(GLwDrawingAreaWidget glw){ |
| 489 |
GLwDrawingAreaCallbackStruct cb; |
| 490 |
if(!XtIsRealized((Widget)glw)) return; |
| 491 |
cb.reason=GLwCR_RESIZE; |
| 492 |
cb.event=NULL; |
| 493 |
cb.width=glw->core.width; |
| 494 |
cb.height=glw->core.height; |
| 495 |
XtCallCallbackList((Widget)glw,glw->glwDrawingArea.resizeCallback,&cb); |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
static void Destroy(GLwDrawingAreaWidget glw){ |
| 501 |
Window *windowsReturn; |
| 502 |
Widget parentShell; |
| 503 |
Status status; |
| 504 |
int countReturn; |
| 505 |
register int i; |
| 506 |
|
| 507 |
if(glw->glwDrawingArea.myList && glw->glwDrawingArea.attribList){ |
| 508 |
XtFree((XtPointer)glw->glwDrawingArea.attribList); |
| 509 |
} |
| 510 |
|
| 511 |
if(glw->glwDrawingArea.myVisual && glw->glwDrawingArea.visualInfo){ |
| 512 |
XtFree((XtPointer)glw->glwDrawingArea.visualInfo); |
| 513 |
} |
| 514 |
|
| 515 |
/* if my colormap was installed, remove it */ |
| 516 |
if(glw->glwDrawingArea.installColormap){ |
| 517 |
|
| 518 |
/* Get parent shell */ |
| 519 |
for(parentShell=XtParent(glw); parentShell&&!XtIsShell(parentShell); parentShell=XtParent(parentShell)); |
| 520 |
|
| 521 |
if(parentShell && XtWindow(parentShell)){ |
| 522 |
|
| 523 |
/* make sure there is a property */ |
| 524 |
status=XGetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),&windowsReturn,&countReturn); |
| 525 |
|
| 526 |
/* if no property, just return. If there was a property, continue */ |
| 527 |
if(status){ |
| 528 |
|
| 529 |
/* search for a match */ |
| 530 |
for(i=0; i<countReturn; i++){ |
| 531 |
if(windowsReturn[i]==XtWindow(glw)){ |
| 532 |
|
| 533 |
/* we found a match, now copy the rest down */ |
| 534 |
for(i++; i<countReturn; i++){ windowsReturn[i-1]=windowsReturn[i]; } |
| 535 |
|
| 536 |
XSetWMColormapWindows(XtDisplay(parentShell),XtWindow(parentShell),windowsReturn,countReturn-1); |
| 537 |
break; |
| 538 |
} |
| 539 |
} |
| 540 |
XtFree((char *)windowsReturn); |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
/* Action routine for keyboard and mouse events */ |
| 549 |
static void glwInput(GLwDrawingAreaWidget glw,XEvent *event,String *params,Cardinal *numParams){ |
| 550 |
GLwDrawingAreaCallbackStruct cb; |
| 551 |
cb.reason=GLwCR_INPUT; |
| 552 |
cb.event=event; |
| 553 |
cb.width=glw->core.width; |
| 554 |
cb.height=glw->core.height; |
| 555 |
XtCallCallbackList((Widget)glw,glw->glwDrawingArea.inputCallback,&cb); |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
/* Make context current */ |
| 560 |
void GLwDrawingAreaMakeCurrent(Widget w,GLXContext ctx){ |
| 561 |
glXMakeCurrent(XtDisplay(w),XtWindow(w),ctx); |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
/* Swap buffers convenience function */ |
| 566 |
void GLwDrawingAreaSwapBuffers(Widget w){ |
| 567 |
glXSwapBuffers(XtDisplay(w),XtWindow(w)); |
| 568 |
} |
| 569 |
|