[Add] toolkit_drawOutline to cleanup some horrible code I hate so much.

This commit is contained in:
Allanis 2013-03-01 00:21:19 +00:00
parent da6b8fa786
commit dec372e06c

View File

@ -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();
} }
} }
@ -615,40 +627,9 @@ static void toolkit_renderButton(Widget* btn, double bx, double by) {
glEnd(); glEnd();
// Inner outline. // Inner outline.
glShadeModel(GL_SMOOTH); toolkit_drawOutline(x, y, btn->w, btn->h, 0., lc, c);
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. // Outter outline.
glShadeModel(GL_FLAT); toolkit_drawOutline(x, y, btn->w, btn->h, 1., &cBlack, NULL);
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,
@ -689,36 +670,11 @@ static void toolkit_renderImage(Widget* img, double bx, double by) {
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);
// 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. // Outter outline.
glShadeModel(GL_SMOOTH); toolkit_drawOutline(x, y+1, img->dat.img.image->sw-1,
glBegin(GL_LINE_LOOP); img->dat.img.image->sh-1, 2., oc, NULL);
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.