Add new window system, not used yet
This commit is contained in:
parent
67fa9e0e49
commit
a1c9e3986e
|
@ -1,5 +1,9 @@
|
|||
D2X-Rebirth Changelog
|
||||
|
||||
20090521
|
||||
--------
|
||||
arch/include/event.h, arch/include/window.h, arch/sdl/event.c, arch/sdl/mouse.c, arch/sdl/window.c, d1x-rebirth.xcodeproj/project.pbxproj, main/inferno.c, SConstruct: Add new window system, not used yet
|
||||
|
||||
20090506
|
||||
--------
|
||||
main/config.c, main/config.h, main/menu.c, main/songs.c: Add option to force either Redbook or Jukebox to use the playing order for the game CD
|
||||
|
|
|
@ -83,6 +83,7 @@ common_sources = [
|
|||
'arch/sdl/mouse.c',
|
||||
'arch/sdl/rbaudio.c',
|
||||
'arch/sdl/timer.c',
|
||||
'arch/sdl/window.c',
|
||||
'arch/sdl/digi.c',
|
||||
'arch/sdl/digi_audio.c',
|
||||
'iff/iff.c',
|
||||
|
|
|
@ -19,15 +19,22 @@
|
|||
#ifndef _EVENT_H
|
||||
#define _EVENT_H
|
||||
|
||||
#ifdef GII_XWIN
|
||||
#include <ggi/input/xwin.h>
|
||||
#endif
|
||||
typedef enum event_type
|
||||
{
|
||||
EVENT_OTHER = 0,
|
||||
EVENT_DRAW
|
||||
} event_type;
|
||||
|
||||
// A vanilla event. Cast to the correct type of event according to 'type'.
|
||||
typedef struct d_event
|
||||
{
|
||||
event_type type;
|
||||
} d_event;
|
||||
|
||||
int event_init();
|
||||
void event_poll();
|
||||
|
||||
#ifdef GII_XWIN
|
||||
void init_gii_xwin(Display *disp,Window win);
|
||||
#endif
|
||||
// Not to be confused with event_poll, which will be removed eventually, this one sends events to event handlers
|
||||
void event_process();
|
||||
|
||||
#endif
|
||||
|
|
25
arch/include/window.h
Normal file
25
arch/include/window.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* A 'window' is simply a canvas that can receive events.
|
||||
* It can be anything from a simple message box to the
|
||||
* game screen when playing.
|
||||
*
|
||||
* See event.c for event handling code.
|
||||
*
|
||||
* -kreator 2009-05-06
|
||||
*/
|
||||
|
||||
#include "event.h"
|
||||
#include "gr.h"
|
||||
|
||||
typedef struct window window;
|
||||
|
||||
extern window *window_create(grs_canvas *src, int x, int y, int w, int h, int (*event_callback)(window *wind, d_event *event, void *data), void *data);
|
||||
extern void window_close(window *wind);
|
||||
extern window *window_get_front(void);
|
||||
extern window *window_get_first(void);
|
||||
extern window *window_get_next(window *wind);
|
||||
extern void window_select(window *wind);
|
||||
extern void window_set_visible(window *wind, int visible);
|
||||
extern int window_is_visible(window *wind);
|
||||
extern grs_canvas *window_get_canvas(window *wind);
|
||||
extern int window_send_event(window *wind, d_event *event);
|
|
@ -8,7 +8,9 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "event.h"
|
||||
#include "key.h"
|
||||
#include "window.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
|
@ -69,3 +71,25 @@ int event_init()
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Process the first event in queue, sending to the appropriate handler
|
||||
// This is the new object-oriented system
|
||||
// Uses the old system for now, but this will change
|
||||
void event_process(void)
|
||||
{
|
||||
d_event event;
|
||||
window *wind;
|
||||
|
||||
// Very trivial system for now.
|
||||
event.type = EVENT_OTHER; // process user input first
|
||||
wind = window_get_front();
|
||||
if (!wind)
|
||||
return;
|
||||
|
||||
window_send_event(wind, &event);
|
||||
|
||||
event.type = EVENT_DRAW; // then draw all visible windows
|
||||
for (wind = window_get_first(); wind != NULL; wind = window_get_next(wind))
|
||||
if (window_is_visible(wind))
|
||||
window_send_event(wind, &event);
|
||||
}
|
||||
|
|
123
arch/sdl/window.c
Normal file
123
arch/sdl/window.c
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* A 'window' is simply a canvas that can receive events.
|
||||
* It can be anything from a simple message box to the
|
||||
* game screen when playing.
|
||||
*
|
||||
* See event.c for event handling code.
|
||||
*
|
||||
* -kreator 2009-05-06
|
||||
*/
|
||||
|
||||
#include "gr.h"
|
||||
#include "window.h"
|
||||
|
||||
struct window
|
||||
{
|
||||
grs_canvas w_canv; // the window's canvas to draw to
|
||||
int (*w_callback)(window *wind, d_event *event, void *data); // the event handler
|
||||
int w_visible; // whether it's visible
|
||||
void *data; // whatever the user wants (eg menu data for 'newmenu' menus)
|
||||
struct window *prev; // the previous window in the doubly linked list
|
||||
struct window *next; // the next window in the doubly linked list
|
||||
};
|
||||
|
||||
static window *FrontWindow = NULL;
|
||||
static window *FirstWindow = NULL;
|
||||
|
||||
window *window_create(grs_canvas *src, int x, int y, int w, int h, int (*event_callback)(window *wind, d_event *event, void *data), void *data)
|
||||
{
|
||||
window *wind;
|
||||
|
||||
wind = d_malloc(sizeof(window));
|
||||
if (wind == NULL)
|
||||
return NULL;
|
||||
|
||||
Assert(src != NULL);
|
||||
Assert(event_callback != NULL);
|
||||
gr_init_sub_canvas(&wind->w_canv, src, x, y, w, h);
|
||||
wind->w_callback = event_callback;
|
||||
wind->w_visible = 1; // default to visible
|
||||
wind->data = data;
|
||||
|
||||
if (FirstWindow == NULL)
|
||||
FirstWindow = wind;
|
||||
wind->prev = FrontWindow;
|
||||
FrontWindow->next = wind;
|
||||
wind->next = NULL;
|
||||
FrontWindow = wind;
|
||||
|
||||
return wind;
|
||||
}
|
||||
|
||||
void window_close(window *wind)
|
||||
{
|
||||
if (wind == FrontWindow)
|
||||
FrontWindow = wind->prev;
|
||||
if (wind == FirstWindow)
|
||||
FirstWindow = wind->next;
|
||||
if (wind->next)
|
||||
wind->next->prev = wind->prev;
|
||||
if (wind->prev)
|
||||
wind->prev->next = wind->next;
|
||||
|
||||
d_free(wind);
|
||||
}
|
||||
|
||||
// Get the top window that's visible
|
||||
window *window_get_front(void)
|
||||
{
|
||||
window *wind;
|
||||
|
||||
for (wind = FrontWindow; (wind != NULL) && !wind->w_visible; wind = wind->prev) {}
|
||||
|
||||
return wind;
|
||||
}
|
||||
|
||||
window *window_get_first(void)
|
||||
{
|
||||
return FirstWindow;
|
||||
}
|
||||
|
||||
window *window_get_next(window *wind)
|
||||
{
|
||||
return wind->next;
|
||||
}
|
||||
|
||||
// Make wind the front window
|
||||
void window_select(window *wind)
|
||||
{
|
||||
Assert (wind != NULL);
|
||||
|
||||
if (wind == FrontWindow)
|
||||
return;
|
||||
if ((wind == FirstWindow) && FirstWindow->next)
|
||||
FirstWindow = FirstWindow->next;
|
||||
|
||||
if (wind->next)
|
||||
wind->next->prev = wind->prev;
|
||||
if (wind->prev)
|
||||
wind->prev->next = wind->next;
|
||||
wind->prev = FrontWindow;
|
||||
wind->next = NULL;
|
||||
FrontWindow = wind;
|
||||
}
|
||||
|
||||
void window_set_visible(window *wind, int visible)
|
||||
{
|
||||
wind->w_visible = visible;
|
||||
}
|
||||
|
||||
int window_is_visible(window *wind)
|
||||
{
|
||||
return wind->w_visible;
|
||||
}
|
||||
|
||||
grs_canvas *window_get_canvas(window *wind)
|
||||
{
|
||||
return &wind->w_canv;
|
||||
}
|
||||
|
||||
int window_send_event(window *wind, d_event *event)
|
||||
{
|
||||
return wind->w_callback(wind, event, wind->data);
|
||||
}
|
|
@ -384,6 +384,8 @@
|
|||
EBC652140890D6DF004FCAA3 /* func.h in Headers */ = {isa = PBXBuildFile; fileRef = EBC652120890D6DF004FCAA3 /* func.h */; };
|
||||
EBC6525C0890F79B004FCAA3 /* nocfile.h in Headers */ = {isa = PBXBuildFile; fileRef = EBC6525B0890F79B004FCAA3 /* nocfile.h */; };
|
||||
EBC6525D0890F79B004FCAA3 /* nocfile.h in Headers */ = {isa = PBXBuildFile; fileRef = EBC6525B0890F79B004FCAA3 /* nocfile.h */; };
|
||||
EBE8D6EB0FC583B4009D181F /* window.c in Sources */ = {isa = PBXBuildFile; fileRef = EBE8D6EA0FC583B4009D181F /* window.c */; };
|
||||
EBE8D6EC0FC583B4009D181F /* window.c in Sources */ = {isa = PBXBuildFile; fileRef = EBE8D6EA0FC583B4009D181F /* window.c */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
|
@ -771,6 +773,8 @@
|
|||
EBC6520F0890D6B7004FCAA3 /* ui.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ui.h; sourceTree = "<group>"; };
|
||||
EBC652120890D6DF004FCAA3 /* func.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = func.h; sourceTree = "<group>"; };
|
||||
EBC6525B0890F79B004FCAA3 /* nocfile.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = nocfile.h; sourceTree = "<group>"; };
|
||||
EBE8D6E90FC58365009D181F /* window.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = window.h; sourceTree = "<group>"; };
|
||||
EBE8D6EA0FC583B4009D181F /* window.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = window.c; sourceTree = "<group>"; };
|
||||
EBF6589B0F936BA200CB5C73 /* ipx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ipx.c; sourceTree = "<group>"; };
|
||||
EBF6589C0F936BA200CB5C73 /* ipx_kali.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ipx_kali.c; sourceTree = "<group>"; };
|
||||
EBF6589D0F936BD800CB5C73 /* ipx.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ipx.c; sourceTree = "<group>"; };
|
||||
|
@ -936,6 +940,7 @@
|
|||
6791CFE30668899A00056A5A /* joy.h */,
|
||||
EB92BE140CDD68200045A32C /* jukebox.h */,
|
||||
6791D07006688A5F00056A5A /* mouse.h */,
|
||||
EBE8D6E90FC58365009D181F /* window.h */,
|
||||
);
|
||||
name = include;
|
||||
path = arch/include;
|
||||
|
@ -1018,6 +1023,7 @@
|
|||
67B441DB06687A0200DF26D8 /* mouse.c */,
|
||||
67B441DC06687A0200DF26D8 /* rbaudio.c */,
|
||||
67B441DD06687A0200DF26D8 /* timer.c */,
|
||||
EBE8D6EA0FC583B4009D181F /* window.c */,
|
||||
);
|
||||
name = sdl;
|
||||
path = arch/sdl;
|
||||
|
@ -1826,6 +1832,7 @@
|
|||
EBB9E5580D8E8502003466E6 /* netdrv_udp.c in Sources */,
|
||||
EB28D9A40ECEAF1C00E68E9B /* init.c in Sources */,
|
||||
EB423D230F63FC710082C684 /* noloss.c in Sources */,
|
||||
EBE8D6EC0FC583B4009D181F /* window.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -1962,6 +1969,7 @@
|
|||
EB92BEA60CDD6A570045A32C /* dl_list.c in Sources */,
|
||||
EB92BEA70CDD6A570045A32C /* hmp2mid.c in Sources */,
|
||||
EB28D9A30ECEAF1C00E68E9B /* init.c in Sources */,
|
||||
EBE8D6EB0FC583B4009D181F /* window.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -444,6 +444,9 @@ int main(int argc, char *argv[])
|
|||
default:
|
||||
Error("Invalid function mode %d",Function_mode);
|
||||
}
|
||||
|
||||
// Send events to windows and the default handler
|
||||
event_process();
|
||||
}
|
||||
|
||||
WriteConfigFile();
|
||||
|
|
Loading…
Reference in a new issue