nuclear@23: #include nuclear@24: #include nuclear@23: #include "imtk.h" nuclear@23: nuclear@23: struct layout { nuclear@23: int box[4], span[4]; nuclear@23: int spacing; nuclear@23: int dir; nuclear@23: }; nuclear@23: nuclear@23: #define MAX_STACK_DEPTH 4 nuclear@23: static struct layout st[MAX_STACK_DEPTH]; nuclear@23: static int top = 0; nuclear@23: nuclear@23: int imtk_layout_push(void) nuclear@23: { nuclear@23: int newtop = top + 1; nuclear@23: nuclear@23: assert(newtop < MAX_STACK_DEPTH); nuclear@23: if(newtop >= MAX_STACK_DEPTH) { nuclear@23: return -1; nuclear@23: } nuclear@23: nuclear@23: st[newtop] = st[top++]; nuclear@23: return 0; nuclear@23: } nuclear@23: nuclear@23: int imtk_layout_pop(void) nuclear@23: { nuclear@23: assert(top > 0); nuclear@23: if(top <= 0) { nuclear@23: return -1; nuclear@23: } nuclear@23: top--; nuclear@24: return 0; nuclear@23: } nuclear@23: nuclear@24: void imtk_layout_start(int x, int y) nuclear@23: { nuclear@23: st[top].box[0] = st[top].span[0] = x; nuclear@23: st[top].box[1] = st[top].span[1] = y; nuclear@23: st[top].box[2] = st[top].box[3] = st[top].span[2] = st[top].span[3] = 0; nuclear@24: /* st[top].spacing = sp; nuclear@24: st[top].dir = dir;*/ nuclear@23: } nuclear@23: nuclear@23: void imtk_layout_dir(int dir) nuclear@23: { nuclear@23: st[top].dir = dir; nuclear@23: if(dir == IMTK_VERTICAL) { nuclear@23: imtk_layout_newline(); nuclear@23: } nuclear@23: } nuclear@23: nuclear@24: void imtk_layout_spacing(int spacing) nuclear@24: { nuclear@24: st[top].spacing = spacing; nuclear@24: } nuclear@24: nuclear@23: void imtk_layout_advance(int width, int height) nuclear@23: { nuclear@23: int max_span_y, max_box_y; nuclear@23: nuclear@23: st[top].span[2] += width + st[top].spacing; nuclear@23: nuclear@23: if(height > st[top].span[3]) { nuclear@23: st[top].span[3] = height; nuclear@23: } nuclear@23: nuclear@23: max_span_y = st[top].span[1] + st[top].span[3]; nuclear@23: max_box_y = st[top].box[1] + st[top].box[3]; nuclear@23: nuclear@23: if(max_span_y > max_box_y) { nuclear@23: st[top].box[3] = max_span_y - st[top].box[1]; nuclear@23: } nuclear@23: if(st[top].span[2] > st[top].box[2]) { nuclear@23: st[top].box[2] = st[top].span[2]; nuclear@23: } nuclear@23: nuclear@23: if(st[top].dir == IMTK_VERTICAL) { nuclear@23: imtk_layout_newline(); nuclear@23: } nuclear@23: } nuclear@23: nuclear@23: void imtk_layout_newline(void) nuclear@23: { nuclear@23: st[top].span[0] = st[top].box[0]; nuclear@24: st[top].span[1] = st[top].box[1] + st[top].box[3] + st[top].spacing; nuclear@23: st[top].span[2] = st[top].span[3] = 0; nuclear@23: } nuclear@23: nuclear@23: void imtk_layout_get_pos(int *x, int *y) nuclear@23: { nuclear@23: *x = st[top].span[0] + st[top].span[2]; nuclear@23: *y = st[top].span[1]; nuclear@23: } nuclear@23: nuclear@23: void imtk_layout_get_bounds(int *bbox) nuclear@23: { nuclear@23: memcpy(bbox, st[top].box, sizeof st[top].box); nuclear@23: }