[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: gaf.git: branch: master updated (1.5.1-20081221-129-g2874ca6)



The branch, master has been updated
       via  2874ca6c016115363ab9edb7809d5ca66509ca14 (commit)
       via  4d79aa73981d6caa2c803250d1be266d7657f0c2 (commit)
      from  e3cbd2a5505f6b284cbe12fdcf72acde6f6ef291 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


=========
 Summary
=========

 gschem/include/prototype.h        |   15 +
 gschem/src/Makefile.am            |    1 +
 gschem/src/a_pan.c                |    4 +-
 gschem/src/a_zoom.c               |   12 +-
 {libgeda => gschem}/src/m_basic.c |  462 ++++++++----------------
 gschem/src/o_arc.c                |   44 +--
 gschem/src/o_basic.c              |   16 +-
 gschem/src/o_box.c                |   48 ++--
 gschem/src/o_buffer.c             |    4 +-
 gschem/src/o_bus.c                |   31 +-
 gschem/src/o_circle.c             |   60 ++--
 gschem/src/o_complex.c            |    4 +-
 gschem/src/o_cue.c                |   24 +-
 gschem/src/o_find.c               |    4 +-
 gschem/src/o_grips.c              |    8 +-
 gschem/src/o_line.c               |   54 ++-
 gschem/src/o_misc.c               |    4 +-
 gschem/src/o_move.c               |   12 +-
 gschem/src/o_net.c                |   59 ++--
 gschem/src/o_path.c               |   51 ++--
 gschem/src/o_picture.c            |   40 +--
 gschem/src/o_pin.c                |   22 +-
 gschem/src/o_place.c              |    8 +-
 gschem/src/o_select.c             |   13 +-
 gschem/src/o_text.c               |   18 +-
 gschem/src/x_dialog.c             |    7 +-
 gschem/src/x_event.c              |   39 +--
 gschem/src/x_grid.c               |   35 +-
 gschem/src/x_image.c              |   14 +-
 libgeda/include/prototype.h       |   15 -
 libgeda/src/m_basic.c             |  705 +------------------------------------
 libgeda/src/o_line_basic.c        |   29 --
 32 files changed, 474 insertions(+), 1388 deletions(-)
 copy {libgeda => gschem}/src/m_basic.c (58%)


=================
 Commit Messages
=================

commit 2874ca6c016115363ab9edb7809d5ca66509ca14
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Sat Jan 3 19:54:04 2009 +0000

    Move world <-> screen coordinate transformation functions into gschem
    
    Convert them and their callers to use a GSCHEM_TOPLEVEL as an arguemnt
    rather than TOPLEVEL.
    
    This commit moves most of libgeda/src/m_basic.c to a new file,
    gschem/src/m_basic.c

:100644 100644 a668516... 061a33f... M	gschem/include/prototype.h
:100644 100644 2a4e7cf... 87c0c3a... M	gschem/src/Makefile.am
:100644 100644 9497cef... a5b3385... M	gschem/src/a_pan.c
:100644 100644 1afabde... 5b32c34... M	gschem/src/a_zoom.c
:000000 100644 0000000... 0e02b8c... A	gschem/src/m_basic.c
:100644 100644 c7d00ce... a9eba03... M	gschem/src/o_arc.c
:100644 100644 472ae12... d5bb316... M	gschem/src/o_basic.c
:100644 100644 72dddb8... edb8b36... M	gschem/src/o_box.c
:100644 100644 5b609ae... cf82276... M	gschem/src/o_buffer.c
:100644 100644 20d6d75... 9b1d87e... M	gschem/src/o_bus.c
:100644 100644 88d686b... 13668d9... M	gschem/src/o_circle.c
:100644 100644 6bc69f7... edd04f2... M	gschem/src/o_complex.c
:100644 100644 bc74598... e46efb8... M	gschem/src/o_cue.c
:100644 100644 f878a22... 65b55d7... M	gschem/src/o_find.c
:100644 100644 c764ddf... fb69ffb... M	gschem/src/o_grips.c
:100644 100644 bad3fc5... f283fe7... M	gschem/src/o_line.c
:100644 100644 8cf7075... ea82dc6... M	gschem/src/o_misc.c
:100644 100644 eaeae6a... 76eca40... M	gschem/src/o_move.c
:100644 100644 b75d513... 41f05ca... M	gschem/src/o_net.c
:100644 100644 50d0971... 50b78f3... M	gschem/src/o_path.c
:100644 100644 755eb5d... 314788d... M	gschem/src/o_picture.c
:100644 100644 bb117c3... 55771d6... M	gschem/src/o_pin.c
:100644 100644 0ea715b... 2001801... M	gschem/src/o_place.c
:100644 100644 0bd4046... 6617b62... M	gschem/src/o_select.c
:100644 100644 4f6f4ab... ba59787... M	gschem/src/o_text.c
:100644 100644 f0fdd0c... e61b398... M	gschem/src/x_dialog.c
:100644 100644 f0ebf63... e2ef971... M	gschem/src/x_event.c
:100644 100644 3b0ae7c... a98c168... M	gschem/src/x_grid.c
:100644 100644 857075e... 61d3270... M	gschem/src/x_image.c
:100644 100644 a8d5f61... 7fdd105... M	libgeda/include/prototype.h
:100644 100644 b5ca7c7... b46c3e6... M	libgeda/src/m_basic.c

commit 4d79aa73981d6caa2c803250d1be266d7657f0c2
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Sat Jan 3 19:54:03 2009 +0000

    Move o_line_visible() from libgeda into gschem
    
    This function relates to on-screen visibility, so should be in gschem.

:100644 100644 1bb685f... a668516... M	gschem/include/prototype.h
:100644 100644 ddd254a... 20d6d75... M	gschem/src/o_bus.c
:100644 100644 3ac4058... bad3fc5... M	gschem/src/o_line.c
:100644 100644 50595d3... b75d513... M	gschem/src/o_net.c
:100644 100644 9e37997... bb117c3... M	gschem/src/o_pin.c
:100644 100644 121a004... a8d5f61... M	libgeda/include/prototype.h
:100644 100644 d04fdf7... dec2ec5... M	libgeda/src/o_line_basic.c

=========
 Changes
=========

commit 2874ca6c016115363ab9edb7809d5ca66509ca14
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Sat Jan 3 19:54:04 2009 +0000

    Move world <-> screen coordinate transformation functions into gschem
    
    Convert them and their callers to use a GSCHEM_TOPLEVEL as an arguemnt
    rather than TOPLEVEL.
    
    This commit moves most of libgeda/src/m_basic.c to a new file,
    gschem/src/m_basic.c

diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index a668516..061a33f 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -452,6 +452,20 @@ gboolean i_callback_close_wm(GtkWidget *widget, GdkEvent *event, gpointer data);
 /* i_vars.c */
 void i_vars_set(GSCHEM_TOPLEVEL *w_current);
 void i_vars_freenames();
+ /* m_basic.c */
+int mil_x(GSCHEM_TOPLEVEL *w_current, int val);
+int mil_y(GSCHEM_TOPLEVEL *w_current, int val);
+int pix_x(GSCHEM_TOPLEVEL *w_current, int val);
+int pix_y(GSCHEM_TOPLEVEL *w_current, int val);
+void WORLDtoSCREEN(GSCHEM_TOPLEVEL *w_current, int x, int y, int *px, int *py);
+void SCREENtoWORLD(GSCHEM_TOPLEVEL *w_current, int mx, int my, int *x, int *y);
+int snap_grid(GSCHEM_TOPLEVEL *w_current, int input);
+int SCREENabs(GSCHEM_TOPLEVEL *w_current, int val);
+int WORLDabs(GSCHEM_TOPLEVEL *w_current, int val);
+int SCREENclip_change(GSCHEM_TOPLEVEL *w_current, int *x1, int *y1, int *x2, int *y2);
+int clip_nochange(GSCHEM_TOPLEVEL *w_current, int x1, int y1, int x2, int y2);
+int visible(GSCHEM_TOPLEVEL *w_current, int wleft, int wtop, int wright, int wbottom);
+double round_5_2_1(double unrounded);
 /* o_arc.c */
 void o_arc_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current);
 void o_arc_invalidate_rubber(GSCHEM_TOPLEVEL *w_current);
diff --git a/gschem/src/Makefile.am b/gschem/src/Makefile.am
index 2a4e7cf..87c0c3a 100644
--- a/gschem/src/Makefile.am
+++ b/gschem/src/Makefile.am
@@ -21,6 +21,7 @@ gschem_SOURCES = \
 	i_basic.c \
 	i_callbacks.c \
 	i_vars.c \
+	m_basic.c \
 	o_arc.c \
 	o_attrib.c \
 	o_basic.c \
diff --git a/gschem/src/a_pan.c b/gschem/src/a_pan.c
index 9497cef..a5b3385 100644
--- a/gschem/src/a_pan.c
+++ b/gschem/src/a_pan.c
@@ -205,8 +205,8 @@ void a_pan_mouse(GSCHEM_TOPLEVEL *w_current, int diff_x, int diff_y)
   page_cx = (toplevel->page_current->left + toplevel->page_current->right) / 2.0;
   page_cy = (toplevel->page_current->top + toplevel->page_current->bottom) / 2.0;
 
-  world_cx = page_cx - WORLDabs(toplevel, diff_x);
-  world_cy = page_cy + WORLDabs(toplevel, diff_y);
+  world_cx = page_cx - WORLDabs (w_current, diff_x);
+  world_cy = page_cy + WORLDabs (w_current, diff_y);
 
 #if DEBUG
   printf("  world_cx=%f, world_cy=%f, world_dx=%d, world_dy=%d\n",
diff --git a/gschem/src/a_zoom.c b/gschem/src/a_zoom.c
index 1afabde..5b32c34 100644
--- a/gschem/src/a_zoom.c
+++ b/gschem/src/a_zoom.c
@@ -123,7 +123,7 @@ void a_zoom(GSCHEM_TOPLEVEL *w_current, int dir, int selected_from, int pan_flag
 	
   /* warp the cursor to the right position */ 
   if (w_current->warp_cursor) {
-     WORLDtoSCREEN(toplevel, world_pan_center_x, world_pan_center_y,
+     WORLDtoSCREEN (w_current, world_pan_center_x, world_pan_center_y,
 		   &start_x, &start_y);
      x_basic_warp_cursor (w_current->drawing_area, start_x, start_y);
   }
@@ -281,11 +281,10 @@ void a_zoom_box_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
  */
 void a_zoom_box_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   o_invalidate_rect (w_current, x1, y1, x2, y1);
   o_invalidate_rect (w_current, x1, y1, x1, y2);
@@ -300,11 +299,10 @@ void a_zoom_box_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void a_zoom_box_draw_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   gschem_cairo_box (w_current->cr, 1, x1, y1, x2, y2);
 
diff --git a/gschem/src/m_basic.c b/gschem/src/m_basic.c
new file mode 100644
index 0000000..0e02b8c
--- /dev/null
+++ b/gschem/src/m_basic.c
@@ -0,0 +1,739 @@
+/* gEDA - GPL Electronic Design Automation
+ * libgeda - gEDA's library
+ * Copyright (C) 1998-2008 Ales Hvezda
+ * Copyright (C) 1998-2008 gEDA Contributors (see ChangeLog for details)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
+ */
+#include <config.h>
+
+#include <stdio.h>
+#include <math.h>
+
+#include <gschem.h>
+
+#ifdef HAVE_LIBDMALLOC
+#include <dmalloc.h>
+#endif
+
+
+/*! \brief Convert a x coordinate to mils.
+ *  \par Function Description
+ *  Convert a x coordinate to mils.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object
+ *  \param [in] val        The x coordinate to convert
+ *  \return The coordinate value in mils.
+ */
+int mil_x (GSCHEM_TOPLEVEL *w_current, int val)
+{
+  double i;
+  double fval;
+  int j;
+
+  fval = val;
+  i = fval * w_current->toplevel->page_current->to_world_x_constant +
+      w_current->toplevel->page_current->left;
+
+#ifdef HAS_RINT
+  j = rint(i);
+#else
+  j = i;
+#endif
+
+  return(j);
+}
+
+/*! \brief Convert a y coordinate to mils
+ *  \par Function Description
+ *  Convert a y coordinate to mils
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in] val        The y coordinate to convert.
+ *  \return The coordinate value in mils.
+ */
+int mil_y(GSCHEM_TOPLEVEL *w_current, int val)
+{
+  double i;
+  double fval;
+  int j;
+
+  fval = w_current->toplevel->height - val;
+  i = fval * w_current->toplevel->page_current->to_world_y_constant +
+      w_current->toplevel->page_current->top;
+
+#ifdef HAS_RINT
+  j = rint(i);
+#else
+  j = i;
+#endif
+
+  return(j);
+}
+
+/*! \brief Convert a x coordinate to pixels.
+ *  \par Function Description
+ *  Convert a x coordinate to pixels.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object
+ *  \param [in] val        The x coordinate to convert
+ *  \return The coordinate value in pixels.
+ */
+int pix_x (GSCHEM_TOPLEVEL *w_current, int val)
+{
+
+  double i;
+  int j;
+
+  i = w_current->toplevel->page_current->to_screen_x_constant *
+        (double)(val - w_current->toplevel->page_current->left);
+
+#ifdef HAS_RINT
+  j = rint(i);
+#else
+  j = i;
+#endif
+
+  /* this is a temp solution to fix the wrapping associated with */
+  /* X coords being greated/less than than 2^15 */
+  if (j >= 32768) {
+    j = 32767;
+  }
+  if (j <= -32768) {
+    j = -32767;
+  }
+
+  return(j);
+}
+
+/*! \brief Convert a y coordinate to pixels.
+ *  \par Function Description
+ *  Convert a y coordinate to pixels.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object
+ *  \param [in] val        The y coordinate to convert
+ *  \return The coordinate value in pixels.
+ */
+int pix_y(GSCHEM_TOPLEVEL *w_current, int val)
+{
+  double i;
+  int j;
+
+  i = w_current->toplevel->height -
+        (w_current->toplevel->page_current->to_screen_y_constant *
+         (double)(val - w_current->toplevel->page_current->top));
+
+#ifdef HAS_RINT
+  j = rint(i);
+#else
+  j = i;
+#endif
+
+  /* this is a temp solution to fix the wrapping associated with */
+  /* X coords being greated/less than than 2^15 */
+  if (j >= 32768) {
+    j = 32767;
+  }
+  if (j <= -32768) {
+    j = -32767;
+  }
+
+  return(j);
+}
+
+/*! \brief Transform WORLD coordinates to SCREEN coordinates
+ *  \par Function Description
+ *  This function takes in WORLD x/y coordinates and
+ *  transforms them to SCREEN x/y coordinates.
+ *
+ *  \param [in]  w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in]  x          The x coordinate in WORLD units.
+ *  \param [in]  y          The y coordinate in WORLD units.
+ *  \param [out] px         The x coordinate in SCREEN units.
+ *  \param [out] py         The y coordinate in SCREEN units.
+ */
+void WORLDtoSCREEN (GSCHEM_TOPLEVEL *w_current, int x, int y, int *px, int *py)
+{
+  *px = pix_x (w_current, x);
+  *py = pix_y (w_current, y);
+}
+
+/*! \brief Transform WORLD coordinates to WORLD coordinates
+ *  \par Function Description
+ *  This function takes in SCREEN x/y coordinates and
+ *  transforms them to WORLD x/y coordinates.
+ *
+ *  \param [in]  w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in]  mx         The x coordinate in SCREEN units.
+ *  \param [in]  my         The y coordinate in SCREEN units.
+ *  \param [out] x          The x coordinate in WORLD units.
+ *  \param [out] y          The y coordinate in WORLD units.
+ *  \note Question: why are we returning in x and y
+ *                  if this is SCREEN to WORLD shouldn't WORLD
+ *                  coordinates be returned in mx and my?
+ */
+void SCREENtoWORLD (GSCHEM_TOPLEVEL *w_current, int mx, int my, int *x, int *y)
+{
+  *x = mil_x (w_current, mx);
+  *y = mil_y (w_current, my);
+}
+
+/*! \brief Find the closest grid coordinate.
+ *  \par Function Description
+ *  This function snaps the current input coordinate to the
+ *  closest grid coordinate.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in] input      The coordinate to snap.
+ *  \return The closest grid coordinate to the input.
+ */
+int snap_grid(GSCHEM_TOPLEVEL *w_current, int input)
+{
+  int p, m, n;
+  int sign, value, snap_grid;
+
+  if (w_current->toplevel->snap == SNAP_OFF ||
+      w_current->toplevel->snap_size <= 0) {
+    return(input);
+  }
+
+  snap_grid = w_current->toplevel->snap_size;
+
+  /* this code was inspired from killustrator, it's much simpler than mine */
+  sign = ( input < 0 ? -1 : 1 );
+  value = abs(input);
+
+  p = value / snap_grid;
+  m = value % snap_grid;
+  n = p * snap_grid;
+  if (m > snap_grid / 2)
+  n += snap_grid;
+
+#if DEBUG
+  printf("p: %d\n", p);
+  printf("m: %d\n", m);
+  printf("m > snap_grid / 2: %d\n", (m > snap_grid / 2));
+  printf("n: %d\n", n);
+  printf("n*s: %d\n", n*sign);
+#endif
+
+  return(sign*n);
+}
+
+/*! \brief Get absolute SCREEN coordinate.
+ *  \par Function Description
+ *  Get absolute SCREEN coordinate.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in] val        The coordinate to convert.
+ *  \return The converted SCREEN coordinate.
+ */
+int SCREENabs(GSCHEM_TOPLEVEL *w_current, int val)
+{
+  double fs,f0,f1,f;
+
+  double i;
+  int j;
+
+  f0 = w_current->toplevel->page_current->left;
+  f1 = w_current->toplevel->page_current->right;
+  fs = w_current->toplevel->width;
+  f = w_current->toplevel->width / (f1 - f0);
+  i = f * (double)(val);
+
+#ifdef HAS_RINT
+  j = rint(i);
+#else
+  j = i;
+#endif
+
+  return(j);
+
+}
+
+/*! \brief Get absolute WORLD coordinate.
+ *  \par Function Description
+ *  Get absolute WORLD coordinate.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in] val        The coordinate to convert.
+ *  \return The converted WORLD coordinate.
+ */
+int WORLDabs(GSCHEM_TOPLEVEL *w_current, int val)
+{
+  double fw0,fw1,fw,fval;
+
+  double i;
+  int j;
+
+  fw1 = w_current->toplevel->page_current->right;
+  fw0 = w_current->toplevel->page_current->left;
+  fw  = w_current->toplevel->width;
+  fval = val;
+  i = fval * (fw1 - fw0) / fw;
+
+#ifdef HAS_RINT
+  j = rint(i);
+#else
+  j = i;
+#endif
+
+  return(j);
+}
+
+
+/*! \brief */
+typedef struct st_halfspace HALFSPACE;
+
+/*! \brief */
+struct st_halfspace {
+  int left; /* these are booleans */
+  int top;
+  int right;
+  int bottom;
+};
+
+/* \note
+ * encode_halfspace and clip are part of the cohen-sutherland clipping
+ * algorithm.  They are used to determine if an object is visible or not
+ */
+/*! \brief Encode SCREEN coordinates as halfspace matrix.
+ *  \par Function Description
+ *  This function takes a point and checks if it is in the bounds
+ *  of the current TOPLEVEL object's page coordinates. It
+ *  handles points with SCREEN coordinates.
+ *
+ *  \param [in]  w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in]  point      The point in SCREEN coordinates to be checked.
+ *  \param [out] halfspace  The created HALFSPACE structure.
+ *
+ *  \warning halfspace must be allocated before this function is called
+ */
+static void SCREENencode_halfspace (GSCHEM_TOPLEVEL *w_current,
+                                    sPOINT *point, HALFSPACE *halfspace)
+{
+  halfspace->left = point->x < 0;
+  halfspace->right = point->x > w_current->toplevel->width;
+  halfspace->bottom = point->y > w_current->toplevel->height;
+  halfspace->top = point->y < 0;
+}
+
+/*! \brief Encode WORLD coordinates as halfspace matrix.
+ *  \par Function Description
+ *  This function takes a point and checks if it is in the bounds
+ *  of the current TOPLEVEL object's page coordinates. It
+ *  handles points with WORLD coordinates.
+ *
+ *  \param [in]  w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in]  point      The point in WORLD coordinates to be checked.
+ *  \param [out] halfspace  The created HALFSPACE structure.
+ *
+ *  \warning halfspace must be allocated before this function is called
+ */
+static void WORLDencode_halfspace (GSCHEM_TOPLEVEL *w_current,
+                                   sPOINT *point, HALFSPACE *halfspace)
+{
+  halfspace->left = point->x < w_current->toplevel->page_current->left;
+  halfspace->right = point->x > w_current->toplevel->page_current->right;
+  halfspace->bottom = point->y > w_current->toplevel->page_current->bottom;
+  halfspace->top = point->y < w_current->toplevel->page_current->top;
+}
+
+/*! \brief Calculate the cliping region for a set of coordinates.
+ *  \par Function Description
+ *  This function will check the provided set of coordinates to see if
+ *  they fall within a clipping region.  If they do the coordinates will
+ *  be changed to reflect only the region no covered by the clipping window.
+ *  All coordinates should be in SCREEN units.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in,out] x1     x coordinate of the first screen point.
+ *  \param [in,out] y1     y coordinate of the first screen point.
+ *  \param [in,out] x2     x coordinate of the second screen point.
+ *  \param [in,out] y2     y coordinate of the second screen point.
+ *  \return TRUE if coordinates are now visible, FALSE otherwise.
+ */
+int SCREENclip_change (GSCHEM_TOPLEVEL *w_current,
+                       int *x1, int *y1, int *x2, int *y2)
+{
+  HALFSPACE half1, half2;
+  HALFSPACE tmp_half;
+  sPOINT tmp_point;
+  sPOINT point1, point2;
+  float slope;
+  int in1, in2, done;
+  int visible;
+  int w_l, w_t, w_r, w_b;
+
+  point1.x = *x1;
+  point1.y = *y1;
+  point2.x = *x2;
+  point2.y = *y2;
+
+
+  w_l = 0;
+  w_t = 0;
+  w_r = w_current->toplevel->width;
+  w_b = w_current->toplevel->height;
+
+
+  done = FALSE;
+  visible = FALSE;
+
+  do {
+    SCREENencode_halfspace (w_current, &point1, &half1);
+    SCREENencode_halfspace (w_current, &point2, &half2);
+
+#if DEBUG
+    printf("starting loop\n");
+    printf("1 %d %d %d %d\n", half1.left, half1.top, half1.right, half1.bottom);
+    printf("2 %d %d %d %d\n", half2.left, half2.top, half2.right, half2.bottom);
+#endif
+
+    in1 = (!half1.left) &&
+      (!half1.top) &&
+      (!half1.right) &&
+      (!half1.bottom);
+
+    in2 = (!half2.left) &&
+      (!half2.top) &&
+      (!half2.right) &&
+      (!half2.bottom);
+
+
+    if (in1 && in2) { /* trivally accept */
+      done = TRUE;
+      visible = TRUE;
+    } else if ( ((half1.left && half2.left) ||
+                 (half1.right && half2.right)) ||
+                ((half1.top && half2.top) ||
+                 (half1.bottom && half2.bottom)) ) {
+      done = TRUE; /* trivially reject */
+      visible = FALSE;
+    } else { /* at least one point outside */
+      if (in1) {
+        tmp_half = half1;
+        half1 = half2;
+        half2 = tmp_half;
+
+        tmp_point = point1;
+        point1 = point2;
+        point2 = tmp_point;
+      }
+
+      if (point2.x == point1.x) { /* vertical line */
+        if (half1.top) {
+          point1.y = w_t;
+        } else if (half1.bottom) {
+          point1.y = w_b;
+        }
+      } else { /* not a vertical line */
+
+        /* possible fix for alpha core dumping */
+        /* assume the object is visible */
+        if ((point2.x - point1.x) == 0) {
+          return(TRUE);
+        }
+
+        slope = (float) (point2.y - point1.y) /
+          (float) (point2.x - point1.x);
+
+        /* possible fix for alpha core dumping */
+        /* assume the object is visible */
+        if (slope == 0.0) {
+          return(TRUE);
+        }
+
+        if (half1.left) {
+          point1.y = point1.y +
+            (w_l - point1.x) * slope;
+          point1.x = w_l;
+        } else if (half1.right) {
+          point1.y = point1.y +
+            (w_r - point1.x) * slope;
+          point1.x = w_r;
+        } else if (half1.bottom) {
+          point1.x = point1.x +
+            (w_b - point1.y) / slope;
+          point1.y = w_b;
+        } else if (half1.top) {
+          point1.x = point1.x +
+            (w_t - point1.y) / slope;
+          point1.y = w_t;
+        }
+      } /* end of not a vertical line */
+    } /* end of at least one outside */
+  } while (!done);
+
+  /*printf("after: %d %d %d %d\n", point1.x, point1.y, point2.x, point2.y);*/
+  *x1 = point1.x;
+  *y1 = point1.y;
+  *x2 = point2.x;
+  *y2 = point2.y;
+  return(visible);
+}
+
+/*! \brief Check if a set of coordinates are within a clipping region
+ *  \par Function Description
+ *  This function will check if the given set of coordinates
+ *  are within a clipping region. No action will be taken to change
+ *  the coordinates.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in,out] x1     x coordinate of the first screen point.
+ *  \param [in,out] y1     y coordinate of the first screen point.
+ *  \param [in,out] x2     x coordinate of the second screen point.
+ *  \param [in,out] y2     y coordinate of the second screen point.
+ *  \return TRUE if coordinates are now visible, FALSE otherwise.
+ */
+int clip_nochange (GSCHEM_TOPLEVEL *w_current, int x1, int y1, int x2, int y2)
+{
+  HALFSPACE half1, half2;
+  HALFSPACE tmp_half;
+  sPOINT tmp_point;
+  sPOINT point1, point2;
+  float slope;
+  int in1, in2, done;
+  int visible;
+  int w_l, w_t, w_r, w_b;
+
+  point1.x = x1;
+  point1.y = y1;
+  point2.x = x2;
+  point2.y = y2;
+
+  /*printf("before: %d %d %d %d\n", x1, y1, x2, y2);*/
+
+  w_l = w_current->toplevel->page_current->left;
+  w_t = w_current->toplevel->page_current->top;
+  w_r = w_current->toplevel->page_current->right;
+  w_b = w_current->toplevel->page_current->bottom;
+
+  done = FALSE;
+  visible = FALSE;
+
+  do {
+    WORLDencode_halfspace (w_current, &point1, &half1);
+    WORLDencode_halfspace (w_current, &point2, &half2);
+
+#if DEBUG
+    printf("starting loop\n");
+    printf("1 %d %d %d %d\n", half1.left, half1.top, half1.right, half1.bottom);
+    printf("2 %d %d %d %d\n", half2.left, half2.top, half2.right, half2.bottom);
+#endif
+
+    in1 = (!half1.left) &&
+      (!half1.top) &&
+      (!half1.right) &&
+      (!half1.bottom);
+
+    in2 = (!half2.left) &&
+      (!half2.top) &&
+      (!half2.right) &&
+      (!half2.bottom);
+
+
+    if (in1 && in2) { /* trivally accept */
+      done = TRUE;
+      visible = TRUE;
+    } else if ( ((half1.left && half2.left) ||
+                 (half1.right && half2.right)) ||
+                ((half1.top && half2.top) ||
+                 (half1.bottom && half2.bottom)) ) {
+      done = TRUE; /* trivially reject */
+      visible = FALSE;
+    } else { /* at least one point outside */
+      if (in1) {
+        tmp_half = half1;
+        half1 = half2;
+        half2 = tmp_half;
+
+        tmp_point = point1;
+        point1 = point2;
+        point2 = tmp_point;
+      }
+
+      if (point2.x == point1.x) { /* vertical line */
+        if (half1.top) {
+          point1.y = w_t;
+        } else if (half1.bottom) {
+          point1.y = w_b;
+        }
+      } else { /* not a vertical line */
+
+        /* possible fix for alpha core dumping */
+        /* assume the object is visible */
+        if ((point2.x - point1.x) == 0) {
+          return(TRUE);
+        }
+
+        slope = (float) (point2.y - point1.y) /
+          (float) (point2.x - point1.x);
+
+        /* possible fix for alpha core dumping */
+        /* assume the object is visible */
+        if (slope == 0.0) {
+          return(TRUE);
+        }
+
+        if (half1.left) {
+          point1.y = point1.y +
+            (w_l - point1.x) * slope;
+          point1.x = w_l;
+        } else if (half1.right) {
+          point1.y = point1.y +
+            (w_r - point1.x) * slope;
+          point1.x = w_r;
+        } else if (half1.bottom) {
+          point1.x = point1.x +
+            (w_b - point1.y) / slope;
+          point1.y = w_b;
+        } else if (half1.top) {
+          point1.x = point1.x +
+            (w_t - point1.y) / slope;
+          point1.y = w_t;
+        }
+      } /* end of not a vertical line */
+    } /* end of at least one outside */
+  } while (!done);
+
+  return(visible);
+}
+
+/*! \brief Check if a bounding box is visible on the screen.
+ *  \par Function Description
+ *  This function checks if a given bounding box is visible on the screen.
+ *
+ *  WARNING: top and bottom are mis-named in world-coords,
+ *  top is the smallest "y" value, and bottom is the largest.
+ *  Be careful! This doesn't correspond to what you'd expect.
+ *
+ *  \param [in] w_current  The GSCHEM_TOPLEVEL object.
+ *  \param [in] wleft      Left coordinate of the bounding box.
+ *  \param [in] wtop       Top coordinate of the bounding box.
+ *  \param [in] wright     Right coordinate of the bounding box.
+ *  \param [in] wbottom    Bottom coordinate of the bounding box.
+ *  \return TRUE if bounding box is visible, FALSE otherwise
+ */
+int visible (GSCHEM_TOPLEVEL *w_current,
+             int wleft, int wtop, int wright, int wbottom)
+{
+  int visible=FALSE;
+
+  /* don't do object clipping if this is false */
+  if (!w_current->toplevel->object_clipping) {
+    return(TRUE);
+  }
+
+  visible = clip_nochange (w_current, wleft, wtop, wright, wtop);
+
+#if DEBUG
+  printf("vis1 %d\n", visible);
+#endif
+
+  if (!visible) {
+    visible = clip_nochange (w_current, wleft, wbottom, wright, wbottom);
+  } else {
+    return(visible);
+  }
+
+#if DEBUG
+  printf("vis2 %d\n", visible);
+#endif
+
+  if (!visible) {
+    visible = clip_nochange (w_current, wleft, wtop, wleft, wbottom);
+  } else {
+    return(visible);
+  }
+
+#if DEBUG
+  printf("vis3 %d\n", visible);
+#endif
+
+  if (!visible) {
+    visible = clip_nochange (w_current, wright, wtop, wright, wbottom);
+  } else {
+    return(visible);
+  }
+
+#if DEBUG
+  printf("vis4 %d\n", visible);
+#endif
+
+#if DEBUG
+  printf("%d %d %d\n", wleft, w_current->toplevel->page_current->top, wright);
+  printf("%d %d %d\n", wtop, w_current->toplevel->page_current->top, wbottom);
+  printf("%d %d %d\n", wleft, w_current->toplevel->page_current->right, wright);
+  printf("%d %d %d\n", wtop, w_current->toplevel->page_current->bottom, wbottom);
+#endif
+
+  /*
+   * now check to see if bounding box encompasses the entire viewport.
+   * We only need to test if one point on the screen clipping boundary
+   * is indide the bounding box of the object.
+   */
+  if (w_current->toplevel->page_current->left >= wleft  &&
+      w_current->toplevel->page_current->left <= wright &&
+      w_current->toplevel->page_current->top >= wtop    &&
+      w_current->toplevel->page_current->top <= wbottom ) {
+    visible = 1;
+  }
+
+#if DEBUG
+  printf("vis5 %d\n", visible);
+#endif
+
+  return(visible);
+}
+
+
+/*! \brief Rounds numbers by a power of 10.
+ *  \par Function Description
+ *  This function will round numbers using a power of 10 method.
+ *  For example:
+ *                1235 rounds to 1000
+ *                 670 rounds to  500
+ *               0.234 rounds to  0.2
+ *  integer values would be enough if there are no numbers smaller than 1 (hw)
+ *
+ *  \param [in] unrounded  The number to be rounded.
+ *  \return The rounded number.
+ */
+/* rounds for example 1235 to 1000, 670 to 500, 0.234 to 0.2 ...
+int would be enough if there are no numbers smaller 1 (hw)*/
+double round_5_2_1(double unrounded)
+{
+  int digits;
+  double betw_1_10;
+
+  /*only using the automatic cast */
+  digits = log10(unrounded);
+  /* creates numbers between 1 and 10 */
+  betw_1_10 = unrounded / pow(10,digits);
+
+  if (betw_1_10 < 1.5) {
+    return(pow(10,digits));
+  }
+  if (betw_1_10 > 1.4 && betw_1_10 < 3.5 ) {
+    return(2*pow(10,digits));
+  }
+  if (betw_1_10 > 3.4 && betw_1_10 < 7.5 ) {
+    return(5*pow(10,digits));
+  }
+  else {
+    return(10*pow(10,digits));
+  }
+}
diff --git a/gschem/src/o_arc.c b/gschem/src/o_arc.c
index c7d00ce..a9eba03 100644
--- a/gschem/src/o_arc.c
+++ b/gschem/src/o_arc.c
@@ -83,18 +83,18 @@ void o_arc_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
   else
     color = x_color_lookup (o_current->color);
 
-  line_width = SCREENabs( toplevel, o_current->line_width );
+  line_width = SCREENabs (w_current, o_current->line_width);
   if(line_width <= 0) {
     line_width = 1;
   }
 
-  length = SCREENabs( toplevel, o_current->line_length );
-  space = SCREENabs( toplevel, o_current->line_space );
+  length = SCREENabs (w_current, o_current->line_length);
+  space = SCREENabs (w_current, o_current->line_space);
 
-  WORLDtoSCREEN (toplevel, o_current->arc->x - o_current->arc->width / 2,
+  WORLDtoSCREEN (w_current, o_current->arc->x - o_current->arc->width / 2,
                            o_current->arc->y + o_current->arc->height / 2,
                            &sx1, &sy1);
-  WORLDtoSCREEN (toplevel, o_current->arc->x + o_current->arc->width / 2,
+  WORLDtoSCREEN (w_current, o_current->arc->x + o_current->arc->width / 2,
                            o_current->arc->y - o_current->arc->height / 2,
                            &sx2, &sy2);
 
@@ -130,12 +130,10 @@ void o_arc_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
  */
 void o_arc_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
-
   int cx, cy, radius;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &cx, &cy);
-  radius = SCREENabs(toplevel, w_current->distance);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &cx, &cy);
+  radius = SCREENabs (w_current, w_current->distance);
 
   /* FIXME: This isn't a tight bounding box */
   o_invalidate_rect (w_current, cx - radius, cy - radius,
@@ -157,7 +155,6 @@ void o_arc_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_arc_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int sx1, sy1, sx2, sy2;
   int line_width = 1;
   int color;
@@ -172,10 +169,10 @@ void o_arc_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cur
     color = o_current->color;
   }
 
-  WORLDtoSCREEN (toplevel, o_current->arc->x + dx - o_current->arc->width / 2,
+  WORLDtoSCREEN (w_current, o_current->arc->x + dx - o_current->arc->width / 2,
                            o_current->arc->y + dy + o_current->arc->height / 2,
                            &sx1, &sy1);
-  WORLDtoSCREEN (toplevel, o_current->arc->x + dx + o_current->arc->width / 2,
+  WORLDtoSCREEN (w_current, o_current->arc->x + dx + o_current->arc->width / 2,
                            o_current->arc->y + dy- o_current->arc->height / 2,
                            &sx2, &sy2);
 
@@ -351,8 +348,8 @@ void o_arc_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y, int whichone)
      * The radius is taken as the biggest distance on the x and y
      * axis between the center of the arc and the mouse position.
      */		
-    diff_x = abs(w_current->first_wx - snap_grid(w_current->toplevel, w_x));
-    diff_y = abs(w_current->first_wy - snap_grid(w_current->toplevel, w_y));
+    diff_x = abs(w_current->first_wx - snap_grid (w_current, w_x));
+    diff_y = abs(w_current->first_wy - snap_grid (w_current, w_y));
     w_current->distance = max(diff_x, diff_y);
   }
   else if((whichone == ARC_START_ANGLE) || (whichone == ARC_END_ANGLE)) {
@@ -395,19 +392,17 @@ void o_arc_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y, int whichone)
  */
 void o_arc_draw_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
-
   double rad_angle;
   double radius;
   double cx, cy;
   int sx1, sy1, sx2, sy2, rx, ry;
 
-  WORLDtoSCREEN (toplevel, w_current->first_wx - w_current->distance,
-                           w_current->first_wy + w_current->distance,
-                           &sx1, &sy1);
-  WORLDtoSCREEN (toplevel, w_current->first_wx + w_current->distance,
-                           w_current->first_wy - w_current->distance,
-                           &sx2, &sy2);
+  WORLDtoSCREEN (w_current, w_current->first_wx - w_current->distance,
+                            w_current->first_wy + w_current->distance,
+                            &sx1, &sy1);
+  WORLDtoSCREEN (w_current, w_current->first_wx + w_current->distance,
+                            w_current->first_wy - w_current->distance,
+                            &sx2, &sy2);
 
   radius = (double)(sy2 - sy1) / 2.;
   cx = (double)(sx1 + sx2) / 2.;
@@ -445,7 +440,6 @@ void o_arc_draw_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_arc_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int radius, x, y, start_angle, end_angle;
   int x1, y1, x2, y2;
 
@@ -461,8 +455,8 @@ void o_arc_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
    *   <DT>*</DT><DD>one at the end of the arc - at (<B>x2</B>,<B>y2</B>).
    */
 
-  WORLDtoSCREEN( toplevel, o_current->arc->x, o_current->arc->y, &x, &y );
-  radius      = SCREENabs( toplevel, o_current->arc->width / 2 );
+  WORLDtoSCREEN (w_current, o_current->arc->x, o_current->arc->y, &x, &y);
+  radius      = SCREENabs (w_current, o_current->arc->width / 2);
   start_angle = o_current->arc->start_angle;
   end_angle   = o_current->arc->end_angle;
 
diff --git a/gschem/src/o_basic.c b/gschem/src/o_basic.c
index 472ae12..d5bb316 100644
--- a/gschem/src/o_basic.c
+++ b/gschem/src/o_basic.c
@@ -62,7 +62,7 @@ void o_redraw_rects (GSCHEM_TOPLEVEL *w_current,
   g_return_if_fail (toplevel->page_current != NULL);
 
   grip_half_size = o_grips_size (w_current);
-  cue_half_size = SCREENabs (toplevel, CUE_BOX_SIZE);
+  cue_half_size = SCREENabs (w_current, CUE_BOX_SIZE);
   bloat = MAX (grip_half_size, cue_half_size);
 
   world_rects = g_new (BOX, n_rectangles);
@@ -75,9 +75,9 @@ void o_redraw_rects (GSCHEM_TOPLEVEL *w_current,
     width = rectangles[i].width;
     height = rectangles[i].height;
 
-    SCREENtoWORLD (toplevel, x - bloat, y + height + bloat,
+    SCREENtoWORLD (w_current, x - bloat, y + height + bloat,
                    &world_rects[i].lower_x, &world_rects[i].lower_y);
-    SCREENtoWORLD (toplevel, x + width + bloat, y - bloat,
+    SCREENtoWORLD (w_current, x + width + bloat, y - bloat,
                    &world_rects[i].upper_x, &world_rects[i].upper_y);
   }
 
@@ -500,7 +500,7 @@ void o_invalidate_rect (GSCHEM_TOPLEVEL *w_current,
     return;
 
   grip_half_size = o_grips_size (w_current);
-  cue_half_size = SCREENabs (w_current->toplevel, CUE_BOX_SIZE);
+  cue_half_size = SCREENabs (w_current, CUE_BOX_SIZE);
   bloat = MAX (grip_half_size, cue_half_size) + INVALIDATE_MARGIN;
 
   rect.x = MIN(x1, x2) - bloat;
@@ -542,8 +542,8 @@ void o_invalidate (GSCHEM_TOPLEVEL *w_current, OBJECT *object)
   int s_left, s_top, s_bottom, s_right;
   if (world_get_single_object_bounds(toplevel, object, &left,  &top,
                                                        &right, &bottom)) {
-    WORLDtoSCREEN (toplevel, left, top, &s_left, &s_top);
-    WORLDtoSCREEN (toplevel, right, bottom, &s_right, &s_bottom);
+    WORLDtoSCREEN (w_current, left, top, &s_left, &s_top);
+    WORLDtoSCREEN (w_current, right, bottom, &s_right, &s_bottom);
     o_invalidate_rect (w_current, s_left, s_top, s_right, s_bottom);
   }
 }
@@ -565,8 +565,8 @@ void o_invalidate_glist (GSCHEM_TOPLEVEL *w_current, GList *list)
   int s_left, s_top, s_bottom, s_right;
   if (world_get_object_glist_bounds (toplevel, list, &left,  &top,
                                                      &right, &bottom)) {
-    WORLDtoSCREEN (toplevel, left, top, &s_left, &s_top);
-    WORLDtoSCREEN (toplevel, right, bottom, &s_right, &s_bottom);
+    WORLDtoSCREEN (w_current, left, top, &s_left, &s_top);
+    WORLDtoSCREEN (w_current, right, bottom, &s_right, &s_bottom);
     o_invalidate_rect (w_current, s_left, s_top, s_right, s_bottom);
   }
 }
diff --git a/gschem/src/o_box.c b/gschem/src/o_box.c
index 72dddb8..edb8b36 100644
--- a/gschem/src/o_box.c
+++ b/gschem/src/o_box.c
@@ -111,18 +111,18 @@ void o_box_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
    * encountered the box is drawn as a solid box independently of its
    * initial type.
    */
-  line_width = SCREENabs( toplevel, o_current->line_width );
+  line_width = SCREENabs (w_current, o_current->line_width);
   if(line_width <= 0) {
     line_width = 1;
   }
 
-  length = SCREENabs( toplevel, o_current->line_length );
-  space = SCREENabs( toplevel, o_current->line_space );
+  length = SCREENabs (w_current, o_current->line_length);
+  space = SCREENabs (w_current, o_current->line_space);
 
-  WORLDtoSCREEN( toplevel, o_current->box->upper_x, o_current->box->upper_y,
-                 &s_upper_x, &s_upper_y );
-  WORLDtoSCREEN( toplevel, o_current->box->lower_x, o_current->box->lower_y,
-                 &s_lower_x, &s_lower_y );
+  WORLDtoSCREEN (w_current, o_current->box->upper_x, o_current->box->upper_y,
+                 &s_upper_x, &s_upper_y);
+  WORLDtoSCREEN (w_current, o_current->box->lower_x, o_current->box->lower_y,
+                 &s_lower_x, &s_lower_y);
 
   /*
    * The values needed for the fill operation are taken from the
@@ -146,7 +146,7 @@ void o_box_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
    * to be distinct. If such a case is encountered the circle is filled
    * hollow (e.q. not filled).
    */
-  fill_width = SCREENabs( toplevel, o_current->fill_width );
+  fill_width = SCREENabs (w_current, o_current->fill_width);
   if(fill_width <= 0) {
     fill_width = 1;
   }
@@ -324,8 +324,8 @@ void o_box_fill_hatch (GdkDrawable *w, GdkGC *gc, COLOR *color,
     int x1, y1, x2, y2;
     LINE *line = &g_array_index (lines, LINE, i);
 
-    WORLDtoSCREEN (w_current->toplevel, line->x[0], line->y[0], &x1, &y1);
-    WORLDtoSCREEN (w_current->toplevel, line->x[1], line->y[1], &x2, &y2);
+    WORLDtoSCREEN (w_current, line->x[0], line->y[0], &x1, &y1);
+    WORLDtoSCREEN (w_current, line->x[1], line->y[1], &x2, &y2);
     gschem_cairo_line (w_current->cr, END_NONE, fill_width, x1, y1, x2, y2);
   }
   gschem_cairo_stroke (w_current->cr, TYPE_SOLID, END_NONE,
@@ -381,11 +381,10 @@ void o_box_fill_mesh (GdkDrawable *w, GdkGC *gc, COLOR *color,
  */
 void o_box_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN (toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN (toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   o_invalidate_rect (w_current, x1, y1, x2, y1);
   o_invalidate_rect (w_current, x1, y1, x1, y2);
@@ -408,7 +407,6 @@ void o_box_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_box_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int screen_x1, screen_y1;
   int screen_x2, screen_y2;
   int color;
@@ -417,10 +415,10 @@ void o_box_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cur
     return;
   }
 
-  WORLDtoSCREEN(toplevel, o_current->box->upper_x + dx, o_current->box->upper_y + dy,
-                &screen_x1, &screen_y1);
-  WORLDtoSCREEN(toplevel, o_current->box->lower_x + dx, o_current->box->lower_y + dy,
-                &screen_x2, &screen_y2);
+  WORLDtoSCREEN (w_current, o_current->box->upper_x + dx, o_current->box->upper_y + dy,
+                 &screen_x1, &screen_y1);
+  WORLDtoSCREEN (w_current, o_current->box->lower_x + dx, o_current->box->lower_y + dy,
+                 &screen_x2, &screen_y2);
 
   if (o_current->saved_color != -1) {
     color = o_current->saved_color;
@@ -583,11 +581,10 @@ void o_box_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
  */
 void o_box_draw_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   gschem_cairo_box (w_current->cr, 1, x1, y1, x2, y2);
 
@@ -609,16 +606,15 @@ void o_box_draw_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_box_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int s_upper_x, s_upper_y, s_lower_x, s_lower_y;
 
   if (w_current->draw_grips == FALSE)
 	  return;
   
-  WORLDtoSCREEN( toplevel, o_current->box->upper_x, o_current->box->upper_y,
-                 &s_upper_x, &s_upper_y );
-  WORLDtoSCREEN( toplevel, o_current->box->lower_x, o_current->box->lower_y,
-                 &s_lower_x, &s_lower_y );
+  WORLDtoSCREEN (w_current, o_current->box->upper_x, o_current->box->upper_y,
+                 &s_upper_x, &s_upper_y);
+  WORLDtoSCREEN (w_current, o_current->box->lower_x, o_current->box->lower_y,
+                 &s_lower_x, &s_lower_y);
 
   /* grip on upper left corner (whichone = BOX_UPPER_LEFT) */
   o_grips_draw(w_current, s_upper_x, s_upper_y);
diff --git a/gschem/src/o_buffer.c b/gschem/src/o_buffer.c
index 5b609ae..cf82276 100644
--- a/gschem/src/o_buffer.c
+++ b/gschem/src/o_buffer.c
@@ -129,8 +129,8 @@ void o_buffer_paste_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y,
   w_current->first_wy = w_y;
 
   /* snap x and y to the grid, pointed out by Martin Benes */
-  x = snap_grid(toplevel, rleft);
-  y = snap_grid(toplevel, rtop);
+  x = snap_grid (w_current, rleft);
+  y = snap_grid (w_current, rtop);
 
   o_glist_translate_world (toplevel, w_x - x, w_y - y,
                            toplevel->page_current->place_list);
diff --git a/gschem/src/o_bus.c b/gschem/src/o_bus.c
index 20d6d75..9b1d87e 100644
--- a/gschem/src/o_bus.c
+++ b/gschem/src/o_bus.c
@@ -59,7 +59,7 @@ void o_bus_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
   size = 1;
 
   if (toplevel->bus_style == THICK ) {
-    size = SCREENabs(toplevel, BUS_WIDTH);
+    size = SCREENabs (w_current, BUS_WIDTH);
 
     if (size < 1)
       size=1;
@@ -111,12 +111,12 @@ void o_bus_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cur
 
 
   if (toplevel->bus_style == THICK ) {
-    size = SCREENabs(toplevel, BUS_WIDTH);
+    size = SCREENabs (w_current, BUS_WIDTH);
     size += 1;
   }
 
-  WORLDtoSCREEN(toplevel, o_current->line->x[0] + dx, o_current->line->y[0] + dy, &sx[0], &sy[0] );
-  WORLDtoSCREEN(toplevel, o_current->line->x[1] + dx, o_current->line->y[1] + dy, &sx[1], &sy[1] );
+  WORLDtoSCREEN (w_current, o_current->line->x[0] + dx, o_current->line->y[0] + dy, &sx[0], &sy[0]);
+  WORLDtoSCREEN (w_current, o_current->line->x[1] + dx, o_current->line->y[1] + dy, &sx[1], &sy[1]);
 
   gschem_cairo_line (w_current->cr, END_NONE, 1, sx[0], sy[0], sx[1], sy[1]);
 
@@ -132,7 +132,6 @@ void o_bus_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cur
 void o_bus_draw_stretch (GSCHEM_TOPLEVEL *w_current,
                          int dx, int dy, int whichone, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int color;
   int dx1= - 1, dy1 = - 1, dx2 = -1, dy2 = -1;
   int x1, y1, x2, y2;
@@ -159,10 +158,10 @@ void o_bus_draw_stretch (GSCHEM_TOPLEVEL *w_current,
     fprintf(stderr, _("Got an invalid which one in o_bus_draw_stretch\n"));
   }
 
-  WORLDtoSCREEN (toplevel, o_current->line->x[0] + dx1,
-                           o_current->line->y[0] + dy1, &x1, &y1);
-  WORLDtoSCREEN (toplevel, o_current->line->x[1] + dx2,
-                           o_current->line->y[1] + dy2, &x2, &y2);
+  WORLDtoSCREEN (w_current, o_current->line->x[0] + dx1,
+                            o_current->line->y[0] + dy1, &x1, &y1);
+  WORLDtoSCREEN (w_current, o_current->line->x[1] + dx2,
+                            o_current->line->y[1] + dy2, &x2, &y2);
 
   gschem_cairo_line (w_current->cr, END_NONE, 1, x1, y1, x2, y2);
 
@@ -302,11 +301,11 @@ void o_bus_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
   int min_x, min_y, max_x, max_y;
   int bloat = 0;
 
-  WORLDtoSCREEN (toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN (toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   if (toplevel->bus_style == THICK ) {
-    bloat = SCREENabs(toplevel, BUS_WIDTH) / 2;
+    bloat = SCREENabs (w_current, BUS_WIDTH) / 2;
   }
 
   min_x = min (x1, x2) - bloat;
@@ -333,11 +332,11 @@ void o_bus_draw_rubber (GSCHEM_TOPLEVEL *w_current)
   TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2, size = 0;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   if (toplevel->bus_style == THICK)
-    size = SCREENabs(toplevel, BUS_WIDTH);
+    size = SCREENabs (w_current, BUS_WIDTH);
 
   if (size < 1)
     size = 1;
diff --git a/gschem/src/o_circle.c b/gschem/src/o_circle.c
index 88d686b..13668d9 100644
--- a/gschem/src/o_circle.c
+++ b/gschem/src/o_circle.c
@@ -96,13 +96,13 @@ void o_circle_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
    * to an endless loop in function called after. If such a case is encountered
    * the circle is drawn as a solid circle independently of its initial type.
    */
-  line_width = SCREENabs( toplevel, o_current->line_width );
+  line_width = SCREENabs (w_current, o_current->line_width);
   if (line_width <= 0) {
     line_width = 1;
   }
 
-  length = SCREENabs( toplevel, o_current->line_length );
-  space = SCREENabs( toplevel, o_current->line_space );
+  length = SCREENabs (w_current, o_current->line_length);
+  space = SCREENabs (w_current, o_current->line_space);
 
   /*
    * The values needed for the fill operation are taken from the
@@ -125,7 +125,7 @@ void o_circle_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
    * distinct. If such a case is encountered the circle is filled hollow
    * (e.q. not filled).
    */
-  fill_width = SCREENabs( toplevel, o_current->fill_width );
+  fill_width = SCREENabs (w_current, o_current->fill_width);
   if( fill_width <= 0) {
     fill_width = 1;
   }
@@ -179,12 +179,12 @@ void o_circle_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
                 color, w_current, o_current->circle,
                 fill_width, angle1, pitch1, angle2, pitch2);
 
-  WORLDtoSCREEN (toplevel, o_current->circle->center_x - o_current->circle->radius,
-                           o_current->circle->center_y + o_current->circle->radius,
-                           &sx1, &sy1);
-  WORLDtoSCREEN (toplevel, o_current->circle->center_x + o_current->circle->radius,
-                           o_current->circle->center_y - o_current->circle->radius,
-                           &sx2, &sy2);
+  WORLDtoSCREEN (w_current, o_current->circle->center_x - o_current->circle->radius,
+                            o_current->circle->center_y + o_current->circle->radius,
+                            &sx1, &sy1);
+  WORLDtoSCREEN (w_current, o_current->circle->center_x + o_current->circle->radius,
+                            o_current->circle->center_y - o_current->circle->radius,
+                            &sx2, &sy2);
 
   cx = (double)(sx1 + sx2) / 2.;
   cy = (double)(sy1 + sy2) / 2.;
@@ -326,8 +326,8 @@ void o_circle_fill_hatch (GdkDrawable *w, GdkGC *gc, COLOR *color,
     int x1, y1, x2, y2;
     LINE *line = &g_array_index (lines, LINE, i);
 
-    WORLDtoSCREEN (w_current->toplevel, line->x[0], line->y[0], &x1, &y1);
-    WORLDtoSCREEN (w_current->toplevel, line->x[1], line->y[1], &x2, &y2);
+    WORLDtoSCREEN (w_current, line->x[0], line->y[0], &x1, &y1);
+    WORLDtoSCREEN (w_current, line->x[1], line->y[1], &x2, &y2);
     gschem_cairo_line (w_current->cr, END_NONE, fill_width, x1, y1, x2, y2);
   }
   gschem_cairo_stroke (w_current->cr, TYPE_SOLID, END_NONE,
@@ -387,11 +387,10 @@ void o_circle_fill_mesh (GdkDrawable *w, GdkGC *gc, COLOR *color,
  */
 void o_circle_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int cx, cy, radius;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &cx, &cy);
-  radius = SCREENabs(toplevel, w_current->distance);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &cx, &cy);
+  radius = SCREENabs (w_current, w_current->distance);
 
   o_invalidate_rect (w_current, cx - radius, cy - radius,
                                 cx + radius, cy + radius);
@@ -415,7 +414,6 @@ void o_circle_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_circle_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int sx1, sy1, sx2, sy2;
   double cx, cy;
   double radius;
@@ -431,12 +429,12 @@ void o_circle_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_
     color = o_current->color;
   }
 
-  WORLDtoSCREEN (toplevel, o_current->circle->center_x + dx - o_current->circle->radius,
-                           o_current->circle->center_y + dy + o_current->circle->radius,
-                           &sx1, &sy1);
-  WORLDtoSCREEN (toplevel, o_current->circle->center_x + dx + o_current->circle->radius,
-                           o_current->circle->center_y + dy - o_current->circle->radius,
-                           &sx2, &sy2);
+  WORLDtoSCREEN (w_current, o_current->circle->center_x + dx - o_current->circle->radius,
+                            o_current->circle->center_y + dy + o_current->circle->radius,
+                            &sx1, &sy1);
+  WORLDtoSCREEN (w_current, o_current->circle->center_x + dx + o_current->circle->radius,
+                            o_current->circle->center_y + dy - o_current->circle->radius,
+                            &sx2, &sy2);
 
   cx = (double)(sx1 + sx2) / 2.;
   cy = (double)(sy1 + sy2) / 2.;
@@ -593,19 +591,18 @@ void o_circle_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
  */
 void o_circle_draw_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int sx1, sy1, sx2, sy2;
   double cx, cy;
   double radius;
 
   /* draw the circle from the w_current variables */
 
-  WORLDtoSCREEN (toplevel, w_current->first_wx - w_current->distance,
-                           w_current->first_wy + w_current->distance,
-                           &sx1, &sy1);
-  WORLDtoSCREEN (toplevel, w_current->first_wx + w_current->distance,
-                           w_current->first_wy - w_current->distance,
-                           &sx2, &sy2);
+  WORLDtoSCREEN (w_current, w_current->first_wx - w_current->distance,
+                            w_current->first_wy + w_current->distance,
+                            &sx1, &sy1);
+  WORLDtoSCREEN (w_current, w_current->first_wx + w_current->distance,
+                            w_current->first_wy - w_current->distance,
+                            &sx2, &sy2);
 
   cx = (double)(sx1 + sx2) / 2.;
   cy = (double)(sy1 + sy2) / 2.;
@@ -636,17 +633,16 @@ void o_circle_draw_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_circle_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x, y;
 
   if (w_current->draw_grips == FALSE)
 	  return;
 
   /* coords of the lower right corner of the square */
-  WORLDtoSCREEN( toplevel,
+  WORLDtoSCREEN (w_current,
                  o_current->circle->center_x + o_current->circle->radius,
                  o_current->circle->center_y - o_current->circle->radius,
-                 &x, &y );
+                 &x, &y);
   
   /* grip on lower right corner of the square */
   o_grips_draw(w_current, x, y);
diff --git a/gschem/src/o_complex.c b/gschem/src/o_complex.c
index 6bc69f7..edd04f2 100644
--- a/gschem/src/o_complex.c
+++ b/gschem/src/o_complex.c
@@ -232,12 +232,12 @@ void o_complex_translate_all(GSCHEM_TOPLEVEL *w_current, int offset)
                                  &w_rright, &w_rbottom);
 
   /*! \todo do we want snap grid here? */
-  x = snap_grid( toplevel, w_rleft );
+  x = snap_grid (w_current, w_rleft);
   /* WARNING: w_rtop isn't the top of the bounds, it is the smaller
    * y_coordinate, which represents in the bottom in world coords.
    * These variables are as named from when screen-coords (which had 
    * the correct sense) were in use . */
-  y = snap_grid( toplevel, w_rtop );
+  y = snap_grid (w_current, w_rtop);
 
   iter = s_page_objects (toplevel->page_current);
   while (iter != NULL) {
diff --git a/gschem/src/o_cue.c b/gschem/src/o_cue.c
index bc74598..e46efb8 100644
--- a/gschem/src/o_cue.c
+++ b/gschem/src/o_cue.c
@@ -153,14 +153,14 @@ void o_cue_draw_lowlevel(GSCHEM_TOPLEVEL *w_current, OBJECT *object, int whichon
   printf("type: %d count: %d\n", type, count);
 #endif
   
-  WORLDtoSCREEN(toplevel, x, y, &screen_x, &screen_y);
+  WORLDtoSCREEN (w_current, x, y, &screen_x, &screen_y);
   
   switch(type) {
 
     case(CONN_ENDPOINT):
       if (object->type == OBJ_NET) { /* only nets have these cues */
         if (count < 1) { /* Didn't find anything connected there */
-          size = SCREENabs(toplevel, CUE_BOX_SIZE);
+          size = SCREENabs (w_current, CUE_BOX_SIZE);
           x2size = 2 * size;
           if (toplevel->DONT_REDRAW == 0) {
             o_cue_set_color (w_current, NET_ENDPOINT_COLOR);
@@ -176,9 +176,9 @@ void o_cue_draw_lowlevel(GSCHEM_TOPLEVEL *w_current, OBJECT *object, int whichon
           /* draw circle */
 
           if (bus_involved) {
-            size = SCREENabs(toplevel, CUE_CIRCLE_LARGE_SIZE) / 2;
+            size = SCREENabs (w_current, CUE_CIRCLE_LARGE_SIZE) / 2;
           } else {
-            size = SCREENabs(toplevel, CUE_CIRCLE_SMALL_SIZE) / 2;
+            size = SCREENabs (w_current, CUE_CIRCLE_SMALL_SIZE) / 2;
           }
           x2size = 2 * size;
           if (toplevel->DONT_REDRAW == 0) {
@@ -192,9 +192,9 @@ void o_cue_draw_lowlevel(GSCHEM_TOPLEVEL *w_current, OBJECT *object, int whichon
         /* Didn't find anything connected there */
         if (count < 1 && object->whichend == whichone) {
           if (bus_involved) {
-            size = SCREENabs(toplevel, PIN_CUE_SIZE_BUS);
+            size = SCREENabs (w_current, PIN_CUE_SIZE_BUS);
           } else {
-            size = SCREENabs(toplevel, PIN_CUE_SIZE_NET);
+            size = SCREENabs (w_current, PIN_CUE_SIZE_NET);
           }
           x2size = size * 2;
 
@@ -202,7 +202,7 @@ void o_cue_draw_lowlevel(GSCHEM_TOPLEVEL *w_current, OBJECT *object, int whichon
 
           pinsize = 1;
           if (toplevel->pin_style == THICK )
-            pinsize = SCREENabs(toplevel, object->line_width);
+            pinsize = SCREENabs (w_current, object->line_width);
 
           if (toplevel->DONT_REDRAW == 0) {
             o_cue_set_color (w_current, NET_ENDPOINT_COLOR);
@@ -246,9 +246,9 @@ void o_cue_draw_lowlevel(GSCHEM_TOPLEVEL *w_current, OBJECT *object, int whichon
   
       /* draw circle */
       if (bus_involved) {
-        size = SCREENabs(toplevel, CUE_CIRCLE_LARGE_SIZE) / 2;
+        size = SCREENabs (w_current, CUE_CIRCLE_LARGE_SIZE) / 2;
       } else {
-        size = SCREENabs(toplevel, CUE_CIRCLE_SMALL_SIZE) / 2;
+        size = SCREENabs (w_current, CUE_CIRCLE_SMALL_SIZE) / 2;
       }
       x2size = size * 2;
 
@@ -295,14 +295,14 @@ void o_cue_draw_lowlevel_midpoints(GSCHEM_TOPLEVEL *w_current, OBJECT *object)
         x = conn->x;
         y = conn->y;
 
-        WORLDtoSCREEN(toplevel, x, y, &screen_x, &screen_y);
+        WORLDtoSCREEN (w_current, x, y, &screen_x, &screen_y);
 
         /* draw circle */
         if (conn->other_object &&
             (object->type == OBJ_BUS || conn->other_object->type == OBJ_BUS)) {
-          size = SCREENabs(toplevel, CUE_CIRCLE_LARGE_SIZE) / 2;
+          size = SCREENabs (w_current, CUE_CIRCLE_LARGE_SIZE) / 2;
         } else {
-          size = SCREENabs(toplevel, CUE_CIRCLE_SMALL_SIZE) / 2;
+          size = SCREENabs (w_current, CUE_CIRCLE_SMALL_SIZE) / 2;
         }
         x2size = size * 2;
 
diff --git a/gschem/src/o_find.c b/gschem/src/o_find.c
index f878a22..65b55d7 100644
--- a/gschem/src/o_find.c
+++ b/gschem/src/o_find.c
@@ -97,7 +97,7 @@ gboolean o_find_object (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y,
   int w_slack;
   const GList *iter = NULL;
 
-  w_slack = WORLDabs( toplevel, w_current->select_slack_pixels );
+  w_slack = WORLDabs (w_current, w_current->select_slack_pixels);
 
   /* Decide whether to iterate over all object or start at the last
      found object. If there is more than one object below the
@@ -160,7 +160,7 @@ gboolean o_find_selected_object(GSCHEM_TOPLEVEL *w_current,
   GList *s_current;
   int w_slack;
 
-  w_slack = WORLDabs( toplevel, w_current->select_slack_pixels );
+  w_slack = WORLDabs (w_current, w_current->select_slack_pixels);
 
   s_current = geda_list_get_glist( toplevel->page_current->selection_list );
   /* do first search */
diff --git a/gschem/src/o_grips.c b/gschem/src/o_grips.c
index c764ddf..fb69ffb 100644
--- a/gschem/src/o_grips.c
+++ b/gschem/src/o_grips.c
@@ -79,7 +79,7 @@ OBJECT *o_grips_search_world(GSCHEM_TOPLEVEL *w_current, int x, int y, int *whic
 
   /* get the size of the grip according to zoom level */
   size = o_grips_size(w_current);
-  w_size = WORLDabs(toplevel, size );
+  w_size = WORLDabs (w_current, size );
 
   s_current = geda_list_get_glist( toplevel->page_current->selection_list );
   while (s_current != NULL) {
@@ -1527,13 +1527,13 @@ int o_grips_size(GSCHEM_TOPLEVEL *w_current)
   factor = (int) toplevel->page_current->to_world_x_constant;
   if (factor > SMALL_ZOOMFACTOR1) {
     /* big zoom factor : small size converted to screen unit */
-    size = SCREENabs(toplevel, GRIP_SIZE1);
+    size = SCREENabs (w_current, GRIP_SIZE1);
   } else if (factor > SMALL_ZOOMFACTOR2) {
     /* medium zoom factor : medium size converted to screen unit */
-    size = SCREENabs(toplevel, GRIP_SIZE2);
+    size = SCREENabs (w_current, GRIP_SIZE2);
   } else {
     /* small zoom factor : big size converted to screen unit */
-    size = SCREENabs(toplevel, GRIP_SIZE3);
+    size = SCREENabs (w_current, GRIP_SIZE3);
   }
   
   return size;
diff --git a/gschem/src/o_line.c b/gschem/src/o_line.c
index bad3fc5..f283fe7 100644
--- a/gschem/src/o_line.c
+++ b/gschem/src/o_line.c
@@ -92,13 +92,13 @@ void o_line_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
   else
   color = x_color_lookup (o_current->color);
 	
-  line_width = SCREENabs( toplevel, o_current->line_width );
+  line_width = SCREENabs (w_current, o_current->line_width);
   if( line_width <= 0) {
     line_width = 1;
   }
 
-  length = SCREENabs( toplevel, o_current->line_length );
-  space = SCREENabs( toplevel, o_current->line_space );
+  length = SCREENabs (w_current, o_current->line_length);
+  space = SCREENabs (w_current, o_current->line_space);
 
   gschem_cairo_line (w_current->cr, o_current->line_end,
                      line_width, x1, y1, x2, y2);
@@ -123,11 +123,10 @@ void o_line_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
  */
 void o_line_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   o_invalidate_rect (w_current, x1, y1, x2, y2);
 }
@@ -145,7 +144,6 @@ void o_line_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_line_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int color;
   int sx[2], sy[2];
 
@@ -159,8 +157,8 @@ void o_line_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cu
     color = o_current->color;
   }
 
-  WORLDtoSCREEN(toplevel, o_current->line->x[0] + dx, o_current->line->y[0] + dy, &sx[0], &sy[0]);
-  WORLDtoSCREEN(toplevel, o_current->line->x[1] + dx, o_current->line->y[1] + dy, &sx[1], &sy[1]);
+  WORLDtoSCREEN (w_current, o_current->line->x[0] + dx, o_current->line->y[0] + dy, &sx[0], &sy[0]);
+  WORLDtoSCREEN (w_current, o_current->line->x[1] + dx, o_current->line->y[1] + dy, &sx[1], &sy[1]);
 
   gschem_cairo_line (w_current->cr, END_NONE, 1, sx[0], sy[0], sx[1], sy[1]);
   gschem_cairo_set_source_color (w_current->cr, x_color_lookup_dark (color));
@@ -294,11 +292,10 @@ void o_line_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
  */
 void o_line_draw_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   gschem_cairo_line (w_current->cr, END_NONE, 1, x1, y1, x2, y2);
 
@@ -318,14 +315,13 @@ void o_line_draw_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_line_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x[2], y[2];
 
   if (w_current->draw_grips == FALSE)
 	  return;
 
-  WORLDtoSCREEN( toplevel, o_current->line->x[0], o_current->line->y[0], &x[0], &y[0] );
-  WORLDtoSCREEN( toplevel, o_current->line->x[1], o_current->line->y[1], &x[1], &y[1] );
+  WORLDtoSCREEN (w_current, o_current->line->x[0], o_current->line->y[0], &x[0], &y[0]);
+  WORLDtoSCREEN (w_current, o_current->line->x[1], o_current->line->y[1], &x[1], &y[1]);
 
   /* draw the grip on line end 1 */
   o_grips_draw(w_current, x[LINE_END1], y[LINE_END1]);
@@ -354,8 +350,8 @@ int o_line_visible (GSCHEM_TOPLEVEL *w_current, LINE *line,
     return(TRUE);
   }
 
-  WORLDtoSCREEN (w_current->toplevel, line->x[0], line->y[0], x1, y1);
-  WORLDtoSCREEN (w_current->toplevel, line->x[1], line->y[1], x2, y2);
+  WORLDtoSCREEN (w_current, line->x[0], line->y[0], x1, y1);
+  WORLDtoSCREEN (w_current, line->x[1], line->y[1], x2, y2);
 
-  return SCREENclip_change (w_current->toplevel, x1, y1, x2, y2);
+  return SCREENclip_change (w_current, x1, y1, x2, y2);
 }
diff --git a/gschem/src/o_misc.c b/gschem/src/o_misc.c
index 8cf7075..ea82dc6 100644
--- a/gschem/src/o_misc.c
+++ b/gschem/src/o_misc.c
@@ -558,14 +558,14 @@ int o_edit_find_text (GSCHEM_TOPLEVEL *w_current, const GList *o_list,
         if (!skiplast) {
           a_zoom(w_current, ZOOM_FULL, DONTCARE, A_PAN_DONT_REDRAW);
           text_screen_height =
-            SCREENabs (toplevel, o_text_height (str, o_current->text->size));
+            SCREENabs (w_current, o_text_height (str, o_current->text->size));
           /* this code will zoom/pan till the text screen height is about */
           /* 50 pixels high, perhaps a future enhancement will be to make */
           /* this number configurable */
           while (text_screen_height < 50) {
             a_zoom(w_current, ZOOM_IN, DONTCARE, A_PAN_DONT_REDRAW);
             text_screen_height =
-              SCREENabs (toplevel, o_text_height (str, o_current->text->size));
+              SCREENabs (w_current, o_text_height (str, o_current->text->size));
           }
           a_pan_general(w_current,
                         o_current->text->x, o_current->text->y,
diff --git a/gschem/src/o_move.c b/gschem/src/o_move.c
index eaeae6a..76eca40 100644
--- a/gschem/src/o_move.c
+++ b/gschem/src/o_move.c
@@ -346,8 +346,8 @@ void o_move_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
        of the object that is aligned with the grid */
     if (resnap) {
       if (o_get_position(toplevel, &object_x, &object_y, object)) {
-        w_x += snap_grid(toplevel, object_x) - object_x;
-        w_y += snap_grid(toplevel, object_y) - object_y;
+        w_x += snap_grid (w_current, object_x) - object_x;
+        w_y += snap_grid (w_current, object_y) - object_y;
       }
     }
   }
@@ -392,10 +392,10 @@ void o_move_invalidate_rubber (GSCHEM_TOPLEVEL *w_current, int drawing)
             dy2 = w_current->second_wy - w_current->first_wy;
           }
 
-          WORLDtoSCREEN (toplevel, object->line->x[0] + dx1,
-                                   object->line->y[0] + dy1, &x1, &y1);
-          WORLDtoSCREEN (toplevel, object->line->x[1] + dx2,
-                                   object->line->y[1] + dy2, &x2, &y2);
+          WORLDtoSCREEN (w_current, object->line->x[0] + dx1,
+                                    object->line->y[0] + dy1, &x1, &y1);
+          WORLDtoSCREEN (w_current, object->line->x[1] + dx2,
+                                    object->line->y[1] + dy2, &x2, &y2);
 
           o_invalidate_rect (w_current, x1, y1, x2, y2);
       }
diff --git a/gschem/src/o_net.c b/gschem/src/o_net.c
index b75d513..41f05ca 100644
--- a/gschem/src/o_net.c
+++ b/gschem/src/o_net.c
@@ -102,7 +102,7 @@ void o_net_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
   size = 1;
 
   if (toplevel->net_style == THICK ) {
-    size = SCREENabs(toplevel, NET_WIDTH);
+    size = SCREENabs (w_current, NET_WIDTH);
 
     if (size < 1)
       size=1;
@@ -153,12 +153,12 @@ void o_net_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cur
   }
 
   if (toplevel->net_style == THICK ) {
-    size = SCREENabs(toplevel, NET_WIDTH);
+    size = SCREENabs (w_current, NET_WIDTH);
     size += 1;
   }
 
-  WORLDtoSCREEN(toplevel, o_current->line->x[0] + dx, o_current->line->y[0] + dy, &sx[0], &sy[0]);
-  WORLDtoSCREEN(toplevel, o_current->line->x[1] + dx, o_current->line->y[1] + dy, &sx[1], &sy[1]);
+  WORLDtoSCREEN (w_current, o_current->line->x[0] + dx, o_current->line->y[0] + dy, &sx[0], &sy[0]);
+  WORLDtoSCREEN (w_current, o_current->line->x[1] + dx, o_current->line->y[1] + dy, &sx[1], &sy[1]);
 
   gschem_cairo_line (w_current->cr, END_NONE, size, sx[0], sy[0], sx[1], sy[1]);
 
@@ -174,7 +174,6 @@ void o_net_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cur
 void o_net_draw_stretch (GSCHEM_TOPLEVEL *w_current,
                          int dx, int dy, int whichone, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int color;
   int dx1 = -1, dx2 = -1, dy1 = -1,dy2 = -1;
   int x1, y1, x2, y2;
@@ -201,9 +200,9 @@ void o_net_draw_stretch (GSCHEM_TOPLEVEL *w_current,
     fprintf(stderr, _("Got an invalid which one in o_net_draw_stretch\n"));
   }
 
-  WORLDtoSCREEN (toplevel, o_current->line->x[0] + dx1,
+  WORLDtoSCREEN (w_current, o_current->line->x[0] + dx1,
                            o_current->line->y[0] + dy1, &x1, &y1);
-  WORLDtoSCREEN (toplevel, o_current->line->x[1] + dx2,
+  WORLDtoSCREEN (w_current, o_current->line->x[1] + dx2,
                            o_current->line->y[1] + dy2, &x2, &y2);
 
   gschem_cairo_line (w_current->cr, END_NONE, 1, x1, y1, x2, y2);
@@ -362,7 +361,7 @@ void o_net_find_magnetic(GSCHEM_TOPLEVEL *w_current,
   /* max distance of all the different reaches */
   magnetic_reach = max(MAGNETIC_PIN_REACH, MAGNETIC_NET_REACH);
   magnetic_reach = max(magnetic_reach, MAGNETIC_BUS_REACH);
-  w_magnetic_reach = WORLDabs(toplevel, magnetic_reach);
+  w_magnetic_reach = WORLDabs (w_current, magnetic_reach);
 
   /* get the objects of the tiles around the reach region */
   x1 = w_x - w_magnetic_reach;
@@ -375,7 +374,7 @@ void o_net_find_magnetic(GSCHEM_TOPLEVEL *w_current,
     for (iter2 = (GList*) iter1->data; iter2 != NULL; iter2 = g_list_next(iter2)) {
       o_current = (OBJECT*) iter2->data;
 
-      if (!visible(toplevel,  o_current->w_left, o_current->w_top, 
+      if (!visible (w_current,  o_current->w_left, o_current->w_top,
 		   o_current->w_right, o_current->w_bottom))
 	continue; /* skip invisible objects */
 
@@ -459,7 +458,7 @@ void o_net_find_magnetic(GSCHEM_TOPLEVEL *w_current,
     case (OBJ_NET): magnetic_reach = MAGNETIC_NET_REACH; break;
     case (OBJ_BUS): magnetic_reach = MAGNETIC_BUS_REACH; break;
     }
-    if (minbest > WORLDabs(toplevel, magnetic_reach)) {
+    if (minbest > WORLDabs (w_current, magnetic_reach)) {
       w_current->magnetic_wx = -1;
       w_current->magnetic_wy = -1;
     }
@@ -563,8 +562,6 @@ void o_net_start_magnetic(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
  */
 void o_net_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
-
   if (w_current->magnetic_wx != -1 && w_current->magnetic_wy != -1) {
     w_current->first_wx = w_current->magnetic_wx;
     w_current->first_wy = w_current->magnetic_wy;
@@ -577,8 +574,8 @@ void o_net_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
   w_current->second_wx = w_current->third_wx = w_current->first_wx;
   w_current->second_wy = w_current->third_wy = w_current->first_wy;
 
-  if (w_current->first_wx != snap_grid(toplevel, w_current->first_wx)
-      || w_current->first_wy != snap_grid(toplevel, w_current->first_wy))
+  if (w_current->first_wx != snap_grid (w_current, w_current->first_wx)
+      || w_current->first_wy != snap_grid (w_current, w_current->first_wy))
       s_log_message(_("Warning: Starting net at off grid coordinate\n"));
 
   if (w_current->net_direction_mode)
@@ -639,8 +636,8 @@ int o_net_end(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
     color = toplevel->override_net_color;
   }
 
-  if (w_current->third_wx != snap_grid(toplevel, w_current->third_wx)
-      || w_current->third_wy != snap_grid(toplevel, w_current->third_wy))
+  if (w_current->third_wx != snap_grid (w_current, w_current->third_wx)
+      || w_current->third_wy != snap_grid (w_current, w_current->third_wy))
       s_log_message(_("Warning: Ending net at off grid coordinate\n"));
 
   if (!primary_zero_length ) {
@@ -815,17 +812,17 @@ void o_net_draw_rubber(GSCHEM_TOPLEVEL *w_current)
   int magnetic_x, magnetic_y;
   int first_x, first_y, third_x, third_y, second_x, second_y;
 
-  WORLDtoSCREEN(toplevel, w_current->magnetic_wx, w_current->magnetic_wy,
-		&magnetic_x, &magnetic_y);
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy,
-		&first_x, &first_y);
-  WORLDtoSCREEN(toplevel, w_current->third_wx, w_current->third_wy,
-		&third_x, &third_y);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy,
-		&second_x, &second_y);
+  WORLDtoSCREEN (w_current, w_current->magnetic_wx, w_current->magnetic_wy,
+                 &magnetic_x, &magnetic_y);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy,
+                 &first_x, &first_y);
+  WORLDtoSCREEN (w_current, w_current->third_wx, w_current->third_wy,
+                 &third_x, &third_y);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy,
+                 &second_x, &second_y);
 
   if (toplevel->net_style == THICK)
-    size = SCREENabs(toplevel, NET_WIDTH);
+    size = SCREENabs (w_current, NET_WIDTH);
 
   size = max (size, 1);
 
@@ -865,17 +862,17 @@ void o_net_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
   int first_x, first_y, third_x, third_y, second_x, second_y;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN (toplevel, w_current->magnetic_wx, w_current->magnetic_wy,
+  WORLDtoSCREEN (w_current, w_current->magnetic_wx, w_current->magnetic_wy,
                  &magnetic_x, &magnetic_y);
-  WORLDtoSCREEN (toplevel, w_current->first_wx, w_current->first_wy,
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy,
                  &first_x, &first_y);
-  WORLDtoSCREEN (toplevel, w_current->third_wx, w_current->third_wy,
+  WORLDtoSCREEN (w_current, w_current->third_wx, w_current->third_wy,
                  &third_x, &third_y);
-  WORLDtoSCREEN (toplevel, w_current->second_wx, w_current->second_wy,
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy,
                  &second_x, &second_y);
 
   if (toplevel->net_style == THICK) {
-    size = SCREENabs (toplevel, NET_WIDTH);
+    size = SCREENabs (w_current, NET_WIDTH);
   }
   size = max (size, 0);
   bloat = size / 2;
diff --git a/gschem/src/o_path.c b/gschem/src/o_path.c
index 50d0971..50b78f3 100644
--- a/gschem/src/o_path.c
+++ b/gschem/src/o_path.c
@@ -51,7 +51,6 @@ static void path_to_points_modify (GSCHEM_TOPLEVEL *w_current, PATH *path,
                                    GdkPoint **points, int *num_points)
 
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   PATH_SECTION *section;
   int x1, y1, x2, y2, x3, y3;
   int i;
@@ -80,8 +79,8 @@ static void path_to_points_modify (GSCHEM_TOPLEVEL *w_current, PATH *path,
         if (whichone == grip_no++) {
           x2 = new_x; y2 = new_y;
         }
-        WORLDtoSCREEN (toplevel, x1, y1, &x1, &y1);
-        WORLDtoSCREEN (toplevel, x2, y2, &x2, &y2);
+        WORLDtoSCREEN (w_current, x1, y1, &x1, &y1);
+        WORLDtoSCREEN (w_current, x2, y2, &x2, &y2);
         /* Fall through */
       case PATH_MOVETO:
       case PATH_MOVETO_OPEN:
@@ -90,7 +89,7 @@ static void path_to_points_modify (GSCHEM_TOPLEVEL *w_current, PATH *path,
         if (whichone == grip_no++) {
           x3 = new_x; y3 = new_y;
         }
-        WORLDtoSCREEN (toplevel, x3, y3, &x3, &y3);
+        WORLDtoSCREEN (w_current, x3, y3, &x3, &y3);
       case PATH_END:
         break;
     }
@@ -220,8 +219,8 @@ static void o_path_fill_hatch (GdkDrawable *w, GdkGC *gc, COLOR *color,
     int x1, y1, x2, y2;
     LINE *line = &g_array_index (lines, LINE, i);
 
-    WORLDtoSCREEN (w_current->toplevel, line->x[0], line->y[0], &x1, &y1);
-    WORLDtoSCREEN (w_current->toplevel, line->x[1], line->y[1], &x2, &y2);
+    WORLDtoSCREEN (w_current, line->x[0], line->y[0], &x1, &y1);
+    WORLDtoSCREEN (w_current, line->x[1], line->y[1], &x2, &y2);
     gschem_cairo_line (w_current->cr, END_NONE, fill_width, x1, y1, x2, y2);
   }
   gschem_cairo_stroke (w_current->cr, TYPE_SOLID, END_NONE,
@@ -303,13 +302,13 @@ void o_path_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
     color = x_color_lookup (o_current->color);
   }
 
-  line_width = SCREENabs( toplevel, o_current->line_width );
+  line_width = SCREENabs (w_current, o_current->line_width);
   if( line_width <= 0) {
     line_width = 1;
   }
 
-  length = SCREENabs( toplevel, o_current->line_length );
-  space = SCREENabs( toplevel, o_current->line_space );
+  length = SCREENabs (w_current, o_current->line_length);
+  space = SCREENabs (w_current, o_current->line_space);
 
   /*
    * The values needed for the fill operation are taken from the
@@ -327,7 +326,7 @@ void o_path_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
    * #o_path_fill_hollow(), #o_path_fill_fill(), #o_path_fill_mesh() and
    * #o_path_fill_hatch().
    */
-  fill_width = SCREENabs( toplevel, o_current->fill_width );
+  fill_width = SCREENabs (w_current, o_current->fill_width);
   if(fill_width <= 0) {
     fill_width = 1;
   }
@@ -386,8 +385,8 @@ void o_path_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
     switch (section->code) {
       case PATH_CURVETO:
         /* Two control point grips */
-        WORLDtoSCREEN (toplevel, section->x1, section->y1, &x1, &y1);
-        WORLDtoSCREEN (toplevel, section->x2, section->y2, &x2, &y2);
+        WORLDtoSCREEN (w_current, section->x1, section->y1, &x1, &y1);
+        WORLDtoSCREEN (w_current, section->x2, section->y2, &x2, &y2);
         hint_coordinates (x1, y1, &fx1, &fy1, line_width);
         hint_coordinates (x2, y2, &fx2, &fy2, line_width);
         /* Fall through */
@@ -395,7 +394,7 @@ void o_path_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
       case PATH_MOVETO_OPEN:
       case PATH_LINETO:
         /* Destination point grip */
-        WORLDtoSCREEN (toplevel, section->x3, section->y3, &x3, &y3);
+        WORLDtoSCREEN (w_current, section->x3, section->y3, &x3, &y3);
         hint_coordinates (x3, y3, &fx3, &fy3, line_width);
       case PATH_END:
         break;
@@ -516,8 +515,8 @@ void o_path_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cu
     switch (section->code) {
       case PATH_CURVETO:
         /* Two control point grips */
-        WORLDtoSCREEN (toplevel, section->x1 + dx, section->y1 + dy, &x1, &y1);
-        WORLDtoSCREEN (toplevel, section->x2 + dx, section->y2 + dy, &x2, &y2);
+        WORLDtoSCREEN (w_current, section->x1 + dx, section->y1 + dy, &x1, &y1);
+        WORLDtoSCREEN (w_current, section->x2 + dx, section->y2 + dy, &x2, &y2);
         hint_coordinates (x1, y1, &fx1, &fy1, line_width);
         hint_coordinates (x2, y2, &fx2, &fy2, line_width);
         /* Fall through */
@@ -525,7 +524,7 @@ void o_path_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cu
       case PATH_MOVETO_OPEN:
       case PATH_LINETO:
         /* Destination point grip */
-        WORLDtoSCREEN (toplevel, section->x3 + dx, section->y3 + dy, &x3, &y3);
+        WORLDtoSCREEN (w_current, section->x3 + dx, section->y3 + dy, &x3, &y3);
         hint_coordinates (x3, y3, &fx3, &fy3, line_width);
       case PATH_END:
         break;
@@ -630,7 +629,6 @@ void o_path_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
  */
 void o_path_draw_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int whichone = w_current->which_grip;
   PATH *path = w_current->which_object->path;
   PATH_SECTION *section;
@@ -665,8 +663,8 @@ void o_path_draw_rubber (GSCHEM_TOPLEVEL *w_current)
         if (whichone == grip_no++) {
           x2 = x; y2 = y;
         }
-        WORLDtoSCREEN (toplevel, x1, y1, &x1, &y1);
-        WORLDtoSCREEN (toplevel, x2, y2, &x2, &y2);
+        WORLDtoSCREEN (w_current, x1, y1, &x1, &y1);
+        WORLDtoSCREEN (w_current, x2, y2, &x2, &y2);
         hint_coordinates (x1, y1, &fx1, &fy1, line_width);
         hint_coordinates (x2, y2, &fx2, &fy2, line_width);
         /* Fall through */
@@ -677,7 +675,7 @@ void o_path_draw_rubber (GSCHEM_TOPLEVEL *w_current)
         if (whichone == grip_no++) {
           x3 = x; y3 = y;
         }
-        WORLDtoSCREEN (toplevel, x3, y3, &x3, &y3);
+        WORLDtoSCREEN (w_current, x3, y3, &x3, &y3);
         hint_coordinates (x3, y3, &fx3, &fy3, line_width);
       case PATH_END:
         break;
@@ -741,16 +739,16 @@ static void draw_control_lines (GSCHEM_TOPLEVEL *w_current,
     section = &o_current->path->sections[i];
 
     if (section->code != PATH_END)
-      WORLDtoSCREEN (toplevel, section->x3, section->y3, &next_x, &next_y);
+      WORLDtoSCREEN (w_current, section->x3, section->y3, &next_x, &next_y);
 
     switch (section->code) {
     case PATH_CURVETO:
       /* Two control point grips */
-      WORLDtoSCREEN (toplevel, section->x1, section->y1, &x, &y);
+      WORLDtoSCREEN (w_current, section->x1, section->y1, &x, &y);
       gschem_cairo_line (w_current->cr, END_NONE, 1, last_x, last_y, x, y);
       gschem_cairo_stroke (w_current->cr, TYPE_SOLID, END_NONE, 1, -1, -1);
 
-      WORLDtoSCREEN (toplevel, section->x2, section->y2, &x, &y);
+      WORLDtoSCREEN (w_current, section->x2, section->y2, &x, &y);
       gschem_cairo_line (w_current->cr, END_NONE, 1, next_x, next_y, x, y);
       gschem_cairo_stroke (w_current->cr, TYPE_SOLID, END_NONE, 1, -1, -1);
 
@@ -779,7 +777,6 @@ static void draw_control_lines (GSCHEM_TOPLEVEL *w_current,
  */
 void o_path_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   PATH_SECTION *section;
   int i;
   int x, y;
@@ -795,16 +792,16 @@ void o_path_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
     switch (section->code) {
     case PATH_CURVETO:
       /* Two control point grips */
-      WORLDtoSCREEN (toplevel, section->x1, section->y1, &x, &y);
+      WORLDtoSCREEN (w_current, section->x1, section->y1, &x, &y);
       o_grips_draw (w_current, x, y);
-      WORLDtoSCREEN (toplevel, section->x2, section->y2, &x, &y);
+      WORLDtoSCREEN (w_current, section->x2, section->y2, &x, &y);
       o_grips_draw (w_current, x, y);
       /* Fall through */
     case PATH_MOVETO:
     case PATH_MOVETO_OPEN:
     case PATH_LINETO:
       /* Destination point grip */
-      WORLDtoSCREEN (toplevel, section->x3, section->y3, &x, &y);
+      WORLDtoSCREEN (w_current, section->x3, section->y3, &x, &y);
       o_grips_draw (w_current, x, y);
       break;
     case PATH_END:
diff --git a/gschem/src/o_picture.c b/gschem/src/o_picture.c
index 755eb5d..314788d 100644
--- a/gschem/src/o_picture.c
+++ b/gschem/src/o_picture.c
@@ -204,14 +204,13 @@ void picture_selection_dialog (GSCHEM_TOPLEVEL *w_current)
  */
 void o_picture_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int left, top, width, height;
 
-  WORLDtoSCREEN (toplevel,
+  WORLDtoSCREEN (w_current,
                  GET_PICTURE_LEFT(w_current), GET_PICTURE_TOP(w_current),
                  &left, &top);
-  width = SCREENabs(toplevel, GET_PICTURE_WIDTH (w_current));
-  height = SCREENabs(toplevel, GET_PICTURE_HEIGHT(w_current));
+  width = SCREENabs (w_current, GET_PICTURE_WIDTH (w_current));
+  height = SCREENabs (w_current, GET_PICTURE_HEIGHT(w_current));
 
   o_invalidate_rect (w_current, left, top, left + width, top);
   o_invalidate_rect (w_current, left, top, left, top + height);
@@ -272,15 +271,14 @@ void o_picture_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
  */
 void o_picture_draw_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int left, top, width, height;
 
   /* get the width/height and the upper left corner of the picture */
-  WORLDtoSCREEN(toplevel,
-		GET_PICTURE_LEFT(w_current), GET_PICTURE_TOP(w_current),
-		&left, &top);
-  width = SCREENabs(toplevel, GET_PICTURE_WIDTH (w_current));
-  height = SCREENabs(toplevel, GET_PICTURE_HEIGHT(w_current));
+  WORLDtoSCREEN (w_current,
+                 GET_PICTURE_LEFT(w_current), GET_PICTURE_TOP(w_current),
+                 &left, &top);
+  width = SCREENabs (w_current, GET_PICTURE_WIDTH (w_current));
+  height = SCREENabs (w_current, GET_PICTURE_HEIGHT(w_current));
 
   gschem_cairo_box (w_current->cr, 1, left, top, left + width, top + height);
 
@@ -312,10 +310,10 @@ void o_picture_draw (GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
     return;
   }
 
-  WORLDtoSCREEN (toplevel, o_current->picture->upper_x,
-                           o_current->picture->upper_y, &s_upper_x, &s_upper_y);
-  WORLDtoSCREEN (toplevel, o_current->picture->lower_x,
-                           o_current->picture->lower_y, &s_lower_x, &s_lower_y);
+  WORLDtoSCREEN (w_current, o_current->picture->upper_x,
+                            o_current->picture->upper_y, &s_upper_x, &s_upper_y);
+  WORLDtoSCREEN (w_current, o_current->picture->lower_x,
+                            o_current->picture->lower_y, &s_lower_x, &s_lower_y);
 
   if (o_current->picture->displayed_picture != NULL) {
     g_object_unref (o_current->picture->displayed_picture);
@@ -377,15 +375,14 @@ void o_picture_draw (GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
  */
 void o_picture_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int s_upper_x, s_upper_y, s_lower_x, s_lower_y;
 
   if (w_current->draw_grips == FALSE)
     return;
 
-  WORLDtoSCREEN( toplevel, o_current->picture->upper_x, o_current->picture->upper_y,
+  WORLDtoSCREEN (w_current, o_current->picture->upper_x, o_current->picture->upper_y,
                  &s_upper_x, &s_upper_y );
-  WORLDtoSCREEN( toplevel, o_current->picture->lower_x, o_current->picture->lower_y,
+  WORLDtoSCREEN (w_current, o_current->picture->lower_x, o_current->picture->lower_y,
                  &s_lower_x, &s_lower_y );
 
   /* grip on upper left corner (whichone = PICTURE_UPPER_LEFT) */
@@ -425,7 +422,6 @@ void o_picture_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
  */
 void o_picture_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int screen_x1, screen_y1;
   int screen_x2, screen_y2;
   int color;
@@ -434,10 +430,10 @@ void o_picture_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o
     return;
   }
 
-  WORLDtoSCREEN( toplevel, o_current->picture->upper_x + dx, o_current->picture->upper_y + dy,
-                 &screen_x1, &screen_y1 );
-  WORLDtoSCREEN( toplevel, o_current->picture->lower_x + dx, o_current->picture->lower_y + dy,
-                 &screen_x2, &screen_y2 );
+  WORLDtoSCREEN (w_current, o_current->picture->upper_x + dx, o_current->picture->upper_y + dy,
+                 &screen_x1, &screen_y1);
+  WORLDtoSCREEN (w_current, o_current->picture->lower_x + dx, o_current->picture->lower_y + dy,
+                 &screen_x2, &screen_y2);
 
   if (o_current->saved_color != -1) {
     color = o_current->saved_color;
diff --git a/gschem/src/o_pin.c b/gschem/src/o_pin.c
index bb117c3..55771d6 100644
--- a/gschem/src/o_pin.c
+++ b/gschem/src/o_pin.c
@@ -63,7 +63,7 @@ void o_pin_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
   if (toplevel->DONT_REDRAW == 0) {
     size = 1;
     if (toplevel->pin_style == THICK) {
-      size = SCREENabs (toplevel, o_current->line_width);
+      size = SCREENabs (w_current, o_current->line_width);
       if (size < 1)
         size=1;
     }
@@ -113,14 +113,14 @@ void o_pin_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cur
   }
 
   if (toplevel->pin_style == THICK) {
-    size = SCREENabs (toplevel, o_current->line_width);
+    size = SCREENabs (w_current, o_current->line_width);
     if (size < 1) {
       size = 1;
     }
   }
 
-  WORLDtoSCREEN(toplevel, o_current->line->x[0] + dx, o_current->line->y[0] + dy, &sx[0], &sy[0]);
-  WORLDtoSCREEN(toplevel, o_current->line->x[1] + dx, o_current->line->y[1] + dy, &sx[1], &sy[1]);
+  WORLDtoSCREEN (w_current, o_current->line->x[0] + dx, o_current->line->y[0] + dy, &sx[0], &sy[0]);
+  WORLDtoSCREEN (w_current, o_current->line->x[1] + dx, o_current->line->y[1] + dy, &sx[1], &sy[1]);
 
   gschem_cairo_line (w_current->cr, END_NONE, size, sx[0], sy[0], sx[1], sy[1]);
 
@@ -234,12 +234,12 @@ void o_pin_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
   int min_x, min_y, max_x, max_y;
   int bloat = 0;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   /* Pins are always first created as net pins, use net pin width */
   if (toplevel->net_style == THICK ) {
-    bloat = SCREENabs (toplevel, PIN_WIDTH_NET) / 2;
+    bloat = SCREENabs (w_current, PIN_WIDTH_NET) / 2;
   }
 
   min_x = min (x1, x2) - bloat;
@@ -262,12 +262,12 @@ void o_pin_draw_rubber (GSCHEM_TOPLEVEL *w_current)
   int x1, y1, x2, y2;
   int size = 1;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   /* Pins are always first created as net pins, use net pin width */
   if (toplevel->net_style == THICK )
-    size = SCREENabs(toplevel, PIN_WIDTH_NET);
+    size = SCREENabs (w_current, PIN_WIDTH_NET);
 
   if (size < 1)
     size = 1;
diff --git a/gschem/src/o_place.c b/gschem/src/o_place.c
index 0ea715b..2001801 100644
--- a/gschem/src/o_place.c
+++ b/gschem/src/o_place.c
@@ -211,8 +211,8 @@ void o_place_invalidate_rubber (GSCHEM_TOPLEVEL *w_current, int drawing)
   /* Find the bounds of the drawing to be done */
   world_get_object_glist_bounds (toplevel, toplevel->page_current->place_list,
                                  &left, &top, &right, &bottom);
-  WORLDtoSCREEN (toplevel, left + diff_x, top + diff_y, &s_left, &s_top);
-  WORLDtoSCREEN (toplevel, right + diff_x, bottom + diff_y, &s_right, &s_bottom);
+  WORLDtoSCREEN (w_current, left + diff_x, top + diff_y, &s_left, &s_top);
+  WORLDtoSCREEN (w_current, right + diff_x, bottom + diff_y, &s_right, &s_bottom);
 
   o_invalidate_rect (w_current, s_left, s_top, s_right, s_bottom);
 }
@@ -291,8 +291,8 @@ void o_place_draw_rubber (GSCHEM_TOPLEVEL *w_current, int drawing)
     world_get_object_glist_bounds (toplevel,
                                    toplevel->page_current->place_list,
                                    &left, &top, &right, &bottom);
-    WORLDtoSCREEN(toplevel, left + diff_x, top + diff_y, &s_left, &s_top);
-    WORLDtoSCREEN(toplevel, right + diff_x, bottom + diff_y, &s_right, &s_bottom);
+    WORLDtoSCREEN (w_current, left + diff_x, top + diff_y, &s_left, &s_top);
+    WORLDtoSCREEN (w_current, right + diff_x, bottom + diff_y, &s_right, &s_bottom);
 
     gschem_cairo_box (w_current->cr, 1, s_left, s_top, s_right, s_bottom);
 
diff --git a/gschem/src/o_select.c b/gschem/src/o_select.c
index 0bd4046..6617b62 100644
--- a/gschem/src/o_select.c
+++ b/gschem/src/o_select.c
@@ -242,7 +242,6 @@ void o_select_object(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current,
  */
 int o_select_box_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int diff_x, diff_y;
 
   diff_x = abs(w_current->first_wx - w_x);
@@ -250,7 +249,7 @@ int o_select_box_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
 
   /* if we are still close to the button press location,
      then don't enter the selection box mode */
-  if (SCREENabs(toplevel, max(diff_x, diff_y)) < 10) {
+  if (SCREENabs (w_current, max(diff_x, diff_y)) < 10) {
     return FALSE;
   }
 
@@ -295,11 +294,10 @@ void o_select_box_motion (GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
  */
 void o_select_box_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   o_invalidate_rect (w_current, x1, y1, x2, y1);
   o_invalidate_rect (w_current, x1, y1, x1, y2);
@@ -314,11 +312,10 @@ void o_select_box_invalidate_rubber (GSCHEM_TOPLEVEL *w_current)
  */
 void o_select_box_draw_rubber (GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int x1, y1, x2, y2;
 
-  WORLDtoSCREEN(toplevel, w_current->first_wx, w_current->first_wy, &x1, &y1);
-  WORLDtoSCREEN(toplevel, w_current->second_wx, w_current->second_wy, &x2, &y2);
+  WORLDtoSCREEN (w_current, w_current->first_wx, w_current->first_wy, &x1, &y1);
+  WORLDtoSCREEN (w_current, w_current->second_wx, w_current->second_wy, &x2, &y2);
 
   gschem_cairo_box (w_current->cr, 1, x1, y1, x2, y2);
 
diff --git a/gschem/src/o_text.c b/gschem/src/o_text.c
index 4f6f4ab..ba59787 100644
--- a/gschem/src/o_text.c
+++ b/gschem/src/o_text.c
@@ -87,8 +87,8 @@ void o_text_draw_rectangle(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
      it's place */
 
   /* NOTE THAT THE TOP AND BOTTOM ARE REVERSED THROUGHT THE WHOLE OF GEDA FOR WORLD COORDS */
-  WORLDtoSCREEN( toplevel, o_current->w_left, o_current->w_bottom, &left, &top );
-  WORLDtoSCREEN( toplevel, o_current->w_right, o_current->w_top, &right, &bottom );
+  WORLDtoSCREEN (w_current, o_current->w_left, o_current->w_bottom, &left, &top);
+  WORLDtoSCREEN (w_current, o_current->w_right, o_current->w_top, &right, &bottom);
 
   if (toplevel->override_color != -1 ) {  /* Override */
     color = x_get_color (toplevel->override_color);
@@ -142,9 +142,9 @@ void o_text_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
         gdk_gc_set_foreground (w_current->gc, x_get_color (LOCK_COLOR));
       }
 
-      offset = SCREENabs(toplevel, 10);
-      small_dist = SCREENabs(toplevel, 20);
-      WORLDtoSCREEN( toplevel, o_current->text->x, o_current->text->y, &screen_x1, &screen_y1 );
+      offset = SCREENabs (w_current, 10);
+      small_dist = SCREENabs (w_current, 20);
+      WORLDtoSCREEN (w_current, o_current->text->x, o_current->text->y, &screen_x1, &screen_y1);
       screen_x1 += offset;
       screen_y1 += offset;
       if (toplevel->DONT_REDRAW == 0) {
@@ -181,13 +181,13 @@ void o_text_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
     return;
   }
 
-  small_dist = SCREENabs(toplevel, 10);
+  small_dist = SCREENabs (w_current, 10);
 
   /* Switch of mark drawing for non-selected text, and at small sizes */
   if (!o_current->selected || small_dist < MINIMUM_MARK_SMALL_DIST)
     return;
 
-  WORLDtoSCREEN( toplevel, o_current->text->x, o_current->text->y, &screen_x1, &screen_y1 );
+  WORLDtoSCREEN (w_current, o_current->text->x, o_current->text->y, &screen_x1, &screen_y1);
 
   /* this is not really a fix, but a lame patch */
   /* not having this will cause a bad draw of things when coords */
@@ -244,8 +244,8 @@ void o_text_draw_place (GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *o_cu
   } else {
     /* text is too small so go through and draw a line in
        it's place */
-    WORLDtoSCREEN(toplevel, o_current->w_left + dx, o_current->w_bottom + dy, &left, &top);
-    WORLDtoSCREEN(toplevel, o_current->w_right + dx, o_current->w_top + dy, &right, &bottom);
+    WORLDtoSCREEN (w_current, o_current->w_left + dx, o_current->w_bottom + dy, &left, &top);
+    WORLDtoSCREEN (w_current, o_current->w_right + dx, o_current->w_top + dy, &right, &bottom);
 
     if (o_current->saved_color != -1) {
       color = o_current->saved_color;
diff --git a/gschem/src/x_dialog.c b/gschem/src/x_dialog.c
index f0fdd0c..e61b398 100644
--- a/gschem/src/x_dialog.c
+++ b/gschem/src/x_dialog.c
@@ -2091,7 +2091,6 @@ void coord_dialog_response(GtkWidget *w, gint response, GSCHEM_TOPLEVEL *w_curre
  */
 void coord_display_update(GSCHEM_TOPLEVEL *w_current, int x, int y)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   char *string;
   int world_x, world_y;
 
@@ -2099,9 +2098,9 @@ void coord_display_update(GSCHEM_TOPLEVEL *w_current, int x, int y)
   gtk_label_set_text(GTK_LABEL(w_current->coord_screen), string );
   g_free(string);
 
-  SCREENtoWORLD(toplevel, x, y, &world_x, &world_y);
-  world_x = snap_grid(toplevel, world_x);
-  world_y = snap_grid(toplevel, world_y);
+  SCREENtoWORLD (w_current, x, y, &world_x, &world_y);
+  world_x = snap_grid (w_current, world_x);
+  world_y = snap_grid (w_current, world_y);
 
   string = g_strdup_printf("(%d, %d)", world_x, world_y);
   gtk_label_set_text(GTK_LABEL(w_current->coord_world), string );
diff --git a/gschem/src/x_event.c b/gschem/src/x_event.c
index f0ebf63..e2ef971 100644
--- a/gschem/src/x_event.c
+++ b/gschem/src/x_event.c
@@ -101,10 +101,10 @@ gint x_event_button_pressed(GtkWidget *widget, GdkEventButton *event,
   printf("\n");
 #endif
 
-  SCREENtoWORLD( toplevel, (int) event->x, (int) event->y,
-                 &unsnapped_wx, &unsnapped_wy );
-  w_x = snap_grid(toplevel, unsnapped_wx);
-  w_y = snap_grid(toplevel, unsnapped_wy);
+  SCREENtoWORLD (w_current, (int) event->x, (int) event->y,
+                 &unsnapped_wx, &unsnapped_wy);
+  w_x = snap_grid (w_current, unsnapped_wx);
+  w_y = snap_grid (w_current, unsnapped_wy);
 
   if (event->type == GDK_2BUTTON_PRESS &&
       (w_current->event_state == STARTSELECT ||
@@ -529,10 +529,10 @@ gint x_event_button_released(GtkWidget *widget, GdkEventButton *event,
   w_current->CONTROLKEY = (event->state & GDK_CONTROL_MASK) ? 1 : 0;
   w_current->ALTKEY     = (event->state & GDK_MOD1_MASK) ? 1 : 0;
 
-  SCREENtoWORLD( toplevel, (int) event->x, (int) event->y,
-                 &unsnapped_wx, &unsnapped_wy );
-  w_x = snap_grid(toplevel, unsnapped_wx);
-  w_y = snap_grid(toplevel, unsnapped_wy);
+  SCREENtoWORLD (w_current, (int) event->x, (int) event->y,
+                 &unsnapped_wx, &unsnapped_wy);
+  w_x = snap_grid (w_current, unsnapped_wx);
+  w_y = snap_grid (w_current, unsnapped_wy);
 
   if (event->button == 1) {
     switch(w_current->event_state) {
@@ -719,7 +719,6 @@ gint x_event_button_released(GtkWidget *widget, GdkEventButton *event,
 gint x_event_motion(GtkWidget *widget, GdkEventMotion *event,
                     GSCHEM_TOPLEVEL *w_current)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int pdiff_x, pdiff_y;
   int w_x, w_y;
   int unsnapped_wx, unsnapped_wy;
@@ -759,10 +758,10 @@ gint x_event_motion(GtkWidget *widget, GdkEventMotion *event,
       return 0;
   }
 
-  SCREENtoWORLD( toplevel, (int) event->x, (int) event->y,
-                 &unsnapped_wx, &unsnapped_wy );
-  w_x = snap_grid(toplevel, unsnapped_wx);
-  w_y = snap_grid(toplevel, unsnapped_wy);
+  SCREENtoWORLD (w_current, (int) event->x, (int) event->y,
+                 &unsnapped_wx, &unsnapped_wy);
+  w_x = snap_grid (w_current, unsnapped_wx);
+  w_y = snap_grid (w_current, unsnapped_wy);
 
   if (w_current->cowindow) {
     coord_display_update(w_current, (int) event->x, (int) event->y);
@@ -1137,14 +1136,13 @@ gint x_event_enter(GtkWidget *widget, GdkEventCrossing *event,
  */
 static void get_snapped_pointer (GSCHEM_TOPLEVEL *w_current, int *wx, int *wy)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int sx, sy;
   int unsnapped_wx, unsnapped_wy;
 
   gtk_widget_get_pointer (w_current->drawing_area, &sx, &sy);
-  SCREENtoWORLD (toplevel, sx, sy, &unsnapped_wx, &unsnapped_wy);
-  *wx = snap_grid (toplevel, unsnapped_wx);
-  *wy = snap_grid (toplevel, unsnapped_wy);
+  SCREENtoWORLD (w_current, sx, sy, &unsnapped_wx, &unsnapped_wy);
+  *wx = snap_grid (w_current, unsnapped_wx);
+  *wy = snap_grid (w_current, unsnapped_wy);
 }
 
 /*! \todo Finish function documentation!!!
@@ -1357,7 +1355,6 @@ gboolean x_event_get_pointer_position (GSCHEM_TOPLEVEL *w_current,
 				       gboolean snapped,
 				       gint *wx, gint *wy)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int sx, sy, x, y;
 
   gtk_widget_get_pointer(w_current->drawing_area, &sx, &sy);
@@ -1367,10 +1364,10 @@ gboolean x_event_get_pointer_position (GSCHEM_TOPLEVEL *w_current,
       || sy <0 || sy >= w_current->win_height)
     return FALSE;
 
-  SCREENtoWORLD(toplevel, sx, sy, &x, &y);
+  SCREENtoWORLD (w_current, sx, sy, &x, &y);
   if (snapped) {
-    x = snap_grid(toplevel, x);
-    y = snap_grid(toplevel, y);
+    x = snap_grid (w_current, x);
+    y = snap_grid (w_current, y);
   }
   *wx = x;
   *wy = y;
diff --git a/gschem/src/x_grid.c b/gschem/src/x_grid.c
index 3b0ae7c..a98c168 100644
--- a/gschem/src/x_grid.c
+++ b/gschem/src/x_grid.c
@@ -66,7 +66,7 @@ static int query_dots_grid_spacing (GSCHEM_TOPLEVEL *w_current)
   } else {
     /* Fixed size grid in world coorinates */
     incr = toplevel->snap_size;
-    screen_incr = SCREENabs (toplevel, incr);
+    screen_incr = SCREENabs (w_current, incr);
     if (screen_incr < w_current->dots_grid_fixed_threshold) {
       /* No grid drawn if the on-screen spacing is less than the threshold */
       incr = -1;
@@ -104,8 +104,8 @@ static void draw_dots_grid_region (GSCHEM_TOPLEVEL *w_current,
 
   gdk_gc_set_foreground (w_current->gc, x_get_color (DOTS_GRID_COLOR));
 
-  SCREENtoWORLD (toplevel, x - 1, y + height + 1, &x_start, &y_start);
-  SCREENtoWORLD (toplevel, x + width + 1, y - 1, &x_end, &y_end);
+  SCREENtoWORLD (w_current, x - 1, y + height + 1, &x_start, &y_start);
+  SCREENtoWORLD (w_current, x + width + 1, y - 1, &x_end, &y_end);
 
   /* figure starting grid coordinates, work by taking the start
    * and end coordinates and rounding down to the nearest
@@ -115,7 +115,7 @@ static void draw_dots_grid_region (GSCHEM_TOPLEVEL *w_current,
 
   for (i = x_start; i <= x_end; i = i + incr) {
     for(j = y_start; j <= y_end; j = j + incr) {
-      WORLDtoSCREEN (toplevel, i,j, &dot_x, &dot_y);
+      WORLDtoSCREEN (w_current, i,j, &dot_x, &dot_y);
       if (inside_region (toplevel->page_current->left,
                          toplevel->page_current->top,
                          toplevel->page_current->right,
@@ -155,7 +155,6 @@ static void draw_mesh (GSCHEM_TOPLEVEL *w_current, int color,
                        int x_start, int y_start, int x_end, int y_end,
                        int incr, int coarse_mult)
 {
-  TOPLEVEL *toplevel = w_current->toplevel;
   int i, j;
   int x1, y1, x2, y2;
   int next_coarse_x, next_coarse_y;
@@ -189,8 +188,8 @@ static void draw_mesh (GSCHEM_TOPLEVEL *w_current, int color,
       next_coarse_y += coarse_incr;
       continue;
     }
-    WORLDtoSCREEN (toplevel, x_start, j, &x1, &y1);
-    WORLDtoSCREEN (toplevel, x_end,   j, &x2, &y2);
+    WORLDtoSCREEN (w_current, x_start, j, &x1, &y1);
+    WORLDtoSCREEN (w_current, x_end,   j, &x2, &y2);
     cairo_move_to (w_current->cr, x1, y1);
     cairo_line_to (w_current->cr, x2, y2);
   }
@@ -203,8 +202,8 @@ static void draw_mesh (GSCHEM_TOPLEVEL *w_current, int color,
       next_coarse_y += coarse_incr;
       continue;
     }
-    WORLDtoSCREEN (toplevel, i, y_start, &x1, &y1);
-    WORLDtoSCREEN (toplevel, i, y_end,   &x2, &y2);
+    WORLDtoSCREEN (w_current, i, y_start, &x1, &y1);
+    WORLDtoSCREEN (w_current, i, y_end,   &x2, &y2);
     cairo_move_to (w_current->cr, x1, y1);
     cairo_line_to (w_current->cr, x2, y2);
   }
@@ -231,7 +230,7 @@ static int query_mesh_grid_spacing (GSCHEM_TOPLEVEL *w_current)
   int incr, screen_incr;
 
   incr = toplevel->snap_size;
-  screen_incr = SCREENabs (toplevel, incr);
+  screen_incr = SCREENabs (w_current, incr);
 
   /* We draw a fine grid if its on-screen spacing is large enough */
   if (screen_incr >= w_current->mesh_grid_display_threshold) {
@@ -239,7 +238,7 @@ static int query_mesh_grid_spacing (GSCHEM_TOPLEVEL *w_current)
   }
 
   incr *= MESH_COARSE_GRID_MULTIPLIER;
-  screen_incr = SCREENabs (toplevel, incr);
+  screen_incr = SCREENabs (w_current, incr);
 
   /* We draw a coarse grid if its on-screen spacing is large enough */
   if (screen_incr >= w_current->mesh_grid_display_threshold)
@@ -268,10 +267,10 @@ static void draw_mesh_grid_region (GSCHEM_TOPLEVEL *w_current,
   int screen_incr;
 
   incr = toplevel->snap_size;
-  screen_incr = SCREENabs (toplevel, incr);
+  screen_incr = SCREENabs (w_current, incr);
 
-  SCREENtoWORLD (toplevel, x - 1, y + height + 1, &x_start, &y_start);
-  SCREENtoWORLD (toplevel, x + width + 1, y - 1, &x_end, &y_end);
+  SCREENtoWORLD (w_current, x - 1, y + height + 1, &x_start, &y_start);
+  SCREENtoWORLD (w_current, x + width + 1, y - 1, &x_end, &y_end);
 
   /* Draw the fine grid if its on-screen spacing is large enough */
   if (screen_incr >= w_current->mesh_grid_display_threshold) {
@@ -280,7 +279,7 @@ static void draw_mesh_grid_region (GSCHEM_TOPLEVEL *w_current,
   }
 
   incr *= MESH_COARSE_GRID_MULTIPLIER;
-  screen_incr = SCREENabs (toplevel, incr);
+  screen_incr = SCREENabs (w_current, incr);
 
   /* Draw the coarse grid if its on-screen spacing is large enough */
   if (screen_incr >= w_current->mesh_grid_display_threshold) {
@@ -368,10 +367,8 @@ void x_draw_tiles(GSCHEM_TOPLEVEL *w_current)
   for (j = 0; j < MAX_TILES_Y; j++) {
     for (i = 0; i < MAX_TILES_X; i++) {
       t_current = &toplevel->page_current->world_tiles[i][j];
-      WORLDtoSCREEN(toplevel, t_current->left,
-                    t_current->top, &x1, &y1);
-      WORLDtoSCREEN(toplevel, t_current->right,
-                    t_current->bottom, &x2, &y2);
+      WORLDtoSCREEN (w_current, t_current->left, t_current->top, &x1, &y1);
+      WORLDtoSCREEN (w_current, t_current->right, t_current->bottom, &x2, &y2);
 
       screen_x = min(x1, x2);
       screen_y = min(y1, y2);
diff --git a/gschem/src/x_image.c b/gschem/src/x_image.c
index 857075e..61d3270 100644
--- a/gschem/src/x_image.c
+++ b/gschem/src/x_image.c
@@ -638,16 +638,10 @@ GdkPixbuf *x_image_get_pixbuf (GSCHEM_TOPLEVEL *w_current)
 
   new_w_current.toplevel = &toplevel;
 
-  WORLDtoSCREEN(&toplevel, 
-      toplevel.page_current->right,
-      toplevel.page_current->left,
-      &s_right,
-      &s_left);
-  WORLDtoSCREEN(&toplevel, 
-      toplevel.page_current->bottom,
-      toplevel.page_current->top,
-      &s_bottom,
-      &s_top);
+  WORLDtoSCREEN (&new_w_current, toplevel.page_current->right,
+                                 toplevel.page_current->left, &s_right, &s_left);
+  WORLDtoSCREEN (&new_w_current, toplevel.page_current->bottom,
+                                 toplevel.page_current->top,  &s_bottom, &s_top);
 
   size_x = s_left - s_right;
   size_y = s_bottom - s_top;
diff --git a/libgeda/include/prototype.h b/libgeda/include/prototype.h
index a8d5f61..7fdd105 100644
--- a/libgeda/include/prototype.h
+++ b/libgeda/include/prototype.h
@@ -69,24 +69,10 @@ GdkPixbuf *gdk_pixbuf_mirror_flip(GdkPixbuf *src, gint mirror, gint flip);
 void libgeda_init(void);
 
 /* m_basic.c */
-int mil_x(TOPLEVEL *toplevel, int val);
-int mil_y(TOPLEVEL *toplevel, int val);
-int pix_x(TOPLEVEL *toplevel, int val);
-int pix_y(TOPLEVEL *toplevel, int val);
-void WORLDtoSCREEN(TOPLEVEL *toplevel, int x, int y, int *mil_x, int *mil_y);
-void SCREENtoWORLD(TOPLEVEL *toplevel, int mx, int my, int *x, int *y);
-int snap_grid(TOPLEVEL *toplevel, int input);
-int SCREENabs(TOPLEVEL *toplevel, int val);
-int WORLDabs(TOPLEVEL *toplevel, int val);
 void set_window(TOPLEVEL *toplevel, PAGE *page, int xmin, int xmax, int ymin, int ymax);
-int on_snap(int val);
-int SCREENclip_change(TOPLEVEL *toplevel, int *x1, int *y1, int *x2, int *y2);
-int clip_nochange(TOPLEVEL *toplevel, int x1, int y1, int x2, int y2);
-int visible(TOPLEVEL *toplevel, int wleft, int wtop, int wright, int wbottom);
 void rotate_point(int x, int y, int angle, int *newx, int *newy);
 void rotate_point_90(int x, int y, int angle, int *newx, int *newy);
 void PAPERSIZEtoWORLD(int width, int height, int border, int *right, int *bottom);
-double round_5_2_1(double unrounded);
 
 /* m_hatch.c */
 void m_hatch_box(BOX *box, gint angle, gint pitch, GArray *lines);
diff --git a/libgeda/src/m_basic.c b/libgeda/src/m_basic.c
index b5ca7c7..b46c3e6 100644
--- a/libgeda/src/m_basic.c
+++ b/libgeda/src/m_basic.c
@@ -28,271 +28,6 @@
 #include <dmalloc.h>
 #endif
 
-/*! \brief Convert a x coordinate to mils.
- *  \par Function Description
- *  Convert a x coordinate to mils.
- *
- *  \param [in] toplevel  The TOPLEVEL object
- *  \param [in] val        The x coordinate to convert
- *  \return The coordinate value in mils.
- */
-int mil_x(TOPLEVEL *toplevel, int val)
-{
-  double i;
-  double fval;
-  int j;
-
-  fval = val;
-  i = fval * toplevel->page_current->to_world_x_constant +
-  toplevel->page_current->left;
-
-#ifdef HAS_RINT
-  j = rint(i);
-#else
-  j = i;
-#endif
-
-  return(j);
-}
-
-/*! \brief Convert a y coordinate to mils
- *  \par Function Description
- *  Convert a y coordinate to mils
- *
- *  \param [in] toplevel  The TOPLEVEL object.
- *  \param [in] val        The y coordinate to convert.
- *  \return The coordinate value in mils.
- */
-int mil_y(TOPLEVEL *toplevel, int val)
-{
-  double i;
-  double fval;
-  int j;
-
-  fval = toplevel->height - val;
-  i = fval * toplevel->page_current->to_world_y_constant +
-  toplevel->page_current->top;
-
-#ifdef HAS_RINT
-  j = rint(i);
-#else
-  j = i;
-#endif
-
-  return(j);
-}
-
-/*! \brief Convert a x coordinate to pixels.
- *  \par Function Description
- *  Convert a x coordinate to pixels.
- *
- *  \param [in] toplevel  The TOPLEVEL object
- *  \param [in] val        The x coordinate to convert
- *  \return The coordinate value in pixels.
- */
-int pix_x(TOPLEVEL *toplevel, int val)
-{
-
-  double i;
-  int j;
-
-  i = toplevel->page_current->to_screen_x_constant *
-  (double)(val - toplevel->page_current->left);
-
-#ifdef HAS_RINT
-  j = rint(i);
-#else
-  j = i;
-#endif
-
-  /* this is a temp solution to fix the wrapping associated with */
-  /* X coords being greated/less than than 2^15 */
-  if (j >= 32768) {
-    j = 32767;
-  }
-  if (j <= -32768) {
-    j = -32767;
-  }
-
-  return(j);
-}
-
-/*! \brief Convert a y coordinate to pixels.
- *  \par Function Description
- *  Convert a y coordinate to pixels.
- *
- *  \param [in] toplevel  The TOPLEVEL object
- *  \param [in] val        The y coordinate to convert
- *  \return The coordinate value in pixels.
- */
-int pix_y(TOPLEVEL *toplevel, int val)
-{
-  double i;
-  int j;
-
-  i = toplevel->height - (
-                           toplevel->page_current->to_screen_y_constant *
-                           (double)(val - toplevel->page_current->top));
-
-#ifdef HAS_RINT
-  j = rint(i);
-#else
-  j = i;
-#endif
-
-  /* this is a temp solution to fix the wrapping associated with */
-  /* X coords being greated/less than than 2^15 */
-  if (j >= 32768) {
-    j = 32767;
-  }
-  if (j <= -32768) {
-    j = -32767;
-  }
-
-  return(j);
-}
-
-/*! \brief Transform WORLD coordinates to SCREEN coordinates
- *  \par Function Description
- *  This function takes in WORLD x/y coordinates and
- *  transforms them to SCREEN x/y coordinates.
- *
- *  \param [in]  toplevel  The TOPLEVEL object.
- *  \param [in]  x          The x coordinate in WORLD units.
- *  \param [in]  y          The y coordinate in WORLD units.
- *  \param [out] mil_x      The x coordinate in SCREEN units.
- *  \param [out] mil_y      The y coordinate in SCREEN units.
- *  \note Question: why are we returning in mil_x and mil_y
- *                  if this is WORLD to SCREEN shouldn't SCREEN
- *                  coordinates be returned in x and y?
- */
-void WORLDtoSCREEN(TOPLEVEL *toplevel, int x, int y, int *mil_x, int *mil_y)
-{
-  *mil_x = pix_x(toplevel, x);
-  *mil_y = pix_y(toplevel, y);
-}
-
-/*! \brief Transform WORLD coordinates to WORLD coordinates
- *  \par Function Description
- *  This function takes in SCREEN x/y coordinates and
- *  transforms them to WORLD x/y coordinates.
- *
- *  \param [in]  toplevel  The TOPLEVEL object.
- *  \param [in]  mx         The x coordinate in SCREEN units.
- *  \param [in]  my         The y coordinate in SCREEN units.
- *  \param [out] x          The x coordinate in WORLD units.
- *  \param [out] y          The y coordinate in WORLD units.
- *  \note Question: why are we returning in x and y
- *                  if this is SCREEN to WORLD shouldn't WORLD
- *                  coordinates be returned in mx and my?
- */
-void SCREENtoWORLD(TOPLEVEL *toplevel, int mx, int my, int *x, int *y)
-{
-  *x = mil_x(toplevel, mx);
-  *y = mil_y(toplevel, my);
-}
-
-/*! \brief Find the closest grid coordinate.
- *  \par Function Description
- *  This function snaps the current input coordinate to the
- *  closest grid coordinate.
- *
- *  \param [in] toplevel  The TOPLEVEL object.
- *  \param [in] input      The coordinate to snap.
- *  \return The closest grid coordinate to the input.
- */
-int snap_grid(TOPLEVEL *toplevel, int input)
-{
-  int p, m, n;
-  int sign, value, snap_grid;
-	
-  if (toplevel->snap == SNAP_OFF || (toplevel->snap_size <= 0)) {
-    return(input);
-  }
-		
-  snap_grid = toplevel->snap_size;
-
-  /* this code was inspired from killustrator, it's much simpler than mine */
-  sign = ( input < 0 ? -1 : 1 );
-  value = abs(input);
-
-  p = value / snap_grid;
-  m = value % snap_grid;
-  n = p * snap_grid;
-  if (m > snap_grid / 2)
-  n += snap_grid;
-
-#if DEBUG 
-  printf("p: %d\n", p);
-  printf("m: %d\n", m);
-  printf("m > snap_grid / 2: %d\n", (m > snap_grid / 2));
-  printf("n: %d\n", n);
-  printf("n*s: %d\n", n*sign);
-#endif
-
-  return(sign*n);
-}                               
-
-/*! \brief Get absolute SCREEN coordinate.
- *  \par Function Description
- *  Get absolute SCREEN coordinate.
- *
- *  \param [in] toplevel  The TOPLEVEL object.
- *  \param [in] val        The coordinate to convert.
- *  \return The converted SCREEN coordinate.
- */
-int SCREENabs(TOPLEVEL *toplevel, int val)
-{
-  double fs,f0,f1,f;
-
-  double i;
-  int j;
-
-  f0 = toplevel->page_current->left;
-  f1 = toplevel->page_current->right;
-  fs = toplevel->width;
-  f = toplevel->width / (f1 - f0);
-  i = f * (double)(val);
-
-#ifdef HAS_RINT
-  j = rint(i);
-#else
-  j = i;
-#endif
-
-  return(j);
-
-}
-
-/*! \brief Get absolute WORLD coordinate.
- *  \par Function Description
- *  Get absolute WORLD coordinate.
- *
- *  \param [in] toplevel  The TOPLEVEL object.
- *  \param [in] val        The coordinate to convert.
- *  \return The converted WORLD coordinate.
- */
-int WORLDabs(TOPLEVEL *toplevel, int val)
-{
-  double fw0,fw1,fw,fval;
-
-  double i;
-  int j;
-
-  fw1 = toplevel->page_current->right;
-  fw0 = toplevel->page_current->left;
-  fw  = toplevel->width;
-  fval = val;
-  i = fval * (fw1 - fw0) / fw;
-
-#ifdef HAS_RINT
-  j = rint(i);
-#else
-  j = i;
-#endif
-
-  return(j);
-}
 
 /*! \brief Set the contraints for the current page.
  *  \par Function Description
@@ -343,406 +78,6 @@ void set_window(TOPLEVEL *toplevel, PAGE *page,
   page->to_world_y_constant = (fw1 - fw0) / fw;
 }
 
-/*! \brief */
-typedef struct st_halfspace HALFSPACE;
-
-/*! \brief */
-struct st_halfspace {
-  int left; /* these are booleans */
-  int top;
-  int right; 
-  int bottom; 
-};
-
-/* \note 
- * encode_halfspace and clip are part of the cohen-sutherland clipping
- * algorithm.  They are used to determine if an object is visible or not 
- */
-/*! \brief Encode SCREEN coordinates as halfspace matrix.
- *  \par Function Description
- *  This function takes a point and checks if it is in the bounds
- *  of the current TOPLEVEL object's page coordinates. It
- *  handles points with SCREEN coordinates.
- *  
- *  \param [in]  toplevel  The TOPLEVEL object.
- *  \param [in]  point      The point in SCREEN coordinates to be checked.
- *  \param [out] halfspace  The created HALFSPACE structure.
- *
- *  \warning halfspace must be allocated before this function is called
- */
-static void SCREENencode_halfspace(TOPLEVEL *toplevel, sPOINT *point, HALFSPACE *halfspace)
-{
-  halfspace->left = point->x < 0;
-  halfspace->right = point->x > toplevel->width;
-  halfspace->bottom = point->y > toplevel->height;
-  halfspace->top = point->y < 0;
-}
-
-/*! \brief Encode WORLD coordinates as halfspace matrix.
- *  \par Function Description
- *  This function takes a point and checks if it is in the bounds
- *  of the current TOPLEVEL object's page coordinates. It
- *  handles points with WORLD coordinates.
- *  
- *  \param [in]  toplevel  The TOPLEVEL object.
- *  \param [in]  point      The point in WORLD coordinates to be checked.
- *  \param [out] halfspace  The created HALFSPACE structure.
- *
- *  \warning halfspace must be allocated before this function is called
- */
-static void WORLDencode_halfspace(TOPLEVEL *toplevel, sPOINT *point, HALFSPACE *halfspace)
-{
-  halfspace->left = point->x < toplevel->page_current->left;
-  halfspace->right = point->x > toplevel->page_current->right;
-  halfspace->bottom = point->y > toplevel->page_current->bottom;
-  halfspace->top = point->y < toplevel->page_current->top;
-}
-
-/*! \brief Calculate the cliping region for a set of coordinates.
- *  \par Function Description
- *  This function will check the provided set of coordinates to see if
- *  they fall within a clipping region.  If they do the coordinates will
- *  be changed to reflect only the region no covered by the clipping window.
- *  All coordinates should be in SCREEN units.
- *
- *  \param [in] toplevel  The current TOPLEVEL object.
- *  \param [in,out] x1     x coordinate of the first screen point.
- *  \param [in,out] y1     y coordinate of the first screen point.
- *  \param [in,out] x2     x coordinate of the second screen point.
- *  \param [in,out] y2     y coordinate of the second screen point.
- *  \return TRUE if coordinates are now visible, FALSE otherwise.
- */
-int SCREENclip_change(TOPLEVEL *toplevel,int *x1, int *y1, int *x2, int *y2)
-{
-  HALFSPACE half1, half2; 
-  HALFSPACE tmp_half;
-  sPOINT tmp_point;
-  sPOINT point1, point2;
-  float slope;
-  int in1, in2, done;
-  int visible;
-  int w_l, w_t, w_r, w_b;
-
-  point1.x = *x1;
-  point1.y = *y1;
-  point2.x = *x2;
-  point2.y = *y2;
-
-
-  w_l = 0;
-  w_t = 0;
-  w_r = toplevel->width;
-  w_b = toplevel->height;
-
-
-  done = FALSE;
-  visible = FALSE;
-
-  do {
-    SCREENencode_halfspace(toplevel, &point1, &half1);
-    SCREENencode_halfspace(toplevel, &point2, &half2);
-
-#if DEBUG
-    printf("starting loop\n");
-    printf("1 %d %d %d %d\n", half1.left, half1.top, half1.right, half1.bottom);
-    printf("2 %d %d %d %d\n", half2.left, half2.top, half2.right, half2.bottom);
-#endif
-
-    in1 = (!half1.left) && 
-      (!half1.top) && 
-      (!half1.right) && 
-      (!half1.bottom);
-
-    in2 = (!half2.left) &&  
-      (!half2.top) && 
-      (!half2.right) && 
-      (!half2.bottom);
-
-
-    if (in1 && in2) { /* trivally accept */
-      done = TRUE;
-      visible = TRUE;
-    } else if ( ((half1.left && half2.left) || 
-                 (half1.right && half2.right)) ||
-                ((half1.top && half2.top) || 
-                 (half1.bottom && half2.bottom)) ) {
-      done = TRUE; /* trivially reject */
-      visible = FALSE;
-    } else { /* at least one point outside */
-      if (in1) {
-        tmp_half = half1;
-        half1 = half2; 
-        half2 = tmp_half;
-
-        tmp_point = point1; 
-        point1 = point2; 
-        point2 = tmp_point;
-      }
-
-      if (point2.x == point1.x) { /* vertical line */
-        if (half1.top) {
-          point1.y = w_t;
-        } else if (half1.bottom) {
-          point1.y = w_b;
-        }
-      } else { /* not a vertical line */
-
-				/* possible fix for alpha core dumping */
-				/* assume the object is visible */
-        if ((point2.x - point1.x) == 0) {
-          return(TRUE);
-        }
-
-        slope = (float) (point2.y - point1.y) / 
-          (float) (point2.x - point1.x); 
-
-				/* possible fix for alpha core dumping */
-				/* assume the object is visible */
-        if (slope == 0.0) {
-          return(TRUE);
-        }
-
-        if (half1.left) {
-          point1.y = point1.y + 
-            (w_l - point1.x) * slope;
-          point1.x = w_l;
-        } else if (half1.right) {
-          point1.y = point1.y + 
-            (w_r - point1.x) * slope;
-          point1.x = w_r;
-        } else if (half1.bottom) {
-          point1.x = point1.x +
-            (w_b - point1.y) / slope;
-          point1.y = w_b;
-        } else if (half1.top) {
-          point1.x = point1.x + 
-            (w_t - point1.y) / slope;
-          point1.y = w_t;
-        }
-      } /* end of not a vertical line */
-    } /* end of at least one outside */
-  } while (!done);
-
-  /*printf("after: %d %d %d %d\n", point1.x, point1.y, point2.x, point2.y);*/
-  *x1 = point1.x;
-  *y1 = point1.y;
-  *x2 = point2.x;
-  *y2 = point2.y;
-  return(visible);
-}
-
-/*! \brief Check if a set of coordinates are within a clipping region
- *  \par Function Description
- *  This function will check if the given set of coordinates
- *  are within a clipping region. No action will be taken to change
- *  the coordinates.
- *
- *  \param [in] toplevel  The current TOPLEVEL object.
- *  \param [in,out] x1     x coordinate of the first screen point.
- *  \param [in,out] y1     y coordinate of the first screen point.
- *  \param [in,out] x2     x coordinate of the second screen point.
- *  \param [in,out] y2     y coordinate of the second screen point.
- *  \return TRUE if coordinates are now visible, FALSE otherwise.
- */
-int clip_nochange(TOPLEVEL *toplevel,int x1, int y1, int x2, int y2)
-{
-  HALFSPACE half1, half2; 
-  HALFSPACE tmp_half;
-  sPOINT tmp_point;
-  sPOINT point1, point2;
-  float slope;
-  int in1, in2, done;
-  int visible;
-  int w_l, w_t, w_r, w_b;
-
-  point1.x = x1;
-  point1.y = y1;
-  point2.x = x2;
-  point2.y = y2;
-
-  /*printf("before: %d %d %d %d\n", x1, y1, x2, y2);*/
-
-  w_l = toplevel->page_current->left;
-  w_t = toplevel->page_current->top;
-  w_r = toplevel->page_current->right;
-  w_b = toplevel->page_current->bottom;
-
-  done = FALSE;
-  visible = FALSE;
-
-  do {
-    WORLDencode_halfspace(toplevel, &point1, &half1);
-    WORLDencode_halfspace(toplevel, &point2, &half2);
-
-#if DEBUG
-    printf("starting loop\n");
-    printf("1 %d %d %d %d\n", half1.left, half1.top, half1.right, half1.bottom);
-    printf("2 %d %d %d %d\n", half2.left, half2.top, half2.right, half2.bottom);
-#endif
-
-    in1 = (!half1.left) && 
-      (!half1.top) && 
-      (!half1.right) && 
-      (!half1.bottom);
-
-    in2 = (!half2.left) &&  
-      (!half2.top) && 
-      (!half2.right) && 
-      (!half2.bottom);
-
-
-    if (in1 && in2) { /* trivally accept */
-      done = TRUE;
-      visible = TRUE;
-    } else if ( ((half1.left && half2.left) || 
-                 (half1.right && half2.right)) ||
-                ((half1.top && half2.top) || 
-                 (half1.bottom && half2.bottom)) ) {
-      done = TRUE; /* trivially reject */
-      visible = FALSE;
-    } else { /* at least one point outside */
-      if (in1) {
-        tmp_half = half1;
-        half1 = half2; 
-        half2 = tmp_half;
-
-        tmp_point = point1; 
-        point1 = point2; 
-        point2 = tmp_point;
-      }
-
-      if (point2.x == point1.x) { /* vertical line */
-        if (half1.top) {
-          point1.y = w_t;
-        } else if (half1.bottom) {
-          point1.y = w_b;
-        }
-      } else { /* not a vertical line */
-
-				/* possible fix for alpha core dumping */
-				/* assume the object is visible */
-        if ((point2.x - point1.x) == 0) {
-          return(TRUE);
-        }
-
-        slope = (float) (point2.y - point1.y) / 
-          (float) (point2.x - point1.x); 
-
-				/* possible fix for alpha core dumping */
-				/* assume the object is visible */
-        if (slope == 0.0) {
-          return(TRUE);
-        }
-
-        if (half1.left) {
-          point1.y = point1.y + 
-            (w_l - point1.x) * slope;
-          point1.x = w_l;
-        } else if (half1.right) {
-          point1.y = point1.y + 
-            (w_r - point1.x) * slope;
-          point1.x = w_r;
-        } else if (half1.bottom) {
-          point1.x = point1.x +
-            (w_b - point1.y) / slope;
-          point1.y = w_b;
-        } else if (half1.top) {
-          point1.x = point1.x + 
-            (w_t - point1.y) / slope;
-          point1.y = w_t;
-        }
-      } /* end of not a vertical line */
-    } /* end of at least one outside */
-  } while (!done);
-
-  return(visible);
-}
-
-/*! \brief Check if a bounding box is visible on the screen.
- *  \par Function Description
- *  This function checks if a given bounding box is visible on the screen.
- *
- *  WARNING: top and bottom are mis-named in world-coords,
- *  top is the smallest "y" value, and bottom is the largest.
- *  Be careful! This doesn't correspond to what you'd expect.
- *
- *  \param [in] toplevel  The TOPLEVEL object.
- *  \param [in] wleft      Left coordinate of the bounding box.
- *  \param [in] wtop       Top coordinate of the bounding box.
- *  \param [in] wright     Right coordinate of the bounding box.
- *  \param [in] wbottom    Bottom coordinate of the bounding box.
- *  \return TRUE if bounding box is visible, FALSE otherwise
- */
-int visible(TOPLEVEL *toplevel, int wleft, int wtop, int wright, int wbottom)
-{
-  int visible=FALSE;
-
-  /* don't do object clipping if this is false */
-  if (!toplevel->object_clipping) {
-    return(TRUE);
-  }
-
-  visible = clip_nochange(toplevel, wleft, wtop, wright, wtop);
-
-#if DEBUG 
-  printf("vis1 %d\n", visible);
-#endif
-
-  if (!visible) {
-    visible = clip_nochange(toplevel, wleft, wbottom, wright, wbottom);
-  } else {
-    return(visible);
-  } 
-
-#if DEBUG
-  printf("vis2 %d\n", visible);
-#endif
-
-  if (!visible) {
-    visible = clip_nochange(toplevel, wleft, wtop, wleft, wbottom);
-  } else {
-    return(visible);
-  } 
-
-#if DEBUG 
-  printf("vis3 %d\n", visible);
-#endif
-
-  if (!visible) {
-    visible = clip_nochange(toplevel, wright, wtop, wright, wbottom);
-  } else {
-    return(visible);
-  } 
-
-#if DEBUG 
-  printf("vis4 %d\n", visible);
-#endif
-
-#if DEBUG
-  printf("%d %d %d\n", wleft, toplevel->page_current->top, wright);
-  printf("%d %d %d\n", wtop, toplevel->page_current->top, wbottom);
-  printf("%d %d %d\n", wleft, toplevel->page_current->right, wright);
-  printf("%d %d %d\n", wtop, toplevel->page_current->bottom, wbottom);
-#endif
-
-  /*
-   * now check to see if bounding box encompasses the entire viewport.
-   * We only need to test if one point on the screen clipping boundary
-   * is indide the bounding box of the object.
-   */
-  if (toplevel->page_current->left >= wleft  &&
-      toplevel->page_current->left <= wright &&
-      toplevel->page_current->top >= wtop    &&
-      toplevel->page_current->top <= wbottom ) {
-    visible = 1;
-  }
-
-#if DEBUG 
-  printf("vis5 %d\n", visible);
-#endif
-
-  return(visible);
-}
 
 /*! \brief Rotate a point by an arbitrary angle.
  *  \par Function Description
@@ -816,6 +151,7 @@ void rotate_point_90(int x, int y, int angle, int *newx, int *newy)
   *newy = x * sintheta + y * costheta;
 }
 
+
 /*! \brief Convert Paper size to World coordinates.
  *  \par Function Description
  *  This function takes the paper size and converts it to
@@ -860,42 +196,3 @@ void PAPERSIZEtoWORLD(int width, int height, int border, int *right, int *bottom
 #endif
 
 }
-
-
-/*! \brief Rounds numbers by a power of 10.
- *  \par Function Description
- *  This function will round numbers using a power of 10 method.
- *  For example:
- *                1235 rounds to 1000
- *                 670 rounds to  500
- *               0.234 rounds to  0.2
- *  integer values would be enough if there are no numbers smaller than 1 (hw)
- *
- *  \param [in] unrounded  The number to be rounded.
- *  \return The rounded number.
- */
-/* rounds for example 1235 to 1000, 670 to 500, 0.234 to 0.2 ...
-int would be enough if there are no numbers smaller 1 (hw)*/
-double round_5_2_1(double unrounded)
-{
-  int digits;
-  double betw_1_10;
-	
-  /*only using the automatic cast */
-  digits = log10(unrounded);
-  /* creates numbers between 1 and 10 */
-  betw_1_10 = unrounded / pow(10,digits);
-	
-  if (betw_1_10 < 1.5) {
-    return(pow(10,digits));
-  }
-  if (betw_1_10 > 1.4 && betw_1_10 < 3.5 ) {
-    return(2*pow(10,digits));
-  }
-  if (betw_1_10 > 3.4 && betw_1_10 < 7.5 ) {
-    return(5*pow(10,digits));
-  }
-  else {
-    return(10*pow(10,digits));
-  }
-}

commit 4d79aa73981d6caa2c803250d1be266d7657f0c2
Author: Peter Clifton <pcjc2@xxxxxxxxx>
Date:   Sat Jan 3 19:54:03 2009 +0000

    Move o_line_visible() from libgeda into gschem
    
    This function relates to on-screen visibility, so should be in gschem.

diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index 1bb685f..a668516 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -582,6 +582,7 @@ void o_line_end(GSCHEM_TOPLEVEL *w_current, int x, int y);
 void o_line_motion(GSCHEM_TOPLEVEL *w_current, int x, int y);
 void o_line_draw_rubber(GSCHEM_TOPLEVEL *w_current);
 void o_line_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current);
+int o_line_visible(GSCHEM_TOPLEVEL *w_current, LINE *line, int *x1, int *y1, int *x2, int *y2);
 /* o_misc.c */
 void o_edit(GSCHEM_TOPLEVEL *w_current, GList *list);
 void o_lock(GSCHEM_TOPLEVEL *w_current);
diff --git a/gschem/src/o_bus.c b/gschem/src/o_bus.c
index ddd254a..20d6d75 100644
--- a/gschem/src/o_bus.c
+++ b/gschem/src/o_bus.c
@@ -48,7 +48,7 @@ void o_bus_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 
   /* reuse line's routine */
   if ( (toplevel->DONT_REDRAW == 1) ||
-       (!o_line_visible(toplevel, o_current->line, &x1, &y1, &x2, &y2)) ) {
+       (!o_line_visible (w_current, o_current->line, &x1, &y1, &x2, &y2)) ) {
     return;
   }
 
diff --git a/gschem/src/o_line.c b/gschem/src/o_line.c
index 3ac4058..bad3fc5 100644
--- a/gschem/src/o_line.c
+++ b/gschem/src/o_line.c
@@ -53,7 +53,7 @@ void o_line_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
   }
 
   if ( (toplevel->DONT_REDRAW == 1) ||
-       (!o_line_visible(toplevel, o_current->line, &x1, &y1, &x2, &y2)) ) {
+       (!o_line_visible (w_current, o_current->line, &x1, &y1, &x2, &y2)) ) {
     return;
   }
 	
@@ -333,3 +333,29 @@ void o_line_draw_grips(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
   /* draw the grip on line end 2 */
   o_grips_draw(w_current, x[LINE_END2], y[LINE_END2]);
 }
+
+
+/*! \brief
+ *  \par Function Description
+ *
+ *  \param [in] toplevel  The TOPLEVEL object.
+ *  \param [in] line
+ *  \param [in] x1
+ *  \param [in] y1
+ *  \param [in] x2
+ *  \param [in] y2
+ *  \return int
+ */
+int o_line_visible (GSCHEM_TOPLEVEL *w_current, LINE *line,
+                    int *x1, int *y1, int *x2, int *y2)
+{
+  /* don't do clipping if this is false */
+  if (!w_current->toplevel->object_clipping) {
+    return(TRUE);
+  }
+
+  WORLDtoSCREEN (w_current->toplevel, line->x[0], line->y[0], x1, y1);
+  WORLDtoSCREEN (w_current->toplevel, line->x[1], line->y[1], x2, y2);
+
+  return SCREENclip_change (w_current->toplevel, x1, y1, x2, y2);
+}
diff --git a/gschem/src/o_net.c b/gschem/src/o_net.c
index 50595d3..b75d513 100644
--- a/gschem/src/o_net.c
+++ b/gschem/src/o_net.c
@@ -91,7 +91,7 @@ void o_net_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 
   /* reuse line's routine */
   if ( (toplevel->DONT_REDRAW == 1) ||
-       (!o_line_visible(toplevel, o_current->line, &x1, &y1, &x2, &y2)) ) {
+       (!o_line_visible (w_current, o_current->line, &x1, &y1, &x2, &y2)) ) {
     return;
   }
 
diff --git a/gschem/src/o_pin.c b/gschem/src/o_pin.c
index 9e37997..bb117c3 100644
--- a/gschem/src/o_pin.c
+++ b/gschem/src/o_pin.c
@@ -46,7 +46,7 @@ void o_pin_draw(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current)
 
   /* reuse line's routine */
   if ( (toplevel->DONT_REDRAW == 1) ||
-       (!o_line_visible(toplevel, o_current->line, &x1, &y1, &x2, &y2)) ) {
+       (!o_line_visible (w_current, o_current->line, &x1, &y1, &x2, &y2)) ) {
     return;
   }
 
diff --git a/libgeda/include/prototype.h b/libgeda/include/prototype.h
index 121a004..a8d5f61 100644
--- a/libgeda/include/prototype.h
+++ b/libgeda/include/prototype.h
@@ -223,7 +223,6 @@ void o_line_translate_world(TOPLEVEL *toplevel, int dx, int dy, OBJECT *object);
 void o_line_rotate_world(TOPLEVEL *toplevel, int world_centerx, int world_centery, int angle, OBJECT *object);
 void o_line_mirror_world(TOPLEVEL *toplevel, int world_centerx, int world_centery, OBJECT *object);
 void o_line_scale_world(TOPLEVEL *toplevel, int x_scale, int y_scale, OBJECT *object);
-int o_line_visible(TOPLEVEL *toplevel, LINE *line, int *x1, int *y1, int *x2, int *y2);
 double o_line_length(OBJECT *object);
 
 /* o_list.c */
diff --git a/libgeda/src/o_line_basic.c b/libgeda/src/o_line_basic.c
index d04fdf7..dec2ec5 100644
--- a/libgeda/src/o_line_basic.c
+++ b/libgeda/src/o_line_basic.c
@@ -1158,35 +1158,6 @@ void o_line_scale_world(TOPLEVEL *toplevel, int x_scale, int y_scale,
   
 }
 
-/*! \brief
- *  \par Function Description
- *
- *  \param [in] toplevel  The TOPLEVEL object.
- *  \param [in] line
- *  \param [in] x1
- *  \param [in] y1
- *  \param [in] x2
- *  \param [in] y2
- *  \return int
- */
-int o_line_visible(TOPLEVEL *toplevel, LINE *line,
-                   int *x1, int *y1, int *x2, int *y2)
-{
-  int visible=0;
-
-
-  /* don't do clipping if this is false */
-  if (!toplevel->object_clipping) {
-    return(TRUE);
-  }
-
-  WORLDtoSCREEN( toplevel, line->x[0], line->y[0], x1, y1 );
-  WORLDtoSCREEN( toplevel, line->x[1], line->y[1], x2, y2 );
-
-  visible = SCREENclip_change(toplevel, x1, y1, x2, y2);
-
-  return(visible);
-}
 
 /*! \brief calculate the lenght of a line object
  *  \par Function Description




_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs