2014-06-01 17:55:23 +00:00
|
|
|
/*
|
2018-09-02 00:57:29 +00:00
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
2014-06-01 17:55:23 +00:00
|
|
|
* 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 "gr.h"
|
2010-12-05 12:33:25 +00:00
|
|
|
#include "console.h"
|
2009-05-21 12:16:39 +00:00
|
|
|
|
2016-10-31 08:15:20 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2015-10-09 02:46:10 +00:00
|
|
|
#include "fwd-window.h"
|
2016-10-28 05:32:24 +00:00
|
|
|
#include "event.h"
|
2020-08-28 00:18:45 +00:00
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2012-11-11 22:12:51 +00:00
|
|
|
|
2016-07-16 16:52:04 +00:00
|
|
|
constexpr const unused_window_userdata_t *unused_window_userdata = nullptr;
|
2013-12-01 05:21:47 +00:00
|
|
|
|
2016-10-03 03:15:22 +00:00
|
|
|
class window
|
2016-10-02 06:32:30 +00:00
|
|
|
{
|
2020-08-28 00:18:45 +00:00
|
|
|
public:
|
2016-10-02 06:32:30 +00:00
|
|
|
grs_canvas w_canv; // the window's canvas to draw to
|
2020-08-28 00:18:45 +00:00
|
|
|
private:
|
2016-10-02 06:32:30 +00:00
|
|
|
int w_visible; // whether it's visible
|
|
|
|
int w_modal; // modal = accept all user input exclusively
|
2016-10-03 03:15:22 +00:00
|
|
|
class window *prev; // the previous window in the doubly linked list
|
|
|
|
class window *next; // the next window in the doubly linked list
|
2016-10-28 08:49:53 +00:00
|
|
|
bool *w_exists; // optional pointer to a tracking variable
|
2016-10-02 06:32:30 +00:00
|
|
|
public:
|
2016-11-19 17:24:52 +00:00
|
|
|
explicit window(grs_canvas &src, int x, int y, int w, int h);
|
2020-12-27 22:03:09 +00:00
|
|
|
window(const window &) = delete;
|
|
|
|
window &operator=(const window &) = delete;
|
2016-11-19 17:24:52 +00:00
|
|
|
virtual ~window();
|
2016-10-02 09:49:19 +00:00
|
|
|
|
2016-11-19 17:24:52 +00:00
|
|
|
virtual window_event_result event_handler(const d_event &) = 0;
|
2016-10-02 09:49:19 +00:00
|
|
|
|
2020-10-22 02:26:16 +00:00
|
|
|
void send_creation_events();
|
2016-10-02 06:32:30 +00:00
|
|
|
friend int window_close(window *wind);
|
|
|
|
friend window *window_get_front();
|
|
|
|
friend window *window_get_first();
|
|
|
|
friend void window_select(window &wind);
|
|
|
|
friend window *window_set_visible(window &wind, int visible);
|
|
|
|
#if !DXX_USE_OGL
|
|
|
|
friend void window_update_canvases();
|
|
|
|
#endif
|
|
|
|
friend window *window_set_visible(window *wind, int visible)
|
|
|
|
{
|
|
|
|
return window_set_visible(*wind, visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
int is_visible()
|
|
|
|
{
|
|
|
|
return w_visible;
|
|
|
|
}
|
|
|
|
|
2020-08-28 00:18:45 +00:00
|
|
|
friend int window_is_visible(window &wind)
|
2016-10-02 06:32:30 +00:00
|
|
|
{
|
2020-08-28 00:18:45 +00:00
|
|
|
return wind.is_visible();
|
2016-10-02 06:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_modal(int modal)
|
|
|
|
{
|
|
|
|
w_modal = modal;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend int window_is_modal(window &wind)
|
|
|
|
{
|
|
|
|
return wind.w_modal;
|
|
|
|
}
|
2016-11-19 17:24:52 +00:00
|
|
|
|
2016-10-02 06:32:30 +00:00
|
|
|
friend window_event_result window_send_event(window &wind, const d_event &event)
|
|
|
|
{
|
2016-11-19 17:24:52 +00:00
|
|
|
auto r = wind.event_handler(event);
|
2016-10-02 06:32:30 +00:00
|
|
|
if (r == window_event_result::close)
|
2016-10-27 08:51:21 +00:00
|
|
|
if (window_close(&wind))
|
|
|
|
return window_event_result::deleted;
|
|
|
|
|
2016-10-02 06:32:30 +00:00
|
|
|
return r;
|
|
|
|
}
|
2016-11-19 17:24:52 +00:00
|
|
|
|
2016-10-02 06:32:30 +00:00
|
|
|
friend window *window_get_next(window &wind)
|
|
|
|
{
|
|
|
|
return wind.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend window *window_get_prev(window &wind)
|
|
|
|
{
|
|
|
|
return wind.prev;
|
|
|
|
}
|
2016-10-28 08:49:53 +00:00
|
|
|
|
2016-10-31 08:15:20 +00:00
|
|
|
void track(bool *exists)
|
2016-10-28 08:49:53 +00:00
|
|
|
{
|
2016-10-31 08:15:20 +00:00
|
|
|
assert(w_exists == nullptr);
|
2016-10-28 08:49:53 +00:00
|
|
|
w_exists = exists;
|
|
|
|
}
|
2016-10-02 06:32:30 +00:00
|
|
|
};
|
|
|
|
|
2018-05-12 18:24:19 +00:00
|
|
|
static inline window_event_result (WINDOW_SEND_EVENT)(window &w, const d_event &event, const char *const file, const unsigned line)
|
2014-08-05 02:34:06 +00:00
|
|
|
{
|
2020-08-28 00:18:45 +00:00
|
|
|
auto &c = w.w_canv;
|
2018-05-12 18:24:19 +00:00
|
|
|
con_printf(CON_DEBUG, "%s:%u: sending event %i to window of dimensions %dx%d", file, line, event.type, 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
|
|
|
}
|
|
|
|
|
2016-11-19 18:09:26 +00:00
|
|
|
void menu_destroy_hook(window *w);
|
|
|
|
|
2020-12-19 16:13:26 +00:00
|
|
|
template <typename T1, typename... ConstructionArgs>
|
2020-12-19 16:13:26 +00:00
|
|
|
T1 *window_create(ConstructionArgs &&... args)
|
2020-12-19 16:13:26 +00:00
|
|
|
{
|
2020-12-19 16:13:26 +00:00
|
|
|
auto r = std::make_unique<T1>(std::forward<ConstructionArgs>(args)...);
|
2020-12-19 16:13:26 +00:00
|
|
|
r->send_creation_events();
|
|
|
|
return r.release();
|
|
|
|
}
|
|
|
|
|
2015-12-05 22:57:24 +00:00
|
|
|
}
|