[Add] You can specify default fptr for windows now.
This commit is contained in:
parent
f45ab67dcc
commit
8da2cb1299
@ -158,6 +158,8 @@ void player_new(void) {
|
|||||||
&gl_smallFont, &cDConsole, "Please tell me your name:");
|
&gl_smallFont, &cDConsole, "Please tell me your name:");
|
||||||
window_addInput(wid, 20, -50, 200, 20, "inpName", 20, 1);
|
window_addInput(wid, 20, -50, 200, 20, "inpName", 20, 1);
|
||||||
window_addButton(wid, -20, 20, 80, 30, "btnClose", "Done", player_nameClose);
|
window_addButton(wid, -20, 20, 80, 30, "btnClose", "Done", player_nameClose);
|
||||||
|
|
||||||
|
window_setFptr(wid, player_nameClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void player_nameClose(char* str) {
|
static void player_nameClose(char* str) {
|
||||||
@ -269,6 +271,8 @@ void player_newShip(Ship* ship, double px, double py,
|
|||||||
window_addInput(wid, 20, -50, 200, 20, "inpName", 20, 1);
|
window_addInput(wid, 20, -50, 200, 20, "inpName", 20, 1);
|
||||||
window_addButton(wid, -20, 20, 80, 30, "btnClose", "Done",
|
window_addButton(wid, -20, 20, 80, 30, "btnClose", "Done",
|
||||||
player_nameShipClose);
|
player_nameShipClose);
|
||||||
|
|
||||||
|
window_setFptr(wid, player_nameShipClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void player_nameShipClose(char* str) {
|
static void player_nameShipClose(char* str) {
|
||||||
|
@ -87,6 +87,10 @@ typedef struct Window_ {
|
|||||||
int hidden; // Is it hidden?
|
int hidden; // Is it hidden?
|
||||||
int focus; // Which window is focused.
|
int focus; // Which window is focused.
|
||||||
|
|
||||||
|
// Pointer to a function to run if user hits 'enter' and no button is focused
|
||||||
|
// nor any other input thiny that catches 'enter'.
|
||||||
|
void(*def_fptr)(char*);
|
||||||
|
|
||||||
double x,y; // Position.
|
double x,y; // Position.
|
||||||
double w,h; // Dimensions.
|
double w,h; // Dimensions.
|
||||||
|
|
||||||
@ -396,6 +400,9 @@ unsigned int window_get(const char* wdwname) {
|
|||||||
// Create a window.
|
// Create a window.
|
||||||
unsigned int window_create(char* name, const int x, const int y,
|
unsigned int window_create(char* name, const int x, const int y,
|
||||||
const int w, const int h) {
|
const int w, const int h) {
|
||||||
|
|
||||||
|
Window* wdw;
|
||||||
|
|
||||||
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));
|
||||||
@ -404,31 +411,35 @@ unsigned int window_create(char* name, const int x, const int y,
|
|||||||
|
|
||||||
const int wid = (++genwid); // Unique id
|
const int wid = (++genwid); // Unique id
|
||||||
|
|
||||||
windows[nwindows].id = wid;
|
wdw = &windows[nwindows];
|
||||||
windows[nwindows].name = strdup(name);
|
|
||||||
|
|
||||||
windows[nwindows].hidden = 0;
|
wdw->id = wid;
|
||||||
windows[nwindows].focus = -1;
|
wdw->name = strdup(name);
|
||||||
|
|
||||||
|
wdw->hidden = 0;
|
||||||
|
wdw->focus = -1;
|
||||||
|
wdw->def_fptr = NULL;
|
||||||
|
|
||||||
|
wdw->w = (double)w;
|
||||||
|
wdw->h = (double)h;
|
||||||
|
|
||||||
windows[nwindows].w = (double) w;
|
|
||||||
windows[nwindows].h = (double) h;
|
|
||||||
// x pos.
|
// x pos.
|
||||||
if(x == -1)
|
if(x == -1)
|
||||||
// Center.
|
// Center.
|
||||||
windows[nwindows].x = gl_screen.w/2. - windows[nwindows].w/2.;
|
wdw->x = gl_screen.w/2. - windows[nwindows].w/2.;
|
||||||
else if(x < 0)
|
else if(x < 0)
|
||||||
windows[nwindows].x = gl_screen.w - windows[nwindows].w + (double)x;
|
wdw->x = gl_screen.w - windows[nwindows].w + (double)x;
|
||||||
else windows[nwindows].x = (double)x;
|
else windows[nwindows].x = (double)x;
|
||||||
// y pos.
|
// y pos.
|
||||||
if(y == -1)
|
if(y == -1)
|
||||||
// Center.
|
// Center.
|
||||||
windows[nwindows].y = gl_screen.h/2. - windows[nwindows].h/2.;
|
wdw->y = gl_screen.h/2. - windows[nwindows].h/2.;
|
||||||
else if(y < 0)
|
else if(y < 0)
|
||||||
windows[nwindows].x = gl_screen.h - windows[nwindows].h + (double)y;
|
wdw->x = gl_screen.h - windows[nwindows].h + (double)y;
|
||||||
else windows[nwindows].y = (double)y;
|
else wdw->y = (double)y;
|
||||||
|
|
||||||
windows[nwindows].widgets = NULL;
|
wdw->widgets = NULL;
|
||||||
windows[nwindows].nwidgets = 0;
|
wdw->nwidgets = 0;
|
||||||
|
|
||||||
nwindows++;
|
nwindows++;
|
||||||
|
|
||||||
@ -441,6 +452,14 @@ unsigned int window_create(char* name, const int x, const int y,
|
|||||||
return wid;
|
return wid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets the window's default function.
|
||||||
|
void window_setFptr(const unsigned int wid, void(*fptr)(char*)) {
|
||||||
|
Window* wdw;
|
||||||
|
|
||||||
|
wdw = window_wget(wid);
|
||||||
|
if(wdw != NULL) wdw->def_fptr = fptr;
|
||||||
|
}
|
||||||
|
|
||||||
// Destroy a widget.
|
// Destroy a widget.
|
||||||
static void widget_cleanup(Widget* widget) {
|
static void widget_cleanup(Widget* widget) {
|
||||||
int i;
|
int i;
|
||||||
@ -1208,6 +1227,7 @@ static void toolkit_nextFocus(void) {
|
|||||||
toolkit_nextFocus();
|
toolkit_nextFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return 1 if the window is focusable.
|
||||||
static int toolkit_isFocusable(Widget* wgt) {
|
static int toolkit_isFocusable(Widget* wgt) {
|
||||||
if(wgt == NULL) return 0;
|
if(wgt == NULL) return 0;
|
||||||
|
|
||||||
@ -1239,6 +1259,7 @@ static void toolkit_triggerFocus(void) {
|
|||||||
wgt->name, wdw->name);
|
wgt->name, wdw->name);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if(wdw->def_fptr)(*wdw->def_fptr)(wgt->name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1272,6 +1293,7 @@ static void toolkit_listFocus(Widget* lst, double bx, double by) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get what is selected currently in a list.
|
||||||
char* toolkit_getList(const unsigned int wid, char* name) {
|
char* toolkit_getList(const unsigned int wid, char* name) {
|
||||||
Widget* wgt = window_getwgt(wid, name);
|
Widget* wgt = window_getwgt(wid, name);
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ void window_addInput(const unsigned int wid,
|
|||||||
// Popups and alerts.
|
// Popups and alerts.
|
||||||
void toolkit_alert(const char* fmt, ...);
|
void toolkit_alert(const char* fmt, ...);
|
||||||
|
|
||||||
// Modification
|
// Modification.
|
||||||
|
void window_setFptr(const unsigned int wid, void(*fptr)(char*));
|
||||||
void window_modifyText(const unsigned int wid, char* name, char* newstring);
|
void window_modifyText(const unsigned int wid, char* name, char* newstring);
|
||||||
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
|
void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user