From: NeilBrown Date: Fri, 22 Sep 2023 05:07:29 +0000 (+1000) Subject: Draw:image: move cursor cols,rows into mode (str2) X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=b5f00189f7281f8ad87a45fc2106f209e328460d;p=edlib.git Draw:image: move cursor cols,rows into mode (str2) Move the rows,cols numbers from x,y into str2, so that we can store more interesting numbers in x,y. Signed-off-by: NeilBrown --- diff --git a/DOC/Calls b/DOC/Calls index a35e7a13..30932d52 100644 --- a/DOC/Calls +++ b/DOC/Calls @@ -129,10 +129,11 @@ Draw an image on the pane (or ancestor which as been cleared). 'R' - place on right if full width isn't used 'T' - place at top if full height isn't used 'B' - place at bottom if full height isn't used. -- (x,y) gives a number of rows and cols to overlay on the image for - the purpose of cursor positioning. If these are positive and - p->cx,cy are not negative, draw a cursor at p->cx,cy highlighting - the relevant cell. + Also a suffix ":NNxNN" will be parse and the two numbers used + to give number of rows and cols to overlay on the image for + the purpose of cursor positioning. If these are present and + p->cx,cy are not negative, draw a cursor at p->cx,cy highlighting + the relevant cell. ## all-displays diff --git a/display-ncurses.c b/display-ncurses.c index 34d22eab..a0102d04 100644 --- a/display-ncurses.c +++ b/display-ncurses.c @@ -1010,9 +1010,11 @@ DEF_CMD(nc_draw_image) * 'T' - place at top if full height isn't used * 'B' - place at bottom if full height isn't used. * - * If 'x' and 'y' are both positive, draw cursor box at - * p->cx, p->cy of a size so that 'x' will fit across and - * 'y' will fit down. + * Also a suffix ":NNxNN" will be parse and the two numbers used + * to give number of rows and cols to overlay on the image for + * the purpose of cursor positioning. If these are present and + * p->cx,cy are not negative, draw a cursor at p->cx,cy highlighting + * the relevant cell. */ struct pane *p = ci->home; struct display_data *dd = p->data; @@ -1087,7 +1089,7 @@ DEF_CMD(nc_draw_image) buf = malloc(h * w * 4); MagickExportImagePixels(wd, 0, 0, w, h, "RGBA", CharPixel, buf); - if (ci->x > 0 && ci->y > 0 && ci->focus->cx >= 0) { + if (ci->focus->cx >= 0 && strchr(mode, ':')) { /* We want a cursor */ cx = x + ci->focus->cx; cy = y + ci->focus->cy; diff --git a/display-x11-xcb.c b/display-x11-xcb.c index 22c75c99..237cf3b0 100644 --- a/display-x11-xcb.c +++ b/display-x11-xcb.c @@ -820,9 +820,11 @@ DEF_CMD(xcb_draw_image) * 'T' - place at top if full height isn't used * 'B' - place at bottom if full height isn't used. * - * If 'x' and 'y' are both positive, draw cursor box at - * p->cx, p->cy of a size so that 'x' will fit across and - * 'y' will fit down. + * Also a suffix ":NNxNN" will be parse and the two numbers used + * to give number of rows and cols to overlay on the image for + * the purpose of cursor positioning. If these are present and + * p->cx,cy are not negative, draw a cursor at p->cx,cy highlighting + * the relevant cell. */ struct xcb_data *xd = ci->home->data; const char *mode = ci->str2 ?: ""; @@ -919,13 +921,17 @@ DEF_CMD(xcb_draw_image) cairo_surface_destroy(surface); free(buf); - if (ci->x > 0 && ci->y > 0 && ci->focus->cx >= 0) { + if (ci->focus->cx >= 0) { struct pane *p = ci->focus; - cairo_rectangle(ps->ctx, p->cx + xo, p->cy + yo, - w/ci->x, h/ci->y); - cairo_set_line_width(ps->ctx, 1.0); - cairo_set_source_rgb(ps->ctx, 1.0, 0.0, 0.0); - cairo_stroke(ps->ctx); + int rows, cols; + char *cl = strchr(mode, ':'); + if (cl && sscanf(cl, ":%dx%d", &cols, &rows) == 2) { + cairo_rectangle(ps->ctx, p->cx + xo, p->cy + yo, + w/cols, h/rows); + cairo_set_line_width(ps->ctx, 1.0); + cairo_set_source_rgb(ps->ctx, 1.0, 0.0, 0.0); + cairo_stroke(ps->ctx); + } } DestroyMagickWand(wd); diff --git a/lib-renderline.c b/lib-renderline.c index 3fcca5e2..04c9a5cf 100644 --- a/lib-renderline.c +++ b/lib-renderline.c @@ -1044,6 +1044,7 @@ static int render_image(struct pane *p safe, struct pane *focus safe, struct xy xyscale = pane_scale(focus); int scale = xyscale.x; struct xy size= {-1, -1}; + char mode[30] = ""; const char *a, *v; const char *end; @@ -1097,6 +1098,9 @@ static int render_image(struct pane *p safe, struct pane *focus safe, */ map_offset = v - orig_line; parse_map(v, &rows, &cols); + if (rows > 0 && cols > 0) + snprintf(mode, sizeof(mode), + ":%dx%d", cols, rows); } } pane_resize(p, (p->parent->w - width)/2, p->y, width, height); @@ -1131,7 +1135,7 @@ static int render_image(struct pane *p safe, struct pane *focus safe, if (fname && dodraw) home_call(focus, "Draw:image", p, 0, NULL, fname, - 0, NULL, NULL, cols, rows); + 0, NULL, mode); free(fname); diff --git a/python/display-pygtk.py b/python/display-pygtk.py index 3c62c528..aa8e5cbd 100644 --- a/python/display-pygtk.py +++ b/python/display-pygtk.py @@ -276,7 +276,7 @@ class EdDisplay(edlib.Pane): return True - def handle_image(self, key, focus, str1, str2, xy, **a): + def handle_image(self, key, focus, str1, str2, **a): "handle:Draw:image" self.damaged(edlib.DAMAGED_POSTORDER) # 'str1' identifies the image. Options are: @@ -292,10 +292,11 @@ class EdDisplay(edlib.Pane): # 'T' - place at top if full height isn't used # 'B' - place at bottom if full height isn't used. # - # xy gives a number of rows and cols to overlay on the image - # for the purpose of cursor positioning. If these are positive - # and focus.cx,cy are not negative, draw a cursor at cx,cy - # highlighting the relevant cell. + # Also a suffix ":NNxNN" will be parse and the two numbers used + # to give number of rows and cols to overlay on the image for + # the purpose of cursor positioning. If these are present and + # focus.cx,cy are not negative, draw a cursor at cx,cy highlighting + # the relevant cell. if not str1: return edlib.Enoarg mode = str2 if str2 else "" @@ -339,7 +340,15 @@ class EdDisplay(edlib.Pane): Gdk.cairo_set_source_pixbuf(cr, scale, x + xo, y + yo) cr.paint() - (rows,cols) = xy + (rows,cols) = (-1,-1) + if ':' in mode: + rc = mode[mode.rindex(':')+1:].split('x') + try: + (rows,cols) = (int(rc[0]), int(rc[1])) + except ValueError: + pass + except IndexError: + pass if rows > 0 and cols > 0 and focus.cx >= 0: cr.rectangle(focus.cx + xo, focus.cy + yo, w/rows, h/cols)