initial check-in
[mesa.git] / src / glut / beos / beos_x11.cpp
1
2 /* Copyright (c) Nate Robins, 1997. */
3
4 /* This program is freely distributable without licensing fees
5 and is provided without guarantee or warrantee expressed or
6 implied. This program is -not- in the public domain. */
7
8 #include <Screen.h>
9 #include <stdio.h>
10 #include "beos_x11.h"
11
12 /* NOTE: These functions require a BApplication to be instantiated first */
13 int DisplayWidth() {
14 BScreen s;
15 return s.Frame().IntegerWidth() + 1;
16 }
17
18 int DisplayHeight() {
19 BScreen s;
20 return s.Frame().IntegerHeight() + 1;
21 }
22
23 /* the following function was stolen from the X sources as indicated. */
24
25 /* Copyright Massachusetts Institute of Technology 1985, 1986, 1987 */
26 /* $XConsortium: XParseGeom.c,v 11.18 91/02/21 17:23:05 rws Exp $ */
27
28 /*
29 Permission to use, copy, modify, distribute, and sell this software and its
30 documentation for any purpose is hereby granted without fee, provided that
31 the above copyright notice appear in all copies and that both that
32 copyright notice and this permission notice appear in supporting
33 documentation, and that the name of M.I.T. not be used in advertising or
34 publicity pertaining to distribution of the software without specific,
35 written prior permission. M.I.T. makes no representations about the
36 suitability of this software for any purpose. It is provided "as is"
37 without express or implied warranty.
38 */
39
40 /*
41 *Returns pointer to first char ins search which is also in what, else NULL.
42 */
43 static char *strscan (char *search, char *what)
44 {
45 int i, len = strlen (what);
46 char c;
47
48 while ((c = *(search++)) != (int)NULL)
49 for (i = 0; i < len; i++)
50 if (c == what [i])
51 return (--search);
52 return (NULL);
53 }
54
55 /*
56 * XParseGeometry parses strings of the form
57 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
58 * width, height, xoffset, and yoffset are unsigned integers.
59 * Example: "=80x24+300-49"
60 * The equal sign is optional.
61 * It returns a bitmask that indicates which of the four values
62 * were actually found in the string. For each value found,
63 * the corresponding argument is updated; for each value
64 * not found, the corresponding argument is left unchanged.
65 */
66
67 static int
68 ReadInteger(char *string, char **NextString)
69 {
70 register int Result = 0;
71 int Sign = 1;
72
73 if (*string == '+')
74 string++;
75 else if (*string == '-')
76 {
77 string++;
78 Sign = -1;
79 }
80 for (; (*string >= '0') && (*string <= '9'); string++)
81 {
82 Result = (Result * 10) + (*string - '0');
83 }
84 *NextString = string;
85 if (Sign >= 0)
86 return (Result);
87 else
88 return (-Result);
89 }
90
91 int XParseGeometry (char *string, int *x, int *y,
92 unsigned int *width, unsigned int *height)
93 {
94 int mask = NoValue;
95 register char *strind;
96 unsigned int tempWidth=0, tempHeight=0;
97 int tempX=0, tempY=0;
98 char *nextCharacter;
99
100 if ( (string == NULL) || (*string == '\0')) return(mask);
101 if (*string == '=')
102 string++; /* ignore possible '=' at beg of geometry spec */
103
104 strind = (char *)string;
105 if (*strind != '+' && *strind != '-' && *strind != 'x') {
106 tempWidth = ReadInteger(strind, &nextCharacter);
107 if (strind == nextCharacter)
108 return (0);
109 strind = nextCharacter;
110 mask |= WidthValue;
111 }
112
113 if (*strind == 'x' || *strind == 'X') {
114 strind++;
115 tempHeight = ReadInteger(strind, &nextCharacter);
116 if (strind == nextCharacter)
117 return (0);
118 strind = nextCharacter;
119 mask |= HeightValue;
120 }
121
122 if ((*strind == '+') || (*strind == '-')) {
123 if (*strind == '-') {
124 strind++;
125 tempX = -ReadInteger(strind, &nextCharacter);
126 if (strind == nextCharacter)
127 return (0);
128 strind = nextCharacter;
129 mask |= XNegative;
130
131 }
132 else
133 { strind++;
134 tempX = ReadInteger(strind, &nextCharacter);
135 if (strind == nextCharacter)
136 return(0);
137 strind = nextCharacter;
138 }
139 mask |= XValue;
140 if ((*strind == '+') || (*strind == '-')) {
141 if (*strind == '-') {
142 strind++;
143 tempY = -ReadInteger(strind, &nextCharacter);
144 if (strind == nextCharacter)
145 return(0);
146 strind = nextCharacter;
147 mask |= YNegative;
148
149 }
150 else
151 {
152 strind++;
153 tempY = ReadInteger(strind, &nextCharacter);
154 if (strind == nextCharacter)
155 return(0);
156 strind = nextCharacter;
157 }
158 mask |= YValue;
159 }
160 }
161
162 /* If strind isn't at the end of the string the it's an invalid
163 geometry specification. */
164
165 if (*strind != '\0') return (0);
166
167 if (mask & XValue)
168 *x = tempX;
169 if (mask & YValue)
170 *y = tempY;
171 if (mask & WidthValue)
172 *width = tempWidth;
173 if (mask & HeightValue)
174 *height = tempHeight;
175 return (mask);
176 }