~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/glut/os2/WarpWin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* WarpWin.c     */
2
 
/* glut for Warp */
3
 
#include <stdio.h>
4
 
#include <string.h>
5
 
 
6
 
#include "WarpWin.h"
7
 
#include "WarpGL.h"
8
 
 
9
 
#define POKA 0
10
 
 
11
 
/* global variables that must be set for some functions to operate
12
 
   correctly. */
13
 
HDC XHDC;
14
 
HWND XHWND;
15
 
 
16
 
 
17
 
void
18
 
XStoreColor(Display* display, Colormap colormap, XColor* color)
19
 
{
20
 
  /* KLUDGE: set XHDC to 0 if the palette should NOT be realized after
21
 
     setting the color.  set XHDC to the correct HDC if it should. */
22
 
 
23
 
  LONG pe;
24
 
  ULONG cclr;
25
 
  int r,g,b;
26
 
  /* X11 stores color from 0-65535, Win32 expects them to be 0-256, so
27
 
     twiddle the bits ( / 256). */
28
 
  r = color->red / 256;
29
 
  g = color->green / 256;
30
 
  b = color->blue / 256;
31
 
  pe = LONGFromRGB(r,g,b);
32
 
  /* make sure we use this flag, otherwise the colors might get mapped
33
 
     to another place in the colormap, and when we glIndex() that
34
 
     color, it may have moved (argh!!) */
35
 
  pe |= (PC_NOCOLLAPSE<<24);
36
 
/* This function changes the entries in a palette.  */
37
 
#if POKA
38
 
OS2:
39
 
 rc = GpiSetPaletteEntries(colormap,LCOLF_CONSECRGB, color->pixel, 1, &pe);
40
 
 GpiSelectPalette(hps,colormap);
41
 
 WinRealizePalette(hwnd,hps,&cclr);
42
 
source Win:
43
 
  if (XHDC) {
44
 
    UnrealizeObject(colormap);
45
 
    SelectPalette(XHDC, colormap, FALSE);
46
 
    RealizePalette(XHDC);
47
 
 
48
 
   }
49
 
#endif
50
 
}
51
 
 
52
 
void
53
 
XSetWindowColormap(Display* display, Window window, Colormap colormap)
54
 
{
55
 
#if POKA
56
 
  HDC hdc = GetDC(window);
57
 
 
58
 
  /* if the third parameter is FALSE, the logical colormap is copied
59
 
     into the device palette when the application is in the
60
 
     foreground, if it is TRUE, the colors are mapped into the current
61
 
     palette in the best possible way. */
62
 
  SelectPalette(hdc, colormap, FALSE);
63
 
  RealizePalette(hdc);
64
 
 
65
 
  /* note that we don't have to release the DC, since our window class
66
 
     uses the WC_OWNDC flag! */
67
 
#endif
68
 
}
69
 
 
70
 
 
71
 
/* display, root and visual - don't used at all */
72
 
Colormap
73
 
XCreateColormap(Display* display, Window root, Visual* visual, int alloc)
74
 
{
75
 
  /* KLUDGE: this function needs XHDC to be set to the HDC currently
76
 
     being operated on before it is invoked! */
77
 
 
78
 
  HPAL    palette;
79
 
  int n;
80
 
#if POKA
81
 
  PIXELFORMATDESCRIPTOR pfd;
82
 
  LOGPALETTE *logical;
83
 
 
84
 
  /* grab the pixel format */
85
 
  memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
86
 
  DescribePixelFormat(XHDC, GetPixelFormat(XHDC),
87
 
                     sizeof(PIXELFORMATDESCRIPTOR), &pfd);
88
 
 
89
 
  if (!(pfd.dwFlags & PFD_NEED_PALETTE ||
90
 
      pfd.iPixelType == PFD_TYPE_COLORINDEX))
91
 
  {
92
 
    return 0;
93
 
  }
94
 
 
95
 
  n = 1 << pfd.cColorBits;
96
 
 
97
 
  /* allocate a bunch of memory for the logical palette (assume 256
98
 
     colors in a Win32 palette */
99
 
  logical = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) +
100
 
                               sizeof(PALETTEENTRY) * n);
101
 
  memset(logical, 0, sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * n);
102
 
 
103
 
  /* set the entries in the logical palette */
104
 
  logical->palVersion = 0x300;
105
 
  logical->palNumEntries = n;
106
 
 
107
 
  /* start with a copy of the current system palette */
108
 
  GetSystemPaletteEntries(XHDC, 0, 256, &logical->palPalEntry[0]);
109
 
 
110
 
  if (pfd.iPixelType == PFD_TYPE_RGBA) {
111
 
    int redMask = (1 << pfd.cRedBits) - 1;
112
 
    int greenMask = (1 << pfd.cGreenBits) - 1;
113
 
    int blueMask = (1 << pfd.cBlueBits) - 1;
114
 
    int i;
115
 
 
116
 
    /* fill in an RGBA color palette */
117
 
    for (i = 0; i < n; ++i) {
118
 
      logical->palPalEntry[i].peRed =
119
 
       (((i >> pfd.cRedShift)   & redMask)   * 255) / redMask;
120
 
      logical->palPalEntry[i].peGreen =
121
 
       (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask;
122
 
       logical->palPalEntry[i].peBlue =
123
 
       (((i >> pfd.cBlueShift)  & blueMask)  * 255) / blueMask;
124
 
      logical->palPalEntry[i].peFlags = 0;
125
 
    }
126
 
  }
127
 
 
128
 
  palette = CreatePalette(logical);
129
 
  free(logical);
130
 
 
131
 
  SelectPalette(XHDC, palette, FALSE);
132
 
  RealizePalette(XHDC);
133
 
#endif /* POKA */
134
 
 
135
 
  return palette;
136
 
}
137
 
 
138
 
 
139
 
 
140
 
int  GetSystemMetrics( int mode)
141
 
{  RECTL rect;
142
 
 
143
 
   switch(mode)
144
 
   {   case   SM_CXSCREEN:
145
 
        WinQueryWindowRect(HWND_DESKTOP,&rect);
146
 
        return (rect.xRight-rect.xLeft);
147
 
      break;
148
 
       case   SM_CYSCREEN:
149
 
        WinQueryWindowRect(HWND_DESKTOP,&rect);
150
 
        return (rect.yTop-rect.yBottom);
151
 
      break;
152
 
       default: ;
153
 
   }
154
 
   return 0;
155
 
}
156
 
/*
157
 
 *    XParseGeometry parses strings of the form
158
 
 *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
159
 
 *   width, height, xoffset, and yoffset are unsigned integers.
160
 
 *   Example:  "=80x24+300-49"
161
 
 *   The equal sign is optional.
162
 
 *   It returns a bitmask that indicates which of the four values
163
 
 *   were actually found in the string.  For each value found,
164
 
 *   the corresponding argument is updated;  for each value
165
 
 *   not found, the corresponding argument is left unchanged.
166
 
 */
167
 
 
168
 
static int
169
 
ReadInteger(char *string, char **NextString)
170
 
{
171
 
    register int Result = 0;
172
 
    int Sign = 1;
173
 
 
174
 
    if (*string == '+')
175
 
       string++;
176
 
    else if (*string == '-')
177
 
    {
178
 
       string++;
179
 
       Sign = -1;
180
 
    }
181
 
    for (; (*string >= '0') && (*string <= '9'); string++)
182
 
    {
183
 
       Result = (Result * 10) + (*string - '0');
184
 
    }
185
 
    *NextString = string;
186
 
    if (Sign >= 0)
187
 
       return (Result);
188
 
    else
189
 
       return (-Result);
190
 
}
191
 
 
192
 
int XParseGeometry(char *string, int *x, int *y, unsigned int *width, unsigned int *height)
193
 
{
194
 
       int mask = NoValue;
195
 
       register char *strind;
196
 
       unsigned int tempWidth, tempHeight;
197
 
       int tempX, tempY;
198
 
       char *nextCharacter;
199
 
 
200
 
       if ( (string == NULL) || (*string == '\0')) return(mask);
201
 
       if (*string == '=')
202
 
               string++;  /* ignore possible '=' at beg of geometry spec */
203
 
 
204
 
       strind = (char *)string;
205
 
       if (*strind != '+' && *strind != '-' && *strind != 'x') {
206
 
               tempWidth = ReadInteger(strind, &nextCharacter);
207
 
               if (strind == nextCharacter)
208
 
                   return (0);
209
 
               strind = nextCharacter;
210
 
               mask |= WidthValue;
211
 
       }
212
 
 
213
 
       if (*strind == 'x' || *strind == 'X') {
214
 
               strind++;
215
 
               tempHeight = ReadInteger(strind, &nextCharacter);
216
 
               if (strind == nextCharacter)
217
 
                   return (0);
218
 
               strind = nextCharacter;
219
 
               mask |= HeightValue;
220
 
       }
221
 
 
222
 
       if ((*strind == '+') || (*strind == '-')) {
223
 
               if (*strind == '-') {
224
 
                       strind++;
225
 
                       tempX = -ReadInteger(strind, &nextCharacter);
226
 
                       if (strind == nextCharacter)
227
 
                           return (0);
228
 
                       strind = nextCharacter;
229
 
                       mask |= XNegative;
230
 
 
231
 
               }
232
 
               else
233
 
               {       strind++;
234
 
                       tempX = ReadInteger(strind, &nextCharacter);
235
 
                       if (strind == nextCharacter)
236
 
                           return(0);
237
 
                       strind = nextCharacter;
238
 
               }
239
 
               mask |= XValue;
240
 
               if ((*strind == '+') || (*strind == '-')) {
241
 
                       if (*strind == '-') {
242
 
                               strind++;
243
 
                               tempY = -ReadInteger(strind, &nextCharacter);
244
 
                               if (strind == nextCharacter)
245
 
                                   return(0);
246
 
                               strind = nextCharacter;
247
 
                               mask |= YNegative;
248
 
 
249
 
                       }
250
 
                       else
251
 
                       {
252
 
                               strind++;
253
 
                               tempY = ReadInteger(strind, &nextCharacter);
254
 
                               if (strind == nextCharacter)
255
 
                                   return(0);
256
 
                               strind = nextCharacter;
257
 
                       }
258
 
                       mask |= YValue;
259
 
               }
260
 
       }
261
 
 
262
 
       /* If strind isn't at the end of the string the it's an invalid
263
 
               geometry specification. */
264
 
 
265
 
       if (*strind != '\0') return (0);
266
 
 
267
 
       if (mask & XValue)
268
 
           *x = tempX;
269
 
       if (mask & YValue)
270
 
           *y = tempY;
271
 
       if (mask & WidthValue)
272
 
            *width = tempWidth;
273
 
       if (mask & HeightValue)
274
 
            *height = tempHeight;
275
 
       return (mask);
276
 
}
277
 
 
278
 
int gettimeofday(struct timeval* tp, void* tzp)
279
 
{
280
 
 DATETIME    DateTime;
281
 
 APIRET       ulrc;  /*  Return Code. */
282
 
 
283
 
 ulrc = DosGetDateTime(&DateTime);
284
 
 tp->tv_sec  = 60 * (60*DateTime.hours + DateTime.minutes) + DateTime.seconds;
285
 
 tp->tv_usec = DateTime.hundredths * 10000;
286
 
 return 0;
287
 
}
288
 
 
289
 
 
290
 
int
291
 
XPending(Display* display)
292
 
{
293
 
  /* similar functionality...I don't think that it is exact, but this
294
 
     will have to do. */
295
 
  QMSG msg;
296
 
  extern HAB   hab;      /* PM anchor block handle         */
297
 
 
298
 
//?? WinPeekMsg(hab
299
 
  return WinPeekMsg(hab, &msg, NULLHANDLE, 0, 0, PM_NOREMOVE);
300
 
}
301
 
 
302
 
void
303
 
__glutAdjustCoords(Window parent, int* x, int* y, int* width, int* height)
304
 
{
305
 
  RECTL rect;
306
 
 
307
 
  /* adjust the window rectangle because Win32 thinks that the x, y,
308
 
     width & height are the WHOLE window (including decorations),
309
 
     whereas GLUT treats the x, y, width & height as only the CLIENT
310
 
     area of the window. */
311
 
  rect.xLeft = *x; rect.yTop = *y;
312
 
  rect.xRight = *x + *width; rect.yBottom = *y + *height;
313
 
 
314
 
  /* must adjust the coordinates according to the correct style
315
 
     because depending on the style, there may or may not be
316
 
     borders. */
317
 
//??  AdjustWindowRect(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
318
 
//??              (parent ? WS_CHILD : WS_OVERLAPPEDWINDOW),
319
 
//??              FALSE);
320
 
  /* FALSE in the third parameter = window has no menu bar */
321
 
 
322
 
  /* readjust if the x and y are offscreen */
323
 
  if(rect.xLeft < 0) {
324
 
    *x = 0;
325
 
  } else {
326
 
    *x = rect.xLeft;
327
 
  }
328
 
 
329
 
  if(rect.yTop < 0) {
330
 
    *y = 0;
331
 
  } else {
332
 
    *y = rect.yTop;
333
 
  }
334
 
 
335
 
  *width = rect.xRight - rect.xLeft;     /* adjusted width */
336
 
  *height = -(rect.yBottom - rect.yTop);    /* adjusted height */
337
 
}
338
 
 
339
 
 
340
 
int
341
 
__glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
342
 
{
343
 
  /* the transparent pixel on Win32 is always index number 0.  So if
344
 
     we put this routine in this file, we can avoid compiling the
345
 
     whole of layerutil.c which is where this routine normally comes
346
 
     from. */
347
 
  return 0;
348
 
}
349
 
 
350
 
/* Translate point coordinates src_x and src_y from src to dst */
351
 
 
352
 
Bool
353
 
XTranslateCoordinates(Display *display, Window src, Window dst,
354
 
                     int src_x, int src_y,
355
 
                     int* dest_x_return, int* dest_y_return,
356
 
                     Window* child_return)
357
 
{
358
 
  SWP swp_src,swp_dst;
359
 
 
360
 
  WinQueryWindowPos(src,&swp_src);
361
 
  WinQueryWindowPos(dst,&swp_dst);
362
 
 
363
 
  *dest_x_return =  src_x + swp_src.x - swp_dst.x;
364
 
  *dest_y_return =  src_y + swp_src.y - swp_dst.y;
365
 
 
366
 
  /* just to make compilers happy...we don't use the return value. */
367
 
  return True;
368
 
}
369
 
 
370
 
Status
371
 
XGetGeometry(Display* display, Window window, Window* root_return,
372
 
            int* x_return, int* y_return,
373
 
            unsigned int* width_return, unsigned int* height_return,
374
 
            unsigned int *border_width_return, unsigned int* depth_return)
375
 
{
376
 
  /* KLUDGE: doesn't return the border_width or depth or root, x & y
377
 
     are in screen coordinates. */
378
 
  SWP swp_src;
379
 
  WinQueryWindowPos(window,&swp_src);
380
 
 
381
 
  *x_return = swp_src.x;
382
 
  *y_return = swp_src.y;
383
 
  *width_return = swp_src.cx;
384
 
  *height_return = swp_src.cy;
385
 
 
386
 
  /* just to make compilers happy...we don't use the return value. */
387
 
  return 1;
388
 
}
389
 
 
390
 
/* Get Display Width in millimeters */
391
 
int
392
 
DisplayWidthMM(Display* display, int screen)
393
 
{
394
 
  int width;
395
 
  LONG *pVC_Caps;
396
 
  pVC_Caps = GetVideoConfig(NULLHANDLE);
397
 
  width = (int)( 0.001 * pVC_Caps[CAPS_WIDTH]  / pVC_Caps[CAPS_HORIZONTAL_RESOLUTION]);/* mm */
398
 
  return width;
399
 
}
400
 
 
401
 
/* Get Display Height in millimeters */
402
 
int
403
 
DisplayHeightMM(Display* display, int screen)
404
 
{
405
 
  int height;
406
 
  LONG *pVC_Caps;
407
 
  pVC_Caps = GetVideoConfig(NULLHANDLE);
408
 
  height = (int)( 0.001 * pVC_Caps[CAPS_HEIGHT] / pVC_Caps[CAPS_VERTICAL_RESOLUTION]); /* mm */
409
 
  return height;
410
 
}
411
 
 
412
 
void ScreenToClient( HWND hwnd,   POINTL *point)
413
 
{
414
 
  SWP swp_src;
415
 
  WinQueryWindowPos(hwnd,&swp_src);
416
 
  point->x -= swp_src.x;
417
 
  point->y -= swp_src.y;
418
 
}
419
 
 
420
 

 
 
b'\\ No newline at end of file'