1 /* $Id$Revision: */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 #ifndef GLCOMPDEFS_H
14 #define GLCOMPDEFS_H
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <stdarg.h>
20 #include <math.h>
21 #ifdef _WIN32
22 #include <windows.h>
23 #include <winuser.h>
24 #include <tchar.h>
25 #endif
26 #include <GL/gl.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <GL/gl.h>
30 #include <GL/glu.h>
31 #ifdef _WIN32
32 #define strdup _strdup
33 #endif
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 
40 #define	GLCOMPSET_PANEL_COLOR_R		(GLfloat)0.16
41 #define	GLCOMPSET_PANEL_COLOR_G		(GLfloat)0.44
42 #define	GLCOMPSET_PANEL_COLOR_B		(GLfloat)0.87
43 #define	GLCOMPSET_PANEL_COLOR_ALPHA	(GLfloat)0.5
44 #define	GLCOMPSET_PANEL_SHADOW_COLOR_R		(GLfloat)0
45 #define	GLCOMPSET_PANEL_SHADOW_COLOR_G		(GLfloat)0
46 #define	GLCOMPSET_PANEL_SHADOW_COLOR_B		(GLfloat)0
47 #define	GLCOMPSET_PANEL_SHADOW_COLOR_A		(GLfloat)0.3
48 #define GLCOMPSET_PANEL_SHADOW_WIDTH		(GLfloat)4
49 
50 #define	GLCOMPSET_BUTTON_COLOR_R		(GLfloat)0
51 #define	GLCOMPSET_BUTTON_COLOR_G		(GLfloat)1
52 #define	GLCOMPSET_BUTTON_COLOR_B		(GLfloat)0.3
53 #define	GLCOMPSET_BUTTON_COLOR_ALPHA	(GLfloat)0.6
54 #define	GLCOMPSET_BUTTON_THICKNESS		(GLfloat)3
55 #define	GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS		(GLfloat)1.7
56 #define GLCOMPSET_FONT_SIZE				(GLfloat)14
57 
58 #define	GLCOMPSET_BUTTON_FONT_COLOR_R		(GLfloat)0
59 #define	GLCOMPSET_BUTTON_FONT_COLOR_G		(GLfloat)0
60 #define	GLCOMPSET_BUTTON_FONT_COLOR_B		(GLfloat)0
61 #define	GLCOMPSET_BUTTON_FONT_COLOR_ALPHA	(GLfloat)1
62 
63 #define GLCOMPSET_FONT_SIZE_FACTOR			(GLfloat)0.7
64 
65 #define	GLCOMPSET_LABEL_COLOR_R		(GLfloat)0
66 #define	GLCOMPSET_LABEL_COLOR_G		(GLfloat)0
67 #define	GLCOMPSET_LABEL_COLOR_B		(GLfloat)0
68 #define	GLCOMPSET_LABEL_COLOR_ALPHA	(GLfloat)1
69 
70 #define	GLCOMPSET_FONT_COLOR_R		(GLfloat)0
71 #define	GLCOMPSET_FONT_COLOR_G		(GLfloat)0
72 #define	GLCOMPSET_FONT_COLOR_B		(GLfloat)0
73 #define	GLCOMPSET_FONT_COLOR_ALPHA	(GLfloat)1
74 #define GLCOMPSET_FONT_DESC  "Times Italic"
75 #define GL_FONTOPTIMIZE 1
76 
77 
78 #define GL_FONTVJUSTIFY	0
79 #define GL_FONTHJUSTIFY	0
80 
81 
82 #define DEFAULT_GLUT_FONT GLUT_BITMAP_HELVETICA_12
83 
84 #define GLCOMPSET_BORDERWIDTH				(GLfloat)2
85 #define GLCOMPSET_PANEL_BORDERWIDTH				(GLfloat)3
86 #define GLCOMPSET_BUTTON_BEVEL				(GLfloat)5
87 #define	GLCOMPSET_BEVEL_DIFF				(GLfloat)0.001
88 #define GLCOMPSET_DEFAULT_PAD		(GLfloat)3
89 #define	GLCOMP_DEFAULT_WIDTH	(GLfloat)10
90 #define	GLCOMP_DEFAULT_HEIGHT	(GLfloat)10
91 
92 
93 
94 #define FONT_MAX_LEN                1024	/* maximum chars to draw to the screen, used for buffers also */
95 #define FONT_TAB_SPACE              4	/* spaces to draw for a tab, make option? */
96 
97 #define C_DPI              16
98 #define R_DPI              16
99 
100     typedef enum { inverted_y, scientific_y } glCompOrientation;
101     typedef enum { gluttext, pangotext } glCompFontType;
102     typedef enum { glAlignNone, glAlignLeft, glAlignTop, glAlignBottom,
103 	    glAlignRight, glAlignParent, glAlignCenter } glCompAlignment;
104 
105     typedef enum { glFontVJustifyNone, glFontVJustifyTop,
106 	    glFontVJustifyBottom, glFontVJustifyCenter } glCompVJustify;
107     typedef enum { glFontHJustifyNone, glFontHJustifyLeft,
108 	    glFontHJustifyRight, glFontHJustifyCenter } glCompHJustify;
109     typedef enum { glButtonGlyphLeft, glButtonGlyphRight, glButtonGlyphTop,
110 	    glButtonGlyphBottom } glCompButtonGlyph;
111     typedef enum { glBorderNone, glBorderSolid, glBorderBevel,
112 	    glBorderCustom } glCompBorderType;
113 
114     typedef enum { glMouseDown, glMouseUp } glCompMouseStatus;
115     typedef enum { glMouseLeftButton, glMouseRightButton,
116 	    glMouseMiddleButton } glMouseButtonType;
117 
118     typedef enum { glTexImage, glTexLabel } glCompTexType;
119     typedef enum { glPanelObj, glButtonObj, glLabelObj,
120 	    glImageObj } glObjType;
121 
122     typedef struct _glCompButton glCompButton;
123     typedef struct _glCompObj glCompObj;
124 
125 /*call backs for widgets*/
126     typedef void (*glcompdrawfunc_t) (void *obj);
127     typedef void (*glcompclickfunc_t) (glCompObj * obj, GLfloat x,
128 				       GLfloat y, glMouseButtonType t);
129     typedef void (*glcompdoubleclickfunc_t) (glCompObj * obj, GLfloat x,
130 					     GLfloat y,
131 					     glMouseButtonType t);
132     typedef void (*glcompmouseoverfunc_t) (glCompObj * obj, GLfloat x,
133 					   GLfloat y);
134     typedef void (*glcompmouseinfunc_t) (glCompObj * obj, GLfloat x,
135 					 GLfloat y);
136     typedef void (*glcompmouseoutfunc_t) (glCompObj * obj, GLfloat x,
137 					  GLfloat y);
138     typedef void (*glcompmousedownfunc_t) (glCompObj * obj, GLfloat x,
139 					   GLfloat y, glMouseButtonType t);
140     typedef void (*glcompmouseupfunc_t) (glCompObj * obj, GLfloat x,
141 					 GLfloat y, glMouseButtonType t);
142     typedef void (*glcompmousedragfunct_t) (glCompObj * obj, GLfloat dx,
143 					    GLfloat dy,
144 					    glMouseButtonType t);
145 
146 
147 
148     typedef struct _glCompAnchor {
149 
150 	int topAnchor;		/*anchor booleans */
151 	int leftAnchor;
152 	int rightAnchor;
153 	int bottomAnchor;
154 
155 	GLfloat top;		/*anchor values */
156 	GLfloat left;
157 	GLfloat right;
158 	GLfloat bottom;
159 
160 
161     } glCompAnchor;
162 
163     typedef struct _glCompJustify {
164 	glCompVJustify VJustify;
165 	glCompHJustify HJustify;
166     } glCompJustify;
167 
168 
169 
170 
171     typedef struct _glCompPoint {
172 	GLfloat x, y, z;
173     } glCompPoint;
174 
175     typedef struct _glCompPointI {
176 	int x, y;
177     } glCompPointI;
178     typedef struct {
179 	int cnt;
180 	int hotKey;
181 	glCompPoint* pts;
182     }glCompPoly;
183 
184     typedef struct {
185 	GLfloat R;
186 	GLfloat G;
187 	GLfloat B;
188 	GLfloat A;		//Alpha
189 	int tag;
190 	int test;
191     } glCompColor;
192 
193 
194     typedef struct _glCompRect {
195 	glCompPoint pos;
196 	GLfloat w;
197 	GLfloat h;
198     } glCompRect;
199 
200     typedef struct _glCompTex {
201 	GLuint id;
202 	char *def;
203 	char *text;
204 	float width;
205 	float height;
206 	glCompTexType type;
207 	int userCount;
208 	int fontSize;
209 	unsigned char *data;	/*data */
210     } glCompTex;
211 
212 
213 
214 /*opengl font*/
215     typedef struct {
216 	char *fontdesc;		//font description , only used with pango fonts
217 	glCompColor color;
218 	glCompFontType type;
219 	void *glutfont;		/*glut font pointer if used */
220 	int transparent;
221 	glCompTex *tex;		/* texture, if type is pangotext */
222 	int size;
223 	int reference;		/*if font has references to parent */
224 	glCompJustify justify;
225 	int is2D;
226 	int optimize;
227     } glCompFont;
228 
229     typedef struct _glCompCallBacks {
230 	glcompdrawfunc_t draw;
231 	glcompclickfunc_t click;
232 	glcompdoubleclickfunc_t doubleclick;
233 	glcompmouseoverfunc_t mouseover;
234 	glcompmouseinfunc_t mousein;
235 	glcompmouseoutfunc_t mouseout;
236 	glcompmousedownfunc_t mousedown;
237 	glcompmouseupfunc_t mouseup;
238 	glcompmousedragfunct_t mousedrag;
239 
240     } glCompCallBacks;
241 
242 
243 /*
244 	common widget properties
245 	also each widget has pointer to its parents common
246 */
247     typedef struct _glCompCommon {
248 	glCompPoint pos;
249 	glCompPoint refPos;	/*calculated pos after anchors and aligns */
250 	GLfloat width, height;
251 	GLfloat borderWidth;
252 	glCompBorderType borderType;
253 	glCompColor color;
254 	int enabled;
255 	int visible;
256 	void *compset;		// compset
257 	void *parent;		/*parent widget */
258 	int data;
259 	glCompFont *font;	//pointer to font to use
260 	glCompAlignment align;
261 	glCompAnchor anchor;
262 	int layer;		/*keep track of object order, what to draw on top */
263 	glCompCallBacks callbacks;
264 	glCompCallBacks functions;
265 	glCompJustify justify;
266     } glCompCommon;
267 
268 /*generic image*/
269     typedef struct _glCompImage {
270 	glObjType objType;	/*always keep this here for each drawable object */
271 	glCompCommon common;
272 	glCompTex *texture;
273 	GLfloat width, height;  /* width and height in world coords */
274 	/* char *pngFile; */
275 	int stretch;
276     } glCompImage;
277 
278 /*generic panel*/
279     typedef struct _glCompPanel {
280 	glObjType objType;	/*always keep this here for each drawable object */
281 	glCompCommon common;
282 	GLfloat shadowwidth;
283 	glCompColor shadowcolor;
284 	char *text;
285 	glCompImage *image;
286     } glCompPanel;
287 
288 /*label*/
289     typedef struct _glCompLabel {
290 	glObjType objType;	/*always keep this here for each drawable object */
291 	glCompCommon common;
292 	int autosize;		/*if 1 label sized is calculated from font */
293 	char *text;
294 	int transparent;
295     } glCompLabel;
296 
297 /*buttons*/
298     struct _glCompButton {
299 	glObjType objType;	/*always keep this here for each drawable object */
300 	glCompCommon common;
301 	GLfloat width, height;
302 	glCompLabel *label;
303 	int status;		//0 not pressed 1 pressed;
304 	int refStatus;		//0 not pressed 1 pressed;
305 	int groupid;
306 	glCompImage *image;	/*glyph */
307 	glCompButtonGlyph glyphPos;
308 	void *customptr;	//general purpose void pointer to pass to call back
309 	int data;
310 
311     };
312 
313 /*texture based image*/
314 
315 /*track bar*/
316     typedef struct _glCompTrackBar {
317 	glObjType objType;	/*always keep this here for each drawable object */
318 	GLfloat width, height;
319 	glCompPanel *outerpanel;
320 	glCompPanel *trackline;
321 	glCompPanel *indicator;
322 
323 	GLfloat bevel;
324 	glCompColor color;
325 	glCompColor shadowcolor;
326 
327 
328 	float value;
329 	float maxvalue;
330 	float minvalue;
331 	int enabled;
332 	int visible;
333 	void *parentset;	//parent compset
334 	int data;
335 	glCompFont *font;	//pointer to font to use
336 	glCompOrientation orientation;
337 
338     } glCompTrackBar;
339 
340 /*glCompFont container class*/
341     typedef struct {
342 	glCompFont **fonts;
343 	int count;
344 	int activefont;
345 	char *font_directory;	//location where the glfont files are stored
346     } fontset_t;
347 
348 /*object prototype*/
349     struct _glCompObj {
350 	glObjType objType;
351 	glCompCommon common;
352     };
353 
354     typedef struct _glCompMouse {
355 	glCompMouseStatus status;
356 	glMouseButtonType t;
357 	glCompPoint initPos; /*current mouse pos,*/
358 	glCompPoint pos; /*current mouse pos,*/
359 	glCompPoint finalPos; /*current mouse pos,*/
360 	glCompPoint GLpos;/*3d converted opengl position*/
361 	glCompPoint GLinitPos;/*mouse button down pos*/
362 	glCompPoint GLfinalPos;/*mouse button up pos*/
363 
364 	GLfloat dragX, dragY;/*GLpos - GLinitpos*/
365 	glCompObj *clickedObj;
366 	glCompCallBacks callbacks;
367 	glCompCallBacks functions;
368 	int down;
369 
370 
371     } glCompMouse;
372 
373 
374 
375 /*main widget set manager*/
376     typedef struct {
377 	glObjType objType;	/*always keep this here for each drawable object */
378 	glCompCommon common;
379 
380 	glCompObj **obj;
381 	int objcnt;
382 	glCompPanel **panels;
383 	glCompButton **buttons;
384 	glCompLabel **labels;
385 	int groupCount;		/*group id counter */
386 	int active;		//0 don't draw, 1 draw
387 	int enabled;		//0 disabled 1 enabled(allow mouse interaction)
388 	GLfloat clickedX, clickedY;
389 
390 	int textureCount;
391 	glCompTex **textures;
392 	glCompMouse mouse;
393     } glCompSet;
394 
395 #ifdef __cplusplus
396 }
397 #endif
398 #endif
399