| 1 |
/* |
| 2 |
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
| 3 |
* It is copyright by its individual contributors, as recorded in the |
| 4 |
* project's Git history. See COPYING.txt at the top level for license |
| 5 |
* terms and a link to the Git history. |
| 6 |
*/ |
| 7 |
/* |
| 8 |
* A 'window' is simply a canvas that can receive events. |
| 9 |
* It can be anything from a simple message box to the |
| 10 |
* game screen when playing. |
| 11 |
* |
| 12 |
* See event.c for event handling code. |
| 13 |
* |
| 14 |
* -kreator 2009-05-06 |
| 15 |
*/ |
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include "dxxsconf.h" |
| 20 |
#include "gr.h" |
| 21 |
#include "console.h" |
| 22 |
|
| 23 |
#include <assert.h> |
| 24 |
|
| 25 |
#include "fwd-window.h" |
| 26 |
#include "event.h" |
| 27 |
#include <memory> |
| 28 |
|
| 29 |
namespace dcx { |
| 30 |
|
| 31 |
class window |
| 32 |
{ |
| 33 |
public: |
| 34 |
grs_subcanvas w_canv; // the window's canvas to draw to |
| 35 |
private: |
| 36 |
class window *prev; // the previous window in the doubly linked list |
| 37 |
class window *next = nullptr; // the next window in the doubly linked list |
| 38 |
uint8_t w_visible{1}; // whether it's visible |
| 39 |
uint8_t w_modal{1}; // modal = accept all user input exclusively |
| 40 |
public: |
| 41 |
explicit window(grs_canvas &src, uint16_t x, uint16_t y, uint16_t w, uint16_t h); |
| 42 |
window(const window &) = delete; |
| 43 |
window &operator=(const window &) = delete; |
| 44 |
virtual ~window(); |
| 45 |
|
| 46 |
virtual window_event_result event_handler(const d_event &) = 0; |
| 47 |
|
| 48 |
void send_creation_events(); |
| 49 |
friend int window_close(window *wind); |
| 50 |
friend window *window_get_front(); |
| 51 |
friend window *window_get_first(); |
| 52 |
friend void window_select(window &wind); |
| 53 |
#if !DXX_USE_OGL |
| 54 |
friend void window_update_canvases(); |
| 55 |
#endif |
| 56 |
|
| 57 |
uint8_t is_visible() const |
| 58 |
{ |
| 59 |
return w_visible; |
| 60 |
} |
| 61 |
window *set_visible(uint8_t visible); |
| 62 |
|
| 63 |
void set_modal(uint8_t modal) |
| 64 |
{ |
| 65 |
w_modal = modal; |
| 66 |
} |
| 67 |
|
| 68 |
uint8_t is_modal() const |
| 69 |
{ |
| 70 |
return w_modal; |
| 71 |
} |
| 72 |
|
| 73 |
window_event_result send_event(const d_event &event |
| 74 |
#if DXX_HAVE_CXX_BUILTIN_FILE_LINE |
| 75 |
, const char *file = __builtin_FILE(), unsigned line = __builtin_LINE() |
| 76 |
#endif |
| 77 |
); |
| 78 |
friend window *window_get_next(window &wind) |
| 79 |
{ |
| 80 |
return wind.next; |
| 81 |
} |
| 82 |
|
| 83 |
friend window *window_get_prev(window &wind) |
| 84 |
{ |
| 85 |
return wind.prev; |
| 86 |
} |
| 87 |
}; |
| 88 |
|
| 89 |
struct mixin_trackable_window |
| 90 |
{ |
| 91 |
std::shared_ptr<bool> exists; |
| 92 |
std::shared_ptr<bool> track() |
| 93 |
{ |
| 94 |
if (!exists) |
| 95 |
exists = std::make_unique<bool>(true); |
| 96 |
return exists; |
| 97 |
} |
| 98 |
~mixin_trackable_window(); |
| 99 |
}; |
| 100 |
|
| 101 |
void menu_destroy_hook(window *w); |
| 102 |
|
| 103 |
template <typename T1, typename... ConstructionArgs> |
| 104 |
T1 *window_create(ConstructionArgs &&... args) |
| 105 |
{ |
| 106 |
auto r = std::make_unique<T1>(std::forward<ConstructionArgs>(args)...); |
| 107 |
r->send_creation_events(); |
| 108 |
return r.release(); |
| 109 |
} |
| 110 |
|
| 111 |
} |