glcompui.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 "glcompui.h"
  11. #include <glcomp/glcompbutton.h>
  12. #include <glcomp/glcomppanel.h>
  13. #include <glcomp/glcomplabel.h>
  14. #include <glcomp/glcompimage.h>
  15. #include "gltemplate.h"
  16. #include <glcomp/glutils.h>
  17. #include "glmotion.h"
  18. #include "topfisheyeview.h"
  19. #include "toolboxcallbacks.h"
  20. #include "viewportcamera.h"
  21. #include "selectionfuncs.h"
  22. #include <stdbool.h>
  23. #include <stdint.h>
  24. #include <stdlib.h>
  25. #include "frmobjectui.h"
  26. static glCompPanel *sel = NULL;
  27. static glCompButton *to3DBtn;
  28. static glCompButton *to2DBtn;
  29. static glCompButton *toFisheye;
  30. static glCompButton *toNormal;
  31. static glCompImage *imgFisheye;
  32. static glCompImage *img3D;
  33. static glCompButton *panBtn;
  34. void menu_click_pan(glCompObj *obj, float x, float y, glMouseButtonType t) {
  35. (void)obj;
  36. (void)x;
  37. (void)y;
  38. (void)t;
  39. deselect_all(view->g[view->activeGraph]);
  40. }
  41. void menu_click_zoom_minus(glCompObj *obj, float x, float y,
  42. glMouseButtonType t)
  43. {
  44. (void)obj;
  45. (void)x;
  46. (void)y;
  47. (void)t;
  48. glmotion_zoom_inc(0);
  49. }
  50. void menu_click_zoom_plus(glCompObj *obj, float x, float y, glMouseButtonType t)
  51. {
  52. (void)obj;
  53. (void)x;
  54. (void)y;
  55. (void)t;
  56. glmotion_zoom_inc(1);
  57. }
  58. static void menu_switch_to_fisheye(glCompObj *obj, float x, float y,
  59. glMouseButtonType t)
  60. {
  61. (void)obj;
  62. (void)x;
  63. (void)y;
  64. (void)t;
  65. if (!view->Topview->fisheyeParams.active)
  66. {
  67. if (!view->Topview->fisheyeParams.h) {
  68. prepare_topological_fisheye(view->g[view->activeGraph],view->Topview);
  69. g_timer_start(view->timer);
  70. }
  71. view->Topview->fisheyeParams.active = 1;
  72. glCompButtonShow(toNormal);
  73. glCompButtonHide(toFisheye);
  74. imgFisheye->base.common.visible = 1;
  75. } else {
  76. view->Topview->fisheyeParams.active = 0;
  77. g_timer_stop(view->timer);
  78. glCompButtonHide(toNormal);
  79. glCompButtonShow(toFisheye);
  80. imgFisheye->base.common.visible = 0;
  81. }
  82. }
  83. void menu_click_center(glCompObj *obj, float x, float y, glMouseButtonType t) {
  84. (void)obj;
  85. (void)x;
  86. (void)y;
  87. (void)t;
  88. if (view->active_camera == SIZE_MAX) { // 2D mode
  89. btnToolZoomFit_clicked(NULL, NULL);
  90. } else { /*there is active camera , adjust it to look at the center */
  91. view->cameras[view->active_camera]->targetx = 0;
  92. view->cameras[view->active_camera]->targety = 0;
  93. view->cameras[view->active_camera]->r = 20;
  94. }
  95. }
  96. void switch2D3D(glCompObj *obj, float x, float y, glMouseButtonType t) {
  97. (void)obj;
  98. (void)x;
  99. (void)y;
  100. if (t == glMouseLeftButton) {
  101. if (view->active_camera == SIZE_MAX) {
  102. if (view->camera_count == 0) {
  103. menu_click_add_camera();
  104. } else {
  105. view->active_camera = 0; /*set to camera */
  106. }
  107. glCompButtonShow(to2DBtn);
  108. glCompButtonHide(to3DBtn);
  109. img3D->base.common.visible = 1;
  110. } else { /*switch to 2d */
  111. view->active_camera = SIZE_MAX; // set to camera
  112. glCompButtonShow(to3DBtn);
  113. glCompButtonHide(to2DBtn);
  114. panBtn->base.common.callbacks.click(&panBtn->base, 0.0f, 0.0f, 0);
  115. img3D->base.common.visible = 0;
  116. }
  117. }
  118. }
  119. static void CBglCompMouseUp(glCompObj *obj, float x, float y, glMouseButtonType t)
  120. {
  121. (void)obj;
  122. (void)x;
  123. (void)y;
  124. (void)t;
  125. sel->base.common.visible = 0;
  126. sel->base.common.pos.x = -5000;
  127. }
  128. static void CBglCompMouseRightClick(glCompObj *obj, float x, float y,
  129. glMouseButtonType t)
  130. {
  131. (void)obj;
  132. if (t == glMouseRightButton)
  133. {
  134. float X, Y, Z = 0;
  135. to3D((int) x, (int) y, &X, &Y, &Z);
  136. }
  137. }
  138. static void attrList(glCompObj *obj, float x, float y, glMouseButtonType t) {
  139. (void)obj;
  140. (void)x;
  141. (void)y;
  142. (void)t;
  143. showAttrsWidget();
  144. }
  145. static void glCompMouseMove(glCompObj *obj, float x, float y) {
  146. (void)x;
  147. (void)y;
  148. glCompMouse *m = &((glCompSet *) obj)->mouse;
  149. sel->base.common.visible = 1;
  150. if ((m->down) && (m->t == glMouseRightButton))
  151. {
  152. sel->base.common.pos.x = m->x - m->dragX;
  153. sel->base.common.pos.y = m->y - m->dragY;
  154. sel->base.common.width = m->dragX;
  155. sel->base.common.height = m->dragY;
  156. glexpose();
  157. }
  158. }
  159. static void selectedges(glCompObj *obj, float x, float y, glMouseButtonType t) {
  160. (void)obj;
  161. (void)x;
  162. (void)y;
  163. (void)t;
  164. view->Topview->sel.selectEdges = !view->Topview->sel.selectEdges;
  165. }
  166. static void selectnodes(glCompObj *obj, float x, float y, glMouseButtonType t) {
  167. (void)obj;
  168. (void)x;
  169. (void)y;
  170. (void)t;
  171. view->Topview->sel.selectNodes = !view->Topview->sel.selectNodes;
  172. }
  173. glCompSet *glcreate_gl_topview_menu(void)
  174. {
  175. float y = 5;
  176. float off = 43;
  177. glCompSet *s = glCompSetNew(view->w, view->h);
  178. glCompPanel *p = NULL;
  179. glCompButton *b = NULL;
  180. glCompImage *i = NULL;
  181. glCompColor c;
  182. s->base.common.callbacks.click = CBglCompMouseRightClick;
  183. p = glCompPanelNew(s, 25, 25, 45, 47);
  184. p->base.common.align = glAlignLeft;
  185. p->base.common.data = 0;
  186. /*pan */
  187. b = glCompButtonNew(p, 1, y, 42, 42, "");
  188. {
  189. char *pan = smyrnaPath("pan.png");
  190. glCompButtonAddPngGlyph(b, pan);
  191. free(pan);
  192. }
  193. b->base.common.callbacks.click = menu_click_pan;
  194. panBtn = b;
  195. y = y + off;
  196. /*switch to fisheye */
  197. b = glCompButtonNew(p, 1, y, 42, 42, "");
  198. {
  199. char *fisheye = smyrnaPath("fisheye.png");
  200. glCompButtonAddPngGlyph(b, fisheye);
  201. free(fisheye);
  202. }
  203. b->base.common.callbacks.click = menu_switch_to_fisheye;
  204. toFisheye = b;
  205. /*switch to normal mode */
  206. b = glCompButtonNew(p, 1, y, 42, 42, "");
  207. {
  208. char *fisheye = smyrnaPath("no_fisheye.png");
  209. glCompButtonAddPngGlyph(b, fisheye);
  210. free(fisheye);
  211. }
  212. b->base.common.callbacks.click = menu_switch_to_fisheye;
  213. b->base.common.visible = 0;
  214. toNormal = b;
  215. y=y+off;
  216. b = glCompButtonNew(p, 1, y, 42, 42, "");
  217. {
  218. char *threed = smyrnaPath("3D.png");
  219. glCompButtonAddPngGlyph(b, threed);
  220. free(threed);
  221. }
  222. b->base.common.callbacks.click = switch2D3D;
  223. to3DBtn = b;
  224. b = glCompButtonNew(p, 1, y, 42, 42, "");
  225. {
  226. char *twod = smyrnaPath("2D.png");
  227. glCompButtonAddPngGlyph(b, twod);
  228. free(twod);
  229. }
  230. b->base.common.callbacks.click = switch2D3D;
  231. glCompButtonHide(b);
  232. to2DBtn = b;
  233. y=y+off;
  234. b = glCompButtonNew(p, 1, y, 42, 42, "N");
  235. b->base.common.callbacks.click = selectnodes;
  236. b->groupid=-1;
  237. b->status = true;
  238. y=y+off;
  239. b = glCompButtonNew(p, 1, y, 42, 42, "E");
  240. b->base.common.callbacks.click = selectedges;
  241. b->groupid=-1;
  242. p = glCompPanelNew(p, 1, 325, 45, 180);
  243. p->base.common.align = glAlignTop;
  244. p->base.common.data = 0;
  245. p->base.common.borderWidth = 1;
  246. p->shadowwidth = 0;
  247. c.R = 0.80f;
  248. c.G = 0.6f;
  249. c.B = 0.6f;
  250. c.A = 1.6f;
  251. y = 1;
  252. b = glCompButtonNew(p, 1, y, 42, 42, "");
  253. {
  254. char *details = smyrnaPath("details.png");
  255. glCompButtonAddPngGlyph(b, details);
  256. free(details);
  257. }
  258. b->base.common.callbacks.click = attrList;
  259. b->base.common.color = c;
  260. y = y + off;
  261. b = glCompButtonNew(p, 1, y, 42, 42, "");
  262. {
  263. char *zoomin = smyrnaPath("zoomin.png");
  264. glCompButtonAddPngGlyph(b, zoomin);
  265. free(zoomin);
  266. }
  267. b->groupid = 0;
  268. b->base.common.callbacks.click = menu_click_zoom_plus;
  269. b->base.common.color = c;
  270. y = y + off;
  271. b = glCompButtonNew(p, 1, y, 42, 42, "");
  272. {
  273. char *zoomout = smyrnaPath("zoomout.png");
  274. glCompButtonAddPngGlyph(b, zoomout);
  275. free(zoomout);
  276. }
  277. b->base.common.callbacks.click = menu_click_zoom_minus;
  278. b->base.common.color = c;
  279. y = y + off;
  280. b = glCompButtonNew(p, 1, y, 42, 42, "");
  281. {
  282. char *center = smyrnaPath("center.png");
  283. glCompButtonAddPngGlyph(b, center);
  284. free(center);
  285. }
  286. b->base.common.callbacks.click = menu_click_center;
  287. b->base.common.color = c;
  288. p = glCompPanelNew(s, -250, 550, 150, 175);
  289. p->base.common.borderWidth = 0;
  290. p->shadowwidth = 0;
  291. p->base.common.color.R = 0;
  292. p->base.common.color.G = 0;
  293. p->base.common.color.B = 1;
  294. p->base.common.color.A = 0.2f;
  295. p->base.common.visible = 0;
  296. sel = p;
  297. s->base.common.callbacks.mouseover = glCompMouseMove;
  298. s->base.common.callbacks.mouseup = CBglCompMouseUp;
  299. p = glCompPanelNew(s, 25, 25, 52, 47);
  300. p->base.common.align = glAlignRight;
  301. p->base.common.data = 0;
  302. p->base.common.color.A = 0;
  303. p = glCompPanelNew(p, 25, 0, 52, 110);
  304. p->base.common.align = glAlignTop;
  305. p->base.common.data = 0;
  306. p->base.common.color.A = 0;
  307. p->shadowwidth = 0;
  308. i = glCompImageNew(p, 0, 0);
  309. {
  310. char *fisheye = smyrnaPath("mod_fisheye.png");
  311. glCompImageLoadPng(i, fisheye);
  312. free(fisheye);
  313. }
  314. imgFisheye = i;
  315. i->base.common.visible = 0;
  316. i = glCompImageNew(p, 0, 52);
  317. {
  318. char *threed = smyrnaPath("mod_3D.png");
  319. glCompImageLoadPng(i, threed);
  320. free(threed);
  321. }
  322. img3D = i;
  323. i->base.common.visible = 0;
  324. return s;
  325. }