2021-02-07 13:38:29 -05:00
|
|
|
#ifndef GUI_HPP
|
|
|
|
|
#define GUI_HPP
|
|
|
|
|
|
2022-02-23 23:08:28 -05:00
|
|
|
#include "wrap-string.hpp"
|
|
|
|
|
#include "wrap-map.hpp"
|
|
|
|
|
#include "wrap-vector.hpp"
|
|
|
|
|
|
2021-02-07 13:38:29 -05:00
|
|
|
#include "luastack.hpp"
|
2021-07-19 15:32:34 -04:00
|
|
|
#include "streambuffer.hpp"
|
2021-02-07 13:38:29 -05:00
|
|
|
|
|
|
|
|
class GuiElt {
|
|
|
|
|
friend class Gui;
|
|
|
|
|
public:
|
|
|
|
|
enum Type {
|
|
|
|
|
TYPE_MENU_ITEM,
|
|
|
|
|
};
|
|
|
|
|
private:
|
|
|
|
|
Type type_;
|
2022-02-24 02:17:41 -05:00
|
|
|
eng::string action_;
|
|
|
|
|
eng::string label_;
|
2021-02-07 13:38:29 -05:00
|
|
|
|
|
|
|
|
GuiElt() {}
|
|
|
|
|
public:
|
|
|
|
|
~GuiElt() {}
|
|
|
|
|
Type type() const { return type_; }
|
2022-02-24 02:17:41 -05:00
|
|
|
const eng::string &action() const { return action_; }
|
|
|
|
|
const eng::string &label() const { return label_; }
|
2021-02-07 13:38:29 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Gui {
|
|
|
|
|
public:
|
2022-02-24 02:17:41 -05:00
|
|
|
using EltVec = eng::vector<GuiElt>;
|
2021-02-07 13:38:29 -05:00
|
|
|
private:
|
2021-11-16 13:14:59 -05:00
|
|
|
int64_t place_;
|
2021-02-07 13:38:29 -05:00
|
|
|
EltVec elts_;
|
|
|
|
|
public:
|
2021-11-16 13:14:59 -05:00
|
|
|
Gui() { place_ = 0; }
|
|
|
|
|
int64_t place() { return place_; }
|
2021-02-07 13:38:29 -05:00
|
|
|
const EltVec &elts() const { return elts_; }
|
2021-11-16 13:14:59 -05:00
|
|
|
void clear(int64_t p) { place_ = p; elts_.clear(); }
|
2022-02-24 02:17:41 -05:00
|
|
|
bool has_action(const eng::string &action) const;
|
|
|
|
|
void menu_item(const eng::string &action, const eng::string &label);
|
|
|
|
|
eng::string get_action(int index);
|
|
|
|
|
eng::string menu_debug_string() const;
|
2021-02-25 14:09:16 -05:00
|
|
|
|
|
|
|
|
// Put a pointer to a gui into the lua registry.
|
|
|
|
|
//
|
|
|
|
|
// All lua commands that manipulate the GUI implicitly
|
|
|
|
|
// operate on this global gui pointer.
|
|
|
|
|
//
|
|
|
|
|
static void store_global_pointer(lua_State *L, Gui *g);
|
|
|
|
|
static Gui *fetch_global_pointer(lua_State *L);
|
2021-02-07 13:38:29 -05:00
|
|
|
};
|
|
|
|
|
|
2021-02-25 14:09:16 -05:00
|
|
|
|
2021-02-07 13:38:29 -05:00
|
|
|
#endif // GUI_HPP
|
|
|
|
|
|