int image(Texture *t, float scale, bool overlaid) { autotab(); if(scale==0) scale = 1; int size = (int)(scale*2*FONTH)-SHADOW; if(visible()) icon_(t, overlaid, curx, cury, size, ishit(size+SHADOW, size+SHADOW)); return layout(size+SHADOW, size+SHADOW); }
int texture(VSlot &vslot, float scale, bool overlaid) { autotab(); if(scale==0) scale = 1; int size = (int)(scale*2*FONTH)-SHADOW; if(visible()) previewslot(vslot, overlaid, curx, cury, size, ishit(size+SHADOW, size+SHADOW)); return layout(size+SHADOW, size+SHADOW); }
int texture(Texture *t, float scale, int rotate, int xoff, int yoff, Texture *glowtex, const vec &glowcolor, Texture *layertex) { autotab(); if(scale==0) scale = 1; int size = (int)(scale*2*FONTH)-SHADOW; if(t!=notexture && visible()) icon_(t, true, true, curx, cury, size, ishit(size+SHADOW, size+SHADOW), rotate, xoff, yoff, glowtex, glowcolor, layertex); return layout(size+SHADOW, size+SHADOW); }
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 playerpreview(int model, int team, int weap, float sizescale, bool overlaid) { autotab(); if(sizescale==0) sizescale = 1; int size = (int)(sizescale*2*FONTH)-SHADOW; if(visible()) { bool hit = ishit(size+SHADOW, size+SHADOW); float xs = size, ys = size, xi = curx, yi = cury; if(overlaid && hit && actionon) { glDisable(GL_TEXTURE_2D); notextureshader->set(); glColor4f(0, 0, 0, 0.75f); rect_(xi+SHADOW, yi+SHADOW, xs, ys); glEnable(GL_TEXTURE_2D); defaultshader->set(); } int x1 = int(floor(screenw*(xi*scale.x+origin.x))), y1 = int(floor(screenh*(1 - ((yi+ys)*scale.y+origin.y)))), x2 = int(ceil(screenw*((xi+xs)*scale.x+origin.x))), y2 = int(ceil(screenh*(1 - (yi*scale.y+origin.y)))); glViewport(x1, y1, x2-x1, y2-y1); glScissor(x1, y1, x2-x1, y2-y1); glEnable(GL_SCISSOR_TEST); glDisable(GL_BLEND); modelpreview::start(overlaid); game::renderplayerpreview(model, team, weap); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); modelpreview::end(); glDisable(GL_SCISSOR_TEST); glViewport(0, 0, screenw, screenh); if(overlaid) { if(hit) { glDisable(GL_TEXTURE_2D); notextureshader->set(); glBlendFunc(GL_ZERO, GL_SRC_COLOR); glColor3f(1, 0.5f, 0.5f); rect_(xi, yi, xs, ys); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); defaultshader->set(); } if(!overlaytex) { string otname; inexor::filesystem::appendmediadir(otname, "guioverlay.png", DIR_UI); overlaytex = textureload(otname, 3); } glColor3fv(light.v); glBindTexture(GL_TEXTURE_2D, overlaytex->id); rect_(xi, yi, xs, ys, 0); } } return layout(size+SHADOW, size+SHADOW); }
int modelpreview(const char *name, int anim, float sizescale, bool overlaid) { autotab(); if(sizescale==0) sizescale = 1; int size = (int)(sizescale*2*FONTH)-SHADOW; if(visible()) { bool hit = ishit(size+SHADOW, size+SHADOW); float xs = size, ys = size, xi = curx, yi = cury; if(overlaid && hit && actionon) { hudnotextureshader->set(); gle::colorf(0, 0, 0, 0.75f); rect_(xi+SHADOW, yi+SHADOW, xs, ys); hudshader->set(); } int x1 = int(floor(screen->w*(xi*scale.x+origin.x))), y1 = int(floor(screen->h*(1 - ((yi+ys)*scale.y+origin.y)))), x2 = int(ceil(screen->w*((xi+xs)*scale.x+origin.x))), y2 = int(ceil(screen->h*(1 - (yi*scale.y+origin.y)))); glDisable(GL_BLEND); modelpreview::start(x1, y1, x2-x1, y2-y1, overlaid); model *m = loadmodel(name); if(m) { entitylight light; light.color = vec(1, 1, 1); light.dir = vec(0, -1, 2).normalize(); vec center, radius; m->boundbox(center, radius); float yaw; vec o = calcmodelpreviewpos(radius, yaw).sub(center); rendermodel(&light, name, anim, o, yaw, 0, 0, NULL, NULL, 0); } modelpreview::end(); hudshader->set(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); if(overlaid) { if(hit) { hudnotextureshader->set(); glBlendFunc(GL_ZERO, GL_SRC_COLOR); gle::colorf(1, 0.5f, 0.5f); rect_(xi, yi, xs, ys); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); hudshader->set(); } if(!overlaytex) overlaytex = textureload("data/guioverlay.png", 3); gle::color(light); glBindTexture(GL_TEXTURE_2D, overlaytex->id); rect_(xi, yi, xs, ys, 0); } } return layout(size+SHADOW, size+SHADOW); }
int prefabpreview(const char *prefab, const vec &color, float sizescale, bool overlaid) { autotab(); if(sizescale==0) sizescale = 1; int size = (int)(sizescale*2*FONTH)-SHADOW; if(visible()) { bool hit = ishit(size+SHADOW, size+SHADOW); float xs = size, ys = size, xi = curx, yi = cury; if(overlaid && hit && actionon) { hudnotextureshader->set(); gle::colorf(0, 0, 0, 0.75f); rect_(xi+SHADOW, yi+SHADOW, xs, ys); hudshader->set(); } int x1 = int(floor(screen->w*(xi*scale.x+origin.x))), y1 = int(floor(screen->h*(1 - ((yi+ys)*scale.y+origin.y)))), x2 = int(ceil(screen->w*((xi+xs)*scale.x+origin.x))), y2 = int(ceil(screen->h*(1 - (yi*scale.y+origin.y)))); glDisable(GL_BLEND); modelpreview::start(x1, y1, x2-x1, y2-y1, overlaid); previewprefab(prefab, color); modelpreview::end(); hudshader->set(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); if(overlaid) { if(hit) { hudnotextureshader->set(); glBlendFunc(GL_ZERO, GL_SRC_COLOR); gle::colorf(1, 0.5f, 0.5f); rect_(xi, yi, xs, ys); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); hudshader->set(); } if(!overlaytex) overlaytex = textureload("data/guioverlay.png", 3); gle::color(light); glBindTexture(GL_TEXTURE_2D, overlaytex->id); rect_(xi, yi, xs, ys, 0); } } return layout(size+SHADOW, size+SHADOW); }
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; } }
char *field_(const char *name, int color, int length, int height, const char *initval, int initmode, int fieldtype = FIELDEDIT) { editor *e = useeditor(name, initmode, false, initval); // generate a new editor if necessary if(layoutpass) { if(initval && e->mode==EDITORFOCUSED && (e!=currentfocus() || fieldmode == FIELDSHOW)) { if(strcmp(e->lines[0].text, initval)) e->clear(initval); } e->linewrap = (length<0); e->maxx = (e->linewrap) ? -1 : length; e->maxy = (height<=0)?1:-1; e->pixelwidth = abs(length)*FONTW; if(e->linewrap && e->maxy==1) { int temp; text_bounds(e->lines[0].text, temp, e->pixelheight, e->pixelwidth); //only single line editors can have variable height } else e->pixelheight = FONTH*max(height, 1); } int h = e->pixelheight; int w = e->pixelwidth + FONTW; bool wasvertical = isvertical(); if(wasvertical && e->maxy != 1) pushlist(); char *result = NULL; if(visible() && !layoutpass) { e->rendered = true; bool hit = ishit(w, h); if(hit) { if(mousebuttons&G3D_DOWN) //mouse request focus { if(fieldtype==FIELDKEY) e->clear(); useeditor(name, initmode, true); e->mark(false); fieldmode = fieldtype; } } bool editing = (fieldmode != FIELDSHOW) && (e==currentfocus()); if(hit && editing && (mousebuttons&G3D_PRESSED)!=0 && fieldtype==FIELDEDIT) e->hit(int(floor(hitx-(curx+FONTW/2))), int(floor(hity-cury)), (mousebuttons&G3D_DRAGGED)!=0); //mouse request position if(editing && ((fieldmode==FIELDCOMMIT) || (fieldmode==FIELDABORT) || !hit)) // commit field if user pressed enter or wandered out of focus { if(fieldmode==FIELDCOMMIT || (fieldmode!=FIELDABORT && !hit)) result = e->currentline().text; e->active = (e->mode!=EDITORFOCUSED); fieldmode = FIELDSHOW; } else fieldsactive = true; e->draw(curx+FONTW/2, cury, color, hit && editing); notextureshader->set(); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); if(editing) glColor3f(1, 0, 0); else glColor3ub(color>>16, (color>>8)&0xFF, color&0xFF); rect_(curx, cury, w, h, -1, true); glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); defaultshader->set(); }
int modelpreview(const char *name, int anim, float sizescale, bool overlaid) { autotab(); if(sizescale==0) sizescale = 1; int size = (int)(sizescale*2*FONTH)-SHADOW; if(visible()) { bool hit = ishit(size+SHADOW, size+SHADOW); float xs = size, ys = size, xi = curx, yi = cury; if(overlaid && hit && actionon) { glDisable(GL_TEXTURE_2D); notextureshader->set(); glColor4f(0, 0, 0, 0.75f); rect_(xi+SHADOW, yi+SHADOW, xs, ys); glEnable(GL_TEXTURE_2D); defaultshader->set(); } int x1 = int(floor(screenw*(xi*scale.x+origin.x))), y1 = int(floor(screenh*(1 - ((yi+ys)*scale.y+origin.y)))), x2 = int(ceil(screenw*((xi+xs)*scale.x+origin.x))), y2 = int(ceil(screenh*(1 - (yi*scale.y+origin.y)))); glViewport(x1, y1, x2-x1, y2-y1); glScissor(x1, y1, x2-x1, y2-y1); glEnable(GL_SCISSOR_TEST); glDisable(GL_BLEND); modelpreview::start(overlaid); model *m = loadmodel(name); if(m) { entitylight light; light.color = vec(1, 1, 1); light.dir = vec(0, -1, 2).normalize(); vec center, radius; m->boundbox(center, radius); float dist = 2.0f*max(radius.magnitude2(), 1.1f*radius.z), yaw = fmod(lastmillis/10000.0f*360.0f, 360.0f); vec o(-center.x, dist - center.y, -0.1f*dist - center.z); rendermodel(&light, name, anim, o, yaw, 0, 0, NULL, NULL, 0); } modelpreview::end(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_SCISSOR_TEST); glViewport(0, 0, screenw, screenh); if(overlaid) { if(hit) { glDisable(GL_TEXTURE_2D); notextureshader->set(); glBlendFunc(GL_ZERO, GL_SRC_COLOR); glColor3f(1, 0.5f, 0.5f); rect_(xi, yi, xs, ys); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); defaultshader->set(); } if(!overlaytex) { string otname; inexor::filesystem::appendmediadir(otname, "guioverlay.png", DIR_UI); overlaytex = textureload(otname, 3); } glColor3fv(light.v); glBindTexture(GL_TEXTURE_2D, overlaytex->id); rect_(xi, yi, xs, ys, 0); } } return layout(size+SHADOW, size+SHADOW); }