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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
|
.de F
.B
.if !"\\$1"" \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6
..
.de L
.B
.if !"\\$1"" \&\\$1 \\$2 \\$3 \\$4 \\$5 \\$6
..
.de FR
.BR "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.de LR
.BR "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.de CW
.ft B
..
.\" This is gross but it avoids relying on internal implementation details
.\" of the -man macros.
.de TF
.IP "" \w'\fB\\$1\ \ \fP'u
.PD0
..
.de EX
.CW
.nf
..
.de EE
.fi
..
.\" delete above this point if your system has F, L, FR, LR, CW and TF macros
.TH GRAPHICS 3G
.SH NAME
Point, Rectangle, Bitmap, Cursor, xtbinit, bclose, berror, bscreenrect, bflush, clipr, cursorswitch, cursorset, rdfontfile, ffree, charwidth, getsubfont, mkfont, scrollfwdbut \- graphics
.SH SYNOPSIS
.nf
.PP
.B
#include <libc.h>
.B
#include <libg.h>
.PP
.ta \w'\fLRectangle 'u
.B
void xtbinit(void (*errfun)(char *), char *class, int *pargc,
.B
char **argv, char **fallbacks)
.PP
.B
void bclose(void)
.PP
.B
void berror(char *msg)
.PP
.B
Rectangle bscreenrect(Rectangle *clipr)
.PP
.B
void bflush(void)
.PP
.B
int clipr(Bitmap *b, Rectangle cr)
.PP
.B
void cursorswitch(Cursor *curs)
.PP
.B
void cursorset(Point p)
.PP
.B
Font* rdfontfile(char *name, int ldepth)
.PP
.B
void ffree(Font *f)
.PP
.B
int charwidth(Font *f, Rune r)
.PP
.B
Subfont *getsubfont(char *name)
.PP
.B
Font *mkfont(Subfont *subfont);
.PP
.B
int scrollfwdbut(void);
.PP
.B
extern Bitmap screen
.PP
.B
extern Font *font
.fi
.SH DESCRIPTION
A
.B Point
is a location in a bitmap
(see below),
such as the screen, and is defined as:
.IP
.EX
.ta 6n
typedef
struct Point {
int x;
int y;
} Point;
.EE
.PP
The coordinate system has
.I x
increasing to the right and
.I y
increasing down.
.PP
A
.B Rectangle
is a rectangular area in a bitmap.
.IP
.EX
.ta 6n
typedef
struct Rectangle {
Point min; /* upper left */
Point max; /* lower right */
} Rectangle;
.EE
.PP
By definition,
.B min.x <= max.x
and
.BR "min.y <= max.y" .
By convention, the right (maximum
.IR x )
and bottom (maximum
.IR y )
edges are
excluded from the represented rectangle, so abutting rectangles have no
points in common.
Thus,
.B max
contains the coordinates of the first point beyond the rectangle.
.PP
A
.B Bitmap
holds a rectangular image.
.IP
.EX
.ta 6n +\w'Rectangle 'u +\w'ldepth; 'u
typedef
struct Bitmap {
Rectangle r; /* rectangle in data area, local coords */
Rectangle clipr; /* clipping region */
int ldepth; /* log base 2 of number of bits per pixel */
int id; /* id as known in the X server */
Bitmap* cache; /* zero; distinguishes bitmap from layer */
int flag; /* flag used by X implementation of libg */
} Bitmap;
.EE
.PP
.B R.min
is the location in the bitmap
of the upper-leftmost point in the image.
There are
.if t .I 2\u\s8ldepth\s10\d
.if n 2^ldepth
contiguous bits for each pixel of the image;
the bits form a binary number giving the pixel value.
.L Clipr
is the clipping rectangle; typically it is the same as
.B r
except in a window, where it is inset by the width of
the border.
Graphical operations on the
.B Bitmap
will be confined to the clipping rectangle.
The subroutine
.I Clipr
sets the clipping rectangle of
.B b
to the intersection of
.B cr
and
.BR b->r .
If
.I cr
does not intersect
.BR b->r
it does nothing.
.I Clipr
returns 1 if the clipping region was set,
0 if it was not.
.PP
A
.B Font
is a set of character images, indexed by runes (see
.IR utf (4)).
The images are organized into
.BR Subfont s,
each containing the images for a small, contiguous set of runes.
.B Font
and
.B Subfont
structures contain two related fields:
.LR ascent ,
the distance from the top of the highest character
(actually the top of the bitmap holding all the characters)
to the baseline,
and
.LR height ,
the distance from the top of the highest character to the bottom of
the lowest character (and hence, the interline spacing).
The width of any particular character
.L r
in a font is returned by
.IR charwidth.
The width is defined as the amount to add to the horizontal position
after drawing the character.
.I Charwidth
calls the graphics error function if
.B r
is zero (NUL) because
.B string
(see
.IR bitblt (3))
cannot draw a NUL.
The other fields are used internally by the text-drawing functions.
See
.IR cachechars (3)
for a detailed description.
.PP
.I Rdfontfile
reads the font description in file
.I name
and returns a pointer that can by used by
.I string
(see
.IR bitblt (3))
to draw characters from the font.
The
.I ldepth
argument specifies how characters will be cached; it should usually
be the ldepth of the bitmap that will most often be the target of
.IR string .
[
.I ldepth
is unused in the X implementation of libg.]
.I Ffree
frees a font.
The convention for naming font files is:
.IP
.B \fIfontdir\fP/\fIname\fP.\fIrange\fP.\fIsize\fP.font
.PD
.PP
where
.I size
is approximately the height in pixels of the lower case letters
(without ascenders or descenders).
.I Range
gives some indication of which characters will be available: for example
.BR ascii ,
.BR latin1 ,
.BR euro ,
or
.BR unicode .
.B Euro
includes most European languages, punctuation marks, the International Phonetic
Alphabet, etc., but no Oriental languages.
.B Unicode
includes every character for which images exist on the system.
.PP
A font is selected by notifying the X server of the location
of the subfonts and then specifying the desired font file.
The directory containing the subfonts must be added to the
server's font search path using the
.B xset
command. For example,
.PP
.EX
xset +fp /usr/local/p9snf
.EE
.PP
adds the directory
.B /usr/local/p9snf
to the font search path.
The
.B p9font
resource contains the full path name
of the desired font file; it is usually specified in the
.B .Xdefaults
or
.B .xrdb
startup file. For example,
the entry:
.PP
.EX
*p9font: /n/pyxis/usr/local/p9fonts/pelm.unicode.9.font
.EE
.PP
selects the 9-point Pellucida Modern unicode font.
.PP
A
.I Cursor
is defined:
.IP
.EX
.ta 6n +\w'Point 'u
typedef struct
Cursor {
Point offset;
uchar clr[2*16];
uchar set[2*16];
} Cursor;
.EE
.PP
The arrays are arranged in rows, two bytes per row, left to
right in big-endian order to give 16 rows
of 16 bits each.
A cursor is displayed on the screen by adding
.B offset
to the current mouse position, using
.B clr
as a mask to zero the pixels where
.B clr
is 1, and then setting pixels to ones where
.B set
is one.
.PP
The function
.I xtbinit
should be called before using any graphics operations.
The
.I errfun
argument is a function that will be called with an error message
argument when the graphics functions detect an error;
such an error function should not return.
A zero for the
.I errfun
argument means use
.IR berror ,
which prints the message and exits.
The
.I class
argument is the name of the class of X application, or zero to
use the capitalized version of the program name.
The
.I pargc
and
.I argv
arguments should be a pointer to the main program's
.I argc
and
.IR argv ;
any standard toolkit options in the argument list will be used
to initialize the window's options, and after
.I xtbinit
returns, those options will have been removed from the argument list.
The
.I fallbacks
argument, when non-null, specifies a list of fallback resources
for the application.
.B Xtbinit
sets up the global
.I screen
to be a bitmap describing the area of the screen that the program
can use.
.I Xtbinit
also initializes the global default
.IR font .
By default,
.I xtbinit
does not install the standard Plan 9 colourmap, see
.IR rgbpix (3).
.PP
.I Bclose
releases the resources allocated by
.I xtbinit
and the other graphics functions.
It usually isn't necessary, since the resources will be released
on program exit. [
.I Bclose
is currently unimplemented.]
.PP
The
.IB screen .r
field is not guaranteed to be always accurate; the
.I bscreenrect
function returns the current size
(see
.IR event (3)
to see how to get reshape notification).
.PP
The mouse cursor is always displayed.
The initial cursor is an arrow.
.I Cursorswitch
causes the argument cursor to be displayed instead.
A zero argument causes a switch back to the arrow cursor.
.I Cursorset
moves the mouse cursor to position
.I p,
provided (if in a window) that the requesting program is
executing in the current window and the mouse is within
the window boundaries; otherwise
.I cursorset
is a no-op.
.PP
The graphics functions described in
.IR bitblt (3)
and
.IR balloc (3)
are implemented by writing commands to the X server;
the writes are buffered, so the functions may not take effect immediately.
.I Bflush
flushes the buffer, doing all pending graphics operations.
.I Xtbinit
arranges that
.I bflush
will be called on exit,
and the following graphics functions all cause a flush:
.IR balloc ,
.IR bfree ,
.IR bscreenrect ,
.IR cursorset ,
.IR cursorswitch ,
.IR ecankbd ,
.IR ecanmouse ,
.IR ekbd ,
.IR emouse ,
.IR event ,
.IR rdbitmap ,
and
.IR wrbitmap .
.PP
.I Getsubfont
attempts to load the font given by
.IR name ;
it returns a pointer to a
.B Subfont
struct if it succeeds, zero otherwise,
see
.IR font (4).
The subfont returned by
.I getsubfont
may be passed to
.I mkfont
to generate a
.B Font
suitable for use in
.IR string .
.PP
.I Scrollfwdbut
returns 3 or 1 depending on which buttons is to be used
as the forward scrolling button on the mouse.
The default is to return 3.
.SH "X DEFAULTS"
LibXg understands all of the core X Toolkit resource names and
classes as well as:
.TP 8
.B "p9font (\fPclass\fB P9font)"
Specifies the path name of a font file.
If the file does not exist or is not a properly formatted
font file, the default X11 font directory is searched for an
X11 font of the same name.
.TP 8
.B "composeMod (\fPclass\fB ComposeMod)"
Specifies the modifier key to be used in composing characters.
The integers 1 to 5 correspond to using modifier keys 1 to 5.
When this resource is non-zero it is only necessary to press the
compose modifier once before beginning a compose sequence, i.e.,
it need not be held down for any of the characters in the sequence.
A zero for
.B composeMod
means use modifier key 1 and this key must be held down in conjuction
with the first key of the sequence.
.TP 8
.B "scrollForwardR (\fPclass\fB ScrollForwardR)"
The value
.I true
for this resource
reverses the value returned by
.IR scrollfwdbut ,
i.e., it returns 3 instead of 1.
This reverses the scroll direction selected by clicks of the left or
right mouse buttons in the scrollbar.
.SH "SEE ALSO"
.IR add (3),
.IR balloc (3),
.IR cachechars (3),
.IR bitblt (3),
.IR event (3),
.IR frame (3),
.IR rgbpix (3),
.IR bitmap (4),
.IR font (4).
.SH DIAGNOSTICS
An error function may call
.IR errstr (2)
for further diagnostics.
|