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