Skip to content

Commit

Permalink
xrEProps: ShaderFunction update
Browse files Browse the repository at this point in the history
New XRay::Token wrapper for xr_token
Put elements into XRay::ECore::Props namespace
  • Loading branch information
Xottab-DUTY committed Feb 25, 2018
1 parent a633e89 commit 226bc9f
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/editors/xrECore/Props/NumericVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace XRay
{
namespace ECore
{
namespace Props
{
bool NumericVector::Run(pcstr title, Fvector* data, int decimal, Fvector* resetValue, Fvector* min, Fvector* max, int* X, int* Y)
{
System::String^ str = gcnew System::String(title);
Expand Down Expand Up @@ -97,6 +99,6 @@ System::Void NumericVector::OnValueChanged(System::Object^ sender, System::Event
if (checkImmediate->Checked)
buttonApply_Click(sender, e);
}

} // namespace Props
} // namespace ECore
} // namespace XRay
3 changes: 3 additions & 0 deletions src/editors/xrECore/Props/NumericVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace XRay
{
namespace ECore
{
namespace Props
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
Expand Down Expand Up @@ -206,5 +208,6 @@ private: System::Void NumericVector_KeyPress(System::Object^ sender, System::Win

private: System::Void OnValueChanged(System::Object^ sender, System::EventArgs^ e);
};
} // namespace Props
} // namespace ECore
} // namespace XRay
126 changes: 125 additions & 1 deletion src/editors/xrECore/Props/ShaderFunction.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,138 @@
#include "pch.hpp"
#include "ShaderFunction.h"
#include "xrEngine/WaveForm.h"
#include "xrCore/xr_token.h"
#include "Token.h"

xr_token function_token[] =
{
{ "Constant", WaveForm::fCONSTANT },
{ "Sin", WaveForm::fSIN },
{ "Triangle", WaveForm::fTRIANGLE },
{ "Square", WaveForm::fSQUARE },
{ "Saw-Tooth", WaveForm::fSAWTOOTH },
{ "Inv Saw-Tooth", WaveForm::fINVSAWTOOTH },
{ nullptr, 0 }
};

namespace XRay
{
namespace ECore
{
namespace Props
{
ShaderFunction::ShaderFunction(void)
{
InitializeComponent();
FillFunctionsFromToken(function_token);
}

bool ShaderFunction::Run(WaveForm* func)
{
return false;
currentFunc = func;
saveFunc = new WaveForm(*func);
GetFuncData();
UpdateFuncData();
auto result = ShowDialog();
delete saveFunc;
return result == Windows::Forms::DialogResult::OK;
}

void ShaderFunction::FillFunctionsFromToken(const xr_token* tokens)
{
comboFunctions->Items->Clear();
for (int i = 0; tokens[i].name; i++)
{
comboFunctions->Items->Add(gcnew XRay::Token(tokens[i].id, tokens[i].name));
}
}

XRay::Token^ ShaderFunction::GetTokenFromValue(int val)
{
for each (XRay::Token^ token in comboFunctions->Items)
{
if (token->ToInt32() == val)
return token;
}

NODEFAULT;
}

System::Void ShaderFunction::ShaderFunction_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
{
switch (e->KeyChar)
{
case (Char)Keys::Escape:
buttonCancel_Click(sender, e);
break;
}
}

System::Void ShaderFunction::buttonCancel_Click(System::Object^ sender, System::EventArgs^ e)
{
CopyMemory(currentFunc, saveFunc, sizeof(WaveForm));
this->Close();
}

System::Void ShaderFunction::numArgX_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e)
{
switch (e->KeyChar)
{
case (Char)Keys::Enter:
UpdateFuncData();
break;
}
}

System::Void ShaderFunction::buttonOk_Click(System::Object^ sender, System::EventArgs^ e)
{
UpdateFuncData();
}

void ShaderFunction::GetFuncData()
{
bLoadMode = true;
comboFunctions->SelectedValue = GetTokenFromValue(currentFunc->F); // XXX: may not work
numArg1->Value = (Decimal)currentFunc->arg[0];
numArg2->Value = (Decimal)currentFunc->arg[1];
numArg3->Value = (Decimal)currentFunc->arg[2];
numArg4->Value = (Decimal)currentFunc->arg[3];
bLoadMode = false;
}

void ShaderFunction::UpdateFuncData()
{
if (bLoadMode)
return;
currentFunc->F = (WaveForm::EFunction)((XRay::Token^)comboFunctions->SelectedValue)->ToInt32();
currentFunc->arg[0] = (float)numArg1->Value;
currentFunc->arg[1] = (float)numArg2->Value;
currentFunc->arg[2] = (float)numArg3->Value;
currentFunc->arg[3] = (float)numArg4->Value;

labelMax->Text = (currentFunc->arg[1] + currentFunc->arg[0]).ToString();
labelMin->Text = (-currentFunc->arg[1] + currentFunc->arg[0]).ToString();
labelCenter->Text = (currentFunc->arg[0]).ToString();

float v = (float)numScale->Value * 1000 / currentFunc->arg[3];
string16 buf;
if (v <= 1000)
xr_sprintf(buf, "%4.0f ms", v);
else
xr_sprintf(buf, "%.2f s", v / 1000);
labelEnd->Text = gcnew System::String(buf);

DrawGraph();
}

void ShaderFunction::DrawGraph()
{
auto w = pbDraw->Width - 4;
auto h = pbDraw->Height - 4;

// XXX: Draw
//System::Windows::Controls::Canvas canvas;
}
} // namespace Props
} // namespace ECore
} // namespace XRay
60 changes: 45 additions & 15 deletions src/editors/xrECore/Props/ShaderFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ ref class ShaderFunction;
}
}

class WaveForm;
struct WaveForm;
struct xr_token;

namespace XRay
{
ref class Token;
}

namespace XRay
{
namespace ECore
{
namespace Props
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
Expand All @@ -24,10 +32,7 @@ using namespace System::Drawing;
public ref class ShaderFunction : public System::Windows::Forms::Form
{
public:
ShaderFunction(void)
{
InitializeComponent();
}
ShaderFunction(void);

protected:
~ShaderFunction()
Expand All @@ -38,6 +43,26 @@ public ref class ShaderFunction : public System::Windows::Forms::Form
}
}

private:
bool bLoadMode;

WaveForm* currentFunc;
WaveForm* saveFunc;

void GetFuncData();
void UpdateFuncData();
void DrawGraph();

public:
bool Run(WaveForm* func);
void FillFunctionsFromToken(const xr_token* tokens);
XRay::Token^ GetTokenFromValue(int val);

private: System::Void ShaderFunction_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e);
private: System::Void numArgX_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e);
private: System::Void buttonOk_Click(System::Object^ sender, System::EventArgs^ e);
private: System::Void buttonCancel_Click(System::Object^ sender, System::EventArgs^ e);

private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
Expand All @@ -60,7 +85,7 @@ private: XRay::SdkControls::NumericSpinner^ numScale;
private: System::Windows::Forms::Panel^ panelLeft;
private: System::Windows::Forms::Panel^ panelRight;

private: System::Windows::Forms::ComboBox^ comboBox1;
private: System::Windows::Forms::ComboBox^ comboFunctions;
private: System::Windows::Forms::PictureBox^ pbDraw;

private: System::Windows::Forms::Button^ buttonOk;
Expand All @@ -83,7 +108,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
this->numArg4 = (gcnew XRay::SdkControls::NumericSpinner());
this->label6 = (gcnew System::Windows::Forms::Label());
this->panelLeft = (gcnew System::Windows::Forms::Panel());
this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
this->comboFunctions = (gcnew System::Windows::Forms::ComboBox());
this->panelRight = (gcnew System::Windows::Forms::Panel());
this->numScale = (gcnew XRay::SdkControls::NumericSpinner());
this->pbDraw = (gcnew System::Windows::Forms::PictureBox());
Expand Down Expand Up @@ -140,6 +165,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
this->numArg1->TabIndex = 5;
this->numArg1->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;
this->numArg1->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 0, 0, 0, 0 });
this->numArg1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &ShaderFunction::numArgX_KeyPress);
this->numArg2->DecimalPlaces = 5;
this->numArg2->Hexadecimal = false;
this->numArg2->Location = System::Drawing::Point(89, 57);
Expand All @@ -152,6 +178,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
this->numArg2->TabIndex = 6;
this->numArg2->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;
this->numArg2->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 0, 0, 0, 0 });
this->numArg2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &ShaderFunction::numArgX_KeyPress);
this->numArg3->DecimalPlaces = 5;
this->numArg3->Hexadecimal = false;
this->numArg3->Location = System::Drawing::Point(89, 84);
Expand All @@ -164,6 +191,7 @@ private: System::Windows::Forms::Button^ buttonCancel;
this->numArg3->TabIndex = 7;
this->numArg3->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;
this->numArg3->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 0, 0, 0, 0 });
this->numArg3->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &ShaderFunction::numArgX_KeyPress);
this->numArg4->DecimalPlaces = 5;
this->numArg4->Hexadecimal = false;
this->numArg4->Location = System::Drawing::Point(89, 111);
Expand All @@ -176,13 +204,14 @@ private: System::Windows::Forms::Button^ buttonCancel;
this->numArg4->TabIndex = 8;
this->numArg4->TextAlign = System::Windows::Forms::HorizontalAlignment::Left;
this->numArg4->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 0, 0, 0, 0 });
this->numArg4->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &ShaderFunction::numArgX_KeyPress);
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(44, 5);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(192, 13);
this->label6->TabIndex = 10;
this->label6->Text = L"y = arg1 + arg2*func((time + arg3)*arg4)";
this->panelLeft->Controls->Add(this->comboBox1);
this->panelLeft->Controls->Add(this->comboFunctions);
this->panelLeft->Controls->Add(this->label1);
this->panelLeft->Controls->Add(this->label2);
this->panelLeft->Controls->Add(this->numArg4);
Expand All @@ -196,11 +225,11 @@ private: System::Windows::Forms::Button^ buttonCancel;
this->panelLeft->Name = L"panelLeft";
this->panelLeft->Size = System::Drawing::Size(205, 140);
this->panelLeft->TabIndex = 11;
this->comboBox1->FormattingEnabled = true;
this->comboBox1->Location = System::Drawing::Point(89, 1);
this->comboBox1->Name = L"comboBox1";
this->comboBox1->Size = System::Drawing::Size(115, 21);
this->comboBox1->TabIndex = 9;
this->comboFunctions->FormattingEnabled = true;
this->comboFunctions->Location = System::Drawing::Point(89, 1);
this->comboFunctions->Name = L"comboFunctions";
this->comboFunctions->Size = System::Drawing::Size(115, 21);
this->comboFunctions->TabIndex = 9;
this->panelRight->Controls->Add(this->numScale);
this->panelRight->Controls->Add(this->pbDraw);
this->panelRight->Controls->Add(this->labelEnd);
Expand Down Expand Up @@ -270,12 +299,14 @@ private: System::Windows::Forms::Button^ buttonCancel;
this->buttonOk->TabIndex = 14;
this->buttonOk->Text = L"Ok";
this->buttonOk->UseVisualStyleBackColor = true;
this->buttonOk->Click += gcnew System::EventHandler(this, &ShaderFunction::buttonOk_Click);
this->buttonCancel->Location = System::Drawing::Point(88, 140);
this->buttonCancel->Name = L"buttonCancel";
this->buttonCancel->Size = System::Drawing::Size(116, 22);
this->buttonCancel->TabIndex = 13;
this->buttonCancel->Text = L"Cancel";
this->buttonCancel->UseVisualStyleBackColor = true;
this->buttonCancel->Click += gcnew System::EventHandler(this, &ShaderFunction::buttonCancel_Click);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(441, 162);
Expand All @@ -295,8 +326,7 @@ private: System::Windows::Forms::Button^ buttonCancel;

}
#pragma endregion

public: bool Run(WaveForm* func);
};
} // namespace Props
} // namespace ECore
} // namespace XRay
19 changes: 19 additions & 0 deletions src/editors/xrECore/Token.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

namespace XRay
{
public ref class Token sealed
{
System::String^ name;
int id;

public:
Token() : id(-1), name(nullptr) {}
Token(int _id, pcstr _name) : id(_id), name(gcnew System::String(_name)) {}
Token(int _id, System::String^ _name) : id(_id), name(_name) {}

System::String^ ToString() override { return name; }
System::Int32 ToInt32() { return (System::Int32)id; }
System::Int64 ToInt64() { return (System::Int64)id; }
};
} // namespace XRay
4 changes: 4 additions & 0 deletions src/editors/xrECore/xrECore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@
<ClInclude Include="Props\ShaderFunction.h">
<FileType>CppForm</FileType>
</ClInclude>
<ClInclude Include="Token.h" />
<ClInclude Include="xrEProps.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\xrCore\xrCore.vcxproj">
<Project>{a0f7d1fb-59a7-4717-a7e4-96f37e91998e}</Project>
</ProjectReference>
<ProjectReference Include="..\xrSdkControls\xrSdkControls.csproj">
<Project>{e9dc16a3-d0fa-4924-af6e-f6fdf3ea0661}</Project>
</ProjectReference>
Expand Down
6 changes: 6 additions & 0 deletions src/editors/xrECore/xrECore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<Filter Include="Props\ShaderFunction">
<UniqueIdentifier>{56d7edeb-5e87-435e-b603-082c4d95413f}</UniqueIdentifier>
</Filter>
<Filter Include="Core">
<UniqueIdentifier>{5ef41f0f-a8ef-4194-ae46-068b92e5bbd3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand All @@ -34,6 +37,9 @@
<ClInclude Include="Props\ShaderFunction.h">
<Filter>Props\ShaderFunction</Filter>
</ClInclude>
<ClInclude Include="Token.h">
<Filter>Core</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Props\NumericVector.resx" />
Expand Down
Loading

0 comments on commit 226bc9f

Please sign in to comment.