92 lines
1.7 KiB
C
92 lines
1.7 KiB
C
#include "log.h"
|
|
#include "pause.h"
|
|
#include "toolkit.h"
|
|
|
|
typedef struct {
|
|
unsigned int id; // Unique identifier.
|
|
|
|
double x,y; // Position.
|
|
double w,h; // Dimensions.
|
|
|
|
gl_texture* t; // Possible texture.
|
|
} Window;
|
|
|
|
static unsigned int genwid = 0; // Generate unique id.
|
|
|
|
int toolkit = 0;
|
|
|
|
#define MIN_WINDOWS 3
|
|
static Window** windows = NULL;
|
|
static int nwindows = 0;
|
|
static int mwindows = 0;
|
|
|
|
// Create a window.
|
|
unsigned int window_create(int x, int y, int w, int h, gl_texture* t) {
|
|
Window* wtmp = NULL;
|
|
if(nwindows == mwindows) {
|
|
// We have reached the memory limit.
|
|
windows = realloc(windows, sizeof(Window*)*(++mwindows));
|
|
if(windows == NULL) WARN("Out of memory");
|
|
}
|
|
wtmp = malloc(sizeof(Window));
|
|
if(wtmp == NULL) WARN("Out of memory");
|
|
|
|
int wid = (++genwid); // Unique id
|
|
|
|
wtmp->id = wid;
|
|
|
|
wtmp->x = x;
|
|
wtmp->y = y;
|
|
wtmp->h = h;
|
|
wtmp->w = w;
|
|
wtmp->t = t;
|
|
|
|
windows[nwindows++] = wtmp;
|
|
|
|
if(toolkit == 0) toolkit = 1; // Enable the toolkit.
|
|
|
|
return wid;
|
|
}
|
|
|
|
// Destroy a window.
|
|
void window_destroy(unsigned int wid) {
|
|
int i;
|
|
|
|
// Destroy the window.
|
|
for(i = 0; i < nwindows; i++)
|
|
if(windows[i]->id == wid) {
|
|
free(windows[i]);
|
|
break;
|
|
}
|
|
// Move the other windows down a layer.
|
|
for(; i<(nwindows-1); i++)
|
|
windows[i] = windows[i+1];
|
|
|
|
nwindows--;
|
|
if(nwindows == 0) toolkit = 0; // Disable the toolkit.
|
|
}
|
|
|
|
// Render the window.
|
|
void toolkit_render(void) {
|
|
|
|
}
|
|
|
|
// Init.
|
|
int toolkit_init(void) {
|
|
windows = malloc(sizeof(Window)*MIN_WINDOWS);
|
|
nwindows = 0;
|
|
mwindows = MIN_WINDOWS;
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Exit the toolkit.
|
|
void toolkit_exit(void) {
|
|
int i;
|
|
for(i = 0; i < nwindows; i++) {
|
|
window_destroy(windows[i]->id);
|
|
free(windows);
|
|
}
|
|
}
|
|
|