[Change] What in the world was I thinking with the gui crap?? Large refactoring..
This commit is contained in:
parent
2a713437a2
commit
811fc0b92a
@ -11,8 +11,8 @@
|
|||||||
// bsx - Position of x of sprite b.
|
// bsx - Position of x of sprite b.
|
||||||
// bsy - Position of y of sprite b.
|
// bsy - Position of y of sprite b.
|
||||||
// bp - Position in space 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,
|
int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2* ap,
|
||||||
const gl_texture* bt, const int bsx, const int bsy, const Vec2* bp) {
|
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp) {
|
||||||
|
|
||||||
int x,y;
|
int x,y;
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
#include "physics.h"
|
#include "physics.h"
|
||||||
|
|
||||||
int CollideSprite(const gl_texture* at, const int asx, const int asy, const Vec2* ap,
|
int CollideSprite(const glTexture* at, const int asx, const int asy, const Vec2* ap,
|
||||||
const gl_texture* bt, const int bsx, const int bsy, const Vec2* bp);
|
const glTexture* bt, const int bsx, const int bsy, const Vec2* bp);
|
||||||
|
|
||||||
|
10
src/main.c
10
src/main.c
@ -122,7 +122,7 @@ int main(int argc, char** argv) {
|
|||||||
WARN("Error initializing AI");
|
WARN("Error initializing AI");
|
||||||
|
|
||||||
// Misc openGL init stuff.
|
// 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.
|
gui_init(); // Init the GUI crap.
|
||||||
toolkit_init(); // Init the toolkit.
|
toolkit_init(); // Init the toolkit.
|
||||||
|
|
||||||
@ -240,6 +240,7 @@ static void render_space(void) {
|
|||||||
static double fps = 0.;
|
static double fps = 0.;
|
||||||
static double fps_cur = 0.;
|
static double fps_cur = 0.;
|
||||||
static void display_fps(const double dt) {
|
static void display_fps(const double dt) {
|
||||||
|
double x, y;
|
||||||
fps_dt += dt;
|
fps_dt += dt;
|
||||||
fps_cur += 1.;
|
fps_cur += 1.;
|
||||||
if(fps_dt > 1.) {
|
if(fps_dt > 1.) {
|
||||||
@ -247,10 +248,11 @@ static void display_fps(const double dt) {
|
|||||||
fps = fps_cur / fps_dt;
|
fps = fps_cur / fps_dt;
|
||||||
fps_dt = fps_cur = 0.;
|
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)
|
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) {
|
static void data_name(void) {
|
||||||
|
57
src/opengl.c
57
src/opengl.c
@ -19,34 +19,34 @@
|
|||||||
#define FONT_DEF "../gfx/fonts/font.ttf"
|
#define FONT_DEF "../gfx/fonts/font.ttf"
|
||||||
|
|
||||||
// Default colors.
|
// Default colors.
|
||||||
gl_colour cLightGrey = { .r = 0.80, .g = 0.80, .b = 0.80, .a = 1 };
|
glColour 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 };
|
glColour 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 };
|
glColour 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 };
|
glColour 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 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.
|
// offsets to Adjust the pilot's place onscreen to be in the middle, even with the GUI.
|
||||||
extern double gui_xoff;
|
extern double gui_xoff;
|
||||||
extern double gui_yoff;
|
extern double gui_yoff;
|
||||||
|
|
||||||
// The screen info, gives data of current opengl settings.
|
// The screen info, gives data of current opengl settings.
|
||||||
gl_info gl_screen;
|
glInfo gl_screen;
|
||||||
|
|
||||||
// Our precious camera.
|
// Our precious camera.
|
||||||
Vec2* gl_camera;
|
Vec2* gl_camera;
|
||||||
|
|
||||||
// Default font.
|
// Default font.
|
||||||
gl_font gl_defFont;
|
glFont gl_defFont;
|
||||||
|
|
||||||
// Misc.
|
// Misc.
|
||||||
static int SDL_VFlipSurface(SDL_Surface* surface);
|
static int SDL_VFlipSurface(SDL_Surface* surface);
|
||||||
static int SDL_IsTrans(SDL_Surface* s, int x, int y);
|
static int SDL_IsTrans(SDL_Surface* s, int x, int y);
|
||||||
static uint8_t* SDL_MapTrans(SDL_Surface* s);
|
static uint8_t* SDL_MapTrans(SDL_Surface* s);
|
||||||
static int pot(int n);
|
static int pot(int n);
|
||||||
// gl_texture.
|
// glTexture.
|
||||||
static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh);
|
static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh);
|
||||||
// Gl font.
|
// 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.
|
// PNG.
|
||||||
int write_png(const char* file_name, png_bytep* rows, int w, int h, int colourtype, int bitdepth);
|
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.
|
// Load the SDL_Surface to an openGL texture.
|
||||||
gl_texture* gl_loadImage(SDL_Surface* surface) {
|
glTexture* gl_loadImage(SDL_Surface* surface) {
|
||||||
int rw, rh;
|
int rw, rh;
|
||||||
|
|
||||||
// Set up the texture defaults.
|
// Set up the texture defaults.
|
||||||
gl_texture* texture = MALLOC_L(gl_texture);
|
glTexture* texture = MALLOC_L(glTexture);
|
||||||
texture->w = (double)surface->w;
|
texture->w = (double)surface->w;
|
||||||
texture->h = (double)surface->h;
|
texture->h = (double)surface->h;
|
||||||
texture->sx = 1.;
|
texture->sx = 1.;
|
||||||
@ -269,9 +269,9 @@ gl_texture* gl_loadImage(SDL_Surface* surface) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the image directly as an opengl texture.
|
// 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;
|
SDL_Surface* tmp, *surface;
|
||||||
gl_texture* t;
|
glTexture* t;
|
||||||
uint8_t* trans = NULL;
|
uint8_t* trans = NULL;
|
||||||
uint32_t filesize;
|
uint32_t filesize;
|
||||||
char* buf = pack_readfile(DATA, (char*)path, &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.
|
// Load the texture immediately, but also set is as a sprite.
|
||||||
gl_texture* gl_newSprite(const char* path, const int sx, const int sy) {
|
glTexture* gl_newSprite(const char* path, const int sx, const int sy) {
|
||||||
gl_texture* texture;
|
glTexture* texture;
|
||||||
if((texture = gl_newImage(path)) == NULL)
|
if((texture = gl_newImage(path)) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
texture->sx = (double)sx;
|
texture->sx = (double)sx;
|
||||||
@ -325,19 +325,19 @@ gl_texture* gl_newSprite(const char* path, const int sx, const int sy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Free the texture.
|
// Free the texture.
|
||||||
void gl_freeTexture(gl_texture* texture) {
|
void gl_freeTexture(glTexture* texture) {
|
||||||
glDeleteTextures(1, &texture->texture);
|
glDeleteTextures(1, &texture->texture);
|
||||||
if(texture->trans) free(texture->trans);
|
if(texture->trans) free(texture->trans);
|
||||||
free(texture);
|
free(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return true if pixel at pos (x,y) is transparent.
|
// 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)));
|
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.
|
// Set x and y to be the appropriate sprite for glTexture using dir.
|
||||||
void gl_getSpriteFromDir(int* x, int* y, const gl_texture* t, const double 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)));
|
int s = (int)(dir / (2.0*M_PI / (t->sy*t->sx)));
|
||||||
|
|
||||||
// Make sure the sprite is "in range".
|
// 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.
|
// 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.
|
// 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 ||
|
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)
|
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.
|
// 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);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix(); // Set up translation matrix.
|
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!
|
// Print text on screen! YES!!!! Just like printf! But different!
|
||||||
// Defaults ft_font to gl_defFont if NULL.
|
// 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.
|
//float h = ft_font->h / .63; // Slightly increases font size.
|
||||||
char text[256];
|
char text[256];
|
||||||
va_list ap;
|
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);
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
|
||||||
glPushMatrix(); // Translation matrix.
|
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.);
|
if(c == NULL) glColor4d(1., 1., 1., 1.);
|
||||||
else COLOUR(*c);
|
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.
|
// 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;
|
int i, n;
|
||||||
char txt[256]; // Holds the string.
|
char txt[256]; // Holds the string.
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -485,7 +486,7 @@ int gl_printWidth(const gl_font* ft_font, const char* fmt, ...) {
|
|||||||
// ================
|
// ================
|
||||||
// FONT!
|
// 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_Glyph glyph;
|
||||||
FT_Bitmap bitmap;
|
FT_Bitmap bitmap;
|
||||||
GLubyte* expanded_data;
|
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);
|
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;
|
if(font == NULL) font = &gl_defFont;
|
||||||
|
|
||||||
uint32_t bufsize;
|
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.
|
// Create each of the font display lists.
|
||||||
unsigned char i;
|
unsigned char i;
|
||||||
for(i = 0; i < 128; 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.
|
// We can now free the face and library.
|
||||||
FT_Done_Face(face);
|
FT_Done_Face(face);
|
||||||
@ -606,7 +607,7 @@ void gl_fontInit(gl_font* font, const char* fname, const unsigned int h) {
|
|||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gl_freeFont(gl_font* font) {
|
void gl_freeFont(glFont* font) {
|
||||||
if(font == NULL) font = &gl_defFont;
|
if(font == NULL) font = &gl_defFont;
|
||||||
glDeleteLists(font->list_base, 128);
|
glDeleteLists(font->list_base, 128);
|
||||||
glDeleteTextures(128, font->textures);
|
glDeleteTextures(128, font->textures);
|
||||||
|
51
src/opengl.h
51
src/opengl.h
@ -24,21 +24,21 @@ typedef struct {
|
|||||||
int fullscreen; // 1 = fullscreen, 0 = windowed.
|
int fullscreen; // 1 = fullscreen, 0 = windowed.
|
||||||
int r, g, b, a; // Framebuffer values in bits.
|
int r, g, b, a; // Framebuffer values in bits.
|
||||||
int doublebuf; // Double buffer.
|
int doublebuf; // Double buffer.
|
||||||
} gl_info;
|
} glInfo;
|
||||||
extern gl_info gl_screen; // Local structure set with gl_init etc.
|
extern glInfo gl_screen; // Local structure set with gl_init etc.
|
||||||
|
|
||||||
// Colours.
|
// Colours.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
double r, g, b, a;
|
double r, g, b, a;
|
||||||
} gl_colour;
|
} glColour;
|
||||||
#define COLOUR(x) glColor4d((x).r, (x).g, (x).b, (x).a)
|
#define COLOUR(x) glColor4d((x).r, (x).g, (x).b, (x).a)
|
||||||
|
|
||||||
// Default colors.
|
// Default colors.
|
||||||
extern gl_colour cLightGrey;
|
extern glColour cLightGrey;
|
||||||
extern gl_colour cGrey;
|
extern glColour cGrey;
|
||||||
extern gl_colour cDarkGrey;
|
extern glColour cDarkGrey;
|
||||||
extern gl_colour cGreen;
|
extern glColour cGreen;
|
||||||
extern gl_colour cRed;
|
extern glColour cRed;
|
||||||
|
|
||||||
// Spritesheet info.
|
// Spritesheet info.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -48,7 +48,7 @@ typedef struct {
|
|||||||
double sw, sh; // Size of each sprite.
|
double sw, sh; // Size of each sprite.
|
||||||
GLuint texture; // The opengl texture itself.
|
GLuint texture; // The opengl texture itself.
|
||||||
uint8_t* trans; // Maps the transparency.
|
uint8_t* trans; // Maps the transparency.
|
||||||
} gl_texture;
|
} glTexture;
|
||||||
|
|
||||||
// Font info.
|
// Font info.
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -56,35 +56,36 @@ typedef struct {
|
|||||||
int* w;
|
int* w;
|
||||||
GLuint* textures;
|
GLuint* textures;
|
||||||
GLuint list_base;
|
GLuint list_base;
|
||||||
} gl_font;
|
} glFont;
|
||||||
extern gl_font gl_defFont; // Default font.
|
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
|
// 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 glFontInit(glFont* font, const char* fname, const unsigned int h);
|
||||||
void gl_freeFont(gl_font* font);
|
void gl_freeFont(glFont* font);
|
||||||
|
|
||||||
// gl_texute loading/freeing.
|
// gl_texute loading/freeing.
|
||||||
gl_texture* gl_loadImage(SDL_Surface* surface); // Frees the surface.
|
glTexture* gl_loadImage(SDL_Surface* surface); // Frees the surface.
|
||||||
gl_texture* gl_newImage(const char* path);
|
glTexture* gl_newImage(const char* path);
|
||||||
gl_texture* gl_newSprite(const char* path, const int sx, const int sy);
|
glTexture* gl_newSprite(const char* path, const int sx, const int sy);
|
||||||
void gl_freeTexture(gl_texture* texture);
|
void gl_freeTexture(glTexture* texture);
|
||||||
|
|
||||||
// Rendering.
|
// Rendering.
|
||||||
void gl_blitSprite(const gl_texture* sprite, const Vec2* pos,
|
void gl_blitSprite(const glTexture* sprite, const Vec2* pos,
|
||||||
const int sx, const int sy, const gl_colour* c);
|
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_bindCamera(const Vec2* pos);
|
||||||
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,
|
||||||
int gl_printWidth(const gl_font* ft_font, const char* fmt, ...);
|
const glColour* c, const char* fmt, ...);
|
||||||
|
int gl_printWidth(const glFont* ft_font, const char* fmt, ...);
|
||||||
|
|
||||||
// Initialize/cleanup.
|
// Initialize/cleanup.
|
||||||
int gl_init(void);
|
int gl_init(void);
|
||||||
void gl_exit(void);
|
void gl_exit(void);
|
||||||
|
|
||||||
// Misc.
|
// Misc.
|
||||||
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);
|
||||||
void gl_getSpriteFromDir(int* x, int* y, const gl_texture* t, const double dir);
|
void gl_getSpriteFromDir(int* x, int* y, const glTexture* t, const double dir);
|
||||||
void gl_screenshot(const char* filename);
|
void gl_screenshot(const char* filename);
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ typedef struct {
|
|||||||
int tech;
|
int tech;
|
||||||
int mass;
|
int mass;
|
||||||
|
|
||||||
gl_texture gfx_store; // Store graphic.
|
glTexture gfx_store; // Store graphic.
|
||||||
|
|
||||||
int properties; // Properties stored bitwise.
|
int properties; // Properties stored bitwise.
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ typedef struct {
|
|||||||
double accuracy; // Desviation accuracy.
|
double accuracy; // Desviation accuracy.
|
||||||
double damage_armour, damage_shield; // Damage.
|
double damage_armour, damage_shield; // Damage.
|
||||||
|
|
||||||
gl_texture* gfx_space;
|
glTexture* gfx_space;
|
||||||
};
|
};
|
||||||
struct { // Launcher.
|
struct { // Launcher.
|
||||||
//unsigned int delay; // Delay between shots.
|
//unsigned int delay; // Delay between shots.
|
||||||
@ -58,7 +58,7 @@ typedef struct {
|
|||||||
unsigned int duration; // Duration.
|
unsigned int duration; // Duration.
|
||||||
//double damage_armour, damage_shield; // Damage.
|
//double damage_armour, damage_shield; // Damage.
|
||||||
|
|
||||||
//gl_texture* gfx_space;
|
//glTexture* gfx_space;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} Outfit;
|
} Outfit;
|
||||||
|
244
src/player.c
244
src/player.c
@ -40,22 +40,23 @@ extern int pilots;
|
|||||||
|
|
||||||
// -- Colours.
|
// -- Colours.
|
||||||
// Standard colors.
|
// 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. };
|
glColour 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. };
|
glColour 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. };
|
glColour 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 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. };
|
glColour 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. };
|
glColour 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_weap = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. };
|
||||||
// Bars.
|
// Bars.
|
||||||
gl_colour cShield = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. };
|
glColour 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. };
|
glColour 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 cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. };
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
double x,y; // Position.
|
||||||
double w,h; // Dimensions.
|
double w,h; // Dimensions.
|
||||||
RadarShape shape;
|
RadarShape shape;
|
||||||
double res; // Resolution.
|
double res; // Resolution.
|
||||||
@ -68,29 +69,27 @@ typedef struct {
|
|||||||
#define RADAR_RES_DEFAULT 40.
|
#define RADAR_RES_DEFAULT 40.
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
double x,y;
|
||||||
double w,h;
|
double w,h;
|
||||||
} Rect;
|
} Rect;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// Graphics.
|
// Graphics.
|
||||||
gl_font smallFont;
|
glFont smallFont;
|
||||||
gl_texture* gfx_frame;
|
glTexture* gfx_frame;
|
||||||
gl_texture* gfx_targetPilot, *gfx_targetPlanet;
|
glTexture* gfx_targetPilot, *gfx_targetPlanet;
|
||||||
|
|
||||||
Radar radar;
|
Radar radar;
|
||||||
Rect nav;
|
Rect nav;
|
||||||
Rect shield, armour, energy;
|
Rect shield, armour, energy;
|
||||||
Rect weapon;
|
Rect weapon;
|
||||||
|
Rect target_health, target_name, target_faction;
|
||||||
Rect misc;
|
Rect misc;
|
||||||
|
Rect msg;
|
||||||
|
|
||||||
// Positions.
|
// Positions.
|
||||||
Vec2 pos_frame;
|
Vec2 frame;
|
||||||
Vec2 pos_radar;
|
Vec2 target;
|
||||||
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;
|
|
||||||
} GUI;
|
} GUI;
|
||||||
|
|
||||||
GUI gui; // Le 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 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 int gui_parse(const xmlNodePtr parent, const char* name);
|
||||||
static void gui_renderPilot(const Pilot* p);
|
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.
|
// Create a new player.
|
||||||
void player_new(void) {
|
void player_new(void) {
|
||||||
@ -213,12 +212,13 @@ void player_message(const char* fmt, ...) {
|
|||||||
// Render the player.
|
// Render the player.
|
||||||
void player_render(void) {
|
void player_render(void) {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
double x, y;
|
||||||
char str[10];
|
char str[10];
|
||||||
Pilot* p;
|
Pilot* p;
|
||||||
Planet* planet;
|
Planet* planet;
|
||||||
|
glColour* c;
|
||||||
|
glFont* f;
|
||||||
Vec2 v;
|
Vec2 v;
|
||||||
gl_colour* c;
|
|
||||||
gl_font* f;
|
|
||||||
|
|
||||||
// Render the player target graphics.
|
// Render the player target graphics.
|
||||||
if(player_target != PLAYER_ID) {
|
if(player_target != PLAYER_ID) {
|
||||||
@ -260,16 +260,16 @@ void player_render(void) {
|
|||||||
|
|
||||||
// GUI!
|
// GUI!
|
||||||
// -- Frame.
|
// -- Frame.
|
||||||
gl_blitStatic(gui.gfx_frame, &gui.pos_frame, NULL);
|
gl_blitStatic(gui.gfx_frame, &gui.frame, NULL);
|
||||||
// -- Radar.
|
// -- Radar.
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
if(gui.radar.shape == RADAR_RECT)
|
if(gui.radar.shape == RADAR_RECT)
|
||||||
glTranslated(VX(gui.pos_radar) - gl_screen.w/2. + gui.radar.w/2.,
|
glTranslated(gui.radar.x - gl_screen.w/2. + gui.radar.w/2.,
|
||||||
VY(gui.pos_radar) - gl_screen.h/2. - gui.radar.h/2., 0.);
|
gui.radar.y - gl_screen.h/2. - gui.radar.h/2., 0.);
|
||||||
else if(gui.radar.shape == RADAR_CIRCLE)
|
else if(gui.radar.shape == RADAR_CIRCLE)
|
||||||
glTranslated(VX(gui.pos_radar) - gl_screen.w/2.,
|
glTranslated(gui.radar.x - gl_screen.w/2.,
|
||||||
VY(gui.pos_radar) - gl_screen.h/2., 0.);
|
gui.radar.y - gl_screen.h/2., 0.);
|
||||||
|
|
||||||
// Planets.
|
// Planets.
|
||||||
COLOUR(cFriend);
|
COLOUR(cFriend);
|
||||||
@ -312,35 +312,36 @@ void player_render(void) {
|
|||||||
if(planet_target >= 0) {
|
if(planet_target >= 0) {
|
||||||
// Planet landing target.
|
// Planet landing target.
|
||||||
i = gl_printWidth(NULL, "Land");
|
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, gui.nav.x + (gui.nav.w - i)/2.,
|
||||||
gl_print(NULL, &v, &cConsole, "Land");
|
gui.nav.y - 5, &cConsole, "Land");
|
||||||
i = gl_printWidth(&gui.smallFont, "%s", cur_system->planets[planet_target].name);
|
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, gui.nav.x + (gui.nav.w - i)/2.,
|
||||||
gl_print(&gui.smallFont, &v, NULL, "%s", cur_system->planets[planet_target].name);
|
gui.nav.y - 10 - gui.smallFont.h, NULL,
|
||||||
|
"%s", cur_system->planets[planet_target].name);
|
||||||
}
|
}
|
||||||
else if(planet_target == -1) {
|
else if(planet_target == -1) {
|
||||||
// No planet target.
|
// No planet target.
|
||||||
i = gl_printWidth(NULL, "Navigation");
|
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, gui.nav.x + (gui.nav.w - i)/2.,
|
||||||
gl_print(NULL, &v, &cConsole, "Navigation");
|
gui.nav.y - 5, &cConsole, "Navigation");
|
||||||
i = gl_printWidth(&gui.smallFont, "Off");
|
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, gui.nav.x + (gui.nav.w - i)/2.,
|
||||||
gl_print(&gui.smallFont, &v, &cGrey, "Off");
|
gui.nav.y - 10 - gui.smallFont.h, &cGrey, "Off");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Health
|
// Health
|
||||||
gui_renderBar(&cShield, &gui.pos_shield, &gui.shield, player->shield / player->shield_max);
|
gui_renderBar(&cShield, &gui.shield, player->shield / player->shield_max);
|
||||||
gui_renderBar(&cArmor, &gui.pos_armour, &gui.armour, player->armour / player->armour_max);
|
gui_renderBar(&cArmor, &gui.armour, player->armour / player->armour_max);
|
||||||
gui_renderBar(&cEnergy, &gui.pos_energy, &gui.energy, player->energy / player->energy_max);
|
gui_renderBar(&cEnergy, &gui.energy, player->energy / player->energy_max);
|
||||||
|
|
||||||
// Weapon.
|
// Weapon.
|
||||||
if(player->secondary == NULL) {
|
if(player->secondary == NULL) {
|
||||||
i = gl_printWidth(NULL, "Secondary");
|
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, gui.weapon.x + (gui.weapon.w - i)/2.,
|
||||||
gl_print(NULL, &v, &cConsole, "Secondary");
|
gui.weapon.y - 5, &cConsole, "Secondary");
|
||||||
i = gl_printWidth(&gui.smallFont, "None");
|
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, gui.weapon.x + (gui.weapon.w - i)/2.,
|
||||||
gl_print(&gui.smallFont, &v, &cGrey, "None");
|
gui.weapon.y - 10 - gl_defFont.h, &cGrey, "None");
|
||||||
} else {
|
} else {
|
||||||
f = &gl_defFont;
|
f = &gl_defFont;
|
||||||
if(player->ammo == NULL) {
|
if(player->ammo == NULL) {
|
||||||
@ -350,9 +351,9 @@ void player_render(void) {
|
|||||||
f = &gui.smallFont;
|
f = &gui.smallFont;
|
||||||
i = gl_printWidth(f, "%s", player->secondary->outfit->name);
|
i = gl_printWidth(f, "%s", player->secondary->outfit->name);
|
||||||
}
|
}
|
||||||
vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2.,
|
gl_print(f, gui.weapon.x + (gui.weapon.w - i)/2.,
|
||||||
VY(gui.pos_weapon) - (gui.weapon.h - f->h)/2.);
|
gui.weapon.y - (gui.weapon.h - f->h)/2.,
|
||||||
gl_print(f, &v, &cConsole, "%s", player->secondary->outfit->name);
|
&cConsole, "%s", player->secondary->outfit->name);
|
||||||
} else {
|
} else {
|
||||||
// Use the ammunitions name.
|
// Use the ammunitions name.
|
||||||
i = gl_printWidth(f, "%s", player->secondary->outfit->name);
|
i = gl_printWidth(f, "%s", player->secondary->outfit->name);
|
||||||
@ -361,15 +362,15 @@ void player_render(void) {
|
|||||||
f = &gui.smallFont;
|
f = &gui.smallFont;
|
||||||
i = gl_printWidth(f, "%s", player->ammo->outfit->name);
|
i = gl_printWidth(f, "%s", player->ammo->outfit->name);
|
||||||
}
|
}
|
||||||
vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2.,
|
gl_print(f, gui.weapon.x + (gui.weapon.w - i)/2.,
|
||||||
VY(gui.pos_weapon) - 5);
|
gui.weapon.y - 5,
|
||||||
gl_print(f, &v, NULL, "%s", player->ammo->outfit->name);
|
&cConsole, "%s", player->ammo->outfit->name);
|
||||||
|
|
||||||
// Print ammo underneath to the left.
|
// Print ammo underneath to the left.
|
||||||
i = gl_printWidth(&gui.smallFont, "%d", player->ammo->quantity);
|
i = gl_printWidth(&gui.smallFont, "%d", player->ammo->quantity);
|
||||||
vect_csetmin(&v, VX(gui.pos_weapon) + (gui.weapon.w - i)/2.,
|
gl_print(&gui.smallFont, gui.weapon.x + (gui.weapon.w - i)/2.,
|
||||||
VY(gui.pos_weapon) - 10 - gl_defFont.h);
|
gui.weapon.y - 10 - gl_defFont.h,
|
||||||
gl_print(&gui.smallFont, &v, &cConsole, "%d", player->ammo->quantity);
|
NULL, "%d", player->ammo->quantity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,33 +378,38 @@ void player_render(void) {
|
|||||||
if(player_target != PLAYER_ID) {
|
if(player_target != PLAYER_ID) {
|
||||||
p = pilot_get(player_target);
|
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.
|
// Target name.
|
||||||
gl_print(NULL, &gui.pos_target_name, NULL, "%s", p->name);
|
gl_print(NULL, gui.target_name.x, gui.target_name.y,
|
||||||
gl_print(&gui.smallFont, &gui.pos_target_faction, NULL, "%s", p->faction->name);
|
NULL, "%s", p->name);
|
||||||
|
gl_print(&gui.smallFont, gui.target_faction.x, gui.target_faction.y,
|
||||||
|
NULL, "%s", p->faction->name);
|
||||||
|
|
||||||
// Target status.
|
// Target status.
|
||||||
if(pilot_isDisabled(p))
|
if(pilot_isDisabled(p))
|
||||||
// Disable the pilot.
|
// 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.)
|
else if(p->shield > p->shield_max / 100.)
|
||||||
// On shields.
|
// 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
|
else
|
||||||
// On armour.
|
// 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 {
|
} else {
|
||||||
// No target.
|
// No target.
|
||||||
i = gl_printWidth(NULL, "No Target");
|
i = gl_printWidth(NULL, "No Target");
|
||||||
vect_csetmin(&v, VX(gui.pos_target) + (SHIP_TARGET_W - i)/2., VY(gui.pos_target) +
|
gl_print(NULL, gui.target.x + (SHIP_TARGET_W - i)/2.,
|
||||||
(SHIP_TARGET_H - gl_defFont.h)/2.);
|
gui.target.y + (SHIP_TARGET_H - gl_defFont.h)/2.,
|
||||||
gl_print(NULL, &v, &cGrey, "No Target");
|
&cGrey, "No Target");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Misc.
|
// Misc.
|
||||||
vect_csetmin(&v, VX(gui.pos_misc) + 10, VY(gui.pos_misc) - 10 - gl_defFont.h);
|
gl_print(NULL, gui.misc.x + 10, gui.misc.y - 10 - gl_defFont.h,
|
||||||
gl_print(NULL, &v, &cConsole, "SCred:");
|
&cConsole, "SCred:");
|
||||||
if(credits >= 1000000)
|
if(credits >= 1000000)
|
||||||
snprintf(str, 10, "%.2fM", (double)credits / 1000000.);
|
snprintf(str, 10, "%.2fM", (double)credits / 1000000.);
|
||||||
else if(credits >= 1000)
|
else if(credits >= 1000)
|
||||||
@ -411,17 +417,18 @@ void player_render(void) {
|
|||||||
else
|
else
|
||||||
snprintf(str, 10, "%d", credits);
|
snprintf(str, 10, "%d", credits);
|
||||||
i = gl_printWidth(&gui.smallFont, "%s", str);
|
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, gui.misc.x + gui.misc.w - 10 - i,
|
||||||
gl_print(&gui.smallFont, &v, NULL, "%s", str);
|
gui.misc.y - 10 - gl_defFont.h, NULL, "%s", str);
|
||||||
|
|
||||||
// Messages.
|
// 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++) {
|
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].str[0] != '\0') {
|
||||||
if(msg_stack[msg_max-i-1].t < SDL_GetTicks())
|
if(msg_stack[msg_max-i-1].t < SDL_GetTicks())
|
||||||
msg_stack[msg_max-i-1].str[0] = '\0';
|
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.
|
// 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;
|
int x, y, sx, sy;
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
COLOUR(*c);
|
COLOUR(*c);
|
||||||
x = VX(*p) - gl_screen.w/2.;
|
x = r->x - gl_screen.w/2.;
|
||||||
y = VY(*p) - gl_screen.h/2.;
|
y = r->y - gl_screen.h/2.;
|
||||||
sx = w * r->w;
|
sx = w * r->w;
|
||||||
sy = r->h;
|
sy = r->h;
|
||||||
glVertex2d(x, y);
|
glVertex2d(x, y);
|
||||||
@ -492,11 +499,12 @@ int gui_init(void) {
|
|||||||
gui.gfx_targetPlanet = NULL;
|
gui.gfx_targetPlanet = NULL;
|
||||||
|
|
||||||
// Font.
|
// Font.
|
||||||
gl_fontInit(&gui.smallFont, NULL, 10);
|
glFontInit(&gui.smallFont, NULL, 10);
|
||||||
// -- Radar.
|
// -- Radar.
|
||||||
gui.radar.res = RADAR_RES_DEFAULT;
|
gui.radar.res = RADAR_RES_DEFAULT;
|
||||||
// -- messages.
|
// -- messages.
|
||||||
vect_csetmin(&gui.pos_msg, 20,30);
|
gui.msg.x = 20;
|
||||||
|
gui.msg.y = 30;
|
||||||
msg_stack = calloc(msg_max, sizeof(Msg));
|
msg_stack = calloc(msg_max, sizeof(Msg));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -603,9 +611,10 @@ static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse a gui node.
|
// 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) {
|
static int gui_parse(const xmlNodePtr parent, const char* name) {
|
||||||
xmlNodePtr cur, node;
|
xmlNodePtr cur, node;
|
||||||
double x, y;
|
|
||||||
char* tmp, *tmp2;
|
char* tmp, *tmp2;
|
||||||
|
|
||||||
// Gfx.
|
// Gfx.
|
||||||
@ -633,7 +642,7 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
|
|||||||
free(tmp2);
|
free(tmp2);
|
||||||
|
|
||||||
// Frame (based on gfx).
|
// Frame (based on gfx).
|
||||||
vect_csetmin(&gui.pos_frame,
|
vect_csetmin(&gui.frame,
|
||||||
gl_screen.w - gui.gfx_frame->w, // x.
|
gl_screen.w - gui.gfx_frame->w, // x.
|
||||||
gl_screen.h - gui.gfx_frame->h); // h.
|
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;
|
node = parent->children;
|
||||||
do {
|
do {
|
||||||
// Offset.
|
// Offset.
|
||||||
if(xml_isNode(node, "offset")) {
|
if(xml_isNode(node, "offset"))
|
||||||
rect_parse(node, &x, &y, NULL, NULL);
|
rect_parse(node, &gui_xoff, &gui_yoff, NULL, NULL);
|
||||||
gui_xoff = x;
|
// Radar.
|
||||||
gui_yoff = y;
|
|
||||||
}
|
|
||||||
else if(xml_isNode(node, "radar")) {
|
else if(xml_isNode(node, "radar")) {
|
||||||
tmp = xml_nodeProp(node,"type");
|
tmp = xml_nodeProp(node,"type");
|
||||||
// Make sure type is valid.
|
// Make sure type is valid.
|
||||||
@ -659,93 +666,80 @@ static int gui_parse(const xmlNodePtr parent, const char* name) {
|
|||||||
|
|
||||||
// Load the appropriate measurements.
|
// Load the appropriate measurements.
|
||||||
if(gui.radar.shape == RADAR_RECT)
|
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)
|
else if(gui.radar.shape == RADAR_CIRCLE)
|
||||||
rect_parse(node, &x, &y, &gui.radar.w, NULL);
|
rect_parse(node, &gui.radar.x, &gui.radar.y, &gui.radar.w, NULL);
|
||||||
vect_csetmin(&gui.pos_radar,
|
RELATIVIZE(gui.radar);
|
||||||
VX(gui.pos_frame) + x,
|
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y);
|
|
||||||
}
|
}
|
||||||
// Nav computer.
|
// Nav computer.
|
||||||
else if(xml_isNode(node, "nav")) {
|
else if(xml_isNode(node, "nav")) {
|
||||||
rect_parse(node, &x, &y, &gui.nav.w, &gui.nav.h);
|
rect_parse(node, &gui.nav.x, &gui.nav.y, &gui.nav.w, &gui.nav.h);
|
||||||
vect_csetmin(&gui.pos_nav,
|
RELATIVIZE(gui.nav);
|
||||||
VX(gui.pos_frame) + x,
|
gui.nav.y -= gl_defFont.h;
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y - gl_defFont.h);
|
|
||||||
}
|
}
|
||||||
// Health bars.
|
// Health bars.
|
||||||
else if(xml_isNode(node, "health")) {
|
else if(xml_isNode(node, "health")) {
|
||||||
cur = node->children;
|
cur = node->children;
|
||||||
do {
|
do {
|
||||||
if(xml_isNode(cur, "shield")) {
|
if(xml_isNode(cur, "shield")) {
|
||||||
rect_parse(cur, &x, &y, &gui.shield.w, &gui.shield.h);
|
rect_parse(cur, &gui.shield.x, &gui.shield.y, &gui.shield.w, &gui.shield.h);
|
||||||
vect_csetmin(&gui.pos_shield,
|
RELATIVIZE(gui.shield);
|
||||||
VX(gui.pos_frame) + x,
|
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xml_isNode(cur, "armour")) {
|
if(xml_isNode(cur, "armour")) {
|
||||||
rect_parse(cur, &x, &y, &gui.armour.w, &gui.armour.h);
|
rect_parse(cur, &gui.armour.x, &gui.armour.y, &gui.armour.w, &gui.armour.h);
|
||||||
vect_csetmin(&gui.pos_armour,
|
RELATIVIZE(gui.armour);
|
||||||
VX(gui.pos_frame) + x,
|
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xml_isNode(cur, "energy")) {
|
if(xml_isNode(cur, "energy")) {
|
||||||
rect_parse(cur, &x, &y, &gui.energy.w, &gui.energy.h);
|
rect_parse(cur, &gui.energy.x, &gui.energy.y, &gui.energy.w, &gui.energy.h);
|
||||||
vect_csetmin(&gui.pos_energy,
|
RELATIVIZE(gui.energy);
|
||||||
VX(gui.pos_frame) + x,
|
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y);
|
|
||||||
}
|
}
|
||||||
} while((cur = cur->next));
|
} while((cur = cur->next));
|
||||||
}
|
}
|
||||||
// Secondary weapon.
|
// Secondary weapon.
|
||||||
else if(xml_isNode(node, "weapon")) {
|
else if(xml_isNode(node, "weapon")) {
|
||||||
rect_parse(node, &x, &y, &gui.weapon.w, &gui.weapon.h);
|
rect_parse(node, &gui.weapon.x, &gui.weapon.y, &gui.weapon.w, &gui.weapon.h);
|
||||||
vect_csetmin(&gui.pos_weapon,
|
RELATIVIZE(gui.weapon);
|
||||||
VX(gui.pos_frame) + x,
|
gui.weapon.y -= gl_defFont.h;
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y - gl_defFont.h);
|
|
||||||
}
|
}
|
||||||
// Target.
|
// Target.
|
||||||
else if(xml_isNode(node, "target")) {
|
else if(xml_isNode(node, "target")) {
|
||||||
cur = node->children;
|
cur = node->children;
|
||||||
do {
|
do {
|
||||||
if(xml_isNode(cur, "gfx")) {
|
if(xml_isNode(cur, "gfx")) {
|
||||||
rect_parse(cur, &x, &y, NULL, NULL);
|
rect_parse(cur, &gui.target.x, &gui.target.y, NULL, NULL);
|
||||||
vect_csetmin(&gui.pos_target,
|
RELATIVIZE(gui.target);
|
||||||
VX(gui.pos_frame) + x,
|
gui.target.y -= SHIP_TARGET_H;
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y - SHIP_TARGET_H);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xml_isNode(cur, "name")) {
|
if(xml_isNode(cur, "name")) {
|
||||||
rect_parse(cur, &x, &y, NULL, NULL);
|
rect_parse(cur, &gui.target_name.x, &gui.target_name.y, NULL, NULL);
|
||||||
vect_csetmin(&gui.pos_target_name,
|
RELATIVIZE(gui.target_name);
|
||||||
VX(gui.pos_frame) + x,
|
gui.target_name.y -= gl_defFont.h;
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y - gl_defFont.h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xml_isNode(cur, "faction")) {
|
if(xml_isNode(cur, "faction")) {
|
||||||
rect_parse(cur, &x, &y, NULL, NULL);
|
rect_parse(cur, &gui.target_faction.x, &gui.target_faction.y, NULL, NULL);
|
||||||
vect_csetmin(&gui.pos_target_faction,
|
RELATIVIZE(gui.target_faction);
|
||||||
VX(gui.pos_frame) + x,
|
gui.target_faction.y -= gui.smallFont.h;
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y - gui.smallFont.h);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(xml_isNode(cur, "health")) {
|
if(xml_isNode(cur, "health")) {
|
||||||
rect_parse(cur, &x, &y, NULL, NULL);
|
rect_parse(cur, &gui.target_health.x, &gui.target_health.y, NULL, NULL);
|
||||||
vect_csetmin(&gui.pos_target_health,
|
RELATIVIZE(gui.target_health);
|
||||||
VX(gui.pos_frame) + x,
|
gui.target_health.y -= gui.smallFont.h;
|
||||||
VY(gui.pos_frame) + gui.gfx_frame->h - y - gui.smallFont.h);
|
|
||||||
}
|
}
|
||||||
} while((cur = cur->next));
|
} while((cur = cur->next));
|
||||||
} else if(xml_isNode(node, "misc")) {
|
} else if(xml_isNode(node, "misc")) {
|
||||||
rect_parse(node, &x, &y, &gui.misc.w, &gui.misc.h);
|
rect_parse(node, &gui.misc.x, &gui.misc.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);
|
RELATIVIZE(gui.misc);
|
||||||
}
|
}
|
||||||
} while((node = node->next));
|
} while((node = node->next));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#undef RELATIVIZE
|
||||||
|
|
||||||
// Free the GUI.
|
// Free the GUI.
|
||||||
void gui_free(void) {
|
void gui_free(void) {
|
||||||
|
@ -32,7 +32,7 @@ typedef struct {
|
|||||||
double thrust, turn, speed;
|
double thrust, turn, speed;
|
||||||
|
|
||||||
// Graphics.
|
// Graphics.
|
||||||
gl_texture* gfx_space, *gfx_target;
|
glTexture* gfx_space, *gfx_target;
|
||||||
|
|
||||||
// GUI interface.
|
// GUI interface.
|
||||||
char* gui;
|
char* gui;
|
||||||
|
@ -40,7 +40,7 @@ typedef struct {
|
|||||||
|
|
||||||
PlanetClass class; // Planet type.
|
PlanetClass class; // Planet type.
|
||||||
Faction* faction; // Planet faction.
|
Faction* faction; // Planet faction.
|
||||||
gl_texture* gfx_space; // Graphics in space.
|
glTexture* gfx_space; // Graphics in space.
|
||||||
} Planet;
|
} Planet;
|
||||||
|
|
||||||
// Star systems.
|
// Star systems.
|
||||||
|
@ -49,7 +49,9 @@ static int mwindows = 0;
|
|||||||
|
|
||||||
static Widget* window_newWidget(const unsigned int wid);
|
static Widget* window_newWidget(const unsigned int wid);
|
||||||
static void widget_cleanup(Widget* widget);
|
static void widget_cleanup(Widget* widget);
|
||||||
|
// Render.
|
||||||
static void window_render(Window* w);
|
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
|
// Add a button that when pressed will trigger call, passing it's name as the
|
||||||
// only parameter.
|
// only parameter.
|
||||||
@ -162,62 +164,29 @@ void window_destroy(unsigned int wid) {
|
|||||||
|
|
||||||
// Render a window.
|
// Render a window.
|
||||||
static void window_render(Window* w) {
|
static void window_render(Window* w) {
|
||||||
int i, j;
|
int i;
|
||||||
double x, y;
|
double x, y;
|
||||||
Widget* wgt;
|
|
||||||
Vec2 v;
|
|
||||||
|
|
||||||
x = w->x - (double)gl_screen.w/2.;
|
x = w->x - (double)gl_screen.w/2.;
|
||||||
y = w->y - (double)gl_screen.h/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.
|
// Window background.
|
||||||
glBegin(GL_TRIANGLE_STRIP);
|
glBegin(GL_QUADS);
|
||||||
COLOUR(cLightGrey);
|
COLOUR(cLightGrey);
|
||||||
|
|
||||||
glVertex2d(0., 0.);
|
glVertex2d(x, y);
|
||||||
glVertex2d(w->w, 0.);
|
glVertex2d(x + w->w, y);
|
||||||
glVertex2d(0., w->h);
|
glVertex2d(x + w->w, y + w->h);
|
||||||
glVertex2d(w->w, w->h);
|
glVertex2d(x, y + w->h);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glPopMatrix(); // Gl Projection.
|
|
||||||
|
|
||||||
// Widgets.
|
// Widgets.
|
||||||
for(i = 0; i < w->nwidgets; i++) {
|
for(i = 0; i < w->nwidgets; i++) {
|
||||||
wgt = &w->widgets[i];
|
switch(w->widgets[i].type) {
|
||||||
|
|
||||||
switch(wgt->type) {
|
|
||||||
case WIDGET_NULL:
|
case WIDGET_NULL:
|
||||||
break;
|
break;
|
||||||
case WIDGET_BUTTON:
|
case WIDGET_BUTTON:
|
||||||
glMatrixMode(GL_PROJECTION);
|
toolkit_renderButton(&w->widgets[i], x, y);
|
||||||
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);
|
|
||||||
break;
|
break;
|
||||||
case WIDGET_TEXT:
|
case WIDGET_TEXT:
|
||||||
break;
|
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.
|
// Render the window.
|
||||||
void toolkit_render(void) {
|
void toolkit_render(void) {
|
||||||
int i;
|
int i;
|
||||||
|
Loading…
Reference in New Issue
Block a user