summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6138b9d)
raw | patch | inline | side by side (parent: 6138b9d)
author | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Wed, 30 Jan 2008 20:05:58 +0000 (20:05 +0000) | ||
committer | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Wed, 30 Jan 2008 20:05:58 +0000 (20:05 +0000) |
diff --git a/src/desktop.cpp b/src/desktop.cpp
index 9498d539910940307901fb5ac8177430850cdf5f..8cd63a68cd9ed1eb47b4af87958b54670fcdf15a 100644 (file)
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
}
/**
- * Set viewbox.
+ * Set viewbox (x0, x1, y0 and y1 are in document pixels. Border is in screen pixels).
*/
void
SPDesktop::set_display_area (double x0, double y0, double x1, double y1, double border, bool log)
newscale = viewbox.dimensions()[NR::Y] / (y1 - y0);
}
- newscale = CLAMP(newscale, SP_DESKTOP_ZOOM_MIN, SP_DESKTOP_ZOOM_MAX);
+ newscale = CLAMP(newscale, SP_DESKTOP_ZOOM_MIN, SP_DESKTOP_ZOOM_MAX); // unit: 'screen pixels' per 'document pixels'
int clear = FALSE;
if (!NR_DF_TEST_CLOSE (newscale, scale, 1e-4 * scale)) {
clear = TRUE;
}
- /* Calculate top left corner */
+ /* Calculate top left corner (in document pixels) */
x0 = cx - 0.5 * viewbox.dimensions()[NR::X] / newscale;
y1 = cy + 0.5 * viewbox.dimensions()[NR::Y] / newscale;
index 2033f8a69c180e5898d79c829d1f44c461c12fc0..cce43825ac858e8b069f5a0da28a54df55ea8003 100644 (file)
}
widget->allocation = *allocation;
-
+
if (GTK_WIDGET_REALIZED (widget)) {
gdk_window_move_resize (widget->window,
widget->allocation.x, widget->allocation.y,
}
/**
- * Scrolls canvas to specific position.
+ * Scrolls canvas to specific position (cx and cy are measured in screen pixels)
*/
void
sp_canvas_scroll_to (SPCanvas *canvas, double cx, double cy, unsigned int clear, bool is_scrolling)
@@ -2092,12 +2092,12 @@ 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) 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;
+ int ix = (int) round(cx); // ix and iy are the new canvas coordinates (integer screen pixels)
+ int iy = (int) round(cy); // cx might be negative, so (int)(cx + 0.5) will not do!
+ int dx = ix - canvas->x0; // dx and dy specify the displacement (scroll) of the
+ int dy = iy - canvas->y0; // canvas w.r.t its previous position
- canvas->dx0 = cx;
+ canvas->dx0 = cx; // here the 'd' stands for double, not delta!
canvas->dy0 = cy;
canvas->x0 = ix;
canvas->y0 = iy;
index 4d44b1b26eea4fc682f125b0df3fc91c822721ab..76452d8515dbf730bc69a3b8065db600f83a5793 100644 (file)
void
sp_desktop_widget_update_rulers (SPDesktopWidget *dtw)
{
- NR::Rect const viewbox = dtw->canvas->getViewbox();
+ sp_desktop_widget_update_hruler(dtw);
+ sp_desktop_widget_update_vruler(dtw);
+}
+
+void
+sp_desktop_widget_update_hruler (SPDesktopWidget *dtw)
+{
+ NR::Rect viewbox = dtw->canvas->getViewbox();
+
double const scale = dtw->desktop->current_zoom();
double s = viewbox.min()[NR::X] / scale - dtw->ruler_origin[NR::X];
double e = viewbox.max()[NR::X] / scale - dtw->ruler_origin[NR::X];
gtk_ruler_set_range(GTK_RULER(dtw->hruler), s, e, GTK_RULER(dtw->hruler)->position, (e - s));
- s = viewbox.min()[NR::Y] / -scale - dtw->ruler_origin[NR::Y];
- e = viewbox.max()[NR::Y] / -scale - dtw->ruler_origin[NR::Y];
+}
+
+void
+sp_desktop_widget_update_vruler (SPDesktopWidget *dtw)
+{
+ NR::Rect viewbox = dtw->canvas->getViewbox();
+
+ double const scale = dtw->desktop->current_zoom();
+ double s = viewbox.min()[NR::Y] / -scale - dtw->ruler_origin[NR::Y];
+ double e = viewbox.max()[NR::Y] / -scale - dtw->ruler_origin[NR::Y];
gtk_ruler_set_range(GTK_RULER(dtw->vruler), s, e, GTK_RULER(dtw->vruler)->position, (e - s));
}
index 8f38277abc72d33b5a54a7cb1f06b534d5bda900..c20a8524edcb431305a125e3e201d41994a479a6 100644 (file)
void sp_desktop_widget_layout(SPDesktopWidget *dtw);
void sp_desktop_widget_update_zoom(SPDesktopWidget *dtw);
void sp_desktop_widget_update_rulers (SPDesktopWidget *dtw);
+void sp_desktop_widget_update_hruler (SPDesktopWidget *dtw);
+void sp_desktop_widget_update_vruler (SPDesktopWidget *dtw);
/* Show/hide rulers & scrollbars */
void sp_desktop_widget_toggle_rulers (SPDesktopWidget *dtw);
diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp
index 07ee66c0ca3af135ddb64ce2669192f9577b5364..e0f0ba68051b5c119f78f0c198ee0c7810f00e23 100644 (file)
--- a/src/widgets/ruler.cpp
+++ b/src/widgets/ruler.cpp
#include <cstdio>
#include <string.h>
#include "widget-sizes.h"
+#include "desktop-widget.h"
#include "ruler.h"
#include "unit-constants.h"
-#include <iostream>
+#include "round.h"
#define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
static void sp_hruler_class_init (SPHRulerClass *klass);
static void sp_hruler_init (SPHRuler *hruler);
-static gint sp_hruler_motion_notify (GtkWidget *widget,
- GdkEventMotion *event);
+static gint sp_hruler_motion_notify (GtkWidget *widget, GdkEventMotion *event);
static void sp_hruler_draw_ticks (GtkRuler *ruler);
static void sp_hruler_draw_pos (GtkRuler *ruler);
+static void sp_hruler_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
+static GtkWidgetClass *hruler_parent_class;
GtkType
sp_hruler_get_type (void)
GtkWidgetClass *widget_class;
GtkRulerClass *ruler_class;
+ hruler_parent_class = (GtkWidgetClass *) gtk_type_class (GTK_TYPE_RULER);
+
widget_class = (GtkWidgetClass*) klass;
ruler_class = (GtkRulerClass*) klass;
widget_class->motion_notify_event = sp_hruler_motion_notify;
+ widget_class->size_allocate = sp_hruler_size_allocate;
ruler_class->draw_ticks = sp_hruler_draw_ticks;
ruler_class->draw_pos = sp_hruler_draw_pos;
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,
GTK_STATE_NORMAL, GTK_SHADOW_NONE,
NULL, widget, "hruler",
while (cur <= end)
{
- pos = int(round ((cur - lower) * increment) - UNUSED_PIXELS);
+ pos = int(Inkscape::round ((cur - lower) * increment) - UNUSED_PIXELS);
gdk_draw_line (ruler->backing_store, gc,
pos, height + ythickness,
increment = (gfloat) (width + 2*UNUSED_PIXELS) / (ruler->upper - ruler->lower);
- x = int(round ((ruler->position - ruler->lower) * increment) + (xthickness - bs_width) / 2 - 1);
+ x = int(Inkscape::round((ruler->position - ruler->lower) * increment + double(xthickness - bs_width) / 2.0) - 1);
y = (height + bs_height) / 2 + ythickness;
for (i = 0; i < bs_height; i++)
}
}
+/**
+ * The hruler widget's size_allocate callback.
+ */
+static void
+sp_hruler_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+ g_assert (widget != NULL);
+ g_assert (SP_IS_HRULER (widget));
+
+ // First call the default gtk_widget_size_allocate() method (which is being overridden here)
+ if (GTK_WIDGET_CLASS (hruler_parent_class)->size_allocate)
+ (* GTK_WIDGET_CLASS (hruler_parent_class)->size_allocate) (widget, allocation);
+
+ // Now the size of the ruler has changed, the ruler bounds (upper & lower) need to be updated
+ // For this we first need to obtain a pointer to the desktop, by walking up the tree of ancestors
+ GtkWidget *parent = gtk_widget_get_parent(widget);
+ do {
+ if (SP_IS_DESKTOP_WIDGET(parent)) {
+ // Now we've found the desktop widget we can have the ruler boundaries updated
+ sp_desktop_widget_update_hruler(SP_DESKTOP_WIDGET(parent));
+ // If the size of the ruler has increased, then a blank part is uncovered; therefore
+ // it must be redrawn
+ sp_hruler_draw_ticks(GTK_RULER(widget));
+ break;
+ }
+ parent = gtk_widget_get_parent(parent);
+ } while (parent != NULL);
+}
GdkEventMotion *event);
static void sp_vruler_draw_ticks (GtkRuler *ruler);
static void sp_vruler_draw_pos (GtkRuler *ruler);
+static void sp_vruler_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
+static GtkWidgetClass *vruler_parent_class;
GtkType
sp_vruler_get_type (void)
GtkWidgetClass *widget_class;
GtkRulerClass *ruler_class;
+ vruler_parent_class = (GtkWidgetClass *) gtk_type_class (GTK_TYPE_RULER);
+
widget_class = (GtkWidgetClass*) klass;
ruler_class = (GtkRulerClass*) klass;
widget_class->motion_notify_event = sp_vruler_motion_notify;
+ widget_class->size_allocate = sp_vruler_size_allocate;
ruler_class->draw_ticks = sp_vruler_draw_ticks;
ruler_class->draw_pos = sp_vruler_draw_pos;
upper = ruler->upper / ruler->metric->pixels_per_unit;
lower = ruler->lower / ruler->metric->pixels_per_unit;
-
+
if ((upper - lower) == 0)
return;
increment = (double) (width + 2*UNUSED_PIXELS) / (upper - lower);
cur = start;
while (cur < end) {
- pos = int(round ((cur - lower) * increment) - UNUSED_PIXELS);
+ pos = int(Inkscape::round ((cur - lower) * increment) - UNUSED_PIXELS);
gdk_draw_line (ruler->backing_store, gc,
height + xthickness - length, pos,
increment = (gfloat) (height + 2*UNUSED_PIXELS) / (ruler->upper - ruler->lower);
x = (width + bs_width) / 2 + xthickness;
- y = int(round ((ruler->position - ruler->lower) * increment) + (ythickness - bs_height) / 2 - 1);
+ y = int(Inkscape::round((ruler->position - ruler->lower) * increment + double(ythickness - bs_height) / 2.0) - 1);
for (i = 0; i < bs_width; i++)
gdk_draw_line (widget->window, gc,
}
}
+/**
+ * The vruler widget's size_allocate callback.
+ */
+static void
+sp_vruler_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+ g_assert (widget != NULL);
+ g_assert (SP_IS_VRULER (widget));
+
+ // First call the default gtk_widget_size_allocate() method (which is being overridden here)
+ if (GTK_WIDGET_CLASS (vruler_parent_class)->size_allocate)
+ (* GTK_WIDGET_CLASS (vruler_parent_class)->size_allocate) (widget, allocation);
+
+ // Now the size of the ruler has changed, the ruler bounds (upper & lower) need to be updated
+ // For this we first need to obtain a pointer to the desktop, by walking up the tree of ancestors
+ GtkWidget *parent = gtk_widget_get_parent(widget);
+ do {
+ if (SP_IS_DESKTOP_WIDGET(parent)) {
+ // Now we've found the desktop widget we can have the ruler boundaries updated
+ sp_desktop_widget_update_vruler(SP_DESKTOP_WIDGET(parent));
+ // If the size of the ruler has increased, then a blank part is uncovered; therefore
+ // it must be redrawn
+ sp_vruler_draw_ticks(GTK_RULER(widget));
+ break;
+ }
+ parent = gtk_widget_get_parent(parent);
+ } while (parent != NULL);
+}
+
+
/// Ruler metrics.
static GtkRulerMetric const sp_ruler_metrics[] = {
// NOTE: the order of records in this struct must correspond to the SPMetric enum.
diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h
index 1370c19c834aa65349a82a2c6791d85cf9f8f5bc..8aa162940b34bb0f3de11fcdad2bdf75ced1d197 100644 (file)
--- a/src/widgets/ruler.h
+++ b/src/widgets/ruler.h
#include <gtk/gtkruler.h>
#include "sp-metric.h"
-
+#include <iostream.h>
#include <glib.h>