Skip to content

Commit

Permalink
xrEProps: TextEdit update (WIP)
Browse files Browse the repository at this point in the history
Broken, but compilation is fixed now
  • Loading branch information
Xottab-DUTY committed Feb 28, 2018
1 parent 5c028f8 commit 816b080
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 58 deletions.
44 changes: 40 additions & 4 deletions src/editors/xrECore/Props/TextEdit.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
#include "pch.hpp"

#include <msclr/marshal.h>

#include "TextEdit.h"

System::Void XRay::ECore::Props::TextEdit::buttonClear_Click(System::Object^ sender, System::EventArgs^ e)
namespace XRay
{
namespace ECore
{
namespace Props
{
System::Void TextEdit::buttonClear_Click(System::Object^ sender, System::EventArgs^ e)
{
textBox1->Clear();
}

System::Void XRay::ECore::Props::TextEdit::buttonOk_Click(System::Object^ sender, System::EventArgs^ e)
System::Void TextEdit::textBox1_SelectionChanged(System::Object^ sender, System::EventArgs^ e)
{
auto line = textBox1->GetLineFromCharIndex(textBox1->SelectionStart);
auto currline = textBox1->GetFirstCharIndexOfCurrentLine();
auto charpos = textBox1->SelectionStart - currline;
toolStripStatusLabel1->Text = (line + 1) + " : " + (charpos + 1);
}

bool TextEdit::Run(xr_string& text, pcstr caption, bool read_only, int lim,
pcstr apply_name, TOnApplyClick^ on_apply, TOnCloseClick^ on_close,
TOnCodeInsight^ on_insight)
{
Text = gcnew String(caption);
m_text = &text;
textBox1->ReadOnly = read_only;
textBox1->Text = gcnew String(text.c_str());
textBox1->MaxLength = lim;

buttonApply->Text = gcnew String(apply_name);
//buttonApply->Click += gcnew EventHandler(on_apply);

return ShowDialog() == Windows::Forms::DialogResult::OK;
}

System::Void TextEdit::buttonOk_Click(System::Object^ sender, System::EventArgs^ e)
{
//marshal this
//*m_text = textBox1->Text;
msclr::interop::marshal_context ctx;
*m_text = ctx.marshal_as<pcstr>(textBox1->Text);
}
} // namespace Props
} // namespace ECore
} // namespace XRay
69 changes: 18 additions & 51 deletions src/editors/xrECore/Props/TextEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ public ref class TextEdit : public System::Windows::Forms::Form
}
}

public:
bool Run();

private:
xr_string* m_text;
delegate void TOnApplyClick(pcstr, bool);
delegate void TOnCloseClick(bool);
delegate void TOnCodeInsight(const xr_string&, xr_string&, bool&);

public:
bool Run(xr_string& text, pcstr caption, bool read_only, int lim,
pcstr apply_name, TOnApplyClick^ on_apply, TOnCloseClick^ on_close,
TOnCodeInsight^ on_insight);


private: System::Void buttonOk_Click(System::Object^ sender, System::EventArgs^ e);
private: System::Void buttonClear_Click(System::Object^ sender, System::EventArgs^ e);
private: System::Void textBox1_SelectionChanged(System::Object^ sender, System::EventArgs^ e);

private: System::Windows::Forms::Button^ buttonOk;
private: System::Windows::Forms::Button^ buttonCancel;
Expand All @@ -47,7 +54,7 @@ private: System::Windows::Forms::Button^ buttonSave;
private: System::Windows::Forms::Button^ buttonClear;

private: System::Windows::Forms::Panel^ panel1;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::RichTextBox^ textBox1;

private: System::Windows::Forms::StatusStrip^ statusStrip1;
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel1;
Expand All @@ -61,7 +68,7 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox1 = (gcnew System::Windows::Forms::RichTextBox());
this->buttonOk = (gcnew System::Windows::Forms::Button());
this->buttonCancel = (gcnew System::Windows::Forms::Button());
this->buttonApply = (gcnew System::Windows::Forms::Button());
Expand All @@ -76,23 +83,16 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->panel1->SuspendLayout();
this->statusStrip1->SuspendLayout();
this->SuspendLayout();
//
// textBox1
//
this->textBox1->AcceptsReturn = true;
this->textBox1->AcceptsTab = true;
this->textBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
| System::Windows::Forms::AnchorStyles::Left)
| System::Windows::Forms::AnchorStyles::Right));
this->textBox1->Location = System::Drawing::Point(0, 25);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Both;
this->textBox1->Size = System::Drawing::Size(445, 217);
this->textBox1->TabIndex = 0;
//
// buttonOk
//
this->textBox1->Text = L"";
this->textBox1->SelectionChanged += gcnew System::EventHandler(this, &TextEdit::textBox1_SelectionChanged);
this->buttonOk->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonOk->AutoSizeMode = System::Windows::Forms::AutoSizeMode::GrowAndShrink;
this->buttonOk->DialogResult = System::Windows::Forms::DialogResult::OK;
Expand All @@ -103,9 +103,6 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->buttonOk->Text = L"Ok";
this->buttonOk->UseVisualStyleBackColor = true;
this->buttonOk->Click += gcnew System::EventHandler(this, &TextEdit::buttonOk_Click);
//
// buttonCancel
//
this->buttonCancel->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonCancel->DialogResult = System::Windows::Forms::DialogResult::Cancel;
this->buttonCancel->Location = System::Drawing::Point(74, 0);
Expand All @@ -114,39 +111,27 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->buttonCancel->TabIndex = 2;
this->buttonCancel->Text = L"Cancel";
this->buttonCancel->UseVisualStyleBackColor = true;
//
// buttonApply
//
this->buttonApply->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonApply->Location = System::Drawing::Point(148, 0);
this->buttonApply->Name = L"buttonApply";
this->buttonApply->Size = System::Drawing::Size(75, 23);
this->buttonApply->TabIndex = 3;
this->buttonApply->Text = L"Apply";
this->buttonApply->UseVisualStyleBackColor = true;
//
// buttonLoad
//
this->buttonLoad->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonLoad->Location = System::Drawing::Point(222, 0);
this->buttonLoad->Name = L"buttonLoad";
this->buttonLoad->Size = System::Drawing::Size(75, 23);
this->buttonLoad->TabIndex = 4;
this->buttonLoad->Text = L"Load";
this->buttonLoad->UseVisualStyleBackColor = true;
//
// buttonSave
//
this->buttonSave->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonSave->Location = System::Drawing::Point(296, 0);
this->buttonSave->Name = L"buttonSave";
this->buttonSave->Size = System::Drawing::Size(75, 23);
this->buttonSave->TabIndex = 5;
this->buttonSave->Text = L"Save";
this->buttonSave->UseVisualStyleBackColor = true;
//
// buttonClear
//
this->buttonClear->Anchor = System::Windows::Forms::AnchorStyles::Top;
this->buttonClear->Location = System::Drawing::Point(370, 0);
this->buttonClear->Name = L"buttonClear";
Expand All @@ -155,9 +140,6 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->buttonClear->Text = L"Clear";
this->buttonClear->UseVisualStyleBackColor = true;
this->buttonClear->Click += gcnew System::EventHandler(this, &TextEdit::buttonClear_Click);
//
// panel1
//
this->panel1->Controls->Add(this->buttonOk);
this->panel1->Controls->Add(this->buttonClear);
this->panel1->Controls->Add(this->buttonCancel);
Expand All @@ -169,9 +151,6 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(445, 24);
this->panel1->TabIndex = 7;
//
// statusStrip1
//
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
this->toolStripStatusLabel1,
this->toolStripStatusLabel2, this->toolStripStatusLabel3
Expand All @@ -181,30 +160,18 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->statusStrip1->Size = System::Drawing::Size(445, 22);
this->statusStrip1->TabIndex = 8;
this->statusStrip1->Text = L"statusStrip1";
//
// toolStripStatusLabel1
//
this->toolStripStatusLabel1->BorderStyle = System::Windows::Forms::Border3DStyle::RaisedInner;
this->toolStripStatusLabel1->Name = L"toolStripStatusLabel1";
this->toolStripStatusLabel1->Size = System::Drawing::Size(54, 17);
this->toolStripStatusLabel1->Text = L"Position";
//
// toolStripStatusLabel2
//
this->toolStripStatusLabel2->Enabled = false;
this->toolStripStatusLabel2->Name = L"toolStripStatusLabel2";
this->toolStripStatusLabel2->Size = System::Drawing::Size(0, 17);
//
// toolStripStatusLabel3
//
this->toolStripStatusLabel3->BorderStyle = System::Windows::Forms::Border3DStyle::RaisedInner;
this->toolStripStatusLabel3->Name = L"toolStripStatusLabel3";
this->toolStripStatusLabel3->Size = System::Drawing::Size(376, 17);
this->toolStripStatusLabel3->Spring = true;
this->toolStripStatusLabel3->Text = L"Description";
//
// TextEdit
//
this->AcceptButton = this->buttonOk;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
Expand All @@ -215,7 +182,7 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
this->Controls->Add(this->textBox1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::SizableToolWindow;
this->Name = L"TextEdit";
this->Text = L"TextForm";
this->Text = L"TextEdit";
this->panel1->ResumeLayout(false);
this->statusStrip1->ResumeLayout(false);
this->statusStrip1->PerformLayout();
Expand All @@ -225,6 +192,6 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
}
#pragma endregion
};
}
}
}
} // namespace Props
} // namespace ECore
} // namespace XRay
12 changes: 12 additions & 0 deletions src/editors/xrECore/xrEProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Props/NumericVector.h"
#include "Props/ShaderFunction.h"
#include "Props/GameType.h"
#include "Props/TextEdit.h"
#include "xrEngine/WaveForm.h"

namespace XRay
Expand All @@ -28,6 +29,17 @@ bool GameTypeRun(pcstr title, GameTypeChooser* data)
auto form = gcnew GameType();
return form->Run(title, data);
}

bool TextEditRun(xr_string& text, pcstr caption /*= "Text"*/, bool read_only /*= false*/,
int lim /*= 0*/, pcstr apply_name /*= "Apply"*/,
TOnApplyClick on_apply /*= 0*/, TOnCloseClick on_close /*= 0*/,
TOnCodeInsight on_insight /*= 0*/)
{
auto form = gcnew TextEdit();
return false;
//return form->Run(text, caption, read_only, lim, apply_name, on_apply, on_close, on_insight);
}

} // namespace Props
} // namespace ECore
} // namespace XRay
16 changes: 13 additions & 3 deletions src/editors/xrECore/xrEProps.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
#pragma once

template <class T>
struct _vector3;
using Fvector = _vector3<float>;
struct WaveForm;
struct GameTypeChooser;

using TOnApplyClick = fastdelegate::FastDelegate1<pcstr, bool>;
using TOnCloseClick = fastdelegate::FastDelegate0<bool>;
using TOnCodeInsight = fastdelegate::FastDelegate3<const xr_string&, xr_string&, bool&>;

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);
bool GameTypeRun(pcstr title, GameTypeChooser* data);
XRECORE_API bool NumericVectorRun(pcstr title, Fvector* data, int decimal, Fvector* reset_value, Fvector* min, Fvector* max, int* X, int* Y);
XRECORE_API bool ShaderFunctionRun(WaveForm* func);
XRECORE_API bool GameTypeRun(pcstr title, GameTypeChooser* data);
XRECORE_API bool TextEditRun(xr_string& text, pcstr caption = "Text", bool read_only = false, int lim = 0,
pcstr apply_name = "Apply", TOnApplyClick on_apply = 0, TOnCloseClick on_close = 0,
TOnCodeInsight on_insight = 0);
} // namespace Props
} // namespace ECore
} // namespace XRay

0 comments on commit 816b080

Please sign in to comment.