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
14 #include "glcomplabel.h"
15 #include "glcompfont.h"
16 #include "glcompset.h"
17 #include "glutils.h"
18 #include "memory.h"
19
glCompLabelNew(glCompObj * par,GLfloat x,GLfloat y,char * text)20 glCompLabel *glCompLabelNew(glCompObj * par, GLfloat x, GLfloat y,
21 char *text)
22 {
23 glCompLabel *p;
24 // glCompCommon* parent=&par->common;
25 p = NEW(glCompLabel);
26 glCompInitCommon((glCompObj *) p, par, x, y);
27 p->objType = glLabelObj;
28 p->transparent=1;
29 //typedef enum {glPanelObj,glbuttonObj,glLabelObj,glImageObj}glObjType;
30
31 p->text = strdup(text);
32 p->common.font = glNewFontFromParent ((glCompObj*)p, text);
33 p->common.functions.draw = (glcompdrawfunc_t)glCompLabelDraw;
34
35 return p;
36 }
37
38
glCompLabelDraw(glCompLabel * p)39 int glCompLabelDraw(glCompLabel * p)
40 {
41 glCompCommon ref;
42 ref = p->common;
43 glCompCalcWidget((glCompCommon *) p->common.parent, &p->common, &ref);
44 /*draw background */
45 if(!p->transparent)
46 {
47 glCompSetColor(&p->common.color);
48 glBegin(GL_QUADS);
49 glVertex3d(ref.refPos.x, ref.refPos.y, ref.refPos.z);
50 glVertex3d(ref.refPos.x + ref.width, ref.refPos.y, ref.refPos.z);
51 glVertex3d(ref.refPos.x + ref.width, ref.refPos.y + ref.height,
52 ref.refPos.z);
53 glVertex3d(ref.refPos.x, ref.refPos.y + ref.height, ref.refPos.z);
54 glEnd();
55 }
56 glCompRenderText(p->common.font, (glCompObj *) p);
57 return 1;
58
59 }
update_font(glCompLabel * p,char * text,char * desc,int fs)60 static void update_font(glCompLabel * p,char* text,char* desc,int fs)
61 {
62
63 glCompFont* temp=p->common.font;
64 if (strlen(text) >512)
65 return ;
66
67 p->common.font=glNewFont (p->common.compset,text,&p->common.color,temp->type,desc,fs,temp->is2D);
68 if(temp)
69 glDeleteFont(temp);
70 if(p->text)
71 free(p->text);
72 p->text = strdup(text);
73
74
75 }
76
glCompLabelSetText(glCompLabel * p,char * text)77 void glCompLabelSetText(glCompLabel * p, char *text)
78 {
79 glCompFont* temp=p->common.font;
80 update_font(p,text,temp->fontdesc,temp->size);
81 }
glCompLabelSetFontSize(glCompLabel * p,int size)82 void glCompLabelSetFontSize(glCompLabel * p, int size)
83 {
84 glCompFont* temp=p->common.font;
85 update_font(p,p->text,temp->fontdesc,size);
86 }
glCompLabelSetFontName(glCompLabel * p,char * fontName)87 void glCompLabelSetFontName(glCompLabel * p, char* fontName)
88 {
89 glCompFont* temp=p->common.font;
90 update_font(p,p->text,fontName,temp->size);
91 }
92
93
glCompLabelClick(glCompObj * o,GLfloat x,GLfloat y,glMouseButtonType t)94 void glCompLabelClick(glCompObj * o, GLfloat x, GLfloat y,
95 glMouseButtonType t)
96 {
97 if (o->common.callbacks.click)
98 o->common.callbacks.click(o, x, y, t);
99 }
100
glCompLabelDoubleClick(glCompObj * obj,GLfloat x,GLfloat y,glMouseButtonType t)101 void glCompLabelDoubleClick(glCompObj * obj, GLfloat x, GLfloat y,
102 glMouseButtonType t)
103 {
104 /*Put your internal code here */
105 if (((glCompLabel *) obj)->common.callbacks.doubleclick)
106 ((glCompLabel *) obj)->common.callbacks.doubleclick(obj, x, y, t);
107 }
108
glCompLabelMouseDown(glCompObj * obj,GLfloat x,GLfloat y,glMouseButtonType t)109 void glCompLabelMouseDown(glCompObj * obj, GLfloat x, GLfloat y,
110 glMouseButtonType t)
111 {
112 /*Put your internal code here */
113 if (((glCompLabel *) obj)->common.callbacks.mousedown)
114 ((glCompLabel *) obj)->common.callbacks.mousedown(obj, x, y, t);
115 }
116
glCompLabelMouseIn(glCompObj * obj,GLfloat x,GLfloat y)117 void glCompLabelMouseIn(glCompObj * obj, GLfloat x, GLfloat y)
118 {
119 /*Put your internal code here */
120 if (((glCompLabel *) obj)->common.callbacks.mousein)
121 ((glCompLabel *) obj)->common.callbacks.mousein(obj, x, y);
122 }
123
glCompLabelMouseOut(glCompObj * obj,GLfloat x,GLfloat y)124 void glCompLabelMouseOut(glCompObj * obj, GLfloat x, GLfloat y)
125 {
126 /*Put your internal code here */
127 if (((glCompLabel *) obj)->common.callbacks.mouseout)
128 ((glCompLabel *) obj)->common.callbacks.mouseout(obj, x, y);
129 }
130
glCompLabelMouseOver(glCompObj * obj,GLfloat x,GLfloat y)131 void glCompLabelMouseOver(glCompObj * obj, GLfloat x, GLfloat y)
132 {
133 /*Put your internal code here */
134 if (((glCompLabel *) obj)->common.callbacks.mouseover)
135 ((glCompLabel *) obj)->common.callbacks.mouseover(obj, x, y);
136 }
137
glCompLabelMouseUp(glCompObj * obj,GLfloat x,GLfloat y,glMouseButtonType t)138 void glCompLabelMouseUp(glCompObj * obj, GLfloat x, GLfloat y,
139 glMouseButtonType t)
140 {
141 /*Put your internal code here */
142 if (((glCompLabel *) obj)->common.callbacks.mouseup)
143 ((glCompLabel *) obj)->common.callbacks.mouseup(obj, x, y, t);
144 }
145