richterm

"terminal emulator" with support for text fonts and images for plan9
git clone git://nsmpr.xyz/richterm.git
Log | Files | Refs | README

commit fac7ef11a99555196c8352f87d9681039ff28593
parent f56f7fdca4c1f63604be5ab43bd5bb941c72b371
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Mon, 26 Jul 2021 12:59:23 +0000

add resize() func, separate Rectangle var for scrollbar

Diffstat:
Mrichterm.c | 36++++++++++++++++++++++++------------
Mrichterm.h | 1+
2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/richterm.c b/richterm.c @@ -18,6 +18,7 @@ Fsctl *fsctl; Fonts fonts; Image *Iscrollbar, *Ilink; +void resize(void); void shutdown(void); void send_interrupt(void); void runcmd(void *); @@ -64,10 +65,11 @@ threadmain(int argc, char **argv) rich.page.scroll = ZP; rich.page.view = nil; - rich.page.r = Rpt(addpt(screen->r.min, Pt(17, 1)), subpt(screen->r.max, Pt(1,1))); Iscrollbar = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x888888FF); Ilink = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DBlue); + + resize(); redraw(1); if ((mctl = initmouse(nil, screen)) == nil) @@ -90,8 +92,7 @@ threadmain(int argc, char **argv) case RESIZE: if (getwindow(display, Refnone) < 0) sysfatal("resize failed: %r"); - rich.page.r = Rpt(addpt(screen->r.min, Pt(17, 1)), subpt(screen->r.max, Pt(1,1))); - redraw(1); + resize(); break; case KBD: if (kv == 0x7f) shutdown(); @@ -356,22 +357,18 @@ void drawscrollbar(void) { double D; - Rectangle r, r2; - r = Rpt( - addpt(Pt(1,1), screen->r.min), - Pt(screen->r.min.x + 13, screen->r.max.y - 1) - ); + Rectangle r; D = (double)rich.page.max.y / (double)Dy(rich.page.r); if (D == 0) return; - r2 = rectaddpt(Rect( + r = rectaddpt(Rect( 0, rich.page.scroll.y / D, 11, (rich.page.scroll.y + Dy(rich.page.r)) / D - ), r.min); + ), rich.page.rs.min); - draw(screen, r, Iscrollbar, nil, ZP); - draw(screen, r2, display->white, nil, ZP); + draw(screen, rich.page.rs, Iscrollbar, nil, ZP); + draw(screen, r, display->white, nil, ZP); } void @@ -418,3 +415,17 @@ send_interrupt(void) if(hostpid > 0) postnote(PNGROUP, hostpid, "interrupt"); } + +void +resize(void) +{ + rich.page.rs = Rpt( + addpt(Pt(1,1), screen->r.min), + Pt(screen->r.min.x + 13, screen->r.max.y - 1) + ); + rich.page.r = Rpt( + addpt(screen->r.min, Pt(17, 1)), + subpt(screen->r.max, Pt(1,1)) + ); + redraw(1); +} +\ No newline at end of file diff --git a/richterm.h b/richterm.h @@ -52,6 +52,7 @@ struct Page { Point scroll; Point max; Rectangle r; + Rectangle rs; }; void drawview(Image *, View *);