ref: 22b3929f26e4c8cf771358da9f3785c76c048a3a
parent: 1bfa8e43df6e6b3d160c6f0308dd3cf617aea536
author: spew <spew@palas>
date: Mon Feb 3 15:24:15 EST 2025
start to implement more mouse stuff
--- a/guitest.c
+++ b/guitest.c
@@ -20,9 +20,12 @@
MOUSE,
KEYBD,
RESIZE,
- MOUSENICKS,
- KEYBDNICKS,
- RESIZENICKS,
+ NICKSMOUSE,
+ NICKSKEYBD,
+ NICKSRESIZE,
+ CMDMOUSE,
+ CMDKEYBD,
+ CMDRESIZE,
NCHAN,
Scrollwid = 12, /* width of scroll bar */
@@ -86,13 +89,13 @@
scrpos = t->scrollr;
if(t->nlines > 0){
- scrpos.min.y = scrpos.min.y+max(0, Dy(scrpos))*t->topline/t->nlines;
+ scrpos.min.y = scrpos.min.y+max(0, Dy(scrpos))*t->origin/t->nlines;
scrpos.max.y = scrpos.min.y+Dy(t->scrollr)*t->Frame.maxlines/t->nlines;
}
scrpos = insetrect(scrpos, 1);
draw(screen, scrpos, t->cols[BACK], nil, ZP);
- frinsert(t, t->text + t->lines[t->topline], t->text + t->textlen, 0);
+ frinsert(t, t->text + t->lines[t->origin], t->text + t->textlen, 0);
flushimage(display, 1);
}
@@ -119,7 +122,7 @@
t->linescap = 1024;
t->lines = emallocz(t->linescap*sizeof(*t->lines), 1);
t->nlines = 0;
- t->topline = 0;
+ t->origin = 0;
}
frclear(t, 0);
@@ -184,9 +187,9 @@
}
void
-texttopline(Text *t, int y)
+textorigin(Text *t, int y)
{
- t->topline = min(max(0, y-t->scrollr.min.y)*t->nlines/Dy(t->scrollr), t->nlines-1);
+ t->origin = min(max(0, y-t->scrollr.min.y)*t->nlines/Dy(t->scrollr), t->nlines-1);
}
void
@@ -202,6 +205,30 @@
}
void
+textscroll(Text *t, Mousectl *mc)
+{
+ while(mc->buttons == 2){
+ textorigin(t, mc->xy.y);
+ textdraw(t);
+ readmouse(mc);
+ }
+ while(mc->buttons == 1){
+ t->origin = max(0, t->origin-1);
+ textdraw(t);
+ readmouse(mc);
+ }
+}
+
+void
+textmouse(Text *t, Mousectl *mc)
+{
+ if(ptinrect(mc->xy, t->scrollr)){
+ textscroll(t, mc);
+ return;
+ }
+}
+
+void
initmousekbd(char *wsys, Image *screen, Mousectl **mc, Keyboardctl **kc)
{
static char s[512];
@@ -218,9 +245,8 @@
threadmain(int argc, char **argv)
{
Chan *chan;
- Keyboardctl *kc, *nickskc;
- Mouse m;
- Mousectl *mc, *nicksmc;
+ Keyboardctl *kc, *nickskc, *cmdkc;
+ Mousectl *mc, *nicksmc, *cmdmc;
Rune r, *rs;
Rectangle dim;
Text *cmd;
@@ -314,49 +340,46 @@
initmousekbd("/dev", screen, &mc, &kc);
initmousekbd(nickswsys, nicksscreen, &nicksmc, &nickskc);
+ initmousekbd(cmdwsys, cmdscreen, &cmdmc, &cmdkc);
Alt a[NCHAN+1] = {
- [MOUSE] {mc->c, &m, CHANRCV},
- [MOUSENICKS] {nicksmc->c, &m, CHANRCV},
- [RESIZE] {mc->resizec, nil, CHANRCV},
- [RESIZENICKS] {nicksmc->resizec, nil, CHANRCV},
+ [MOUSE] {mc->c, nil, CHANRCV},
[KEYBD] {kc->c, &r, CHANRCV},
- [KEYBDNICKS] {nickskc->c, &r, CHANRCV},
+ [RESIZE] {mc->resizec, nil, CHANRCV},
+ [NICKSMOUSE] {nicksmc->c, nil, CHANRCV},
+ [NICKSKEYBD] {nickskc->c, &r, CHANRCV},
+ [NICKSRESIZE] {nicksmc->resizec, nil, CHANRCV},
+ [CMDMOUSE] {cmdmc->c, nil, CHANRCV},
+ [CMDKEYBD] {cmdkc->c, &r, CHANRCV},
+ [CMDRESIZE] {cmdmc->resizec, nil, CHANRCV},
[NCHAN] {nil, nil, CHANEND},
};
for(;;)switch(alt(a)){
default:
break;
- case KEYBDNICKS:
+ case NICKSKEYBD:
+ case CMDKEYBD:
case KEYBD:
if(r == Kdel)
goto end;
break;
case MOUSE:
- if(!ptinrect(m.xy, chan->body.scrollr))
- break;
- while(m.buttons == 2){
- texttopline(&chan->body, m.xy.y);
- textdraw(&chan->body);
- readmouse(mc);
- m = *mc;
- }
+ textmouse(&chan->body, mc);
break;
- case MOUSENICKS:
- if(!ptinrect(m.xy, chan->nicks.scrollr))
- break;
- while(m.buttons == 2){
- texttopline(&chan->nicks, m.xy.y);
- textdraw(&chan->nicks);
- readmouse(nicksmc);
- m = *nicksmc;
- }
+ case NICKSMOUSE:
+ textmouse(&chan->nicks, nicksmc);
break;
+ case CMDMOUSE:
+ textmouse(cmd, cmdmc);
+ break;
case RESIZE:
textresize(&chan->body);
break;
- case RESIZENICKS:
+ case NICKSRESIZE:
textresize(&chan->nicks);
+ break;
+ case CMDRESIZE:
+ textresize(cmd);
break;
}
end:
--- a/mez.h
+++ b/mez.h
@@ -12,7 +12,7 @@
struct Text {
Frame;
Rune *text;
- uint textlen, topline, nlines, linescap, textcap, *lines;
+ uint textlen, origin, nlines, linescap, textcap, *lines;
Rectangle scrollr, bodyr;
Image **screen, *cols[NCOL];
Screen **_screen;