about summary refs log tree commit diff stats
path: root/drw.h
blob: 819da85dcda7fdadb940369bb91ffb56a33b4e33 (plain) (blame)
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
/* See LICENSE file for copyright and license details. */

typedef struct {
	unsigned long rgb;
} Clr;

typedef struct {
	int ascent;
	int descent;
	unsigned int h;
	XFontSet set;
	XFontStruct *xfont;
} Fnt;

typedef struct {
	unsigned int w, h;
	Display *dpy;
	int screen;
	Window win;
	Drawable drwable;
	GC gc;
	Clr *fg;
	Clr *bg;
	Fnt *font;
} Drw;

typedef struct {
	unsigned int w;
	unsigned int h;
	int xOff;
	int yOff;
} Extnts;

/* Drawable abstraction */
Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h);
void drw_resize(Drw *drw, unsigned int w, unsigned int h);
void drw_free(Drw *drw);

/* Fnt abstraction */
Fnt *drw_font_create(Drw *drw, const char *fontname);
void drw_font_free(Drw *drw, Fnt *font);

/* Clrour abstraction */
Clr *drw_clr_create(Drw *drw, const char *clrname);
void drw_clr_free(Drw *drw, Clr *clr);

/* Drawing context manipulation */
void drw_setfont(Drw *drw, Fnt *font);
void drw_setfg(Drw *drw, Clr *clr);
void drw_setbg(Drw *drw, Clr *clr);

/* Drawing functions */
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, Bool filled, Bool empty, Bool invert);
void drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *text, Bool invert);

/* Map functions */
void drw_map(Drw *drw, int x, int y, unsigned int w, unsigned int h);

/* Text functions */
void drw_getexts(Drw *drw, const char *text, unsigned int len, Extnts *extnts);
an>PRE>(define (game low high) (let ((guess (average low high))) (cond ((too-low? guess) (game (+ guess 1) high)) ((too-high? guess) (game low (- guess 1))) (else '(I win!))))) </PRE> <P>This isn't a complete program because we haven't written <CODE>too-low?</CODE> and <CODE>too-high?</CODE>. But it illustrates the idea of a problem that contains a version of itself as a subproblem: We're asked to find a secret number within a given range. We make a guess, and if it's not the answer, we use that guess to create another problem in which the same secret number is known to be within a smaller range. The self-reference of the problem description is expressed in Scheme by a procedure that invokes itself as a subprocedure. <P>Actually, this isn't the first time we've seen self-reference in this book. We defined &quot;expression&quot; in Chapter 3 self-referentially: An expression is either atomic or composed of smaller expressions. <P>The idea of self-reference also comes up in some paradoxes: Is the sentence &quot;This sentence is false&quot; true or false? (If it's true, then it must also be false, since it says so; if it's false, then it must also be true, since that's the opposite of what it says.) This idea also appears in the self-referential shapes called <EM>fractals</EM> that are used to produce realistic-looking waves, clouds, mountains, and coastlines in computer-generated graphics. <P> </BIG> <HR> <P><A HREF="../ss-toc2.html">(back to Table of Contents)</A><P> <A HREF="../ssch10/ttt.html"><STRONG>BACK</STRONG></A> chapter thread <A HREF="recursion.html"><STRONG>NEXT</STRONG></A> <P> <ADDRESS> <A HREF="../index.html">Brian Harvey</A>, <CODE>bh@cs.berkeley.edu</CODE> </ADDRESS> </BODY> </HTML>