[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-cvs: CVS update: a_pan.nw
User: werner
Date: 06/04/09 04:11:36
Modified: . a_pan.nw a_zoom.nw i_callbacks.nw o_misc.nw
x_event.nw
Log:
rewrite of a_pan() and a_pan_mouse(), fixed scrollbar-update bugs
Revision Changes Path
1.7 +61 -296 eda/geda/devel/gschem/noweb/a_pan.nw
(In the diff below, changes in quantity of whitespace are not shown.)
Index: a_pan.nw
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/a_pan.nw,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- a_pan.nw 11 Feb 2005 18:22:10 -0000 1.6
+++ a_pan.nw 9 Apr 2006 08:11:36 -0000 1.7
@@ -12,9 +12,7 @@
<<a_pan.c : include directives>>
<<a_pan.c : macros>>
-<<a_pan.c : global variables>>
<<a_pan.c : a_pan_general()>>
-<<a_pan.c : a_pan_calc()>>
<<a_pan.c : a_pan()>>
<<a_pan.c : a_pan_mouse()>>
@@ -71,42 +69,32 @@
((w)->page_current->bottom - (w)->page_current->top )
#define GET_PAGE_CENTER_X(w) \
- ((w)->page_current->left + GET_PAGE_WIDTH(w) / 2);
+ (((w)->page_current->left + (w)->page_current->right) / 2.0)
#define GET_PAGE_CENTER_Y(w) \
- ((w)->page_current->top + GET_PAGE_HEIGHT(w) / 2);
+ (((w)->page_current->top + (w)->page_current->bottom) / 2.0)
@ %def GET_PAGE_WIDTH GET_PAGE_HEIGHT GET_PAGE_CENTER_X GET_PAGE_CENTER_Y
-<<a_pan.c : global variables>>=
-int current_center_x = 0;
-int current_center_y = 0;
-
-@ %def current_center_x current_center_y
-
-
@section Function @code{a_pan_general()}
@defun a_pan_general w_current world_cx world_cy relativ_zoom_factor flags
@end defun
<<a_pan.c : a_pan_general()>>=
-/* experimental */
/* Kazu Hirata <kazu@xxxxxxxx> on July 25, 1999 - all zoom- and
* pan-related functions should eventually get to this function. It
* takes the desired center coordinate and the desired zoom
* factor. Necessary adjustments may be done depending on situations.
* */
-/* this code is not longer experimental an is use by several funktions
-like every zooming-function and the x_event_configure (Werner Hoch,(hw))*/
+/* this code is not longer experimental an is used by several functions
+ like every zooming-function and the x_event_configure (Werner Hoch,(hw))*/
+
void a_pan_general(TOPLEVEL *w_current, double world_cx, double world_cy,
double relativ_zoom_factor,int flags)
{
/* see libgeda/include/defines.h for flags */
-
- int fix = 0;
-
- /*if the borders should be ignored always rm outcomment or changes
+ /*if the borders should be ignored always, remove, outcomment or changes
the flags in the function-calls*/
/* flags |= A_PAN_IGNORE_BORDERS;
*/
@@ -115,10 +103,10 @@
int zoom_max = 5;
double zx,zy,zoom_old,zoom_new,zoom_min;
#if DEBUG
- printf("--------------a_pan_general: \nworld_cx: %f, world_cy: %f \n ",world_cx, world_cy);
+ printf("a_pan_general(): world_cx=%f, world_cy=%f\n",world_cx, world_cy);
#endif
- /* calc minimum zoomfactors and choose the smaller one, they are equal
- if the aspectratio of the world is the same as the worlds*/
+ /* calc minimum zoomfactors and choose the smaller one. They are equal
+ if the aspectratio of the world is the same as the screen ratio */
zx = (double) w_current->width / (w_current->init_right -
w_current->init_left);
zy = (double) w_current->height / (w_current->init_bottom -
@@ -126,28 +114,27 @@
zoom_min = zx < zy ? zx : zy;
#if DEBUG
- printf("zx_min: %f, zy_min: %f , flags: %d\n ",zx, zy, flags);
+ printf(" zx_min=%f, zy_min=%f , flags=%d\n ",zx, zy, flags);
#endif
- /*to_screen_x_constant and to_screen_y_constant are nearly equal*/
- /* zx = w_current->page_current->to_screen_x_constant;
- zy = w_current->page_current->to_screen_y_constant;
- zoom_old = zx < zy ? zx : zy;
- */
+ /* to_screen_x_constant and to_screen_y_constant are almost the same.
+ lets use to_screen_y_constant */
zoom_old = w_current->page_current->to_screen_y_constant;
- /*calc new zooming factor */
+ /* calc new zooming factor */
+ /* check if there's a zoom_full (relativ_zoom_factor == -1) */
+ if (relativ_zoom_factor <0) {
+ zoom_new = zoom_min;
+ }
+ else {
zoom_new = zoom_old * relativ_zoom_factor;
zoom_new = zoom_new > zoom_max ? zoom_max : zoom_new;
if (!(flags & A_PAN_IGNORE_BORDERS)) {
zoom_new = zoom_new < zoom_min ? zoom_min : zoom_new;
}
-
- /*check if theres a zoom_full (rel is -1)*/
- if (relativ_zoom_factor <0) {
- zoom_new = zoom_min;
}
- /*calculate the new visible area; adding 0.5 to round */
+
+ /* calculate the new visible area; adding 0.5 to round */
w_current->page_current->left = world_cx - (double) w_current->width
/ 2 / zoom_new + 0.5;
w_current->page_current->right = world_cx + (double) w_current->width
@@ -157,7 +144,7 @@
w_current->page_current->bottom = world_cy + (double) w_current->height
/ 2 / zoom_new + 0.5;
- /*and put it back to the borders */
+ /* and put it back to the borders */
if (!(flags & A_PAN_IGNORE_BORDERS)) {
/* check right border */
if (w_current->page_current->right > w_current->init_right) {
@@ -200,12 +187,6 @@
(float) fabs(w_current->page_current->bottom - w_current->page_current->top ));
#endif
- /* not used any longer because there are no rounding errors to fix*/
- /* correct aspect ratio */
- if (fix != 0) {
- correct_aspect(w_current);
- }
-
/* set_window */
set_window(w_current, w_current->page_current,
w_current->page_current->left ,
@@ -215,100 +196,14 @@
/* redraw */
if (!(flags & A_PAN_DONT_REDRAW)) {
- w_current->DONT_RECALC = 1;
- w_current->DONT_RESIZE = 1;
- w_current->DONT_REDRAW = 1;
- x_hscrollbar_update(w_current);
- x_vscrollbar_update(w_current);
+ x_scrollbars_update(w_current);
o_redraw_all_fast(w_current);
- w_current->DONT_REDRAW = 0;
- w_current->DONT_RECALC = 0;
- w_current->DONT_RESIZE = 0;
}
}
-
@ %def a_pan_general
-@section Function @code{a_pan_calc()}
-
-@defun a_pan_calc w_current x y
-@end defun
-
-<<a_pan.c : a_pan_calc()>>=
-void
-a_pan_calc(TOPLEVEL *w_current, int x, int y)
-{
- int pan_x, pan_y;
- int ix, iy, center_x, center_y;
-
- pan_x = mil_x(w_current, x);
- pan_y = mil_y(w_current, y);
-
- center_x = GET_PAGE_CENTER_X(w_current);
- center_y = GET_PAGE_CENTER_Y(w_current);
-
- ix = center_x - pan_x;
- if (w_current->page_current->right - ix > w_current->init_right) {
- /* the right wall was hit */
-
- w_current->page_current->left =
- w_current->init_right - GET_PAGE_WIDTH(w_current);
-
- w_current->page_current->right = w_current->init_right;
- } else if (w_current->page_current->left - ix < w_current->init_left) {
- /* the left wall was hit */
- w_current->page_current->right =
- w_current->init_left + GET_PAGE_WIDTH(w_current);
-
- w_current->page_current->left = w_current->init_left;
- } else {
- /* normal case */
- w_current->page_current->left -= ix;
- w_current->page_current->right -= ix;
- }
-
- iy = center_y - pan_y;
- if (w_current->page_current->bottom - iy > w_current->init_bottom) {
- /* the bottom wall was hit */
- w_current->page_current->top =
- w_current->init_bottom - GET_PAGE_HEIGHT(w_current);
-
- w_current->page_current->bottom = w_current->init_bottom;
- } else if (w_current->page_current->top - iy < w_current->init_top) {
- /* the top wall was hit */
- w_current->page_current->bottom =
- w_current->init_top + GET_PAGE_HEIGHT(w_current);
-
- w_current->page_current->top = w_current->init_top;
- } else {
- /* normal case */
- w_current->page_current->top -= iy;
- w_current->page_current->bottom -= iy;
- }
-
-#if DEBUG
- printf("left: %d, right: %d, top: %d, bottom: %d\n",
- w_current->page_current->left, w_current->page_current->right, w_current->page_current->top, w_current->page_current->bottom);
- printf("aspect: %f\n",
- (float) fabs(w_current->page_current->right - w_current->page_current->left) /
- (float) fabs(w_current->page_current->bottom - w_current->page_current->top ));
- printf("zoomfactor: %d\n", w_current->page_current->zoom_factor);
-#endif
-
- current_center_x = GET_PAGE_CENTER_X(w_current);
- current_center_y = GET_PAGE_CENTER_Y(w_current);
-
-#if DEBUG
- printf("%d %d\n", current_center_x, current_center_y);
-#endif
-}
-
-
-@ %def a_pan_calc
-
-
@section Function @code{a_pan()}
@defun a_pan w_current x y
@@ -321,17 +216,19 @@
a_pan(TOPLEVEL *w_current, int x, int y)
{
int sx, sy, lx, ly;
+ double world_cx, world_cy;
+#if DEBUG
+ printf("a_pan(): x=%d, y=%d\n", x, y);
+#endif
/* check to see if we are inside an action draw net, etc. If
* yes, convert screen coords to world coords */
if (w_current->inside_action) {
SCREENtoWORLD(w_current,
- w_current->start_x,
- w_current->start_y,
+ w_current->start_x, w_current->start_y,
&sx, &sy);
SCREENtoWORLD(w_current,
- w_current->last_x,
- w_current->last_y,
+ w_current->last_x, w_current->last_y,
&lx, &ly);
#if 0
@@ -340,46 +237,30 @@
printf("BEGIN: last x %d -> %d \n", w_current->last_x , lx);
printf("BEGIN: last y %d -> %d \n", w_current->last_y , ly);
#endif
- w_current->start_x = sx;
- w_current->start_y = sy;
- w_current->last_x = lx;
- w_current->last_y = ly;
- }
-
- /* do the actual work */
- a_pan_calc(w_current, x, y);
-
- w_current->DONT_RECALC = 1;
- w_current->DONT_RESIZE = 1;
- w_current->DONT_REDRAW = 1;
- x_hscrollbar_update(w_current);
- x_vscrollbar_update(w_current);
- w_current->DONT_REDRAW = 0;
- w_current->DONT_RECALC = 0;
- w_current->DONT_RESIZE = 0;
+ }
- o_redraw_all_fast(w_current);
+ /* make mouse to the new world-center;
+ attention: there are information looses because of type cast in mil_x */
+
+ world_cx = mil_x(w_current, x);
+ world_cy = mil_y(w_current, y);
+
+ a_pan_general(w_current, world_cx, world_cy, 1, 0);
- /* convert coords back to screen coords */
+ /* convert world coords back to screen coords */
if (w_current->inside_action) {
WORLDtoSCREEN(w_current,
- w_current->start_x,
- w_current->start_y,
- &sx, &sy);
+ sx, sy,
+ &(w_current->start_x), &(w_current->start_y));
WORLDtoSCREEN(w_current,
- w_current->last_x,
- w_current->last_y,
- &lx, &ly);
+ lx, ly,
+ &(w_current->last_x), &(w_current->last_y));
#if 0
printf("END: start x %d <- %d \n", sx, w_current->start_x);
printf("END: start y %d <- %d \n", sy, w_current->start_y);
printf("END: last x %d <- %d \n", lx, w_current->last_x );
printf("END: last y %d <- %d \n", ly, w_current->last_y );
#endif
- w_current->start_x = sx;
- w_current->start_y = sy;
- w_current->last_x = lx;
- w_current->last_y = ly;
}
/* not needed */
/* o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY); */
@@ -398,141 +279,25 @@
void
a_pan_mouse(TOPLEVEL *w_current, int diff_x, int diff_y)
{
- int pan_x, pan_y;
- int fix = 0;
+ int world_dx, world_dy;
+ double world_cx, world_cy;
- pan_x = WORLDabs(w_current, diff_x);
- pan_y = WORLDabs(w_current, diff_y);
-
-#if 0
- printf("inside pan: %d %d\n", pan_x, pan_y);
- printf("before: %d %d %d %d\n",
- w_current->page_current->left ,
- w_current->page_current->top ,
- w_current->page_current->right ,
- w_current->page_current->bottom);
-#endif
-
-#if 0
- w_current->page_current->right -= pan_x;
- w_current->page_current->left -= pan_x;
- w_current->page_current->top -= pan_y;
- w_current->page_current->bottom -= pan_y;
-#endif
-
- if (w_current->page_current->left - pan_x <=
- w_current->init_left) {
- w_current->page_current->left = w_current->init_left;
- /* the left wall was hit */
-#if DEBUG
- printf("LEFT\n");
-#endif
- fix++;
- } else {
- /* normal case */
- w_current->page_current->right -= pan_x;
#if DEBUG
- printf("left normal\n");
+ printf("a_pan_mouse(): diff_x=%d, diff_y=%d\n", diff_x, diff_y);
#endif
- }
- if (w_current->page_current->right - pan_x >=
- w_current->init_right) {
- /* the right wall was hit */
- w_current->page_current->right = w_current->init_right;
-#if DEBUG
- printf("RIGHT\n");
-#endif
- fix++;
- } else {
- /* normal case */
- w_current->page_current->left -= pan_x;
-#if DEBUG
- printf("right normal\n");
-#endif
- }
+ world_dx = WORLDabs(w_current, diff_x);
+ world_dy = WORLDabs(w_current, diff_y);
- if (w_current->page_current->top + pan_y <=
- w_current->init_top) {
- /* the top wall was hit */
- w_current->page_current->top = w_current->init_top;
-#if DEBUG
- printf("TOP\n");
-#endif
- fix++;
- } else {
- /* normal case */
- w_current->page_current->bottom += pan_y;
-#if DEBUG
- printf("top normal\n");
-#endif
- }
+ world_cx=GET_PAGE_CENTER_X(w_current) - world_dx;
+ world_cy=GET_PAGE_CENTER_Y(w_current) + world_dy;
- if (w_current->page_current->bottom + pan_y >=
- w_current->init_bottom) {
- /* the bottom wall was hit */
- w_current->page_current->bottom = w_current->init_bottom;
-#if DEBUG
- printf("BOTTOM\n");
-#endif
- fix++;
- } else {
- /* normal */
- w_current->page_current->top += pan_y;
#if DEBUG
- printf("bottom normal\n");
+ printf(" world_cx=%f, world_cy=%f, world_dx=%d, world_dy=%d\n",
+ world_cx, world_cy, world_dx, world_dy);
#endif
- }
-
- /* really bound the left */
- if (w_current->page_current->left < 0) {
- w_current->page_current->left = 0;
- fix++;
- }
-
- /* really bound the top */
- if (w_current->page_current->top < 0) {
- w_current->page_current->top = 0;
- fix++;
- }
-
- if (fix != 0) {
- correct_aspect(w_current);
- }
-
- set_window(w_current, w_current->page_current,
- w_current->page_current->left ,
- w_current->page_current->right ,
- w_current->page_current->top ,
- w_current->page_current->bottom);
-
-#if 0
- printf("after: %d %d %d %d\n",
- w_current->page_current->left ,
- w_current->page_current->top ,
- w_current->page_current->right ,
- w_current->page_current->bottom);
-#endif
-
- w_current->DONT_RECALC = 1;
- w_current->DONT_RESIZE = 1;
- w_current->DONT_REDRAW = 1;
- x_hscrollbar_update(w_current);
- x_vscrollbar_update(w_current);
- w_current->DONT_REDRAW = 0;
- w_current->DONT_RECALC = 0;
- w_current->DONT_RESIZE = 0;
-
- o_redraw_all_fast(w_current);
-#if DEBUG
- printf("left: %d, right: %d, top: %d, bottom: %d\n",
- w_current->page_current->left, w_current->page_current->right, w_current->page_current->top, w_current->page_current->bottom);
- printf("aspect: %f\n",
- (float) fabs(w_current->page_current->right - w_current->page_current->left) /
- (float) fabs(w_current->page_current->bottom - w_current->page_current->top ));
- printf("zoomfactor: %d\n", w_current->page_current->zoom_factor);
-#endif
+ a_pan_general(w_current, world_cx, world_cy, 1, 0);
}
1.9 +2 -3 eda/geda/devel/gschem/noweb/a_zoom.nw
(In the diff below, changes in quantity of whitespace are not shown.)
Index: a_zoom.nw
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/a_zoom.nw,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- a_zoom.nw 4 Feb 2005 04:39:29 -0000 1.8
+++ a_zoom.nw 9 Apr 2006 08:11:36 -0000 1.9
@@ -111,7 +111,7 @@
@end defun
<<a_zoom.c : a_zoom()>>=
-/* dir is either ZOOM_IN or ZOOM_OUT which are defined in globals.h */
+/* dir is either ZOOM_IN, ZOOM_OUT or ZOOM_FULL which are defined in globals.h */
void
a_zoom(TOPLEVEL *w_current, int dir, int selected_from, int pan_flags)
{
@@ -173,7 +173,6 @@
case(ZOOM_FULL):
/*hope someone have a better idea (hw)*/
relativ_zoom_factor = -1;
-
break;
}
1.47 +12 -16 eda/geda/devel/gschem/noweb/i_callbacks.nw
(In the diff below, changes in quantity of whitespace are not shown.)
Index: i_callbacks.nw
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/i_callbacks.nw,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- i_callbacks.nw 11 Jan 2006 14:48:06 -0000 1.46
+++ i_callbacks.nw 9 Apr 2006 08:11:36 -0000 1.47
@@ -1802,8 +1802,7 @@
exit_if_null(w_current);
/* scroll bar stuff */
- a_zoom(w_current, ZOOM_FULL, DONTCARE, A_PAN_DONT_REDRAW);
- o_redraw_all_fast(w_current);
+ a_zoom(w_current, ZOOM_FULL, DONTCARE, 0);
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
@@ -1825,9 +1824,7 @@
exit_if_null(w_current);
/* scroll bar stuff */
- a_zoom_extents(w_current, w_current->page_current->object_head,
- A_PAN_DONT_REDRAW);
- o_redraw_all_fast(w_current);
+ a_zoom_extents(w_current, w_current->page_current->object_head, 0);
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
@@ -1894,7 +1891,6 @@
exit_if_null(w_current);
a_zoom(w_current, ZOOM_IN, MENU, 0);
- o_redraw_all_fast(w_current);
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
@@ -1916,7 +1912,6 @@
exit_if_null(w_current);
a_zoom(w_current, ZOOM_OUT, MENU, 0);
- o_redraw_all_fast(w_current);
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
@@ -1939,7 +1934,6 @@
exit_if_null(w_current);
a_zoom(w_current, ZOOM_IN, HOTKEY, 0);
- o_redraw_all_fast(w_current);
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
@@ -1961,7 +1955,6 @@
exit_if_null(w_current);
a_zoom(w_current, ZOOM_OUT, HOTKEY, 0);
- o_redraw_all_fast(w_current);
o_undo_savestate(w_current, UNDO_VIEWPORT_ONLY);
}
@@ -3786,6 +3779,7 @@
w_current->page_current->object_head,
A_PAN_DONT_REDRAW);
o_redraw_all(w_current);
+ x_scrollbars_update(w_current);
x_pagesel_update (w_current);
i_update_menus(w_current);
}
@@ -3827,6 +3821,7 @@
a_zoom_extents(w_current,
w_current->page_current->object_head,
A_PAN_DONT_REDRAW);
+ x_scrollbars_update(w_current);
o_undo_savestate(w_current, UNDO_ALL);
o_redraw_all(w_current);
x_pagesel_update (w_current);
@@ -3854,6 +3849,7 @@
s_hierarchy_up(w_current, w_current->page_current->up);
i_set_filename(w_current, w_current->page_current->page_filename);
+ x_scrollbars_update(w_current);
o_redraw_all(w_current);
x_pagesel_update (w_current);
i_update_menus(w_current);
1.43 +4 -6 eda/geda/devel/gschem/noweb/o_misc.nw
(In the diff below, changes in quantity of whitespace are not shown.)
Index: o_misc.nw
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/o_misc.nw,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -b -r1.42 -r1.43
--- o_misc.nw 25 Feb 2006 15:00:58 -0000 1.42
+++ o_misc.nw 9 Apr 2006 08:11:36 -0000 1.43
@@ -1154,7 +1154,7 @@
correct_aspect(w_current);
#endif
- a_zoom(w_current, ZOOM_FULL, HOTKEY, A_PAN_DONT_REDRAW);
+ a_zoom(w_current, ZOOM_FULL, DONTCARE, A_PAN_DONT_REDRAW);
text_screen_height = SCREENabs(w_current,
o_text_height(o_current->
text->string,
@@ -1164,17 +1164,15 @@
/* 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, HOTKEY, A_PAN_DONT_REDRAW);
- a_pan_general(w_current, o_current->text->x, o_current->text->y,
- 1, A_PAN_DONT_REDRAW);
+ a_zoom(w_current, ZOOM_IN, DONTCARE, A_PAN_DONT_REDRAW);
text_screen_height = SCREENabs(w_current,
o_text_height(o_current->
text->string,
o_current->
text->size));
}
- x_scrollbars_update(w_current);
- o_redraw_all_fast(w_current);
+ a_pan_general(w_current, o_current->text->x, o_current->text->y,
+ 1, 0);
last_o = o_current;
break;
1.21 +5 -3 eda/geda/devel/gschem/noweb/x_event.nw
(In the diff below, changes in quantity of whitespace are not shown.)
Index: x_event.nw
===================================================================
RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/x_event.nw,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- x_event.nw 20 Aug 2005 02:15:58 -0000 1.20
+++ x_event.nw 9 Apr 2006 08:11:36 -0000 1.21
@@ -1266,7 +1266,7 @@
w_current->page_current->right) /2;
cy = (double) (w_current->page_current->top +
w_current->page_current->bottom) /2;
- a_pan_general(w_current, cx, cy, 1.0, 6);
+ a_pan_general(w_current, cx, cy, 1.0, A_PAN_DONT_REDRAW);
if (w_current->backingstore) {
@@ -1277,8 +1277,10 @@
widget->allocation.width,
widget->allocation.height,
-1);
- if (!w_current->DONT_REDRAW)
+ if (!w_current->DONT_REDRAW) {
o_redraw_all_fast(w_current);
+ x_scrollbars_update(w_current);
+ }
return(0);
}