forked from CedricGuillemet/Imogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.h
188 lines (169 loc) · 4.59 KB
/
UI.h
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
// https://github.com/CedricGuillemet/Imogen
//
// The MIT License(MIT)
//
// Copyright(c) 2019 Cedric Guillemet
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// 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.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#pragma once
#include "ImCurveEdit.h"
#include "ImGradient.h"
#include "imgui_markdown/imgui_markdown.h"
#include <algorithm>
void SetStyle();
void InitFonts();
struct ImguiAppLog
{
ImguiAppLog()
{
Log = this;
}
static ImguiAppLog* Log;
ImGuiTextBuffer Buf;
ImGuiTextFilter Filter;
ImVector<int> LineOffsets; // Index to lines offset
bool ScrollToBottom;
void Clear()
{
Buf.clear();
LineOffsets.clear();
}
void AddLog(const char* fmt, ...);
void DrawEmbedded();
};
void ImConsoleOutput(const char* szText);
struct RampEdit : public ImCurveEdit::Delegate
{
RampEdit()
{
mMin = ImVec2(0.f, 0.f);
mMax = ImVec2(1.f, 1.f);
}
size_t GetCurveCount()
{
return 1;
}
size_t GetPointCount(size_t curveIndex)
{
return mPointCount;
}
uint32_t GetCurveColor(size_t curveIndex)
{
return 0xFFAAAAAA;
}
ImVec2* GetPoints(size_t curveIndex)
{
return mPts;
}
virtual ImVec2& GetMin()
{
return mMin;
}
virtual ImVec2& GetMax()
{
return mMax;
}
virtual int EditPoint(size_t curveIndex, int pointIndex, ImVec2 value)
{
mPts[pointIndex] = value;
SortValues(curveIndex);
for (size_t i = 0; i < GetPointCount(curveIndex); i++)
{
if (mPts[i].x == value.x)
return int(i);
}
return pointIndex;
}
virtual void AddPoint(size_t curveIndex, ImVec2 value)
{
if (mPointCount >= 8)
return;
mPts[mPointCount++] = value;
SortValues(curveIndex);
}
virtual void DelPoint(size_t curveIndex, size_t pointIndex)
{
mPts[pointIndex].x = FLT_MAX;
SortValues(curveIndex);
mPointCount--;
mPts[mPointCount].x = -1.f; // end marker
}
ImVec2 mPts[8];
size_t mPointCount;
private:
void SortValues(size_t curveIndex)
{
auto b = std::begin(mPts);
auto e = std::begin(mPts) + GetPointCount(curveIndex);
std::sort(b, e, [](ImVec2 a, ImVec2 b) { return a.x < b.x; });
}
ImVec2 mMin, mMax;
};
struct GradientEdit : public ImGradient::Delegate
{
GradientEdit()
{
mPointCount = 0;
}
size_t GetPointCount()
{
return mPointCount;
}
ImVec4* GetPoints()
{
return mPts;
}
virtual int EditPoint(int pointIndex, ImVec4 value)
{
mPts[pointIndex] = value;
SortValues();
for (size_t i = 0; i < GetPointCount(); i++)
{
if (mPts[i].w == value.w)
return int(i);
}
return pointIndex;
}
virtual void AddPoint(ImVec4 value)
{
if (mPointCount >= 8)
return;
mPts[mPointCount++] = value;
SortValues();
}
virtual ImVec4 GetPoint(float t);
ImVec4 mPts[8];
size_t mPointCount;
private:
void SortValues()
{
auto b = std::begin(mPts);
auto e = std::begin(mPts) + GetPointCount();
std::sort(b, e, [](ImVec4 a, ImVec4 b) { return a.w < b.w; });
}
};
// draw callbacks
struct ImRect;
struct ImDrawList;
struct EvaluationContext;
typedef void (*NodeUICallBackFunc)(EvaluationContext* context, size_t nodeIndex);
void AddUICustomDraw(
ImDrawList* drawList, const ImRect& rc, NodeUICallBackFunc func, size_t nodeIndex, EvaluationContext* context);
void InitCallbackRects();