[Add] toolkit_drawOutline to cleanup some horrible code I hate so much.
This commit is contained in:
parent
da6b8fa786
commit
dec372e06c
122
src/toolkit.c
122
src/toolkit.c
@ -89,6 +89,8 @@ static void window_render(Window* w);
|
||||
static void toolkit_renderButton(Widget* btn, double bx, double by);
|
||||
static void toolkit_renderText(Widget* txt, double bx, double by);
|
||||
static void toolkit_renderImage(Widget* img, double bx, double by);
|
||||
static void toolkit_drawOutline(double x, double y, double w,
|
||||
double h, double b, glColour* c, glColour* lc);
|
||||
|
||||
// Add a button that when pressed will trigger call, passing it's name as the
|
||||
// only parameter.
|
||||
@ -347,6 +349,31 @@ void window_destroyWidget(unsigned int wid, const char* wgtname) {
|
||||
w->nwidgets--; // Not that we don't actually realloc the space..
|
||||
}
|
||||
|
||||
static void toolkit_drawOutline(double x, double y, double w, double h,
|
||||
double b, glColour* c, glColour* lc) {
|
||||
|
||||
glShadeModel((lc == NULL) ? GL_FLAT : GL_SMOOTH);
|
||||
if(!lc) COLOUR(*c);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
// Left.
|
||||
if(lc) COLOUR(*lc);
|
||||
glVertex2d(x-b, y);
|
||||
if(lc) COLOUR(*c);
|
||||
glVertex2d(x-b, y+h);
|
||||
// Top.
|
||||
glVertex2d(x, y+h+b);
|
||||
glVertex2d(x+w, y+h+b);
|
||||
// Right.
|
||||
glVertex2d(x+w+b, y+h);
|
||||
if(lc) COLOUR(*lc);
|
||||
glVertex2d(x+w+b, y);
|
||||
// Bottom.
|
||||
glVertex2d(x+w, y-b);
|
||||
glVertex2d(x, y-b);
|
||||
glVertex2d(x-b, y);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// Render a window.
|
||||
static void window_render(Window* w) {
|
||||
int i;
|
||||
@ -542,23 +569,8 @@ static void window_render(Window* w) {
|
||||
y += w->widgets[w->focus].y;
|
||||
wid = w->widgets[w->focus].w;
|
||||
hei = w->widgets[w->focus].h;
|
||||
|
||||
glBegin(GL_LINE_LOOP);
|
||||
COLOUR(cBlack);
|
||||
// Left.
|
||||
glVertex2d(x-3., y);
|
||||
glVertex2d(x-3., y+hei);
|
||||
// Top.
|
||||
glVertex2d(x, y+hei+3.);
|
||||
glVertex2d(x+wid, y+hei+3.);
|
||||
// Right.
|
||||
glVertex2d(x+wid+3., y+hei);
|
||||
glVertex2d(x+wid+3., y);
|
||||
// Bottom.
|
||||
glVertex2d(x+wid, y-3.);
|
||||
glVertex2d(x, y-3.);
|
||||
glVertex2d(x-3., y);
|
||||
glEnd();
|
||||
|
||||
toolkit_drawOutline(x, y, wid, hei, 3, &cBlack, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -614,41 +626,10 @@ static void toolkit_renderButton(Widget* btn, double bx, double by) {
|
||||
glVertex2d(x, y+btn->h);
|
||||
glEnd();
|
||||
|
||||
// Inner outline.
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
// Left.
|
||||
COLOUR(*c);
|
||||
glVertex2d(x, y);
|
||||
COLOUR(*lc);
|
||||
glVertex2d(x, y+btn->h);
|
||||
// Top.
|
||||
glVertex2d(x+btn->w, y+btn->h);
|
||||
// Right.
|
||||
COLOUR(*c);
|
||||
glVertex2d(x+btn->w, y);
|
||||
// Bottom.
|
||||
glVertex2d(x, y);
|
||||
glEnd();
|
||||
|
||||
// Outter outline.
|
||||
glShadeModel(GL_FLAT);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
COLOUR(cBlack);
|
||||
// Left.
|
||||
glVertex2d(x-1., y);
|
||||
glVertex2d(x-1., y+btn->h);
|
||||
// Top.
|
||||
glVertex2d(x, y+btn->h+1.);
|
||||
glVertex2d(x+btn->w, y+btn->h+1.);
|
||||
// Right.
|
||||
glVertex2d(x+btn->w+1., y+btn->h);
|
||||
glVertex2d(x+btn->w+1., y);
|
||||
// Bottom.
|
||||
glVertex2d(x+btn->w, y-1.);
|
||||
glVertex2d(x, y-1.);
|
||||
glVertex2d(x-1, y);
|
||||
glEnd();
|
||||
// Inner outline.
|
||||
toolkit_drawOutline(x, y, btn->w, btn->h, 0., lc, c);
|
||||
// Outter outline.
|
||||
toolkit_drawOutline(x, y, btn->w, btn->h, 1., &cBlack, NULL);
|
||||
|
||||
gl_printMid(NULL, (int)btn->w,
|
||||
bx + (double)gl_screen.w/2. + btn->x,
|
||||
@ -688,37 +669,12 @@ static void toolkit_renderImage(Widget* img, double bx, double by) {
|
||||
x + (double)gl_screen.w/2.,
|
||||
y + (double)gl_screen.h/2., NULL);
|
||||
|
||||
// Inner outline (outwards).
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
COLOUR(*lc);
|
||||
// Top.
|
||||
glVertex2d(x-1, y+img->dat.img.image->sh+1.);
|
||||
glVertex2d(x+img->dat.img.image->sw, y+img->dat.img.image->sh+1.);
|
||||
// Right.
|
||||
COLOUR(*c);
|
||||
glVertex2d(x+img->dat.img.image->sw, y);
|
||||
// Bottom.
|
||||
glVertex2d(x-1., y);
|
||||
// Left.
|
||||
COLOUR(*lc);
|
||||
glVertex2d(x-1., y+img->dat.img.image->sh+1.);
|
||||
glEnd();
|
||||
|
||||
// Outter outline.
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
COLOUR(*oc);
|
||||
// Top.
|
||||
glVertex2d(x-2., y+img->dat.img.image->sh+2.);
|
||||
glVertex2d(x+img->dat.img.image->sw+1., y+img->dat.img.image->sh+2.);
|
||||
// Right.
|
||||
glVertex2d(x+img->dat.img.image->sw+1., y-1.);
|
||||
// Bottom.
|
||||
glVertex2d(x-2., y-1.);
|
||||
// Left.
|
||||
glVertex2d(x-2., y+img->dat.img.image->sh+2.);
|
||||
glEnd();
|
||||
// Inner outline (outwards).
|
||||
toolkit_drawOutline(x, y+1, img->dat.img.image->sw-1,
|
||||
img->dat.img.image->sh-1, 1., lc, c);
|
||||
// Outter outline.
|
||||
toolkit_drawOutline(x, y+1, img->dat.img.image->sw-1,
|
||||
img->dat.img.image->sh-1, 2., oc, NULL);
|
||||
}
|
||||
|
||||
// Render the window.
|
||||
|
Loading…
Reference in New Issue
Block a user