]> git.neil.brown.name Git - edlib.git/commitdiff
Draw:image: move cursor cols,rows into mode (str2)
authorNeilBrown <neil@brown.name>
Fri, 22 Sep 2023 05:07:29 +0000 (15:07 +1000)
committerNeilBrown <neil@brown.name>
Wed, 27 Sep 2023 06:00:03 +0000 (16:00 +1000)
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 <neil@brown.name>
DOC/Calls
display-ncurses.c
display-x11-xcb.c
lib-renderline.c
python/display-pygtk.py

index a35e7a135db27c9f3882261384c75fe7751fae20..30932d52da852b76bfdc20bb358a3ffc37dd4e56 100644 (file)
--- 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
 
index 34d22eab5d201a1188414fcc2a40a563f2e8b5f1..a0102d04422b1267fc58aa74925c3b0bfe75af56 100644 (file)
@@ -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;
index 22c75c993dee4cb4e3700ef65d9c18a7bdc75140..237cf3b069270e184b8645ce623d7000e47b0788 100644 (file)
@@ -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);
 
index 3fcca5e26478fd7b181d9811da008ad17f695324..04c9a5cf116c7f22de7324850f420beaeea5a103 100644 (file)
@@ -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);
 
index 3c62c5287460d52ec0387c95d21670ad1a540b29..aa8e5cbd1ce85e7a5aab0d46040b4e7ee225baaf 100644 (file)
@@ -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)