handle cursor drawing in multiple graphs, some with log scale some others without
This commit is contained in:
parent
5dc27fb364
commit
9c5a1a9816
|
|
@ -380,12 +380,16 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
|
|||
/* set cursor position from master graph x-axis */
|
||||
if(event == MotionNotify && (state & Button1Mask) && (xctx->graph_flags & 16 )) {
|
||||
xctx->graph_cursor1_x = G_X(xctx->mousex);
|
||||
xctx->graph_flags &= ~128;
|
||||
if(xctx->graph_flags & 2) xctx->graph_flags |= 128 * gr->logx;
|
||||
}
|
||||
/* move cursor2 */
|
||||
/* set cursor position from master graph x-axis */
|
||||
else if(event == MotionNotify && (state & Button1Mask) && (xctx->graph_flags & 32 )) {
|
||||
int floaters = there_are_floaters();
|
||||
xctx->graph_cursor2_x = G_X(xctx->mousex);
|
||||
xctx->graph_flags &= ~256;
|
||||
if(xctx->graph_flags & 2) xctx->graph_flags |= 256 * gr->logx;
|
||||
if(tclgetboolvar("live_cursor2_backannotate")) {
|
||||
backannotate_at_cursor_b_pos(r, gr);
|
||||
if(floaters) set_modify(-2); /* update floater caches to reflect actual backannotation */
|
||||
|
|
@ -416,11 +420,29 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
|
|||
zoom_m = (xctx->mousex - gr->x1) / gr->w;
|
||||
if(event == ButtonPress && button == Button1) {
|
||||
/* dragging cursors when mouse is very close */
|
||||
if( (xctx->graph_flags & 2) && fabs(xctx->mousex - W_X(xctx->graph_cursor1_x)) < 10) {
|
||||
xctx->graph_flags |= 16; /* Start move cursor1 */
|
||||
if(xctx->graph_flags & 2) {
|
||||
double c = xctx->graph_cursor1_x;
|
||||
if(!gr->logx && (xctx->graph_flags & 128)) {
|
||||
c = pow(10, c);
|
||||
}
|
||||
if(gr->logx && !(xctx->graph_flags & 128)) {
|
||||
c = log10(c);
|
||||
}
|
||||
if(fabs(xctx->mousex - W_X(c)) < 10) {
|
||||
xctx->graph_flags |= 16; /* Start move cursor1 */
|
||||
}
|
||||
}
|
||||
if( (xctx->graph_flags & 4) && fabs(xctx->mousex - W_X(xctx->graph_cursor2_x)) < 10) {
|
||||
xctx->graph_flags |= 32; /* Start move cursor2 */
|
||||
if(xctx->graph_flags & 4) {
|
||||
double c = xctx->graph_cursor2_x;
|
||||
if(!gr->logx && (xctx->graph_flags & 256)) {
|
||||
c = pow(10, c);
|
||||
}
|
||||
if(gr->logx && !(xctx->graph_flags & 256)) {
|
||||
c = log10(c);
|
||||
}
|
||||
if(fabs(xctx->mousex - W_X(c)) < 10) {
|
||||
xctx->graph_flags |= 32; /* Start move cursor2 */
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(event == ButtonPress && button == Button3) {
|
||||
|
|
@ -462,6 +484,8 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
|
|||
/* x cursor1 toggle */
|
||||
else if((key == 'a' && rstate == 0) ) {
|
||||
xctx->graph_flags ^= 2;
|
||||
xctx->graph_flags &= ~128;
|
||||
if(xctx->graph_flags & 2) xctx->graph_flags |= 128 * gr->logx;
|
||||
need_all_redraw = 1;
|
||||
if(xctx->graph_flags & 2) xctx->graph_cursor1_x = G_X(xctx->mousex);
|
||||
}
|
||||
|
|
@ -469,6 +493,8 @@ static int waves_callback(int event, int mx, int my, KeySym key, int button, int
|
|||
else if((key == 'b') ) {
|
||||
int floaters = there_are_floaters();
|
||||
xctx->graph_flags ^= 4;
|
||||
xctx->graph_flags &= ~256;
|
||||
if(xctx->graph_flags & 4) xctx->graph_flags |= 256 * gr->logx;
|
||||
if(xctx->graph_flags & 4) {
|
||||
xctx->graph_cursor2_x = G_X(xctx->mousex);
|
||||
if(tclgetboolvar("live_cursor2_backannotate")) {
|
||||
|
|
|
|||
46
src/draw.c
46
src/draw.c
|
|
@ -2923,15 +2923,15 @@ static void draw_cursor(double active_cursorx, double other_cursorx, int cursor_
|
|||
}
|
||||
}
|
||||
|
||||
static void draw_cursor_difference(Graph_ctx *gr)
|
||||
static void draw_cursor_difference(double c1, double c2, Graph_ctx *gr)
|
||||
{
|
||||
int tmp;
|
||||
char tmpstr[100];
|
||||
double txtsize = gr->txtsizex;
|
||||
double tx1, ty1, tx2, ty2;
|
||||
double aa = W_X(xctx->graph_cursor1_x);
|
||||
double aa = W_X(c1);
|
||||
double a = CLIP(aa, gr->x1, gr->x2);
|
||||
double bb = W_X(xctx->graph_cursor2_x);
|
||||
double bb = W_X(c2);
|
||||
double b = CLIP(bb, gr->x1, gr->x2);
|
||||
double diff = fabs(b - a);
|
||||
double diffw;
|
||||
|
|
@ -2943,9 +2943,9 @@ static void draw_cursor_difference(Graph_ctx *gr)
|
|||
|
||||
/* if(gr->logx) return; */
|
||||
if(gr->logx) {
|
||||
diffw = fabs(pow(10, xctx->graph_cursor2_x) - pow(10, xctx->graph_cursor1_x));
|
||||
diffw = fabs(pow(10, c2) - pow(10, c1));
|
||||
} else {
|
||||
diffw = fabs(xctx->graph_cursor2_x - xctx->graph_cursor1_x);
|
||||
diffw = fabs(c2 - c1);
|
||||
}
|
||||
|
||||
if(gr->unitx != 1.0)
|
||||
|
|
@ -3471,6 +3471,8 @@ int find_closest_wave(int i, Graph_ctx *gr)
|
|||
* 2: draw x-cursor1
|
||||
* 4: draw x-cursor2
|
||||
* 8: all drawing, if not set do only XCopyArea / x-cursor if specified
|
||||
* 128: cursor1 is log scale
|
||||
* 256: cursor2 is log scale
|
||||
* ct is a pointer used in windows for cairo
|
||||
*/
|
||||
void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
|
||||
|
|
@ -3787,12 +3789,34 @@ void draw_graph(int i, const int flags, Graph_ctx *gr, void *ct)
|
|||
* bbox(SET_INSIDE, 0.0, 0.0, 0.0, 0.0);
|
||||
*/
|
||||
if(flags & 8) {
|
||||
double c1 = xctx->graph_cursor1_x;
|
||||
double c2 = xctx->graph_cursor2_x;
|
||||
if(flags & 6) {
|
||||
if(!gr->logx && (xctx->graph_flags & 128)) {
|
||||
c1 = pow(10, c1);
|
||||
}
|
||||
if(gr->logx && !(xctx->graph_flags & 128)) {
|
||||
c1 = log10(c1);
|
||||
}
|
||||
if(!gr->logx && (xctx->graph_flags & 256)) {
|
||||
c2 = pow(10, c2);
|
||||
}
|
||||
if(gr->logx && !(xctx->graph_flags & 256)) {
|
||||
c2 = log10(c2);
|
||||
}
|
||||
}
|
||||
/* cursor1 */
|
||||
if((flags & 2)) draw_cursor(xctx->graph_cursor1_x, xctx->graph_cursor2_x, 1, gr);
|
||||
if((flags & 2)) {
|
||||
draw_cursor(c1, c2, 1, gr);
|
||||
}
|
||||
/* cursor2 */
|
||||
if((flags & 4)) draw_cursor(xctx->graph_cursor2_x, xctx->graph_cursor1_x, 3, gr);
|
||||
if((flags & 4)) {
|
||||
draw_cursor(c2, c1, 3, gr);
|
||||
}
|
||||
/* difference between cursors */
|
||||
if((flags & 2) && (flags & 4)) draw_cursor_difference(gr);
|
||||
if((flags & 2) && (flags & 4)) {
|
||||
draw_cursor_difference(c1, c2, gr);
|
||||
}
|
||||
}
|
||||
if(flags & 1) { /* copy save buffer to screen */
|
||||
if(!xctx->draw_window) {
|
||||
|
|
@ -4443,7 +4467,11 @@ void draw(void)
|
|||
xctx->areaw, xctx->areah);
|
||||
dbg(1, "draw(): window: %d %d %d %d\n",xctx->areax1, xctx->areay1, xctx->areax2, xctx->areay2);
|
||||
if(!xctx->only_probes) drawgrid();
|
||||
draw_graph_all((xctx->graph_flags & 6) + 8); /* xctx->graph_flags for cursors */
|
||||
/* 2: draw cursor 1
|
||||
* 4: draw cursor 2
|
||||
* 128: cursor 1 is log scale
|
||||
* 256: cursor 2 is log scale */
|
||||
draw_graph_all((xctx->graph_flags & (2 | 4 | 128 | 256)) + 8); /* xctx->graph_flags for cursors */
|
||||
draw_images_all();
|
||||
|
||||
x1 = X_TO_XSCHEM(xctx->areax1);
|
||||
|
|
|
|||
|
|
@ -755,7 +755,11 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
|||
if(argc > 3) {
|
||||
flags = atoi(argv[3]);
|
||||
} else {
|
||||
flags = 1 + 8 + (xctx->graph_flags & 6);
|
||||
/* 2: draw cursor 1
|
||||
* 4: draw cursor 2
|
||||
* 128: cursor 1 is log scale
|
||||
* 256: cursor 2 is log scale */
|
||||
flags = 1 + 8 + (xctx->graph_flags & (2 + 4 + 128 + 256));
|
||||
}
|
||||
setup_graph_data(i, 0, &xctx->graph_struct);
|
||||
draw_graph(i, flags, &xctx->graph_struct, NULL);
|
||||
|
|
@ -1194,6 +1198,18 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
|
|||
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
|
||||
Tcl_SetResult(interp, my_itoa(xctx->currsch),TCL_VOLATILE);
|
||||
}
|
||||
else if(!strcmp(argv[2], "cursor1_x")) {
|
||||
char c[70];
|
||||
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
|
||||
my_snprintf(c, S(c), "%g", xctx->graph_cursor1_x);
|
||||
Tcl_SetResult(interp, c, TCL_VOLATILE);
|
||||
}
|
||||
else if(!strcmp(argv[2], "cursor2_x")) {
|
||||
char c[70];
|
||||
if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
|
||||
my_snprintf(c, S(c), "%g", xctx->graph_cursor2_x);
|
||||
Tcl_SetResult(interp, c, TCL_VOLATILE);
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
if(!strcmp(argv[2], "debug_var")) { /* debug level (0 = no debug, 1, 2, 3,...) */
|
||||
|
|
|
|||
|
|
@ -485,6 +485,7 @@ static void alloc_xschem_data(const char *top_path, const char *win_path)
|
|||
xctx->extra_raw_n = 0;
|
||||
xctx->graph_master = 0;
|
||||
xctx->graph_cursor1_x = 0;
|
||||
xctx->graph_cursor2_x = 0;
|
||||
xctx->graph_flags = 0;
|
||||
xctx->graph_top = 0;
|
||||
xctx->graph_bottom = 0;
|
||||
|
|
|
|||
|
|
@ -1089,8 +1089,7 @@ typedef struct {
|
|||
|
||||
/* */
|
||||
/* data related to all graphs, so not stored in per-graph graph_struct */
|
||||
double graph_cursor1_x;
|
||||
double graph_cursor2_x;
|
||||
double graph_cursor1_x, graph_cursor2_x;
|
||||
/* graph_flags:
|
||||
* 1: dnu, reserved, used in draw_graphs()
|
||||
* 2: draw x-cursor1
|
||||
|
|
@ -1099,6 +1098,8 @@ typedef struct {
|
|||
* 16: move cursor1
|
||||
* 32: move cursor2
|
||||
* 64: show measurement tooltip
|
||||
* 128: cursor1 is log scale
|
||||
* 256: cursor2 is log scale
|
||||
*/
|
||||
int graph_flags;
|
||||
int graph_master; /* graph where mouse operations are started, used to lock x-axis */
|
||||
|
|
|
|||
Loading…
Reference in New Issue