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
|
enum {
Pbackground,
Pborder,
Pmargin,
Ppadding,
Porientation,
Pbordercolour,
Ptext,
Ptextcolour,
Pmax,
};
enum {
nbaseprops = 5
};
enum {
Gcontainer,
Gtextbox,
Gmax,
};
enum {
Horizontal,
Vertical,
Up,
Down,
};
enum {
Xmousedown,
Xmouseup,
Xmouseclick,
Xmousescroll,
Xkeyboard,
Xmax,
};
typedef struct Colour Colour;
typedef struct Spacing Spacing;
typedef union PropVal PropVal;
typedef struct PropSpec PropSpec;
typedef struct Prop Prop;
typedef struct Event Event;
typedef struct GuiSpec GuiSpec;
typedef struct GuiElement GuiElement;
struct Colour {
Image *image;
ulong code;
};
struct Spacing {
int up;
int right;
int down;
int left;
};
union PropVal {
Colour *colour;
Spacing *spacing;
int orientation;
Rune *text;
};
struct PropSpec {
char *name;
PropVal (*def)(int, int);
char *(*print)(PropVal);
char *(*parse)(char *, PropVal *);
};
struct Prop {
int tag;
PropVal val;
Qid qid;
};
struct Event {
int type;
union {
Mouse m;
Rune r;
int direction;
};
};
struct GuiSpec {
char *name;
void (*draw)(GuiElement *);
void (*layout)(GuiElement *, Rectangle);
int leafnode;
int nprops;
int *proptags;
};
struct GuiElement {
RWLock lock;
int type;
int id;
Qid qid;
Qid qclone;
Qid qevent;
Qid qtype;
Qid qprops;
int nchildren;
GuiElement **children;
GuiElement *parent;
int nprops;
Prop *props;
uvlong listening; /* the user is reading from the 'event' file. Bitmask of which events are wanted */
Channel *events;
char *currentevents;
int buttons;
Rectangle border;
Rectangle rect;
Rectangle content;
};
extern Point mousexy;
extern GuiElement *root;
extern PropSpec propspecs[Pmax];
extern GuiSpec guispecs[Gmax];
extern int baseprops[nbaseprops];
void *emalloc(ulong);
int allspace(char *);
Colour *mkcolour(ulong);
void initgraphics(void);
void layout(GuiElement *, Rectangle);
void updategui(int);
void drawcontainer(GuiElement *);
void drawtextbox(GuiElement *);
void layoutcontainer(GuiElement *, Rectangle);
void layouttextbox(GuiElement *, Rectangle);
PropVal getprop(GuiElement *, int, int);
void setprop(GuiElement *, int, PropVal, int);
int mouseevent(Mouse);
int keyboardevent(Rune);
|