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