[Add] Embed name on window creation rather than having the overhead of writing and positioning a block of text.
This commit is contained in:
parent
4384adec98
commit
8f7df9fc2f
15
src/land.c
15
src/land.c
@ -44,11 +44,7 @@ static void shipyard(void) {
|
|||||||
|
|
||||||
// Spaceport bar.
|
// Spaceport bar.
|
||||||
static void spaceport_bar(void) {
|
static void spaceport_bar(void) {
|
||||||
secondary_wid = window_create(-1, -1, BAR_WIDTH, BAR_HEIGHT);
|
secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT);
|
||||||
|
|
||||||
// Window title.
|
|
||||||
window_addText(secondary_wid, 0, -20, BAR_WIDTH, 0, 1,
|
|
||||||
"txtTitle", NULL, &cBlack, "Spaceport Bar");
|
|
||||||
|
|
||||||
window_addText(secondary_wid, 20, 20 + BUTTON_HEIGHT + 20,
|
window_addText(secondary_wid, 20, 20 + BUTTON_HEIGHT + 20,
|
||||||
BAR_WIDTH-140, BAR_HEIGHT - 40 - BUTTON_HEIGHT - 60,
|
BAR_WIDTH-140, BAR_HEIGHT - 40 - BUTTON_HEIGHT - 60,
|
||||||
@ -65,11 +61,7 @@ static void spaceport_bar_close(char* str) {
|
|||||||
|
|
||||||
// Planet news reports.
|
// Planet news reports.
|
||||||
static void news(void) {
|
static void news(void) {
|
||||||
secondary_wid = window_create(-1, -1, NEWS_WIDTH, NEWS_HEIGHT);
|
secondary_wid = window_create("New Reports", -1, -1, NEWS_WIDTH, NEWS_HEIGHT);
|
||||||
|
|
||||||
// Window title.
|
|
||||||
window_addText(secondary_wid, 0, -20, NEWS_WIDTH, 0, 1,
|
|
||||||
"txtTitle", NULL, &cBlack, "News Reports");
|
|
||||||
|
|
||||||
window_addText(secondary_wid, 20, 20 + BUTTON_HEIGHT + 20,
|
window_addText(secondary_wid, 20, 20 + BUTTON_HEIGHT + 20,
|
||||||
NEWS_WIDTH-40, NEWS_HEIGHT - 20 - BUTTON_HEIGHT - 20 - 20 -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) {
|
void land(Planet* p) {
|
||||||
if(landed) return;
|
if(landed) return;
|
||||||
planet = p;
|
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.
|
// 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_addImage(land_wid, 20, -440, "imgPlanet", p->gfx_exterior);
|
||||||
window_addText(land_wid, 440, 80, 200, 460, 0,
|
window_addText(land_wid, 440, 80, 200, 460, 0,
|
||||||
"txtPlanetDesc", &gl_smallFont, &cBlack, p->description);
|
"txtPlanetDesc", &gl_smallFont, &cBlack, p->description);
|
||||||
|
@ -47,6 +47,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int id; // Unique identifier.
|
unsigned int id; // Unique identifier.
|
||||||
|
char* name;
|
||||||
|
|
||||||
double x,y; // Position.
|
double x,y; // Position.
|
||||||
double w,h; // Dimensions.
|
double w,h; // Dimensions.
|
||||||
@ -162,7 +163,7 @@ static Window* window_get(const unsigned int wid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a window.
|
// 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) {
|
if(nwindows >= mwindows) {
|
||||||
// We have reached our memory limit.
|
// We have reached our memory limit.
|
||||||
windows = realloc(windows, sizeof(Window)*(++mwindows));
|
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
|
const int wid = (++genwid); // Unique id
|
||||||
|
|
||||||
windows[nwindows].id = wid;
|
windows[nwindows].id = wid;
|
||||||
|
windows[nwindows].name = strdup(name);
|
||||||
|
|
||||||
windows[nwindows].w = (double) w;
|
windows[nwindows].w = (double) w;
|
||||||
windows[nwindows].h = (double) h;
|
windows[nwindows].h = (double) h;
|
||||||
@ -221,6 +223,7 @@ void window_destroy(unsigned int wid) {
|
|||||||
// Destroy the window.
|
// Destroy the window.
|
||||||
for(i = 0; i < nwindows; i++)
|
for(i = 0; i < nwindows; i++)
|
||||||
if(windows[i].id == wid) {
|
if(windows[i].id == wid) {
|
||||||
|
if(windows[i].name) free(windows[i].name);
|
||||||
for(j = 0; j < windows[i].nwidgets; j++)
|
for(j = 0; j < windows[i].nwidgets; j++)
|
||||||
widget_cleanup(&windows[i].widgets[j]);
|
widget_cleanup(&windows[i].widgets[j]);
|
||||||
free(windows[i].widgets);
|
free(windows[i].widgets);
|
||||||
@ -424,6 +427,12 @@ static void window_render(Window* w) {
|
|||||||
glVertex2d(x+21., y); // Back to beginning.
|
glVertex2d(x+21., y); // Back to beginning.
|
||||||
glEnd();
|
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.
|
// Widgets.
|
||||||
for(i = 0; i < w->nwidgets; i++) {
|
for(i = 0; i < w->nwidgets; i++) {
|
||||||
switch(w->widgets[i].type) {
|
switch(w->widgets[i].type) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
extern int toolkit;
|
extern int toolkit;
|
||||||
|
|
||||||
// Creation.
|
// 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,
|
void window_addButton(const unsigned int wid, const int x, const int y,
|
||||||
const int w, const int h, char* name, char* display,
|
const int w, const int h, char* name, char* display,
|
||||||
|
Loading…
Reference in New Issue
Block a user