Graphviz 13.0.0~dev.20241220.2304
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 <glcomp/glcompbutton.h>
12#include <glcomp/glcomplabel.h>
13#include <glcomp/glcompimage.h>
14#include <glcomp/glcompfont.h>
15#include <glcomp/glutils.h>
16#include <glcomp/glcompset.h>
17#include <stdbool.h>
18#include <stddef.h>
19#include <string.h>
20#include <GL/glut.h>
21#include <util/alloc.h>
22
23glCompButton *glCompButtonNew(void *par, float x, float y, float w, float h,
24 char *caption) {
26 glCompInitCommon(&p->base, par, x, y);
27 /*customize button color */
32
34
35 p->base.common.width = w;
36 p->base.common.height = h;
37 p->status = false; // false not pressed, true pressed
38 p->groupid = 0;
40 /*set event functions */
41
43
51
52 /*caption */
55 p->label = glCompLabelNew(p, caption);
59 /*image */
60 p->image = NULL;
61 return p;
62}
63
65 int rv;
66 /*delete if there is an existing image */
67 if (b->image)
69 /*image on left for now */
70 b->image = glCompImageNew(b, 0, 0);
71
73 if (rv) {
75 b->image->base.common.anchor.left = 0;
76
78 b->image->base.common.anchor.top = 0;
79
82
87
89 b->label->base.common.anchor.top = 0;
90
93
95 }
96 return rv;
97}
98
100{
101 p->base.common.visible = 0;
102 if (p->label)
103 p->label->base.common.visible = 0;
104 if (p->image)
105 p->image->base.common.visible = 0;
106}
107
109{
110 p->base.common.visible = 1;
111 if (p->label)
112 p->label->base.common.visible = 1;
113 if (p->image)
114 p->image->base.common.visible = 1;
115}
116
118{
121 if (!p->base.common.visible)
122 return;
123 /*draw panel */
124 glCompDrawRectPrism(&(ref.pos), ref.width, ref.height,
125 p->base.common.borderWidth, 0.01f, &ref.color,
126 !p->status);
127 if (p->label)
129 if (p->image)
131 if (p->base.common.callbacks.draw)
132 p->base.common.callbacks.draw(p); // user defined drawing routines are called here
133}
134
135void glCompButtonClick(glCompObj *o, float x, float y, glMouseButtonType t) {
136 glCompButton *p = (glCompButton *) o;
137 ((glCompButton *) o)->status=((glCompButton *) o)->refStatus ;
138 if (p->groupid == -1) {
139 p->status = !p->status;
140 } else {
141 p->status = false;
142 }
143 if (p->base.common.callbacks.click)
144 p->base.common.callbacks.click(&p->base, x, y, t);
145}
146
147void glCompButtonDoubleClick(glCompObj *obj, float x, float y,
149{
151 obj->common.callbacks.doubleclick(obj, x, y, t);
152}
153
154void glCompButtonMouseDown(glCompObj *obj, float x, float y,
156{
157 /*Put your internal code here */
158
159
160 ((glCompButton *) obj)->refStatus = ((glCompButton *) obj)->status;
161 ((glCompButton *) obj)->status = true;
162 if (obj->common.callbacks.mousedown)
163 obj->common.callbacks.mousedown(obj, x, y, t);
164}
165
166void glCompButtonMouseIn(glCompObj *obj, float x, float y) {
167 if (obj->common.callbacks.mousein)
168 obj->common.callbacks.mousein(obj, x, y);
169}
170
171void glCompButtonMouseOut(glCompObj *obj, float x, float y) {
172 if (obj->common.callbacks.mouseout)
173 obj->common.callbacks.mouseout(obj, x, y);
174}
175
176void glCompButtonMouseOver(glCompObj *obj, float x, float y) {
177 if (obj->common.callbacks.mouseover)
178 obj->common.callbacks.mouseover(obj, x, y);
179}
180
181void glCompButtonMouseUp(glCompObj *obj, float x, float y, glMouseButtonType t)
182{
183 if (obj->common.callbacks.mouseup)
184 obj->common.callbacks.mouseup(obj, x, y, t);
185}
Memory allocation wrappers that exit on failure.
static void * gv_alloc(size_t size)
Definition alloc.h:47
int glCompButtonAddPngGlyph(glCompButton *b, const char *fileName)
void glCompButtonDraw(glCompButton *p)
void glCompButtonDoubleClick(glCompObj *obj, float x, float y, glMouseButtonType t)
glCompButton * glCompButtonNew(void *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:40
@ glFontVJustifyCenter
Definition glcompdefs.h:63
@ glFontHJustifyCenter
Definition glcompdefs.h:64
#define GLCOMPSET_BUTTON_COLOR_R
Definition glcompdefs.h:39
#define GLCOMPSET_BUTTON_BEVEL
Definition glcompdefs.h:55
#define GLCOMPSET_BUTTON_COLOR_ALPHA
Definition glcompdefs.h:42
void(* glcompdrawfunc_t)(void *obj)
Definition glcompdefs.h:75
#define GLCOMPSET_BUTTON_COLOR_B
Definition glcompdefs.h:41
glMouseButtonType
Definition glcompdefs.h:67
@ glAlignNone
Definition glcompdefs.h:60
@ glAlignParent
Definition glcompdefs.h:61
glCompFont glNewFontFromParent(glCompObj *o, char *text)
Definition glcompfont.c:70
void glDeleteFont(glCompFont *f)
Definition glcompfont.c:38
void glCompImageDelete(glCompImage *p)
Definition glcompimage.c:50
int glCompImageLoadPng(glCompImage *i, const char *pngFile)
Definition glcompimage.c:75
glCompImage * glCompImageNew(void *par, float x, float y)
Definition glcompimage.c:20
glCompLabel * glCompLabelNew(void *par, char *text)
Definition glcomplabel.c:24
void glCompInitCommon(glCompObj *childObj, glCompObj *parentObj, float x, float y)
Definition glcompset.c:114
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:306
node NULL
Definition grammar.y:163
char * fileName(ingraph_state *sp)
Return name of current file being processed.
Definition ingraphs.c:156
void ref(Site *v)
Definition site.c:59
glCompLabel * label
Definition glcompdefs.h:228
glCompImage * image
Definition glcompdefs.h:232
glCompObj base
Definition glcompdefs.h:226
bool status
false not pressed, true pressed
Definition glcompdefs.h:229
glcompdoubleclickfunc_t doubleclick
Definition glcompdefs.h:162
glcompmouseoutfunc_t mouseout
Definition glcompdefs.h:165
glcompmouseupfunc_t mouseup
Definition glcompdefs.h:167
glcompclickfunc_t click
Definition glcompdefs.h:161
glcompmouseinfunc_t mousein
Definition glcompdefs.h:164
glcompmousedownfunc_t mousedown
Definition glcompdefs.h:166
glcompdrawfunc_t draw
Definition glcompdefs.h:160
glcompmouseoverfunc_t mouseover
Definition glcompdefs.h:163
glCompColor color
Definition glcompdefs.h:183
glCompCallBacks callbacks
Definition glcompdefs.h:193
glCompCallBacks functions
Definition glcompdefs.h:194
glCompAnchor anchor
Definition glcompdefs.h:191
glCompAlignment align
Definition glcompdefs.h:190
void * parent
Definition glcompdefs.h:187
glCompFont font
font to use
Definition glcompdefs.h:189
float borderWidth
Definition glcompdefs.h:182
glCompJustify justify
Definition glcompdefs.h:155
glCompObj base
Definition glcompdefs.h:205
glCompHJustify HJustify
Definition glcompdefs.h:111
glCompVJustify VJustify
Definition glcompdefs.h:110
glCompObj base
Definition glcompdefs.h:220
object prototype
Definition glcompdefs.h:199
glCompCommon common
Definition glcompdefs.h:200