Skip to content

Commit 3d37f3e

Browse files
committed
hotfixes
1 parent d35b0bd commit 3d37f3e

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

System/Drawing/Editor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public static EditorValue<int[]> IntField(string name, params int[] value)
157157
UnityEngine.GUILayout.Label(name + ":", UnityEngine.GUILayout.Width(_nameWidth));
158158

159159
bool changed = false;
160-
int[] intBuffer = value;
160+
int[] intBuffer = new int[value.Length];
161161
for (int i = 0; i < value.Length; i++)
162162
{
163163
if (WinFormsCompatible)

System/Windows/Forms/ListBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected override void OnPaint(PaintEventArgs e)
223223
if (Items.Count > _visibleItems)
224224
_scrollVisible = true;
225225

226-
if (_scrollVisible)
226+
if (_scrollVisible && Items.Count > 0)
227227
{
228228
_scrollX = Width - _scrollWidth;
229229
_scrollY = ScrollIndex * Height / Items.Count;

System/Windows/Forms/TextBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected override void OnPaint(PaintEventArgs e)
9494
}
9595
}
9696
else
97-
g.DrawString(Text, Font, new SolidBrush(ForeColor), new RectangleF(4, 0, Width - 8, Height));
97+
g.DrawString(Text, Font, new SolidBrush(ForeColor), new RectangleF(Padding.Left, Padding.Top, Width - Padding.Left - Padding.Right, Height - Padding.Bottom - Padding.Top));
9898

9999
g.DrawRectangle(new Pen(_hovered ? BorderHoverColor : BorderColor), 0, 0, Width, Height);
100100
}

System/Windows/Forms/TreeView.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class TreeView : Control
1919
private bool _scrollVisible = false; // smooth scrolling.
2020
private bool _scroll;
2121
private bool _scrollHovered;
22-
private float _scrollIndex;
23-
private float _scrollY;
24-
private float _scrollHeight;
25-
private float _scrollWidth = 10;
22+
protected float scrollIndex;
23+
private float _scrollbarY;
24+
private float _scrollbarHeight;
25+
private float _scrollbarWidth = 10;
2626
private float _scrollStartY;
2727
private float _scroll_ItemsEstimatedHeigh;
2828
private List<TreeNode> _scrollNodeList;
@@ -35,7 +35,7 @@ public class TreeView : Control
3535
public ImageList ImageList { get { return _imageList; } set { _imageList = value; } }
3636
public int ItemHeight { get; set; }
3737
public TreeNodeCollection Nodes { get { return _nodes; } private set { _nodes = value; } }
38-
public float ScrollIndex { get { return _scrollIndex; } internal set { _scrollIndex = value; } }
38+
public float ScrollIndex { get { return scrollIndex; } internal set { scrollIndex = value; } }
3939
public float ScrollSpeed { get; set; }
4040
public TreeNode SelectedNode { get; set; }
4141
public Color SelectionColor { get; set; }
@@ -70,15 +70,15 @@ private void _AddjustScrollIndexToSelectedNode()
7070
{
7171
if (SelectedNode != null)
7272
{
73-
if (_scrollIndex > SelectedNode.Bounds.Y)
73+
if (scrollIndex > SelectedNode.Bounds.Y)
7474
{
7575

76-
_scrollIndex = SelectedNode.Bounds.Y;
76+
scrollIndex = SelectedNode.Bounds.Y;
7777
_UpdateScrollList();
7878
}
79-
if (_scrollIndex + Height < SelectedNode.Bounds.Y + ItemHeight)
79+
if (scrollIndex + Height < SelectedNode.Bounds.Y + ItemHeight)
8080
{
81-
_scrollIndex = SelectedNode.Bounds.Y + ItemHeight - Height;
81+
scrollIndex = SelectedNode.Bounds.Y + ItemHeight - Height;
8282
_UpdateScrollList();
8383
}
8484
}
@@ -95,22 +95,22 @@ private void _FixScrollIndex()
9595
{
9696
if (_nodeList == null || _nodeList.Count == 0)
9797
{
98-
_scrollIndex = 0;
98+
scrollIndex = 0;
9999
return;
100100
}
101101

102102
if (SmoothScrolling == false)
103-
_scrollIndex = (float)Math.Ceiling(_scrollIndex / ItemHeight) * ItemHeight;
103+
scrollIndex = (float)Math.Ceiling(scrollIndex / ItemHeight) * ItemHeight;
104104

105-
if (_scrollIndex > _nodeList.Last().Bounds.Y + ItemHeight - Height) _scrollIndex = _nodeList.Last().Bounds.Y + ItemHeight - Height;
106-
if (_scrollIndex < 0) _scrollIndex = 0;
105+
if (scrollIndex > _nodeList.Last().Bounds.Y + ItemHeight - Height) scrollIndex = _nodeList.Last().Bounds.Y + ItemHeight - Height;
106+
if (scrollIndex < 0) scrollIndex = 0;
107107
}
108108
private TreeNode _GetNodeAtPosition(TreeNode rootNode, Point position)
109109
{
110110
if (rootNode != root && rootNode.IsVisible)
111111
{
112112
int nodeWidth = Width;
113-
var rootNodeRect = new Rectangle(rootNode.Bounds.X, rootNode.Bounds.Y - (int)_scrollIndex, nodeWidth, rootNode.Bounds.Height);
113+
var rootNodeRect = new Rectangle(rootNode.Bounds.X, rootNode.Bounds.Y - (int)scrollIndex, nodeWidth, rootNode.Bounds.Height);
114114
if (UseNodeBoundsForSelection == false) rootNodeRect.X = 0;
115115
if (rootNodeRect.Contains(position))
116116
return rootNode;
@@ -143,7 +143,7 @@ private void _OnDrawNode(object sender, DrawTreeNodeEventArgs e)
143143
{
144144
// Node drawing.
145145
e.Graphics.FillRectangle(new SolidBrush(e.Node.BackColor), e.Node.Bounds);
146-
if (e.Node.IsSelected) e.Graphics.FillRectangle(new SolidBrush(SelectionColor), UseNodeBoundsForSelection ? e.Node.Bounds.X : 0, e.Node.Bounds.Y - (int)_scrollIndex, Width, ItemHeight);
146+
if (e.Node.IsSelected) e.Graphics.FillRectangle(new SolidBrush(SelectionColor), UseNodeBoundsForSelection ? e.Node.Bounds.X : 0, e.Node.Bounds.Y - (int)scrollIndex, Width, ItemHeight);
147147

148148
bool hasImage = false;
149149
int imageWidth = 0;
@@ -152,15 +152,15 @@ private void _OnDrawNode(object sender, DrawTreeNodeEventArgs e)
152152
var image = ImageList.Images[e.Node.ImageIndex];
153153
if (image != null && image.uTexture != null)
154154
{
155-
e.Graphics.DrawTexture(image.uTexture, e.Node.Bounds.X, e.Node.Bounds.Y + e.Node.Bounds.Height / 2 - image.Height / 2 - (int)_scrollIndex, image.Width, image.Height, e.Node.ImageColor);
155+
e.Graphics.DrawTexture(image.uTexture, e.Node.Bounds.X, e.Node.Bounds.Y + e.Node.Bounds.Height / 2 - image.Height / 2 - (int)scrollIndex, image.Width, image.Height, e.Node.ImageColor);
156156
hasImage = true;
157157
imageWidth = image.Width;
158158
}
159159
}
160160

161161
string stringToDraw = e.Node.Text;
162162
if (stringToDraw == null && e.Node.Tag != null) stringToDraw = e.Node.Tag.ToString();
163-
e.Graphics.DrawString(stringToDraw, Font, new SolidBrush(e.Node.ForeColor), e.Node.Bounds.X + (hasImage ? imageWidth + 2 : 0), e.Node.Bounds.Y - (int)_scrollIndex - 2, (WrapText ? Width : Width * 16), e.Bounds.Height + 4, ContentAlignment.MiddleLeft);
163+
e.Graphics.DrawString(stringToDraw, Font, new SolidBrush(e.Node.ForeColor), e.Node.Bounds.X + (hasImage ? imageWidth + 2 : 0), e.Node.Bounds.Y - (int)scrollIndex - 2, (WrapText ? Width : Width * 16), e.Bounds.Height + 4, ContentAlignment.MiddleLeft);
164164
// End of drawing.
165165

166166
DrawNode(this, e);
@@ -228,13 +228,13 @@ private void _UpdateScrollList()
228228
{
229229
_scrollNodeList = new List<TreeNode>();
230230

231-
int startNode = (int)(_scrollIndex / ItemHeight) - 1;
231+
int startNode = (int)(scrollIndex / ItemHeight) - 1;
232232
if (startNode < 0) startNode = 0;
233233
int nodesOnScreen = Height / ItemHeight + 3; // Magic number.
234234

235235
for (int i = startNode; i < startNode + nodesOnScreen && i < _nodeList.Count; i++)
236236
{
237-
if (_nodeList[i].Bounds.Y + _nodeList[i].Bounds.Height > 0 && _nodeList[i].Bounds.Y - (int)_scrollIndex < Height)
237+
if (_nodeList[i].Bounds.Y + _nodeList[i].Bounds.Height > 0 && _nodeList[i].Bounds.Y - (int)scrollIndex < Height)
238238
{
239239
_scrollNodeList.Add(_nodeList[i]);
240240
}
@@ -292,7 +292,7 @@ protected override void OnMouseDown(MouseEventArgs e)
292292
var mclient = PointToClient(MousePosition);
293293

294294
_scroll = true;
295-
_scrollStartY = mclient.Y - _scrollY;
295+
_scrollStartY = mclient.Y - _scrollbarY;
296296
return;
297297
}
298298

@@ -305,7 +305,7 @@ protected override void OnMouseDown(MouseEventArgs e)
305305
protected override void OnMouseHover(EventArgs e)
306306
{
307307
var mclient = PointToClient(MousePosition);
308-
RectangleF _scrollRect = new RectangleF(Width - _scrollWidth, _scrollY, _scrollWidth, _scrollHeight);
308+
RectangleF _scrollRect = new RectangleF(Width - _scrollbarWidth, _scrollbarY, _scrollbarWidth, _scrollbarHeight);
309309
if (_scrollRect.Contains(mclient))
310310
_scrollHovered = true;
311311
else
@@ -317,7 +317,7 @@ protected override void OnMouseMove(MouseEventArgs e)
317317
{
318318
var mclient = PointToClient(MousePosition);
319319

320-
_scrollIndex = (mclient.Y - _scrollStartY) * (_scroll_ItemsEstimatedHeigh / Height);
320+
scrollIndex = (mclient.Y - _scrollStartY) * (_scroll_ItemsEstimatedHeigh / Height);
321321

322322
_FixScrollIndex();
323323
_UpdateScrollList();
@@ -334,7 +334,7 @@ protected override void OnMouseMove(MouseEventArgs e)
334334
}
335335
protected override void OnMouseWheel(MouseEventArgs e)
336336
{
337-
_scrollIndex -= e.Delta * ScrollSpeed;
337+
scrollIndex -= e.Delta * ScrollSpeed;
338338

339339
_FixScrollIndex();
340340
_UpdateScrollList();
@@ -359,11 +359,11 @@ protected override void OnPaint(PaintEventArgs e)
359359
if (_scrollHovered || _scroll) _scrollColor = Color.FromArgb(136, 136, 136);
360360

361361
float _scrollYCoeff = Height / _scroll_ItemsEstimatedHeigh;
362-
_scrollHeight = Height * _scrollYCoeff;
363-
if (_scrollHeight < 8) _scrollHeight = 8;
364-
_scrollY = _scrollIndex * _scrollYCoeff;
362+
_scrollbarHeight = Height * _scrollYCoeff;
363+
if (_scrollbarHeight < 8) _scrollbarHeight = 8;
364+
_scrollbarY = scrollIndex * _scrollYCoeff;
365365

366-
e.Graphics.FillRectangle(new SolidBrush(_scrollColor), Width - _scrollWidth + 2, _scrollY, _scrollWidth - 2, _scrollHeight);
366+
e.Graphics.FillRectangle(new SolidBrush(_scrollColor), Width - _scrollbarWidth + 2, _scrollbarY, _scrollbarWidth - 2, _scrollbarHeight);
367367
}
368368
#endregion
369369

0 commit comments

Comments
 (0)