commit 2d63702cd5d1b7205e12726bad26c51bbc3ffa3f
parent 4d01aaa458fd881b90b38268c37bff196cb82a0a
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sun, 13 Mar 2022 10:46:19 +0000
getelem
Diffstat:
M | richterm.c | | | 41 | +++++++++++++++++++++++++++++++++-------- |
1 file changed, 33 insertions(+), 8 deletions(-)
diff --git a/richterm.c b/richterm.c
@@ -19,6 +19,7 @@ void runcmd(void *);
void scroll(Point, Rich *);
void mouse(Mousectl *, Mouse, int *);
void insertfromcons(Array *);
+Elem *getelem(Point);
Rich rich;
int hostpid = -1;
@@ -160,6 +161,9 @@ threadmain(int argc, char **argv)
threadsetname("main");
+ char initmenu[] = "test\n";
+ arraygrow(menubuf, sizeof(initmenu), initmenu);
+
void *ov, *ov2;
enum {MOUSE, RESIZE, REDRAW, INSERT, KBD, AEND};
@@ -334,30 +338,31 @@ mouse(Mousectl *mc, Mouse mv, int *mmode)
}
break;
case MM_TEXT:
- break;
-
-/*
if (mv.buttons == 1) {
+ /*
selstart = getsel(mv.xy);
selend = selstart;
rich.selmin = selstart;
rich.selmax = selstart;
nbsend(redrawc, nil);
*mmode = MM_SELECT;
+ /*
} else if (mv.buttons == 2) {
+ /*
int f;
f = menuhit(2, mc, &mmenu, nil);
if (f >= 0) mfunc[f](&rich);
+ */
*mmode = MM_NONE;
} else if (mv.buttons == 4) {
int f;
- Object *obj;
- obj = getobj(mv.xy);
- if ((obj != nil) && (obj->dlink->count > 0)) {
+ Elem *e;
+ e = getelem(mv.xy);
+ if ((e != nil) && (e->link != nil)) {
f = menuhit(3, mc, &rmenu, nil);
if (f >= 0) {
if (f >= rsize - 1) ruseract(f - rsize + 1);
- else rfunc[f](obj);
+ else rfunc[f](e);
}
} else if (menubuf->count > 0) {
f = menuhit(3, mc, &rusermenu, nil);
@@ -366,7 +371,6 @@ mouse(Mousectl *mc, Mouse mv, int *mmode)
*mmode = MM_NONE;
}
break;
-*/
case MM_SELECT:
break;
@@ -1013,3 +1017,24 @@ freeelem(Elem *e)
e->pos = ZP;
e->nlpos = ZP;
}
+
+Elem *
+getelem(Point xy)
+{
+ int i;
+ Elem *e;
+ Point sp, np, ep;
+ for (i = 0; i < elems->count; i++) {
+ arrayget(elems, i, &e);
+ sp = e->pos;
+ np = e->nlpos;
+ ep = (e->next != nil) ? e->next->pos : Pt(rich.page.r.max.x, sp.y);
+ if (
+ (xy.y >= sp.y) &&
+ (xy.y < np.y) &&
+ (xy.x >= sp.x) &&
+ (xy.x < ep.x)
+ ) return e;
+ }
+ return nil;
+}