summaryrefslogtreecommitdiffstats
path: root/src/controller/callbacks/mouse_wheel.c (plain)
blob: 9ca73bc7a3c1ed766a6ba10dec0a919df4ca619d
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
#include "mouse_wheel.h"
#include "../actions/zoom.h"
#include "../../view/state0.h"
#include <GL/glut.h>
#include <math.h>

#define S state0

void
mouse_wheel (int button, int dir, int x, int y)
{
  /*
   * Start at the origin of the window.  An alternative would be to
   * start at the position of the mouse.  Calculate a bounding box
   * that will be the selection and zoom to it.
   */
  double width = fabs(S.ortho.max_x - S.ortho.min_x);
  double height = fabs(S.ortho.max_y - S.ortho.min_y);

  /*
   * Box the smaller of the two dimensions.
   */
  double box = 0.0;
  if (width <= height)
    box = width;
  else
    box = height;

  /*
   * The step size could be either a fixed number of pixels or a
   * percentage.  Here we take 10% of the size of the box.
   */
  double step = box * 0.10;

  double x1 = 0.0;
  double y1 = 0.0;
  double x2 = 0.0;
  double y2 = 0.0;

  if (width < height)
    {
      x1 = S.ortho.min_x;
      x2 = S.ortho.max_x;
      y1 = ((S.ortho.max_y + S.ortho.min_y) / 2.0) - (0.5 * width);
      y2 = ((S.ortho.max_y + S.ortho.min_y) / 2.0) + (0.5 * width);
    }
  else if (width > height)
    {
      x1 = ((S.ortho.max_x + S.ortho.min_x) / 2.0) - (0.5 * height);
      x2 = ((S.ortho.max_x + S.ortho.min_x) / 2.0) + (0.5 * height);
      y1 = S.ortho.min_y;
      y2 = S.ortho.max_y;
    }
  else
    {
      x1 = S.ortho.min_x;
      x2 = S.ortho.max_x;
      y1 = S.ortho.min_y;
      y2 = S.ortho.max_y;
    }

  // Zoom in
  if (dir > 0)
    {
      zoom (x1 + step, y1 + step, x2 - step, y2 - step);
    }

  // Zoom out
  else
    {
      zoom (x1 - step, y1 - step, x2 + step, y2 + step);
    }

  return;
}

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.