Browse Source

Merge remote-tracking branch 'Stan/development' into development

kindlich 6 years ago
parent
commit
47ab94f85f
No known key found for this signature in database
1 changed files with 28 additions and 11 deletions
  1. 28
    11
      DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java

+ 28
- 11
DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java View File

7
 
7
 
8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.List;
9
 import java.util.List;
10
+import org.openzen.drawablegui.DColorableIcon;
10
 import org.openzen.drawablegui.DColorableIconInstance;
11
 import org.openzen.drawablegui.DColorableIconInstance;
11
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponentContext;
13
 import org.openzen.drawablegui.DComponentContext;
124
 		int rowIndex = yToRow(e.y);
125
 		int rowIndex = yToRow(e.y);
125
 		if (rowIndex >= 0 && rowIndex < rows.size()) {
126
 		if (rowIndex >= 0 && rowIndex < rows.size()) {
126
 			Row rowEntry = rows.get(rowIndex);
127
 			Row rowEntry = rows.get(rowIndex);
127
-			if (e.x >= rowEntry.x && e.x < (rowEntry.x + nodeOpenedIcon.getNominalWidth())) {
128
+			if (e.x >= rowEntry.x && e.x < (rowEntry.x + getIconWidth(nodeOpenedIcon))) {
128
 				if (!rowEntry.node.isLeaf())
129
 				if (!rowEntry.node.isLeaf())
129
 					rowEntry.node.isCollapsed().toggle();
130
 					rowEntry.node.isCollapsed().toggle();
130
 				return;
131
 				return;
143
 				int selectionY = bounds.y + style.padding + rowIndex * (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent()) - style.selectedPaddingTop;
144
 				int selectionY = bounds.y + style.padding + rowIndex * (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent()) - style.selectedPaddingTop;
144
 				int selectionWidth = (int)(fontMetrics.getWidth(row.node.getTitle())
145
 				int selectionWidth = (int)(fontMetrics.getWidth(row.node.getTitle())
145
 						+ style.iconTextSpacing
146
 						+ style.iconTextSpacing
146
-						+ row.icon.getNominalWidth()
147
+						+ getIconWidth(row.icon)
147
 						+ style.iconTextSpacing
148
 						+ style.iconTextSpacing
148
-						+ row.node.getIcon().getNominalWidth()
149
+						+ getIconWidth(row.node.getIcon())
149
 						+ style.selectedPaddingLeft
150
 						+ style.selectedPaddingLeft
150
 						+ style.selectedPaddingRight);
151
 						+ style.selectedPaddingRight);
151
 				int selectionHeight = fontMetrics.getAscent() + fontMetrics.getDescent() + style.selectedPaddingTop + style.selectedPaddingBottom;
152
 				int selectionHeight = fontMetrics.getAscent() + fontMetrics.getDescent() + style.selectedPaddingTop + style.selectedPaddingBottom;
152
 				
153
 				
153
 				if (row.node.isLeaf()) {
154
 				if (row.node.isLeaf()) {
154
-					int delta = (int)(row.icon.getNominalWidth() + style.iconTextSpacing);
155
+					int delta = (int)(getIconWidth(row.icon) + style.iconTextSpacing);
155
 					selectionX += delta;
156
 					selectionX += delta;
156
 					selectionWidth -= delta;
157
 					selectionWidth -= delta;
157
 				}
158
 				}
182
 		return (y - bounds.y - style.padding) / (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent());
183
 		return (y - bounds.y - style.padding) / (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent());
183
 	}
184
 	}
184
 	
185
 	
186
+	private float getIconWidth(DDrawable drawable) {
187
+		return drawable.getNominalWidth() * iconScale;
188
+	}
189
+	
190
+	private float getIconHeight(DDrawable drawable) {
191
+		return drawable.getNominalHeight() * iconScale; 
192
+	}
193
+	
194
+	private float getIconWidth(DColorableIcon icon) {
195
+		return icon.getNominalWidth() * iconScale;
196
+	}
197
+	
198
+	private float getIconHeight(DColorableIcon icon) {
199
+		return icon.getNominalHeight() * iconScale; 
200
+	}
201
+	
185
 	private void updateLayout() {
202
 	private void updateLayout() {
186
 		int oldRowCount = rows.size();
203
 		int oldRowCount = rows.size();
187
 		
204
 		
265
 					context.surface,
282
 					context.surface,
266
 					context.z + 2,
283
 					context.z + 2,
267
 					node.getIcon(),
284
 					node.getIcon(),
268
-					DTransform2D.scaleAndTranslate(baseX + icon.getNominalWidth() + style.iconTextSpacing, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight(), iconScale),
285
+					DTransform2D.scaleAndTranslate(baseX + getIconWidth(icon) + style.iconTextSpacing, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon), iconScale),
269
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor);
286
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor);
270
 			
287
 			
271
 			if (!node.isLeaf())
288
 			if (!node.isLeaf())
273
 						context.surface, 
290
 						context.surface, 
274
 						context.z + 2,
291
 						context.z + 2,
275
 						icon,
292
 						icon,
276
-						DTransform2D.scaleAndTranslate(baseX, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight(), iconScale));
293
+						DTransform2D.scaleAndTranslate(baseX, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon), iconScale));
277
 			
294
 			
278
 			text = context.drawText(
295
 			text = context.drawText(
279
 					2,
296
 					2,
280
 					style.font,
297
 					style.font,
281
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor,
298
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor,
282
-					baseX + style.iconTextSpacing + icon.getNominalWidth() + style.iconTextSpacing + node.getIcon().getNominalWidth(),
299
+					baseX + style.iconTextSpacing + getIconWidth(icon) + style.iconTextSpacing + getIconWidth(node.getIcon()),
283
 					baseY + fontMetrics.getAscent(),
300
 					baseY + fontMetrics.getAscent(),
284
 					node.getTitle());
301
 					node.getTitle());
285
 		}
302
 		}
291
 			if (collapseIcon != null) {
308
 			if (collapseIcon != null) {
292
 				collapseIcon.setTransform(DTransform2D.scaleAndTranslate(
309
 				collapseIcon.setTransform(DTransform2D.scaleAndTranslate(
293
 						baseX,
310
 						baseX,
294
-						baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight(),
311
+						baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon),
295
 						iconScale));
312
 						iconScale));
296
 			}
313
 			}
297
 			nodeIcon.setTransform(DTransform2D.scaleAndTranslate(
314
 			nodeIcon.setTransform(DTransform2D.scaleAndTranslate(
298
-					baseX + icon.getNominalWidth() + style.iconTextSpacing,
299
-					baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight(),
315
+					baseX + getIconWidth(icon) + style.iconTextSpacing,
316
+					baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - getIconHeight(icon),
300
 					iconScale));
317
 					iconScale));
301
 			text.setPosition(
318
 			text.setPosition(
302
-					baseX + style.iconTextSpacing + icon.getNominalWidth() + style.iconTextSpacing + node.getIcon().getNominalWidth(),
319
+					baseX + style.iconTextSpacing + getIconWidth(icon) + style.iconTextSpacing + getIconWidth(node.getIcon()),
303
 					baseY + fontMetrics.getAscent());
320
 					baseY + fontMetrics.getAscent());
304
 		}
321
 		}
305
 
322
 

Loading…
Cancel
Save