1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include <libpspp/tower.h>
22 #include "psppire-axis.h"
26 /* --- prototypes --- */
27 static void psppire_axis_class_init (PsppireAxisClass *class);
28 static void psppire_axis_init (PsppireAxis *axis);
29 static void psppire_axis_finalize (GObject *object);
32 /* --- variables --- */
33 static GObjectClass *parent_class = NULL;
35 /* --- functions --- */
37 * psppire_axis_get_type:
38 * @returns: the type ID for accelerator groups.
41 psppire_axis_get_type (void)
43 static GType object_type = 0;
47 static const GTypeInfo object_info = {
48 sizeof (PsppireAxisClass),
50 (GBaseFinalizeFunc) NULL,
51 (GClassInitFunc) psppire_axis_class_init,
52 NULL, /* class_finalize */
53 NULL, /* class_data */
56 (GInstanceInitFunc) psppire_axis_init,
59 object_type = g_type_register_static (G_TYPE_OBJECT,
69 psppire_axis_class_init (PsppireAxisClass *class)
71 GObjectClass *object_class = G_OBJECT_CLASS (class);
73 parent_class = g_type_class_peek_parent (class);
75 object_class->finalize = psppire_axis_finalize;
79 psppire_axis_init (PsppireAxis *axis)
81 tower_init (&axis->tower);
86 psppire_axis_finalize (GObject *object)
88 G_OBJECT_CLASS (parent_class)->finalize (object);
93 * @returns: a new #PsppireAxis object
95 * Creates a new #PsppireAxis.
98 psppire_axis_new (gint w)
100 PsppireAxis *new_axis = g_object_new (G_TYPE_PSPPIRE_AXIS, NULL);
109 psppire_axis_unit_size (PsppireAxis *a, gint unit)
113 const struct tower_node *node;
114 if (unit >= tower_count (&a->tower))
117 node = tower_get (&a->tower, unit);
119 return tower_node_get_size (node);
126 psppire_axis_unit_count (PsppireAxis *a)
129 return tower_count (&a->tower);
135 psppire_axis_pixel_start (PsppireAxis *a, gint unit)
137 if ( a->width == -1 )
139 const struct tower_node *node;
141 if ( unit >= tower_count (&a->tower))
142 return tower_height (&a->tower);
144 node = tower_get (&a->tower, unit);
146 return tower_node_get_level (node);
149 return a->width * unit;
153 psppire_axis_get_unit_at_pixel (PsppireAxis *a, glong pixel)
157 const struct tower_node *node;
158 unsigned long int node_start;
160 if (pixel >= tower_height (&a->tower))
161 return tower_count (&a->tower);
163 node = tower_lookup (&a->tower, pixel, &node_start);
165 return tower_node_get_index (node);
168 return pixel / a->width;
172 psppire_axis_append (PsppireAxis *a, gint width)
174 struct tower_node *new = g_slice_alloc0 (sizeof *new);
175 tower_insert (&a->tower, width, new, NULL);