From 226bc9fdb8411e8a5f09b7a1cf9a3a2d6e84a14c Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Mon, 26 Feb 2018 00:43:43 +0500 Subject: [PATCH] xrEProps: ShaderFunction update New XRay::Token wrapper for xr_token Put elements into XRay::ECore::Props namespace --- src/editors/xrECore/Props/NumericVector.cpp | 4 +- src/editors/xrECore/Props/NumericVector.h | 3 + src/editors/xrECore/Props/ShaderFunction.cpp | 126 ++++++++++++++++++- src/editors/xrECore/Props/ShaderFunction.h | 60 ++++++--- src/editors/xrECore/Token.h | 19 +++ src/editors/xrECore/xrECore.vcxproj | 4 + src/editors/xrECore/xrECore.vcxproj.filters | 6 + src/editors/xrECore/xrEProps.cpp | 23 +++- src/editors/xrECore/xrEProps.h | 12 ++ 9 files changed, 236 insertions(+), 21 deletions(-) create mode 100644 src/editors/xrECore/Token.h diff --git a/src/editors/xrECore/Props/NumericVector.cpp b/src/editors/xrECore/Props/NumericVector.cpp index 4b907e966aa..286333204f2 100644 --- a/src/editors/xrECore/Props/NumericVector.cpp +++ b/src/editors/xrECore/Props/NumericVector.cpp @@ -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); @@ -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 diff --git a/src/editors/xrECore/Props/NumericVector.h b/src/editors/xrECore/Props/NumericVector.h index b695f62a7a6..c58e79d953a 100644 --- a/src/editors/xrECore/Props/NumericVector.h +++ b/src/editors/xrECore/Props/NumericVector.h @@ -16,6 +16,8 @@ namespace XRay { namespace ECore { +namespace Props +{ using namespace System; using namespace System::ComponentModel; using namespace System::Collections; @@ -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 diff --git a/src/editors/xrECore/Props/ShaderFunction.cpp b/src/editors/xrECore/Props/ShaderFunction.cpp index 0cf3313797a..2d377f3ce4b 100644 --- a/src/editors/xrECore/Props/ShaderFunction.cpp +++ b/src/editors/xrECore/Props/ShaderFunction.cpp @@ -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 diff --git a/src/editors/xrECore/Props/ShaderFunction.h b/src/editors/xrECore/Props/ShaderFunction.h index e9138b1d047..8aa6ba0dee7 100644 --- a/src/editors/xrECore/Props/ShaderFunction.h +++ b/src/editors/xrECore/Props/ShaderFunction.h @@ -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; @@ -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() @@ -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; @@ -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; @@ -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()); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -295,8 +326,7 @@ private: System::Windows::Forms::Button^ buttonCancel; } #pragma endregion - -public: bool Run(WaveForm* func); }; +} // namespace Props } // namespace ECore } // namespace XRay diff --git a/src/editors/xrECore/Token.h b/src/editors/xrECore/Token.h new file mode 100644 index 00000000000..84137585561 --- /dev/null +++ b/src/editors/xrECore/Token.h @@ -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 diff --git a/src/editors/xrECore/xrECore.vcxproj b/src/editors/xrECore/xrECore.vcxproj index 5f134c3ea59..471b8dfa27f 100644 --- a/src/editors/xrECore/xrECore.vcxproj +++ b/src/editors/xrECore/xrECore.vcxproj @@ -98,9 +98,13 @@ CppForm + + + {a0f7d1fb-59a7-4717-a7e4-96f37e91998e} + {e9dc16a3-d0fa-4924-af6e-f6fdf3ea0661} diff --git a/src/editors/xrECore/xrECore.vcxproj.filters b/src/editors/xrECore/xrECore.vcxproj.filters index b521320995a..08f19213e22 100644 --- a/src/editors/xrECore/xrECore.vcxproj.filters +++ b/src/editors/xrECore/xrECore.vcxproj.filters @@ -10,6 +10,9 @@ {56d7edeb-5e87-435e-b603-082c4d95413f} + + {5ef41f0f-a8ef-4194-ae46-068b92e5bbd3} + @@ -34,6 +37,9 @@ Props\ShaderFunction + + Core + diff --git a/src/editors/xrECore/xrEProps.cpp b/src/editors/xrECore/xrEProps.cpp index 72a00888dae..6f861b58066 100644 --- a/src/editors/xrECore/xrEProps.cpp +++ b/src/editors/xrECore/xrEProps.cpp @@ -1,11 +1,26 @@ #include "pch.hpp" #include "xrEProps.h" #include "Props/NumericVector.h" +#include "Props/ShaderFunction.h" +#include "xrEngine/WaveForm.h" -using namespace XRay::ECore; - +namespace XRay +{ +namespace ECore +{ +namespace Props +{ bool NumericVectorRun(pcstr title, Fvector* data, int decimal, Fvector* reset_value, Fvector* min, Fvector* max, int* X, int* Y) { - auto frm = gcnew NumericVector(); - return frm->Run(title, data, decimal, reset_value, min, max, X, Y); + auto form = gcnew NumericVector(); + return form->Run(title, data, decimal, reset_value, min, max, X, Y); +} + +bool ShaderFunctionRun(WaveForm* func) +{ + auto form = gcnew ShaderFunction(); + return form->Run(func); } +} // namespace Props +} // namespace ECore +} // namespace XRay diff --git a/src/editors/xrECore/xrEProps.h b/src/editors/xrECore/xrEProps.h index 40a49e3cb10..a293ca5754a 100644 --- a/src/editors/xrECore/xrEProps.h +++ b/src/editors/xrECore/xrEProps.h @@ -1,3 +1,15 @@ #pragma once +struct WaveForm; + +namespace XRay +{ +namespace ECore +{ +namespace Props +{ bool NumericVectorRun(pcstr title, Fvector* data, int decimal, Fvector* reset_value, Fvector* min, Fvector* max, int* X, int* Y); +bool ShaderFunctionRun(WaveForm* func); +} // namespace Props +} // namespace ECore +} // namespace XRay