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