]> git.neil.brown.name Git - edlib.git/commitdiff
Discard hx,hy in favour explicit conversion functions.
authorNeilBrown <neil@brown.name>
Fri, 11 Dec 2015 23:21:59 +0000 (10:21 +1100)
committerNeilBrown <neil@brown.name>
Fri, 11 Dec 2015 23:23:44 +0000 (10:23 +1100)
Less room for conversion, and best to do the work when it is needed.

Signed-off-by: NeilBrown <neil@brown.name>
core-keymap.c
core-pane.c
core.h
lang-python.c
lib-input.c
lib-view.c
render-lines.c

index 2170e997129b14e652390520f1ea41a862e304e1..12905640d1c757a8b4d22f2b9ab7632f772d0742 100644 (file)
@@ -301,9 +301,6 @@ int key_handle(const struct cmd_info *ci)
        if (ci->comm)
                return ci->comm->func(ci);
 
-       vci->hx = ci->x;
-       vci->hy = ci->y;
-
        /* If 'home' is set, search from there, else search
         * from focus
         */
@@ -320,10 +317,6 @@ int key_handle(const struct cmd_info *ci)
                if (ret)
                        /* 'p' might have been destroyed */
                        break;
-               if (ci->hx >= 0) {
-                       vci->hx += p->x;
-                       vci->hy += p->y;
-               }
                p = p->parent;
        }
        return ret;
index 11eb41ddabdfacd57dc0f5afcb769c8fe1631656..64d420767f722e509c9fdd88ec51debdb3d1f633 100644 (file)
@@ -620,3 +620,29 @@ struct pane *call_pane(char *key, struct pane *focus, int numeric,
                return NULL;
        return cr.p;
 }
+
+/* convert pane-relative co-ords to absolute */
+void pane_absxy(struct pane *p, int *x, int *y)
+{
+       while (p) {
+               *x += p->x;
+               *y += p->y;
+               p = p->parent;
+       }
+}
+
+/* Convert absolute c-ords to relative */
+void pane_relxy(struct pane *p, int *x, int *y)
+{
+       while (p) {
+               *x -= p->x;
+               *y -= p->y;
+               p = p->parent;
+       }
+}
+
+void pane_map_xy(struct pane *orig, struct pane *target, int *x, int *y)
+{
+       pane_absxy(orig, x, y);
+       pane_relxy(target, x, y);
+}
diff --git a/core.h b/core.h
index 54785a05a9f4092bb3e3ecdc063151be0d0d4763..f5b5eb5620c502d71a2ff1ea1b08bfd4b46e1c47 100644 (file)
--- a/core.h
+++ b/core.h
@@ -287,7 +287,6 @@ struct cmd_info {
        struct pane     *home, *focus;
        int             numeric, extra;
        int             x,y;            /* relative to focus */
-       int             hx, hy;         /* x,y mapped to 'home' */
        char            *str, *str2;
        struct mark     *mark, *mark2;
        struct command  *comm, *comm2;
@@ -351,6 +350,9 @@ void pane_clear(struct pane *p, char *attrs);
 void pane_text(struct pane *p, wchar_t ch, char *attrs, int x, int y);
 char *pane_attr_get(struct pane *p, char *key);
 char *pane_mark_attr(struct pane *p, struct mark *m, int forward, char *key);
+void pane_absxy(struct pane *p, int *x, int *y);
+void pane_relxy(struct pane *p, int *x, int *y);
+void pane_map_xy(struct pane *orig, struct pane *target, int *x, int *y);
 struct pane *call_pane(char *key, struct pane *focus, int numeric,
                       struct mark *m, int extra);
 
index 17dee29afcf442f0f918380deb057ab25e765985..1c431e920293b36e31338c4bdc6231825977b034 100644 (file)
@@ -156,7 +156,6 @@ REDEF_CMD(python_call)
        PyDict_SetItemString(kwds, "numeric", Py_BuildValue("i", ci->numeric));
        PyDict_SetItemString(kwds, "extra", Py_BuildValue("i", ci->extra));
        PyDict_SetItemString(kwds, "xy", Py_BuildValue("ii", ci->x, ci->y));
-       PyDict_SetItemString(kwds, "hxy", Py_BuildValue("ii", ci->hx, ci->hy));
 
        if (pc->home_func)
                PyDict_SetItemString(kwds, "data", ci->home->data);
@@ -718,7 +717,7 @@ static int get_cmd_info(struct cmd_info *ci, PyObject *args, PyObject *kwds)
        PyObject *a;
        int i;
        int numeric_set = 0, extra_set = 0;
-       int xy_set = 0, hxy_set = 0;
+       int xy_set = 0;
 
        if (!PyTuple_Check(args))
                return 0;
@@ -789,12 +788,8 @@ static int get_cmd_info(struct cmd_info *ci, PyObject *args, PyObject *kwds)
                                ci->x = PyInt_AsLong(n1);
                                ci->y = PyInt_AsLong(n2);
                                xy_set = 1;
-                       } else if (!hxy_set) {
-                               ci->hx = PyInt_AsLong(n1);
-                               ci->hy = PyInt_AsLong(n2);
-                               hxy_set = 1;
                        } else {
-                               PyErr_SetString(PyExc_TypeError, "Only two tuples permitted");
+                               PyErr_SetString(PyExc_TypeError, "Only one tuple permitted");
                                return 0;
                        }
                } else if (Py_TYPE(a) == &CommType) {
index 0f004308f42e4b8438fa75f05f4a1d86594fbb02..e6aa88a39c755769b5041e70f1d1d64ffce86251 100644 (file)
@@ -71,14 +71,15 @@ DEF_CMD(mouse_event)
        int l;
        struct cmd_info ci2 = {0};
 
+
        l = strlen(im->mode) + strlen(ci->str) + 1;
        ci2.key = malloc(l);
        strcat(strcpy(ci2.key, im->mode), ci->str);
        ci2.focus = ci->home;
        ci2.numeric = im->numeric;
        ci2.extra = im->extra;
-       ci2.x = ci->hx;
-       ci2.y = ci->hy;
+       ci2.x = ci->x; ci2.y = ci->y;
+       pane_map_xy(ci->focus, ci2.focus, &ci2.x, &ci2.y);
 
        im->mode = "";
        im->numeric = NO_NUMERIC;
index 94fc381a8e3bb2c89e67ca677934221356d6261e..a10236ec44ce6af24bacfd2d0d06d19d6b09be9f 100644 (file)
@@ -237,8 +237,12 @@ DEF_CMD(view_click)
        int mid = vd->scroll_bar_y;
        char *key;
        int num;
+       int cihx, cihy;
 
-       if (ci->hx != 0)
+       cihx = ci->x; cihy = ci->y;
+       pane_map_xy(ci->focus, ci->home, &cihx, &cihy);
+
+       if (cihx != 0)
                return 0;
        if (p->h <= 4)
                return 0;
@@ -248,16 +252,16 @@ DEF_CMD(view_click)
        key = "Move-View-Small";
        num = RPT_NUM(ci);
 
-       if (ci->hy == mid-1) {
+       if (cihy == mid-1) {
                /* scroll up */
                num = -num;
-       } else if (ci->hy < mid-1) {
+       } else if (cihy < mid-1) {
                /* big scroll up */
                num = -num;
                key = "Move-View-Large";
-       } else if (ci->hy == mid+1) {
+       } else if (cihy == mid+1) {
                /* scroll down */
-       } else if (ci->hy > mid+1 && ci->hy < p->h-1) {
+       } else if (cihy > mid+1 && cihy < p->h-1) {
                key = "Move-View-Large";
        } else
                return 0;
index ff4470ed3839bf2652301ad3a0b39ccaa0542c4d..988ec6f888f1e01f952aafe97b510efcd2f12771 100644 (file)
@@ -744,18 +744,20 @@ DEF_CMD(render_lines_set_cursor)
        struct mark *m;
        int y = rl->header_lines - rl->skip_lines;
        int found = 0;
-       int cihy;
+       int cihx, cihy;
 
        render_lines_other_move_func(ci);
 
        m = vmark_first(p, rl->typenum);
 
-       cihy = ci->hy;
-       if (y > ci->hy)
+       cihx = ci->x; cihy = ci->y;
+       pane_map_xy(ci->focus, ci->home, &cihx, &cihy);
+
+       if (y > cihy)
                /* x,y is in header line - try lower */
                cihy = y;
-       while (y <= ci->hy && m && m->mdata) {
-               int cx = ci->hx, cy = cihy, o = -1;
+       while (y <= cihy && m && m->mdata) {
+               int cx = cihx, cy = cihy, o = -1;
                render_line(p, m->mdata, &y, 0, &cx, &cy, &o);
                if (o >= 0) {
                        struct mark *m2 = call_render_line_offset(p, m, o);