Skip to content

Commit e636883

Browse files
committed
2 parents d678e66 + cfadc36 commit e636883

6 files changed

Lines changed: 696 additions & 0 deletions

File tree

include/__doxygen.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@
338338
//! @defgroup libkiwi_core core
339339
//! @brief Core system
340340

341+
//! @ingroup libkiwi
342+
//! @defgroup libkiwi_crypt crypt
343+
//! @brief Cryptography
344+
341345
//! @ingroup libkiwi
342346
//! @defgroup libkiwi_debug debug
343347
//! @brief Debugging
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <libkiwi.h>
2+
3+
namespace kiwi {
4+
5+
;
6+
7+
} // namespace kiwi

lib/libkiwi/debug/kiwiDebugMenu.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#ifndef LIBKIWI_DEBUG_DEBUG_MENU_H
2+
#define LIBKIWI_DEBUG_DEBUG_MENU_H
3+
#include <Pack/RPGraphics.h>
4+
#include <libkiwi/k_types.h>
5+
#include <libkiwi/prim/kiwiVector.h>
6+
7+
namespace kiwi {
8+
//! @addtogroup libkiwi_debug
9+
//! @{
10+
11+
// Forward declarations
12+
class DebugOptionBase;
13+
14+
/**
15+
* @brief Debug menu
16+
*/
17+
class DebugMenu : public IRPGrpDrawObject {
18+
public:
19+
/**
20+
* @brief Option action result
21+
*/
22+
enum EResult {
23+
EResult_None, //!< Nothing happened
24+
EResult_Invalid, //!< State failed to change
25+
EResult_Change, //!< State changed
26+
EResult_Close, //!< Request to close menu
27+
};
28+
29+
public:
30+
/**
31+
* @brief Constructor
32+
*/
33+
DebugMenu() : mCursor(0) {}
34+
/**
35+
* @brief Destructor
36+
*/
37+
virtual ~DebugMenu() {
38+
mOptions.Clear();
39+
}
40+
41+
/**
42+
* @brief Updates the menu state
43+
*/
44+
virtual void Calculate();
45+
/**
46+
* @brief User-level render pass
47+
*/
48+
virtual void UserDraw();
49+
50+
/**
51+
* @brief Updates the menu state (for sub-classes)
52+
*/
53+
virtual void OnCalculate() {}
54+
/**
55+
* @brief Render pass (for sub-classes)
56+
*/
57+
virtual void OnUserDraw() {}
58+
59+
protected:
60+
//! Cursor position
61+
u32 mCursor;
62+
63+
//! Option list
64+
TVector<DebugOptionBase*> mOptions;
65+
};
66+
67+
//! @}
68+
} // namespace kiwi
69+
70+
#endif
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
#include <libkiwi.h>
2+
3+
namespace kiwi {
4+
5+
/******************************************************************************
6+
*
7+
* DebugOptionBase
8+
*
9+
******************************************************************************/
10+
11+
/**
12+
* @brief Sets whether the option is enabled
13+
*
14+
* @param enable Enable status
15+
*/
16+
void DebugOptionBase::SetEnabled(bool enable) {
17+
mIsEnabled = enable;
18+
UpdateString();
19+
}
20+
21+
/******************************************************************************
22+
*
23+
* DebugIntOption
24+
*
25+
******************************************************************************/
26+
27+
/**
28+
* @brief Constructor
29+
*
30+
* @param rName Option name
31+
* @param min Minimum value (inclusive)
32+
* @param max Maximum value (inclusive)
33+
* @param initial Initial value (optional)
34+
*/
35+
DebugIntOption::DebugIntOption(const String& rName, int min, int max,
36+
Optional<int> initial)
37+
: DebugOptionBase(rName), mMin(min), mMax(max) {
38+
39+
K_ASSERT(max >= min);
40+
41+
// Initial value defaults to minimum
42+
SetValue(initial ? *initial : min);
43+
}
44+
45+
/**
46+
* @brief Increments the option value
47+
* @return Action result
48+
*/
49+
DebugMenu::EResult DebugIntOption::Increment() {
50+
if (!IsEnabled()) {
51+
return DebugMenu::EResult_Invalid;
52+
}
53+
54+
// Value wraps around
55+
SetValue(mValue == mMax ? mMin : mValue + 1);
56+
return DebugMenu::EResult_Change;
57+
}
58+
59+
/**
60+
* @brief Decrements the option value
61+
* @return Action result
62+
*/
63+
DebugMenu::EResult DebugIntOption::Decrement() {
64+
if (!IsEnabled()) {
65+
return DebugMenu::EResult_Invalid;
66+
}
67+
68+
// Value wraps around
69+
SetValue(mValue == mMin ? mMax : mValue - 1);
70+
return DebugMenu::EResult_Change;
71+
}
72+
73+
/**
74+
* @brief Sets the maximum value (inclusive)
75+
* @details The current option value is validated upon range changes.
76+
*
77+
* @param max New maximum value (inclusive)
78+
*/
79+
void DebugIntOption::SetMax(int max) {
80+
K_ASSERT(max >= mMin);
81+
82+
mMax = max;
83+
Validate();
84+
}
85+
86+
/**
87+
* @brief Sets the minimum value (inclusive)
88+
* @details The current option value is validated upon range changes.
89+
*
90+
* @param min New minimum value (inclusive)
91+
*/
92+
void DebugIntOption::SetMin(int min) {
93+
K_ASSERT(min <= mMax);
94+
95+
mMin = min;
96+
Validate();
97+
}
98+
99+
/**
100+
* @brief Sets the range (inclusive) of acceptable values
101+
* @details The current option value is validated upon range changes.
102+
*
103+
* @param min New minimum value (inclusive)
104+
* @param max New maximum value (inclusive)
105+
*/
106+
void DebugIntOption::SetRange(int min, int max) {
107+
K_ASSERT(max >= min);
108+
109+
mMin = min;
110+
mMax = max;
111+
Validate();
112+
}
113+
114+
/**
115+
* @brief Validates the option value
116+
*/
117+
void DebugIntOption::Validate() {
118+
if (mValue > mMax) {
119+
SetValue(mMax);
120+
} else if (mValue < mMin) {
121+
SetValue(mMin);
122+
}
123+
}
124+
125+
/**
126+
* @brief Updates the option value string
127+
*/
128+
void DebugIntOption::UpdateString() {
129+
if (IsEnabled()) {
130+
mValueText = kiwi::ToString(mValue);
131+
} else {
132+
mValueText = "DISABLED";
133+
}
134+
}
135+
136+
/**
137+
* @brief Sets the integer option value
138+
*
139+
* @param value New value
140+
*/
141+
void DebugIntOption::SetValue(int value) {
142+
mValue = Clamp(mValue, mMin, mMax);
143+
UpdateString();
144+
}
145+
146+
/******************************************************************************
147+
*
148+
* DebugBoolOption
149+
*
150+
******************************************************************************/
151+
152+
/**
153+
* @brief Updates the option value string
154+
*/
155+
void DebugBoolOption::UpdateString() {
156+
if (IsEnabled()) {
157+
mValueText = GetValue() ? "True" : "False";
158+
} else {
159+
mValueText = "DISABLED";
160+
}
161+
}
162+
163+
/******************************************************************************
164+
*
165+
* DebugEnumOption
166+
*
167+
******************************************************************************/
168+
169+
/**
170+
* @brief Sets the option enum value strings
171+
*
172+
* @param ppValues Enum value strings
173+
*/
174+
void DebugEnumOption::SetEnumValues(const char** ppValues) {
175+
K_ASSERT(ppValues != nullptr);
176+
177+
mppValues = ppValues;
178+
UpdateString();
179+
}
180+
181+
/**
182+
* @brief Updates the option value string
183+
*/
184+
void DebugEnumOption::UpdateString() {
185+
K_ASSERT(mppValues != nullptr);
186+
187+
if (IsEnabled()) {
188+
mValueText = mppValues[GetValue()];
189+
} else {
190+
mValueText = "DISABLED";
191+
}
192+
}
193+
194+
/******************************************************************************
195+
*
196+
* DebugProcOption
197+
*
198+
******************************************************************************/
199+
200+
/**
201+
* @brief Performs the option selection logic
202+
* @return Action result
203+
*/
204+
DebugMenu::EResult DebugProcOption::Select() {
205+
if (!IsEnabled()) {
206+
return DebugMenu::EResult_Invalid;
207+
}
208+
209+
if (mpCallback != nullptr) {
210+
return mpCallback(mpCallbackArg);
211+
}
212+
213+
return DebugMenu::EResult_None;
214+
}
215+
216+
} // namespace kiwi

0 commit comments

Comments
 (0)