11 #define MAX_STACK_DEPTH 4
12 static struct layout st[MAX_STACK_DEPTH];
15 int imtk_layout_push(void)
19 assert(newtop < MAX_STACK_DEPTH);
20 if(newtop >= MAX_STACK_DEPTH) {
24 st[newtop] = st[top++];
28 int imtk_layout_pop(void)
38 void imtk_layout_start(int x, int y)
40 st[top].box[0] = st[top].span[0] = x;
41 st[top].box[1] = st[top].span[1] = y;
42 st[top].box[2] = st[top].box[3] = st[top].span[2] = st[top].span[3] = 0;
43 /* st[top].spacing = sp;
47 void imtk_layout_dir(int dir)
50 if(dir == IMTK_VERTICAL) {
51 imtk_layout_newline();
55 void imtk_layout_spacing(int spacing)
57 st[top].spacing = spacing;
60 void imtk_layout_advance(int width, int height)
62 int max_span_y, max_box_y;
64 st[top].span[2] += width + st[top].spacing;
66 if(height > st[top].span[3]) {
67 st[top].span[3] = height;
70 max_span_y = st[top].span[1] + st[top].span[3];
71 max_box_y = st[top].box[1] + st[top].box[3];
73 if(max_span_y > max_box_y) {
74 st[top].box[3] = max_span_y - st[top].box[1];
76 if(st[top].span[2] > st[top].box[2]) {
77 st[top].box[2] = st[top].span[2];
80 if(st[top].dir == IMTK_VERTICAL) {
81 imtk_layout_newline();
85 void imtk_layout_newline(void)
87 st[top].span[0] = st[top].box[0];
88 st[top].span[1] = st[top].box[1] + st[top].box[3] + st[top].spacing;
89 st[top].span[2] = st[top].span[3] = 0;
92 void imtk_layout_get_pos(int *x, int *y)
94 *x = st[top].span[0] + st[top].span[2];
98 void imtk_layout_get_bounds(int *bbox)
100 memcpy(bbox, st[top].box, sizeof st[top].box);
103 int imtk_layout_contains(int x, int y)
105 if(x < st[top].box[0] || x >= st[top].box[0] + st[top].box[2]) {
108 if(y < st[top].box[1] || y >= st[top].box[1] + st[top].box[3]) {