1
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#include <sys/timeb.h>
15
16/* The following added by Paul Garceau <pgarceau@teleport.com> */
17#if defined(__MINGW32__)
18#include <GL/gl.h>
19#include <time.h>
20#include <windows.h>
21struct timeval;
22#endif
23
24extern StrokeFontRec glutStrokeRoman, glutStrokeMonoRoman;
25extern BitmapFontRec glutBitmap8By13, glutBitmap9By15, glutBitmapTimesRoman10, glutBitmapTimesRoman24, glutBitmapHelvetica10, glutBitmapHelvetica12, glutBitmapHelvetica18;
26
27#ifndef __CYGWIN32__
28int
29gettimeofday(struct timeval* tp, void* tzp)
30{
31  struct timeb tb;
32
33  ftime(&tb);
34  tp->tv_sec = tb.time;
35  tp->tv_usec = tb.millitm * 1000;
36
37  /* 0 indicates that the call succeeded. */
38  return 0;
39}
40#endif
41
42/* To get around the fact that Microsoft DLLs only allow functions
43   to be exported and now data addresses (as Unix DSOs support), the
44   GLUT API constants such as GLUT_STROKE_ROMAN have to get passed
45   through a case statement to get mapped to the actual data structure
46   address. */
47void*
48__glutFont(void *font)
49{
50  switch((int)font) {
51  case (int)GLUT_STROKE_ROMAN:
52    return &glutStrokeRoman;
53  case (int)GLUT_STROKE_MONO_ROMAN:
54    return &glutStrokeMonoRoman;
55  case (int)GLUT_BITMAP_9_BY_15:
56    return &glutBitmap9By15;
57  case (int)GLUT_BITMAP_8_BY_13:
58    return &glutBitmap8By13;
59  case (int)GLUT_BITMAP_TIMES_ROMAN_10:
60    return &glutBitmapTimesRoman10;
61  case (int)GLUT_BITMAP_TIMES_ROMAN_24:
62    return &glutBitmapTimesRoman24;
63  case (int)GLUT_BITMAP_HELVETICA_10:
64    return &glutBitmapHelvetica10;
65  case (int)GLUT_BITMAP_HELVETICA_12:
66    return &glutBitmapHelvetica12;
67  case (int)GLUT_BITMAP_HELVETICA_18:
68    return &glutBitmapHelvetica18;
69  }
70  __glutFatalError("font not found.");
71  /* NOTREACHED */
72  return NULL; /* MSVC compiler complains if there is no return at all */
73}
74
75int
76__glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
77{
78  /* the transparent pixel on Win32 is always index number 0.  So if
79     we put this routine in this file, we can avoid compiling the
80     whole of layerutil.c which is where this routine normally comes
81     from. */
82  return 0;
83}
84
85void
86__glutAdjustCoords(Window parent, int* x, int* y, int* width, int* height)
87{
88  RECT rect;
89
90  /* adjust the window rectangle because Win32 thinks that the x, y,
91     width & height are the WHOLE window (including decorations),
92     whereas GLUT treats the x, y, width & height as only the CLIENT
93     area of the window. */
94  rect.left = *x; rect.top = *y;
95  rect.right = *x + *width; rect.bottom = *y + *height;
96
97  /* must adjust the coordinates according to the correct style
98     because depending on the style, there may or may not be
99     borders. */
100  AdjustWindowRect(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
101		   (parent ? WS_CHILD : WS_OVERLAPPEDWINDOW),
102		   FALSE);
103  /* FALSE in the third parameter = window has no menu bar */
104
105  /* readjust if the x and y are offscreen */
106  if(rect.left < 0) {
107    *x = 0;
108  } else {
109    *x = rect.left;
110  }
111
112  if(rect.top < 0) {
113    *y = 0;
114  } else {
115    *y = rect.top;
116  }
117
118  *width = rect.right - rect.left;	/* adjusted width */
119  *height = rect.bottom - rect.top;	/* adjusted height */
120}
121
122