File: glmotion.c

package info (click to toggle)
graphviz 14.0.5-2
  • links: PTS
  • area: main
  • in suites: sid
  • size: 139,388 kB
  • sloc: ansic: 141,938; cpp: 11,957; python: 7,766; makefile: 4,043; yacc: 3,030; xml: 2,972; tcl: 2,495; sh: 1,388; objc: 1,159; java: 560; lex: 423; perl: 243; awk: 156; pascal: 139; php: 58; ruby: 49; cs: 31; sed: 1
file content (82 lines) | stat: -rw-r--r-- 2,665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*************************************************************************
 * Copyright (c) 2011 AT&T Intellectual Property 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: Details at https://graphviz.org
 *************************************************************************/

#include "glmotion.h"
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkgl.h>
#include <gdk/gdkcursor.h>
#include "draw.h"
#include <glcomp/glutils.h>
#include "hotkeymap.h"
#include <stdint.h>

/*real zoom in out is done here, all other functions send this one what they desire, it is not guranteed,*/
static void graph_zoom(double real_zoom) {
    double old_zoom;

    if (view->active_camera == SIZE_MAX)
		old_zoom = view->zoom;
    else
		old_zoom = view->cameras[view->active_camera]->r;

    if (real_zoom < view->Topview->fitin_zoom * MAX_ZOOM)
		real_zoom = view->Topview->fitin_zoom * MAX_ZOOM;
    if (real_zoom > view->Topview->fitin_zoom * MIN_ZOOM)
		real_zoom = view->Topview->fitin_zoom * MIN_ZOOM;
    if (view->active_camera == SIZE_MAX)
		view->zoom = real_zoom;
    else
		view->cameras[view->active_camera]->r = real_zoom * -1;
    /*adjust pan values */
    view->panx = old_zoom * view->panx / real_zoom;
    view->pany = old_zoom * view->pany / real_zoom;
}

void glmotion_zoom_inc(int zoomin)
{
    if (zoomin)			/*zooming in , zoom value should be decreased */
	graph_zoom(view->zoom - view->zoom * 0.25);
    else
	graph_zoom(view->zoom + view->zoom * 0.25);	/*zoom out */
    glexpose();

}

void glmotion_zoom(void)
{
    double real_zoom;
    if (view->active_camera == SIZE_MAX) {
	real_zoom =
	    view->zoom + view->mouse.dragX / 10 * (view->zoom * -1 / 20);
    } else {
	real_zoom =
	    (view->cameras[view->active_camera]->r +
	     view->mouse.dragX / 10 * (view->cameras[view->active_camera]->r /
				    20)) * -1;
    }
    graph_zoom(real_zoom);

}

void glmotion_pan(ViewInfo * v)
{
    if (v->active_camera == SIZE_MAX) {
	const double gldx = GetOGLDistance(v->mouse.dragX) / v->zoom * -1;
	const double gldy = GetOGLDistance(v->mouse.dragY) / v->zoom * -1;
	v->panx = v->panx - gldx;
	v->pany = v->pany + gldy;
    } else {
	const double gldx = GetOGLDistance(v->mouse.dragX) / v->cameras[v->active_camera]->r;
	const double gldy = GetOGLDistance(v->mouse.dragY) / v->cameras[v->active_camera]->r;
	v->cameras[v->active_camera]->targetx -= gldx;
	v->cameras[v->active_camera]->targety += gldy;
    }
}