| 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 |
#pragma once |
| 12 |
|
| 13 |
#include <stdbool.h> |
| 14 |
#include <stdio.h> |
| 15 |
#include <stdint.h> |
| 16 |
#include <stdlib.h> |
| 17 |
#include <string.h> |
| 18 |
#include <stdarg.h> |
| 19 |
#include <math.h> |
| 20 |
#ifdef _WIN32 |
| 21 |
#include <windows.h> |
| 22 |
#include <winuser.h> |
| 23 |
#include <tchar.h> |
| 24 |
#endif |
| 25 |
#include <glcomp/opengl.h> |
| 26 |
#include <util/list.h> |
| 27 |
|
| 28 |
#ifdef __cplusplus |
| 29 |
extern "C" { |
| 30 |
#endif |
| 31 |
|
| 32 |
|
| 33 |
#define GLCOMPSET_PANEL_COLOR_R 0.16f |
| 34 |
#define GLCOMPSET_PANEL_COLOR_G 0.44f |
| 35 |
#define GLCOMPSET_PANEL_COLOR_B 0.87f |
| 36 |
#define GLCOMPSET_PANEL_COLOR_ALPHA 0.5f |
| 37 |
#define GLCOMPSET_PANEL_SHADOW_WIDTH 4.0f |
| 38 |
|
| 39 |
#define GLCOMPSET_BUTTON_COLOR_R 0.0f |
| 40 |
#define GLCOMPSET_BUTTON_COLOR_G 1.0f |
| 41 |
#define GLCOMPSET_BUTTON_COLOR_B 0.3f |
| 42 |
#define GLCOMPSET_BUTTON_COLOR_ALPHA 0.6f |
| 43 |
#define GLCOMPSET_BUTTON_THICKNESS 3.0f |
| 44 |
#define GLCOMPSET_BUTTON_BEVEL_BRIGHTNESS 1.7f |
| 45 |
#define GLCOMPSET_FONT_SIZE 14.0f |
| 46 |
|
| 47 |
#define GLCOMPSET_FONT_COLOR_R 0.0f |
| 48 |
#define GLCOMPSET_FONT_COLOR_G 0.0f |
| 49 |
#define GLCOMPSET_FONT_COLOR_B 0.0f |
| 50 |
#define GLCOMPSET_FONT_COLOR_ALPHA 1.0f |
| 51 |
#define GLCOMPSET_FONT_DESC "Times Italic" |
| 52 |
|
| 53 |
#define GLCOMPSET_BORDERWIDTH 2.0f |
| 54 |
#define GLCOMPSET_PANEL_BORDERWIDTH 3.0f |
| 55 |
#define GLCOMPSET_BUTTON_BEVEL 5.0f |
| 56 |
#define GLCOMPSET_BEVEL_DIFF 0.001f |
| 57 |
#define GLCOMP_DEFAULT_WIDTH 10.0f |
| 58 |
#define GLCOMP_DEFAULT_HEIGHT 10.0f |
| 59 |
|
| 60 |
typedef enum { glAlignNone, glAlignLeft, glAlignTop, glAlignBottom, |
| 61 |
glAlignRight, glAlignParent, glAlignCenter } glCompAlignment; |
| 62 |
|
| 63 |
typedef enum { glFontVJustifyNone, glFontVJustifyCenter } glCompVJustify; |
| 64 |
typedef enum { glFontHJustifyNone, glFontHJustifyCenter } glCompHJustify; |
| 65 |
|
| 66 |
typedef enum { glMouseDown, glMouseUp } glCompMouseStatus; |
| 67 |
typedef enum { glMouseLeftButton, glMouseRightButton, |
| 68 |
glMouseMiddleButton } glMouseButtonType; |
| 69 |
|
| 70 |
typedef enum { glTexImage, glTexLabel } glCompTexType; |
| 71 |
|
| 72 |
typedef struct glCompObj_ glCompObj; |
| 73 |
|
| 74 |
/*call backs for widgets*/ |
| 75 |
typedef void (*glcompdrawfunc_t) (void *obj); |
| 76 |
typedef void (*glcompclickfunc_t)(glCompObj *obj, float x, |
| 77 |
float y, glMouseButtonType t); |
| 78 |
typedef void (*glcompmouseoverfunc_t) (glCompObj * obj, float x, |
| 79 |
float y); |
| 80 |
typedef void (*glcompmousedownfunc_t) (glCompObj * obj, float x, |
| 81 |
float y, glMouseButtonType t); |
| 82 |
typedef void (*glcompmouseupfunc_t) (glCompObj * obj, float x, |
| 83 |
float y, glMouseButtonType t); |
| 84 |
|
| 85 |
typedef struct { |
| 86 |
int topAnchor; /*anchor booleans */ |
| 87 |
int leftAnchor; |
| 88 |
int rightAnchor; |
| 89 |
int bottomAnchor; |
| 90 |
|
| 91 |
float top; /*anchor values */ |
| 92 |
float left; |
| 93 |
float right; |
| 94 |
float bottom; |
| 95 |
|
| 96 |
|
| 97 |
} glCompAnchor; |
| 98 |
|
| 99 |
typedef struct { |
| 100 |
glCompVJustify VJustify; |
| 101 |
glCompHJustify HJustify; |
| 102 |
} glCompJustify; |
| 103 |
|
| 104 |
typedef struct { |
| 105 |
float x, y, z; |
| 106 |
} glCompPoint; |
| 107 |
|
| 108 |
typedef LIST(glCompPoint) glCompPoly_t; |
| 109 |
|
| 110 |
typedef struct { |
| 111 |
double R; |
| 112 |
double G; |
| 113 |
double B; |
| 114 |
double A; //Alpha |
| 115 |
} glCompColor; |
| 116 |
|
| 117 |
typedef struct { |
| 118 |
glCompPoint pos; |
| 119 |
float w; |
| 120 |
float h; |
| 121 |
} glCompRect; |
| 122 |
|
| 123 |
typedef struct { |
| 124 |
uint32_t id; |
| 125 |
char *def; |
| 126 |
char *text; |
| 127 |
int width; |
| 128 |
int height; |
| 129 |
glCompTexType type; |
| 130 |
int userCount; |
| 131 |
int fontSize; |
| 132 |
unsigned char *data; |
| 133 |
} glCompTex; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
/*opengl font*/ |
| 138 |
typedef struct { |
| 139 |
char *fontdesc; //font description , only used with pango fonts |
| 140 |
glCompColor color; |
| 141 |
void *glutfont; /*glut font pointer if used */ |
| 142 |
int transparent; |
| 143 |
glCompTex *tex; /* texture, if type is pangotext */ |
| 144 |
int size; |
| 145 |
glCompJustify justify; |
| 146 |
bool is2D; |
| 147 |
} glCompFont; |
| 148 |
|
| 149 |
typedef struct { |
| 150 |
glcompdrawfunc_t draw; |
| 151 |
glcompclickfunc_t click; |
| 152 |
glcompmouseoverfunc_t mouseover; |
| 153 |
glcompmousedownfunc_t mousedown; |
| 154 |
glcompmouseupfunc_t mouseup; |
| 155 |
} glCompCallBacks; |
| 156 |
|
| 157 |
typedef struct glCompSet_ glCompSet; |
| 158 |
|
| 159 |
/* |
| 160 |
common widget properties |
| 161 |
also each widget has pointer to its parents common |
| 162 |
*/ |
| 163 |
typedef struct { |
| 164 |
glCompPoint pos; |
| 165 |
glCompPoint refPos; /*calculated pos after anchors and aligns */ |
| 166 |
float width, height; |
| 167 |
float borderWidth; |
| 168 |
glCompColor color; |
| 169 |
int enabled; |
| 170 |
int visible; |
| 171 |
glCompSet *compset; |
| 172 |
void *parent; /*parent widget */ |
| 173 |
int data; |
| 174 |
glCompFont font; ///< font to use |
| 175 |
glCompAlignment align; |
| 176 |
glCompAnchor anchor; |
| 177 |
int layer; /*keep track of object order, what to draw on top */ |
| 178 |
glCompCallBacks callbacks; |
| 179 |
glCompCallBacks functions; |
| 180 |
glCompJustify justify; |
| 181 |
} glCompCommon; |
| 182 |
|
| 183 |
/// object prototype |
| 184 |
struct glCompObj_ { |
| 185 |
glCompCommon common; |
| 186 |
}; |
| 187 |
|
| 188 |
/*generic image*/ |
| 189 |
typedef struct { |
| 190 |
glCompObj base; |
| 191 |
glCompTex *texture; |
| 192 |
float width, height; /* width and height in world coords */ |
| 193 |
} glCompImage; |
| 194 |
|
| 195 |
/*generic panel*/ |
| 196 |
typedef struct { |
| 197 |
glCompObj base; |
| 198 |
float shadowwidth; |
| 199 |
char *text; |
| 200 |
} glCompPanel; |
| 201 |
|
| 202 |
/*label*/ |
| 203 |
typedef struct { |
| 204 |
glCompObj base; |
| 205 |
char *text; |
| 206 |
} glCompLabel; |
| 207 |
|
| 208 |
/*buttons*/ |
| 209 |
typedef struct { |
| 210 |
glCompObj base; |
| 211 |
float width, height; |
| 212 |
glCompLabel *label; |
| 213 |
bool status; ///< false not pressed, true pressed |
| 214 |
bool refStatus; ///< false not pressed, true pressed |
| 215 |
int groupid; |
| 216 |
glCompImage *image; /*glyph */ |
| 217 |
int data; |
| 218 |
} glCompButton; |
| 219 |
|
| 220 |
/*texture based image*/ |
| 221 |
|
| 222 |
typedef struct { |
| 223 |
glMouseButtonType t; |
| 224 |
float x, y; ///< current mouse pos |
| 225 |
glCompPoint GLpos;/*3d converted opengl position*/ |
| 226 |
glCompPoint GLinitPos;/*mouse button down pos*/ |
| 227 |
glCompPoint GLfinalPos;/*mouse button up pos*/ |
| 228 |
|
| 229 |
float dragX, dragY;/*GLpos - GLinitpos*/ |
| 230 |
glCompObj *clickedObj; |
| 231 |
glCompCallBacks callbacks; |
| 232 |
glCompCallBacks functions; |
| 233 |
bool down; |
| 234 |
} glCompMouse; |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
/*main widget set manager*/ |
| 239 |
struct glCompSet_ { |
| 240 |
glCompObj base; |
| 241 |
glCompObj **obj; |
| 242 |
size_t objcnt; |
| 243 |
size_t textureCount; |
| 244 |
glCompTex **textures; |
| 245 |
glCompMouse mouse; |
| 246 |
}; |
| 247 |
|
| 248 |
#ifdef __cplusplus |
| 249 |
} |
| 250 |
#endif |