summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 704744e)
raw | patch | inline | side by side (parent: 704744e)
author | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Fri, 18 Jan 2008 19:32:38 +0000 (19:32 +0000) | ||
committer | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Fri, 18 Jan 2008 19:32:38 +0000 (19:32 +0000) |
src/display/sp-canvas.cpp | patch | blob | history | |
src/widgets/ruler.cpp | patch | blob | history |
index 6fca902cef03c95bd07a9b8e73539a99179a324b..2033f8a69c180e5898d79c829d1f44c461c12fc0 100644 (file)
@@ -2092,8 +2092,8 @@ sp_canvas_scroll_to (SPCanvas *canvas, double cx, double cy, unsigned int clear,
g_return_if_fail (canvas != NULL);
g_return_if_fail (SP_IS_CANVAS (canvas));
- int ix = (int) (cx + 0.5);
- int iy = (int) (cy + 0.5);
+ int ix = (int) round(cx); //cx might be negative, so (int)(cx + 0.5) will not do!
+ int iy = (int) round(cy);
int dx = ix - canvas->x0;
int dy = iy - canvas->y0;
diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp
index c4ff1746c03a1db39c535871d5a7e6440fc6d329..07ee66c0ca3af135ddb64ce2669192f9577b5364 100644 (file)
--- a/src/widgets/ruler.cpp
+++ b/src/widgets/ruler.cpp
#include "widget-sizes.h"
#include "ruler.h"
#include "unit-constants.h"
+#include <iostream>
#define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
#define MAXIMUM_SCALES 10
-
-#define ROUND(x) int (std::floor ((x) + 0.5000000001))
-
+#define UNUSED_PIXELS 2 // There appear to be two pixels that are not being used at each end of the ruler
static void sp_hruler_class_init (SPHRulerClass *klass);
static void sp_hruler_init (SPHRuler *hruler);
GdkEventMotion *event)
{
GtkRuler *ruler;
- gint x;
-
+
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (SP_IS_HRULER (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
ruler = GTK_RULER (widget);
-
- x = (int)event->x;
-
- ruler->position = ruler->lower + ((ruler->upper - ruler->lower) * x) / widget->allocation.width;
-
+ double x = event->x; //Although event->x is double according to the docs, it only appears to return integers
+ ruler->position = ruler->lower + (ruler->upper - ruler->lower) * (x + UNUSED_PIXELS) / (widget->allocation.width + 2*UNUSED_PIXELS);
+
/* Make sure the ruler has been allocated already */
if (ruler->backing_store != NULL)
gtk_ruler_draw_pos (ruler);
xthickness = widget->style->xthickness;
ythickness = widget->style->ythickness;
- width = widget->allocation.width;
+ width = widget->allocation.width; // in pixels; is apparently 2 pixels shorter than the canvas at each end
height = widget->allocation.height;// - ythickness * 2;
gtk_paint_box (widget->style, ruler->backing_store,
if ((upper - lower) == 0)
return;
- increment = (double) width / (upper - lower);
+ increment = (double) (width + 2*UNUSED_PIXELS) / (upper - lower);
/* determine the scale
* We calculate the text size as for the vruler instead of using
while (cur <= end)
{
- pos = ROUND ((cur - lower) * increment);
+ pos = int(round ((cur - lower) * increment) - UNUSED_PIXELS);
gdk_draw_line (ruler->backing_store, gc,
pos, height + ythickness,
gc = widget->style->fg_gc[GTK_STATE_NORMAL];
xthickness = widget->style->xthickness;
ythickness = widget->style->ythickness;
- width = widget->allocation.width;
+ width = widget->allocation.width; // in pixels; is apparently 2 pixels shorter than the canvas at each end
height = widget->allocation.height - ythickness * 2;
bs_width = height / 2;
ruler->xsrc, ruler->ysrc,
bs_width, bs_height);
- increment = (gfloat) width / (ruler->upper - ruler->lower);
+ increment = (gfloat) (width + 2*UNUSED_PIXELS) / (ruler->upper - ruler->lower);
- x = ROUND ((ruler->position - ruler->lower) * increment) + (xthickness - bs_width) / 2 - 1;
+ x = int(round ((ruler->position - ruler->lower) * increment) + (xthickness - bs_width) / 2 - 1);
y = (height + bs_height) / 2 + ythickness;
for (i = 0; i < bs_height; i++)
GdkEventMotion *event)
{
GtkRuler *ruler;
- gint y;
-
+
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (SP_IS_VRULER (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
ruler = GTK_RULER (widget);
-
- y = (int)event->y;
-
- ruler->position = ruler->lower + ((ruler->upper - ruler->lower) * y) / widget->allocation.height;
+ double y = event->y; //Although event->y is double according to the docs, it only appears to return integers
+ ruler->position = ruler->lower + (ruler->upper - ruler->lower) * (y + UNUSED_PIXELS) / (widget->allocation.height + 2*UNUSED_PIXELS);
/* Make sure the ruler has been allocated already */
if (ruler->backing_store != NULL)
xthickness = widget->style->xthickness;
ythickness = widget->style->ythickness;
- width = widget->allocation.height;
+ width = widget->allocation.height; //in pixels; is apparently 2 pixels shorter than the canvas at each end
height = widget->allocation.width;// - ythickness * 2;
gtk_paint_box (widget->style, ruler->backing_store,
if ((upper - lower) == 0)
return;
- increment = (double) width / (upper - lower);
+ increment = (double) (width + 2*UNUSED_PIXELS) / (upper - lower);
/* determine the scale
* use the maximum extents of the ruler to determine the largest
cur = start;
while (cur < end) {
- pos = ROUND ((cur - lower) * increment);
+ pos = int(round ((cur - lower) * increment) - UNUSED_PIXELS);
gdk_draw_line (ruler->backing_store, gc,
height + xthickness - length, pos,
xthickness = widget->style->xthickness;
ythickness = widget->style->ythickness;
width = widget->allocation.width - xthickness * 2;
- height = widget->allocation.height;
+ height = widget->allocation.height; // in pixels; is apparently 2 pixels shorter than the canvas at each end
bs_height = width / 2;
bs_height |= 1; /* make sure it's odd */
ruler->xsrc, ruler->ysrc,
bs_width, bs_height);
- increment = (gfloat) height / (ruler->upper - ruler->lower);
+ increment = (gfloat) (height + 2*UNUSED_PIXELS) / (ruler->upper - ruler->lower);
x = (width + bs_width) / 2 + xthickness;
- y = ROUND ((ruler->position - ruler->lower) * increment) + (ythickness - bs_height) / 2 - 1;
+ y = int(round ((ruler->position - ruler->lower) * increment) + (ythickness - bs_height) / 2 - 1);
for (i = 0; i < bs_width; i++)
gdk_draw_line (widget->window, gc,