OLD | NEW |
1 #include <u.h> | 1 #include <u.h> |
2 #include <libc.h> | 2 #include <libc.h> |
3 #include <draw.h> | 3 #include <draw.h> |
4 #include <thread.h> | 4 #include <thread.h> |
5 #include <cursor.h> | 5 #include <cursor.h> |
6 #include <mouse.h> | 6 #include <mouse.h> |
7 #include <keyboard.h> | 7 #include <keyboard.h> |
8 #include <frame.h> | 8 #include <frame.h> |
9 #include <fcall.h> | 9 #include <fcall.h> |
10 #include <9pclient.h> | 10 #include <9pclient.h> |
(...skipping 17 matching lines...) Expand all Loading... |
28 static Image *cols[NCOL]; | 28 static Image *cols[NCOL]; |
29 static Image *grey; | 29 static Image *grey; |
30 static Image *darkgrey; | 30 static Image *darkgrey; |
31 static Cursor *lastcursor; | 31 static Cursor *lastcursor; |
32 static Image *titlecol; | 32 static Image *titlecol; |
33 static Image *lighttitlecol; | 33 static Image *lighttitlecol; |
34 static Image *holdcol; | 34 static Image *holdcol; |
35 static Image *lightholdcol; | 35 static Image *lightholdcol; |
36 static Image *paleholdcol; | 36 static Image *paleholdcol; |
37 | 37 |
| 38 static int |
| 39 wscale(Window *w, int n) |
| 40 { |
| 41 if(w == nil || w->i == nil) |
| 42 return n; |
| 43 return scalesize(w->i->display, n); |
| 44 } |
| 45 |
38 Window* | 46 Window* |
39 wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling) | 47 wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling) |
40 { | 48 { |
41 Window *w; | 49 Window *w; |
42 Rectangle r; | 50 Rectangle r; |
43 | 51 |
44 if(cols[0] == nil){ | 52 if(cols[0] == nil){ |
45 /* greys are multiples of 0x11111100+0xFF, 14* being palest */ | 53 /* greys are multiples of 0x11111100+0xFF, 14* being palest */ |
46 grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF); | 54 grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF); |
47 darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666
FF); | 55 darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666
FF); |
48 cols[BACK] = display->white; | 56 cols[BACK] = display->white; |
49 cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCC
CCFF); | 57 cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCC
CCFF); |
50 cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x9999
99FF); | 58 cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x9999
99FF); |
51 cols[TEXT] = display->black; | 59 cols[TEXT] = display->black; |
52 cols[HTEXT] = display->black; | 60 cols[HTEXT] = display->black; |
53 titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygre
en); | 61 titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygre
en); |
54 lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPa
legreygreen); | 62 lighttitlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPa
legreygreen); |
55 holdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue)
; | 63 holdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DMedblue)
; |
56 lightholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGre
yblue); | 64 lightholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGre
yblue); |
57 paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPale
greyblue); | 65 paleholdcol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DPale
greyblue); |
58 } | 66 } |
59 w = emalloc(sizeof(Window)); | 67 w = emalloc(sizeof(Window)); |
60 w->screenr = i->r; | 68 w->screenr = i->r; |
61 » r = insetrect(i->r, Selborder+1); | 69 » r = insetrect(i->r, wscale(w, Selborder)+wscale(w, 1)); |
62 w->i = i; | 70 w->i = i; |
63 w->mc = *mc; | 71 w->mc = *mc; |
64 w->ck = ck; | 72 w->ck = ck; |
65 w->cctl = cctl; | 73 w->cctl = cctl; |
66 w->cursorp = nil; | 74 w->cursorp = nil; |
67 w->conswrite = chancreate(sizeof(Conswritemesg), 0); | 75 w->conswrite = chancreate(sizeof(Conswritemesg), 0); |
68 w->consread = chancreate(sizeof(Consreadmesg), 0); | 76 w->consread = chancreate(sizeof(Consreadmesg), 0); |
69 w->mouseread = chancreate(sizeof(Mousereadmesg), 0); | 77 w->mouseread = chancreate(sizeof(Mousereadmesg), 0); |
70 w->wctlread = chancreate(sizeof(Consreadmesg), 0); | 78 w->wctlread = chancreate(sizeof(Consreadmesg), 0); |
71 w->scrollr = r; | 79 w->scrollr = r; |
72 » w->scrollr.max.x = r.min.x+Scrollwid; | 80 » w->scrollr.max.x = r.min.x+wscale(w, Scrollwid); |
73 w->lastsr = ZR; | 81 w->lastsr = ZR; |
74 » r.min.x += Scrollwid+Scrollgap; | 82 » r.min.x += wscale(w, Scrollwid)+wscale(w, Scrollgap); |
75 frinit(&w->f, r, font, i, cols); | 83 frinit(&w->f, r, font, i, cols); |
76 w->f.maxtab = maxtab*stringwidth(font, "0"); | 84 w->f.maxtab = maxtab*stringwidth(font, "0"); |
77 w->topped = ++topped; | 85 w->topped = ++topped; |
78 w->id = ++id; | 86 w->id = ++id; |
79 w->notefd = -1; | 87 w->notefd = -1; |
80 w->scrolling = scrolling; | 88 w->scrolling = scrolling; |
81 w->dir = estrdup(startdir); | 89 w->dir = estrdup(startdir); |
82 w->label = estrdup("<unnamed>"); | 90 w->label = estrdup("<unnamed>"); |
83 » r = insetrect(w->i->r, Selborder); | 91 » r = insetrect(w->i->r, wscale(w, Selborder)); |
84 draw(w->i, r, cols[BACK], nil, w->f.entire.min); | 92 draw(w->i, r, cols[BACK], nil, w->f.entire.min); |
85 » wborder(w, Selborder); | 93 » wborder(w, wscale(w, Selborder)); |
86 wscrdraw(w); | 94 wscrdraw(w); |
87 incref(&w->ref); /* ref will be removed after mounting; avoids de
lete before ready to be deleted */ | 95 incref(&w->ref); /* ref will be removed after mounting; avoids de
lete before ready to be deleted */ |
88 return w; | 96 return w; |
89 } | 97 } |
90 | 98 |
91 void | 99 void |
92 wsetname(Window *w) | 100 wsetname(Window *w) |
93 { | 101 { |
94 int i, n; | 102 int i, n; |
95 char err[ERRMAX]; | 103 char err[ERRMAX]; |
(...skipping 20 matching lines...) Expand all Loading... |
116 or = w->i->r; | 124 or = w->i->r; |
117 if(move || (Dx(or)==Dx(i->r) && Dy(or)==Dy(i->r))) | 125 if(move || (Dx(or)==Dx(i->r) && Dy(or)==Dy(i->r))) |
118 draw(i, i->r, w->i, nil, w->i->r.min); | 126 draw(i, i->r, w->i, nil, w->i->r.min); |
119 if(w->i != i){ | 127 if(w->i != i){ |
120 fprint(2, "res %p %p\n", w->i, i); | 128 fprint(2, "res %p %p\n", w->i, i); |
121 freeimage(w->i); | 129 freeimage(w->i); |
122 w->i = i; | 130 w->i = i; |
123 } | 131 } |
124 /* wsetname(w); */ | 132 /* wsetname(w); */ |
125 /*XXX w->mc.image = i; */ | 133 /*XXX w->mc.image = i; */ |
126 » r = insetrect(i->r, Selborder+1); | 134 » r = insetrect(i->r, wscale(w, Selborder)+wscale(w, 1)); |
127 w->scrollr = r; | 135 w->scrollr = r; |
128 » w->scrollr.max.x = r.min.x+Scrollwid; | 136 » w->scrollr.max.x = r.min.x+wscale(w, Scrollwid); |
129 w->lastsr = ZR; | 137 w->lastsr = ZR; |
130 » r.min.x += Scrollwid+Scrollgap; | 138 » r.min.x += wscale(w, Scrollwid)+wscale(w, Scrollgap); |
131 if(move) | 139 if(move) |
132 frsetrects(&w->f, r, w->i); | 140 frsetrects(&w->f, r, w->i); |
133 else{ | 141 else{ |
134 frclear(&w->f, FALSE); | 142 frclear(&w->f, FALSE); |
135 frinit(&w->f, r, w->f.font, w->i, cols); | 143 frinit(&w->f, r, w->f.font, w->i, cols); |
136 wsetcols(w); | 144 wsetcols(w); |
137 w->f.maxtab = maxtab*stringwidth(w->f.font, "0"); | 145 w->f.maxtab = maxtab*stringwidth(w->f.font, "0"); |
138 » » r = insetrect(w->i->r, Selborder); | 146 » » r = insetrect(w->i->r, wscale(w, Selborder)); |
139 draw(w->i, r, cols[BACK], nil, w->f.entire.min); | 147 draw(w->i, r, cols[BACK], nil, w->f.entire.min); |
140 wfill(w); | 148 wfill(w); |
141 wsetselect(w, w->q0, w->q1); | 149 wsetselect(w, w->q0, w->q1); |
142 wscrdraw(w); | 150 wscrdraw(w); |
143 } | 151 } |
144 » wborder(w, Selborder); | 152 » wborder(w, wscale(w, Selborder)); |
145 w->topped = ++topped; | 153 w->topped = ++topped; |
146 w->resized = TRUE; | 154 w->resized = TRUE; |
147 w->mouse.counter++; | 155 w->mouse.counter++; |
148 } | 156 } |
149 | 157 |
150 void | 158 void |
151 wrefresh(Window *w, Rectangle r) | 159 wrefresh(Window *w, Rectangle r) |
152 { | 160 { |
153 /* USED(r); */ | 161 /* USED(r); */ |
154 | 162 |
155 /* BUG: rectangle is ignored */ | 163 /* BUG: rectangle is ignored */ |
156 if(w == input) | 164 if(w == input) |
157 » » wborder(w, Selborder); | 165 » » wborder(w, wscale(w, Selborder)); |
158 else | 166 else |
159 » » wborder(w, Unselborder); | 167 » » wborder(w, wscale(w, Unselborder)); |
160 if(w->mouseopen) | 168 if(w->mouseopen) |
161 return; | 169 return; |
162 draw(w->i, insetrect(w->i->r, Borderwidth), w->f.cols[BACK], nil, w->i->
r.min); | 170 draw(w->i, insetrect(w->i->r, Borderwidth), w->f.cols[BACK], nil, w->i->
r.min); |
163 w->f.ticked = 0; | 171 w->f.ticked = 0; |
164 if(w->f.p0 > 0) | 172 if(w->f.p0 > 0) |
165 frdrawsel(&w->f, frptofchar(&w->f, 0), 0, w->f.p0, 0); | 173 frdrawsel(&w->f, frptofchar(&w->f, 0), 0, w->f.p0, 0); |
166 if(w->f.p1 < w->f.nchars) | 174 if(w->f.p1 < w->f.nchars) |
167 frdrawsel(&w->f, frptofchar(&w->f, w->f.p1), w->f.p1, w->f.nchar
s, 0); | 175 frdrawsel(&w->f, frptofchar(&w->f, w->f.p1), w->f.p1, w->f.nchar
s, 0); |
168 frdrawsel(&w->f, frptofchar(&w->f, w->f.p0), w->f.p0, w->f.p1, 1); | 176 frdrawsel(&w->f, frptofchar(&w->f, w->f.p0), w->f.p0, w->f.p1, 1); |
169 w->lastsr = ZR; | 177 w->lastsr = ZR; |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 } | 765 } |
758 | 766 |
759 void | 767 void |
760 wrepaint(Window *w) | 768 wrepaint(Window *w) |
761 { | 769 { |
762 wsetcols(w); | 770 wsetcols(w); |
763 if(!w->mouseopen){ | 771 if(!w->mouseopen){ |
764 frredraw(&w->f); | 772 frredraw(&w->f); |
765 } | 773 } |
766 if(w == input){ | 774 if(w == input){ |
767 » » wborder(w, Selborder); | 775 » » wborder(w, wscale(w, Selborder)); |
768 wsetcursor(w, 0); | 776 wsetcursor(w, 0); |
769 }else | 777 }else |
770 » » wborder(w, Unselborder); | 778 » » wborder(w, wscale(w, Unselborder)); |
771 } | 779 } |
772 | 780 |
773 int | 781 int |
774 wbswidth(Window *w, Rune c) | 782 wbswidth(Window *w, Rune c) |
775 { | 783 { |
776 uint q, eq, stop; | 784 uint q, eq, stop; |
777 Rune r; | 785 Rune r; |
778 int skipping; | 786 int skipping; |
779 | 787 |
780 /* there is known to be at least one character to erase */ | 788 /* there is known to be at least one character to erase */ |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 riosetcursor(&query, 1); | 891 riosetcursor(&query, 1); |
884 sleep(300); | 892 sleep(300); |
885 riosetcursor(c, 1); | 893 riosetcursor(c, 1); |
886 } | 894 } |
887 plumbfree(m); | 895 plumbfree(m); |
888 } | 896 } |
889 | 897 |
890 int | 898 int |
891 winborder(Window *w, Point xy) | 899 winborder(Window *w, Point xy) |
892 { | 900 { |
893 » return ptinrect(xy, w->screenr) && !ptinrect(xy, insetrect(w->screenr, S
elborder)); | 901 » return ptinrect(xy, w->screenr) && !ptinrect(xy, insetrect(w->screenr, w
scale(w, Selborder))); |
894 } | 902 } |
895 | 903 |
896 void | 904 void |
897 wmousectl(Window *w) | 905 wmousectl(Window *w) |
898 { | 906 { |
899 int but; | 907 int but; |
900 | 908 |
901 if(w->mc.m.buttons == 1) | 909 if(w->mc.m.buttons == 1) |
902 but = 1; | 910 but = 1; |
903 else if(w->mc.m.buttons == 2) | 911 else if(w->mc.m.buttons == 2) |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1666 frinsert(&w->f, rp, rp+i, w->f.nchars); | 1674 frinsert(&w->f, rp, rp+i, w->f.nchars); |
1667 }while(w->f.lastlinefull == FALSE); | 1675 }while(w->f.lastlinefull == FALSE); |
1668 free(rp); | 1676 free(rp); |
1669 } | 1677 } |
1670 | 1678 |
1671 char* | 1679 char* |
1672 wcontents(Window *w, int *ip) | 1680 wcontents(Window *w, int *ip) |
1673 { | 1681 { |
1674 return runetobyte(w->r, w->nr, ip); | 1682 return runetobyte(w->r, w->nr, ip); |
1675 } | 1683 } |
OLD | NEW |