refactoring and cleanup of wave_callback() -4-

This commit is contained in:
stefan schippers 2025-01-09 00:17:55 +01:00
parent ed9dc9b211
commit 7d7b381b7b
1 changed files with 347 additions and 370 deletions

View File

@ -842,345 +842,151 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
dbg(1, "%g %g %g %g - %d %d\n", gr->gx1, gr->gy1, gr->gx2, gr->gy2, gr->divx, gr->divy);
if( event == KeyPress || event == ButtonPress || event == MotionNotify ) {
if(event == MotionNotify && (state & Button1Mask) && !xctx->graph_bottom &&
!(xctx->graph_flags & (16 | 32 | 512 | 1024))) {
double delta;
/* vertical move of waveforms */
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
delta = gr->posh;
delta_threshold = 0.01;
if(fabs(xctx->my_double_save - xctx->mousey_snap) > fabs(gr->dcy * delta) * delta_threshold) {
yy1 = gr->ypos1 + (xctx->my_double_save - xctx->mousey_snap) / gr->dcy;
yy2 = gr->ypos2 + (xctx->my_double_save - xctx->mousey_snap) / gr->dcy;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
xctx->my_double_save = xctx->mousey_snap;
need_redraw = 1;
}
} else {
delta = gr->gh / gr->divy;
delta_threshold = 0.01;
if(fabs(xctx->my_double_save - xctx->mousey_snap) > fabs(gr->cy * delta) * delta_threshold) {
yy1 = gr->gy1 + (xctx->my_double_save - xctx->mousey_snap) / gr->cy;
yy2 = gr->gy2 + (xctx->my_double_save - xctx->mousey_snap) / gr->cy;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
xctx->my_double_save = xctx->mousey_snap;
need_redraw = 1;
}
}
}
}
/* horizontal move of waveforms */
else {
save_mouse_at_end = 1;
delta = gr->gw;
delta_threshold = 0.01;
/* selected or locked or master */
if( r->sel || !(r->flags & 2) || i == xctx->graph_master) {
dbg(1, "moving waves: %d\n", i);
if(fabs(xctx->mx_double_save - xctx->mousex_snap) > fabs(gr->cx * delta) * delta_threshold) {
xx1 = gr->gx1 + (xctx->mx_double_save - xctx->mousex_snap) / gr->cx;
xx2 = gr->gx2 + (xctx->mx_double_save - xctx->mousex_snap) / gr->cx;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
}
else if(event == ButtonPress && button == Button3) {
/* Numerically set hcursor position */
if(xctx->graph_flags & 128) {
double cursor;
cursor = gr->hcursor1_y;
if(gr->logy ) {
cursor = mylog10(cursor);
}
if(fabs(xctx->mousey - W_Y(cursor)) < 10) {
xctx->ui_state &= ~GRAPHPAN; /* we are setting a cursor so clear GRAPHPAN set before */
tclvareval("input_line {Pos:} {} ", dtoa_eng(cursor), NULL);
cursor = atof_spice(tclresult());
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor1_y", dtoa(cursor)));
}
need_redraw = 1;
}
/* Numerically set hcursor position */
if(xctx->graph_flags & 256) {
double cursor;
cursor = gr->hcursor2_y;
if(gr->logy ) {
cursor = mylog10(cursor);
}
if(fabs(xctx->mousey - W_Y(cursor)) < 10) {
xctx->ui_state &= ~GRAPHPAN; /* we are setting a cursor so clear GRAPHPAN set before */
tclvareval("input_line {Pos:} {} ", dtoa_eng(cursor), NULL);
cursor = atof_spice(tclresult());
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor2_y", dtoa(cursor)));
}
need_redraw = 1;
}
}
else if(event == ButtonPress && button == Button5 && !(state & ShiftMask)) {
double delta;
/* vertical move of waveforms with mouse wheel */
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
delta = gr->posh * 0.05;
yy1 = gr->ypos1 + delta;
yy2 = gr->ypos2 + delta;
if(event == MotionNotify && (state & Button1Mask) && !xctx->graph_bottom &&
!(xctx->graph_flags & (16 | 32 | 512 | 1024))) {
double delta;
/* vertical move of waveforms */
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
delta = gr->posh;
delta_threshold = 0.01;
if(fabs(xctx->my_double_save - xctx->mousey_snap) > fabs(gr->dcy * delta) * delta_threshold) {
yy1 = gr->ypos1 + (xctx->my_double_save - xctx->mousey_snap) / gr->dcy;
yy2 = gr->ypos2 + (xctx->my_double_save - xctx->mousey_snap) / gr->dcy;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
need_redraw = 1;
} else {
delta = gr->gh/ gr->divy;
delta_threshold = 1.0;
yy1 = gr->gy1 + delta * delta_threshold;
yy2 = gr->gy2 + delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
xctx->my_double_save = xctx->mousey_snap;
need_redraw = 1;
}
}
}
/* horizontal move of waveforms with mouse wheel */
else {
/* selected or locked or master */
if( r->sel || !(r->flags & 2) || i == xctx->graph_master) {
delta = gr->gw;
delta_threshold = 0.05;
xx1 = gr->gx1 - delta * delta_threshold;
xx2 =gr->gx2 - delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
else if(event == ButtonPress && button == Button4 && !(state & ShiftMask)) {
double delta;
/* vertical move of waveforms with mouse wheel */
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
delta = gr->posh * 0.05;
yy1 = gr->ypos1 - delta;
yy2 = gr->ypos2 - delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
need_redraw = 1;
} else {
delta = gr->gh / gr->divy;
delta_threshold = 1.0;
yy1 = gr->gy1 - delta * delta_threshold;
yy2 = gr->gy2 - delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
}
}
/* horizontal move of waveforms with mouse wheel */
else {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
delta = gr->gw;
delta_threshold = 0.05;
xx1 = gr->gx1 + delta * delta_threshold;
xx2 = gr->gx2 + delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
else if(event == ButtonPress && button == Button5 && (state & ShiftMask)) {
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
double m = DG_Y(xctx->mousey);
double a = m - gr->ypos1;
double b = gr->ypos2 -m;
double delta = gr->posh;
double var = delta * 0.05;
yy2 = gr->ypos2 + var * b / delta;
yy1 = gr->ypos1 - var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
need_redraw = 1;
} else {
double m = G_Y(xctx->mousey);
double a = m - gr->gy1;
double b = gr->gy2 -m;
double delta = (gr->gy2 - gr->gy1);
double var = delta * 0.2;
yy2 = gr->gy2 + var * b / delta;
yy1 = gr->gy1 - var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
}
} else {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * gr->gw;
xx2 = gr->gx2 + var * (1 - zoom_m);
xx1 = gr->gx1 - var * zoom_m;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
else if(event == ButtonPress && button == Button4 && (state & ShiftMask)) {
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
double m = DG_Y(xctx->mousey);
double a = m - gr->ypos1;
double b = gr->ypos2 -m;
double delta = (gr->ypos2 - gr->ypos1);
double var = delta * 0.05;
yy2 = gr->ypos2 - var * b / delta;
yy1 = gr->ypos1 + var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
need_redraw = 1;
} else {
double m = G_Y(xctx->mousey);
double a = m - gr->gy1;
double b = gr->gy2 -m;
double delta = (gr->gy2 - gr->gy1);
double var = delta * 0.2;
yy2 = gr->gy2 - var * b / delta;
yy1 = gr->gy1 + var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
}
} else {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * gr->gw;
xx2 = gr->gx2 - var * (1 - zoom_m);
xx1 = gr->gx1 + var * zoom_m;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
/* y hcursor1 toggle */
else if(event == KeyPress && key == 'A' && access_cond && i == xctx->graph_master) {
xctx->graph_flags ^= 128;
need_redraw = 1;
if(xctx->graph_flags & 128) {
double c = G_Y(xctx->mousey);
if(gr->logy) c = pow(10, c);
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor1_y", dtoa(c)));
} else {
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor1_y", NULL));
}
}
/* y hcursor2 toggle */
else if(event == KeyPress && key == 'B' && access_cond && i == xctx->graph_master) {
xctx->graph_flags ^= 256;
need_redraw = 1;
if(xctx->graph_flags & 256) {
double c = G_Y(xctx->mousey);
if(gr->logy) c = pow(10, c);
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor2_y", dtoa(c)));
} else {
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor2_y", NULL));
}
}
else if(event == KeyPress && key == 't' && access_cond ) {
if(track_dset != -2) { /* -2 means no dataset selection ('t' key) was started */
/*
const char *unlocked = strstr(get_tok_value(r->prop_ptr, "flags", 0), "unlocked");
*/
int unlocked = r->flags & 2;
int floaters = there_are_floaters();
if(i == xctx->graph_master || !unlocked) {
gr->dataset = track_dset;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "dataset", my_itoa(track_dset)));
}
/* do this here to update texts printing current dataset in graph
* tcleval([xschem getprop rect 2 n dataset]) */
if(i == xctx->graph_master && floaters) {
set_modify(-2); /* update floater caches to reflect actual backannotation */
need_fullredraw = 1;
}
if((xctx->graph_flags & 4) && tclgetboolvar("live_cursor2_backannotate")) {
if(i == xctx->graph_master) {
backannotate_at_cursor_b_pos(r, gr);
}
need_fullredraw = 1;
} else {
if(!need_fullredraw) need_redraw = 1;
delta = gr->gh / gr->divy;
delta_threshold = 0.01;
if(fabs(xctx->my_double_save - xctx->mousey_snap) > fabs(gr->cy * delta) * delta_threshold) {
yy1 = gr->gy1 + (xctx->my_double_save - xctx->mousey_snap) / gr->cy;
yy2 = gr->gy2 + (xctx->my_double_save - xctx->mousey_snap) / gr->cy;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
xctx->my_double_save = xctx->mousey_snap;
need_redraw = 1;
}
}
}
} /* key == 't' */
else if(event == KeyPress && key == XK_Left) {
double delta;
if(xctx->graph_left) {
if(!gr->digital && i == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - gr->gy1;
double b = gr->gy2 -m;
double delta = gr->gh;
double var = delta * 0.2;
yy2 = gr->gy2 + var * b / delta;
yy1 = gr->gy1 - var * a / delta;
}
/* horizontal move of waveforms */
else {
save_mouse_at_end = 1;
delta = gr->gw;
delta_threshold = 0.01;
/* selected or locked or master */
if( r->sel || !(r->flags & 2) || i == xctx->graph_master) {
dbg(1, "moving waves: %d\n", i);
if(fabs(xctx->mx_double_save - xctx->mousex_snap) > fabs(gr->cx * delta) * delta_threshold) {
xx1 = gr->gx1 + (xctx->mx_double_save - xctx->mousex_snap) / gr->cx;
xx2 = gr->gx2 + (xctx->mx_double_save - xctx->mousex_snap) / gr->cx;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
}
else if(event == ButtonPress && button == Button3) {
/* Numerically set hcursor position */
if(xctx->graph_flags & 128) {
double cursor;
cursor = gr->hcursor1_y;
if(gr->logy ) {
cursor = mylog10(cursor);
}
if(fabs(xctx->mousey - W_Y(cursor)) < 10) {
xctx->ui_state &= ~GRAPHPAN; /* we are setting a cursor so clear GRAPHPAN set before */
tclvareval("input_line {Pos:} {} ", dtoa_eng(cursor), NULL);
cursor = atof_spice(tclresult());
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor1_y", dtoa(cursor)));
}
need_redraw = 1;
}
/* Numerically set hcursor position */
if(xctx->graph_flags & 256) {
double cursor;
cursor = gr->hcursor2_y;
if(gr->logy ) {
cursor = mylog10(cursor);
}
if(fabs(xctx->mousey - W_Y(cursor)) < 10) {
xctx->ui_state &= ~GRAPHPAN; /* we are setting a cursor so clear GRAPHPAN set before */
tclvareval("input_line {Pos:} {} ", dtoa_eng(cursor), NULL);
cursor = atof_spice(tclresult());
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor2_y", dtoa(cursor)));
}
need_redraw = 1;
}
}
else if(event == ButtonPress && button == Button5 && !(state & ShiftMask)) {
double delta;
/* vertical move of waveforms with mouse wheel */
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
delta = gr->posh * 0.05;
yy1 = gr->ypos1 + delta;
yy2 = gr->ypos2 + delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
need_redraw = 1;
} else {
delta = gr->gh/ gr->divy;
delta_threshold = 1.0;
yy1 = gr->gy1 + delta * delta_threshold;
yy2 = gr->gy2 + delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
} else {
}
}
/* horizontal move of waveforms with mouse wheel */
else {
/* selected or locked or master */
if( r->sel || !(r->flags & 2) || i == xctx->graph_master) {
delta = gr->gw;
delta_threshold = 0.05;
xx1 = gr->gx1 - delta * delta_threshold;
xx2 = gr->gx2 - delta * delta_threshold;
xx2 =gr->gx2 - delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
else if(event == KeyPress && key == XK_Right) {
double delta;
if(xctx->graph_left) {
if(!gr->digital && i == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - gr->gy1;
double b = gr->gy2 -m;
double delta = gr->gh;
double var = delta * 0.2;
yy2 = gr->gy2 - var * b / delta;
yy1 = gr->gy1 + var * a / delta;
}
else if(event == ButtonPress && button == Button4 && !(state & ShiftMask)) {
double delta;
/* vertical move of waveforms with mouse wheel */
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
delta = gr->posh * 0.05;
yy1 = gr->ypos1 - delta;
yy2 = gr->ypos2 - delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
need_redraw = 1;
} else {
delta = gr->gh / gr->divy;
delta_threshold = 1.0;
yy1 = gr->gy1 - delta * delta_threshold;
yy2 = gr->gy2 - delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
} else {
}
}
/* horizontal move of waveforms with mouse wheel */
else {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
delta = gr->gw;
delta_threshold = 0.05;
xx1 = gr->gx1 + delta * delta_threshold;
@ -1190,71 +996,242 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
need_redraw = 1;
}
}
else if(event == KeyPress && key == XK_Down) {
if(!xctx->graph_left) {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * gr->gw;
xx2 = gr->gx2 + var * (1 - zoom_m);
xx1 = gr->gx1 - var * zoom_m;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
}
else if(event == ButtonPress && button == Button5 && (state & ShiftMask)) {
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
double m = DG_Y(xctx->mousey);
double a = m - gr->ypos1;
double b = gr->ypos2 -m;
double delta = gr->posh;
double var = delta * 0.05;
yy2 = gr->ypos2 + var * b / delta;
yy1 = gr->ypos1 - var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
need_redraw = 1;
} else {
double m = G_Y(xctx->mousey);
double a = m - gr->gy1;
double b = gr->gy2 -m;
double delta = (gr->gy2 - gr->gy1);
double var = delta * 0.2;
yy2 = gr->gy2 + var * b / delta;
yy1 = gr->gy1 - var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
}
} else {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * gr->gw;
xx2 = gr->gx2 + var * (1 - zoom_m);
xx1 = gr->gx1 - var * zoom_m;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
else if(event == KeyPress && key == XK_Up) {
if(!xctx->graph_left) {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * gr->gw;
xx2 = gr->gx2 - var * (1 - zoom_m);
xx1 = gr->gx1 + var * zoom_m;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
}
else if(event == ButtonPress && button == Button4 && (state & ShiftMask)) {
if(xctx->graph_left) {
if(i == xctx->graph_master) {
if(gr->digital) {
double m = DG_Y(xctx->mousey);
double a = m - gr->ypos1;
double b = gr->ypos2 -m;
double delta = (gr->ypos2 - gr->ypos1);
double var = delta * 0.05;
yy2 = gr->ypos2 - var * b / delta;
yy1 = gr->ypos1 + var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "ypos2", dtoa(yy2)));
need_redraw = 1;
} else {
double m = G_Y(xctx->mousey);
double a = m - gr->gy1;
double b = gr->gy2 -m;
double delta = (gr->gy2 - gr->gy1);
double var = delta * 0.2;
yy2 = gr->gy2 - var * b / delta;
yy1 = gr->gy1 + var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
}
}
else if(event == KeyPress && key == 'f' && access_cond) {
if(xctx->raw && xctx->raw->values) {
if(xctx->graph_left) { /* full Y zoom*/
if(i == xctx->graph_master) {
need_redraw = graph_fullyzoom(r, gr, dataset);
} /* graph_master */
} else { /* not graph_left, full X zoom*/
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
need_redraw = graph_fullxzoom(i, gr, dataset);
}
}
} /* raw->values */
} /* key == 'f' */
/* absolute positioning by mouse drag in bottom graph area */
else if(event == MotionNotify && (state & Button1Mask) && xctx->graph_bottom ) {
if(xctx->raw && xctx->raw->values) {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
/* xx1 and xx2 calculated for master graph above */
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
} else {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * gr->gw;
xx2 = gr->gx2 - var * (1 - zoom_m);
xx1 = gr->gx1 + var * zoom_m;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
/* y hcursor1 toggle */
else if(event == KeyPress && key == 'A' && access_cond && i == xctx->graph_master) {
xctx->graph_flags ^= 128;
need_redraw = 1;
if(xctx->graph_flags & 128) {
double c = G_Y(xctx->mousey);
if(gr->logy) c = pow(10, c);
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor1_y", dtoa(c)));
} else {
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor1_y", NULL));
}
}
/* y hcursor2 toggle */
else if(event == KeyPress && key == 'B' && access_cond && i == xctx->graph_master) {
xctx->graph_flags ^= 256;
need_redraw = 1;
if(xctx->graph_flags & 256) {
double c = G_Y(xctx->mousey);
if(gr->logy) c = pow(10, c);
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor2_y", dtoa(c)));
} else {
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "hcursor2_y", NULL));
}
}
else if(event == KeyPress && key == 't' && access_cond ) {
if(track_dset != -2) { /* -2 means no dataset selection ('t' key) was started */
/*
const char *unlocked = strstr(get_tok_value(r->prop_ptr, "flags", 0), "unlocked");
*/
int unlocked = r->flags & 2;
int floaters = there_are_floaters();
if(i == xctx->graph_master || !unlocked) {
gr->dataset = track_dset;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "dataset", my_itoa(track_dset)));
}
/* do this here to update texts printing current dataset in graph
* tcleval([xschem getprop rect 2 n dataset]) */
if(i == xctx->graph_master && floaters) {
set_modify(-2); /* update floater caches to reflect actual backannotation */
need_fullredraw = 1;
}
if((xctx->graph_flags & 4) && tclgetboolvar("live_cursor2_backannotate")) {
if(i == xctx->graph_master) {
backannotate_at_cursor_b_pos(r, gr);
}
need_fullredraw = 1;
} else {
if(!need_fullredraw) need_redraw = 1;
}
}
} /* key == 't' */
else if(event == KeyPress && key == XK_Left) {
double delta;
if(xctx->graph_left) {
if(!gr->digital && i == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - gr->gy1;
double b = gr->gy2 -m;
double delta = gr->gh;
double var = delta * 0.2;
yy2 = gr->gy2 + var * b / delta;
yy1 = gr->gy1 - var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
} else {
delta = gr->gw;
delta_threshold = 0.05;
xx1 = gr->gx1 - delta * delta_threshold;
xx2 = gr->gx2 - delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
else if(event == KeyPress && key == XK_Right) {
double delta;
if(xctx->graph_left) {
if(!gr->digital && i == xctx->graph_master) {
double m = G_Y(xctx->mousey);
double a = m - gr->gy1;
double b = gr->gy2 -m;
double delta = gr->gh;
double var = delta * 0.2;
yy2 = gr->gy2 - var * b / delta;
yy1 = gr->gy1 + var * a / delta;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y1", dtoa(yy1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "y2", dtoa(yy2)));
need_redraw = 1;
}
} else {
delta = gr->gw;
delta_threshold = 0.05;
xx1 = gr->gx1 + delta * delta_threshold;
xx2 = gr->gx2 + delta * delta_threshold;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
else if(event == KeyPress && key == XK_Down) {
if(!xctx->graph_left) {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * gr->gw;
xx2 = gr->gx2 + var * (1 - zoom_m);
xx1 = gr->gx1 - var * zoom_m;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
else if(event == KeyPress && key == XK_Up) {
if(!xctx->graph_left) {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
double var = 0.2 * gr->gw;
xx2 = gr->gx2 - var * (1 - zoom_m);
xx1 = gr->gx1 + var * zoom_m;
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
else if(event == KeyPress && key == 'f' && access_cond) {
if(xctx->raw && xctx->raw->values) {
if(xctx->graph_left) { /* full Y zoom*/
if(i == xctx->graph_master) {
need_redraw = graph_fullyzoom(r, gr, dataset);
} /* graph_master */
} else { /* not graph_left, full X zoom*/
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
need_redraw = graph_fullxzoom(i, gr, dataset);
}
}
} /* raw->values */
} /* key == 'f' */
/* absolute positioning by mouse drag in bottom graph area */
else if(event == MotionNotify && (state & Button1Mask) && xctx->graph_bottom ) {
if(xctx->raw && xctx->raw->values) {
/* selected or locked or master */
if(r->sel || !(r->flags & 2) || i == xctx->graph_master) {
} /* if( event == KeyPress || event == ButtonPress || event == MotionNotify ) */
/* xx1 and xx2 calculated for master graph above */
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x1", dtoa(xx1)));
my_strdup(_ALLOC_ID_, &r->prop_ptr, subst_token(r->prop_ptr, "x2", dtoa(xx2)));
need_redraw = 1;
}
}
}
else if(event == ButtonRelease) {