glcomppanel.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include <glcomp/glcomppanel.h>
  11. #include <glcomp/glcompfont.h>
  12. #include <glcomp/glcompset.h>
  13. #include <glcomp/glcomptexture.h>
  14. #include <glcomp/glutils.h>
  15. #include <stdbool.h>
  16. #include <util/alloc.h>
  17. static void glCompPanelDraw(void *o) {
  18. glCompPanel *p = o;
  19. glCompRect r;
  20. glCompCommon ref = p->base.common;
  21. glCompCalcWidget(p->base.common.parent, &p->base.common, &ref);
  22. if (!p->base.common.visible)
  23. return;
  24. /*draw shadow */
  25. const float SHADOW_COLOR_R = 0.0f;
  26. const float SHADOW_COLOR_G = 0.0f;
  27. const float SHADOW_COLOR_B = 0.0f;
  28. const float SHADOW_COLOR_A = 0.3f;
  29. glColor4f(SHADOW_COLOR_R, SHADOW_COLOR_G, SHADOW_COLOR_B, SHADOW_COLOR_A);
  30. r.h = p->shadowwidth;
  31. r.w = ref.width;
  32. r.pos.x = ref.pos.x + p->shadowwidth;
  33. r.pos.y = ref.pos.y - p->shadowwidth;
  34. r.pos.z = -0.001f;
  35. glCompDrawRectangle(&r);
  36. r.h = ref.height;
  37. r.w = p->shadowwidth;
  38. r.pos.x = ref.pos.x + ref.width;
  39. r.pos.y = ref.pos.y - p->shadowwidth;
  40. r.pos.z = -0.001f;
  41. glCompDrawRectangle(&r);
  42. /*draw panel */
  43. glCompDrawRectPrism(&ref.pos, ref.width, ref.height,
  44. p->base.common.borderWidth, 0.01f, &ref.color, true);
  45. /*draw image if there is */
  46. if (p->image) {
  47. p->image->base.common.callbacks.draw(p->image);
  48. }
  49. }
  50. glCompPanel *glCompPanelNew(void *parentObj, float x, float y, float w,
  51. float h) {
  52. glCompPanel *p = gv_alloc(sizeof(glCompPanel));
  53. glCompInitCommon(&p->base, parentObj, x, y);
  54. p->shadowwidth = GLCOMPSET_PANEL_SHADOW_WIDTH;
  55. p->base.common.borderWidth = GLCOMPSET_PANEL_BORDERWIDTH;
  56. p->base.common.width = w;
  57. p->base.common.height = h;
  58. glDeleteFont(&p->base.common.font);
  59. p->base.common.font = glNewFontFromParent(&p->base, NULL);
  60. p->text = NULL;
  61. p->base.common.functions.draw = glCompPanelDraw;
  62. p->image = NULL;
  63. return p;
  64. }