11 /* global variables that must be set for some functions to operate
18 XStoreColor(Display
* display
, Colormap colormap
, XColor
* color
)
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. */
26 /* X11 stores color from 0-65535, Win32 expects them to be 0-256, so
27 twiddle the bits ( / 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. */
39 rc
= GpiSetPaletteEntries(colormap
,LCOLF_CONSECRGB
, color
->pixel
, 1, &pe
);
40 GpiSelectPalette(hps
,colormap
);
41 WinRealizePalette(hwnd
,hps
,&cclr
);
44 UnrealizeObject(colormap
);
45 SelectPalette(XHDC
, colormap
, FALSE
);
53 XSetWindowColormap(Display
* display
, Window window
, Colormap colormap
)
56 HDC hdc
= GetDC(window
);
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
);
65 /* note that we don't have to release the DC, since our window class
66 uses the WC_OWNDC flag! */
71 /* display, root and visual - don't used at all */
73 XCreateColormap(Display
* display
, Window root
, Visual
* visual
, int alloc
)
75 /* KLUDGE: this function needs XHDC to be set to the HDC currently
76 being operated on before it is invoked! */
81 PIXELFORMATDESCRIPTOR pfd
;
84 /* grab the pixel format */
85 memset(&pfd
, 0, sizeof(PIXELFORMATDESCRIPTOR
));
86 DescribePixelFormat(XHDC
, GetPixelFormat(XHDC
),
87 sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
89 if (!(pfd
.dwFlags
& PFD_NEED_PALETTE
||
90 pfd
.iPixelType
== PFD_TYPE_COLORINDEX
))
95 n
= 1 << pfd
.cColorBits
;
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
);
103 /* set the entries in the logical palette */
104 logical
->palVersion
= 0x300;
105 logical
->palNumEntries
= n
;
107 /* start with a copy of the current system palette */
108 GetSystemPaletteEntries(XHDC
, 0, 256, &logical
->palPalEntry
[0]);
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;
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;
128 palette
= CreatePalette(logical
);
131 SelectPalette(XHDC
, palette
, FALSE
);
132 RealizePalette(XHDC
);
140 int GetSystemMetrics( int mode
)
145 WinQueryWindowRect(HWND_DESKTOP
,&rect
);
146 return (rect
.xRight
-rect
.xLeft
);
149 WinQueryWindowRect(HWND_DESKTOP
,&rect
);
150 return (rect
.yTop
-rect
.yBottom
);
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.
169 ReadInteger(char *string
, char **NextString
)
171 register int Result
= 0;
176 else if (*string
== '-')
181 for (; (*string
>= '0') && (*string
<= '9'); string
++)
183 Result
= (Result
* 10) + (*string
- '0');
185 *NextString
= string
;
192 int XParseGeometry(char *string
, int *x
, int *y
, unsigned int *width
, unsigned int *height
)
195 register char *strind
;
196 unsigned int tempWidth
, tempHeight
;
200 if ( (string
== NULL
) || (*string
== '\0')) return(mask
);
202 string
++; /* ignore possible '=' at beg of geometry spec */
204 strind
= (char *)string
;
205 if (*strind
!= '+' && *strind
!= '-' && *strind
!= 'x') {
206 tempWidth
= ReadInteger(strind
, &nextCharacter
);
207 if (strind
== nextCharacter
)
209 strind
= nextCharacter
;
213 if (*strind
== 'x' || *strind
== 'X') {
215 tempHeight
= ReadInteger(strind
, &nextCharacter
);
216 if (strind
== nextCharacter
)
218 strind
= nextCharacter
;
222 if ((*strind
== '+') || (*strind
== '-')) {
223 if (*strind
== '-') {
225 tempX
= -ReadInteger(strind
, &nextCharacter
);
226 if (strind
== nextCharacter
)
228 strind
= nextCharacter
;
234 tempX
= ReadInteger(strind
, &nextCharacter
);
235 if (strind
== nextCharacter
)
237 strind
= nextCharacter
;
240 if ((*strind
== '+') || (*strind
== '-')) {
241 if (*strind
== '-') {
243 tempY
= -ReadInteger(strind
, &nextCharacter
);
244 if (strind
== nextCharacter
)
246 strind
= nextCharacter
;
253 tempY
= ReadInteger(strind
, &nextCharacter
);
254 if (strind
== nextCharacter
)
256 strind
= nextCharacter
;
262 /* If strind isn't at the end of the string the it's an invalid
263 geometry specification. */
265 if (*strind
!= '\0') return (0);
271 if (mask
& WidthValue
)
273 if (mask
& HeightValue
)
274 *height
= tempHeight
;
278 int gettimeofday(struct timeval
* tp
, void* tzp
)
281 APIRET ulrc
; /* Return Code. */
283 ulrc
= DosGetDateTime(&DateTime
);
284 tp
->tv_sec
= 60 * (60*DateTime
.hours
+ DateTime
.minutes
) + DateTime
.seconds
;
285 tp
->tv_usec
= DateTime
.hundredths
* 10000;
291 XPending(Display
* display
)
293 /* similar functionality...I don't think that it is exact, but this
296 extern HAB hab
; /* PM anchor block handle */
299 return WinPeekMsg(hab
, &msg
, NULLHANDLE
, 0, 0, PM_NOREMOVE
);
303 __glutAdjustCoords(Window parent
, int* x
, int* y
, int* width
, int* height
)
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
;
314 /* must adjust the coordinates according to the correct style
315 because depending on the style, there may or may not be
317 //?? AdjustWindowRect(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
318 //?? (parent ? WS_CHILD : WS_OVERLAPPEDWINDOW),
320 /* FALSE in the third parameter = window has no menu bar */
322 /* readjust if the x and y are offscreen */
335 *width
= rect
.xRight
- rect
.xLeft
; /* adjusted width */
336 *height
= -(rect
.yBottom
- rect
.yTop
); /* adjusted height */
341 __glutGetTransparentPixel(Display
* dpy
, XVisualInfo
* vinfo
)
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
350 /* Translate point coordinates src_x and src_y from src to dst */
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
)
360 WinQueryWindowPos(src
,&swp_src
);
361 WinQueryWindowPos(dst
,&swp_dst
);
363 *dest_x_return
= src_x
+ swp_src
.x
- swp_dst
.x
;
364 *dest_y_return
= src_y
+ swp_src
.y
- swp_dst
.y
;
366 /* just to make compilers happy...we don't use the return value. */
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
)
376 /* KLUDGE: doesn't return the border_width or depth or root, x & y
377 are in screen coordinates. */
379 WinQueryWindowPos(window
,&swp_src
);
381 *x_return
= swp_src
.x
;
382 *y_return
= swp_src
.y
;
383 *width_return
= swp_src
.cx
;
384 *height_return
= swp_src
.cy
;
386 /* just to make compilers happy...we don't use the return value. */
390 /* Get Display Width in millimeters */
392 DisplayWidthMM(Display
* display
, int screen
)
396 pVC_Caps
= GetVideoConfig(NULLHANDLE
);
397 width
= (int)( 0.001 * pVC_Caps
[CAPS_WIDTH
] / pVC_Caps
[CAPS_HORIZONTAL_RESOLUTION
]);/* mm */
401 /* Get Display Height in millimeters */
403 DisplayHeightMM(Display
* display
, int screen
)
407 pVC_Caps
= GetVideoConfig(NULLHANDLE
);
408 height
= (int)( 0.001 * pVC_Caps
[CAPS_HEIGHT
] / pVC_Caps
[CAPS_VERTICAL_RESOLUTION
]); /* mm */
412 void ScreenToClient( HWND hwnd
, POINTL
*point
)
415 WinQueryWindowPos(hwnd
,&swp_src
);
416 point
->x
-= swp_src
.x
;
417 point
->y
-= swp_src
.y
;