From 8f7df9fc2f17117438bcf21c9a5ef7e794249228 Mon Sep 17 00:00:00 2001 From: Allanis Date: Tue, 19 Feb 2013 21:38:57 +0000 Subject: [PATCH] [Add] Embed name on window creation rather than having the overhead of writing and positioning a block of text. --- src/land.c | 15 +++------------ src/toolkit.c | 11 ++++++++++- src/toolkit.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/land.c b/src/land.c index d7de7fd..ffff9a6 100644 --- a/src/land.c +++ b/src/land.c @@ -44,11 +44,7 @@ static void shipyard(void) { // Spaceport bar. static void spaceport_bar(void) { - secondary_wid = window_create(-1, -1, BAR_WIDTH, BAR_HEIGHT); - - // Window title. - window_addText(secondary_wid, 0, -20, BAR_WIDTH, 0, 1, - "txtTitle", NULL, &cBlack, "Spaceport Bar"); + secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT); window_addText(secondary_wid, 20, 20 + BUTTON_HEIGHT + 20, BAR_WIDTH-140, BAR_HEIGHT - 40 - BUTTON_HEIGHT - 60, @@ -65,11 +61,7 @@ static void spaceport_bar_close(char* str) { // Planet news reports. static void news(void) { - secondary_wid = window_create(-1, -1, NEWS_WIDTH, NEWS_HEIGHT); - - // Window title. - window_addText(secondary_wid, 0, -20, NEWS_WIDTH, 0, 1, - "txtTitle", NULL, &cBlack, "News Reports"); + secondary_wid = window_create("New Reports", -1, -1, NEWS_WIDTH, NEWS_HEIGHT); window_addText(secondary_wid, 20, 20 + BUTTON_HEIGHT + 20, NEWS_WIDTH-40, NEWS_HEIGHT - 20 - BUTTON_HEIGHT - 20 - 20 -20, @@ -89,10 +81,9 @@ static void news_close(char* str) { void land(Planet* p) { if(landed) return; planet = p; - land_wid = window_create(-1, -1, LAND_WIDTH, LAND_HEIGHT); + land_wid = window_create(p->name, -1, -1, LAND_WIDTH, LAND_HEIGHT); // Pretty display. - window_addText(land_wid, 0., -20, LAND_WIDTH, 0, 1, "txtPlanet", NULL, &cBlack, p->name); window_addImage(land_wid, 20, -440, "imgPlanet", p->gfx_exterior); window_addText(land_wid, 440, 80, 200, 460, 0, "txtPlanetDesc", &gl_smallFont, &cBlack, p->description); diff --git a/src/toolkit.c b/src/toolkit.c index 554fdf5..58ee140 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -47,6 +47,7 @@ typedef struct { typedef struct { unsigned int id; // Unique identifier. + char* name; double x,y; // Position. double w,h; // Dimensions. @@ -162,7 +163,7 @@ static Window* window_get(const unsigned int wid) { } // Create a window. -unsigned int window_create(const int x, const int y, const int w, const int h) { +unsigned int window_create(char* name, const int x, const int y, const int w, const int h) { if(nwindows >= mwindows) { // We have reached our memory limit. windows = realloc(windows, sizeof(Window)*(++mwindows)); @@ -172,6 +173,7 @@ unsigned int window_create(const int x, const int y, const int w, const int h) { const int wid = (++genwid); // Unique id windows[nwindows].id = wid; + windows[nwindows].name = strdup(name); windows[nwindows].w = (double) w; windows[nwindows].h = (double) h; @@ -221,6 +223,7 @@ void window_destroy(unsigned int wid) { // Destroy the window. for(i = 0; i < nwindows; i++) if(windows[i].id == wid) { + if(windows[i].name) free(windows[i].name); for(j = 0; j < windows[i].nwidgets; j++) widget_cleanup(&windows[i].widgets[j]); free(windows[i].widgets); @@ -424,6 +427,12 @@ static void window_render(Window* w) { glVertex2d(x+21., y); // Back to beginning. glEnd(); + // Render the window name. + gl_printMid(&gl_defFont, w->w, + x + (double)gl_screen.w/2., + y + w->h - 20. + (double)gl_screen.h/2., + &cBlack, w->name); + // Widgets. for(i = 0; i < w->nwidgets; i++) { switch(w->widgets[i].type) { diff --git a/src/toolkit.h b/src/toolkit.h index 10bfa07..eea5dfd 100644 --- a/src/toolkit.h +++ b/src/toolkit.h @@ -6,7 +6,7 @@ extern int toolkit; // Creation. -unsigned int window_create(const int x, const int y, const int w, const int h); +unsigned int window_create(char* name, const int x, const int y, const int w, const int h); void window_addButton(const unsigned int wid, const int x, const int y, const int w, const int h, char* name, char* display,