-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBox.cs
More file actions
123 lines (102 loc) · 2.99 KB
/
TextBox.cs
File metadata and controls
123 lines (102 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using MiniCooked;
using System.Text;
public class TextBox : RectUI
{
private StringBuilder _sb = new StringBuilder();
//[][][]
//c c c
//cw[sb[1]] cw[sb[2]]
private int _tempIdx = 0;
private int _lineCount = 0;
private List<int> _lineRange = new List<int>();
public TextBox(Rect m_rect) : base(m_rect)
{
}
public TextBox(string m_text)
{
SetNewText(m_text);
}
/// <summary>
/// 기존의 문자를 비우고 새로운 문자로 배치합니다.
/// </summary>
public void SetNewText(string m_text)
{
_lineRange.Clear();
_lineRange.Add(0);
_tempIdx = 0;
_sb.Clear();
_lineCount = 1;
int count = 0;
for (int i = 0; i < m_text.Length; i++)
{
_sb.Append(m_text[i]);
count++;
if (CharController.isHalf(m_text[i]))
{
_sb.Append(' '); // 반각 문자는 공백 추가로 2칸 차지하게 함
count++;
}
}
_rect.EndX = _rect.StartX + count;
_lineRange.Add(count);
}
/// <summary>
/// 문자열을 추가합니다.
/// </summary>
/// <param name="m_lineMode">true = 다음라인에 작성 , false = 기존라인에 추가작성</param>
/// <returns></returns>
public TextBox AddText(string m_text, bool m_lineMode = false)
{
if (m_lineMode)
{
_sb.AppendLine();
_tempIdx = _sb.Length;
_rect.EndY++;
_lineCount++;
_lineRange.Add(_lineRange[_lineRange.Count - 1]);
}
int count = 0;
for (int i = 0; i < m_text.Length; i++)
{
_sb.Append(m_text[i]);
count++;
if (CharController.isHalf(m_text[i]))
{
_sb.Append(' '); // 반각 문자 뒤에 공백 추가
count++;
}
}
_tempIdx += count;
_lineRange[_lineRange.Count - 1] = _tempIdx;
if (_rect.EndY < _tempIdx)
_rect.EndY = _tempIdx;
return this;
}
/// <summary>
/// 문자를 추가합니다.
/// </summary>
/// <param name="m_text"></param>
/// <param name="m_lineMode">true = 다음라인에 작성 , false = 기존라인에 추가작성</param>
public TextBox AddText(char m_text, bool m_lineMode = false)
{
return AddText(m_text.ToString(), m_lineMode);
}
/// <summary>
/// UI 요소를 화면에 출력합니다.
/// </summary>
protected override void PrintLogic()
{
int standardX = Left;
int standardY = Top;
int strLength;
for (int i = 1; i <= _lineCount; i++)
{
strLength = _lineRange[i] - _lineRange[i - 1];
int start = _lineRange[i - 1];
for (int j = 0; j < strLength; j++)
{
ColorPrinter.Print(standardX + j, standardY+i, _printColor, _sb[start + j]);
}
}
}
}