!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / LuaRemoteDebugger / Aga.Controls / Tree / AutoRowHeightLayout.cs
blob39941048c3e7414904f8271bf758ada712ab9e49
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System;
4 using System.Collections.Generic;
5 using System.Text;
6 using System.Drawing;
7 using Aga.Controls.Tree.NodeControls;
9 namespace Aga.Controls.Tree
11 public class AutoRowHeightLayout: IRowLayout
13 private DrawContext _measureContext;
14 private TreeViewAdv _treeView;
15 private List<Rectangle> _rowCache;
17 public AutoRowHeightLayout(TreeViewAdv treeView, int rowHeight)
19 _rowCache = new List<Rectangle>();
20 _treeView = treeView;
21 PreferredRowHeight = rowHeight;
22 _measureContext = new DrawContext();
23 _measureContext.Graphics = Graphics.FromImage(new Bitmap(1, 1));
26 private int _rowHeight;
27 public int PreferredRowHeight
29 get { return _rowHeight; }
30 set { _rowHeight = value; }
34 public int PageRowCount
36 get
38 if (_treeView.RowCount == 0)
39 return 0;
40 else
42 int pageHeight = _treeView.DisplayRectangle.Height - _treeView.ColumnHeaderHeight;
43 int y = 0;
44 for (int i = _treeView.RowCount - 1; i >= 0; i--)
46 y += GetRowHeight(i);
47 if (y > pageHeight)
48 return Math.Max(0, _treeView.RowCount - 1 - i);
50 return _treeView.RowCount;
55 public int CurrentPageSize
57 get
59 if (_treeView.RowCount == 0)
60 return 0;
61 else
63 int pageHeight = _treeView.DisplayRectangle.Height - _treeView.ColumnHeaderHeight;
64 int y = 0;
65 for (int i = _treeView.FirstVisibleRow; i < _treeView.RowCount; i++)
67 y += GetRowHeight(i);
68 if (y > pageHeight)
69 return Math.Max(0, i - _treeView.FirstVisibleRow);
71 return Math.Max(0, _treeView.RowCount - _treeView.FirstVisibleRow);
76 public Rectangle GetRowBounds(int rowNo)
78 if (rowNo >= _rowCache.Count)
80 int count = _rowCache.Count;
81 int y = count > 0 ? _rowCache[count - 1].Bottom : 0;
82 for (int i = count; i <= rowNo; i++)
84 int height = GetRowHeight(i);
85 _rowCache.Add(new Rectangle(0, y, 0, height));
86 y += height;
88 if (rowNo < _rowCache.Count - 1)
89 return Rectangle.Empty;
91 if (rowNo >= 0 && rowNo < _rowCache.Count)
92 return _rowCache[rowNo];
93 else
94 return Rectangle.Empty;
97 private int GetRowHeight(int rowNo)
99 if (rowNo < _treeView.RowMap.Count)
101 TreeNodeAdv node = _treeView.RowMap[rowNo];
102 if (node.Height == null)
104 int res = 0;
105 _measureContext.Font = _treeView.Font;
106 foreach (NodeControl nc in _treeView.NodeControls)
108 int h = nc.GetActualSize(node, _measureContext).Height;
109 if (h > res)
110 res = h;
112 node.Height = res;
114 return node.Height.Value;
116 else
117 return 0;
120 public int GetRowAt(Point point)
122 int py = point.Y - _treeView.ColumnHeaderHeight;
123 int y = 0;
124 for (int i = _treeView.FirstVisibleRow; i < _treeView.RowCount; i++)
126 int h = GetRowHeight(i);
127 if (py >= y && py < y + h)
128 return i;
129 else
130 y += h;
132 return -1;
135 public int GetFirstRow(int lastPageRow)
137 int pageHeight = _treeView.DisplayRectangle.Height - _treeView.ColumnHeaderHeight;
138 int y = 0;
139 for (int i = lastPageRow; i >= 0; i--)
141 y += GetRowHeight(i);
142 if (y > pageHeight)
143 return Math.Max(0, i + 1);
145 return 0;
148 public void ClearCache()
150 _rowCache.Clear();