glcompdefs.h 6.4 KB

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