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
|
|
|
|
*/
|
|
|
|
|
2014-10-16 02:30:29 +00:00
|
|
|
#pragma once
|
2010-01-09 09:19:26 +00:00
|
|
|
|
2009-05-21 12:16:39 +00:00
|
|
|
#include "event.h"
|
|
|
|
#include "gr.h"
|
2010-12-05 12:33:25 +00:00
|
|
|
#include "console.h"
|
2009-05-21 12:16:39 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
2013-12-22 22:03:07 +00:00
|
|
|
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;
|
2014-10-16 02:30:29 +00:00
|
|
|
static const unused_window_userdata_t *const unused_window_userdata = nullptr;
|
2013-12-01 05:21:47 +00:00
|
|
|
|
2014-09-07 18:06:59 +00:00
|
|
|
struct embed_window_pointer_t
|
|
|
|
{
|
|
|
|
window *wind;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ignore_window_pointer_t
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2014-12-20 04:36:09 +00:00
|
|
|
window *window_create(grs_canvas *src, int x, int y, int w, int h, window_subfunction_t<void>::type event_callback, void *userdata, const void *createdata);
|
2014-08-05 02:33:40 +00:00
|
|
|
|
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 *) {}
|
|
|
|
|
2014-12-20 04:36:09 +00:00
|
|
|
template <typename T1, typename T2 = const void>
|
|
|
|
static inline window *window_create(grs_canvas *src, int x, int y, int w, int h, typename window_subfunction_t<T1>::type event_callback, T1 *data, T2 *createdata = nullptr)
|
2013-12-01 05:21:47 +00:00
|
|
|
{
|
2014-12-20 04:36:09 +00:00
|
|
|
auto win = window_create(src, x, y, w, h, (window_subfunction_t<void>::type)event_callback, static_cast<void *>(data), static_cast<const void *>(createdata));
|
2014-09-07 18:06:59 +00:00
|
|
|
set_embedded_window_pointer(data, win);
|
|
|
|
return win;
|
2013-12-01 05:21:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-20 04:36:09 +00:00
|
|
|
template <typename T1, typename T2 = const void>
|
|
|
|
static inline window *window_create(grs_canvas *src, int x, int y, int w, int h, typename window_subfunction_t<const T1>::type event_callback, const T1 *userdata, T2 *createdata = nullptr)
|
2014-10-16 02:30:29 +00:00
|
|
|
{
|
2014-12-20 04:36:09 +00:00
|
|
|
return window_create(src, x, y, w, h, (window_subfunction_t<void>::type)event_callback, static_cast<void *>(const_cast<T1 *>(userdata)), static_cast<const void *>(createdata));
|
2014-10-16 02:30:29 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 13:49:54 +00:00
|
|
|
extern int window_close(window *wind);
|
2010-03-17 09:44:19 +00:00
|
|
|
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);
|
2010-04-04 09:41:53 +00:00
|
|
|
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);
|
2015-01-17 18:31:40 +00:00
|
|
|
grs_canvas &window_get_canvas(window &wind);
|
2012-03-24 06:43:08 +00:00
|
|
|
extern void window_update_canvases(void);
|
2015-01-17 18:31:40 +00:00
|
|
|
window_event_result window_send_event(window &wind,const d_event &event);
|
2015-01-17 18:31:41 +00:00
|
|
|
void window_set_modal(window &wind, int modal);
|
|
|
|
static inline void window_set_modal(window *wind, int modal)
|
|
|
|
{
|
|
|
|
window_set_modal(*wind, modal);
|
|
|
|
}
|
2015-01-17 18:31:40 +00:00
|
|
|
int window_is_modal(window &wind);
|
2010-12-05 12:33:25 +00:00
|
|
|
|
2015-01-17 18:31:40 +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
|
|
|
{
|
2015-01-17 18:31:40 +00:00
|
|
|
auto &c = window_get_canvas(w);
|
2015-01-17 18:31:40 +00:00
|
|
|
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);
|
2015-01-17 18:31:40 +00:00
|
|
|
return window_send_event(w, event);
|
2014-08-05 02:34:06 +00:00
|
|
|
}
|
|
|
|
|
2015-01-17 18:31:40 +00:00
|
|
|
#define WINDOW_SEND_EVENT(w, e) (event.type = e, (WINDOW_SEND_EVENT)(*w, event, __FILE__, __LINE__, #e))
|
2010-12-05 12:33:25 +00:00
|
|
|
|
2012-11-11 22:12:51 +00:00
|
|
|
#endif
|