summaryrefslogtreecommitdiff
path: root/src/engine/3dgui.cpp
diff options
context:
space:
mode:
authorxolatile2025-07-19 16:01:38 +0200
committerxolatile2025-07-19 16:01:38 +0200
commite9ad09c58820b31743251f793f30e5d4d49a0dca (patch)
treef3e3afdf61301d6489f6777f03628e0ffe6c9b0f /src/engine/3dgui.cpp
parentc79dda69d6e603500a5681430172b5152041af0a (diff)
downloadxolatile-badassbug-e9ad09c58820b31743251f793f30e5d4d49a0dca.tar.xz
xolatile-badassbug-e9ad09c58820b31743251f793f30e5d4d49a0dca.tar.zst
Rough changes...
Diffstat (limited to 'src/engine/3dgui.cpp')
-rw-r--r--src/engine/3dgui.cpp196
1 files changed, 98 insertions, 98 deletions
diff --git a/src/engine/3dgui.cpp b/src/engine/3dgui.cpp
index f1f6ef2..68d5428 100644
--- a/src/engine/3dgui.cpp
+++ b/src/engine/3dgui.cpp
@@ -15,7 +15,7 @@ static float firstx, firsty;
enum {FIELDCOMMIT, FIELDABORT, FIELDEDIT, FIELDSHOW, FIELDKEY};
-static int fieldmode = FIELDSHOW;
+static int fieldmode = FIELDSHOW;
static bool fieldsactive = false;
static bool hascursor;
@@ -73,12 +73,12 @@ struct gui : g3d_gui
return oldval;
}
- void autotab()
- {
+ void autotab()
+ {
if(tcurrent)
{
if(layoutpass && !tpos) tcurrent = NULL; //disable tabs because you didn't start with one
- if(shouldautotab && !curdepth && (layoutpass ? 0 : cury) + ysize > guiautotab*FONTH) tab(NULL, tcolor);
+ if(shouldautotab && !curdepth && (layoutpass ? 0 : cury) + ysize > guiautotab*FONTH) tab(NULL, tcolor);
}
}
@@ -116,20 +116,20 @@ struct gui : g3d_gui
bool visible() { return (!tcurrent || tpos==*tcurrent) && !layoutpass; }
//tab is always at top of page
- void tab(const char *name, int color)
+ void tab(const char *name, int color)
{
if(curdepth != 0) return;
if(color) tcolor = color;
- tpos++;
- if(!name) name = intstr(tpos);
+ tpos++;
+ if(!name) name = intstr(tpos);
int w = max(text_width(name) - 2*INSERT, 0);
- if(layoutpass)
- {
- ty = max(ty, ysize);
+ if(layoutpass)
+ {
+ ty = max(ty, ysize);
ysize = 0;
}
- else
- {
+ else
+ {
cury = -ysize;
int h = FONTH-2*INSERT,
x1 = curx + tx,
@@ -137,20 +137,20 @@ struct gui : g3d_gui
y1 = cury - ((skiny[6]-skiny[1])-(skiny[3]-skiny[2]))*SKIN_SCALE-h,
y2 = cury;
bool hit = tcurrent && windowhit==this && hitx>=x1 && hity>=y1 && hitx<x2 && hity<y2;
- if(hit && (!guiclicktab || mousebuttons&G3D_DOWN))
+ if(hit && (!guiclicktab || mousebuttons&G3D_DOWN))
*tcurrent = tpos; //roll-over to switch tab
-
+
drawskin(x1-skinx[visible()?2:6]*SKIN_SCALE, y1-skiny[1]*SKIN_SCALE, w, h, visible()?10:19, 9, gui2d ? 1 : 2, light, alpha);
text_(name, x1 + (skinx[3]-skinx[2])*SKIN_SCALE - (w ? INSERT : INSERT/2), y1 + (skiny[2]-skiny[1])*SKIN_SCALE - INSERT, tcolor, visible());
}
- tx += w + ((skinx[5]-skinx[4]) + (skinx[3]-skinx[2]))*SKIN_SCALE;
+ tx += w + ((skinx[5]-skinx[4]) + (skinx[3]-skinx[2]))*SKIN_SCALE;
}
bool ishorizontal() const { return curdepth&1; }
bool isvertical() const { return !ishorizontal(); }
void pushlist()
- {
+ {
if(layoutpass)
{
if(curlist>=0)
@@ -188,7 +188,7 @@ struct gui : g3d_gui
ysize = l.h;
}
}
- curdepth++;
+ curdepth++;
}
void poplist()
@@ -204,7 +204,7 @@ struct gui : g3d_gui
curlist = l.parent;
curdepth--;
if(lists.inrange(curlist))
- {
+ {
int w = xsize, h = ysize;
if(ishorizontal()) cury -= h; else curx -= w;
list &p = lists[curlist];
@@ -214,7 +214,7 @@ struct gui : g3d_gui
{
list &s = lists[p.parent];
if(ishorizontal()) xsize = s.w; else ysize = s.h;
- }
+ }
layout(w, h);
}
}
@@ -231,8 +231,8 @@ struct gui : g3d_gui
//add space between list items
void space(float size) { layout(isvertical() ? 0 : int(size*FONTW), isvertical() ? int(size*FONTH) : 0); }
- void spring(int weight)
- {
+ void spring(int weight)
+ {
if(curlist < 0) return;
list &l = lists[curlist];
if(layoutpass) { if(l.parent >= 0) l.springs += weight; return; }
@@ -283,10 +283,10 @@ struct gui : g3d_gui
}
}
- bool mergehits(bool on)
- {
+ bool mergehits(bool on)
+ {
bool oldval = shouldmergehits;
- shouldmergehits = on;
+ shouldmergehits = on;
return oldval;
}
@@ -306,7 +306,7 @@ struct gui : g3d_gui
if(visible()) icon_(t, overlaid!=NULL, curx, cury, size, ishit(size+SHADOW, size+SHADOW), overlaid);
return layout(size+SHADOW, size+SHADOW);
}
-
+
int texture(VSlot &vslot, float scale, bool overlaid)
{
autotab();
@@ -464,7 +464,7 @@ struct gui : g3d_gui
}
return layout(size+SHADOW, size+SHADOW);
}
-
+
void slider(int &val, int vmin, int vmax, int color, const char *label)
{
autotab();
@@ -516,7 +516,7 @@ struct gui : g3d_gui
}
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)
{
@@ -528,48 +528,48 @@ struct gui : g3d_gui
e->maxx = (e->linewrap) ? -1 : length;
e->maxy = (height<=0)?1:-1;
e->pixelwidth = abs(length)*FONTW;
- if(e->linewrap && e->maxy==1)
+ 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);
+ 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(hit)
{
if(mousebuttons&G3D_DOWN) //mouse request focus
- {
+ {
if(fieldtype==FIELDKEY) e->clear();
- useeditor(name, initmode, true);
+ 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(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);
-
+
hudnotextureshader->set();
glDisable(GL_BLEND);
if(editing) gle::colorf(1, 0, 0);
@@ -579,19 +579,19 @@ struct gui : g3d_gui
hudshader->set();
}
layout(w, h);
-
+
if(e->maxy != 1)
{
int slines = e->limitscrolly();
- if(slines > 0)
+ if(slines > 0)
{
int pos = e->scrolly;
slider(e->scrolly, slines, 0, color, NULL);
- if(pos != e->scrolly) e->cy = e->scrolly;
+ if(pos != e->scrolly) e->cy = e->scrolly;
}
if(wasvertical) poplist();
}
-
+
return result;
}
@@ -620,7 +620,7 @@ struct gui : g3d_gui
xtraverts += gle::end();
}
- void text_(const char *text, int x, int y, int color, bool shadow, bool force = false)
+ void text_(const char *text, int x, int y, int color, bool shadow, bool force = false)
{
if(shadow) draw_text(text, x+SHADOW, y+SHADOW, 0x00, 0x00, 0x00, -0xC0);
draw_text(text, x, y, color>>16, (color>>8)&0xFF, color&0xFF, force ? -0xFF : 0xFF);
@@ -632,7 +632,7 @@ struct gui : g3d_gui
hudnotextureshader->set();
gle::colorub(color>>16, (color>>8)&0xFF, color&0xFF, 0x80);
int w = xsize, h = ysize;
- if(inheritw>0)
+ if(inheritw>0)
{
int parentw = curlist, parentdepth = 0;
for(;parentdepth < inheritw && lists[parentw].parent>=0; parentdepth++)
@@ -676,7 +676,7 @@ struct gui : g3d_gui
rect_(x, y, xs, ys, 0);
if(title) text_(title, x + xs/12, y + ys - ys/12 - FONTH, hit ? 0xFF0000 : 0xFFFFFF, hit && actionon, hit);
}
- }
+ }
void previewslot(VSlot &vslot, bool overlaid, int x, int y, int size, bool hit)
{
@@ -699,12 +699,12 @@ struct gui : g3d_gui
else if(slot.thumbnail && slot.thumbnail != notexture) t = slot.thumbnail;
else return;
float xt = min(1.0f, t->xs/(float)t->ys), yt = min(1.0f, t->ys/(float)t->xs), xs = size, ys = size;
- if(hit && actionon)
+ if(hit && actionon)
{
hudnotextureshader->set();
gle::colorf(0, 0, 0, 0.75f);
rect_(x+SHADOW, y+SHADOW, xs, ys);
- hudshader->set();
+ hudshader->set();
}
SETSHADER(hudrgb);
gle::defvertex(2);
@@ -719,7 +719,7 @@ struct gui : g3d_gui
if(r.flipx) { xoff *= -1; loopk(4) tc[k].x *= -1; }
if(r.flipy) { yoff *= -1; loopk(4) tc[k].y *= -1; }
}
- loopk(4) { tc[k].x = tc[k].x/xt - xoff/t->xs; tc[k].y = tc[k].y/yt - yoff/t->ys; }
+ loopk(4) { tc[k].x = tc[k].x/xt - xoff/t->xs; tc[k].y = tc[k].y/yt - yoff/t->ys; }
if(slot.loaded) gle::color(vec(color).mul(vslot.colorscale));
else gle::color(color);
glBindTexture(GL_TEXTURE_2D, t->id);
@@ -754,9 +754,9 @@ struct gui : g3d_gui
gle::attribf(x+xs, y+ys); gle::attrib(tc[2]);
gle::end();
}
-
+
hudshader->set();
- if(overlaid)
+ if(overlaid)
{
if(!overlaytex) overlaytex = textureload("data/guioverlay.png", 3);
glBindTexture(GL_TEXTURE_2D, overlaytex->id);
@@ -766,29 +766,29 @@ struct gui : g3d_gui
}
void line_(int size, float percent = 1.0f)
- {
+ {
if(visible())
{
if(!slidertex) slidertex = textureload("data/guislider.png", 3);
glBindTexture(GL_TEXTURE_2D, slidertex->id);
- if(percent < 0.99f)
+ if(percent < 0.99f)
{
gle::colorf(light.x, light.y, light.z, 0.375f);
- if(ishorizontal())
+ if(ishorizontal())
rect_(curx + FONTH/2 - size/2, cury, size, ysize, 0);
else
rect_(curx, cury + FONTH/2 - size/2, xsize, size, 1);
}
gle::color(light);
- if(ishorizontal())
+ if(ishorizontal())
rect_(curx + FONTH/2 - size/2, cury + ysize*(1-percent), size, ysize*percent, 0);
- else
+ else
rect_(curx, cury + FONTH/2 - size/2, xsize*percent, size, 1);
}
layout(ishorizontal() ? FONTH : 0, ishorizontal() ? 0 : FONTH);
}
- void textbox(const char *text, int width, int height, int color)
+ void textbox(const char *text, int width, int height, int color)
{
width *= FONTW;
height *= FONTH;
@@ -806,20 +806,20 @@ struct gui : g3d_gui
if(icon) w += ICON_SIZE;
if(icon && text) w += padding;
if(text) w += text_width(text);
-
+
if(visible())
{
bool hit = ishit(w, FONTH);
- if(hit && clickable) color = 0xFF0000;
- int x = curx;
+ if(hit && clickable) color = 0xFF0000;
+ int x = curx;
if(isvertical() && center) x += (xsize-w)/2;
-
+
if(icon)
{
if(icon[0] != ' ')
{
const char *ext = strrchr(icon, '.');
- defformatstring(tname, "packages/icons/%s%s", icon, ext ? "" : ".jpg");
+ defformatstring(tname, "packages/icons/%s%s", icon, ext ? "" : ".png");
icon_(textureload(tname, 3), false, x, cury, ICON_SIZE, clickable && hit);
}
x += ICON_SIZE;
@@ -834,15 +834,15 @@ struct gui : g3d_gui
static const int skinx[], skiny[];
static const struct patch { ushort left, right, top, bottom; uchar flags; } patches[];
- static void drawskin(int x, int y, int gapw, int gaph, int start, int n, int passes = 1, const vec &light = vec(1, 1, 1), float alpha = 0.80f)//int vleft, int vright, int vtop, int vbottom, int start, int n)
+ static void drawskin(int x, int y, int gapw, int gaph, int start, int n, int passes = 1, const vec &light = vec(1, 1, 1), float alpha = 0.80f)//int vleft, int vright, int vtop, int vbottom, int start, int n)
{
if(!skintex) skintex = textureload("data/guiskin.png", 3);
glBindTexture(GL_TEXTURE_2D, skintex->id);
int gapx1 = INT_MAX, gapy1 = INT_MAX, gapx2 = INT_MAX, gapy2 = INT_MAX;
float wscale = 1.0f/(SKIN_W*SKIN_SCALE), hscale = 1.0f/(SKIN_H*SKIN_SCALE);
-
+
loopj(passes)
- {
+ {
bool quads = false;
if(passes>1) glDepthFunc(j ? GL_LEQUAL : GL_GREATER);
gle::color(j ? light : vec(1, 1, 1), passes<=1 || j ? alpha : alpha/2); //ghost when its behind something in depth
@@ -873,13 +873,13 @@ struct gui : g3d_gui
top += gaph - (gapy2-gapy1);
bottom += gaph - (gapy2-gapy1);
}
-
+
//multiple tiled quads if necessary rather than a single stretched one
int ystep = bottom-top;
int yo = y+top;
- while(ystep > 0)
+ while(ystep > 0)
{
- if(p.flags&0x10 && yo+ystep-(y+top) > gaph)
+ if(p.flags&0x10 && yo+ystep-(y+top) > gaph)
{
ystep = gaph+y+top-yo;
tbottom = ttop+ystep*hscale;
@@ -887,11 +887,11 @@ struct gui : g3d_gui
int xstep = right-left;
int xo = x+left;
float tright2 = tright;
- while(xstep > 0)
+ while(xstep > 0)
{
- if(p.flags&0x01 && xo+xstep-(x+left) > gapw)
+ if(p.flags&0x01 && xo+xstep-(x+left) > gapw)
{
- xstep = gapw+x+left-xo;
+ xstep = gapw+x+left-xo;
tright = tleft+xstep*wscale;
}
if(!quads)
@@ -917,7 +917,7 @@ struct gui : g3d_gui
else break; //if it didn't happen on the first pass, it won't happen on the second..
}
if(passes>1) glDepthFunc(GL_ALWAYS);
- }
+ }
vec origin, scale, *savedorigin;
float dist;
@@ -943,10 +943,10 @@ struct gui : g3d_gui
}
void start(int starttime, float initscale, int *tab, bool allowinput)
- {
- if(gui2d)
+ {
+ if(gui2d)
{
- initscale *= 0.025f;
+ initscale *= 0.025f;
if(allowinput) hascursor = true;
}
basescale = initscale;
@@ -961,7 +961,7 @@ struct gui : g3d_gui
tcurrent = tab;
tcolor = 0xFFFFFF;
pushlist();
- if(layoutpass)
+ if(layoutpass)
{
firstlist = nextlist = curlist;
memset(columns, 0, sizeof(columns));
@@ -969,13 +969,13 @@ struct gui : g3d_gui
else
{
if(tcurrent && !*tcurrent) tcurrent = NULL;
- cury = -ysize;
+ cury = -ysize;
curx = -xsize/2;
-
+
if(gui2d)
{
hudmatrix.ortho(0, 1, 1, 0, -1, 1);
- hudmatrix.translate(origin);
+ hudmatrix.translate(origin);
hudmatrix.scale(scale);
light = vec(1, 1, 1);
@@ -988,9 +988,9 @@ struct gui : g3d_gui
hudmatrix.rotate_around_z(yaw - 90*RAD);
hudmatrix.rotate_around_x(-90*RAD);
hudmatrix.scale(-scale.x, scale.y, scale.z);
-
+
vec dir;
- lightreaching(origin, light, dir, false, 0, 0.5f);
+ lightreaching(origin, light, dir, false, 0, 0.5f);
float intensity = vec(yaw, 0.0f).dot(dir);
light.mul(1.0f + max(intensity, 0.0f));
}
@@ -1028,7 +1028,7 @@ struct gui : g3d_gui
}
xsize = max(xsize, w);
}
-
+
void adjustcolumns()
{
if(lists.inrange(curlist))
@@ -1051,7 +1051,7 @@ struct gui : g3d_gui
}
if(l.column >= 0)
{
- if(depth&1) adjusthorizontalcolumn(l.column, i);
+ if(depth&1) adjusthorizontalcolumn(l.column, i);
else adjustverticalcolumn(l.column, i);
}
}
@@ -1060,7 +1060,7 @@ struct gui : g3d_gui
void end()
{
if(layoutpass)
- {
+ {
adjustcolumns();
xsize = max(tx, xsize);
ysize = max(ty, ysize);
@@ -1114,8 +1114,8 @@ Texture *gui::skintex = NULL, *gui::overlaytex = NULL, *gui::slidertex = NULL;
const int gui::skiny[] = {0, 7, 21, 34, 43, 48, 56, 104, 111, 117, 128},
gui::skinx[] = {0, 11, 23, 37, 105, 119, 137, 151, 215, 229, 246, 256};
//Note: skinx[3]-skinx[2] = skinx[7]-skinx[6]
-// skinx[5]-skinx[4] = skinx[9]-skinx[8]
-const gui::patch gui::patches[] =
+// skinx[5]-skinx[4] = skinx[9]-skinx[8]
+const gui::patch gui::patches[] =
{ //arguably this data can be compressed - it depends on what else needs to be skinned in the future
{1,2,3,6, 0}, // body
{2,9,5,6, 0x01},
@@ -1166,7 +1166,7 @@ bool g3d_input(const char *str, int len)
{
editor *e = currentfocus();
if(fieldmode == FIELDKEY || fieldmode == FIELDSHOW || !e) return false;
-
+
e->input(str, len);
return true;
}
@@ -1198,10 +1198,10 @@ bool g3d_key(int code, bool isdown)
{
if(windowhit) switch(code)
{
- case -4: // window "management"
+ case -4: // window "management"
if(isdown)
{
- if(windowhit->gui2d)
+ if(windowhit->gui2d)
{
vec origin = *guis2d.last().savedorigin;
int i = windowhit - &guis2d[0];
@@ -1300,7 +1300,7 @@ static inline bool g3d_sort(const gui &a, const gui &b) { return a.dist < b.dist
bool g3d_windowhit(bool on, bool act)
{
extern int cleargui(int n);
- if(act)
+ if(act)
{
if(actionon || windowhit)
{
@@ -1311,25 +1311,25 @@ bool g3d_windowhit(bool on, bool act)
return (guis2d.length() && hascursor) || (windowhit && !windowhit->gui2d);
}
-void g3d_render()
+void g3d_render()
{
- windowhit = NULL;
+ windowhit = NULL;
if(actionon) mousebuttons |= G3D_PRESSED;
-
- gui::reset();
+
+ gui::reset();
guis2d.shrink(0);
guis3d.shrink(0);
-
+
// call all places in the engine that may want to render a gui from here, they call g3d_addgui()
extern void g3d_texturemenu();
-
+
if(!mainmenu) g3d_texturemenu();
g3d_mainmenu();
if(!mainmenu) game::g3d_gamemenus();
guis2d.sort(g3d_sort);
guis3d.sort(g3d_sort);
-
+
readyeditors();
fieldsactive = false;