From 69fa323b708bc5784a475a0911d1c100927edab8 Mon Sep 17 00:00:00 2001 From: Werner Hoch Date: Thu, 17 Apr 2008 23:08:20 +0200 Subject: [PATCH] switch complex copy and complex place to world coords switched all functions to world coords. The temporary calculation of the world coords can be removed now, as all complex objects are in world coords now. --- gschem/src/i_callbacks.c | 19 ++++--------------- gschem/src/o_basic.c | 14 ++------------ gschem/src/o_buffer.c | 7 ++++--- gschem/src/o_complex.c | 36 +++++++++++------------------------- gschem/src/o_copy.c | 27 +++++---------------------- gschem/src/x_event.c | 37 ++++++++++++------------------------- 6 files changed, 38 insertions(+), 102 deletions(-) diff --git a/gschem/src/i_callbacks.c b/gschem/src/i_callbacks.c index 0578285d8..187ccb3a7 100644 --- a/gschem/src/i_callbacks.c +++ b/gschem/src/i_callbacks.c @@ -610,7 +610,7 @@ DEFINE_I_CALLBACK(edit_copy_hotkey) if (o_select_return_first_object(w_current)) { o_redraw_cleanstates(w_current); w_current->event_state = COPY; - o_copy_start(w_current, mouse_x, mouse_y); + o_copy_start(w_current, mouse_wx, mouse_wy); w_current->event_state = ENDCOPY; w_current->inside_action = 1; } @@ -651,7 +651,7 @@ DEFINE_I_CALLBACK(edit_mcopy_hotkey) if (o_select_return_first_object(w_current)) { o_redraw_cleanstates(w_current); w_current->event_state = MCOPY; - o_copy_start(w_current, mouse_x, mouse_y); + o_copy_start(w_current, mouse_wx, mouse_wy); w_current->event_state = ENDMCOPY; w_current->inside_action = 1; } @@ -843,7 +843,6 @@ DEFINE_I_CALLBACK(edit_rotate_90_hotkey) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; GList *object_list; - int w_x, w_y; exit_if_null(w_current); @@ -880,11 +879,7 @@ DEFINE_I_CALLBACK(edit_rotate_90_hotkey) i_callback_edit_rotate_90_hotkey, _("Rotate")); /* Allow o_rotate_world_update to redraw the objects */ w_current->toplevel->DONT_REDRAW = 0; - SCREENtoWORLD( w_current->toplevel, mouse_x, mouse_y, &w_x, &w_y ); - w_x = snap_grid(w_current->toplevel, w_x); - w_y = snap_grid(w_current->toplevel, w_y); - - o_rotate_world_update(w_current, w_x, w_y, 90, object_list); + o_rotate_world_update(w_current, mouse_wx, mouse_wy, 90, object_list); } w_current->event_state = SELECT; @@ -916,7 +911,6 @@ DEFINE_I_CALLBACK(edit_mirror_hotkey) { GSCHEM_TOPLEVEL *w_current = (GSCHEM_TOPLEVEL*) data; GList *object_list; - int w_x, w_y; exit_if_null(w_current); @@ -927,12 +921,7 @@ DEFINE_I_CALLBACK(edit_mirror_hotkey) if (object_list) { i_update_middle_button(w_current, i_callback_edit_mirror_hotkey, _("Mirror")); - - SCREENtoWORLD( w_current->toplevel, mouse_x, mouse_y, &w_x, &w_y ); - w_x = snap_grid(w_current->toplevel, w_x); - w_y = snap_grid(w_current->toplevel, w_y); - - o_mirror_world_update(w_current, w_x, w_y, object_list); + o_mirror_world_update(w_current, mouse_wx, mouse_wy, object_list); } w_current->event_state = SELECT; diff --git a/gschem/src/o_basic.c b/gschem/src/o_basic.c index ecca6cff6..0da381d85 100644 --- a/gschem/src/o_basic.c +++ b/gschem/src/o_basic.c @@ -366,18 +366,6 @@ void o_drawbounding(GSCHEM_TOPLEVEL *w_current, GList *o_glist, return; } - /* BUG: temporary fix while switching to world corrds */ - if (!(w_current->event_state == MOVE) - && !(w_current->event_state == ENDMOVE) - && !(w_current->event_state == DRAWTEXT) - && !(w_current->event_state == ENDTEXT) - && !(w_current->event_state == ENDPASTE)) { - SCREENtoWORLD(toplevel, w_current->start_x, w_current->start_y, - &(w_current->first_wx), &(w_current->first_wy)); - SCREENtoWORLD(toplevel, w_current->last_x, w_current->last_y, - &(w_current->second_wx), &(w_current->second_wy)); - } - /* If drawing is true, then don't worry about the previous drawing * method and movement constraints, use with the current settings */ if (drawing) { @@ -394,8 +382,10 @@ void o_drawbounding(GSCHEM_TOPLEVEL *w_current, GList *o_glist, if (w_current->drawbounding_action_mode == CONSTRAINED ) { if (abs(diff_x) >= abs(diff_y)) { w_current->second_wy = w_current->first_wy; + diff_y = 0; } else { w_current->second_wx = w_current->first_wx; + diff_x = 0; } } diff --git a/gschem/src/o_buffer.c b/gschem/src/o_buffer.c index c0b9be124..408a212ab 100644 --- a/gschem/src/o_buffer.c +++ b/gschem/src/o_buffer.c @@ -162,13 +162,14 @@ void o_buffer_paste_end(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y, o_drawbounding(w_current, object_buffer[buf_num], x_get_darkcolor(w_current->bb_color), FALSE); -#if DEBUG - printf("%d %d\n", w_x - w_start_x, w_y - w_start_y); -#endif /* calc and translate objects to their final position */ w_diff_x = w_current->second_wx - w_current->first_wx; w_diff_y = w_current->second_wy - w_current->first_wy; +#if DEBUG + printf("%d %d\n", w_diff_x, w_diff_y); +#endif + toplevel->ADDING_SEL = 1; o_glist_translate_world(toplevel, w_diff_x, w_diff_y, object_buffer[buf_num]); diff --git a/gschem/src/o_complex.c b/gschem/src/o_complex.c index dc7c284e0..5b235a03d 100644 --- a/gschem/src/o_complex.c +++ b/gschem/src/o_complex.c @@ -70,32 +70,24 @@ void o_complex_draw_xor(GSCHEM_TOPLEVEL *w_current, int dx, int dy, OBJECT *obje * \par Function Description * */ -void o_complex_start(GSCHEM_TOPLEVEL *w_current, int screen_x, int screen_y) +void o_complex_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y) { TOPLEVEL *toplevel = w_current->toplevel; - int x, y; int i, temp; const CLibSymbol *sym; int redraw_state; - w_current->last_x = w_current->start_x = fix_x(toplevel, screen_x); - w_current->last_y = w_current->start_y = fix_y(toplevel, screen_y); - + w_current->first_wx = w_current->second_wx = w_x; + w_current->first_wy = w_current->second_wy = w_y; w_current->last_drawb_mode = -1; /* make sure list is null first, so that you don't have a mem * leak */ - SCREENtoWORLD(toplevel, - w_current->start_x, - w_current->start_y, - &x, - &y); - toplevel->ADDING_SEL = 1; /* reuse this flag, rename later hack */ sym = s_clib_get_symbol_by_name (toplevel->internal_symbol_name); o_complex_add(toplevel, NULL, &(toplevel->page_current->complex_place_list), - OBJ_COMPLEX, WHITE, x, y, 0, 0, + OBJ_COMPLEX, WHITE, w_x, w_y, 0, 0, sym, toplevel->internal_symbol_name, 1, TRUE); toplevel->ADDING_SEL = 0; @@ -199,11 +191,9 @@ void o_complex_place_rotate(GSCHEM_TOPLEVEL *w_current) * \par Function Description * */ -void o_complex_end(GSCHEM_TOPLEVEL *w_current, int screen_x, int screen_y) +void o_complex_end(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y) { TOPLEVEL *toplevel = w_current->toplevel; - int diff_x, diff_y; - int x, y; OBJECT *o_current; OBJECT *o_start; OBJECT *o_temp; @@ -212,18 +202,14 @@ void o_complex_end(GSCHEM_TOPLEVEL *w_current, int screen_x, int screen_y) GList *connected_objects=NULL; const CLibSymbol *sym; - diff_x = w_current->last_x - w_current->start_x; - diff_y = w_current->last_y - w_current->start_y; - - SCREENtoWORLD(toplevel, screen_x, screen_y, &x, &y); - x = snap_grid(toplevel, x); - y = snap_grid(toplevel, y); - #if DEBUG printf("place_basename: %s\n",internal_basename); printf("place_clib: %s\n",internal_clib); #endif + w_current->second_wx = w_x; + w_current->second_wy = w_y; + o_drawbounding(w_current, w_current->toplevel->page_current->complex_place_list, x_get_darkcolor(w_current->bb_color), FALSE); @@ -241,7 +227,7 @@ void o_complex_end(GSCHEM_TOPLEVEL *w_current, int screen_x, int screen_y) o_start = o_start->next; toplevel->ADDING_SEL=0; - o_list_translate_world(toplevel, x, y, o_start); + o_list_translate_world(toplevel, w_x, w_y, o_start); o_temp = o_start; while (o_temp != NULL) { @@ -275,7 +261,7 @@ void o_complex_end(GSCHEM_TOPLEVEL *w_current, int screen_x, int screen_y) toplevel->page_current->object_tail = o_complex_add(toplevel, toplevel->page_current->object_tail, NULL, - OBJ_COMPLEX, WHITE, x, y, w_current->complex_rotate, 0, + OBJ_COMPLEX, WHITE, w_x, w_y, w_current->complex_rotate, 0, sym, toplevel->internal_symbol_name, 1, TRUE); @@ -286,7 +272,7 @@ void o_complex_end(GSCHEM_TOPLEVEL *w_current, int screen_x, int screen_y) case(OBJ_TEXT): temp = w_current->complex_rotate / 90; for (i = 0; i < temp; i++) { - o_text_rotate_world(toplevel, x, y, 90, o_temp); + o_text_rotate_world(toplevel, w_x, w_y, 90, o_temp); } break; } diff --git a/gschem/src/o_copy.c b/gschem/src/o_copy.c index 08c31d985..26251ebae 100644 --- a/gschem/src/o_copy.c +++ b/gschem/src/o_copy.c @@ -37,7 +37,7 @@ * \par Function Description * */ -void o_copy_start(GSCHEM_TOPLEVEL *w_current, int x, int y) +void o_copy_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y) { TOPLEVEL *toplevel = w_current->toplevel; if (geda_list_get_glist( toplevel->page_current->selection_list ) != NULL) { @@ -49,15 +49,11 @@ void o_copy_start(GSCHEM_TOPLEVEL *w_current, int x, int y) o_undo_savestate(w_current, UNDO_ALL); #endif - /* Shouldn't this set by the caller ? */ - /* w_current->event_state = COPY; */ - - w_current->last_x = w_current->start_x = fix_x(toplevel, x); - w_current->last_y = w_current->start_y = fix_y(toplevel, y); + w_current->first_wx = w_current->second_wx = w_x; + w_current->first_wy = w_current->second_wy = w_y; o_drawbounding(w_current, geda_list_get_glist( toplevel->page_current->selection_list ), x_get_darkcolor(w_current->bb_color), TRUE); - w_current->inside_action = 1; } } @@ -78,8 +74,6 @@ void o_copy_end(GSCHEM_TOPLEVEL *w_current) OBJECT *new_objects_head = NULL; OBJECT *object; int diff_x, diff_y; - int lx, ly; - int sx, sy; int color; /* int redraw_state; not needed for now */ @@ -92,19 +86,8 @@ void o_copy_end(GSCHEM_TOPLEVEL *w_current) return; } - SCREENtoWORLD(toplevel, - w_current->last_x, w_current->last_y, - &lx, &ly); - SCREENtoWORLD(toplevel, - w_current->start_x, w_current->start_y, - &sx, &sy); - lx = snap_grid(toplevel,lx); - ly = snap_grid(toplevel,ly); - sx = snap_grid(toplevel,sx); - sy = snap_grid(toplevel,sy); - - diff_x = lx - sx; - diff_y = ly - sy; + diff_x = w_current->second_wx - w_current->first_wx; + diff_y = w_current->second_wy - w_current->first_wy; /* erase the bounding box */ o_drawbounding(w_current, diff --git a/gschem/src/x_event.c b/gschem/src/x_event.c index bd903a3ce..263ebb6b9 100644 --- a/gschem/src/x_event.c +++ b/gschem/src/x_event.c @@ -152,8 +152,7 @@ gint x_event_button_pressed(GtkWidget *widget, GdkEventButton *event, case(STARTCOPY): if (o_select_selected(w_current)) { w_current->rotated_inside = 0; - o_copy_start(w_current, - (int) event->x, (int) event->y); + o_copy_start(w_current, w_x, w_y); w_current->event_state = COPY; w_current->inside_action = 1; } @@ -162,8 +161,7 @@ gint x_event_button_pressed(GtkWidget *widget, GdkEventButton *event, case(STARTMCOPY): if (o_select_selected(w_current)) { w_current->rotated_inside = 0; - o_copy_start(w_current, - (int) event->x, (int) event->y); + o_copy_start(w_current, w_x, w_y); w_current->event_state = MCOPY; w_current->inside_action = 1; } @@ -296,18 +294,11 @@ gint x_event_button_pressed(GtkWidget *widget, GdkEventButton *event, break; case(ENDCOMP): - o_complex_end(w_current, - fix_x(toplevel, (int) event->x), - fix_y(toplevel, (int) event->y)); - /* not sure on this one */ - /* probably keep this one */ - + o_complex_end(w_current, w_x, w_y); o_redraw_single(w_current, toplevel->page_current-> object_tail); if (w_current->continue_component_place) { - o_complex_start(w_current, - (int) event->x, - (int) event->y); + o_complex_start(w_current, w_x, w_y); } else { w_current->inside_action = 0; i_set_state(w_current, SELECT); @@ -430,9 +421,7 @@ gint x_event_button_pressed(GtkWidget *widget, GdkEventButton *event, } if (w_current->ALTKEY) { - o_copy_start(w_current, - (int) event->x, - (int) event->y); + o_copy_start(w_current, w_x, w_y); w_current->inside_action = 1; i_set_state(w_current, COPY); } else { @@ -621,8 +610,8 @@ gint x_event_button_released(GtkWidget *widget, GdkEventButton *event, /* having this stay in copy was driving me nuts*/ w_current->inside_action = 1; /* Keep the state and the inside_action, as the copy has not finished. */ - w_current->last_x = w_current->start_x = fix_x(toplevel, mouse_x); - w_current->last_y = w_current->start_y = fix_y(toplevel, mouse_y); + w_current->first_wx = w_current->second_wx = w_x; + w_current->first_wy = w_current->second_wy = w_y; o_drawbounding(w_current, geda_list_get_glist(toplevel->page_current->selection_list), x_get_darkcolor(w_current->bb_color), TRUE); @@ -961,8 +950,8 @@ gint x_event_motion(GtkWidget *widget, GdkEventMotion *event, o_drawbounding(w_current, geda_list_get_glist( toplevel->page_current->selection_list ), x_get_darkcolor(w_current->bb_color), FALSE); - w_current->last_x = fix_x(toplevel, (int) event->x); - w_current->last_y = fix_y(toplevel, (int) event->y); + w_current->second_wx = w_x; + w_current->second_wy = w_y; o_drawbounding(w_current, geda_list_get_glist( toplevel->page_current->selection_list ), x_get_darkcolor(w_current->bb_color), TRUE); @@ -1020,17 +1009,15 @@ gint x_event_motion(GtkWidget *widget, GdkEventMotion *event, case(DRAWCOMP): w_current->complex_rotate = 0; /* reset to known state */ - o_complex_start(w_current, - (int) event->x, - (int) event->y); + o_complex_start(w_current, w_x, w_y); w_current->event_state = ENDCOMP; w_current->inside_action = 1; break; case(ENDCOMP): o_complex_rubbercomplex(w_current); - w_current->last_x = fix_x(toplevel, (int) event->x); - w_current->last_y = fix_y(toplevel, (int) event->y); + w_current->second_wx = w_x; + w_current->second_wy = w_y; o_complex_rubbercomplex(w_current); break; -- 2.11.4.GIT