Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
glcompbutton.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <cgraph/alloc.h>
12#include <glcomp/glcompbutton.h>
13#include <glcomp/glcomplabel.h>
14#include <glcomp/glcompimage.h>
15#include <glcomp/glcompfont.h>
16#include <glcomp/glutils.h>
17#include <glcomp/glcompset.h>
18#include <stdbool.h>
19#include <stddef.h>
20#include <string.h>
21#include <GL/glut.h>
22
23
24glCompButton *glCompButtonNew(glCompObj *par, float x, float y, float w,
25 float h, char *caption) {
27 glCompInitCommon((glCompObj *) p, par, x, y);
29 /*customize button color */
34
36
37 p->common.width = w;
38 p->common.height = h;
39 p->status = false; // false not pressed, true pressed
40 p->groupid = 0;
42 /*set event functions */
43
45
53
54 /*caption */
56 p->label = glCompLabelNew((glCompObj*) p, caption);
60 /*image */
61 p->image = NULL;
62 return p;
63}
64
66{
67 int rv;
68 /*delete if there is an existing image */
69 if (b->image)
71 /*image on left for now */
72 b->image = glCompImageNew((glCompObj *) b, 0, 0);
73
75 if (rv) {
77 b->image->common.anchor.left = 0;
78
80 b->image->common.anchor.top = 0;
81
83 b->image->common.anchor.bottom = 0;
84
88 b->label->common.anchor.right = 0;
89
91 b->label->common.anchor.top = 0;
92
94 b->label->common.anchor.bottom = 0;
95
97 }
98 return rv;
99}
100
102{
103 p->common.visible = 0;
104 if (p->label)
105 p->label->common.visible = 0;
106 if (p->image)
107 p->image->common.visible = 0;
108}
109
111{
112 p->common.visible = 1;
113 if (p->label)
114 p->label->common.visible = 1;
115 if (p->image)
116 p->image->common.visible = 1;
117}
118
120{
121
123 ref = p->common;
125 if (!p->common.visible)
126 return;
127 /*draw panel */
128 glCompDrawRectPrism(&(ref.pos), ref.width, ref.height,
129 p->common.borderWidth, 0.01f, &(ref.color),
130 !p->status);
131 if (p->label)
133 if (p->image)
135 if (p->common.callbacks.draw)
136 p->common.callbacks.draw(p); /*user defined drawing routines are called here. */
137}
138
139void glCompButtonClick(glCompObj *o, float x, float y, glMouseButtonType t) {
140 glCompButton *p = (glCompButton *) o;
141 glCompObj *obj;
143 ((glCompButton *) o)->status=((glCompButton *) o)->refStatus ;
144 if (p->groupid > 0)
145 {
146 for (size_t ind = 0; ind < s->objcnt; ind++) {
147 obj = s->obj[ind];
148 if (obj->objType == glButtonObj && obj != o) {
149 if (((glCompButton *) obj)->groupid == p->groupid)
150 ((glCompButton *) obj)->status = false;
151 }
152 }
153 p->status = true;
154 }
155 else {
156 if (p->groupid == -1) {
157 p->status = !p->status;
158 } else
159 p->status = false;
160 }
161 if (p->common.callbacks.click)
162 p->common.callbacks.click((glCompObj *) p, x, y, t);
163}
164
165void glCompButtonDoubleClick(glCompObj *obj, float x, float y,
167{
168 /*Put your internal code here */
169 if (((glCompButton *) obj)->common.callbacks.doubleclick)
170 ((glCompButton *) obj)->common.callbacks.doubleclick(obj, x, y, t);
171}
172
173void glCompButtonMouseDown(glCompObj *obj, float x, float y,
175{
176 /*Put your internal code here */
177
178
179 ((glCompButton *) obj)->refStatus = ((glCompButton *) obj)->status;
180 ((glCompButton *) obj)->status = true;
181 if (((glCompButton *) obj)->common.callbacks.mousedown)
182 ((glCompButton *) obj)->common.callbacks.mousedown(obj, x, y, t);
183}
184
185void glCompButtonMouseIn(glCompObj *obj, float x, float y) {
186 /*Put your internal code here */
187 if (((glCompButton *) obj)->common.callbacks.mousein)
188 ((glCompButton *) obj)->common.callbacks.mousein(obj, x, y);
189}
190
191void glCompButtonMouseOut(glCompObj *obj, float x, float y) {
192 /*Put your internal code here */
193 if (((glCompButton *) obj)->common.callbacks.mouseout)
194 ((glCompButton *) obj)->common.callbacks.mouseout(obj, x, y);
195}
196
197void glCompButtonMouseOver(glCompObj *obj, float x, float y) {
198 /*Put your internal code here */
199 if (((glCompButton *) obj)->common.callbacks.mouseover)
200 ((glCompButton *) obj)->common.callbacks.mouseover(obj, x, y);
201}
202
203void glCompButtonMouseUp(glCompObj *obj, float x, float y, glMouseButtonType t)
204{
205 /*Put your internal code here */
206
207 if (((glCompButton *) obj)->common.callbacks.mouseup)
208 ((glCompButton *) obj)->common.callbacks.mouseup(obj, x, y, t);
209}
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Definition alloc.h:47
void glCompButtonDraw(glCompButton *p)
void glCompButtonDoubleClick(glCompObj *obj, float x, float y, glMouseButtonType t)
int glCompButtonAddPngGlyph(glCompButton *b, char *fileName)
glCompButton * glCompButtonNew(glCompObj *par, float x, float y, float w, float h, char *caption)
void glCompButtonClick(glCompObj *o, float x, float y, glMouseButtonType t)
void glCompButtonMouseOver(glCompObj *obj, float x, float y)
void glCompButtonMouseDown(glCompObj *obj, float x, float y, glMouseButtonType t)
void glCompButtonMouseUp(glCompObj *obj, float x, float y, glMouseButtonType t)
void glCompButtonShow(glCompButton *p)
void glCompButtonMouseIn(glCompObj *obj, float x, float y)
void glCompButtonMouseOut(glCompObj *obj, float x, float y)
void glCompButtonHide(glCompButton *p)
#define GLCOMPSET_BUTTON_COLOR_G
Definition glcompdefs.h:43
@ glFontVJustifyCenter
Definition glcompdefs.h:84
@ glFontHJustifyCenter
Definition glcompdefs.h:86
#define GLCOMPSET_BUTTON_COLOR_R
Definition glcompdefs.h:42
#define GLCOMPSET_BUTTON_BEVEL
Definition glcompdefs.h:75
#define GLCOMPSET_BUTTON_COLOR_ALPHA
Definition glcompdefs.h:45
void(* glcompdrawfunc_t)(void *obj)
Definition glcompdefs.h:100
#define GLCOMPSET_BUTTON_COLOR_B
Definition glcompdefs.h:44
@ glButtonObj
Definition glcompdefs.h:93
glMouseButtonType
Definition glcompdefs.h:89
@ glAlignNone
Definition glcompdefs.h:80
@ glAlignParent
Definition glcompdefs.h:81
glCompFont * glNewFontFromParent(glCompObj *o, char *text)
Definition glcompfont.c:75
void glCompImageDelete(glCompImage *p)
Definition glcompimage.c:50
int glCompImageLoadPng(glCompImage *i, char *pngFile)
Definition glcompimage.c:75
glCompImage * glCompImageNew(glCompObj *par, float x, float y)
Definition glcompimage.c:19
glCompLabel * glCompLabelNew(glCompObj *par, char *text)
Definition glcomplabel.c:36
void glCompInitCommon(glCompObj *childObj, glCompObj *parentObj, float x, float y)
Definition glcompset.c:120
void glCompCalcWidget(glCompCommon *parent, glCompCommon *child, glCompCommon *ref)
Definition glutils.c:195
void glCompDrawRectPrism(glCompPoint *p, float w, float h, float b, float d, glCompColor *c, bool bumped)
Definition glutils.c:309
node NULL
Definition grammar.y:149
char * fileName(ingraph_state *sp)
Return name of current file being processed.
Definition ingraphs.c:156
void ref(Site *v)
Definition site.c:59
glCompCommon common
Definition glcompdefs.h:258
bool status
false not pressed, true pressed
Definition glcompdefs.h:261
glCompLabel * label
Definition glcompdefs.h:260
glObjType objType
Definition glcompdefs.h:257
glCompImage * image
Definition glcompdefs.h:264
glCompCommon common
Definition glcompdefs.h:274
glObjType objType
Definition glcompdefs.h:273
glcompdoubleclickfunc_t doubleclick
Definition glcompdefs.h:192
glcompmouseoutfunc_t mouseout
Definition glcompdefs.h:195
glcompmouseupfunc_t mouseup
Definition glcompdefs.h:197
glcompclickfunc_t click
Definition glcompdefs.h:191
glcompmouseinfunc_t mousein
Definition glcompdefs.h:194
glcompmousedownfunc_t mousedown
Definition glcompdefs.h:196
glcompdrawfunc_t draw
Definition glcompdefs.h:190
glcompmouseoverfunc_t mouseover
Definition glcompdefs.h:193
glCompColor color
Definition glcompdefs.h:212
glCompCallBacks callbacks
Definition glcompdefs.h:222
glCompCallBacks functions
Definition glcompdefs.h:223
glCompFont * font
Definition glcompdefs.h:218
glCompAnchor anchor
Definition glcompdefs.h:220
glCompAlignment align
Definition glcompdefs.h:219
void * parent
Definition glcompdefs.h:216
void * compset
Definition glcompdefs.h:215
float borderWidth
Definition glcompdefs.h:211
glCompJustify justify
Definition glcompdefs.h:184
glCompCommon common
Definition glcompdefs.h:230
glCompHJustify HJustify
Definition glcompdefs.h:136
glCompVJustify VJustify
Definition glcompdefs.h:135
glCompCommon common
Definition glcompdefs.h:250
Definition grammar.c:93