Skip to content

Commit 816b080

Browse files
committed
xrEProps: TextEdit update (WIP)
Broken, but compilation is fixed now
1 parent 5c028f8 commit 816b080

File tree

4 files changed

+83
-58
lines changed

4 files changed

+83
-58
lines changed
Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,49 @@
11
#include "pch.hpp"
2+
3+
#include <msclr/marshal.h>
4+
25
#include "TextEdit.h"
36

4-
System::Void XRay::ECore::Props::TextEdit::buttonClear_Click(System::Object^ sender, System::EventArgs^ e)
7+
namespace XRay
8+
{
9+
namespace ECore
10+
{
11+
namespace Props
12+
{
13+
System::Void TextEdit::buttonClear_Click(System::Object^ sender, System::EventArgs^ e)
514
{
615
textBox1->Clear();
716
}
817

9-
System::Void XRay::ECore::Props::TextEdit::buttonOk_Click(System::Object^ sender, System::EventArgs^ e)
18+
System::Void TextEdit::textBox1_SelectionChanged(System::Object^ sender, System::EventArgs^ e)
19+
{
20+
auto line = textBox1->GetLineFromCharIndex(textBox1->SelectionStart);
21+
auto currline = textBox1->GetFirstCharIndexOfCurrentLine();
22+
auto charpos = textBox1->SelectionStart - currline;
23+
toolStripStatusLabel1->Text = (line + 1) + " : " + (charpos + 1);
24+
}
25+
26+
bool TextEdit::Run(xr_string& text, pcstr caption, bool read_only, int lim,
27+
pcstr apply_name, TOnApplyClick^ on_apply, TOnCloseClick^ on_close,
28+
TOnCodeInsight^ on_insight)
29+
{
30+
Text = gcnew String(caption);
31+
m_text = &text;
32+
textBox1->ReadOnly = read_only;
33+
textBox1->Text = gcnew String(text.c_str());
34+
textBox1->MaxLength = lim;
35+
36+
buttonApply->Text = gcnew String(apply_name);
37+
//buttonApply->Click += gcnew EventHandler(on_apply);
38+
39+
return ShowDialog() == Windows::Forms::DialogResult::OK;
40+
}
41+
42+
System::Void TextEdit::buttonOk_Click(System::Object^ sender, System::EventArgs^ e)
1043
{
11-
//marshal this
12-
//*m_text = textBox1->Text;
44+
msclr::interop::marshal_context ctx;
45+
*m_text = ctx.marshal_as<pcstr>(textBox1->Text);
1346
}
47+
} // namespace Props
48+
} // namespace ECore
49+
} // namespace XRay

src/editors/xrECore/Props/TextEdit.h

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@ public ref class TextEdit : public System::Windows::Forms::Form
3030
}
3131
}
3232

33-
public:
34-
bool Run();
35-
3633
private:
3734
xr_string* m_text;
35+
delegate void TOnApplyClick(pcstr, bool);
36+
delegate void TOnCloseClick(bool);
37+
delegate void TOnCodeInsight(const xr_string&, xr_string&, bool&);
38+
39+
public:
40+
bool Run(xr_string& text, pcstr caption, bool read_only, int lim,
41+
pcstr apply_name, TOnApplyClick^ on_apply, TOnCloseClick^ on_close,
42+
TOnCodeInsight^ on_insight);
43+
3844

3945
private: System::Void buttonOk_Click(System::Object^ sender, System::EventArgs^ e);
4046
private: System::Void buttonClear_Click(System::Object^ sender, System::EventArgs^ e);
47+
private: System::Void textBox1_SelectionChanged(System::Object^ sender, System::EventArgs^ e);
4148

4249
private: System::Windows::Forms::Button^ buttonOk;
4350
private: System::Windows::Forms::Button^ buttonCancel;
@@ -47,7 +54,7 @@ private: System::Windows::Forms::Button^ buttonSave;
4754
private: System::Windows::Forms::Button^ buttonClear;
4855

4956
private: System::Windows::Forms::Panel^ panel1;
50-
private: System::Windows::Forms::TextBox^ textBox1;
57+
private: System::Windows::Forms::RichTextBox^ textBox1;
5158

5259
private: System::Windows::Forms::StatusStrip^ statusStrip1;
5360
private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel1;
@@ -61,7 +68,7 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
6168
#pragma region Windows Form Designer generated code
6269
void InitializeComponent(void)
6370
{
64-
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
71+
this->textBox1 = (gcnew System::Windows::Forms::RichTextBox());
6572
this->buttonOk = (gcnew System::Windows::Forms::Button());
6673
this->buttonCancel = (gcnew System::Windows::Forms::Button());
6774
this->buttonApply = (gcnew System::Windows::Forms::Button());
@@ -76,23 +83,16 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
7683
this->panel1->SuspendLayout();
7784
this->statusStrip1->SuspendLayout();
7885
this->SuspendLayout();
79-
//
80-
// textBox1
81-
//
82-
this->textBox1->AcceptsReturn = true;
8386
this->textBox1->AcceptsTab = true;
8487
this->textBox1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom)
8588
| System::Windows::Forms::AnchorStyles::Left)
8689
| System::Windows::Forms::AnchorStyles::Right));
8790
this->textBox1->Location = System::Drawing::Point(0, 25);
88-
this->textBox1->Multiline = true;
8991
this->textBox1->Name = L"textBox1";
90-
this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Both;
9192
this->textBox1->Size = System::Drawing::Size(445, 217);
9293
this->textBox1->TabIndex = 0;
93-
//
94-
// buttonOk
95-
//
94+
this->textBox1->Text = L"";
95+
this->textBox1->SelectionChanged += gcnew System::EventHandler(this, &TextEdit::textBox1_SelectionChanged);
9696
this->buttonOk->Anchor = System::Windows::Forms::AnchorStyles::Top;
9797
this->buttonOk->AutoSizeMode = System::Windows::Forms::AutoSizeMode::GrowAndShrink;
9898
this->buttonOk->DialogResult = System::Windows::Forms::DialogResult::OK;
@@ -103,9 +103,6 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
103103
this->buttonOk->Text = L"Ok";
104104
this->buttonOk->UseVisualStyleBackColor = true;
105105
this->buttonOk->Click += gcnew System::EventHandler(this, &TextEdit::buttonOk_Click);
106-
//
107-
// buttonCancel
108-
//
109106
this->buttonCancel->Anchor = System::Windows::Forms::AnchorStyles::Top;
110107
this->buttonCancel->DialogResult = System::Windows::Forms::DialogResult::Cancel;
111108
this->buttonCancel->Location = System::Drawing::Point(74, 0);
@@ -114,39 +111,27 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
114111
this->buttonCancel->TabIndex = 2;
115112
this->buttonCancel->Text = L"Cancel";
116113
this->buttonCancel->UseVisualStyleBackColor = true;
117-
//
118-
// buttonApply
119-
//
120114
this->buttonApply->Anchor = System::Windows::Forms::AnchorStyles::Top;
121115
this->buttonApply->Location = System::Drawing::Point(148, 0);
122116
this->buttonApply->Name = L"buttonApply";
123117
this->buttonApply->Size = System::Drawing::Size(75, 23);
124118
this->buttonApply->TabIndex = 3;
125119
this->buttonApply->Text = L"Apply";
126120
this->buttonApply->UseVisualStyleBackColor = true;
127-
//
128-
// buttonLoad
129-
//
130121
this->buttonLoad->Anchor = System::Windows::Forms::AnchorStyles::Top;
131122
this->buttonLoad->Location = System::Drawing::Point(222, 0);
132123
this->buttonLoad->Name = L"buttonLoad";
133124
this->buttonLoad->Size = System::Drawing::Size(75, 23);
134125
this->buttonLoad->TabIndex = 4;
135126
this->buttonLoad->Text = L"Load";
136127
this->buttonLoad->UseVisualStyleBackColor = true;
137-
//
138-
// buttonSave
139-
//
140128
this->buttonSave->Anchor = System::Windows::Forms::AnchorStyles::Top;
141129
this->buttonSave->Location = System::Drawing::Point(296, 0);
142130
this->buttonSave->Name = L"buttonSave";
143131
this->buttonSave->Size = System::Drawing::Size(75, 23);
144132
this->buttonSave->TabIndex = 5;
145133
this->buttonSave->Text = L"Save";
146134
this->buttonSave->UseVisualStyleBackColor = true;
147-
//
148-
// buttonClear
149-
//
150135
this->buttonClear->Anchor = System::Windows::Forms::AnchorStyles::Top;
151136
this->buttonClear->Location = System::Drawing::Point(370, 0);
152137
this->buttonClear->Name = L"buttonClear";
@@ -155,9 +140,6 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
155140
this->buttonClear->Text = L"Clear";
156141
this->buttonClear->UseVisualStyleBackColor = true;
157142
this->buttonClear->Click += gcnew System::EventHandler(this, &TextEdit::buttonClear_Click);
158-
//
159-
// panel1
160-
//
161143
this->panel1->Controls->Add(this->buttonOk);
162144
this->panel1->Controls->Add(this->buttonClear);
163145
this->panel1->Controls->Add(this->buttonCancel);
@@ -169,9 +151,6 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
169151
this->panel1->Name = L"panel1";
170152
this->panel1->Size = System::Drawing::Size(445, 24);
171153
this->panel1->TabIndex = 7;
172-
//
173-
// statusStrip1
174-
//
175154
this->statusStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(3) {
176155
this->toolStripStatusLabel1,
177156
this->toolStripStatusLabel2, this->toolStripStatusLabel3
@@ -181,30 +160,18 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
181160
this->statusStrip1->Size = System::Drawing::Size(445, 22);
182161
this->statusStrip1->TabIndex = 8;
183162
this->statusStrip1->Text = L"statusStrip1";
184-
//
185-
// toolStripStatusLabel1
186-
//
187163
this->toolStripStatusLabel1->BorderStyle = System::Windows::Forms::Border3DStyle::RaisedInner;
188164
this->toolStripStatusLabel1->Name = L"toolStripStatusLabel1";
189165
this->toolStripStatusLabel1->Size = System::Drawing::Size(54, 17);
190166
this->toolStripStatusLabel1->Text = L"Position";
191-
//
192-
// toolStripStatusLabel2
193-
//
194167
this->toolStripStatusLabel2->Enabled = false;
195168
this->toolStripStatusLabel2->Name = L"toolStripStatusLabel2";
196169
this->toolStripStatusLabel2->Size = System::Drawing::Size(0, 17);
197-
//
198-
// toolStripStatusLabel3
199-
//
200170
this->toolStripStatusLabel3->BorderStyle = System::Windows::Forms::Border3DStyle::RaisedInner;
201171
this->toolStripStatusLabel3->Name = L"toolStripStatusLabel3";
202172
this->toolStripStatusLabel3->Size = System::Drawing::Size(376, 17);
203173
this->toolStripStatusLabel3->Spring = true;
204174
this->toolStripStatusLabel3->Text = L"Description";
205-
//
206-
// TextEdit
207-
//
208175
this->AcceptButton = this->buttonOk;
209176
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
210177
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
@@ -215,7 +182,7 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
215182
this->Controls->Add(this->textBox1);
216183
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::SizableToolWindow;
217184
this->Name = L"TextEdit";
218-
this->Text = L"TextForm";
185+
this->Text = L"TextEdit";
219186
this->panel1->ResumeLayout(false);
220187
this->statusStrip1->ResumeLayout(false);
221188
this->statusStrip1->PerformLayout();
@@ -225,6 +192,6 @@ private: System::Windows::Forms::ToolStripStatusLabel^ toolStripStatusLabel3;
225192
}
226193
#pragma endregion
227194
};
228-
}
229-
}
230-
}
195+
} // namespace Props
196+
} // namespace ECore
197+
} // namespace XRay

src/editors/xrECore/xrEProps.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Props/NumericVector.h"
44
#include "Props/ShaderFunction.h"
55
#include "Props/GameType.h"
6+
#include "Props/TextEdit.h"
67
#include "xrEngine/WaveForm.h"
78

89
namespace XRay
@@ -28,6 +29,17 @@ bool GameTypeRun(pcstr title, GameTypeChooser* data)
2829
auto form = gcnew GameType();
2930
return form->Run(title, data);
3031
}
32+
33+
bool TextEditRun(xr_string& text, pcstr caption /*= "Text"*/, bool read_only /*= false*/,
34+
int lim /*= 0*/, pcstr apply_name /*= "Apply"*/,
35+
TOnApplyClick on_apply /*= 0*/, TOnCloseClick on_close /*= 0*/,
36+
TOnCodeInsight on_insight /*= 0*/)
37+
{
38+
auto form = gcnew TextEdit();
39+
return false;
40+
//return form->Run(text, caption, read_only, lim, apply_name, on_apply, on_close, on_insight);
41+
}
42+
3143
} // namespace Props
3244
} // namespace ECore
3345
} // namespace XRay

src/editors/xrECore/xrEProps.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
#pragma once
22

3+
template <class T>
4+
struct _vector3;
5+
using Fvector = _vector3<float>;
36
struct WaveForm;
47
struct GameTypeChooser;
58

9+
using TOnApplyClick = fastdelegate::FastDelegate1<pcstr, bool>;
10+
using TOnCloseClick = fastdelegate::FastDelegate0<bool>;
11+
using TOnCodeInsight = fastdelegate::FastDelegate3<const xr_string&, xr_string&, bool&>;
12+
613
namespace XRay
714
{
815
namespace ECore
916
{
1017
namespace Props
1118
{
12-
bool NumericVectorRun(pcstr title, Fvector* data, int decimal, Fvector* reset_value, Fvector* min, Fvector* max, int* X, int* Y);
13-
bool ShaderFunctionRun(WaveForm* func);
14-
bool GameTypeRun(pcstr title, GameTypeChooser* data);
19+
XRECORE_API bool NumericVectorRun(pcstr title, Fvector* data, int decimal, Fvector* reset_value, Fvector* min, Fvector* max, int* X, int* Y);
20+
XRECORE_API bool ShaderFunctionRun(WaveForm* func);
21+
XRECORE_API bool GameTypeRun(pcstr title, GameTypeChooser* data);
22+
XRECORE_API bool TextEditRun(xr_string& text, pcstr caption = "Text", bool read_only = false, int lim = 0,
23+
pcstr apply_name = "Apply", TOnApplyClick on_apply = 0, TOnCloseClick on_close = 0,
24+
TOnCodeInsight on_insight = 0);
1525
} // namespace Props
1626
} // namespace ECore
1727
} // namespace XRay

0 commit comments

Comments
 (0)