summaryrefslogtreecommitdiffstats
path: root/src/controller/callbacks/reshape.c (plain)
blob: 99557b7eb2603ff69d363821fc830fa24f53ba2b
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
83
84
85
86
87
#include "../../model/geometry/datarose_geometry.h"
#include "../../model/geometry/density_legend_geometry.h"
#include "../../view/state0.h"
#include "../actions/set_ortho.h"
#include "reshape.h"
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>

#define S state0

void
reshape (int w, int h)
{
  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();

  /*
   * Scale the zoom region to the aspect ratio of the window.
   */
  if (S.zoom.active)
    {
      if (w >= h)
	{
	  double scale
	    =
	    (((S.zoom.coords[1] -
	       S.zoom.coords[0]) * ((double) w / (double) h)) -
	     (S.zoom.coords[1] - S.zoom.coords[0])) * 0.5;

	  S.ortho.min_x = S.zoom.coords[0] - scale;
	  S.ortho.max_x = S.zoom.coords[1] + scale;
	  S.ortho.min_y = S.zoom.coords[2];
	  S.ortho.max_y = S.zoom.coords[3];
	}
      else
	{
	  double scale
	    =
	    (((S.zoom.coords[3] -
	       S.zoom.coords[2]) * ((double) h / (double) w)) -
	     (S.zoom.coords[3] - S.zoom.coords[2])) * 0.5;

	  S.ortho.min_x = S.zoom.coords[0];
	  S.ortho.max_x = S.zoom.coords[1];
	  S.ortho.min_y = S.zoom.coords[2] - scale;
	  S.ortho.max_y = S.zoom.coords[3] + scale;
	}
    }

  else
    {
      /*
       * This scaling produces an odd effect when the coordinates are
       * not centered at 0,0.  When 0,0 is the lower left rather than
       * the center this reshape is a bit unnatural since the image is
       * not centered in the middle of the window.  Try chaning this
       * to use the method used above for the zoom region scaling.
       */
      if (w <= h)
	{
	  S.ortho.min_x = S.ortho_min;
	  S.ortho.max_x = S.ortho_max;
	  S.ortho.min_y = S.ortho_min * (double) h / (double) w;
	  S.ortho.max_y = S.ortho_max * (double) h / (double) w;
	}
      else
	{
	  S.ortho.min_x = S.ortho_min * (double) w / (double) h;
	  S.ortho.max_x = S.ortho_max * (double) w / (double) h;
	  S.ortho.min_y = S.ortho_min;
	  S.ortho.max_y = S.ortho_max;
	}
    }

  set_ortho ();

  glMatrixMode (GL_MODELVIEW);

  // Set the viewport equal to the size of the window.
  glViewport (0, 0, (GLsizei) w, (GLsizei) h);

  density_legend_geometry ();
  datarose_geometry ();

  return;
}

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.