hollyhock
dialog.hpp
1 #pragma once
2 #include <stdint.h>
3 #include "util.hpp"
4 
5 // pre-declare the class, since a pointer to it is placed in the vtable
6 class GUIDialog;
7 
9 struct GUIDialog_Wrapped_VTable {
25  GUIDialog *me;
26  uint32_t fakeentrypadding[2];
27 
28  VTABLE_FAKE_ENTRY(1, 0);
29 
30  // Args: event
31  // Return: unknown?
32  VTableFunction<int, struct GUIDialog_OnEvent_Data *> OnEvent;
33 
34  VTABLE_FAKE_ENTRY(1, 1);
35 
36  // Args: element, unknown0
37  // unknown0 - always pass 0
38  VTableFunction<void, void *, int> AddElement;
39 
40  VTABLE_FAKE_ENTRY(4, 2);
41 
42  VTableFunction<void> Refresh;
43 
44  VTABLE_FAKE_ENTRY(23, 3);
45 
46  // Return: dialog result
47  VTableFunction<int> ShowDialog;
48 
49  VTABLE_FAKE_ENTRY(20, 4);
50 };
51 
53 struct GUIDialog_Wrapped {
54  uint8_t unknown0[0x10];
55 
56  // refer to accessors in GUIDialog class for documentation
57  uint16_t leftX;
58  uint16_t topY;
59  uint16_t rightX;
60  uint16_t bottomY;
61 
62  uint8_t unknown1[0x34];
63 
64  struct GUIDialog_Wrapped_VTable *vtable;
65 
66  uint8_t unknown2[0x58];
67 };
68 static_assert(sizeof(struct GUIDialog_Wrapped) == 0xA8);
69 
71  uint16_t type;
72 
74  uint16_t data;
75 
77  void *element;
78 
86  constexpr uint16_t GetEventID() {
87  return (type >> 4) - 8;
88  }
89 };
90 
91 class GUIDialog : public Wrapped {
92 public:
93  enum Height : int {
94  Height25 = 0,
95  Height55 = 1,
96  Height75 = 2,
97  Height95 = 3,
98  Height35 = 4,
99  Height60 = 5
100  };
101 
102  enum Alignment : int {
103  AlignTop = 0,
104  AlignCenter = 1,
105  AlignBottom = 2
106  };
107 
108  enum KeyboardState : int {
109  KeyboardStateNone = 0, // 2 gives same effect
110  KeyboardStateMath1 = 1, // 3 gives same effect
111  KeyboardStateMath2 = 4,
112  KeyboardStateMath3 = 5,
113  KeyboardStateTrig = 6,
114  KeyboardStateVar = 7,
115  KeyboardStateABC = 8,
116  KeyboardStateCatalog = 9,
117  KeyboardStateAdvance = 10,
118  KeyboardStateNumber = 11
119  };
120 
121  enum DialogResult : int {
122  DialogResultOK = 0x3EA,
123  DialogResultCancel = 0x3EB
124  };
125 
126  GUIDialog(
127  enum Height height, enum Alignment alignment,
128  const char* title,
129  enum KeyboardState keyboard
130  );
131 
132  virtual int OnEvent(struct GUIDialog_Wrapped *dialog, struct GUIDialog_OnEvent_Data *event);
133 
134  uint16_t GetLeftX();
135  uint16_t GetTopY();
136  uint16_t GetRightX();
137  uint16_t GetBottomY();
138 
139  void AddElement(GUIElement &element);
140  void Refresh();
141  DialogResult ShowDialog();
142 
143 private:
144  struct GUIDialog_Wrapped_VTable *m_oldVTable;
145  struct GUIDialog_Wrapped_VTable m_vtable;
146 
147  static int OnEvent_Wrap(struct GUIDialog_Wrapped *dialog, struct GUIDialog_OnEvent_Data *event);
148 };
149 
151 extern "C"
152 struct GUIDialog_Wrapped *GUIDialog_ctor(
153  void *dialog,
154  int height, int alignment,
155  const char *title,
156  int unknown2, int unknown3,
157  int keyboard
158 );
Definition: dialog.hpp:91
uint16_t GetRightX()
Definition: dialog.cpp:74
uint16_t GetBottomY()
Definition: dialog.cpp:83
uint16_t GetLeftX()
Definition: dialog.cpp:56
void Refresh()
Definition: dialog.cpp:102
void AddElement(GUIElement &element)
Definition: dialog.cpp:92
GUIDialog(enum Height height, enum Alignment alignment, const char *title, enum KeyboardState keyboard)
Definition: dialog.cpp:12
DialogResult ShowDialog()
Definition: dialog.cpp:111
uint16_t GetTopY()
Definition: dialog.cpp:65
Definition: util.hpp:78
Definition: util.hpp:48
Definition: dialog.hpp:70
uint16_t data
Arbitary data. Usage dependent on event and element type.
Definition: dialog.hpp:74
constexpr uint16_t GetEventID()
Definition: dialog.hpp:86
void * element
The pointer to the internal GUI element class the event refers to.
Definition: dialog.hpp:77