aboutsummaryrefslogtreecommitdiff
path: root/man/man3/frame.3
blob: 1e063802c0c85908d10ecc0fe1d945f9c9114b57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
.TH FRAME 3
.SH NAME
frinit, frsetrects, frinittick, frclear, frcharofpt, frptofchar, frinsert, frdelete, frselect, frtick, frselectpaint, frdrawsel, frdrawsel0, frgetmouse \- frames of text
.SH SYNOPSIS
.nf
.B
#include <u.h>
.B
#include <libc.h>
.B
#include <draw.h>
.B
#include <thread.h>
.B
#include <mouse.h>
.B
#include <frame.h>
.PP
.B
void  frinit(Frame *f, Rectangle r, Font *ft, Image *b, Image **cols)
.PP
.B
void  frsetrects(Frame *f, Rectangle r, Image *b)
.PP
.B
void  frinittick(Frame *f)
.PP
.B
void  frclear(Frame *f, int resize)
.PP
.B
ulong frcharofpt(Frame *f, Point pt)
.PP
.B
Point frptofchar(Frame *f, ulong p)
.PP
.B
void  frinsert(Frame *f, Rune *r0, Rune *r1, ulong p)
.PP
.B
int   frdelete(Frame *f, ulong p0, ulong p1)
.PP
.B
void  frselect(Frame *f, Mousectl *m)
.PP
.B
void  frtick(Frame *f, Point pt, int up)
.PP
.B
void  frselectpaint(Frame *f, Point p0, Point p1, Image *col)
.PP
.B
void  frdrawsel(Frame *f, Point pt0, ulong p0, ulong p1,
.B
		int highlighted)
.PP
.B
void  frdrawsel0(Frame *f, Point pt0, ulong p0, ulong p1,
.B
		Image *back, Image *text)
.PP
.ft L
enum{
	BACK,
	HIGH,
	BORD,
	TEXT,
	HTEXT,
	NCOL
};
.fi
.SH DESCRIPTION
This library supports
.I frames
of editable text in a single font on raster displays, such as in
.IR sam (1)
and
.IR 9term (1).
Frames may hold any character except NUL (0).
Long lines are folded and tabs are at fixed intervals.
.PP
The user-visible data structure, a
.BR Frame ,
is defined in
.BR <frame.h> :
.IP
.EX
.ta 6n +\w'Rectangle 'u +\w'lastlinefull;   'u
typedef struct Frame Frame;
struct Frame
{
	Font	*font;		/* of chars in the frame */
	Display	*display;	/* on which frame appears */
	Image	*b;		/* on which frame appears */
	Image	*cols[NCOL];	/* text and background colors */
	Rectangle	r;		/* in which text appears */
	Rectangle	entire;		/* of full frame */
	Frbox	*box;
	ulong	p0, p1;		/* selection */
	ushort	nbox, nalloc;
	ushort	maxtab;		/* max size of tab, in pixels */
	ushort	nchars;		/* # runes in frame */
	ushort	nlines;		/* # lines with text */
	ushort	maxlines;	/* total # lines in frame */
	ushort	lastlinefull;	/* last line fills frame */
	ushort	modified;	/* changed since frselect() */
	Image	*tick;	/* typing tick */
	Image	*tickback;	/* saved image under tick */
	int	ticked;	/* flag: is tick onscreen? */
};
.EE
.PP
.B Frbox
is an internal type and is not used by the interface.
.B P0
and
.B p1
may be changed by the application provided the selection routines are called
afterwards to maintain a consistent display.
.I Maxtab
determines the size of tab stops.
.I Frinit
sets it to 8 times the width of a
.B 0
(zero)
character in the font;
it may be changed before any text is added to the frame.
The other elements of the structure are maintained by the library and
should not be modified directly.
.PP
The text within frames
is not directly addressable;
instead frames are designed to work alongside
another structure that holds the text.
The typical application is to display a section of a longer document such
as a text file or terminal session.
Usually the program will keep its own copy of the
text in the window (probably as
an array of
.BR Runes )
and pass components of this text to the frame routines to
display the visible portion.
Only the text that is visible is held by the
.BR Frame ;
the application must check
.BR maxlines ,
.BR nlines ,
and
.B lastlinefull
to determine, for example, whether new text needs to be appended
at the end of the
.B Frame
after calling
.I frdelete
(q.v.). 
.PP
There are no routines in the library to allocate
.BR Frames ;
instead the interface assumes that
.B Frames
will be components of larger structures.
.I Frinit
prepares the
.B Frame
.I f
so characters drawn in it will appear
in the single
.B Font
.IR ft .
It then calls
.I frsetrects
and
.I frinittick
to initialize the geometry for the
.BR Frame .
The
.B Image
.I b
is where the
.B Frame
is to be drawn;
.B Rectangle
.I r
defines the limit of the portion of the
.B Image
the text will occupy.
The
.B Image
pointer
may be null, allowing the other routines to be called to maintain the
associated data structure in, for example, an obscured window.
.PP
The array of
.B Images
cols sets the colors in which text and borders will be drawn.  The background of the frame will be drawn in
.BR cols[BACK] ;
the background of highlighted text in
.BR cols[HIGH] ;
borders and scroll bar in
.BR cols[BORD] ;
regular text in
.BR cols[TEXT] ;
and highlighted text in
.BR cols[HTEXT] .
.PP
.I Frclear
frees the internal structures associated with
.IR f ,
permitting another
.I frinit
or
.I frsetrects
on the
.BR Frame .
It does not clear the associated display.
If
.I f
is to be deallocated, the associated
.B Font
and
.B Image
must be freed separately.
The
.B resize
argument should be non-zero if the frame is to be redrawn with
a different font; otherwise the frame will maintain some
data structures associated with the font.
.PP
To resize a
.BR Frame ,
use
.I frclear
and
.I frinit
and then
.I frinsert
(q.v.) to recreate the display.
If a
.B Frame
is being moved but not resized, that is, if the shape of its containing
rectangle is unchanged, it is sufficient to use
.IR draw (3)
to copy the containing rectangle from the old to the new location and then call
.I frsetrects
to establish the new geometry.
(It is unnecessary to call
.I frinittick
unless the font size has changed.)
No redrawing is necessary.
.PP
.B Frames
hold text as runes,
not as bytes.
.I Frptofchar
returns the location of the upper left corner of the
.I p'th
rune, starting from 0, in the
.B Frame
.IR f .
If
.I f
holds fewer than
.I p
runes,
.I frptofchar
returns the location of the upper right corner of the last character in
.IR f .
.I Frcharofpt
is the inverse: it
returns the index of the closest rune whose image's upper left corner
is up and to the left of
.IR pt .
.PP
.I Frinsert
inserts into
.B Frame
.I f
starting at rune index
.I p
the runes between
.I r0
and
.IR r1 .
If a NUL (0) character
is inserted, chaos will ensue.
Tabs and newlines
are handled by the library, but all other characters,
including control characters, are just displayed.
For example, backspaces are printed; to erase
a character, use
.IR frdelete .
.PP
.I Frdelete
deletes from the
.B Frame
the text between
.I p0
and
.IR p1 ;
.I p1
points at the first rune beyond the deletion.
.PP
.I Frselect
tracks the mouse to select a contiguous string of text in the
.BR Frame .
When called, a mouse button is typically down.
.I Frselect
will return when the button state has changed (some buttons may
still be down) and will set
.IB f ->p0
and
.IB f ->p1
to the selected range of text.
.PP
Programs that wish to manage the selection themselves have several routines to help.
They involve the maintenance of the `tick', the vertical line indicating a null selection
between characters, and the colored region representing a non-null selection.
.I Frtick
draws (if
.I up
is non-zero) or removes (if
.I up
is zero) the tick at the screen position indicated by
.IR pt .
.I Frdrawsel
repaints a section of the frame, delimited by character positions
.I p0
and
.IR p1 ,
either with plain background or
entirely highlighted, according to the flag
.IR highlighted ,
managing the tick appropriately.
The point
.I pt0
is the geometrical location of
.I p0
on the screen; like all of the selection-helper routines'
.B Point
arguments, it must be a value generated by
.IR frptofchar .
.I Frdrawsel0
is a lower-level routine, taking as arguments a background color,
.IR back ,
and text color,
.IR text .
It assumes that the tick is being handled (removed beforehand, replaced afterwards, as required)
by its caller.
.I Frselectpaint
uses a solid color,
.IR col ,
to paint a region of the frame defined by the
.B Points
.I p0
and
.IR p1 .
.SH SOURCE
.B \*9/src/libframe
.SH SEE ALSO
.IR graphics (3),
.IR draw (3),
.IR cachechars (3).