void poplist() { if(!lists.inrange(curlist)) return; list &l = lists[curlist]; if(layoutpass) { l.w = xsize; l.h = ysize; } curlist = l.parent; curdepth--; if(lists.inrange(curlist)) { int w = xsize, h = ysize; if(ishorizontal()) cury -= h; else curx -= w; list &p = lists[curlist]; xsize = p.w; ysize = p.h; if(!layoutpass && p.springs > 0) { list &s = lists[p.parent]; if(ishorizontal()) xsize = s.w; else ysize = s.h; } layout(w, h); } }
bool ishit(int w, int h, int x = curx, int y = cury) { if(shouldmergehits) return windowhit==this && (ishorizontal() ? hitx>=x && hitx<x+w : hity>=y && hity<y+h); if(ishorizontal()) h = ysize; else w = xsize; return windowhit==this && hitx>=x && hity>=y && hitx<x+w && hity<y+h; }
void poplist() { list &l = lists[curlist]; if(layoutpass) { l.w = xsize; l.h = ysize; } curlist = l.parent; curdepth--; if(curlist>=0) { xsize = lists[curlist].w; ysize = lists[curlist].h; if(ishorizontal()) cury -= l.h; else curx -= l.w; layout(l.w, l.h); if(!layoutpass) switch(l.align) { case 0: if(ishorizontal()) cury -= max(ysize - l.h, 0)/2; else curx -= max(xsize - l.w, 0)/2; break; case 1: if(ishorizontal()) cury -= max(ysize - l.h, 0); else curx -= max(xsize - l.h, 0); break; } } }
void pushlist(int align = -1) { if(layoutpass) { if(curlist>=0) { lists[curlist].w = xsize; lists[curlist].h = ysize; } list &l = lists.add(); l.parent = curlist; l.align = align; curlist = lists.length()-1; xsize = ysize = 0; } else { int xpad = xsize, ypad = ysize; curlist = nextlist++; xsize = lists[curlist].w; ysize = lists[curlist].h; switch(align) { case 0: if(ishorizontal()) cury += max(ypad - ysize, 0)/2; else curx += max(xpad - xsize, 0)/2; break; case 1: if(ishorizontal()) cury += max(ypad - ysize, 0); else curx += max(xpad - xsize, 0); break; } } curdepth++; }
void slider(int &val, int vmin, int vmax, int color, char *label) { autotab(); int x = curx; int y = cury; line_(10); if(visible()) { if(!label) { static string s; formatstring(s)("%d", val); label = s; } int w = text_width(label); bool hit; int px, py; if(ishorizontal()) { hit = ishit(FONTH, ysize, x, y); px = x + (FONTH-w)/2; py = y + (ysize-FONTH) - ((ysize-FONTH)*(val-vmin))/((vmax==vmin) ? 1 : (vmax-vmin)); //vmin at bottom } else { hit = ishit(xsize, FONTH, x, y); px = x + FONTH/2 - w/2 + ((xsize-w)*(val-vmin))/((vmax==vmin) ? 1 : (vmax-vmin)); //vmin at left py = y; } if(hit) color = 0xFF0000; text_(label, px, py, color, hit && actionon); if(hit && actionon) { int vnew = (vmin < vmax ? 1 : -1)+vmax-vmin; if(ishorizontal()) vnew = int(vnew*(y+ysize-FONTH/2-hity)/(ysize-FONTH)); else vnew = int(vnew*(hitx-x-FONTH/2)/(xsize-w)); vnew += vmin; vnew = vmin < vmax ? clamp(vnew, vmin, vmax) : clamp(vnew, vmax, vmin); if(vnew != val) val = vnew; } } }
int layout(int w, int h) { if(layoutpass) { if(ishorizontal()) { xsize += w; ysize = max(ysize, h); } else { xsize = max(xsize, w); ysize += h; } return 0; } else { bool hit = ishit(w, h); if(ishorizontal()) curx += w; else cury += h; return (hit && visible()) ? mousebuttons|G3D_ROLLOVER : 0; } }
void spring(int weight) { if(curlist < 0) return; list &l = lists[curlist]; if(layoutpass) { if(l.parent >= 0) l.springs += weight; return; } int nextspring = min(l.curspring + weight, l.springs); if(nextspring <= l.curspring) return; if(ishorizontal()) { int w = xsize - l.w; layout((w*nextspring)/l.springs - (w*l.curspring)/l.springs, 0); } else { int h = ysize - l.h; layout(0, (h*nextspring)/l.springs - (h*l.curspring)/l.springs); } l.curspring = nextspring; }
void poplist() { list &l = lists[curlist]; if(layoutpass) { l.w = xsize; l.h = ysize; } curlist = l.parent; curdepth--; if(curlist>=0) { xsize = lists[curlist].w; ysize = lists[curlist].h; if(ishorizontal()) cury -= l.h; else curx -= l.w; layout(l.w, l.h); } }
void pushlist() { if(layoutpass) { if(curlist>=0) { lists[curlist].w = xsize; lists[curlist].h = ysize; } list &l = lists.add(); l.parent = curlist; l.springs = 0; l.column = -1; curlist = lists.length()-1; xsize = ysize = 0; } else { curlist = nextlist++; if(curlist >= lists.length()) // should never get here unless script code doesn't use same amount of lists in layout and render passes { list &l = lists.add(); l.parent = curlist; l.springs = 0; l.column = -1; l.w = l.h = 0; } list &l = lists[curlist]; l.curspring = 0; if(l.springs > 0) { if(ishorizontal()) xsize = l.w; else ysize = l.h; } else { xsize = l.w; ysize = l.h; } } curdepth++; }
bool isvertical() const { return !ishorizontal(); }
int check_win(char *board) { return (ishorizontal(board) || isvertical(board) || isdiagonal(board)); }