Skip to content

Commit 226bc9f

Browse files
committed
xrEProps: ShaderFunction update
New XRay::Token wrapper for xr_token Put elements into XRay::ECore::Props namespace
1 parent a633e89 commit 226bc9f

File tree

9 files changed

+236
-21
lines changed

9 files changed

+236
-21
lines changed

src/editors/xrECore/Props/NumericVector.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace XRay
55
{
66
namespace ECore
77
{
8+
namespace Props
9+
{
810
bool NumericVector::Run(pcstr title, Fvector* data, int decimal, Fvector* resetValue, Fvector* min, Fvector* max, int* X, int* Y)
911
{
1012
System::String^ str = gcnew System::String(title);
@@ -97,6 +99,6 @@ System::Void NumericVector::OnValueChanged(System::Object^ sender, System::Event
9799
if (checkImmediate->Checked)
98100
buttonApply_Click(sender, e);
99101
}
100-
102+
} // namespace Props
101103
} // namespace ECore
102104
} // namespace XRay

src/editors/xrECore/Props/NumericVector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ namespace XRay
1616
{
1717
namespace ECore
1818
{
19+
namespace Props
20+
{
1921
using namespace System;
2022
using namespace System::ComponentModel;
2123
using namespace System::Collections;
@@ -206,5 +208,6 @@ private: System::Void NumericVector_KeyPress(System::Object^ sender, System::Win
206208

207209
private: System::Void OnValueChanged(System::Object^ sender, System::EventArgs^ e);
208210
};
211+
} // namespace Props
209212
} // namespace ECore
210213
} // namespace XRay
Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,138 @@
11
#include "pch.hpp"
22
#include "ShaderFunction.h"
33
#include "xrEngine/WaveForm.h"
4+
#include "xrCore/xr_token.h"
5+
#include "Token.h"
6+
7+
xr_token function_token[] =
8+
{
9+
{ "Constant", WaveForm::fCONSTANT },
10+
{ "Sin", WaveForm::fSIN },
11+
{ "Triangle", WaveForm::fTRIANGLE },
12+
{ "Square", WaveForm::fSQUARE },
13+
{ "Saw-Tooth", WaveForm::fSAWTOOTH },
14+
{ "Inv Saw-Tooth", WaveForm::fINVSAWTOOTH },
15+
{ nullptr, 0 }
16+
};
417

518
namespace XRay
619
{
720
namespace ECore
821
{
22+
namespace Props
23+
{
24+
ShaderFunction::ShaderFunction(void)
25+
{
26+
InitializeComponent();
27+
FillFunctionsFromToken(function_token);
28+
}
29+
930
bool ShaderFunction::Run(WaveForm* func)
1031
{
11-
return false;
32+
currentFunc = func;
33+
saveFunc = new WaveForm(*func);
34+
GetFuncData();
35+
UpdateFuncData();
36+
auto result = ShowDialog();
37+
delete saveFunc;
38+
return result == Windows::Forms::DialogResult::OK;
39+
}
40+
41+
void ShaderFunction::FillFunctionsFromToken(const xr_token* tokens)
42+
{
43+
comboFunctions->Items->Clear();
44+
for (int i = 0; tokens[i].name; i++)
45+
{
46+
comboFunctions->Items->Add(gcnew XRay::Token(tokens[i].id, tokens[i].name));
47+
}
48+
}
49+
50+
XRay::Token^ ShaderFunction::GetTokenFromValue(int val)
51+
{
52+
for each (XRay::Token^ token in comboFunctions->Items)
53+
{
54+
if (token->ToInt32() == val)
55+
return token;
56+
}
57+
58+
NODEFAULT;
59+
}
60+
61+
System::Void ShaderFunction::ShaderFunction_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
62+
{
63+
switch (e->KeyChar)
64+
{
65+
case (Char)Keys::Escape:
66+
buttonCancel_Click(sender, e);
67+
break;
68+
}
69+
}
70+
71+
System::Void ShaderFunction::buttonCancel_Click(System::Object^ sender, System::EventArgs^ e)
72+
{
73+
CopyMemory(currentFunc, saveFunc, sizeof(WaveForm));
74+
this->Close();
75+
}
76+
77+
System::Void ShaderFunction::numArgX_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
78+
{
79+
switch (e->KeyChar)
80+
{
81+
case (Char)Keys::Enter:
82+
UpdateFuncData();
83+
break;
84+
}
85+
}
86+
87+
System::Void ShaderFunction::buttonOk_Click(System::Object^ sender, System::EventArgs^ e)
88+
{
89+
UpdateFuncData();
90+
}
91+
92+
void ShaderFunction::GetFuncData()
93+
{
94+
bLoadMode = true;
95+
comboFunctions->SelectedValue = GetTokenFromValue(currentFunc->F); // XXX: may not work
96+
numArg1->Value = (Decimal)currentFunc->arg[0];
97+
numArg2->Value = (Decimal)currentFunc->arg[1];
98+
numArg3->Value = (Decimal)currentFunc->arg[2];
99+
numArg4->Value = (Decimal)currentFunc->arg[3];
100+
bLoadMode = false;
101+
}
102+
103+
void ShaderFunction::UpdateFuncData()
104+
{
105+
if (bLoadMode)
106+
return;
107+
currentFunc->F = (WaveForm::EFunction)((XRay::Token^)comboFunctions->SelectedValue)->ToInt32();
108+
currentFunc->arg[0] = (float)numArg1->Value;
109+
currentFunc->arg[1] = (float)numArg2->Value;
110+
currentFunc->arg[2] = (float)numArg3->Value;
111+
currentFunc->arg[3] = (float)numArg4->Value;
112+
113+
labelMax->Text = (currentFunc->arg[1] + currentFunc->arg[0]).ToString();
114+
labelMin->Text = (-currentFunc->arg[1] + currentFunc->arg[0]).ToString();
115+
labelCenter->Text = (currentFunc->arg[0]).ToString();
116+
117+
float v = (float)numScale->Value * 1000 / currentFunc->arg[3];
118+
string16 buf;
119+
if (v <= 1000)
120+
xr_sprintf(buf, "%4.0f ms", v);
121+
else
122+
xr_sprintf(buf, "%.2f s", v / 1000);
123+
labelEnd->Text = gcnew System::String(buf);
124+
125+
DrawGraph();
126+
}
127+
128+
void ShaderFunction::DrawGraph()
129+
{
130+
auto w = pbDraw->Width - 4;
131+
auto h = pbDraw->Height - 4;
132+
133+
// XXX: Draw
134+
//System::Windows::Controls::Canvas canvas;
12135
}
136+
} // namespace Props
13137
} // namespace ECore
14138
} // namespace XRay

src/editors/xrECore/Props/ShaderFunction.h

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ ref class ShaderFunction;
88
}
99
}
1010

11-
class WaveForm;
11+
struct WaveForm;
12+
struct xr_token;
13+
14+
namespace XRay
15+
{
16+
ref class Token;
17+
}
1218

1319
namespace XRay
1420
{
1521
namespace ECore
1622
{
23+
namespace Props
24+
{
1725
using namespace System;
1826
using namespace System::ComponentModel;
1927
using namespace System::Collections;
@@ -24,10 +32,7 @@ using namespace System::Drawing;
2432
public ref class ShaderFunction : public System::Windows::Forms::Form
2533
{
2634
public:
27-
ShaderFunction(void)
28-
{
29-
InitializeComponent();
30-
}
35+
ShaderFunction(void);
3136

3237
protected:
3338
~ShaderFunction()
@@ -38,6 +43,26 @@ public ref class ShaderFunction : public System::Windows::Forms::Form
3843
}
3944
}
4045

46+
private:
47+
bool bLoadMode;
48+
49+
WaveForm* currentFunc;
50+
WaveForm* saveFunc;
51+
52+
void GetFuncData();
53+
void UpdateFuncData();
54+
void DrawGraph();
55+
56+
public:
57+
bool Run(WaveForm* func);
58+
void FillFunctionsFromToken(const xr_token* tokens);
59+
XRay::Token^ GetTokenFromValue(int val);
60+
61+
private: System::Void ShaderFunction_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e);
62+
private: System::Void numArgX_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e);
63+
private: System::Void buttonOk_Click(System::Object^ sender, System::EventArgs^ e);
64+
private: System::Void buttonCancel_Click(System::Object^ sender, System::EventArgs^ e);
65+
4166
private: System::Windows::Forms::Label^ label1;
4267
private: System::Windows::Forms::Label^ label2;
4368
private: System::Windows::Forms::Label^ label3;
@@ -60,7 +85,7 @@ private: XRay::SdkControls::NumericSpinner^ numScale;
6085
private: System::Windows::Forms::Panel^ panelLeft;
6186
private: System::Windows::Forms::Panel^ panelRight;
6287

63-
private: System::Windows::Forms::ComboBox^ comboBox1;
88+
private: System::Windows::Forms::ComboBox^ comboFunctions;
6489
private: System::Windows::Forms::PictureBox^ pbDraw;
6590

6691
private: System::Windows::Forms::Button^ buttonOk;
@@ -83,7 +108,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
83108
this->numArg4 = (gcnew XRay::SdkControls::NumericSpinner());
84109
this->label6 = (gcnew System::Windows::Forms::Label());
85110
this->panelLeft = (gcnew System::Windows::Forms::Panel());
86-
this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
111+
this->comboFunctions = (gcnew System::Windows::Forms::ComboBox());
87112
this->panelRight = (gcnew System::Windows::Forms::Panel());
88113
this->numScale = (gcnew XRay::SdkControls::NumericSpinner());
89114
this->pbDraw = (gcnew System::Windows::Forms::PictureBox());
@@ -140,6 +165,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
140165
this->numArg1->TabIndex = 5;
141166
this->numArg1->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;
142167
this->numArg1->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 0, 0, 0, 0 });
168+
this->numArg1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &ShaderFunction::numArgX_KeyPress);
143169
this->numArg2->DecimalPlaces = 5;
144170
this->numArg2->Hexadecimal = false;
145171
this->numArg2->Location = System::Drawing::Point(89, 57);
@@ -152,6 +178,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
152178
this->numArg2->TabIndex = 6;
153179
this->numArg2->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;
154180
this->numArg2->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 0, 0, 0, 0 });
181+
this->numArg2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &ShaderFunction::numArgX_KeyPress);
155182
this->numArg3->DecimalPlaces = 5;
156183
this->numArg3->Hexadecimal = false;
157184
this->numArg3->Location = System::Drawing::Point(89, 84);
@@ -164,6 +191,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
164191
this->numArg3->TabIndex = 7;
165192
this->numArg3->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;
166193
this->numArg3->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 0, 0, 0, 0 });
194+
this->numArg3->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &ShaderFunction::numArgX_KeyPress);
167195
this->numArg4->DecimalPlaces = 5;
168196
this->numArg4->Hexadecimal = false;
169197
this->numArg4->Location = System::Drawing::Point(89, 111);
@@ -176,13 +204,14 @@ private: System::Windows::Forms::Button^ buttonCancel;
176204
this->numArg4->TabIndex = 8;
177205
this->numArg4->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;
178206
this->numArg4->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 0, 0, 0, 0 });
207+
this->numArg4->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &ShaderFunction::numArgX_KeyPress);
179208
this->label6->AutoSize = true;
180209
this->label6->Location = System::Drawing::Point(44, 5);
181210
this->label6->Name = L"label6";
182211
this->label6->Size = System::Drawing::Size(192, 13);
183212
this->label6->TabIndex = 10;
184213
this->label6->Text = L"y = arg1 + arg2*func((time + arg3)*arg4)";
185-
this->panelLeft->Controls->Add(this->comboBox1);
214+
this->panelLeft->Controls->Add(this->comboFunctions);
186215
this->panelLeft->Controls->Add(this->label1);
187216
this->panelLeft->Controls->Add(this->label2);
188217
this->panelLeft->Controls->Add(this->numArg4);
@@ -196,11 +225,11 @@ private: System::Windows::Forms::Button^ buttonCancel;
196225
this->panelLeft->Name = L"panelLeft";
197226
this->panelLeft->Size = System::Drawing::Size(205, 140);
198227
this->panelLeft->TabIndex = 11;
199-
this->comboBox1->FormattingEnabled = true;
200-
this->comboBox1->Location = System::Drawing::Point(89, 1);
201-
this->comboBox1->Name = L"comboBox1";
202-
this->comboBox1->Size = System::Drawing::Size(115, 21);
203-
this->comboBox1->TabIndex = 9;
228+
this->comboFunctions->FormattingEnabled = true;
229+
this->comboFunctions->Location = System::Drawing::Point(89, 1);
230+
this->comboFunctions->Name = L"comboFunctions";
231+
this->comboFunctions->Size = System::Drawing::Size(115, 21);
232+
this->comboFunctions->TabIndex = 9;
204233
this->panelRight->Controls->Add(this->numScale);
205234
this->panelRight->Controls->Add(this->pbDraw);
206235
this->panelRight->Controls->Add(this->labelEnd);
@@ -270,12 +299,14 @@ private: System::Windows::Forms::Button^ buttonCancel;
270299
this->buttonOk->TabIndex = 14;
271300
this->buttonOk->Text = L"Ok";
272301
this->buttonOk->UseVisualStyleBackColor = true;
302+
this->buttonOk->Click += gcnew System::EventHandler(this, &ShaderFunction::buttonOk_Click);
273303
this->buttonCancel->Location = System::Drawing::Point(88, 140);
274304
this->buttonCancel->Name = L"buttonCancel";
275305
this->buttonCancel->Size = System::Drawing::Size(116, 22);
276306
this->buttonCancel->TabIndex = 13;
277307
this->buttonCancel->Text = L"Cancel";
278308
this->buttonCancel->UseVisualStyleBackColor = true;
309+
this->buttonCancel->Click += gcnew System::EventHandler(this, &ShaderFunction::buttonCancel_Click);
279310
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
280311
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
281312
this->ClientSize = System::Drawing::Size(441, 162);
@@ -295,8 +326,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
295326

296327
}
297328
#pragma endregion
298-
299-
public: bool Run(WaveForm* func);
300329
};
330+
} // namespace Props
301331
} // namespace ECore
302332
} // namespace XRay

src/editors/xrECore/Token.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
namespace XRay
4+
{
5+
public ref class Token sealed
6+
{
7+
System::String^ name;
8+
int id;
9+
10+
public:
11+
Token() : id(-1), name(nullptr) {}
12+
Token(int _id, pcstr _name) : id(_id), name(gcnew System::String(_name)) {}
13+
Token(int _id, System::String^ _name) : id(_id), name(_name) {}
14+
15+
System::String^ ToString() override { return name; }
16+
System::Int32 ToInt32() { return (System::Int32)id; }
17+
System::Int64 ToInt64() { return (System::Int64)id; }
18+
};
19+
} // namespace XRay

src/editors/xrECore/xrECore.vcxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,13 @@
9898
<ClInclude Include="Props\ShaderFunction.h">
9999
<FileType>CppForm</FileType>
100100
</ClInclude>
101+
<ClInclude Include="Token.h" />
101102
<ClInclude Include="xrEProps.h" />
102103
</ItemGroup>
103104
<ItemGroup>
105+
<ProjectReference Include="..\..\xrCore\xrCore.vcxproj">
106+
<Project>{a0f7d1fb-59a7-4717-a7e4-96f37e91998e}</Project>
107+
</ProjectReference>
104108
<ProjectReference Include="..\xrSdkControls\xrSdkControls.csproj">
105109
<Project>{e9dc16a3-d0fa-4924-af6e-f6fdf3ea0661}</Project>
106110
</ProjectReference>

src/editors/xrECore/xrECore.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<Filter Include="Props\ShaderFunction">
1111
<UniqueIdentifier>{56d7edeb-5e87-435e-b603-082c4d95413f}</UniqueIdentifier>
1212
</Filter>
13+
<Filter Include="Core">
14+
<UniqueIdentifier>{5ef41f0f-a8ef-4194-ae46-068b92e5bbd3}</UniqueIdentifier>
15+
</Filter>
1316
</ItemGroup>
1417
<ItemGroup>
1518
<ClCompile Include="pch.cpp" />
@@ -34,6 +37,9 @@
3437
<ClInclude Include="Props\ShaderFunction.h">
3538
<Filter>Props\ShaderFunction</Filter>
3639
</ClInclude>
40+
<ClInclude Include="Token.h">
41+
<Filter>Core</Filter>
42+
</ClInclude>
3743
</ItemGroup>
3844
<ItemGroup>
3945
<EmbeddedResource Include="Props\NumericVector.resx" />

0 commit comments

Comments
 (0)