mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
Initial import.
This commit is contained in:
parent
b822e0d803
commit
a59ea66fa9
5 changed files with 1548 additions and 0 deletions
6
src/cmd/samterm/acid
Normal file
6
src/cmd/samterm/acid
Normal file
|
@ -0,0 +1,6 @@
|
|||
include("/sys/src/cmd/drawsamterm/syms");
|
||||
|
||||
defn x(){
|
||||
print("font->cacheimage: ", font->cacheimage\X, "\n");
|
||||
print(" display: ", font->cacheimage.display\X, "\n");
|
||||
}
|
52
src/cmd/samterm/icons.c
Normal file
52
src/cmd/samterm/icons.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <draw.h>
|
||||
#include <thread.h>
|
||||
#include <mouse.h>
|
||||
#include <cursor.h>
|
||||
#include <keyboard.h>
|
||||
#include <frame.h>
|
||||
#include "flayer.h"
|
||||
#include "samterm.h"
|
||||
|
||||
Cursor bullseye={
|
||||
{-7, -7},
|
||||
{0x1F, 0xF8, 0x3F, 0xFC, 0x7F, 0xFE, 0xFB, 0xDF,
|
||||
0xF3, 0xCF, 0xE3, 0xC7, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xE3, 0xC7, 0xF3, 0xCF,
|
||||
0x7B, 0xDF, 0x7F, 0xFE, 0x3F, 0xFC, 0x1F, 0xF8,},
|
||||
{0x00, 0x00, 0x0F, 0xF0, 0x31, 0x8C, 0x21, 0x84,
|
||||
0x41, 0x82, 0x41, 0x82, 0x41, 0x82, 0x7F, 0xFE,
|
||||
0x7F, 0xFE, 0x41, 0x82, 0x41, 0x82, 0x41, 0x82,
|
||||
0x21, 0x84, 0x31, 0x8C, 0x0F, 0xF0, 0x00, 0x00,}
|
||||
};
|
||||
Cursor deadmouse={
|
||||
{-7, -7},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x0C, 0x00, 0x8E, 0x1D, 0xC7,
|
||||
0xFF, 0xE3, 0xFF, 0xF3, 0xFF, 0xFF, 0x7F, 0xFE,
|
||||
0x3F, 0xF8, 0x17, 0xF0, 0x03, 0xE0, 0x00, 0x00,},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x08, 0x00, 0x04, 0x00, 0x82,
|
||||
0x04, 0x41, 0xFF, 0xE1, 0x5F, 0xF1, 0x3F, 0xFE,
|
||||
0x17, 0xF0, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00,}
|
||||
};
|
||||
Cursor lockarrow={
|
||||
{-7, -7},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,},
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x0F, 0xC0,
|
||||
0x03, 0xC0, 0x07, 0xC0, 0x0E, 0xC0, 0x1C, 0xC0,
|
||||
0x38, 0x00, 0x70, 0x00, 0xE0, 0xDB, 0xC0, 0xDB,}
|
||||
};
|
||||
|
||||
Image *darkgrey;
|
||||
|
||||
void
|
||||
iconinit(void)
|
||||
{
|
||||
darkgrey = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, 0x444444FF);
|
||||
}
|
266
src/cmd/samterm/rasp.c
Normal file
266
src/cmd/samterm/rasp.c
Normal file
|
@ -0,0 +1,266 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <draw.h>
|
||||
#include <thread.h>
|
||||
#include <mouse.h>
|
||||
#include <cursor.h>
|
||||
#include <keyboard.h>
|
||||
#include <frame.h>
|
||||
#include "flayer.h"
|
||||
#include "samterm.h"
|
||||
|
||||
void
|
||||
rinit(Rasp *r)
|
||||
{
|
||||
r->nrunes=0;
|
||||
r->sect=0;
|
||||
}
|
||||
|
||||
void
|
||||
rclear(Rasp *r)
|
||||
{
|
||||
Section *s, *ns;
|
||||
|
||||
for(s=r->sect; s; s=ns){
|
||||
ns = s->next;
|
||||
free(s->text);
|
||||
free(s);
|
||||
}
|
||||
r->sect = 0;
|
||||
}
|
||||
|
||||
Section*
|
||||
rsinsert(Rasp *r, Section *s) /* insert before s */
|
||||
{
|
||||
Section *t;
|
||||
Section *u;
|
||||
|
||||
t = alloc(sizeof(Section));
|
||||
if(r->sect == s){ /* includes empty list case: r->sect==s==0 */
|
||||
r->sect = t;
|
||||
t->next = s;
|
||||
}else{
|
||||
u = r->sect;
|
||||
if(u == 0)
|
||||
panic("rsinsert 1");
|
||||
do{
|
||||
if(u->next == s){
|
||||
t->next = s;
|
||||
u->next = t;
|
||||
goto Return;
|
||||
}
|
||||
u=u->next;
|
||||
}while(u);
|
||||
panic("rsinsert 2");
|
||||
}
|
||||
Return:
|
||||
return t;
|
||||
}
|
||||
|
||||
void
|
||||
rsdelete(Rasp *r, Section *s)
|
||||
{
|
||||
Section *t;
|
||||
|
||||
if(s == 0)
|
||||
panic("rsdelete");
|
||||
if(r->sect == s){
|
||||
r->sect = s->next;
|
||||
goto Free;
|
||||
}
|
||||
for(t=r->sect; t; t=t->next)
|
||||
if(t->next == s){
|
||||
t->next = s->next;
|
||||
Free:
|
||||
if(s->text)
|
||||
free(s->text);
|
||||
free(s);
|
||||
return;
|
||||
}
|
||||
panic("rsdelete 2");
|
||||
}
|
||||
|
||||
void
|
||||
splitsect(Rasp *r, Section *s, long n0)
|
||||
{
|
||||
if(s == 0)
|
||||
panic("splitsect");
|
||||
rsinsert(r, s->next);
|
||||
if(s->text == 0)
|
||||
s->next->text = 0;
|
||||
else{
|
||||
s->next->text = alloc(RUNESIZE*(TBLOCKSIZE+1));
|
||||
Strcpy(s->next->text, s->text+n0);
|
||||
s->text[n0] = 0;
|
||||
}
|
||||
s->next->nrunes = s->nrunes-n0;
|
||||
s->nrunes = n0;
|
||||
}
|
||||
|
||||
Section *
|
||||
findsect(Rasp *r, Section *s, long p, long q) /* find sect containing q and put q on a sect boundary */
|
||||
{
|
||||
if(s==0 && p!=q)
|
||||
panic("findsect");
|
||||
for(; s && p+s->nrunes<=q; s=s->next)
|
||||
p += s->nrunes;
|
||||
if(p != q){
|
||||
splitsect(r, s, q-p);
|
||||
s = s->next;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
rresize(Rasp *r, long a, long old, long new)
|
||||
{
|
||||
Section *s, *t, *ns;
|
||||
|
||||
s = findsect(r, r->sect, 0L, a);
|
||||
t = findsect(r, s, a, a+old);
|
||||
for(; s!=t; s=ns){
|
||||
ns=s->next;
|
||||
rsdelete(r, s);
|
||||
}
|
||||
/* now insert the new piece before t */
|
||||
if(new > 0){
|
||||
ns=rsinsert(r, t);
|
||||
ns->nrunes=new;
|
||||
ns->text=0;
|
||||
}
|
||||
r->nrunes += new-old;
|
||||
}
|
||||
|
||||
void
|
||||
rdata(Rasp *r, long p0, long p1, Rune *cp)
|
||||
{
|
||||
Section *s, *t, *ns;
|
||||
|
||||
s = findsect(r, r->sect, 0L, p0);
|
||||
t = findsect(r, s, p0, p1);
|
||||
for(; s!=t; s=ns){
|
||||
ns=s->next;
|
||||
if(s->text)
|
||||
panic("rdata");
|
||||
rsdelete(r, s);
|
||||
}
|
||||
p1 -= p0;
|
||||
s = rsinsert(r, t);
|
||||
s->text = alloc(RUNESIZE*(TBLOCKSIZE+1));
|
||||
memmove(s->text, cp, RUNESIZE*p1);
|
||||
s->text[p1] = 0;
|
||||
s->nrunes = p1;
|
||||
}
|
||||
|
||||
void
|
||||
rclean(Rasp *r)
|
||||
{
|
||||
Section *s;
|
||||
|
||||
for(s=r->sect; s; s=s->next)
|
||||
while(s->next && (s->text!=0)==(s->next->text!=0)){
|
||||
if(s->text){
|
||||
if(s->nrunes+s->next->nrunes>TBLOCKSIZE)
|
||||
break;
|
||||
Strcpy(s->text+s->nrunes, s->next->text);
|
||||
}
|
||||
s->nrunes += s->next->nrunes;
|
||||
rsdelete(r, s->next);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Strcpy(Rune *to, Rune *from)
|
||||
{
|
||||
do; while(*to++ = *from++);
|
||||
}
|
||||
|
||||
Rune*
|
||||
rload(Rasp *r, ulong p0, ulong p1, ulong *nrp)
|
||||
{
|
||||
Section *s;
|
||||
long p;
|
||||
int n, nb;
|
||||
|
||||
nb = 0;
|
||||
Strgrow(&scratch, &nscralloc, p1-p0+1);
|
||||
scratch[0] = 0;
|
||||
for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next)
|
||||
p += s->nrunes;
|
||||
while(p<p1 && s){
|
||||
/*
|
||||
* Subtle and important. If we are preparing to handle an 'rdata'
|
||||
* call, it's because we have an 'rresize' hole here, so the
|
||||
* screen doesn't have data for that space anyway (it got cut
|
||||
* first). So pretend it isn't there.
|
||||
*/
|
||||
if(s->text){
|
||||
n = s->nrunes-(p0-p);
|
||||
if(n>p1-p0) /* all in this section */
|
||||
n = p1-p0;
|
||||
memmove(scratch+nb, s->text+(p0-p), n*RUNESIZE);
|
||||
nb += n;
|
||||
scratch[nb] = 0;
|
||||
}
|
||||
p += s->nrunes;
|
||||
p0 = p;
|
||||
s = s->next;
|
||||
}
|
||||
if(nrp)
|
||||
*nrp = nb;
|
||||
return scratch;
|
||||
}
|
||||
|
||||
int
|
||||
rmissing(Rasp *r, ulong p0, ulong p1)
|
||||
{
|
||||
Section *s;
|
||||
long p;
|
||||
int n, nm=0;
|
||||
|
||||
for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next)
|
||||
p += s->nrunes;
|
||||
while(p<p1 && s){
|
||||
if(s->text == 0){
|
||||
n = s->nrunes-(p0-p);
|
||||
if(n > p1-p0) /* all in this section */
|
||||
n = p1-p0;
|
||||
nm += n;
|
||||
}
|
||||
p += s->nrunes;
|
||||
p0 = p;
|
||||
s = s->next;
|
||||
}
|
||||
return nm;
|
||||
}
|
||||
|
||||
int
|
||||
rcontig(Rasp *r, ulong p0, ulong p1, int text)
|
||||
{
|
||||
Section *s;
|
||||
long p, n;
|
||||
int np=0;
|
||||
|
||||
for(p=0,s=r->sect; s && p+s->nrunes<=p0; s=s->next)
|
||||
p += s->nrunes;
|
||||
while(p<p1 && s && (text? (s->text!=0) : (s->text==0))){
|
||||
n = s->nrunes-(p0-p);
|
||||
if(n > p1-p0) /* all in this section */
|
||||
n = p1-p0;
|
||||
np += n;
|
||||
p += s->nrunes;
|
||||
p0 = p;
|
||||
s = s->next;
|
||||
}
|
||||
return np;
|
||||
}
|
||||
|
||||
void
|
||||
Strgrow(Rune **s, long *n, int want) /* can always toss the old data when called */
|
||||
{
|
||||
if(*n >= want)
|
||||
return;
|
||||
free(*s);
|
||||
*s = alloc(RUNESIZE*want);
|
||||
*n = want;
|
||||
}
|
169
src/cmd/samterm/scroll.c
Normal file
169
src/cmd/samterm/scroll.c
Normal file
|
@ -0,0 +1,169 @@
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <draw.h>
|
||||
#include <thread.h>
|
||||
#include <mouse.h>
|
||||
#include <cursor.h>
|
||||
#include <keyboard.h>
|
||||
#include <frame.h>
|
||||
#include "flayer.h"
|
||||
#include "samterm.h"
|
||||
|
||||
static Image *scrtmp;
|
||||
static Image *scrback;
|
||||
|
||||
void
|
||||
scrtemps(void)
|
||||
{
|
||||
int h;
|
||||
|
||||
if(scrtmp)
|
||||
return;
|
||||
if(screensize(0, &h) == 0)
|
||||
h = 2048;
|
||||
scrtmp = allocimage(display, Rect(0, 0, 32, h), screen->chan, 0, 0);
|
||||
scrback = allocimage(display, Rect(0, 0, 32, h), screen->chan, 0, 0);
|
||||
if(scrtmp==0 || scrback==0)
|
||||
panic("scrtemps");
|
||||
}
|
||||
|
||||
Rectangle
|
||||
scrpos(Rectangle r, long p0, long p1, long tot)
|
||||
{
|
||||
Rectangle q;
|
||||
int h;
|
||||
|
||||
q = r;
|
||||
h = q.max.y-q.min.y;
|
||||
if(tot == 0)
|
||||
return q;
|
||||
if(tot > 1024L*1024L)
|
||||
tot>>=10, p0>>=10, p1>>=10;
|
||||
if(p0 > 0)
|
||||
q.min.y += h*p0/tot;
|
||||
if(p1 < tot)
|
||||
q.max.y -= h*(tot-p1)/tot;
|
||||
if(q.max.y < q.min.y+2){
|
||||
if(q.min.y+2 <= r.max.y)
|
||||
q.max.y = q.min.y+2;
|
||||
else
|
||||
q.min.y = q.max.y-2;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
|
||||
void
|
||||
scrmark(Flayer *l, Rectangle r)
|
||||
{
|
||||
r.max.x--;
|
||||
if(rectclip(&r, l->scroll))
|
||||
draw(l->f.b, r, l->f.cols[HIGH], nil, ZP);
|
||||
}
|
||||
|
||||
void
|
||||
scrunmark(Flayer *l, Rectangle r)
|
||||
{
|
||||
if(rectclip(&r, l->scroll))
|
||||
draw(l->f.b, r, scrback, nil, Pt(0, r.min.y-l->scroll.min.y));
|
||||
}
|
||||
|
||||
void
|
||||
scrdraw(Flayer *l, long tot)
|
||||
{
|
||||
Rectangle r, r1, r2;
|
||||
Image *b;
|
||||
|
||||
scrtemps();
|
||||
if(l->f.b == 0)
|
||||
panic("scrdraw");
|
||||
r = l->scroll;
|
||||
r1 = r;
|
||||
if(l->visible == All){
|
||||
b = scrtmp;
|
||||
r1.min.x = 0;
|
||||
r1.max.x = Dx(r);
|
||||
}else
|
||||
b = l->f.b;
|
||||
r2 = scrpos(r1, l->origin, l->origin+l->f.nchars, tot);
|
||||
if(!eqrect(r2, l->lastsr)){
|
||||
l->lastsr = r2;
|
||||
draw(b, r1, l->f.cols[BORD], nil, ZP);
|
||||
draw(b, r2, l->f.cols[BACK], nil, r2.min);
|
||||
r2 = r1;
|
||||
r2.min.x = r2.max.x-1;
|
||||
draw(b, r2, l->f.cols[BORD], nil, ZP);
|
||||
if(b!=l->f.b)
|
||||
draw(l->f.b, r, b, nil, r1.min);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
scroll(Flayer *l, int but)
|
||||
{
|
||||
int in = 0, oin;
|
||||
long tot = scrtotal(l);
|
||||
Rectangle scr, r, s, rt;
|
||||
int x, y, my, oy, h;
|
||||
long p0;
|
||||
|
||||
s = l->scroll;
|
||||
x = s.min.x+FLSCROLLWID/2;
|
||||
scr = scrpos(l->scroll, l->origin, l->origin+l->f.nchars, tot);
|
||||
r = scr;
|
||||
y = scr.min.y;
|
||||
my = mousep->xy.y;
|
||||
draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
|
||||
do{
|
||||
oin = in;
|
||||
in = abs(x-mousep->xy.x)<=FLSCROLLWID/2;
|
||||
if(oin && !in)
|
||||
scrunmark(l, r);
|
||||
if(in){
|
||||
scrmark(l, r);
|
||||
oy = y;
|
||||
my = mousep->xy.y;
|
||||
if(my < s.min.y)
|
||||
my = s.min.y;
|
||||
if(my >= s.max.y)
|
||||
my = s.max.y;
|
||||
if(!eqpt(mousep->xy, Pt(x, my)))
|
||||
moveto(mousectl, Pt(x, my));
|
||||
if(but == 1){
|
||||
p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my));
|
||||
rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
|
||||
y = rt.min.y;
|
||||
}else if(but == 2){
|
||||
y = my;
|
||||
if(y > s.max.y-2)
|
||||
y = s.max.y-2;
|
||||
}else if(but == 3){
|
||||
p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my));
|
||||
rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
|
||||
y = rt.min.y;
|
||||
}
|
||||
if(y != oy){
|
||||
scrunmark(l, r);
|
||||
r = rectaddpt(scr, Pt(0, y-scr.min.y));
|
||||
scrmark(l, r);
|
||||
}
|
||||
}
|
||||
}while(button(but));
|
||||
if(in){
|
||||
h = s.max.y-s.min.y;
|
||||
scrunmark(l, r);
|
||||
p0 = 0;
|
||||
if(but == 1)
|
||||
p0 = (long)(my-s.min.y)/l->f.font->height+1;
|
||||
else if(but == 2){
|
||||
if(tot > 1024L*1024L)
|
||||
p0 = ((tot>>10)*(y-s.min.y)/h)<<10;
|
||||
else
|
||||
p0 = tot*(y-s.min.y)/h;
|
||||
}else if(but == 3){
|
||||
p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my));
|
||||
if(p0 > tot)
|
||||
p0 = tot;
|
||||
}
|
||||
scrorigin(l, but, p0);
|
||||
}
|
||||
}
|
1055
src/cmd/samterm/syms
Normal file
1055
src/cmd/samterm/syms
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue