-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImEditor.h
More file actions
240 lines (208 loc) · 7.25 KB
/
Copy pathImEditor.h
File metadata and controls
240 lines (208 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
Copyright (c) 2024-2025 Toksisitee. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, refer to license.md or https://opensource.org/licenses/MIT
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*/
#pragma once
#include <array>
#include <utility>
#include <unordered_set>
#include "imgui.h"
#include "Editor.h"
class CTexture2D;
typedef struct IDirect3DDevice9* LPDIRECT3DDEVICE9, * PDIRECT3DDEVICE9;
namespace ImEditor
{
namespace Constants
{
namespace Step
{
extern const int8_t s8_one;
extern const int16_t s16_one;
extern const int32_t s32_one;
extern const uint8_t u8_one;
extern const uint16_t u16_one;
extern const uint32_t u32_one;
extern const float f_one;
extern const double d_one;
}
namespace Limits
{
extern const int8_t s8_min, s8_max;
extern const uint8_t u8_min, u8_max;
extern const int16_t s16_min, s16_max;
extern const uint16_t u16_min, u16_max;
extern const int32_t s32_min, s32_max;
extern const uint32_t u32_min, u32_max;
extern const int64_t s64_min, s64_max;
extern const uint64_t u64_min, u64_max;
extern const float f_min, f_max;
extern const double d_min, d_max;
}
}
template<typename PT>
const void* GetImGuiLimits( PT p_data, bool min )
{
using T = std::remove_pointer_t<PT>;
constexpr static std::array<std::pair<const void*, const void*>, 10> limits = { {
{&Constants::Limits::s8_min, &Constants::Limits::s8_max},
{&Constants::Limits::u8_min, &Constants::Limits::u8_max},
{&Constants::Limits::s16_min, &Constants::Limits::s16_max},
{&Constants::Limits::u16_min, &Constants::Limits::u16_max},
{&Constants::Limits::s32_min, &Constants::Limits::s32_max},
{&Constants::Limits::u32_min, &Constants::Limits::u32_max},
{&Constants::Limits::s64_min, &Constants::Limits::s64_max},
{&Constants::Limits::u64_min, &Constants::Limits::u64_max},
{&Constants::Limits::f_min, &Constants::Limits::f_max},
{&Constants::Limits::d_min, &Constants::Limits::d_max},
} };
if constexpr ( std::is_same_v<T, int8_t> ) {
return min ? limits[0].first : limits[0].second;
}
else if constexpr ( std::is_same_v<T, uint8_t> ) {
return min ? limits[1].first : limits[1].second;
}
else if constexpr ( std::is_same_v<T, int16_t> ) {
return min ? limits[2].first : limits[2].second;
}
else if constexpr ( std::is_same_v<T, uint16_t> ) {
return min ? limits[3].first : limits[3].second;
}
else if constexpr ( std::is_same_v<T, int32_t> ) {
return min ? limits[4].first : limits[4].second;
}
else if constexpr ( std::is_same_v<T, uint32_t> ) {
return min ? limits[5].first : limits[5].second;
}
else if constexpr ( std::is_same_v<T, int64_t> ) {
return min ? limits[6].first : limits[6].second;
}
else if constexpr ( std::is_same_v<T, uint64_t> ) {
return min ? limits[7].first : limits[7].second;
}
else if constexpr ( std::is_same_v<T, float> ) {
return min ? limits[8].first : limits[8].second;
}
else if constexpr ( std::is_same_v<T, double> ) {
return min ? limits[9].first : limits[9].second;
}
assert( false && "Invalid data type in GetImGuiLimits" );
return 0;
}
template<typename PT>
const void* GetImGuiStepOne( PT p_data )
{
using T = std::remove_pointer_t<PT>;
if constexpr ( std::is_same_v<T, int8_t> ) {
return &Constants::Step::s8_one;
}
if constexpr ( std::is_same_v<T, uint8_t> ) {
return &Constants::Step::u8_one;
}
if constexpr ( std::is_same_v<T, int16_t> ) {
return &Constants::Step::s16_one;
}
if constexpr ( std::is_same_v<T, uint16_t> ) {
return &Constants::Step::u16_one;
}
if constexpr ( std::is_same_v<T, int32_t> ) {
return &Constants::Step::s32_one;
}
if constexpr ( std::is_same_v<T, uint32_t> ) {
return &Constants::Step::u32_one;
}
if constexpr ( std::is_same_v<T, float> ) {
return &Constants::Step::f_one;
}
if constexpr ( std::is_same_v<T, double> ) {
return &Constants::Step::d_one;
}
assert( false && "Invalid data type in GetImGuiStepOne" );
return NULL;
}
template<typename PT>
ImGuiDataType GetImGuiDataType( PT p_data )
{
using T = std::remove_pointer_t<PT>;
if constexpr ( std::is_same_v<T, int8_t> ) {
return ImGuiDataType_S8;
}
if constexpr ( std::is_same_v<T, uint8_t> ) {
return ImGuiDataType_U8;
}
if constexpr ( std::is_same_v<T, int16_t> ) {
return ImGuiDataType_S16;
}
if constexpr ( std::is_same_v<T, uint16_t> ) {
return ImGuiDataType_U16;
}
if constexpr ( std::is_same_v<T, int32_t> ) {
return ImGuiDataType_S32;
}
if constexpr ( std::is_same_v<T, uint32_t> ) {
return ImGuiDataType_U32;
}
if constexpr ( std::is_same_v<T, float> ) {
return ImGuiDataType_Float;
}
if constexpr ( std::is_same_v<T, double> ) {
return ImGuiDataType_Double;
}
assert( false && "Invalid data type in GetImGuiDataType" );
return ImGuiDataType_COUNT;
}
template<typename PT>
const char* GetImGuiFormatSpec( PT p_data )
{
using T = std::remove_pointer_t<PT>;
if constexpr ( std::is_same_v<T, int8_t> ) {
return "%d";
}
if constexpr ( std::is_same_v<T, uint8_t> ) {
return "%u";
}
if constexpr ( std::is_same_v<T, int16_t> ) {
return "%d";
}
if constexpr ( std::is_same_v<T, uint16_t> ) {
return "%u";
}
if constexpr ( std::is_same_v<T, int32_t> ) {
return "%d";
}
if constexpr ( std::is_same_v<T, uint32_t> ) {
return "%u";
}
if constexpr ( std::is_same_v<T, float> ) {
return "%f";
}
if constexpr ( std::is_same_v<T, double> ) {
return "%lf";
}
assert( false && "Invalid data type in GetImGuiFormatSpec" );
return "%u";
}
template<typename T>
bool InputScalar( const char* label, T* p_data, const void* p_step = NULL, ImGuiInputTextFlags flags = 0 )
{
auto eDataType = GetImGuiDataType( p_data );
return ImGui::InputScalar( label, eDataType, p_data, p_step == NULL ? (T*)GetImGuiStepOne( p_data ) : p_step, NULL, GetImGuiFormatSpec( p_data ), flags );
}
template<typename T>
bool SliderScalar( const char* label, T* p_data, const void* p_min = NULL, const void* p_max = NULL, const char* format = NULL, ImGuiSliderFlags flags = 0 )
{
auto eDataType = GetImGuiDataType( p_data );
return ImGui::SliderScalar( label, eDataType, p_data,
p_min == NULL ? GetImGuiLimits( p_data, true ) : p_min,
p_max == NULL ? GetImGuiLimits( p_data, false ) : p_max,
GetImGuiFormatSpec( p_data ), flags );
}
extern void SetPointFiltering( LPDIRECT3DDEVICE9 pD3DDevice );
extern void ResetRenderState();
extern void RenderTexture( CTexture2D* pTexture, const ImVec2& size = ImVec2( 0, 0 ), const ImVec2& uv0 = ImVec2( 0, 0 ), const ImVec2& uv1 = ImVec2( 1, 1 ), const ImVec4& tint_col = ImVec4( 1, 1, 1, 1 ), const ImVec4& border_col = ImVec4( 0, 0, 0, 0 ) );
extern bool ImageButton( CTexture2D* pTexture, const ImVec2& size = ImVec2( 0, 0 ), const ImVec2& uv0 = ImVec2( 0, 0 ), const ImVec2& uv1 = ImVec2( 1, 1 ), int frame_padding = -1, const ImVec4& bg_col = ImVec4( 0, 0, 0, 0 ), const ImVec4& tint_col = ImVec4( 1, 1, 1, 1 ) );
extern void RenderModifiablePalette( void* pPalette, size_t uMin, size_t uMax, std::unordered_set<uint8_t>* psIndicies );
};