Graphviz 14.1.2~dev.20260123.1158
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 "config.h"
12
13#include <glcomp/glcompbutton.h>
14#include <glcomp/glcomplabel.h>
15#include <glcomp/glcompimage.h>
16#include <glcomp/glcompfont.h>
17#include <glcomp/glutils.h>
18#include <glcomp/glcompset.h>
19#include <stdbool.h>
20#include <stddef.h>
21#include <string.h>
22#include <GL/glut.h>
23#include <util/alloc.h>
24
25glCompButton *glCompButtonNew(void *par, float x, float y, float w, float h,
26 char *caption) {
28 glCompInitCommon(&p->base, par, x, y);
29 /*customize button color */
34
36
37 p->base.common.width = w;
38 p->base.common.height = h;
39 p->status = false; // false not pressed, true pressed
40 p->groupid = 0;
42 /*set event functions */
43
45
50
51 /*caption */
54 p->label = glCompLabelNew(p, caption);
58 /*image */
59 p->image = NULL;
60 return p;
61}
62
64 int rv;
65 /*delete if there is an existing image */
66 if (b->image)
68 /*image on left for now */
69 b->image = glCompImageNew(b, 0, 0);
70
72 if (rv) {
74 b->image->base.common.anchor.left = 0;
75
77 b->image->base.common.anchor.top = 0;
78
81
86
88 b->label->base.common.anchor.top = 0;
89
92
94 }
95 return rv;
96}
97
99{
100 p->base.common.visible = 0;
101 if (p->label)
102 p->label->base.common.visible = 0;
103 if (p->image)
104 p->image->base.common.visible = 0;
105}
106
108{
109 p->base.common.visible = 1;
110 if (p->label)
111 p->label->base.common.visible = 1;
112 if (p->image)
113 p->image->base.common.visible = 1;
114}
115
117{
118 glCompCommon ref = p->base.common;
120 if (!p->base.common.visible)
121 return;
122 /*draw panel */
123 glCompDrawRectPrism(ref.pos, ref.width, ref.height,
124 p->base.common.borderWidth, ref.color, !p->status);
125 if (p->label)
127 if (p->image)
129}
130
131void glCompButtonClick(glCompObj *o, float x, float y, glMouseButtonType t) {
132 glCompButton *p = (glCompButton *) o;
133 ((glCompButton *) o)->status=((glCompButton *) o)->refStatus ;
134 if (p->groupid == -1) {
135 p->status = !p->status;
136 } else {
137 p->status = false;
138 }
139 if (p->base.common.callbacks.click)
140 p->base.common.callbacks.click(&p->base, x, y, t);
141}
142
143void glCompButtonMouseDown(glCompObj *obj, float x, float y,
145{
146 (void)x;
147 (void)y;
148 (void)t;
149
150 ((glCompButton *) obj)->refStatus = ((glCompButton *) obj)->status;
151 ((glCompButton *) obj)->status = true;
152}
153
154void glCompButtonMouseOver(glCompObj *obj, float x, float y) {
155 if (obj->common.callbacks.mouseover)
156 obj->common.callbacks.mouseover(obj, x, y);
157}
158
159void glCompButtonMouseUp(glCompObj *obj, float x, float y, glMouseButtonType t)
160{
161 if (obj->common.callbacks.mouseup)
162 obj->common.callbacks.mouseup(obj, x, y, t);
163}
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)
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 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, const char *text)
Definition glcompfont.c:72
void glDeleteFont(glCompFont *f)
Definition glcompfont.c:40
void glCompImageDelete(glCompImage *p)
Definition glcompimage.c:52
int glCompImageLoadPng(glCompImage *i, const char *pngFile)
Definition glcompimage.c:77
glCompImage * glCompImageNew(void *par, float x, float y)
Definition glcompimage.c:22
glCompLabel * glCompLabelNew(void *par, char *text)
Definition glcomplabel.c:26
void glCompInitCommon(glCompObj *childObj, glCompObj *parentObj, float x, float y)
Definition glcompset.c:113
void glCompDrawRectPrism(glCompPoint p, float w, float h, float b, glCompColor c, bool bumped)
Definition glutils.c:293
void glCompCalcWidget(glCompCommon *parent, glCompCommon *child, glCompCommon *ref)
Definition glutils.c:183
node NULL
Definition grammar.y:181
char * fileName(ingraph_state *sp)
Return name of current file being processed.
Definition ingraphs.c:156
glCompLabel * label
Definition glcompdefs.h:212
glCompImage * image
Definition glcompdefs.h:216
glCompObj base
Definition glcompdefs.h:210
bool status
false not pressed, true pressed
Definition glcompdefs.h:213
glcompmouseupfunc_t mouseup
Definition glcompdefs.h:154
glcompclickfunc_t click
Definition glcompdefs.h:151
glcompmousedownfunc_t mousedown
Definition glcompdefs.h:153
glcompdrawfunc_t draw
Definition glcompdefs.h:150
glcompmouseoverfunc_t mouseover
Definition glcompdefs.h:152
glCompColor color
Definition glcompdefs.h:168
glCompCallBacks callbacks
Definition glcompdefs.h:178
glCompCallBacks functions
Definition glcompdefs.h:179
glCompPoint pos
Definition glcompdefs.h:164
glCompAnchor anchor
Definition glcompdefs.h:176
glCompAlignment align
Definition glcompdefs.h:175
void * parent
Definition glcompdefs.h:172
glCompFont font
font to use
Definition glcompdefs.h:174
float borderWidth
Definition glcompdefs.h:167
glCompJustify justify
Definition glcompdefs.h:145
glCompObj base
Definition glcompdefs.h:190
glCompHJustify HJustify
Definition glcompdefs.h:101
glCompVJustify VJustify
Definition glcompdefs.h:100
glCompObj base
Definition glcompdefs.h:204
object prototype
Definition glcompdefs.h:184
glCompCommon common
Definition glcompdefs.h:185