fix some positioning glithes in UI when placing text via bindkey or menu or context menu

This commit is contained in:
Stefan Frederik 2021-11-06 03:24:45 +01:00
parent 173450edde
commit 7985e8d22c
4 changed files with 44 additions and 31 deletions

View File

@ -2234,7 +2234,7 @@ int text_bbox(const char *str,double xscale, double yscale,
return 1;
}
void place_text(int draw_text, double mx, double my)
int place_text(int draw_text, double mx, double my)
{
char *txt;
int textlayer;
@ -2257,7 +2257,7 @@ void place_text(int draw_text, double mx, double my)
dbg(1, "place_text(): hsize=%s vsize=%s\n",tclgetvar("hsize"), tclgetvar("vsize") );
txt = (char *)tclgetvar("retval");
if(!strcmp(txt,"")) return; /* dont allocate text object if empty string given */
if(!strcmp(txt,"")) return 0; /* dont allocate text object if empty string given */
push_undo();
check_text_storage();
t->txt_ptr=NULL;
@ -2329,6 +2329,7 @@ void place_text(int draw_text, double mx, double my)
drawtemprect(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0);
drawtempline(gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0);
set_modify(1);
return 1;
}
void pan2(int what, int mx, int my)

View File

@ -324,29 +324,34 @@ int callback(int event, int mx, int my, KeySym key,
select_rect(START,1);
onetime=1;
}
if(abs(mx-xctx->mx_save) > 8 || abs(my-xctx->my_save) > 8 ) { /* set some reasonable threshold before unselecting */
if(abs(mx-xctx->mx_save) > 8 ||
abs(my-xctx->my_save) > 8 ) { /* set reasonable threshold before unsel */
if(onetime) {
unselect_all(); /* 20171026 avoid multiple calls of unselect_all() */
onetime=0;
}
xctx->ui_state|=STARTSELECT; /* set it again cause unselect_all() clears it... 20121123 */
xctx->ui_state|=STARTSELECT; /* set it again cause unselect_all() clears it... */
}
}
}
if((state & Button1Mask) && (state & Mod1Mask) && !(state & ShiftMask) &&
!(xctx->ui_state & STARTPAN2) && !(xctx->ui_state & (PLACE_SYMBOL | PLACE_TEXT))) { /* 20150927 unselect area */
!(xctx->ui_state & STARTPAN2) &&
!(xctx->ui_state & (PLACE_SYMBOL | PLACE_TEXT))) { /* unselect area */
if( !(xctx->ui_state & STARTSELECT)) {
select_rect(START,0);
}
}
else if((state&Button1Mask) && (state & ShiftMask) && !(xctx->ui_state & (PLACE_SYMBOL | PLACE_TEXT)) &&
else if((state&Button1Mask) && (state & ShiftMask) &&
!(xctx->ui_state & (PLACE_SYMBOL | PLACE_TEXT)) &&
!(xctx->ui_state & STARTPAN2) ) {
if(mx != xctx->mx_save || my != xctx->my_save) {
if( !(xctx->ui_state & STARTSELECT)) {
select_rect(START,1);
}
if(abs(mx-xctx->mx_save) > 8 || abs(my-xctx->my_save) > 8 ) { /* set some reasonable threshold before unselecting */
select_object(X_TO_XSCHEM(xctx->mx_save), Y_TO_XSCHEM(xctx->my_save), 0, 0); /* remove near object if dragging */
if(abs(mx-xctx->mx_save) > 8 ||
abs(my-xctx->my_save) > 8 ) { /* set reasonable threshold before unsel */
select_object(X_TO_XSCHEM(xctx->mx_save),
Y_TO_XSCHEM(xctx->my_save), 0, 0); /* remove near obj if dragging */
rebuild_selected_array();
}
}
@ -731,12 +736,14 @@ int callback(int event, int mx, int my, KeySym key,
{
if(xctx->semaphore >= 2) break;
xctx->last_command = 0;
xctx->ui_state |= PLACE_TEXT;
place_text(0, xctx->mousex_snap, xctx->mousey_snap); /* 1 = draw text 24122002 */
xctx->mx_save = mx; xctx->my_save = my;
xctx->mx_double_save=xctx->mousex_snap;
xctx->my_double_save=xctx->mousey_snap;
move_objects(START,0,0,0);
xctx->mx_double_save = xctx->mousex_snap;
xctx->my_double_save = xctx->mousey_snap;
if(place_text(0, xctx->mousex_snap, xctx->mousey_snap)) { /* 1 = draw text 24122002 */
xctx->mousey_snap = xctx->my_double_save;
xctx->mousex_snap = xctx->mx_double_save;
move_objects(START,0,0,0);
xctx->ui_state |= PLACE_TEXT;
}
break;
}
if(key=='r' && !xctx->ui_state && state==0) /* start rect */
@ -1509,13 +1516,16 @@ int callback(int event, int mx, int my, KeySym key,
xctx->last_command = 0;
new_polygon(PLACE);
break;
case 6:
case 6: /* place text */
xctx->last_command = 0;
place_text(0, xctx->mousex_snap, xctx->mousey_snap); /* 1 = draw text */
xctx->mx_save = mx; xctx->my_save = my;
xctx->mx_double_save=xctx->mousex_snap;
xctx->my_double_save=xctx->mousey_snap;
move_objects(START,0,0,0);
if(place_text(0, xctx->mousex_snap, xctx->mousey_snap)) { /* 1 = draw text */
xctx->mousey_snap = xctx->my_double_save;
xctx->mousex_snap = xctx->mx_double_save;
move_objects(START,0,0,0);
xctx->ui_state |= PLACE_TEXT;
}
break;
case 7: /* cut selection into clipboard */
rebuild_selected_array();
@ -1644,11 +1654,6 @@ int callback(int event, int mx, int my, KeySym key,
if(xctx->last_command == STARTWIRE) start_wire(mx, my);
break;
}
if(xctx->ui_state & MENUSTARTTEXT) {
place_text(1, xctx->mousex_snap, xctx->mousey_snap);
xctx->ui_state &=~MENUSTARTTEXT;
break;
}
if(xctx->ui_state & MENUSTARTWIRE) {
xctx->mx_save = mx; xctx->my_save = my;
xctx->mx_double_save=xctx->mousex_snap;

View File

@ -1666,13 +1666,12 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
} else if(argc == 3) {
ret = place_symbol(-1,argv[2],xctx->mousex_snap, xctx->mousey_snap, 0, 0, NULL, 4, 1, 1/*to_push_undo*/);
} else {
#if 1 /* enable on request also in callback.c */
xctx->last_command = 0;
rebuild_selected_array();
if(xctx->lastsel && xctx->sel_array[0].type==ELEMENT) {
Tcl_VarEval(interp, "set INITIALINSTDIR [file dirname {",
abs_sym_path(xctx->inst[xctx->sel_array[0].n].name, ""), "}]", NULL);
}
#endif
ret = place_symbol(-1,NULL,xctx->mousex_snap, xctx->mousey_snap, 0, 0, NULL, 4, 1, 1/*to_push_undo*/);
}
@ -1689,9 +1688,18 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
else if(!strcmp(argv[1],"place_text"))
{
cmd_found = 1;
xctx->ui_state |= MENUSTARTTEXT;
/* place_text(0,xctx->mousex_snap, xctx->mousey_snap); */
/* move_objects(START,0,0,0); */
xctx->semaphore++;
xctx->last_command = 0;
xctx->mx_double_save = xctx->mousex_snap;
xctx->my_double_save = xctx->mousey_snap;
if(place_text(0, xctx->mousex_snap, xctx->mousey_snap)) { /* 1 = draw text 24122002 */
xctx->mousey_snap = xctx->my_double_save;
xctx->mousex_snap = xctx->mx_double_save;
move_objects(START,0,0,0);
xctx->ui_state |= PLACE_TEXT;
}
xctx->semaphore--;
Tcl_ResetResult(interp);
}

View File

@ -191,7 +191,7 @@ extern char win_temp_dir[PATH_MAX];
#define MENUSTARTRECT 4096 /* start rect invoked from menu */
#define MENUSTARTZOOM 8192 /* start zoom box invoked from menu */
#define STARTPAN2 16384 /* new pan method with mouse button3 */
#define MENUSTARTTEXT 32768 /* 20161201 click to place text if action starts from menu */
#define PLACE_TEXT 32768
#define MENUSTARTSNAPWIRE 65536 /* start wire invoked from menu, snap to pin variant 20171022 */
#define STARTPOLYGON 131072
#define MENUSTARTPOLYGON 262144
@ -200,7 +200,6 @@ extern char win_temp_dir[PATH_MAX];
#define MENUSTARTCIRCLE 2097152
#define PLACE_SYMBOL 4194304 /* used in move_objects after place_symbol to avoid storing intermediate undo state */
#define START_SYMPIN 8388608
#define PLACE_TEXT 16777216
#define SELECTED 1 /* used in the .sel field for selected objs. */
#define SELECTED1 2 /* first point selected... */
#define SELECTED2 4 /* second point selected... */
@ -1050,7 +1049,7 @@ extern const char *tclgetvar(const char *s);
extern void tclsetvar(const char *s, const char *value);
extern const char *tcl_hook2(char **res);
extern void statusmsg(char str[],int n);
extern void place_text(int draw_text, double mx, double my);
extern int place_text(int draw_text, double mx, double my);
extern void init_inst_iterator(struct iterator_ctx *ctx, double x1, double y1, double x2, double y2);
extern struct instentry *inst_iterator_next(struct iterator_ctx *ctx);
extern void init_wire_iterator(struct iterator_ctx *ctx, double x1, double y1, double x2, double y2);