| 1 | /* $Id: win32_util.c,v 1.2 2000-02-09 08:46:22 jeroen Exp $ */
|
|---|
| 2 | /* Copyright (c) Nate Robins, 1997. */
|
|---|
| 3 |
|
|---|
| 4 | /* portions Copyright (c) Mark Kilgard, 1997, 1998. */
|
|---|
| 5 |
|
|---|
| 6 | /* This program is freely distributable without licensing fees
|
|---|
| 7 | and is provided without guarantee or warrantee expressed or
|
|---|
| 8 | implied. This program is -not- in the public domain. */
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 | #include "glutint.h"
|
|---|
| 12 | #include "glutstroke.h"
|
|---|
| 13 | #include "glutbitmap.h"
|
|---|
| 14 | #if defined(__CYGWIN32__)
|
|---|
| 15 | typedef MINMAXINFO* LPMINMAXINFO;
|
|---|
| 16 | #else
|
|---|
| 17 | #include <sys/timeb.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | extern const StrokeFontRec glutStrokeRoman, glutStrokeMonoRoman;
|
|---|
| 21 | extern const BitmapFontRec glutBitmap8By13, glutBitmap9By15,
|
|---|
| 22 | glutBitmapTimesRoman10,glutBitmapTimesRoman24,
|
|---|
| 23 | glutBitmapHelvetica10, glutBitmapHelvetica12,
|
|---|
| 24 | glutBitmapHelvetica18;
|
|---|
| 25 |
|
|---|
| 26 | int
|
|---|
| 27 | gettimeofday(struct timeval* tp, void* tzp)
|
|---|
| 28 | {
|
|---|
| 29 | struct timeb tb;
|
|---|
| 30 |
|
|---|
| 31 | ftime(&tb);
|
|---|
| 32 | tp->tv_sec = tb.time;
|
|---|
| 33 | tp->tv_usec = tb.millitm * 1000;
|
|---|
| 34 |
|
|---|
| 35 | /* 0 indicates that the call succeeded. */
|
|---|
| 36 | return 0;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | /* To get around the fact that Microsoft DLLs only allow functions
|
|---|
| 40 | to be exported and now data addresses (as Unix DSOs support), the
|
|---|
| 41 | GLUT API constants such as GLUT_STROKE_ROMAN have to get passed
|
|---|
| 42 | through a case statement to get mapped to the actual data structure
|
|---|
| 43 | address. */
|
|---|
| 44 | void*
|
|---|
| 45 | __glutFont(void *font)
|
|---|
| 46 | {
|
|---|
| 47 | switch((int)font) {
|
|---|
| 48 | case I_GLUT_STROKE_ROMAN:
|
|---|
| 49 | return (void *)&glutStrokeRoman;
|
|---|
| 50 | case I_GLUT_STROKE_MONO_ROMAN:
|
|---|
| 51 | return (void *)&glutStrokeMonoRoman;
|
|---|
| 52 | case I_GLUT_BITMAP_9_BY_15:
|
|---|
| 53 | return (void *)&glutBitmap9By15;
|
|---|
| 54 | case I_GLUT_BITMAP_8_BY_13:
|
|---|
| 55 | return (void *)&glutBitmap8By13;
|
|---|
| 56 | case I_GLUT_BITMAP_TIMES_ROMAN_10:
|
|---|
| 57 | return (void *)&glutBitmapTimesRoman10;
|
|---|
| 58 | case I_GLUT_BITMAP_TIMES_ROMAN_24:
|
|---|
| 59 | return (void *)&glutBitmapTimesRoman24;
|
|---|
| 60 | case I_GLUT_BITMAP_HELVETICA_10:
|
|---|
| 61 | return (void *)&glutBitmapHelvetica10;
|
|---|
| 62 | case I_GLUT_BITMAP_HELVETICA_12:
|
|---|
| 63 | return (void *)&glutBitmapHelvetica12;
|
|---|
| 64 | case I_GLUT_BITMAP_HELVETICA_18:
|
|---|
| 65 | return (void *)&glutBitmapHelvetica18;
|
|---|
| 66 | }
|
|---|
| 67 | __glutFatalError("out of memory.");
|
|---|
| 68 | /* NOTREACHED */
|
|---|
| 69 | return NULL;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | int
|
|---|
| 73 | __glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
|
|---|
| 74 | {
|
|---|
| 75 | /* the transparent pixel on Win32 is always index number 0. So if
|
|---|
| 76 | we put this routine in this file, we can avoid compiling the
|
|---|
| 77 | whole of layerutil.c which is where this routine normally comes
|
|---|
| 78 | from. */
|
|---|
| 79 | return 0;
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | void
|
|---|
| 83 | __glutAdjustCoords(Window parent, int* x, int* y, int* width, int* height)
|
|---|
| 84 | {
|
|---|
| 85 | RECT rect;
|
|---|
| 86 |
|
|---|
| 87 | /* adjust the window rectangle because Win32 thinks that the x, y,
|
|---|
| 88 | width & height are the WHOLE window (including decorations),
|
|---|
| 89 | whereas GLUT treats the x, y, width & height as only the CLIENT
|
|---|
| 90 | area of the window. */
|
|---|
| 91 | rect.left = *x; rect.top = *y;
|
|---|
| 92 | rect.right = *x + *width; rect.bottom = *y + *height;
|
|---|
| 93 |
|
|---|
| 94 | /* must adjust the coordinates according to the correct style
|
|---|
| 95 | because depending on the style, there may or may not be
|
|---|
| 96 | borders. */
|
|---|
| 97 | AdjustWindowRect(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
|
|---|
| 98 | (parent ? WS_CHILD : WS_OVERLAPPEDWINDOW),
|
|---|
| 99 | FALSE);
|
|---|
| 100 | /* FALSE in the third parameter = window has no menu bar */
|
|---|
| 101 |
|
|---|
| 102 | /* readjust if the x and y are offscreen */
|
|---|
| 103 | if(rect.left < 0) {
|
|---|
| 104 | *x = 0;
|
|---|
| 105 | } else {
|
|---|
| 106 | *x = rect.left;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | if(rect.top < 0) {
|
|---|
| 110 | *y = 0;
|
|---|
| 111 | } else {
|
|---|
| 112 | *y = rect.top;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | *width = rect.right - rect.left; /* adjusted width */
|
|---|
| 116 | *height = rect.bottom - rect.top; /* adjusted height */
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|