From 811fc0b92a4789f5519422f795891934a4ab2a96 Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Sun, 17 Feb 2013 21:56:57 +0000
Subject: [PATCH] [Change] What in the world was I thinking with the gui crap??
 Large refactoring..

---
 src/collision.c |   4 +-
 src/collision.h |   4 +-
 src/main.c      |  10 +-
 src/opengl.c    |  57 +++++------
 src/opengl.h    |  51 +++++-----
 src/outfit.h    |   6 +-
 src/player.c    | 244 +++++++++++++++++++++++-------------------------
 src/ship.h      |   2 +-
 src/space.h     |   2 +-
 src/toolkit.c   |  82 ++++++++--------
 10 files changed, 230 insertions(+), 232 deletions(-)

diff --git a/src/collision.c b/src/collision.c
index 932f0a2..2c522a4 100644
--- a/src/collision.c
+++ b/src/collision.c
@@ -11,8 +11,8 @@
 // bsx  - Position of x of sprite b.
 // bsy  - Position of y of sprite b.
 // bp   - Position in space of sprite b.
-int CollideSprite(const gl_texture* at, const int asx, const int asy, const Vec2* ap,
-      const gl_texture* bt, const int bsx, const int bsy, const Vec2* bp) {
+int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2* ap,
+      const glTexture* bt, const int bsx, const int bsy, const Vec2* bp) {
   
   int x,y;
 
diff --git a/src/collision.h b/src/collision.h
index 1d9425b..0eb5955 100644
--- a/src/collision.h
+++ b/src/collision.h
@@ -2,6 +2,6 @@
 #include "opengl.h"
 #include "physics.h"
 
-int CollideSprite(const gl_texture* at, const int asx, const int asy, const Vec2* ap,
-      const gl_texture* bt, const int bsx, const int bsy, const Vec2* bp);
+int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2* ap,
+      const glTexture* bt, const int bsx, const int bsy, const Vec2* bp);
 
diff --git a/src/main.c b/src/main.c
index 75a809c..450041f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -122,7 +122,7 @@ int main(int argc, char** argv) {
     WARN("Error initializing AI");
 
   // Misc openGL init stuff.
-  gl_fontInit(NULL, NULL, FONT_SIZE); // Init default font size.
+  glFontInit(NULL, NULL, FONT_SIZE); // Init default font size.
   gui_init(); // Init the GUI crap.
   toolkit_init(); // Init the toolkit.
 
@@ -240,6 +240,7 @@ static void render_space(void) {
 static double fps = 0.;
 static double fps_cur = 0.;
 static void display_fps(const double dt) {
+  double x, y;
   fps_dt += dt;
   fps_cur += 1.;
   if(fps_dt > 1.) {
@@ -247,10 +248,11 @@ static void display_fps(const double dt) {
     fps = fps_cur / fps_dt;
     fps_dt = fps_cur = 0.;
   }
-  Vec2 pos;
-  vect_csetmin(&pos, 10., (double)(gl_screen.h-20));
+
+  x = 10.;
+  y = (double)(gl_screen.h - 20);
   if(show_fps)
-    gl_print(NULL, &pos, NULL, "%3.2f", fps);
+    gl_print(NULL, x, y, NULL, "%3.2f", fps);
 }
 
 static void data_name(void) {
diff --git a/src/opengl.c b/src/opengl.c
index a9433b1..b6d3bcd 100644
--- a/src/opengl.c
+++ b/src/opengl.c
@@ -19,34 +19,34 @@
 #define FONT_DEF "../gfx/fonts/font.ttf"
 
 // Default colors.
-gl_colour cLightGrey   = { .r = 0.80, .g = 0.80, .b = 0.80, .a = 1 };
-gl_colour cGrey        = { .r = 0.65, .g = 0.65, .b = 0.65, .a = 1 };
-gl_colour cDarkGrey    = { .r = 0.50, .g = 0.50, .b = 0.50, .a = 1 };
-gl_colour cGreen       = { .r = 0.20, .g = 0.80, .b = 0.20, .a = 1 };
-gl_colour cRed         = { .r = 0.80, .g = 0.20, .b = 0.20, .a = 1 };
+glColour cLightGrey   = { .r = 0.80, .g = 0.80, .b = 0.80, .a = 1 };
+glColour cGrey        = { .r = 0.65, .g = 0.65, .b = 0.65, .a = 1 };
+glColour cDarkGrey    = { .r = 0.50, .g = 0.50, .b = 0.50, .a = 1 };
+glColour cGreen       = { .r = 0.20, .g = 0.80, .b = 0.20, .a = 1 };
+glColour cRed         = { .r = 0.80, .g = 0.20, .b = 0.20, .a = 1 };
 
 // offsets to Adjust the pilot's place onscreen to be in the middle, even with the GUI.
 extern double gui_xoff;
 extern double gui_yoff;
 
 // The screen info, gives data of current opengl settings.
-gl_info gl_screen;
+glInfo gl_screen;
 
 // Our precious camera.
 Vec2* gl_camera;
 
 // Default font.
-gl_font gl_defFont;
+glFont gl_defFont;
 
 // Misc.
 static int SDL_VFlipSurface(SDL_Surface* surface);
 static int SDL_IsTrans(SDL_Surface* s, int x, int y);
 static uint8_t* SDL_MapTrans(SDL_Surface* s);
 static int pot(int n);
-// gl_texture.
+// glTexture.
 static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh);
 // Gl font.
-static void gl_fontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* tex_base, int* width_base);
+static void glFontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* tex_base, int* width_base);
 // PNG.
 int write_png(const char* file_name, png_bytep* rows, int w, int h, int colourtype, int bitdepth);
 
@@ -246,11 +246,11 @@ static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh) {
 }
 
 // Load the SDL_Surface to an openGL texture.
-gl_texture* gl_loadImage(SDL_Surface* surface) {
+glTexture* gl_loadImage(SDL_Surface* surface) {
   int rw, rh;
 
   // Set up the texture defaults.
-  gl_texture* texture = MALLOC_L(gl_texture);
+  glTexture* texture = MALLOC_L(glTexture);
   texture->w = (double)surface->w;
   texture->h = (double)surface->h;
   texture->sx = 1.;
@@ -269,9 +269,9 @@ gl_texture* gl_loadImage(SDL_Surface* surface) {
 }
 
 // Load the image directly as an opengl texture.
-gl_texture* gl_newImage(const char* path) {
+glTexture* gl_newImage(const char* path) {
   SDL_Surface* tmp, *surface;
-  gl_texture* t;
+  glTexture* t;
   uint8_t* trans = NULL;
   uint32_t filesize;
   char* buf = pack_readfile(DATA, (char*)path, &filesize);
@@ -313,8 +313,8 @@ gl_texture* gl_newImage(const char* path) {
 }
 
 // Load the texture immediately, but also set is as a sprite.
-gl_texture* gl_newSprite(const char* path, const int sx, const int sy) {
-  gl_texture* texture;
+glTexture* gl_newSprite(const char* path, const int sx, const int sy) {
+  glTexture* texture;
   if((texture = gl_newImage(path)) == NULL)
     return NULL;
   texture->sx = (double)sx;
@@ -325,19 +325,19 @@ gl_texture* gl_newSprite(const char* path, const int sx, const int sy) {
 }
 
 // Free the texture.
-void gl_freeTexture(gl_texture* texture) {
+void gl_freeTexture(glTexture* texture) {
   glDeleteTextures(1, &texture->texture);
   if(texture->trans) free(texture->trans);
   free(texture);
 }
 
 // Return true if pixel at pos (x,y) is transparent.
-int gl_isTrans(const gl_texture* t, const int x, const int y) {
+int gl_isTrans(const glTexture* t, const int x, const int y) {
   return !(t->trans[(y*(int)(t->w)+x)/8] & (1<<((y*(int)(t->w)+x)%8)));
 }
 
-// Set x and y to be the appropriate sprite for gl_texture using dir.
-void gl_getSpriteFromDir(int* x, int* y, const gl_texture* t, const double dir) {
+// Set x and y to be the appropriate sprite for glTexture using dir.
+void gl_getSpriteFromDir(int* x, int* y, const glTexture* t, const double dir) {
   int s = (int)(dir / (2.0*M_PI / (t->sy*t->sx)));
 
   // Make sure the sprite is "in range".
@@ -352,7 +352,7 @@ void gl_getSpriteFromDir(int* x, int* y, const gl_texture* t, const double dir)
 // ================
 
 // Blit the sprite at given position.
-void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, const int sy, const gl_colour* c) {
+void gl_blitSprite(const glTexture* sprite, const Vec2* pos, const int sx, const int sy, const glColour* c) {
   // Don't bother drawing if offscreen -- waste of cycles.
   if(fabs(VX(*pos) -VX(*gl_camera)+gui_xoff) > gl_screen.w / 2 + sprite->sw / 2 ||
         fabs(VY(*pos) -VY(*gl_camera)+gui_yoff) > gl_screen.h / 2 + sprite->sh / 2)
@@ -394,7 +394,7 @@ void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, cons
 }
 
 // Just straight out blit the thing at position.
-void gl_blitStatic(const gl_texture* texture, const Vec2* pos, const gl_colour* c) {
+void gl_blitStatic(const glTexture* texture, const Vec2* pos, const glColour* c) {
   glEnable(GL_TEXTURE_2D);
   glMatrixMode(GL_PROJECTION);
   glPushMatrix(); // Set up translation matrix.
@@ -428,7 +428,8 @@ void gl_bindCamera(const Vec2* pos) {
 
 // Print text on screen! YES!!!! Just like printf! But different!
 // Defaults ft_font to gl_defFont if NULL.
-void gl_print(const gl_font* ft_font, const Vec2* pos, const gl_colour* c, const char* fmt, ...) {
+void gl_print(const glFont* ft_font, const double x, const double y,
+      const glColour* c, const char* fmt, ...) {
   //float h = ft_font->h / .63; // Slightly increases font size.
   char text[256];
   va_list ap;
@@ -450,7 +451,7 @@ void gl_print(const gl_font* ft_font, const Vec2* pos, const gl_colour* c, const
   glMatrixMode(GL_PROJECTION);
 
   glPushMatrix(); // Translation matrix.
-  glTranslated(VX(*pos) - (double)gl_screen.w/2., VY(*pos) - (double)gl_screen.h/2., 0);
+  glTranslated(x - (double)gl_screen.w/2., y - (double)gl_screen.h/2., 0);
 
   if(c == NULL) glColor4d(1., 1., 1., 1.);
   else COLOUR(*c);
@@ -461,7 +462,7 @@ void gl_print(const gl_font* ft_font, const Vec2* pos, const gl_colour* c, const
 }
 
 // Get the width of the text about to be printed.
-int gl_printWidth(const gl_font* ft_font, const char* fmt, ...) {
+int gl_printWidth(const glFont* ft_font, const char* fmt, ...) {
   int i, n;
   char txt[256]; // Holds the string.
   va_list ap;
@@ -485,7 +486,7 @@ int gl_printWidth(const gl_font* ft_font, const char* fmt, ...) {
 // ================
 // FONT!
 // ================
-static void gl_fontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* tex_base, int* width_base) {
+static void glFontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* tex_base, int* width_base) {
   FT_Glyph glyph;
   FT_Bitmap bitmap;
   GLubyte* expanded_data;
@@ -562,7 +563,7 @@ static void gl_fontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* te
   FT_Done_Glyph(glyph);
 }
 
-void gl_fontInit(gl_font* font, const char* fname, const unsigned int h) {
+void glFontInit(glFont* font, const char* fname, const unsigned int h) {
   if(font == NULL) font = &gl_defFont;
   
   uint32_t bufsize;
@@ -598,7 +599,7 @@ void gl_fontInit(gl_font* font, const char* fname, const unsigned int h) {
   // Create each of the font display lists.
   unsigned char i;
   for(i = 0; i < 128; i++)
-    gl_fontMakeDList(face, i, font->list_base, font->textures, font->w);
+    glFontMakeDList(face, i, font->list_base, font->textures, font->w);
 
   // We can now free the face and library.
   FT_Done_Face(face);
@@ -606,7 +607,7 @@ void gl_fontInit(gl_font* font, const char* fname, const unsigned int h) {
   free(buf);
 }
 
-void gl_freeFont(gl_font* font) {
+void gl_freeFont(glFont* font) {
   if(font == NULL) font = &gl_defFont;
   glDeleteLists(font->list_base, 128);
   glDeleteTextures(128, font->textures);
diff --git a/src/opengl.h b/src/opengl.h
index c4b4e87..c7481a7 100644
--- a/src/opengl.h
+++ b/src/opengl.h
@@ -24,21 +24,21 @@ typedef struct {
   int fullscreen;   // 1 = fullscreen, 0 = windowed.
   int r, g, b, a;   // Framebuffer values in bits.
   int doublebuf;    // Double buffer.
-} gl_info;
-extern gl_info gl_screen; // Local structure set with gl_init etc.
+} glInfo;
+extern glInfo gl_screen; // Local structure set with gl_init etc.
 
 // Colours.
 typedef struct {
   double r, g, b, a;
-} gl_colour;
+} glColour;
 #define COLOUR(x) glColor4d((x).r, (x).g, (x).b, (x).a)
 
 // Default colors.
-extern gl_colour cLightGrey;
-extern gl_colour cGrey;
-extern gl_colour cDarkGrey;
-extern gl_colour cGreen;
-extern gl_colour cRed;
+extern glColour cLightGrey;
+extern glColour cGrey;
+extern glColour cDarkGrey;
+extern glColour cGreen;
+extern glColour cRed;
 
 // Spritesheet info.
 typedef struct {
@@ -48,7 +48,7 @@ typedef struct {
   double sw, sh;      // Size of each sprite.
   GLuint texture;     // The opengl texture itself.
   uint8_t* trans;     // Maps the transparency.
-} gl_texture;
+} glTexture;
 
 // Font info.
 typedef struct {
@@ -56,35 +56,36 @@ typedef struct {
   int* w;
   GLuint* textures;
   GLuint list_base;
-} gl_font;
-extern gl_font gl_defFont; // Default font.
+} glFont;
+extern glFont gl_defFont; // Default font.
 
-// gl_font loading/freeing.
+// glFont loading/freeing.
 // If font is NULL it uses the internal default font, same with gl_print
-void gl_fontInit(gl_font* font, const char* fname, const unsigned int h);
-void gl_freeFont(gl_font* font);
+void glFontInit(glFont* font, const char* fname, const unsigned int h);
+void gl_freeFont(glFont* font);
 
 // gl_texute loading/freeing.
-gl_texture* gl_loadImage(SDL_Surface* surface); // Frees the surface.
-gl_texture* gl_newImage(const char* path);
-gl_texture* gl_newSprite(const char* path, const int sx, const int sy);
-void gl_freeTexture(gl_texture* texture);
+glTexture* gl_loadImage(SDL_Surface* surface); // Frees the surface.
+glTexture* gl_newImage(const char* path);
+glTexture* gl_newSprite(const char* path, const int sx, const int sy);
+void gl_freeTexture(glTexture* texture);
 
 // Rendering.
-void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, 
-      const int sx, const int sy, const gl_colour* c);
+void gl_blitSprite(const glTexture* sprite, const Vec2* pos, 
+      const int sx, const int sy, const glColour* c);
 
-void gl_blitStatic(const gl_texture* texture, const Vec2* pos, const gl_colour* c);
+void gl_blitStatic(const glTexture* texture, const Vec2* pos, const glColour* c);
 void gl_bindCamera(const Vec2* pos);
-void gl_print(const gl_font* ft_font, const Vec2* pos, const gl_colour* c, const char* fmt, ...);
-int  gl_printWidth(const gl_font* ft_font, const char* fmt, ...);
+void gl_print(const glFont* ft_font, const double x, const double y,
+      const glColour* c, const char* fmt, ...);
+int  gl_printWidth(const glFont* ft_font, const char* fmt, ...);
 
 // Initialize/cleanup.
 int gl_init(void);
 void gl_exit(void);
 
 // Misc.
-int gl_isTrans(const gl_texture* t, const int x, const int y);
-void gl_getSpriteFromDir(int* x, int* y, const gl_texture* t, const double dir);
+int gl_isTrans(const glTexture* t, const int x, const int y);
+void gl_getSpriteFromDir(int* x, int* y, const glTexture* t, const double dir);
 void gl_screenshot(const char* filename);
 
diff --git a/src/outfit.h b/src/outfit.h
index 422d584..2eceb69 100644
--- a/src/outfit.h
+++ b/src/outfit.h
@@ -31,7 +31,7 @@ typedef struct {
   int tech;
   int mass;
 
-  gl_texture gfx_store; // Store graphic.
+  glTexture gfx_store; // Store graphic.
 
   int properties; // Properties stored bitwise.
   
@@ -45,7 +45,7 @@ typedef struct {
       double accuracy; // Desviation accuracy.
       double damage_armour, damage_shield; // Damage.
 
-      gl_texture* gfx_space;
+      glTexture* gfx_space;
     };
     struct { // Launcher.
       //unsigned int delay; // Delay between shots.
@@ -58,7 +58,7 @@ typedef struct {
       unsigned int duration; // Duration.
       //double damage_armour, damage_shield; // Damage.
 
-      //gl_texture* gfx_space;
+      //glTexture* gfx_space;
     };
   };
 } Outfit;
diff --git a/src/player.c b/src/player.c
index f1ffcda..6281a93 100644
--- a/src/player.c
+++ b/src/player.c
@@ -40,22 +40,23 @@ extern int pilots;
 
 // -- Colours.
 // Standard colors.
-gl_colour cConsole          = { .r = 0.5, .g = 0.8, .b = 0.5, .a = 1. };
+glColour cConsole          = { .r = 0.5, .g = 0.8, .b = 0.5, .a = 1. };
 
-gl_colour cInert            = { .r = 0.6, .g = 0.6, .b = 0.6, .a = 1. };
-gl_colour cNeutral          = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. };
-gl_colour cFriend           = { .r = 0.0, .g = 1.0, .b = 0.0, .a = 1. };
-gl_colour cHostile          = { .r = 0.9, .g = 0.2, .b = 0.2, .a = 1. };
+glColour cInert            = { .r = 0.6, .g = 0.6, .b = 0.6, .a = 1. };
+glColour cNeutral          = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. };
+glColour cFriend           = { .r = 0.0, .g = 1.0, .b = 0.0, .a = 1. };
+glColour cHostile          = { .r = 0.9, .g = 0.2, .b = 0.2, .a = 1. };
 
-gl_colour cRadar_player     = { .r = 0.4, .g = 0.8, .b = 0.4, .a = 1. };
-gl_colour cRadar_targ       = { .r = 0.0, .g = 0.7, .b = 1.0, .a = 1. };
-gl_colour cRadar_weap       = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. };
+glColour cRadar_player     = { .r = 0.4, .g = 0.8, .b = 0.4, .a = 1. };
+glColour cRadar_targ       = { .r = 0.0, .g = 0.7, .b = 1.0, .a = 1. };
+glColour cRadar_weap       = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. };
 // Bars.
-gl_colour cShield           = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. };
-gl_colour cArmor            = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. };
-gl_colour cEnergy           = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. };
+glColour cShield           = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. };
+glColour cArmor            = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. };
+glColour cEnergy           = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. };
 
 typedef struct {
+  double x,y; // Position.
   double w,h; // Dimensions.
   RadarShape shape;
   double res; // Resolution.
@@ -68,29 +69,27 @@ typedef struct {
 #define RADAR_RES_DEFAULT   40.
 
 typedef struct {
+  double x,y;
   double w,h;
 } Rect;
 
 typedef struct {
   // Graphics.
-  gl_font smallFont;
-  gl_texture* gfx_frame;
-  gl_texture* gfx_targetPilot, *gfx_targetPlanet;
+  glFont smallFont;
+  glTexture* gfx_frame;
+  glTexture* gfx_targetPilot, *gfx_targetPlanet;
+
   Radar radar;
   Rect nav;
   Rect shield, armour, energy;
   Rect weapon;
+  Rect target_health, target_name, target_faction;
   Rect misc;
+  Rect msg;
 
   // Positions.
-  Vec2 pos_frame;
-  Vec2 pos_radar;
-  Vec2 pos_nav;
-  Vec2 pos_shield, pos_armour, pos_energy;
-  Vec2 pos_weapon;
-  Vec2 pos_target, pos_target_health, pos_target_name, pos_target_faction;
-  Vec2 pos_misc;
-  Vec2 pos_msg;
+  Vec2 frame;
+  Vec2 target;
 } GUI;
 
 GUI gui; // Le Gui!
@@ -116,7 +115,7 @@ extern void planets_minimap(const double res, const double w, const double h, co
 static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w, double* h);
 static int gui_parse(const xmlNodePtr parent, const char* name);
 static void gui_renderPilot(const Pilot* p);
-static void gui_renderBar(const gl_colour* c, const Vec2* p, const Rect* r, const double w);
+static void gui_renderBar(const glColour* c, const Rect* r, const double w);
 
 // Create a new player.
 void player_new(void) {
@@ -213,12 +212,13 @@ void player_message(const char* fmt, ...) {
 // Render the player.
 void player_render(void) {
   int i, j;
+  double x, y;
   char str[10];
   Pilot* p;
   Planet* planet;
+  glColour* c;
+  glFont* f;
   Vec2 v;
-  gl_colour* c;
-  gl_font* f;
 
   // Render the player target graphics.
   if(player_target != PLAYER_ID) {
@@ -260,16 +260,16 @@ void player_render(void) {
 
   // GUI!
   // -- Frame.
-  gl_blitStatic(gui.gfx_frame, &gui.pos_frame, NULL);
+  gl_blitStatic(gui.gfx_frame, &gui.frame, NULL);
   // -- Radar.
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   if(gui.radar.shape == RADAR_RECT)
-    glTranslated(VX(gui.pos_radar) - gl_screen.w/2. + gui.radar.w/2.,
-          VY(gui.pos_radar) - gl_screen.h/2. - gui.radar.h/2., 0.);
+    glTranslated(gui.radar.x - gl_screen.w/2. + gui.radar.w/2.,
+          gui.radar.y - gl_screen.h/2. - gui.radar.h/2., 0.);
   else if(gui.radar.shape == RADAR_CIRCLE)
-    glTranslated(VX(gui.pos_radar) - gl_screen.w/2.,
-          VY(gui.pos_radar) - gl_screen.h/2., 0.);
+    glTranslated(gui.radar.x - gl_screen.w/2.,
+          gui.radar.y - gl_screen.h/2., 0.);
   
   // Planets.
   COLOUR(cFriend);
@@ -312,35 +312,36 @@ void player_render(void) {
   if(planet_target >= 0) {
     // Planet landing target.
     i = gl_printWidth(NULL, "Land");
-    vect_csetmin(&v, VX(gui.pos_nav) + (gui.nav.w - i)/2., VY(gui.pos_nav) - 5);
-    gl_print(NULL, &v, &cConsole, "Land");
+    gl_print(NULL, gui.nav.x + (gui.nav.w - i)/2.,
+          gui.nav.y - 5, &cConsole, "Land");
     i = gl_printWidth(&gui.smallFont, "%s", cur_system->planets[planet_target].name);
-    vect_csetmin(&v, VX(gui.pos_nav) + (gui.nav.w - i)/2., VY(gui.pos_nav) - 10 - gui.smallFont.h);
-    gl_print(&gui.smallFont, &v, NULL, "%s", cur_system->planets[planet_target].name);  
+    gl_print(&gui.smallFont, gui.nav.x + (gui.nav.w - i)/2.,
+          gui.nav.y - 10 - gui.smallFont.h, NULL,
+          "%s", cur_system->planets[planet_target].name);  
   }
   else if(planet_target == -1) {
     // No planet target.
     i = gl_printWidth(NULL, "Navigation");
-    vect_csetmin(&v, VX(gui.pos_nav) + (gui.nav.w - i)/2., VY(gui.pos_nav) - 5);
-    gl_print(NULL, &v, &cConsole, "Navigation");
+    gl_print(NULL, gui.nav.x + (gui.nav.w - i)/2.,
+          gui.nav.y - 5, &cConsole, "Navigation");
     i = gl_printWidth(&gui.smallFont, "Off");
-    vect_csetmin(&v, VX(gui.pos_nav) + (gui.nav.w - i)/2., VY(gui.pos_nav) - 10 - gui.smallFont.h);
-    gl_print(&gui.smallFont, &v, &cGrey, "Off");
+    gl_print(&gui.smallFont, gui.nav.x + (gui.nav.w - i)/2.,
+          gui.nav.y - 10 - gui.smallFont.h, &cGrey, "Off");
   }
 
   // Health
-  gui_renderBar(&cShield, &gui.pos_shield, &gui.shield, player->shield / player->shield_max);
-  gui_renderBar(&cArmor,  &gui.pos_armour, &gui.armour, player->armour / player->armour_max);
-  gui_renderBar(&cEnergy, &gui.pos_energy, &gui.energy, player->energy / player->energy_max);
+  gui_renderBar(&cShield, &gui.shield, player->shield / player->shield_max);
+  gui_renderBar(&cArmor,  &gui.armour, player->armour / player->armour_max);
+  gui_renderBar(&cEnergy, &gui.energy, player->energy / player->energy_max);
   
   // Weapon.
   if(player->secondary == NULL) {
     i = gl_printWidth(NULL, "Secondary");
-    vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2., VY(gui.pos_weapon) - 5);
-    gl_print(NULL, &v, &cConsole, "Secondary");
+    gl_print(NULL, gui.weapon.x + (gui.weapon.w - i)/2.,
+          gui.weapon.y - 5, &cConsole, "Secondary");
     i = gl_printWidth(&gui.smallFont, "None");
-    vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2., VY(gui.pos_weapon) - 10 - gl_defFont.h);
-    gl_print(&gui.smallFont, &v, &cGrey, "None");
+    gl_print(&gui.smallFont, gui.weapon.x + (gui.weapon.w - i)/2.,
+          gui.weapon.y - 10 - gl_defFont.h, &cGrey, "None");
   } else {
     f = &gl_defFont;
     if(player->ammo == NULL) {
@@ -350,9 +351,9 @@ void player_render(void) {
         f = &gui.smallFont;
         i = gl_printWidth(f, "%s", player->secondary->outfit->name);
       }
-      vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2.,
-            VY(gui.pos_weapon) - (gui.weapon.h - f->h)/2.);
-      gl_print(f, &v, &cConsole, "%s", player->secondary->outfit->name);
+      gl_print(f, gui.weapon.x + (gui.weapon.w - i)/2.,
+            gui.weapon.y - (gui.weapon.h - f->h)/2.,
+            &cConsole, "%s", player->secondary->outfit->name);
     } else {
       // Use the ammunitions name.
       i = gl_printWidth(f, "%s", player->secondary->outfit->name);
@@ -361,15 +362,15 @@ void player_render(void) {
         f = &gui.smallFont;
         i = gl_printWidth(f, "%s", player->ammo->outfit->name);
       }
-      vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2.,
-            VY(gui.pos_weapon) - 5);
-      gl_print(f, &v, NULL, "%s", player->ammo->outfit->name);
+      gl_print(f, gui.weapon.x + (gui.weapon.w - i)/2.,
+            gui.weapon.y - 5,
+            &cConsole, "%s", player->ammo->outfit->name);
 
       // Print ammo underneath to the left.
       i = gl_printWidth(&gui.smallFont, "%d", player->ammo->quantity);
-      vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2.,
-            VY(gui.pos_weapon) - 10 - gl_defFont.h);
-      gl_print(&gui.smallFont, &v, &cConsole, "%d", player->ammo->quantity);
+      gl_print(&gui.smallFont, gui.weapon.x + (gui.weapon.w - i)/2.,
+            gui.weapon.y - 10 - gl_defFont.h,
+            NULL, "%d", player->ammo->quantity);
     }
   }
 
@@ -377,33 +378,38 @@ void player_render(void) {
   if(player_target != PLAYER_ID) {
     p = pilot_get(player_target);
 
-    gl_blitStatic(p->ship->gfx_target, &gui.pos_target, NULL);
+    gl_blitStatic(p->ship->gfx_target, &gui.target, NULL);
     
     // Target name.
-    gl_print(NULL, &gui.pos_target_name, NULL, "%s", p->name);
-    gl_print(&gui.smallFont, &gui.pos_target_faction, NULL, "%s", p->faction->name);
+    gl_print(NULL, gui.target_name.x, gui.target_name.y,
+          NULL, "%s", p->name);
+    gl_print(&gui.smallFont, gui.target_faction.x, gui.target_faction.y,
+          NULL, "%s", p->faction->name);
 
     // Target status.
     if(pilot_isDisabled(p))
       // Disable the pilot.
-      gl_print(&gui.smallFont, &gui.pos_target_health, NULL, "Disabled");
+      gl_print(&gui.smallFont, gui.target_health.x, gui.target_health.y,
+            NULL, "Disabled");
     else if(p->shield > p->shield_max / 100.)
       // On shields.
-      gl_print(&gui.smallFont, &gui.pos_target_health, NULL, "%s: %.0f%%", "Shield", p->shield/p->shield_max*100.);
+      gl_print(&gui.smallFont, gui.target_health.x, gui.target_health.y,
+            NULL, "%s: %.0f%%", "Shield", p->shield/p->shield_max*100.);
     else
       // On armour.
-      gl_print(&gui.smallFont, &gui.pos_target_health, NULL, "%s: %.0f%%", "Armor", p->armour/p->armour_max*100.);
+      gl_print(&gui.smallFont, gui.target_health.x, gui.target_health.y,
+            NULL, "%s: %.0f%%", "Armor", p->armour/p->armour_max*100.);
   } else {
     // No target.
     i = gl_printWidth(NULL, "No Target");
-    vect_csetmin(&v, VX(gui.pos_target) + (SHIP_TARGET_W - i)/2., VY(gui.pos_target) + 
-          (SHIP_TARGET_H - gl_defFont.h)/2.);
-    gl_print(NULL, &v, &cGrey, "No Target");
+    gl_print(NULL, gui.target.x + (SHIP_TARGET_W - i)/2.,
+          gui.target.y + (SHIP_TARGET_H - gl_defFont.h)/2.,
+          &cGrey, "No Target");
   }
 
   // Misc.
-  vect_csetmin(&v, VX(gui.pos_misc) + 10, VY(gui.pos_misc) - 10 - gl_defFont.h);
-  gl_print(NULL, &v, &cConsole, "SCred:");
+  gl_print(NULL, gui.misc.x + 10, gui.misc.y - 10 - gl_defFont.h,
+        &cConsole, "SCred:");
   if(credits >= 1000000)
     snprintf(str, 10, "%.2fM", (double)credits / 1000000.);
   else if(credits >= 1000)
@@ -411,17 +417,18 @@ void player_render(void) {
   else
     snprintf(str, 10, "%d", credits);
   i = gl_printWidth(&gui.smallFont, "%s", str);
-  vect_csetmin(&v, VX(gui.pos_misc) + gui.misc.w - 10 - i, VY(gui.pos_misc) - 10 - gl_defFont.h);
-  gl_print(&gui.smallFont, &v, NULL, "%s", str);
+  gl_print(&gui.smallFont, gui.misc.x + gui.misc.w - 10 - i,
+        gui.misc.y - 10 - gl_defFont.h, NULL, "%s", str);
   
   // Messages.
-  vect_csetmin(&v, VX(gui.pos_msg), VY(gui.pos_msg) + (double)(gl_defFont.h*msg_max)*1.2);
+  x = gui.msg.x;
+  y = gui.msg.y + (double)(gl_defFont.h * msg_max)*1.2;
   for(i = 0; i < msg_max; i++) {
-    VY(v) -= (double)gl_defFont.h*1.2;
+    y -= (double)gl_defFont.h*1.2;
     if(msg_stack[msg_max-i-1].str[0] != '\0') {
       if(msg_stack[msg_max-i-1].t < SDL_GetTicks())
         msg_stack[msg_max-i-1].str[0] = '\0';
-      else gl_print(NULL, &v, NULL, "%s", msg_stack[msg_max-i-1].str);
+      else gl_print(NULL, x, y, NULL, "%s", msg_stack[msg_max-i-1].str);
     }
   }
 }
@@ -468,13 +475,13 @@ static void gui_renderPilot(const Pilot* p) {
 }
 
 // Render a bar.
-static void gui_renderBar(const gl_colour* c, const Vec2* p, const Rect* r, const double w) {
+static void gui_renderBar(const glColour* c, const Rect* r, const double w) {
   int x, y, sx, sy;
 
   glBegin(GL_QUADS);
     COLOUR(*c);
-    x = VX(*p) - gl_screen.w/2.;
-    y = VY(*p) - gl_screen.h/2.;
+    x = r->x - gl_screen.w/2.;
+    y = r->y - gl_screen.h/2.;
     sx = w * r->w;
     sy = r->h;
     glVertex2d(x, y);
@@ -492,11 +499,12 @@ int gui_init(void) {
   gui.gfx_targetPlanet = NULL;
 
   // Font.
-  gl_fontInit(&gui.smallFont, NULL, 10);
+  glFontInit(&gui.smallFont, NULL, 10);
   // -- Radar.
   gui.radar.res = RADAR_RES_DEFAULT;
   // -- messages.
-  vect_csetmin(&gui.pos_msg, 20,30);
+  gui.msg.x = 20;
+  gui.msg.y = 30;
   msg_stack = calloc(msg_max, sizeof(Msg));
 
   return 0;
@@ -603,9 +611,10 @@ static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w,
 }
 
 // Parse a gui node.
+#define RELATIVIZE(a) \
+      { (a).x += VX(gui.frame); (a).y = VY(gui.frame) + gui.gfx_frame->h-(a).y; }
 static int gui_parse(const xmlNodePtr parent, const char* name) {
   xmlNodePtr cur, node;
-  double x, y;
   char* tmp, *tmp2;
 
   // Gfx.
@@ -633,7 +642,7 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
   free(tmp2);
 
   // Frame (based on gfx).
-  vect_csetmin(&gui.pos_frame,
+  vect_csetmin(&gui.frame,
         gl_screen.w - gui.gfx_frame->w,  // x.
         gl_screen.h - gui.gfx_frame->h); // h.
 
@@ -641,11 +650,9 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
   node = parent->children;
   do {
     // Offset.
-    if(xml_isNode(node, "offset")) {
-      rect_parse(node, &x, &y, NULL, NULL);
-      gui_xoff = x;
-      gui_yoff = y;
-    }
+    if(xml_isNode(node, "offset"))
+      rect_parse(node, &gui_xoff, &gui_yoff, NULL, NULL);
+    // Radar.
     else if(xml_isNode(node, "radar")) {
       tmp = xml_nodeProp(node,"type");
       // Make sure type is valid.
@@ -659,93 +666,80 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
 
       // Load the appropriate measurements.
       if(gui.radar.shape == RADAR_RECT)
-        rect_parse(node, &x, &y, &gui.radar.w, &gui.radar.h);
+        rect_parse(node, &gui.radar.x, &gui.radar.y, &gui.radar.w, &gui.radar.h);
       else if(gui.radar.shape == RADAR_CIRCLE)
-        rect_parse(node, &x, &y, &gui.radar.w, NULL);
-      vect_csetmin(&gui.pos_radar,
-            VX(gui.pos_frame) + x,
-            VY(gui.pos_frame) + gui.gfx_frame->h - y);
+        rect_parse(node, &gui.radar.x, &gui.radar.y, &gui.radar.w, NULL);
+      RELATIVIZE(gui.radar);
     }
     // Nav computer.
     else if(xml_isNode(node, "nav")) {
-      rect_parse(node, &x, &y, &gui.nav.w, &gui.nav.h);
-      vect_csetmin(&gui.pos_nav,
-            VX(gui.pos_frame) + x,
-            VY(gui.pos_frame) + gui.gfx_frame->h - y - gl_defFont.h);
+      rect_parse(node, &gui.nav.x, &gui.nav.y, &gui.nav.w, &gui.nav.h);
+      RELATIVIZE(gui.nav);
+      gui.nav.y -= gl_defFont.h;
     }
     // Health bars.
     else if(xml_isNode(node, "health")) {
       cur = node->children;
       do {
         if(xml_isNode(cur, "shield")) {
-          rect_parse(cur, &x, &y, &gui.shield.w, &gui.shield.h);
-          vect_csetmin(&gui.pos_shield,
-          VX(gui.pos_frame) + x,
-          VY(gui.pos_frame) + gui.gfx_frame->h - y);
+          rect_parse(cur, &gui.shield.x, &gui.shield.y, &gui.shield.w, &gui.shield.h);
+          RELATIVIZE(gui.shield);
         }
       
         if(xml_isNode(cur, "armour")) {
-          rect_parse(cur, &x, &y, &gui.armour.w, &gui.armour.h);
-          vect_csetmin(&gui.pos_armour,
-          VX(gui.pos_frame) + x,
-          VY(gui.pos_frame) + gui.gfx_frame->h - y);
+          rect_parse(cur, &gui.armour.x, &gui.armour.y, &gui.armour.w, &gui.armour.h);
+          RELATIVIZE(gui.armour);
         }
       
         if(xml_isNode(cur, "energy")) {
-          rect_parse(cur, &x, &y, &gui.energy.w, &gui.energy.h);
-          vect_csetmin(&gui.pos_energy,
-          VX(gui.pos_frame) + x,
-          VY(gui.pos_frame) + gui.gfx_frame->h - y);
+          rect_parse(cur, &gui.energy.x, &gui.energy.y, &gui.energy.w, &gui.energy.h);
+          RELATIVIZE(gui.energy);
         }
       } while((cur = cur->next));
     }
     // Secondary weapon.
     else if(xml_isNode(node, "weapon")) {
-      rect_parse(node, &x, &y, &gui.weapon.w, &gui.weapon.h);
-      vect_csetmin(&gui.pos_weapon,
-            VX(gui.pos_frame) + x,
-            VY(gui.pos_frame) + gui.gfx_frame->h - y - gl_defFont.h);
+      rect_parse(node, &gui.weapon.x, &gui.weapon.y, &gui.weapon.w, &gui.weapon.h);
+      RELATIVIZE(gui.weapon);
+      gui.weapon.y -= gl_defFont.h;
     }
     // Target.
     else if(xml_isNode(node, "target")) {
       cur = node->children;
       do {
         if(xml_isNode(cur, "gfx")) {
-          rect_parse(cur, &x, &y, NULL, NULL);
-          vect_csetmin(&gui.pos_target,
-          VX(gui.pos_frame) + x,
-          VY(gui.pos_frame) + gui.gfx_frame->h - y - SHIP_TARGET_H);
+          rect_parse(cur, &gui.target.x, &gui.target.y, NULL, NULL);
+          RELATIVIZE(gui.target);
+          gui.target.y -= SHIP_TARGET_H;
         }
       
         if(xml_isNode(cur, "name")) {
-          rect_parse(cur, &x, &y, NULL, NULL);
-          vect_csetmin(&gui.pos_target_name,
-          VX(gui.pos_frame) + x,
-          VY(gui.pos_frame) + gui.gfx_frame->h - y - gl_defFont.h);
+          rect_parse(cur, &gui.target_name.x, &gui.target_name.y, NULL, NULL);
+          RELATIVIZE(gui.target_name);
+          gui.target_name.y -= gl_defFont.h;
         }
       
         if(xml_isNode(cur, "faction")) {
-          rect_parse(cur, &x, &y, NULL, NULL);
-          vect_csetmin(&gui.pos_target_faction,
-          VX(gui.pos_frame) + x,
-          VY(gui.pos_frame) + gui.gfx_frame->h - y - gui.smallFont.h);
+          rect_parse(cur, &gui.target_faction.x, &gui.target_faction.y, NULL, NULL);
+          RELATIVIZE(gui.target_faction);
+          gui.target_faction.y -= gui.smallFont.h;
         }
 
         if(xml_isNode(cur, "health")) {
-          rect_parse(cur, &x, &y, NULL, NULL);
-          vect_csetmin(&gui.pos_target_health,
-          VX(gui.pos_frame) + x,
-          VY(gui.pos_frame) + gui.gfx_frame->h - y - gui.smallFont.h);
+          rect_parse(cur, &gui.target_health.x, &gui.target_health.y, NULL, NULL);
+          RELATIVIZE(gui.target_health);
+          gui.target_health.y -= gui.smallFont.h;
         }
       } while((cur = cur->next));
     } else if(xml_isNode(node, "misc")) {
-      rect_parse(node, &x, &y, &gui.misc.w, &gui.misc.h);
-      vect_csetmin(&gui.pos_misc, VX(gui.pos_frame) + x, VY(gui.pos_frame) + gui.gfx_frame->h - y);
+      rect_parse(node, &gui.misc.x, &gui.misc.y, &gui.misc.w, &gui.misc.h);
+      RELATIVIZE(gui.misc);
     }
   } while((node = node->next));
 
   return 0;
 }
+#undef RELATIVIZE
 
 // Free the GUI.
 void gui_free(void) {
diff --git a/src/ship.h b/src/ship.h
index 7f9813a..0555900 100644
--- a/src/ship.h
+++ b/src/ship.h
@@ -32,7 +32,7 @@ typedef struct {
   double thrust, turn, speed;
 
   // Graphics.
-  gl_texture* gfx_space, *gfx_target;
+  glTexture* gfx_space, *gfx_target;
 
   // GUI interface.
   char* gui;
diff --git a/src/space.h b/src/space.h
index ad7c814..ae8a164 100644
--- a/src/space.h
+++ b/src/space.h
@@ -40,7 +40,7 @@ typedef struct {
 
   PlanetClass class; // Planet type.
   Faction* faction; // Planet faction.
-  gl_texture* gfx_space; // Graphics in space.
+  glTexture* gfx_space; // Graphics in space.
 } Planet;
 
 // Star systems.
diff --git a/src/toolkit.c b/src/toolkit.c
index a10bebf..473ded7 100644
--- a/src/toolkit.c
+++ b/src/toolkit.c
@@ -49,7 +49,9 @@ static int mwindows = 0;
 
 static Widget* window_newWidget(const unsigned int wid);
 static void widget_cleanup(Widget* widget);
+// Render.
 static void window_render(Window* w);
+static void toolkit_renderButton(Widget* btn, double bx, double by);
 
 // Add a button that when pressed will trigger call, passing it's name as the
 // only parameter.
@@ -162,62 +164,29 @@ void window_destroy(unsigned int wid) {
 
 // Render a window.
 static void window_render(Window* w) {
-  int i, j;
+  int i;
   double x, y;
-  Widget* wgt;
-  Vec2 v;
 
   x = w->x - (double)gl_screen.w/2.;
   y = w->y - (double)gl_screen.h/2.;
 
-  // Translate to window position  (bottom left).
-  glMatrixMode(GL_PROJECTION);
-  glPushMatrix(); // Projection translation matrix.
-  glTranslated(x, y, 0.);
-
   // Window background.
-  glBegin(GL_TRIANGLE_STRIP);
+  glBegin(GL_QUADS);
     COLOUR(cLightGrey);
 
-    glVertex2d(0.,      0.);
-    glVertex2d(w->w,    0.);
-    glVertex2d(0.,    w->h);
-    glVertex2d(w->w,  w->h);
+    glVertex2d(x,         y);
+    glVertex2d(x + w->w,  y);
+    glVertex2d(x + w->w,  y + w->h);
+    glVertex2d(x,         y + w->h);
   glEnd();
 
-  glPopMatrix(); // Gl Projection.
-
   // Widgets.
   for(i = 0; i < w->nwidgets; i++) {
-    wgt = &w->widgets[i];
-
-    switch(wgt->type) {
+    switch(w->widgets[i].type) {
       case WIDGET_NULL:
         break;
       case WIDGET_BUTTON:
-        glMatrixMode(GL_PROJECTION);
-        glPushMatrix(); // Projection matrix.
-        glTranslated(x + wgt->x, y + wgt->y, 0.);
-
-        glBegin(GL_TRIANGLE_STRIP);
-          switch(wgt->status) {
-            // Set the colour.
-            case WIDGET_STATUS_NORMAL:      COLOUR(cDarkGrey);  break;
-            case WIDGET_STATUS_MOUSEOVER:   COLOUR(cGrey);      break;
-            case WIDGET_STATUS_MOUSEDOWN:   COLOUR(cGreen);     break;
-          }
-          
-          glVertex2d(0.,          0.);
-          glVertex2d(wgt->w,      0.);
-          glVertex2d(0.,      wgt->h);
-          glVertex2d(wgt->w,  wgt->h);
-        glEnd();
-        glPopMatrix();
-
-        j = gl_printWidth(NULL, wgt->string);
-        vect_csetmin(&v, w->x + wgt->x + (wgt->w - (double)j)/2.,
-              w->y + wgt->y + (wgt->h - gl_defFont.h)/2.);
-        gl_print(NULL, &v, &cRed, wgt->string);
+        toolkit_renderButton(&w->widgets[i], x, y);
         break;
       case WIDGET_TEXT:
         break;
@@ -225,6 +194,37 @@ static void window_render(Window* w) {
   }
 }
 
+static void toolkit_renderButton(Widget* btn, double bx, double by) {
+  glColour* c;
+  double x, y;
+  int j;
+  
+  x = bx + btn->x;
+  y = by + btn->y;
+
+  switch(btn->status) {
+    // Set the color.
+    case WIDGET_STATUS_NORMAL:    c = &cDarkGrey; break;
+    case WIDGET_STATUS_MOUSEOVER: c = &cGrey;     break;
+    case WIDGET_STATUS_MOUSEDOWN: c = &cGreen;    break;
+  }
+
+  glShadeModel(GL_SMOOTH);
+  glBegin(GL_QUADS);
+    COLOUR(*c);
+    glVertex2d(x,           y + 2/3*btn->h);
+    glVertex2d(x + btn->w,  y + 2/3*btn->h);
+    glVertex2d(x + btn->w,  y + btn->h);
+    glVertex2d(x,           y + btn->h);
+  glEnd();
+
+  j = gl_printWidth(NULL, btn->string);
+  gl_print(NULL, 
+        bx + (double)gl_screen.w/2. + btn->x + (btn->w - (double)j)/2,
+        by + (double)gl_screen.h/2. + btn->y + (btn->h - gl_defFont.h)/2.,
+        &cRed, btn->string);
+}
+
 // Render the window.
 void toolkit_render(void) {
   int i;