dxx-rebirth/common/include/window.h

103 lines
2.9 KiB
C
Raw Normal View History

2014-06-01 17:55:23 +00:00
/*
* This file is part of the DXX-Rebirth project <http://www.dxx-rebirth.com/>.
* It is copyright by its individual contributors, as recorded in the
* project's Git history. See COPYING.txt at the top level for license
* terms and a link to the Git history.
*/
2009-05-21 12:16:39 +00:00
/*
* 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
*/
2010-01-09 09:19:26 +00:00
#ifndef DESCENT_WINDOW_H
#define DESCENT_WINDOW_H
2009-05-21 12:16:39 +00:00
#include "event.h"
#include "gr.h"
#include "console.h"
2009-05-21 12:16:39 +00:00
#ifdef __cplusplus
struct window;
2009-05-21 12:16:39 +00:00
2014-08-06 02:10:49 +00:00
enum class window_event_result
{
// Window ignored event. Bubble up.
ignored,
// Window handled event.
handled,
close,
};
2012-11-11 00:14:30 +00:00
void arch_init(void);
2013-12-01 05:21:47 +00:00
template <typename T>
class window_subfunction_t
{
public:
2014-10-04 21:47:13 +00:00
typedef window_event_result (*type)(window *menu,const d_event &event, T *userdata);
2013-12-01 05:21:47 +00:00
};
class unused_window_userdata_t;
static unused_window_userdata_t *const unused_window_userdata = NULL;
2014-09-07 18:06:59 +00:00
struct embed_window_pointer_t
{
window *wind;
};
struct ignore_window_pointer_t
{
};
window *window_create(grs_canvas *src, int x, int y, int w, int h, window_subfunction_t<void>::type event_callback, void *data);
2014-09-07 18:06:59 +00:00
static inline void set_embedded_window_pointer(embed_window_pointer_t *wp, window *w)
{
wp->wind = w;
}
static inline void set_embedded_window_pointer(ignore_window_pointer_t *, window *) {}
static inline void set_embedded_window_pointer(unused_window_userdata_t *, window *) {}
2013-12-01 05:21:47 +00:00
template <typename T>
window *window_create(grs_canvas *src, int x, int y, int w, int h, typename window_subfunction_t<T>::type event_callback, T *data)
{
2014-09-07 18:06:59 +00:00
auto win = window_create(src, x, y, w, h, (window_subfunction_t<void>::type)event_callback, static_cast<void *>(data));
set_embedded_window_pointer(data, win);
return win;
2013-12-01 05:21:47 +00:00
}
extern int window_close(window *wind);
extern int window_exists(window *wind);
2009-05-21 12:16:39 +00:00
extern window *window_get_front(void);
extern window *window_get_first(void);
extern window *window_get_next(window *wind);
extern window *window_get_prev(window *wind);
2009-05-21 12:16:39 +00:00
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 void window_update_canvases(void);
2014-10-04 21:47:13 +00:00
window_event_result window_send_event(window *wind,const d_event &event);
extern void window_set_modal(window *wind, int modal);
extern int window_is_modal(window *wind);
2014-10-04 21:47:13 +00:00
static inline window_event_result WINDOW_SEND_EVENT(window *w, const d_event &event, const char *file, unsigned line, const char *e)
2014-08-05 02:34:06 +00:00
{
auto c = window_get_canvas(w);
con_printf(CON_DEBUG, "%s:%u: sending event %s to window of dimensions %dx%d", file, line, e, c->cv_bitmap.bm_w, c->cv_bitmap.bm_h);
2014-10-04 21:47:13 +00:00
return window_send_event(w, event);
2014-08-05 02:34:06 +00:00
}
#define WINDOW_SEND_EVENT(w, e) (event.type = e, (WINDOW_SEND_EVENT)(w, event, __FILE__, __LINE__, #e))
#endif
2010-06-14 08:19:27 +00:00
#endif