[Add] toolkit_drawOutline to cleanup some horrible code I hate so much.
This commit is contained in:
parent
da6b8fa786
commit
dec372e06c
120
src/toolkit.c
120
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_renderButton(Widget* btn, double bx, double by);
|
||||||
static void toolkit_renderText(Widget* txt, 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_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
|
// Add a button that when pressed will trigger call, passing it's name as the
|
||||||
// only parameter.
|
// 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..
|
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.
|
// Render a window.
|
||||||
static void window_render(Window* w) {
|
static void window_render(Window* w) {
|
||||||
int i;
|
int i;
|
||||||
@ -543,22 +570,7 @@ static void window_render(Window* w) {
|
|||||||
wid = w->widgets[w->focus].w;
|
wid = w->widgets[w->focus].w;
|
||||||
hei = w->widgets[w->focus].h;
|
hei = w->widgets[w->focus].h;
|
||||||
|
|
||||||
glBegin(GL_LINE_LOOP);
|
toolkit_drawOutline(x, y, wid, hei, 3, &cBlack, NULL);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,41 +626,10 @@ static void toolkit_renderButton(Widget* btn, double bx, double by) {
|
|||||||
glVertex2d(x, y+btn->h);
|
glVertex2d(x, y+btn->h);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
// Inner outline.
|
// Inner outline.
|
||||||
glShadeModel(GL_SMOOTH);
|
toolkit_drawOutline(x, y, btn->w, btn->h, 0., lc, c);
|
||||||
glBegin(GL_LINE_LOOP);
|
// Outter outline.
|
||||||
// Left.
|
toolkit_drawOutline(x, y, btn->w, btn->h, 1., &cBlack, NULL);
|
||||||
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();
|
|
||||||
|
|
||||||
gl_printMid(NULL, (int)btn->w,
|
gl_printMid(NULL, (int)btn->w,
|
||||||
bx + (double)gl_screen.w/2. + btn->x,
|
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.,
|
x + (double)gl_screen.w/2.,
|
||||||
y + (double)gl_screen.h/2., NULL);
|
y + (double)gl_screen.h/2., NULL);
|
||||||
|
|
||||||
// Inner outline (outwards).
|
// Inner outline (outwards).
|
||||||
glShadeModel(GL_SMOOTH);
|
toolkit_drawOutline(x, y+1, img->dat.img.image->sw-1,
|
||||||
glBegin(GL_LINE_LOOP);
|
img->dat.img.image->sh-1, 1., lc, c);
|
||||||
COLOUR(*lc);
|
// Outter outline.
|
||||||
// Top.
|
toolkit_drawOutline(x, y+1, img->dat.img.image->sw-1,
|
||||||
glVertex2d(x-1, y+img->dat.img.image->sh+1.);
|
img->dat.img.image->sh-1, 2., oc, NULL);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the window.
|
// Render the window.
|
||||||
|
Loading…
Reference in New Issue
Block a user