Bladeren bron

- Removed some unnecessary classes

- Added styling system
- WIP on the aspect bar
Stan Hebben 6 jaren geleden
bovenliggende
commit
02daef6093
56 gewijzigde bestanden met toevoegingen van 1749 en 347 verwijderingen
  1. 0
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/BaseComponentGroup.java
  2. 3
    7
      DrawableGui/src/main/java/org/openzen/drawablegui/DCanvas.java
  3. 10
    4
      DrawableGui/src/main/java/org/openzen/drawablegui/DComponent.java
  4. 11
    4
      DrawableGui/src/main/java/org/openzen/drawablegui/DEmptyView.java
  5. 0
    24
      DrawableGui/src/main/java/org/openzen/drawablegui/DIRectangle.java
  6. 51
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DPath.java
  7. 72
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DPathBoundsCalculator.java
  8. 35
    16
      DrawableGui/src/main/java/org/openzen/drawablegui/DSideLayout.java
  9. 16
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DTransform2D.java
  10. 10
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java
  11. 2
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DBorder.java
  12. 4
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DEmptyBorder.java
  13. 3
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DLineBorder.java
  14. 20
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/dimension/DDimension.java
  15. 25
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/dimension/DDpDimension.java
  16. 25
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/dimension/DPxDimension.java
  17. 3
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/listeners/DIRectangle.java
  18. 26
    16
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBar.java
  19. 11
    13
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBarStyle.java
  20. 42
    19
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java
  21. 4
    8
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPaneStyle.java
  22. 49
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStyleDefinition.java
  23. 21
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStylesheets.java
  24. 27
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleClass.java
  25. 28
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleDefinition.java
  26. 3
    7
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylePath.java
  27. 38
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylePathRoot.java
  28. 16
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleSheets.java
  29. 58
    13
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingCanvas.java
  30. 12
    4
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java
  31. 15
    6
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java
  32. 2
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java
  33. 40
    24
      DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java
  34. 55
    16
      DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeViewStyle.java
  35. 50
    2
      DrawableGuiIconConverter/src/main/java/org/openzen/drawablegui/iconconverter/Main.java
  36. 24
    3
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBar.java
  37. 3
    11
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBarControl.java
  38. 3
    45
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectToolbar.java
  39. 0
    21
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEDrawable.java
  40. 13
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java
  41. 59
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColorableAddBoxIcon.java
  42. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColorableProjectIcon.java
  43. 57
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColorableSaveIcon.java
  44. 81
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColorableSettingsIcon.java
  45. 40
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColoredIcon.java
  46. 31
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/SaveIcon.java
  47. 98
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java
  48. 13
    7
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarView.java
  49. 6
    4
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java
  50. 95
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java
  51. 46
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButtonStyle.java
  52. 63
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarStyle.java
  53. 234
    14
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java
  54. 60
    30
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java
  55. 34
    13
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditorStyle.java
  56. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenModel.java

+ 0
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/BaseComponentGroup.java Bestand weergeven

@@ -5,7 +5,6 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
-import java.awt.event.MouseWheelEvent;
9 8
 import java.util.function.Consumer;
10 9
 import java.util.function.Predicate;
11 10
 

+ 3
- 7
DrawableGui/src/main/java/org/openzen/drawablegui/DCanvas.java Bestand weergeven

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
+import org.openzen.drawablegui.listeners.DIRectangle;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker
@@ -20,16 +22,10 @@ public interface DCanvas {
20 22
 	
21 23
 	DIRectangle getBounds();
22 24
 	
23
-	DDrawingContext getContext();
25
+	DUIContext getContext();
24 26
 	
25 27
 	void drawText(DFont font, int color, float x, float y, String text);
26 28
 	
27
-	default float measureTextLength(DFont font, String text) {
28
-		return measureTextLength(font, text, 0, text.length());
29
-	}
30
-	
31
-	float measureTextLength(DFont font, String text, int offset, int length);
32
-	
33 29
 	/**
34 30
 	 * Strokes a given path.
35 31
 	 * 

+ 10
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/DComponent.java Bestand weergeven

@@ -5,20 +5,23 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
+import org.openzen.drawablegui.listeners.DIRectangle;
9
+import java.io.Closeable;
8 10
 import org.openzen.drawablegui.live.LiveObject;
11
+import org.openzen.drawablegui.style.DStylePath;
9 12
 
10 13
 /**
11 14
  *
12 15
  * @author Hoofdgebruiker
13 16
  */
14
-public interface DComponent {
15
-	void setContext(DDrawingContext context);
17
+public interface DComponent extends Closeable {
18
+	void setContext(DStylePath parent, DUIContext context);
16 19
 	
17 20
 	LiveObject<DDimensionPreferences> getDimensionPreferences();
18 21
 	
19
-	DRectangle getBounds();
22
+	DIRectangle getBounds();
20 23
 	
21
-	void setBounds(DRectangle bounds);
24
+	void setBounds(DIRectangle bounds);
22 25
 	
23 26
 	void paint(DCanvas canvas);
24 27
 	
@@ -47,4 +50,7 @@ public interface DComponent {
47 50
 	default void onKeyPressed(DKeyEvent e) {}
48 51
 	
49 52
 	default void onKeyReleased(DKeyEvent e) {}
53
+	
54
+	@Override
55
+	void close();
50 56
 }

+ 11
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/DEmptyView.java Bestand weergeven

@@ -5,8 +5,10 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
+import org.openzen.drawablegui.listeners.DIRectangle;
8 9
 import org.openzen.drawablegui.live.ImmutableLiveObject;
9 10
 import org.openzen.drawablegui.live.LiveObject;
11
+import org.openzen.drawablegui.style.DStylePath;
10 12
 
11 13
 /**
12 14
  *
@@ -16,12 +18,12 @@ public class DEmptyView implements DComponent {
16 18
 	public static final DEmptyView INSTANCE = new DEmptyView();
17 19
 	
18 20
 	private static final LiveObject<DDimensionPreferences> DIMENSION = new ImmutableLiveObject(new DDimensionPreferences(0, 0));
19
-	private static final DRectangle NO_BOUNDS = new DRectangle(0, 0, 0, 0);
21
+	private static final DIRectangle NO_BOUNDS = new DIRectangle(0, 0, 0, 0);
20 22
 	
21 23
 	private DEmptyView() {}
22 24
 
23 25
 	@Override
24
-	public void setContext(DDrawingContext context) {
26
+	public void setContext(DStylePath parent, DUIContext context) {
25 27
 		
26 28
 	}
27 29
 	
@@ -31,12 +33,12 @@ public class DEmptyView implements DComponent {
31 33
 	}
32 34
 	
33 35
 	@Override
34
-	public DRectangle getBounds() {
36
+	public DIRectangle getBounds() {
35 37
 		return NO_BOUNDS;
36 38
 	}
37 39
 
38 40
 	@Override
39
-	public void setBounds(DRectangle bounds) {
41
+	public void setBounds(DIRectangle bounds) {
40 42
 		
41 43
 	}
42 44
 
@@ -44,4 +46,9 @@ public class DEmptyView implements DComponent {
44 46
 	public void paint(DCanvas canvas) {
45 47
 		
46 48
 	}
49
+
50
+	@Override
51
+	public void close() {
52
+		// nothing to clean up
53
+	}
47 54
 }

+ 0
- 24
DrawableGui/src/main/java/org/openzen/drawablegui/DIRectangle.java Bestand weergeven

@@ -1,24 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.drawablegui;
7
-
8
-/**
9
- *
10
- * @author Hoofdgebruiker
11
- */
12
-public class DIRectangle {
13
-	public final int x;
14
-	public final int y;
15
-	public final int width;
16
-	public final int height;
17
-	
18
-	public DIRectangle(int x, int y, int width, int height) {
19
-		this.x = x;
20
-		this.y = y;
21
-		this.width = width;
22
-		this.height = height;
23
-	}
24
-}

+ 51
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DPath.java Bestand weergeven

@@ -10,5 +10,56 @@ package org.openzen.drawablegui;
10 10
  * @author Hoofdgebruiker
11 11
  */
12 12
 public interface DPath {
13
+	public static DPath circle(float x, float y, float radius) {
14
+		// see http://spencermortensen.com/articles/bezier-circle/
15
+		return tracer -> {
16
+			float c = radius * 0.551915024494f;
17
+			tracer.moveTo(x, y + radius);
18
+			tracer.bezierCubic(
19
+					x + c, y + radius,
20
+					x + radius, y + c,
21
+					x + radius, y);
22
+			tracer.bezierCubic(
23
+					x + radius, y - c,
24
+					x + c, y - radius,
25
+					x, y - radius);
26
+			tracer.bezierCubic(
27
+					x - c, y - radius,
28
+					x - radius, y - c,
29
+					x - radius, y);
30
+			tracer.bezierCubic(
31
+					x - radius, y + c,
32
+					x - c, y + radius,
33
+					x, y + radius);
34
+		};
35
+	}
36
+	
37
+	public static DPath roundedRectangle(float x, float y, float width, float height, float radius) {
38
+		return tracer -> {
39
+			float c = radius - radius * 0.551915024494f;
40
+			tracer.moveTo(x + width - radius, y + height);
41
+			tracer.bezierCubic(
42
+					x + width - c, y + height,
43
+					x + width, y + height - c,
44
+					x + width, y + height - radius);
45
+			tracer.lineTo(x + width, y + radius);
46
+			tracer.bezierCubic(
47
+					x + width, y + c,
48
+					x + width - c, y,
49
+					x + width - radius, y);
50
+			tracer.lineTo(x + radius, y);
51
+			tracer.bezierCubic(
52
+					x + c, y,
53
+					x, y + c,
54
+					x, y + radius);
55
+			tracer.lineTo(x, y + height - radius);
56
+			tracer.bezierCubic(
57
+					x, y + height - c,
58
+					x + c, y + height,
59
+					x + radius, y + height);
60
+			tracer.close();
61
+		};
62
+	}
63
+	
13 64
 	void trace(DPathTracer tracer);
14 65
 }

+ 72
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DPathBoundsCalculator.java Bestand weergeven

@@ -0,0 +1,72 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.listeners.DIRectangle;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class DPathBoundsCalculator implements DPathTracer {
15
+	public static DIRectangle getBounds(DPath path, DTransform2D transform) {
16
+		DPathBoundsCalculator calculator = new DPathBoundsCalculator(transform);
17
+		path.trace(calculator);
18
+		return new DIRectangle(
19
+				(int)calculator.minX,
20
+				(int)calculator.minY,
21
+				(int)Math.ceil(calculator.maxX - calculator.minX),
22
+				(int)Math.ceil(calculator.maxY - calculator.minY));
23
+	}
24
+	
25
+	private final DTransform2D transform;
26
+	private float minX = Float.MAX_VALUE;
27
+	private float minY = Float.MAX_VALUE;
28
+	private float maxX = Float.MIN_VALUE;
29
+	private float maxY = Float.MIN_VALUE;
30
+	
31
+	private DPathBoundsCalculator(DTransform2D transform) {
32
+		this.transform = transform;
33
+	}
34
+	
35
+	private void add(float x, float y) {
36
+		float tx = transform.getX(x, y);
37
+		float ty = transform.getY(x, y);
38
+		
39
+		minX = Math.min(minX, tx);
40
+		minY = Math.min(minY, ty);
41
+		maxX = Math.max(maxX, tx);
42
+		maxY = Math.max(maxY, ty);
43
+	}
44
+
45
+	@Override
46
+	public void moveTo(float x, float y) {
47
+		add(x, y);
48
+	}
49
+
50
+	@Override
51
+	public void lineTo(float x, float y) {
52
+		add(x, y);
53
+	}
54
+
55
+	@Override
56
+	public void bezierCubic(float x1, float y1, float x2, float y2, float x3, float y3) {
57
+		add(x1, y1);
58
+		add(x2, y2);
59
+		add(x3, y3);
60
+	}
61
+
62
+	@Override
63
+	public void bezierQuadratic(float x1, float y1, float x2, float y2) {
64
+		add(x1, y1);
65
+		add(x2, y2);
66
+	}
67
+
68
+	@Override
69
+	public void close() {
70
+		
71
+	}
72
+}

+ 35
- 16
DrawableGui/src/main/java/org/openzen/drawablegui/DSideLayout.java Bestand weergeven

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
+import org.openzen.drawablegui.listeners.DIRectangle;
8 9
 import java.io.Closeable;
9 10
 import java.util.ArrayList;
10 11
 import java.util.List;
@@ -13,47 +14,58 @@ import java.util.function.Predicate;
13 14
 import org.openzen.drawablegui.listeners.ListenerHandle;
14 15
 import org.openzen.drawablegui.live.LiveObject;
15 16
 import org.openzen.drawablegui.live.SimpleLiveObject;
17
+import org.openzen.drawablegui.style.DStyleClass;
18
+import org.openzen.drawablegui.style.DStylePath;
16 19
 
17 20
 /**
18 21
  *
19 22
  * @author Hoofdgebruiker
20 23
  */
21 24
 public class DSideLayout extends BaseComponentGroup {
25
+	private final DStyleClass styleClass;
26
+	
22 27
 	private DComponent main;
23 28
 	private final List<SideComponent> sides = new ArrayList<>();
24 29
 	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
25 30
 	
26
-	private DDrawingContext context;
27
-	private DRectangle bounds;
31
+	private DStylePath path;
32
+	private DUIContext context;
33
+	private DIRectangle bounds;
28 34
 	
29
-	public DSideLayout(DComponent main) {
35
+	public DSideLayout(DStyleClass styleClass, DComponent main) {
36
+		this.styleClass = styleClass;
30 37
 		this.main = main;
31 38
 	}
32 39
 	
33 40
 	public void add(Side side, DComponent component) {
34 41
 		if (context != null)
35
-			component.setContext(context);
42
+			component.setContext(path, context);
36 43
 		
37 44
 		sides.add(new SideComponent(side, component));
38 45
 	}
39 46
 	
40 47
 	public void setMain(DComponent component) {
48
+		if (this.main != null)
49
+			this.main.close();
50
+		
41 51
 		this.main = component;
42
-		main.setContext(context);
52
+		main.setContext(path, context);
43 53
 		setBounds(bounds);
44
-		context.repaint(bounds.x, bounds.y, bounds.width, bounds.height);
54
+		context.repaint(bounds);
45 55
 	}
46 56
 
47 57
 	@Override
48
-	public void setContext(DDrawingContext context) {
58
+	public void setContext(DStylePath parent, DUIContext context) {
49 59
 		this.context = context;
50
-		main.setContext(context);
60
+		this.path = parent.getChild("sidelayout", styleClass);
61
+		
62
+		main.setContext(path, context);
51 63
 		for (SideComponent side : sides)
52
-			side.component.setContext(context);
64
+			side.component.setContext(path, context);
53 65
 	}
54 66
 	
55 67
 	@Override
56
-	public DRectangle getBounds() {
68
+	public DIRectangle getBounds() {
57 69
 		return bounds;
58 70
 	}
59 71
 
@@ -63,7 +75,7 @@ public class DSideLayout extends BaseComponentGroup {
63 75
 	}
64 76
 
65 77
 	@Override
66
-	public void setBounds(DRectangle bounds) {
78
+	public void setBounds(DIRectangle bounds) {
67 79
 		this.bounds = bounds;
68 80
 		
69 81
 		int left = bounds.x;
@@ -86,7 +98,7 @@ public class DSideLayout extends BaseComponentGroup {
86 98
 						componentWidth = preferences.maximumWidth;
87 99
 					}
88 100
 					
89
-					side.component.setBounds(new DRectangle(componentX, componentY, componentWidth, componentHeight));
101
+					side.component.setBounds(new DIRectangle(componentX, componentY, componentWidth, componentHeight));
90 102
 					top += componentHeight;
91 103
 					break;
92 104
 				}
@@ -102,7 +114,7 @@ public class DSideLayout extends BaseComponentGroup {
102 114
 						componentWidth = preferences.maximumWidth;
103 115
 					}
104 116
 					
105
-					side.component.setBounds(new DRectangle(componentX, componentY, componentWidth, componentHeight));
117
+					side.component.setBounds(new DIRectangle(componentX, componentY, componentWidth, componentHeight));
106 118
 					break;
107 119
 				}
108 120
 				case LEFT: {
@@ -116,7 +128,7 @@ public class DSideLayout extends BaseComponentGroup {
116 128
 						componentHeight = preferences.maximumHeight;
117 129
 					}
118 130
 					
119
-					side.component.setBounds(new DRectangle(componentX, componentY, componentWidth, componentHeight));
131
+					side.component.setBounds(new DIRectangle(componentX, componentY, componentWidth, componentHeight));
120 132
 					left += componentWidth;
121 133
 					break;
122 134
 				}
@@ -132,13 +144,13 @@ public class DSideLayout extends BaseComponentGroup {
132 144
 						componentHeight = preferences.maximumHeight;
133 145
 					}
134 146
 					
135
-					side.component.setBounds(new DRectangle(componentX, componentY, componentWidth, componentHeight));
147
+					side.component.setBounds(new DIRectangle(componentX, componentY, componentWidth, componentHeight));
136 148
 					break;
137 149
 				}
138 150
 			}
139 151
 		}
140 152
 		
141
-		main.setBounds(new DRectangle(left, top, right - left, bottom - top));
153
+		main.setBounds(new DIRectangle(left, top, right - left, bottom - top));
142 154
 	}
143 155
 
144 156
 	@Override
@@ -208,6 +220,13 @@ public class DSideLayout extends BaseComponentGroup {
208 220
 		
209 221
 		return null;
210 222
 	}
223
+
224
+	@Override
225
+	public void close() {
226
+		main.close();
227
+		for (SideComponent side : sides)
228
+			side.close();
229
+	}
211 230
 	
212 231
 	public class SideComponent implements Closeable, LiveObject.Listener<DDimensionPreferences> {
213 232
 		public final Side side;

+ 16
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DTransform2D.java Bestand weergeven

@@ -16,6 +16,10 @@ public final class DTransform2D {
16 16
 		return new DTransform2D(1, 0, 0, 1, x, y);
17 17
 	}
18 18
 	
19
+	public static DTransform2D scaleAndTranslate(float x, float y, float scale) {
20
+		return new DTransform2D(scale, 0, 0, scale, x, y);
21
+	}
22
+	
19 23
 	public static DTransform2D scale(float scale) {
20 24
 		return new DTransform2D(scale, 0, 0, scale, 0, 0);
21 25
 	}
@@ -35,4 +39,16 @@ public final class DTransform2D {
35 39
 		this.dx = dx;
36 40
 		this.dy = dy;
37 41
 	}
42
+	
43
+	public DTransform2D offset(float x, float y) {
44
+		return new DTransform2D(xx, xy, yx, yy, dx + x, dy + y);
45
+	}
46
+	
47
+	public float getX(float x, float y) {
48
+		return x * xx + y * xy + dx;
49
+	}
50
+	
51
+	public float getY(float x, float y) {
52
+		return x * yx + y * yy + dy;
53
+	}
38 54
 }

DrawableGui/src/main/java/org/openzen/drawablegui/DDrawingContext.java → DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java Bestand weergeven

@@ -5,15 +5,24 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
+import org.openzen.drawablegui.listeners.DIRectangle;
9
+import org.openzen.drawablegui.style.DStyleSheets;
10
+
8 11
 /**
9 12
  *
10 13
  * @author Hoofdgebruiker
11 14
  */
12
-public interface DDrawingContext {
15
+public interface DUIContext {
16
+	DStyleSheets getStylesheets();
17
+	
13 18
 	float getScale();
14 19
 	
15 20
 	void repaint(int x, int y, int width, int height);
16 21
 	
22
+	default void repaint(DIRectangle rectangle) {
23
+		repaint(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
24
+	}
25
+	
17 26
 	void setCursor(Cursor cursor);
18 27
 	
19 28
 	void focus(DComponent component);

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/border/DBorder.java Bestand weergeven

@@ -5,15 +5,15 @@
5 5
  */
6 6
 package org.openzen.drawablegui.border;
7 7
 
8
-import org.openzen.drawablegui.DRectangle;
9 8
 import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.listeners.DIRectangle;
10 10
 
11 11
 /**
12 12
  *
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public interface DBorder {
16
-	public void paint(DCanvas canvas, DRectangle bounds);
16
+	public void paint(DCanvas canvas, DIRectangle bounds);
17 17
 	
18 18
 	public int getPaddingLeft();
19 19
 	

+ 4
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/border/DEmptyBorder.java Bestand weergeven

@@ -5,8 +5,9 @@
5 5
  */
6 6
 package org.openzen.drawablegui.border;
7 7
 
8
-import org.openzen.drawablegui.DRectangle;
9 8
 import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.listeners.DIRectangle;
10
+import org.openzen.drawablegui.DUIContext;
10 11
 
11 12
 /**
12 13
  *
@@ -14,9 +15,9 @@ import org.openzen.drawablegui.DCanvas;
14 15
  */
15 16
 public class DEmptyBorder implements DBorder {
16 17
 	public static final DEmptyBorder INSTANCE = new DEmptyBorder();
17
-
18
+	
18 19
 	@Override
19
-	public void paint(DCanvas canvas, DRectangle bounds) {
20
+	public void paint(DCanvas canvas, DIRectangle bounds) {
20 21
 		
21 22
 	}
22 23
 

+ 3
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/border/DLineBorder.java Bestand weergeven

@@ -5,9 +5,10 @@
5 5
  */
6 6
 package org.openzen.drawablegui.border;
7 7
 
8
-import org.openzen.drawablegui.DRectangle;
9 8
 import org.openzen.drawablegui.DCanvas;
10 9
 import org.openzen.drawablegui.DTransform2D;
10
+import org.openzen.drawablegui.listeners.DIRectangle;
11
+import org.openzen.drawablegui.DUIContext;
11 12
 
12 13
 /**
13 14
  *
@@ -23,7 +24,7 @@ public class DLineBorder implements DBorder {
23 24
 	}
24 25
 
25 26
 	@Override
26
-	public void paint(DCanvas canvas, DRectangle bounds) {
27
+	public void paint(DCanvas canvas, DIRectangle bounds) {
27 28
 		canvas.strokePath(tracer -> {
28 29
 				tracer.moveTo(bounds.x, bounds.y);
29 30
 				tracer.lineTo(bounds.x + bounds.width - borderWidth, bounds.y);

+ 20
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/dimension/DDimension.java Bestand weergeven

@@ -0,0 +1,20 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.dimension;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface DDimension {
15
+	float eval(DUIContext context);
16
+	
17
+	default int evalInt(DUIContext context) {
18
+		return (int)(eval(context) + 0.5f);
19
+	}
20
+}

+ 25
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/dimension/DDpDimension.java Bestand weergeven

@@ -0,0 +1,25 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.dimension;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class DDpDimension implements DDimension {
15
+	private final float value;
16
+	
17
+	public DDpDimension(float value) {
18
+		this.value = value;
19
+	}
20
+
21
+	@Override
22
+	public float eval(DUIContext context) {
23
+		return value * context.getScale();
24
+	}
25
+}

+ 25
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/dimension/DPxDimension.java Bestand weergeven

@@ -0,0 +1,25 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.dimension;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class DPxDimension implements DDimension {
15
+	private final float pixels;
16
+	
17
+	public DPxDimension(float pixels) {
18
+		this.pixels = pixels;
19
+	}
20
+
21
+	@Override
22
+	public float eval(DUIContext context) {
23
+		return pixels;
24
+	}
25
+}

DrawableGui/src/main/java/org/openzen/drawablegui/DRectangle.java → DrawableGui/src/main/java/org/openzen/drawablegui/listeners/DIRectangle.java Bestand weergeven

@@ -3,19 +3,19 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.drawablegui;
6
+package org.openzen.drawablegui.listeners;
7 7
 
8 8
 /**
9 9
  *
10 10
  * @author Hoofdgebruiker
11 11
  */
12
-public final class DRectangle {
12
+public class DIRectangle {
13 13
 	public final int x;
14 14
 	public final int y;
15 15
 	public final int width;
16 16
 	public final int height;
17 17
 	
18
-	public DRectangle(int x, int y, int width, int height) {
18
+	public DIRectangle(int x, int y, int width, int height) {
19 19
 		this.x = x;
20 20
 		this.y = y;
21 21
 		this.width = width;

+ 26
- 16
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBar.java Bestand weergeven

@@ -5,33 +5,36 @@
5 5
  */
6 6
 package org.openzen.drawablegui.scroll;
7 7
 
8
-import org.openzen.drawablegui.DRectangle;
9 8
 import org.openzen.drawablegui.DCanvas;
10 9
 import org.openzen.drawablegui.DComponent;
11 10
 import org.openzen.drawablegui.DDimensionPreferences;
12
-import org.openzen.drawablegui.DDrawingContext;
13 11
 import org.openzen.drawablegui.DMouseEvent;
12
+import org.openzen.drawablegui.listeners.DIRectangle;
14 13
 import org.openzen.drawablegui.listeners.ListenerHandle;
15
-import org.openzen.drawablegui.live.ImmutableLiveObject;
16 14
 import org.openzen.drawablegui.live.LiveInt;
17 15
 import org.openzen.drawablegui.live.LiveObject;
16
+import org.openzen.drawablegui.live.SimpleLiveObject;
17
+import org.openzen.drawablegui.DUIContext;
18
+import org.openzen.drawablegui.style.DStyleClass;
19
+import org.openzen.drawablegui.style.DStylePath;
18 20
 
19 21
 /**
20 22
  *
21 23
  * @author Hoofdgebruiker
22 24
  */
23 25
 public class DScrollBar implements DComponent {
24
-	private final DScrollBarStyle style;
25 26
 	private final LiveObject<DDimensionPreferences> preferences;
26 27
 	
28
+	private final DStyleClass styleClass;
27 29
 	private final LiveInt targetHeight;
28 30
 	private final LiveInt offset;
29 31
 	
30 32
 	private final ListenerHandle<LiveInt.Listener> targetHeightListener;
31 33
 	private final ListenerHandle<LiveInt.Listener> offsetListener;
32 34
 	
33
-	private DDrawingContext context;
34
-	private DRectangle bounds;
35
+	private DUIContext context;
36
+	private DScrollBarStyle style;
37
+	private DIRectangle bounds;
35 38
 	
36 39
 	private int fromY = 0;
37 40
 	private int toY = 0;
@@ -40,19 +43,21 @@ public class DScrollBar implements DComponent {
40 43
 	private int dragStartOffset;
41 44
 	private int dragStartY;
42 45
 	
43
-	public DScrollBar(DScrollBarStyle style, LiveInt targetHeight, LiveInt offset) {
44
-		this.style = style;
46
+	public DScrollBar(DStyleClass styleClass, LiveInt targetHeight, LiveInt offset) {
47
+		this.styleClass = styleClass;
45 48
 		this.targetHeight = targetHeight;
46 49
 		this.offset = offset;
47
-		this.preferences = new ImmutableLiveObject<>(new DDimensionPreferences(style.width, 0));
50
+		this.preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
48 51
 		
49 52
 		targetHeightListener = targetHeight.addListener(new ScrollListener());
50 53
 		offsetListener = offset.addListener(new ScrollListener());
51 54
 	}
52 55
 
53 56
 	@Override
54
-	public void setContext(DDrawingContext context) {
57
+	public void setContext(DStylePath parent, DUIContext context) {
55 58
 		this.context = context;
59
+		this.style = new DScrollBarStyle(context.getStylesheets().get(context, parent.getChild("scrollbar", styleClass)));
60
+		preferences.setValue(new DDimensionPreferences(style.width, 0));
56 61
 	}
57 62
 
58 63
 	@Override
@@ -61,12 +66,12 @@ public class DScrollBar implements DComponent {
61 66
 	}
62 67
 
63 68
 	@Override
64
-	public DRectangle getBounds() {
69
+	public DIRectangle getBounds() {
65 70
 		return bounds;
66 71
 	}
67 72
 
68 73
 	@Override
69
-	public void setBounds(DRectangle bounds) {
74
+	public void setBounds(DIRectangle bounds) {
70 75
 		this.bounds = bounds;
71 76
 		recalculate();
72 77
 	}
@@ -84,7 +89,7 @@ public class DScrollBar implements DComponent {
84 89
 		if (dragging)
85 90
 			color = style.scrollBarPressColor;
86 91
 		
87
-		canvas.fillRectangle(bounds.x, bounds.y + fromY, this.bounds.width, toY - fromY, color);
92
+		canvas.fillRectangle(bounds.x, fromY, this.bounds.width, toY - fromY, color);
88 93
 	}
89 94
 	
90 95
 	@Override
@@ -125,6 +130,11 @@ public class DScrollBar implements DComponent {
125 130
 	public void onMouseRelease(DMouseEvent e) {
126 131
 		setDragging(false);
127 132
 	}
133
+
134
+	@Override
135
+	public void close() {
136
+		// nothing to clean up
137
+	}
128 138
 	
129 139
 	private void checkHover(DMouseEvent e) {
130 140
 		setHovering(e.y >= fromY && e.y < toY);
@@ -147,11 +157,11 @@ public class DScrollBar implements DComponent {
147 157
 	}
148 158
 	
149 159
 	private void recalculate() {
150
-		if (targetHeight.getValue() == 0)
160
+		if (targetHeight.getValue() == 0 || bounds == null)
151 161
 			return;
152 162
 		
153
-		fromY = this.bounds.height * offset.getValue() / targetHeight.getValue();
154
-		toY = this.bounds.height * (offset.getValue() + this.bounds.height) / targetHeight.getValue();
163
+		fromY = bounds.y + this.bounds.height * offset.getValue() / targetHeight.getValue();
164
+		toY = bounds.y + this.bounds.height * (offset.getValue() + this.bounds.height) / targetHeight.getValue();
155 165
 	}
156 166
 	
157 167
 	private class ScrollListener implements LiveInt.Listener {

+ 11
- 13
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBarStyle.java Bestand weergeven

@@ -5,29 +5,27 @@
5 5
  */
6 6
 package org.openzen.drawablegui.scroll;
7 7
 
8
+import org.openzen.drawablegui.dimension.DDimension;
9
+import org.openzen.drawablegui.dimension.DDpDimension;
10
+import org.openzen.drawablegui.DUIContext;
11
+import org.openzen.drawablegui.style.DStyleDefinition;
12
+
8 13
 /**
9 14
  *
10 15
  * @author Hoofdgebruiker
11 16
  */
12 17
 public class DScrollBarStyle {
13
-	public static final DScrollBarStyle DEFAULT = new DScrollBarStyle(0xFFF0F0F0, 0xFFCDCDCD, 0xFF888888, 0xFF666666, 20);
14
-	
15 18
 	public final int scrollBarBackgroundColor;
16 19
 	public final int scrollBarNormalColor;
17 20
 	public final int scrollBarHoverColor;
18 21
 	public final int scrollBarPressColor;
19 22
 	public final int width;
20 23
 	
21
-	public DScrollBarStyle(
22
-			int scrollBarBackgroundColor,
23
-			int scrollBarNormalColor,
24
-			int scrollBarHoverColor,
25
-			int scrollBarPressColor,
26
-			int width) {
27
-		this.scrollBarBackgroundColor = scrollBarBackgroundColor;
28
-		this.scrollBarNormalColor = scrollBarNormalColor;
29
-		this.scrollBarHoverColor = scrollBarHoverColor;
30
-		this.scrollBarPressColor = scrollBarPressColor;
31
-		this.width = width;
24
+	public DScrollBarStyle(DStyleDefinition style) {
25
+		this.scrollBarBackgroundColor = style.getColor("scrollbar.background.color", 0xFFF0F0F0);
26
+		this.scrollBarNormalColor = style.getColor("scrollbar.color.normal", 0xFFCDCDCD);
27
+		this.scrollBarHoverColor = style.getColor("scrollbar.color.hover", 0xFF888888);
28
+		this.scrollBarPressColor = style.getColor("scrollbar.color.press", 0xFF666666);
29
+		this.width = style.getDimension("width", new DDpDimension(12));
32 30
 	}
33 31
 }

+ 42
- 19
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java Bestand weergeven

@@ -5,33 +5,36 @@
5 5
  */
6 6
 package org.openzen.drawablegui.scroll;
7 7
 
8
-import org.openzen.drawablegui.DRectangle;
9 8
 import org.openzen.drawablegui.DCanvas;
10 9
 import org.openzen.drawablegui.DClipboard;
11 10
 import org.openzen.drawablegui.DComponent;
12 11
 import org.openzen.drawablegui.DDimensionPreferences;
13
-import org.openzen.drawablegui.DDrawingContext;
14 12
 import org.openzen.drawablegui.DFont;
15 13
 import org.openzen.drawablegui.DFontMetrics;
16
-import org.openzen.drawablegui.DIRectangle;
14
+import org.openzen.drawablegui.listeners.DIRectangle;
17 15
 import org.openzen.drawablegui.DMouseEvent;
18 16
 import org.openzen.drawablegui.DTimerHandle;
19 17
 import org.openzen.drawablegui.listeners.ListenerHandle;
20 18
 import org.openzen.drawablegui.live.LiveInt;
21 19
 import org.openzen.drawablegui.live.LiveObject;
22 20
 import org.openzen.drawablegui.live.SimpleLiveInt;
21
+import org.openzen.drawablegui.DUIContext;
22
+import org.openzen.drawablegui.style.DStyleClass;
23
+import org.openzen.drawablegui.style.DStylePath;
24
+import org.openzen.drawablegui.style.DStyleSheets;
23 25
 
24 26
 /**
25 27
  *
26 28
  * @author Hoofdgebruiker
27 29
  */
28 30
 public class DScrollPane implements DComponent {
29
-	private final DScrollPaneStyle style;
31
+	private final DStyleClass styleClass;
30 32
 	private final DComponent contents;
31 33
 	private final DScrollBar scrollBar;
32
-	private DDrawingContext context;
33
-	private DRectangle bounds;
34
+	private DUIContext context;
35
+	private DIRectangle bounds;
34 36
 	
37
+	private DScrollPaneStyle style;
35 38
 	private final LiveInt contentsHeight;
36 39
 	private final LiveInt offsetX;
37 40
 	private final LiveInt offsetY;
@@ -42,15 +45,15 @@ public class DScrollPane implements DComponent {
42 45
 	
43 46
 	private DComponent hovering = null;
44 47
 	
45
-	public DScrollPane(DScrollPaneStyle style, DComponent contents) {
46
-		this.style = style;
48
+	public DScrollPane(DStyleClass styleClass, DComponent contents) {
49
+		this.styleClass = styleClass;
47 50
 		this.contents = contents;
48 51
 		
49 52
 		contentsHeight = new SimpleLiveInt();
50 53
 		offsetX = new SimpleLiveInt();
51 54
 		offsetY = new SimpleLiveInt();
52 55
 		
53
-		scrollBar = new DScrollBar(style.scrollBarStyle, contentsHeight, offsetY);
56
+		scrollBar = new DScrollBar(DStyleClass.EMPTY, contentsHeight, offsetY);
54 57
 		
55 58
 		contentsHeightListener = contentsHeight.addListener(new ScrollListener());
56 59
 		offsetXListener = offsetX.addListener(new ScrollListener());
@@ -60,16 +63,22 @@ public class DScrollPane implements DComponent {
60 63
 			if (bounds == null)
61 64
 				return;
62 65
 			
63
-			contents.setBounds(new DRectangle(0, 0, bounds.width, Math.max(bounds.height, newPreferences.preferredHeight)));
66
+			contents.setBounds(new DIRectangle(0, 0, bounds.width, Math.max(bounds.height, newPreferences.preferredHeight)));
64 67
 			contentsHeight.setValue(newPreferences.preferredHeight);
65 68
 		});
66 69
 	}
67 70
 
68 71
 	@Override
69
-	public void setContext(DDrawingContext context) {
72
+	public void setContext(DStylePath parent, DUIContext context) {
70 73
 		this.context = context;
71
-		contents.setContext(new TranslatedContext());
72
-		scrollBar.setContext(context);
74
+		
75
+		DStylePath path = parent.getChild("scrollpane", styleClass);
76
+		contents.setContext(path, new TranslatedContext());
77
+		scrollBar.setContext(path, context);
78
+		style = new DScrollPaneStyle(context.getStylesheets().get(context, path));
79
+		
80
+		if (bounds != null)
81
+			setBounds(bounds);
73 82
 	}
74 83
 
75 84
 	@Override
@@ -78,23 +87,27 @@ public class DScrollPane implements DComponent {
78 87
 	}
79 88
 
80 89
 	@Override
81
-	public DRectangle getBounds() {
90
+	public DIRectangle getBounds() {
82 91
 		return bounds;
83 92
 	}
84 93
 
85 94
 	@Override
86
-	public void setBounds(DRectangle bounds) {
95
+	public void setBounds(DIRectangle bounds) {
87 96
 		this.bounds = bounds;
97
+		
98
+		if (this.context == null)
99
+			return;
100
+		
88 101
 		int height = Math.max(
89 102
 				bounds.height - style.border.getPaddingTop() - style.border.getPaddingBottom(),
90 103
 				contents.getDimensionPreferences().getValue().preferredHeight);
91 104
 		int scrollBarWidth = scrollBar.getDimensionPreferences().getValue().preferredWidth;
92
-		scrollBar.setBounds(new DRectangle(
105
+		scrollBar.setBounds(new DIRectangle(
93 106
 				bounds.x + bounds.width - scrollBarWidth - style.border.getPaddingRight(),
94 107
 				bounds.y + style.border.getPaddingTop(),
95 108
 				scrollBarWidth,
96 109
 				bounds.height - style.border.getPaddingTop() - style.border.getPaddingBottom()));
97
-		contents.setBounds(new DRectangle(0, 0, bounds.width - scrollBar.getBounds().width, height));
110
+		contents.setBounds(new DIRectangle(0, 0, bounds.width - scrollBar.getBounds().width, height));
98 111
 		contentsHeight.setValue(height);
99 112
 	}
100 113
 
@@ -178,6 +191,11 @@ public class DScrollPane implements DComponent {
178 191
 		
179 192
 		onMouseMove(e);
180 193
 	}
194
+
195
+	@Override
196
+	public void close() {
197
+		contents.close();
198
+	}
181 199
 	
182 200
 	private DMouseEvent forward(DComponent target, DMouseEvent e) {
183 201
 		return target == contents ? translateMouseEvent(e) : e;
@@ -203,7 +221,12 @@ public class DScrollPane implements DComponent {
203 221
 				e.clickCount);
204 222
 	}
205 223
 	
206
-	private class TranslatedContext implements DDrawingContext {
224
+	private class TranslatedContext implements DUIContext {
225
+		
226
+		@Override
227
+		public DStyleSheets getStylesheets(){
228
+			return context.getStylesheets();
229
+		}
207 230
 
208 231
 		@Override
209 232
 		public float getScale() {
@@ -275,7 +298,7 @@ public class DScrollPane implements DComponent {
275 298
 			if (value != offsetY.getValue())
276 299
 				offsetY.setValue(value);
277 300
 			if (context != null && bounds != null)
278
-				context.repaint(bounds.x, bounds.y, bounds.width, bounds.height);
301
+				context.repaint(bounds);
279 302
 		}
280 303
 	}
281 304
 }

+ 4
- 8
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPaneStyle.java Bestand weergeven

@@ -7,21 +7,17 @@ package org.openzen.drawablegui.scroll;
7 7
 
8 8
 import org.openzen.drawablegui.border.DBorder;
9 9
 import org.openzen.drawablegui.border.DLineBorder;
10
+import org.openzen.drawablegui.DUIContext;
11
+import org.openzen.drawablegui.style.DStyleDefinition;
10 12
 
11 13
 /**
12 14
  *
13 15
  * @author Hoofdgebruiker
14 16
  */
15 17
 public class DScrollPaneStyle {
16
-	public static final DScrollPaneStyle DEFAULT = new DScrollPaneStyle(new DLineBorder(0xFF888888, 1), DScrollBarStyle.DEFAULT);
17
-	
18 18
 	public final DBorder border;
19
-	public final DScrollBarStyle scrollBarStyle;
20 19
 	
21
-	public DScrollPaneStyle(
22
-			DBorder border,
23
-			DScrollBarStyle scrollBarStyle) {
24
-		this.border = border;
25
-		this.scrollBarStyle = scrollBarStyle;
20
+	public DScrollPaneStyle(DStyleDefinition style) {
21
+		this.border = style.getBorder("border", context -> new DLineBorder(0xFF888888, 1));
26 22
 	}
27 23
 }

+ 49
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStyleDefinition.java Bestand weergeven

@@ -0,0 +1,49 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.style;
7
+
8
+import java.util.function.Function;
9
+import org.openzen.drawablegui.DFont;
10
+import org.openzen.drawablegui.DUIContext;
11
+import org.openzen.drawablegui.border.DBorder;
12
+import org.openzen.drawablegui.dimension.DDimension;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class DEmptyStyleDefinition implements DStyleDefinition {
19
+	private final DUIContext context;
20
+	
21
+	public DEmptyStyleDefinition(DUIContext context) {
22
+		this.context = context;
23
+	}
24
+
25
+	@Override
26
+	public int getDimension(String name, DDimension defaultValue) {
27
+		return defaultValue.evalInt(context);
28
+	}
29
+	
30
+	@Override
31
+	public float getFloatDimension(String name, DDimension defaultValue) {
32
+		return defaultValue.eval(context);
33
+	}
34
+
35
+	@Override
36
+	public int getColor(String name, int defaultValue) {
37
+		return defaultValue;
38
+	}
39
+
40
+	@Override
41
+	public DFont getFont(String name, Function<DUIContext, DFont> defaultValue) {
42
+		return defaultValue.apply(context);
43
+	}
44
+
45
+	@Override
46
+	public DBorder getBorder(String name, Function<DUIContext, DBorder> defaultValue) {
47
+		return defaultValue.apply(context);
48
+	}
49
+}

+ 21
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DEmptyStylesheets.java Bestand weergeven

@@ -0,0 +1,21 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.style;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class DEmptyStylesheets implements DStyleSheets {
15
+	public static final DEmptyStylesheets INSTANCE = new DEmptyStylesheets();
16
+
17
+	@Override
18
+	public DStyleDefinition get(DUIContext context, DStylePath path) {
19
+		return new DEmptyStyleDefinition(context);
20
+	}
21
+}

+ 27
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleClass.java Bestand weergeven

@@ -0,0 +1,27 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.style;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class DStyleClass {
13
+	private static final String[] NO_CLASSES = new String[0];
14
+	public static final DStyleClass EMPTY = new DStyleClass(null, NO_CLASSES);
15
+	
16
+	public static DStyleClass forId(String id) {
17
+		return new DStyleClass(id, NO_CLASSES);
18
+	}
19
+	
20
+	public final String id;
21
+	public final String[] classes;
22
+	
23
+	public DStyleClass(String id, String[] classes) {
24
+		this.id = id;
25
+		this.classes = classes;
26
+	}
27
+}

+ 28
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleDefinition.java Bestand weergeven

@@ -0,0 +1,28 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.style;
7
+
8
+import java.util.function.Function;
9
+import org.openzen.drawablegui.DFont;
10
+import org.openzen.drawablegui.DUIContext;
11
+import org.openzen.drawablegui.border.DBorder;
12
+import org.openzen.drawablegui.dimension.DDimension;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public interface DStyleDefinition {
19
+	public int getDimension(String name, DDimension defaultValue);
20
+	
21
+	public float getFloatDimension(String name, DDimension defaultValue);
22
+	
23
+	public int getColor(String name, int defaultValue);
24
+	
25
+	public DFont getFont(String name, Function<DUIContext, DFont> defaultValue);
26
+	
27
+	public DBorder getBorder(String name, Function<DUIContext, DBorder> defaultValue);
28
+}

IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEStyle.java → DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylePath.java Bestand weergeven

@@ -3,16 +3,12 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.ide.ui;
6
+package org.openzen.drawablegui.style;
7 7
 
8 8
 /**
9 9
  *
10 10
  * @author Hoofdgebruiker
11 11
  */
12
-public class IDEStyle {
13
-	public final int primaryColor;
14
-	
15
-	public IDEStyle(int primaryColor) {
16
-		this.primaryColor = primaryColor;
17
-	}
12
+public interface DStylePath {
13
+	public DStylePath getChild(String element, DStyleClass styleClass);
18 14
 }

+ 38
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStylePathRoot.java Bestand weergeven

@@ -0,0 +1,38 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.style;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class DStylePathRoot implements DStylePath {
13
+	public static final DStylePathRoot INSTANCE = new DStylePathRoot();
14
+	
15
+	private DStylePathRoot() {}
16
+
17
+	@Override
18
+	public DStylePath getChild(String element, DStyleClass styleClass) {
19
+		return new DStyleChildElement(this, element, styleClass);
20
+	}
21
+	
22
+	private static class DStyleChildElement implements DStylePath {
23
+		private final DStylePath parent;
24
+		private final String element;
25
+		private final DStyleClass styleClass;
26
+		
27
+		public DStyleChildElement(DStylePath parent, String element, DStyleClass styleClass) {
28
+			this.parent = parent;
29
+			this.element = element;
30
+			this.styleClass = styleClass;
31
+		}
32
+
33
+		@Override
34
+		public DStylePath getChild(String element, DStyleClass styleClass) {
35
+			return new DStyleChildElement(this, element, styleClass);
36
+		}
37
+	}
38
+}

+ 16
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DStyleSheets.java Bestand weergeven

@@ -0,0 +1,16 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.style;
7
+
8
+import org.openzen.drawablegui.DUIContext;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface DStyleSheets {
15
+	public DStyleDefinition get(DUIContext context, DStylePath path);
16
+}

+ 58
- 13
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingCanvas.java Bestand weergeven

@@ -13,15 +13,18 @@ import java.awt.Rectangle;
13 13
 import java.awt.RenderingHints;
14 14
 import java.awt.geom.AffineTransform;
15 15
 import java.awt.geom.GeneralPath;
16
-import java.awt.geom.Rectangle2D;
16
+import java.awt.image.BufferedImage;
17
+import java.awt.image.ConvolveOp;
18
+import java.awt.image.Kernel;
17 19
 import java.util.Stack;
18 20
 import org.openzen.drawablegui.DCanvas;
19 21
 import org.openzen.drawablegui.DFont;
20 22
 import org.openzen.drawablegui.DFontFamily;
21 23
 import org.openzen.drawablegui.DTransform2D;
22
-import org.openzen.drawablegui.DDrawingContext;
23
-import org.openzen.drawablegui.DIRectangle;
24
+import org.openzen.drawablegui.listeners.DIRectangle;
24 25
 import org.openzen.drawablegui.DPath;
26
+import org.openzen.drawablegui.DPathBoundsCalculator;
27
+import org.openzen.drawablegui.DUIContext;
25 28
 
26 29
 /**
27 30
  *
@@ -82,15 +85,7 @@ public class SwingCanvas implements DCanvas {
82 85
 	}
83 86
 
84 87
 	@Override
85
-	public float measureTextLength(DFont font, String text, int offset, int length) {
86
-		prepare(font);
87
-		g.setFont((Font) font.cached);
88
-		Rectangle2D rect = g.getFontMetrics().getStringBounds(text, offset, length, g);
89
-		return (float) rect.getWidth();
90
-	}
91
-
92
-	@Override
93
-	public DDrawingContext getContext() {
88
+	public DUIContext getContext() {
94 89
 		return context;
95 90
 	}
96 91
 
@@ -117,7 +112,22 @@ public class SwingCanvas implements DCanvas {
117 112
 
118 113
 	@Override
119 114
 	public void shadowPath(DPath path, DTransform2D transform, int color, float dx, float dy, float radius) {
120
-		// TODO
115
+		DIRectangle bounds = DPathBoundsCalculator.getBounds(path, transform.offset(dx, dy));
116
+		int offset = 2 * (int)Math.ceil(radius);
117
+		
118
+		GeneralPath jPath = context.getPath(path);
119
+		
120
+		BufferedImage image = new BufferedImage(bounds.width + 2 * offset, bounds.height + 2 * offset, BufferedImage.TYPE_INT_ARGB);
121
+		Graphics2D imageG = (Graphics2D) image.getGraphics();
122
+		
123
+		imageG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
124
+		imageG.setColor(new Color(color, true));
125
+		imageG.setTransform(getTransform(transform.offset(offset + dx - bounds.x, offset + dy - bounds.y)));
126
+		imageG.fill(jPath);
127
+		
128
+		image = getGaussianBlurFilter((int)Math.ceil(radius), true).filter(image, null);
129
+		image = getGaussianBlurFilter((int)Math.ceil(radius), false).filter(image, null);
130
+		g.drawImage(image, bounds.x - offset, bounds.y - offset, null);
121 131
 	}
122 132
 
123 133
 	@Override
@@ -143,4 +153,39 @@ public class SwingCanvas implements DCanvas {
143 153
 	private AffineTransform getTransform(DTransform2D transform) {
144 154
 		return new AffineTransform(transform.xx, transform.xy, transform.yx, transform.yy, transform.dx, transform.dy);
145 155
 	}
156
+    
157
+	
158
+	// taken from http://www.java2s.com/Code/Java/Advanced-Graphics/GaussianBlurDemo.htm
159
+    public static ConvolveOp getGaussianBlurFilter(int radius, boolean horizontal) {
160
+        if (radius < 1) {
161
+            throw new IllegalArgumentException("Radius must be >= 1");
162
+        }
163
+        
164
+        int size = radius * 2 + 1;
165
+        float[] data = new float[size];
166
+        
167
+        float sigma = radius / 3.0f;
168
+        float twoSigmaSquare = 2.0f * sigma * sigma;
169
+        float sigmaRoot = (float) Math.sqrt(twoSigmaSquare * Math.PI);
170
+        float total = 0.0f;
171
+        
172
+        for (int i = -radius; i <= radius; i++) {
173
+            float distance = i * i;
174
+            int index = i + radius;
175
+            data[index] = (float) Math.exp(-distance / twoSigmaSquare) / sigmaRoot;
176
+            total += data[index];
177
+        }
178
+        
179
+        for (int i = 0; i < data.length; i++) {
180
+            data[i] /= total;
181
+        }        
182
+        
183
+        Kernel kernel = null;
184
+        if (horizontal) {
185
+            kernel = new Kernel(size, 1, data);
186
+        } else {
187
+            kernel = new Kernel(1, size, data);
188
+        }
189
+        return new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
190
+    }
146 191
 }

+ 12
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java Bestand weergeven

@@ -13,24 +13,27 @@ import javax.swing.Timer;
13 13
 import org.openzen.drawablegui.DClipboard;
14 14
 import org.openzen.drawablegui.DComponent;
15 15
 import org.openzen.drawablegui.DPath;
16
-import org.openzen.drawablegui.DDrawingContext;
17 16
 import org.openzen.drawablegui.DFont;
18 17
 import org.openzen.drawablegui.DFontMetrics;
19 18
 import org.openzen.drawablegui.DPathTracer;
20 19
 import org.openzen.drawablegui.DTimerHandle;
20
+import org.openzen.drawablegui.DUIContext;
21
+import org.openzen.drawablegui.style.DStyleSheets;
21 22
 
22 23
 /**
23 24
  *
24 25
  * @author Hoofdgebruiker
25 26
  */
26
-public class SwingGraphicsContext implements DDrawingContext {
27
-	public final float scale;
27
+public class SwingGraphicsContext implements DUIContext {
28
+	private final DStyleSheets stylesheets;
29
+	private final float scale;
28 30
 	private final WeakHashMap<DPath, GeneralPath> preparedPaths = new WeakHashMap<>();
29 31
 	private final SwingRoot root;
30 32
 	private final JavaClipboard clipboard = new JavaClipboard();
31 33
 	private Graphics graphics;
32 34
 	
33
-	public SwingGraphicsContext(float scale, SwingRoot root) {
35
+	public SwingGraphicsContext(DStyleSheets stylesheets, float scale, SwingRoot root) {
36
+		this.stylesheets = stylesheets;
34 37
 		this.scale = scale;
35 38
 		this.root = root;
36 39
 	}
@@ -45,6 +48,11 @@ public class SwingGraphicsContext implements DDrawingContext {
45 48
 		return generalPath;
46 49
 	}
47 50
 	
51
+	@Override
52
+	public DStyleSheets getStylesheets() {
53
+		return stylesheets;
54
+	}
55
+	
48 56
 	@Override
49 57
 	public float getScale() {
50 58
 		return scale;

+ 15
- 6
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java Bestand weergeven

@@ -20,11 +20,12 @@ import java.awt.event.MouseMotionListener;
20 20
 import java.awt.event.MouseWheelEvent;
21 21
 import java.awt.event.MouseWheelListener;
22 22
 import org.openzen.drawablegui.DComponent;
23
-import org.openzen.drawablegui.DIRectangle;
23
+import org.openzen.drawablegui.listeners.DIRectangle;
24 24
 import org.openzen.drawablegui.DKeyEvent;
25 25
 import static org.openzen.drawablegui.DKeyEvent.KeyCode.*;
26 26
 import org.openzen.drawablegui.DMouseEvent;
27
-import org.openzen.drawablegui.DRectangle;
27
+import org.openzen.drawablegui.style.DEmptyStylesheets;
28
+import org.openzen.drawablegui.style.DStylePathRoot;
28 29
 
29 30
 /**
30 31
  *
@@ -34,15 +35,18 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
34 35
 	public final SwingGraphicsContext context;
35 36
 	public final DComponent component;
36 37
 	private DComponent focus = null;
38
+	private boolean firstPaint = true;
37 39
 
38 40
 	public SwingRoot(DComponent root) {
39 41
 		this.component = root;
40 42
 		setFocusable(true);
41 43
 		setFocusTraversalKeysEnabled(false); // prevent tab from being handled by focus traversal
42 44
 		
43
-		context = new SwingGraphicsContext(Toolkit.getDefaultToolkit().getScreenResolution() / 96.0f, this);
44
-		component.setContext(context);
45
-		component.setBounds(new DRectangle(0, 0, getWidth(), getHeight()));
45
+		context = new SwingGraphicsContext(
46
+				DEmptyStylesheets.INSTANCE,
47
+				Toolkit.getDefaultToolkit().getScreenResolution() / 96.0f,
48
+				this);
49
+		component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
46 50
 		addComponentListener(this);
47 51
 		addMouseListener(this);
48 52
 		addMouseMotionListener(this);
@@ -63,6 +67,11 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
63 67
 
64 68
 	@Override
65 69
 	public void paint(Graphics g) {
70
+		if (firstPaint) {
71
+			firstPaint = false;
72
+			component.setContext(DStylePathRoot.INSTANCE, context);
73
+		}
74
+		
66 75
 		Rectangle clipBounds = g.getClipBounds();
67 76
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
68 77
 		SwingCanvas canvas = new SwingCanvas((Graphics2D) g, context, clipBounds2);
@@ -71,7 +80,7 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
71 80
 
72 81
 	@Override
73 82
 	public void componentResized(ComponentEvent e) {
74
-		component.setBounds(new DRectangle(0, 0,
83
+		component.setBounds(new DIRectangle(0, 0,
75 84
 				e.getComponent().getWidth(),
76 85
 				e.getComponent().getHeight()));
77 86
 

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java Bestand weergeven

@@ -8,7 +8,7 @@ package org.openzen.drawablegui.swing;
8 8
 import java.awt.BorderLayout;
9 9
 import javax.swing.JFrame;
10 10
 import org.openzen.drawablegui.DComponent;
11
-import org.openzen.drawablegui.DDrawingContext;
11
+import org.openzen.drawablegui.DUIContext;
12 12
 
13 13
 /**
14 14
  *
@@ -24,7 +24,7 @@ public final class SwingWindow extends JFrame {
24 24
 		swingComponent.requestFocusInWindow();
25 25
 	}
26 26
 	
27
-	public DDrawingContext getContext() {
27
+	public DUIContext getContext() {
28 28
 		return swingComponent.context;
29 29
 	}
30 30
 }

+ 40
- 24
DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java Bestand weergeven

@@ -8,18 +8,20 @@ package org.openzen.drawablegui.tree;
8 8
 import java.io.Closeable;
9 9
 import java.util.ArrayList;
10 10
 import java.util.List;
11
-import org.openzen.drawablegui.DRectangle;
12 11
 import org.openzen.drawablegui.DCanvas;
13 12
 import org.openzen.drawablegui.DComponent;
14 13
 import org.openzen.drawablegui.DDimensionPreferences;
15 14
 import org.openzen.drawablegui.DDrawable;
16
-import org.openzen.drawablegui.DDrawingContext;
15
+import org.openzen.drawablegui.DFontMetrics;
17 16
 import org.openzen.drawablegui.DMouseEvent;
18 17
 import org.openzen.drawablegui.DTransform2D;
18
+import org.openzen.drawablegui.listeners.DIRectangle;
19 19
 import org.openzen.drawablegui.listeners.ListenerHandle;
20 20
 import org.openzen.drawablegui.live.LiveBool;
21 21
 import org.openzen.drawablegui.live.LiveObject;
22 22
 import org.openzen.drawablegui.live.SimpleLiveObject;
23
+import org.openzen.drawablegui.DUIContext;
24
+import org.openzen.drawablegui.style.DStylePath;
23 25
 
24 26
 /**
25 27
  *
@@ -27,28 +29,32 @@ import org.openzen.drawablegui.live.SimpleLiveObject;
27 29
  */
28 30
 public class DTreeView<N extends DTreeNode<N>> implements DComponent {
29 31
 	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
30
-	private DRectangle bounds;
32
+	private DIRectangle bounds;
31 33
 	
32 34
 	private int selectedRow = -1;
33 35
 	private N selectedNode = null;
34 36
 	
35
-	private final DTreeViewStyle style;
37
+	private final DTreeViewStyle styleDefinition;
38
+	private DTreeViewStyle.Calculated style;
39
+	private DFontMetrics fontMetrics;
36 40
 	
37
-	private DDrawingContext context;
41
+	private DUIContext context;
38 42
 	private final N root;
39 43
 	private final boolean showRoot;
40 44
 	private final List<Row> rows = new ArrayList<>();
41 45
 	
42 46
 	public DTreeView(DTreeViewStyle style, N root, boolean showRoot) {
43
-		this.style = style;
44
-		
47
+		this.styleDefinition = style;
45 48
 		this.root = root;
46 49
 		this.showRoot = showRoot;
47 50
 	}
48 51
 
49 52
 	@Override
50
-	public void setContext(DDrawingContext context) {
53
+	public void setContext(DStylePath parent, DUIContext context) {
51 54
 		this.context = context;
55
+		style = styleDefinition.forContext(context);
56
+		fontMetrics = context.getFontMetrics(style.font);
57
+		
52 58
 		updateLayout();
53 59
 	}
54 60
 
@@ -58,18 +64,18 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
58 64
 	}
59 65
 	
60 66
 	@Override
61
-	public DRectangle getBounds() {
67
+	public DIRectangle getBounds() {
62 68
 		return bounds;
63 69
 	}
64 70
 
65 71
 	@Override
66
-	public void setBounds(DRectangle bounds) {
72
+	public void setBounds(DIRectangle bounds) {
67 73
 		this.bounds = bounds;
68 74
 	}
69 75
 
70 76
 	@Override
71 77
 	public void paint(DCanvas canvas) {
72
-		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
78
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, styleDefinition.backgroundColor);
73 79
 		
74 80
 		int drawX = bounds.x + style.padding;
75 81
 		int drawY = bounds.y + style.padding;
@@ -88,7 +94,7 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
88 94
 		int row = yToRow(e.y);
89 95
 		if (row >= 0 && row < rows.size()) {
90 96
 			Row rowEntry = rows.get(row);
91
-			if (e.x >= rowEntry.x && e.x < (rowEntry.x + style.nodeOpenedIcon.getNominalWidth())) {
97
+			if (e.x >= rowEntry.x && e.x < (rowEntry.x + styleDefinition.nodeOpenedIcon.getNominalWidth())) {
92 98
 				if (!rowEntry.node.isLeaf())
93 99
 					rowEntry.node.isCollapsed().toggle();
94 100
 				return;
@@ -106,43 +112,48 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
106 112
 							bounds.x,
107 113
 							rowToY(oldRow) - style.selectedPaddingTop,
108 114
 							bounds.width,
109
-							style.font.size + style.selectedPaddingTop + style.selectedPaddingBottom);
115
+							fontMetrics.getAscent() + fontMetrics.getDescent() + style.selectedPaddingTop + style.selectedPaddingBottom);
110 116
 				context.repaint(
111 117
 						bounds.x,
112 118
 						rowToY(row) - style.selectedPaddingTop,
113 119
 						bounds.width,
114
-						style.font.size + style.selectedPaddingTop + style.selectedPaddingBottom);
120
+						fontMetrics.getAscent() + fontMetrics.getDescent() + style.selectedPaddingTop + style.selectedPaddingBottom);
115 121
 			}
116 122
 		}
117 123
 	}
118 124
 	
119 125
 	private int rowToY(int row) {
120
-		return row * (style.rowSpacing + style.font.size) + style.padding;
126
+		return row * (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent()) + style.padding;
121 127
 	}
122 128
 	
123 129
 	private int yToRow(int y) {
124
-		return (y - bounds.y - style.padding) / (style.rowSpacing + style.font.size);
130
+		return (y - bounds.y - style.padding) / (style.rowSpacing + fontMetrics.getAscent() + fontMetrics.getDescent());
125 131
 	}
126 132
 	
127 133
 	private int paintNode(DCanvas canvas, N node, int drawX, int drawY) {
128
-		int textColor = style.nodeTextColor;
134
+		int textColor = styleDefinition.nodeTextColor;
129 135
 		if (node == selectedNode) {
130
-			textColor = style.selectedNodeTextColor;
131
-			canvas.fillRectangle(bounds.x, drawY - style.selectedPaddingTop, bounds.width, style.font.size + style.selectedPaddingTop + style.selectedPaddingBottom, style.selectedBackgroundColor);
136
+			textColor = styleDefinition.selectedNodeTextColor;
137
+			canvas.fillRectangle(
138
+					bounds.x,
139
+					drawY - style.selectedPaddingTop,
140
+					bounds.width,
141
+					fontMetrics.getAscent() + fontMetrics.getDescent() + style.selectedPaddingTop + style.selectedPaddingBottom,
142
+					styleDefinition.selectedBackgroundColor);
132 143
 		}
133 144
 		
134 145
 		int drawingX = drawX;
135 146
 		if (!node.isLeaf()) {
136 147
 			DDrawable icon = node.isCollapsed().getValue() ? style.nodeClosedIcon : style.nodeOpenedIcon;
137
-			icon.draw(canvas, DTransform2D.translate(drawingX, drawY + style.font.size - icon.getNominalHeight()));
148
+			icon.draw(canvas, DTransform2D.translate(drawingX, drawY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()));
138 149
 			drawingX += style.iconTextSpacing + icon.getNominalWidth();
139 150
 		} else {
140 151
 			drawingX += style.iconTextSpacing + style.nodeClosedIcon.getNominalWidth();
141 152
 		}
142
-		node.getIcon().draw(canvas, DTransform2D.translate(drawingX, drawY + style.font.size - node.getIcon().getNominalHeight()), textColor);
153
+		node.getIcon().draw(canvas, DTransform2D.translate(drawingX, drawY + fontMetrics.getAscent() + fontMetrics.getDescent() - node.getIcon().getNominalHeight()), textColor);
143 154
 		drawingX += style.iconTextSpacing + node.getIcon().getNominalWidth();
144
-		canvas.drawText(style.font, textColor, drawingX, drawY + style.font.size + style.textShift, node.getTitle());
145
-		drawY += style.font.size;
155
+		canvas.drawText(style.font, textColor, drawingX, drawY + fontMetrics.getAscent(), node.getTitle());
156
+		drawY += fontMetrics.getAscent() + fontMetrics.getDescent();
146 157
 		
147 158
 		if (!node.isCollapsed().getValue()) {
148 159
 			for (N child : node.getChildren()) {
@@ -195,6 +206,11 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
195 206
 			}
196 207
 		}
197 208
 	}
209
+
210
+	@Override
211
+	public void close() {
212
+		// nothing to clean up
213
+	}
198 214
 	
199 215
 	private class Row implements Closeable, LiveBool.Listener {
200 216
 		private final int x;
@@ -210,7 +226,7 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
210 226
 		@Override
211 227
 		public void onChanged(boolean oldValue, boolean newValue) {
212 228
 			updateLayout();
213
-			context.repaint(bounds.x, bounds.y, bounds.width, bounds.height);
229
+			context.repaint(bounds);
214 230
 		}
215 231
 		
216 232
 		@Override

+ 55
- 16
DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeViewStyle.java Bestand weergeven

@@ -8,6 +8,9 @@ package org.openzen.drawablegui.tree;
8 8
 import org.openzen.drawablegui.DDrawable;
9 9
 import org.openzen.drawablegui.DFont;
10 10
 import org.openzen.drawablegui.DFontFamily;
11
+import org.openzen.drawablegui.dimension.DDimension;
12
+import org.openzen.drawablegui.dimension.DDpDimension;
13
+import org.openzen.drawablegui.DUIContext;
11 14
 
12 15
 /**
13 16
  *
@@ -20,33 +23,69 @@ public class DTreeViewStyle {
20 23
 	public final DDrawable nodeClosedIcon;
21 24
 	public final int backgroundColor;
22 25
 	public final int borderColor;
23
-	public final int padding;
24
-	public final int rowSpacing;
25
-	public final DFont font;
26
-	public final int indent;
27
-	public final int textShift;
28
-	public final int iconTextSpacing;
26
+	public final DDimension padding;
27
+	public final DDimension rowSpacing;
28
+	public final DDimension fontSize;
29
+	public final DDimension indent;
30
+	public final DDimension iconTextSpacing;
29 31
 	public final int nodeTextColor;
30 32
 	public final int selectedNodeTextColor;
31 33
 	public final int selectedBackgroundColor;
32
-	public final int selectedPaddingTop;
33
-	public final int selectedPaddingBottom;
34
+	public final DDimension selectedPaddingTop;
35
+	public final DDimension selectedPaddingBottom;
34 36
 	
35 37
 	private DTreeViewStyle() {
36 38
 		nodeOpenedIcon = ExpandedArrow.INSTANCE;
37 39
 		nodeClosedIcon = CollapsedArrow.INSTANCE;
38 40
 		backgroundColor = 0xFFFFFFFF;
39 41
 		borderColor = 0xFF888888;
40
-		padding = 5;
41
-		rowSpacing = 10;
42
-		font = new DFont(DFontFamily.UI, false, false, false, 22);
43
-		indent = 20;
44
-		textShift = -4;
45
-		iconTextSpacing = 3;
42
+		padding = new DDpDimension(3);
43
+		rowSpacing = new DDpDimension(2);
44
+		fontSize = new DDpDimension(12.5f);  
45
+		indent = new DDpDimension(12);
46
+		iconTextSpacing = new DDpDimension(2);
46 47
 		nodeTextColor = 0xFF000000;
47 48
 		selectedNodeTextColor = 0xFFFFFFFF;
48 49
 		selectedBackgroundColor = 0xFF007ACC;
49
-		selectedPaddingTop = 3;
50
-		selectedPaddingBottom = 3;
50
+		selectedPaddingTop = new DDpDimension(1);
51
+		selectedPaddingBottom = new DDpDimension(1);
52
+	}
53
+	
54
+	public Calculated forContext(DUIContext context) {
55
+		return new Calculated(this, context);
56
+	}
57
+	
58
+	public static class Calculated {
59
+		public final DDrawable nodeOpenedIcon;
60
+		public final DDrawable nodeClosedIcon;
61
+		public final int backgroundColor;
62
+		public final int borderColor;
63
+		public final int padding;
64
+		public final int rowSpacing;
65
+		public final DFont font;
66
+		public final int indent;
67
+		public final int iconTextSpacing;
68
+		public final int nodeTextColor;
69
+		public final int selectedNodeTextColor;
70
+		public final int selectedBackgroundColor;
71
+		public final int selectedPaddingTop;
72
+		public final int selectedPaddingBottom;
73
+		
74
+		private Calculated(DTreeViewStyle style, DUIContext context) {
75
+			nodeOpenedIcon = style.nodeOpenedIcon;
76
+			nodeClosedIcon = style.nodeClosedIcon;
77
+			backgroundColor = style.backgroundColor;
78
+			borderColor = style.borderColor;
79
+			padding = style.padding.evalInt(context);
80
+			rowSpacing = style.rowSpacing.evalInt(context);
81
+			font = new DFont(DFontFamily.UI, false, false, false, style.fontSize.evalInt(context));
82
+			indent = style.indent.evalInt(context);
83
+			iconTextSpacing = style.iconTextSpacing.evalInt(context);
84
+			nodeTextColor = style.nodeTextColor;
85
+			selectedNodeTextColor = style.selectedNodeTextColor;
86
+			selectedBackgroundColor = style.selectedBackgroundColor;
87
+			selectedPaddingTop = style.selectedPaddingTop.evalInt(context);
88
+			selectedPaddingBottom = style.selectedPaddingBottom.evalInt(context);
89
+		}
51 90
 	}
52 91
 }

+ 50
- 2
DrawableGuiIconConverter/src/main/java/org/openzen/drawablegui/iconconverter/Main.java Bestand weergeven

@@ -21,9 +21,9 @@ import org.w3c.dom.NodeList;
21 21
  */
22 22
 public class Main {
23 23
 	public static void main(String[] args) throws Exception {
24
-		String filename = "baseline-folder-24px.svg"; //args[0];
24
+		String filename = "baseline-settings-20px.svg"; //args[0];
25 25
 		//String filename = "baseline-dashboard-24px.svg";
26
-		String className = "ColorableFolderIcon";
26
+		String className = "ColorableSettingsIcon";
27 27
 		File file = new File(filename);
28 28
 		if (!file.exists()) {
29 29
 			System.out.println("No such file: " + filename);
@@ -94,6 +94,8 @@ public class Main {
94 94
 		CharStream stream = new CharStream(path);
95 95
 		float x = 0;
96 96
 		float y = 0;
97
+		float guideX = 0;
98
+		float guideY = 0;
97 99
 		char instruction = stream.next();
98 100
 		while (stream.hasMore()) {
99 101
 			if (!stream.nextIsNumber())
@@ -187,6 +189,8 @@ public class Main {
187 189
 							.append(y3).append("f);\n");
188 190
 					x = x3;
189 191
 					y = y3;
192
+					guideX = x2;
193
+					guideY = y2;
190 194
 					break;
191 195
 				}
192 196
 				case 'c': {
@@ -198,6 +202,50 @@ public class Main {
198 202
 					float y3 = y + stream.parseFloat();
199 203
 					x = x3;
200 204
 					y = y3;
205
+					guideX = x2;
206
+					guideY = y2;
207
+					output.append(indent)
208
+							.append("tracer.bezierCubic(")
209
+							.append(x1).append("f, ")
210
+							.append(y1).append("f, ")
211
+							.append(x2).append("f, ")
212
+							.append(y2).append("f, ")
213
+							.append(x3).append("f, ")
214
+							.append(y3).append("f);\n");
215
+					break;
216
+				}
217
+				case 'S': {
218
+					float x1 = x + (x - guideX);
219
+					float y1 = y + (y - guideY);
220
+					float x2 = stream.parseFloat();
221
+					float y2 = stream.parseFloat();
222
+					float x3 = stream.parseFloat();
223
+					float y3 = stream.parseFloat();
224
+					output.append(indent)
225
+							.append("tracer.bezierCubic(")
226
+							.append(x1).append("f, ")
227
+							.append(y1).append("f, ")
228
+							.append(x2).append("f, ")
229
+							.append(y2).append("f, ")
230
+							.append(x3).append("f, ")
231
+							.append(y3).append("f);\n");
232
+					x = x3;
233
+					y = y3;
234
+					guideX = x2;
235
+					guideY = y2;
236
+					break;
237
+				}
238
+				case 's': {
239
+					float x1 = x + (x - guideX);
240
+					float y1 = y + (y - guideY);
241
+					float x2 = x + stream.parseFloat();
242
+					float y2 = y + stream.parseFloat();
243
+					float x3 = x + stream.parseFloat();
244
+					float y3 = y + stream.parseFloat();
245
+					x = x3;
246
+					y = y3;
247
+					guideX = x2;
248
+					guideY = y2;
201 249
 					output.append(indent)
202 250
 							.append("tracer.bezierCubic(")
203 251
 							.append(x1).append("f, ")

+ 24
- 3
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBar.java Bestand weergeven

@@ -5,17 +5,18 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui;
7 7
 
8
-import java.util.ArrayList;
9
-import java.util.List;
8
+import java.io.Closeable;
10 9
 import org.openzen.drawablegui.listeners.ListenerHandle;
11 10
 import org.openzen.drawablegui.listeners.ListenerList;
11
+import org.openzen.drawablegui.live.LiveArrayList;
12
+import org.openzen.drawablegui.live.LiveList;
12 13
 
13 14
 /**
14 15
  *
15 16
  * @author Hoofdgebruiker
16 17
  */
17 18
 public class IDEAspectBar {
18
-	private final List<IDEAspectToolbar> aspectToolbars = new ArrayList<>();
19
+	public final LiveList<IDEAspectToolbar> aspectToolbars = new LiveArrayList<>(); // TODO: only expose read-only variant
19 20
 	private final ListenerList<Listener> listeners = new ListenerList<>();
20 21
 	
21 22
 	public ListenerHandle<Listener> addListener(Listener listener) {
@@ -37,6 +38,11 @@ public class IDEAspectBar {
37 38
 		return true;
38 39
 	}
39 40
 	
41
+	public BarHandle openContentBar(IDEAspectToolbar toolbar) {
42
+		listeners.accept(listener -> listener.onOpenContextBar(toolbar));
43
+		return new BarHandle(toolbar);
44
+	}
45
+	
40 46
 	private int insertToolbar(IDEAspectToolbar toolbar) {
41 47
 		for (int i = 0; i < aspectToolbars.size(); i++) {
42 48
 			if (toolbar.order < aspectToolbars.get(i).order) {
@@ -49,8 +55,23 @@ public class IDEAspectBar {
49 55
 		return index;
50 56
 	}
51 57
 	
58
+	public class BarHandle implements Closeable {
59
+		private final IDEAspectToolbar toolbar;
60
+		
61
+		public BarHandle(IDEAspectToolbar toolbar) {
62
+			this.toolbar = toolbar;
63
+		}
64
+		
65
+		@Override
66
+		public void close() {
67
+			listeners.accept(listener -> listener.onCloseContextBar(toolbar));
68
+		}
69
+	}
70
+	
52 71
 	public interface Listener {
53 72
 		void onAspectBarAdded(int index, IDEAspectToolbar toolbar);
54 73
 		void onAspectBarRemoved(int index, IDEAspectToolbar toolbar);
74
+		void onOpenContextBar(IDEAspectToolbar toolbar);
75
+		void onCloseContextBar(IDEAspectToolbar toolbar);
55 76
 	}
56 77
 }

+ 3
- 11
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBarControl.java Bestand weergeven

@@ -5,20 +5,12 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui;
7 7
 
8
-import org.openzen.drawablegui.listeners.ListenerHandle;
8
+import org.openzen.drawablegui.DComponent;
9 9
 
10 10
 /**
11 11
  *
12 12
  * @author Hoofdgebruiker
13 13
  */
14
-public interface IDEAspectBarControl extends IDEDrawable {
15
-	ListenerHandle<InvalidationListener> addInvalidationListener(InvalidationListener listener);
16
-	
17
-	public interface InvalidationListener {
18
-		/* Indicates that this component needs to be redrawn */
19
-		void invalidateView(int x, int y, int width, int height);
20
-		
21
-		/* Indicates that layout should be recalculated for this component (eg because its size changed). */
22
-		void invalidateLayout();
23
-	}
14
+public interface IDEAspectBarControl {
15
+	DComponent instantiate();
24 16
 }

+ 3
- 45
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectToolbar.java Bestand weergeven

@@ -6,66 +6,24 @@
6 6
 package org.openzen.zenscript.ide.ui;
7 7
 
8 8
 import org.openzen.drawablegui.DColorableIcon;
9
-import java.util.ArrayList;
10
-import java.util.Collections;
11
-import java.util.List;
12
-import org.openzen.drawablegui.listeners.ListenerHandle;
13
-import org.openzen.drawablegui.listeners.ListenerList;
9
+import org.openzen.drawablegui.live.LiveArrayList;
10
+import org.openzen.drawablegui.live.LiveList;
14 11
 
15 12
 /**
16 13
  *
17 14
  * @author Hoofdgebruiker
18 15
  */
19 16
 public class IDEAspectToolbar {
20
-	private final ListenerList<Listener> listeners = new ListenerList<>();
21
-	
22 17
 	public final int order;
23 18
 	public final DColorableIcon icon;
24 19
 	public final String title;
25 20
 	public final String description;
26
-	private boolean active;
27
-	private final List<IDEAspectBarControl> controls = new ArrayList<>();
21
+	public final LiveList<IDEAspectBarControl> controls = new LiveArrayList<>();
28 22
 	
29 23
 	public IDEAspectToolbar(int order, DColorableIcon icon, String title, String description) {
30 24
 		this.order = order;
31 25
 		this.icon = icon;
32 26
 		this.title = title;
33 27
 		this.description = description;
34
-		this.active = true;
35
-	}
36
-	
37
-	public ListenerHandle<Listener> addListener(Listener listener) {
38
-		return listeners.add(listener);
39
-	}
40
-	
41
-	public boolean getActive() {
42
-		return active;
43
-	}
44
-	
45
-	public void setActive(boolean active) {
46
-		this.active = active;
47
-		listeners.accept(listener -> listener.onActiveChanged(active));
48
-	}
49
-	
50
-	public List<IDEAspectBarControl> getControls() {
51
-		return Collections.unmodifiableList(controls);
52
-	}
53
-	
54
-	public void addControl(IDEAspectBarControl control) {
55
-		controls.add(control);
56
-		listeners.accept(listener -> listener.onControlAdded(control));
57
-	}
58
-	
59
-	public void removeControl(IDEAspectBarControl control) {
60
-		controls.remove(control);
61
-		listeners.accept(listener -> listener.onControlRemoved(control));
62
-	}
63
-	
64
-	public interface Listener {
65
-		void onActiveChanged(boolean active);
66
-		
67
-		void onControlAdded(IDEAspectBarControl control);
68
-		
69
-		void onControlRemoved(IDEAspectBarControl control);
70 28
 	}
71 29
 }

+ 0
- 21
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEDrawable.java Bestand weergeven

@@ -1,21 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.zenscript.ide.ui;
7
-
8
-import org.openzen.drawablegui.DCanvas;
9
-import org.openzen.drawablegui.DTransform2D;
10
-
11
-/**
12
- *
13
- * @author Hoofdgebruiker
14
- */
15
-public interface IDEDrawable {
16
-	void draw(DCanvas canvas, DTransform2D transform, IDEStyle style);
17
-	
18
-	float getNominalWidth();
19
-	
20
-	float getNominalHeight();
21
-}

+ 13
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java Bestand weergeven

@@ -6,6 +6,10 @@
6 6
 package org.openzen.zenscript.ide.ui;
7 7
 
8 8
 import org.openzen.zenscript.ide.host.IDESourceFile;
9
+import org.openzen.zenscript.ide.ui.icons.ColorableAddBoxIcon;
10
+import org.openzen.zenscript.ide.ui.icons.ColorableProjectIcon;
11
+import org.openzen.zenscript.ide.ui.icons.ColorableSettingsIcon;
12
+import org.openzen.zenscript.ide.ui.view.IconButtonControl;
9 13
 
10 14
 /**
11 15
  *
@@ -20,15 +24,24 @@ public class IDEWindow {
20 24
 		aspectBar = new IDEAspectBar();
21 25
 		dockWindow = new IDEDockWindow();
22 26
 		statusBar = new IDEStatusBar();
27
+		init();
23 28
 	}
24 29
 	
25 30
 	public IDEWindow(IDEAspectBar aspectBar, IDEDockWindow dockWindow, IDEStatusBar statusBar) {
26 31
 		this.aspectBar = aspectBar;
27 32
 		this.dockWindow = dockWindow;
28 33
 		this.statusBar = statusBar;
34
+		init();
29 35
 	}
30 36
 	
31 37
 	public void open(IDESourceFile sourceFile) {
32 38
 		dockWindow.currentSourceFile.setValue(sourceFile);
33 39
 	}
40
+	
41
+	private void init() {
42
+		IDEAspectToolbar projectToolbar = new IDEAspectToolbar(0, ColorableProjectIcon.INSTANCE, "Project", "Project management");
43
+		projectToolbar.controls.add(() -> new IconButtonControl(ColorableAddBoxIcon.BLACK, e -> {}));
44
+		projectToolbar.controls.add(() -> new IconButtonControl(ColorableSettingsIcon.BLACK, e -> {}));
45
+		aspectBar.addToolbar(projectToolbar);
46
+	}
34 47
 }

+ 59
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColorableAddBoxIcon.java Bestand weergeven

@@ -0,0 +1,59 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.icons;
7
+import org.openzen.drawablegui.DCanvas;
8
+import org.openzen.drawablegui.DPath;
9
+import org.openzen.drawablegui.DTransform2D;
10
+import org.openzen.drawablegui.DColorableIcon;
11
+
12
+public class ColorableAddBoxIcon implements DColorableIcon {
13
+	public static final ColorableAddBoxIcon INSTANCE = new ColorableAddBoxIcon();
14
+	public static final ColoredIcon BLACK = new ColoredIcon(INSTANCE, 0xFF000000);
15
+	
16
+	private ColorableAddBoxIcon() {}
17
+	
18
+	private static final DPath PATH = tracer -> {
19
+		tracer.moveTo(19f, 3f);
20
+		tracer.lineTo(5.0f, 3.0f);
21
+		tracer.bezierCubic(3.8899999f, 3.0f, 3.0f, 3.9f, 3.0f, 5.0f);
22
+		tracer.lineTo(3.0f, 19.0f);
23
+		tracer.bezierCubic(3.0f, 20.1f, 3.8899999f, 21.0f, 5.0f, 21.0f);
24
+		tracer.lineTo(19.0f, 21.0f);
25
+		tracer.bezierCubic(20.1f, 21.0f, 21.0f, 20.1f, 21.0f, 19.0f);
26
+		tracer.lineTo(21.0f, 5.0f);
27
+		tracer.bezierCubic(21.0f, 3.9f, 20.1f, 3.0f, 19.0f, 3.0f);
28
+		tracer.close();
29
+		tracer.moveTo(17.0f, 13.0f);
30
+		tracer.lineTo(13.0f, 13.0f);
31
+		tracer.lineTo(13.0f, 17.0f);
32
+		tracer.lineTo(11.0f, 17.0f);
33
+		tracer.lineTo(11.0f, 13.0f);
34
+		tracer.lineTo(7.0f, 13.0f);
35
+		tracer.lineTo(7.0f, 11.0f);
36
+		tracer.lineTo(11.0f, 11.0f);
37
+		tracer.lineTo(11.0f, 7.0f);
38
+		tracer.lineTo(13.0f, 7.0f);
39
+		tracer.lineTo(13.0f, 11.0f);
40
+		tracer.lineTo(17.0f, 11.0f);
41
+		tracer.lineTo(17.0f, 13.0f);
42
+		tracer.close();
43
+	};
44
+	
45
+	@Override
46
+	public void draw(DCanvas canvas, DTransform2D transform, int color) {
47
+		canvas.fillPath(PATH, transform, color);
48
+	}
49
+
50
+	@Override
51
+	public float getNominalWidth() {
52
+		return 24;
53
+	}
54
+
55
+	@Override
56
+	public float getNominalHeight() {
57
+		return 24;
58
+	}
59
+}

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColorableProjectIcon.java Bestand weergeven

@@ -8,11 +8,11 @@ package org.openzen.zenscript.ide.ui.icons;
8 8
 import org.openzen.drawablegui.DCanvas;
9 9
 import org.openzen.drawablegui.DPath;
10 10
 import org.openzen.drawablegui.DTransform2D;
11
-import org.openzen.zenscript.ide.ui.IDEStyle;
12 11
 import org.openzen.drawablegui.DColorableIcon;
13 12
 
14 13
 public class ColorableProjectIcon implements DColorableIcon {
15 14
 	public static final ColorableProjectIcon INSTANCE = new ColorableProjectIcon();
15
+	public static final ColoredIcon GREY = new ColoredIcon(INSTANCE, 0xFF888888);
16 16
 	
17 17
 	private ColorableProjectIcon() {}
18 18
 	

+ 57
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColorableSaveIcon.java Bestand weergeven

@@ -0,0 +1,57 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.icons;
7
+
8
+import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.DPath;
10
+import org.openzen.drawablegui.DTransform2D;
11
+import org.openzen.drawablegui.DColorableIcon;
12
+
13
+public class ColorableSaveIcon implements DColorableIcon {
14
+	public static final ColorableSaveIcon INSTANCE = new ColorableSaveIcon();
15
+	
16
+	private ColorableSaveIcon() {}
17
+	
18
+	private static final DPath PATH = tracer -> {
19
+		tracer.moveTo(17f, 3f);
20
+		tracer.lineTo(5.0f, 3.0f);
21
+		tracer.bezierCubic(3.8899999f, 3.0f, 3.0f, 3.9f, 3.0f, 5.0f);
22
+		tracer.lineTo(3.0f, 19.0f);
23
+		tracer.bezierCubic(3.0f, 20.1f, 3.8899999f, 21.0f, 5.0f, 21.0f);
24
+		tracer.lineTo(19.0f, 21.0f);
25
+		tracer.bezierCubic(20.1f, 21.0f, 21.0f, 20.1f, 21.0f, 19.0f);
26
+		tracer.lineTo(21.0f, 7.0f);
27
+		tracer.lineTo(17.0f, 3.0f);
28
+		tracer.close();
29
+		tracer.moveTo(12.0f, 19.0f);
30
+		tracer.bezierCubic(10.34f, 19.0f, 9.0f, 17.66f, 9.0f, 16.0f);
31
+		tracer.bezierCubic(9.0f, 14.34f, 10.34f, 13.0f, 12.0f, 13.0f);
32
+		tracer.bezierCubic(13.66f, 13.0f, 15.0f, 14.34f, 15.0f, 16.0f);
33
+		tracer.bezierCubic(15.0f, 17.66f, 13.66f, 19.0f, 12.0f, 19.0f);
34
+		tracer.close();
35
+		tracer.moveTo(15.0f, 9.0f);
36
+		tracer.lineTo(5.0f, 9.0f);
37
+		tracer.lineTo(5.0f, 5.0f);
38
+		tracer.lineTo(15.0f, 5.0f);
39
+		tracer.lineTo(15.0f, 9.0f);
40
+		tracer.close();
41
+	};
42
+	
43
+	@Override
44
+	public void draw(DCanvas canvas, DTransform2D transform, int color) {
45
+		canvas.fillPath(PATH, transform, color);
46
+	}
47
+
48
+	@Override
49
+	public float getNominalWidth() {
50
+		return 24;
51
+	}
52
+
53
+	@Override
54
+	public float getNominalHeight() {
55
+		return 24;
56
+	}
57
+}

+ 81
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColorableSettingsIcon.java Bestand weergeven

@@ -0,0 +1,81 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.icons;
7
+import org.openzen.drawablegui.DCanvas;
8
+import org.openzen.drawablegui.DPath;
9
+import org.openzen.drawablegui.DTransform2D;
10
+import org.openzen.drawablegui.DColorableIcon;
11
+
12
+public class ColorableSettingsIcon implements DColorableIcon {
13
+	public static final ColorableSettingsIcon INSTANCE = new ColorableSettingsIcon();
14
+	public static final ColoredIcon BLACK = new ColoredIcon(INSTANCE, 0xFF000000);
15
+	
16
+	private ColorableSettingsIcon() {}
17
+	
18
+	private static final DPath PATH = tracer -> {
19
+		tracer.moveTo(15.95f, 10.78f);
20
+		tracer.bezierCubic(15.98f, 10.53f, 16.0f, 10.2699995f, 16.0f, 10.0f);
21
+		tracer.bezierCubic(16.0f, 9.7300005f, 15.98f, 9.47f, 15.94f, 9.22f);
22
+		tracer.lineTo(17.63f, 7.9f);
23
+		tracer.bezierCubic(17.779999f, 7.78f, 17.82f, 7.56f, 17.73f, 7.3900003f);
24
+		tracer.lineTo(16.13f, 4.6200004f);
25
+		tracer.bezierCubic(16.029999f, 4.4400005f, 15.819999f, 4.3800006f, 15.639999f, 4.4400005f);
26
+		tracer.lineTo(13.65f, 5.2400007f);
27
+		tracer.bezierCubic(13.23f, 4.9200006f, 12.79f, 4.660001f, 12.299999f, 4.460001f);
28
+		tracer.lineTo(12f, 2.34f);
29
+		tracer.bezierCubic(11.97f, 2.1399999f, 11.8f, 1.9999999f, 11.6f, 1.9999999f);
30
+		tracer.lineTo(8.4f, 1.9999999f);
31
+		tracer.bezierCubic(8.2f, 1.9999999f, 8.04f, 2.1399999f, 8.009999f, 2.34f);
32
+		tracer.lineTo(7.709999f, 4.46f);
33
+		tracer.bezierCubic(7.2199993f, 4.66f, 6.769999f, 4.93f, 6.359999f, 5.24f);
34
+		tracer.lineTo(4.369999f, 4.4399996f);
35
+		tracer.bezierCubic(4.189999f, 4.3699994f, 3.979999f, 4.4399996f, 3.879999f, 4.6199994f);
36
+		tracer.lineTo(2.2799988f, 7.3899994f);
37
+		tracer.bezierCubic(2.1799989f, 7.569999f, 2.2199988f, 7.7799993f, 2.3799987f, 7.8999996f);
38
+		tracer.lineTo(4.0699987f, 9.219999f);
39
+		tracer.bezierCubic(4.029999f, 9.469999f, 3.9999988f, 9.74f, 3.9999988f, 9.999999f);
40
+		tracer.bezierCubic(3.9999988f, 10.259998f, 4.019999f, 10.529999f, 4.059999f, 10.779999f);
41
+		tracer.lineTo(2.37f, 12.1f);
42
+		tracer.bezierCubic(2.2199998f, 12.22f, 2.1799998f, 12.440001f, 2.27f, 12.610001f);
43
+		tracer.lineTo(3.87f, 15.380001f);
44
+		tracer.bezierCubic(3.9699998f, 15.560001f, 4.18f, 15.620001f, 4.3599997f, 15.560001f);
45
+		tracer.lineTo(6.3499994f, 14.760001f);
46
+		tracer.bezierCubic(6.7699995f, 15.080001f, 7.2099996f, 15.340001f, 7.6999993f, 15.540001f);
47
+		tracer.lineTo(7.9999995f, 17.66f);
48
+		tracer.bezierCubic(8.04f, 17.86f, 8.2f, 18.0f, 8.4f, 18.0f);
49
+		tracer.lineTo(11.599999f, 18.0f);
50
+		tracer.bezierCubic(11.799999f, 18.0f, 11.969999f, 17.86f, 11.99f, 17.66f);
51
+		tracer.lineTo(12.29f, 15.54f);
52
+		tracer.bezierCubic(12.78f, 15.34f, 13.23f, 15.07f, 13.64f, 14.76f);
53
+		tracer.lineTo(15.63f, 15.56f);
54
+		tracer.bezierCubic(15.81f, 15.63f, 16.02f, 15.56f, 16.12f, 15.38f);
55
+		tracer.lineTo(17.720001f, 12.610001f);
56
+		tracer.bezierCubic(17.820002f, 12.43f, 17.78f, 12.22f, 17.62f, 12.1f);
57
+		tracer.lineTo(15.950001f, 10.780001f);
58
+		tracer.close();
59
+		tracer.moveTo(10f, 13f);
60
+		tracer.bezierCubic(8.35f, 13.0f, 7.0f, 11.65f, 7.0f, 10.0f);
61
+		tracer.bezierCubic(7.0f, 8.35f, 8.35f, 7.0f, 10.0f, 7.0f);
62
+		tracer.bezierCubic(11.65f, 7.0f, 13.0f, 8.35f, 13.0f, 10.0f);
63
+		tracer.bezierCubic(13.0f, 11.65f, 11.65f, 13.0f, 10.0f, 13.0f);
64
+		tracer.close();
65
+	};
66
+	
67
+	@Override
68
+	public void draw(DCanvas canvas, DTransform2D transform, int color) {
69
+		canvas.fillPath(PATH, transform, color);
70
+	}
71
+
72
+	@Override
73
+	public float getNominalWidth() {
74
+		return 20;
75
+	}
76
+
77
+	@Override
78
+	public float getNominalHeight() {
79
+		return 20;
80
+	}
81
+}

+ 40
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/ColoredIcon.java Bestand weergeven

@@ -0,0 +1,40 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.icons;
7
+
8
+import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.DColorableIcon;
10
+import org.openzen.drawablegui.DDrawable;
11
+import org.openzen.drawablegui.DTransform2D;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class ColoredIcon implements DDrawable {
18
+	private final DColorableIcon icon;
19
+	private final int color;
20
+	
21
+	public ColoredIcon(DColorableIcon icon, int color) {
22
+		this.icon = icon;
23
+		this.color = color;
24
+	}
25
+
26
+	@Override
27
+	public void draw(DCanvas canvas, DTransform2D transform) {
28
+		icon.draw(canvas, transform, color);
29
+	}
30
+
31
+	@Override
32
+	public float getNominalWidth() {
33
+		return icon.getNominalWidth();
34
+	}
35
+
36
+	@Override
37
+	public float getNominalHeight() {
38
+		return icon.getNominalHeight();
39
+	}
40
+}

+ 31
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/SaveIcon.java Bestand weergeven

@@ -0,0 +1,31 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.icons;
7
+
8
+import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.DDrawable;
10
+import org.openzen.drawablegui.DTransform2D;
11
+
12
+public class SaveIcon implements DDrawable {
13
+	public static final SaveIcon INSTANCE = new SaveIcon();
14
+	
15
+	private SaveIcon() {}
16
+	
17
+	@Override
18
+	public void draw(DCanvas canvas, DTransform2D transform) {
19
+		ColorableSaveIcon.INSTANCE.draw(canvas, transform, 0xFF000000);
20
+	}
21
+
22
+	@Override
23
+	public float getNominalWidth() {
24
+		return 24;
25
+	}
26
+
27
+	@Override
28
+	public float getNominalHeight() {
29
+		return 24;
30
+	}
31
+}

+ 98
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java Bestand weergeven

@@ -0,0 +1,98 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.view;
7
+
8
+import java.util.function.Consumer;
9
+import org.openzen.drawablegui.DCanvas;
10
+import org.openzen.drawablegui.DComponent;
11
+import org.openzen.drawablegui.DDimensionPreferences;
12
+import org.openzen.drawablegui.DDrawable;
13
+import org.openzen.drawablegui.DMouseEvent;
14
+import org.openzen.drawablegui.DTransform2D;
15
+import org.openzen.drawablegui.DUIContext;
16
+import org.openzen.drawablegui.listeners.DIRectangle;
17
+import org.openzen.drawablegui.live.LiveObject;
18
+import org.openzen.drawablegui.live.SimpleLiveObject;
19
+import org.openzen.drawablegui.style.DStylePath;
20
+
21
+/**
22
+ *
23
+ * @author Hoofdgebruiker
24
+ */
25
+public class IconButtonControl implements DComponent {
26
+	private final DDrawable icon;
27
+	private final Consumer<DMouseEvent> onClick;
28
+	
29
+	private DUIContext context;
30
+	private DIRectangle bounds;
31
+	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
32
+	private boolean hover;
33
+	
34
+	public IconButtonControl(DDrawable icon, Consumer<DMouseEvent> onClick) {
35
+		this.icon = icon;
36
+		this.onClick = onClick;
37
+	}
38
+
39
+	@Override
40
+	public void setContext(DStylePath parent, DUIContext context) {
41
+		this.context = context;
42
+		preferences.setValue(new DDimensionPreferences(
43
+				(int)(icon.getNominalWidth() * context.getScale() + 0.5f),
44
+				(int)(icon.getNominalHeight() * context.getScale() + 0.5f)));
45
+	}
46
+
47
+	@Override
48
+	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
49
+		return preferences;
50
+	}
51
+
52
+	@Override
53
+	public DIRectangle getBounds() {
54
+		return bounds;
55
+	}
56
+
57
+	@Override
58
+	public void setBounds(DIRectangle bounds) {
59
+		this.bounds = bounds;
60
+	}
61
+
62
+	@Override
63
+	public void paint(DCanvas canvas) {
64
+		if (hover) {
65
+			canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, 0xFFE0E0E0);
66
+		}
67
+		icon.draw(canvas, DTransform2D.scaleAndTranslate(
68
+				bounds.x + (bounds.width - icon.getNominalWidth() * context.getScale()) / 2,
69
+				bounds.y + (bounds.height - icon.getNominalHeight() * context.getScale()) / 2,
70
+				context.getScale()));
71
+	}
72
+
73
+	@Override
74
+	public void close() {
75
+		// nothing to clean up
76
+	}
77
+	
78
+	@Override
79
+	public void onMouseEnter(DMouseEvent e) {
80
+		hover = true;
81
+		context.repaint(bounds);
82
+	}
83
+	
84
+	@Override
85
+	public void onMouseExit(DMouseEvent e) {
86
+		hover = false;
87
+		context.repaint(bounds);
88
+	}
89
+	
90
+	@Override
91
+	public void onMouseClick(DMouseEvent e) {
92
+		onClick.accept(e);
93
+	}
94
+	
95
+	private void repaint() {
96
+		
97
+	}
98
+}

+ 13
- 7
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarView.java Bestand weergeven

@@ -5,13 +5,14 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui.view;
7 7
 
8
-import org.openzen.drawablegui.DRectangle;
9 8
 import org.openzen.drawablegui.DCanvas;
10 9
 import org.openzen.drawablegui.DComponent;
11 10
 import org.openzen.drawablegui.DDimensionPreferences;
12
-import org.openzen.drawablegui.DDrawingContext;
11
+import org.openzen.drawablegui.listeners.DIRectangle;
13 12
 import org.openzen.drawablegui.live.LiveObject;
14 13
 import org.openzen.drawablegui.live.SimpleLiveObject;
14
+import org.openzen.drawablegui.DUIContext;
15
+import org.openzen.drawablegui.style.DStylePath;
15 16
 
16 17
 /**
17 18
  *
@@ -22,11 +23,11 @@ public class StatusBarView implements DComponent {
22 23
 	//private static final int COLOR = 0xFFFFFFFF;
23 24
 	
24 25
 	private final SimpleLiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 40));
25
-	private DRectangle bounds;
26
-	private DDrawingContext context;
26
+	private DIRectangle bounds;
27
+	private DUIContext context;
27 28
 
28 29
 	@Override
29
-	public void setContext(DDrawingContext context) {
30
+	public void setContext(DStylePath parent, DUIContext context) {
30 31
 		this.context = context;
31 32
 	}
32 33
 	
@@ -36,12 +37,12 @@ public class StatusBarView implements DComponent {
36 37
 	}
37 38
 	
38 39
 	@Override
39
-	public DRectangle getBounds() {
40
+	public DIRectangle getBounds() {
40 41
 		return bounds;
41 42
 	}
42 43
 
43 44
 	@Override
44
-	public void setBounds(DRectangle bounds) {
45
+	public void setBounds(DIRectangle bounds) {
45 46
 		this.bounds = bounds;
46 47
 	}
47 48
 
@@ -49,4 +50,9 @@ public class StatusBarView implements DComponent {
49 50
 	public void paint(DCanvas canvas) {
50 51
 		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, COLOR);
51 52
 	}
53
+
54
+	@Override
55
+	public void close() {
56
+		// nothing to clean up
57
+	}
52 58
 }

+ 6
- 4
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java Bestand weergeven

@@ -8,12 +8,13 @@ package org.openzen.zenscript.ide.ui.view;
8 8
 import org.openzen.drawablegui.DDimensionPreferences;
9 9
 import org.openzen.drawablegui.DEmptyView;
10 10
 import org.openzen.drawablegui.scroll.DScrollPane;
11
-import org.openzen.drawablegui.scroll.DScrollPaneStyle;
12 11
 import org.openzen.drawablegui.DSideLayout;
12
+import org.openzen.drawablegui.style.DStyleClass;
13 13
 import org.openzen.drawablegui.tree.DTreeView;
14 14
 import org.openzen.drawablegui.tree.DTreeViewStyle;
15 15
 import org.openzen.zenscript.ide.host.DevelopmentHost;
16 16
 import org.openzen.zenscript.ide.ui.IDEWindow;
17
+import org.openzen.zenscript.ide.ui.view.aspectbar.AspectBarView;
17 18
 import org.openzen.zenscript.ide.ui.view.editor.SourceEditor;
18 19
 import org.openzen.zenscript.ide.ui.view.project.RootTreeNode;
19 20
 
@@ -23,18 +24,19 @@ import org.openzen.zenscript.ide.ui.view.project.RootTreeNode;
23 24
  */
24 25
 public final class WindowView extends DSideLayout {
25 26
 	public WindowView(IDEWindow window, DevelopmentHost host) {
26
-		super(DEmptyView.INSTANCE);
27
+		super(DStyleClass.EMPTY, DEmptyView.INSTANCE);
27 28
 		
28 29
 		DTreeView projectView = new DTreeView(DTreeViewStyle.DEFAULT, new RootTreeNode(window, host), false);
29 30
 		projectView.getDimensionPreferences().setValue(new DDimensionPreferences(500, 500));
30
-		add(Side.LEFT, new DScrollPane(DScrollPaneStyle.DEFAULT, projectView));
31
+		add(Side.LEFT, new DScrollPane(DStyleClass.forId("projectView"), projectView));
31 32
 		add(Side.BOTTOM, new StatusBarView());
33
+		add(Side.TOP, new AspectBarView(DStyleClass.EMPTY, window.aspectBar));
32 34
 		
33 35
 		window.dockWindow.currentSourceFile.addListener((oldSource, newSource) -> {
34 36
 			if (newSource == null) {
35 37
 				setMain(DEmptyView.INSTANCE);
36 38
 			} else {
37
-				setMain(new DScrollPane(DScrollPaneStyle.DEFAULT, new SourceEditor(newSource)));
39
+				setMain(new DScrollPane(DStyleClass.EMPTY, new SourceEditor(DStyleClass.EMPTY, window, newSource)));
38 40
 			}
39 41
 		});
40 42
 	}

+ 95
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java Bestand weergeven

@@ -0,0 +1,95 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.view.aspectbar;
7
+
8
+import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.DColorableIcon;
10
+import org.openzen.drawablegui.DComponent;
11
+import org.openzen.drawablegui.DDimensionPreferences;
12
+import org.openzen.drawablegui.DDrawable;
13
+import org.openzen.drawablegui.DPath;
14
+import org.openzen.drawablegui.DTransform2D;
15
+import org.openzen.drawablegui.DUIContext;
16
+import org.openzen.drawablegui.listeners.DIRectangle;
17
+import org.openzen.drawablegui.live.LiveBool;
18
+import org.openzen.drawablegui.live.LiveObject;
19
+import org.openzen.drawablegui.live.SimpleLiveObject;
20
+import org.openzen.drawablegui.style.DStyleClass;
21
+import org.openzen.drawablegui.style.DStylePath;
22
+
23
+/**
24
+ *
25
+ * @author Hoofdgebruiker
26
+ */
27
+public class AspectBarSelectorButton implements DComponent {
28
+	
29
+	public final LiveBool active = new LiveBool();
30
+	
31
+	private final DStyleClass styleClass;
32
+	private final DDrawable icon;
33
+	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
34
+	private DUIContext context;
35
+	private AspectBarSelectorButtonStyle style;
36
+	private DIRectangle bounds;
37
+	private DPath shape;
38
+	
39
+	public AspectBarSelectorButton(DStyleClass styleClass, DDrawable icon) {
40
+		this.styleClass = styleClass;
41
+		this.icon = icon;
42
+	}
43
+
44
+	@Override
45
+	public void setContext(DStylePath parent, DUIContext context) {
46
+		this.context = context;
47
+		DStylePath path = parent.getChild("selectorbutton", styleClass);
48
+		style = new AspectBarSelectorButtonStyle(context.getStylesheets().get(context, path));
49
+		shape = DPath.roundedRectangle(
50
+				0,
51
+				0,
52
+				style.width,
53
+				style.height,
54
+				style.roundingRadius);
55
+	}
56
+
57
+	@Override
58
+	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
59
+		return preferences;
60
+	}
61
+
62
+	@Override
63
+	public DIRectangle getBounds() {
64
+		return bounds;
65
+	}
66
+
67
+	@Override
68
+	public void setBounds(DIRectangle bounds) {
69
+		this.bounds = bounds;
70
+	}
71
+
72
+	@Override
73
+	public void paint(DCanvas canvas) {
74
+		canvas.shadowPath(
75
+					shape,
76
+					DTransform2D.translate(bounds.x, bounds.y),
77
+					style.shadowColor,
78
+					style.shadowOffsetX,
79
+					style.shadowOffsetY,
80
+					style.shadowRadius);
81
+			canvas.fillPath(
82
+					shape,
83
+					DTransform2D.translate(bounds.x, bounds.y),
84
+					style.colorNormal);
85
+			icon.draw(canvas, DTransform2D.scaleAndTranslate(
86
+					bounds.x + (style.width - icon.getNominalWidth() * context.getScale()) / 2,
87
+					bounds.y + (style.height - icon.getNominalHeight() * context.getScale()) / 2,
88
+					context.getScale()));
89
+	}
90
+
91
+	@Override
92
+	public void close() {
93
+		// nothing
94
+	}
95
+}

+ 46
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButtonStyle.java Bestand weergeven

@@ -0,0 +1,46 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.view.aspectbar;
7
+
8
+import org.openzen.drawablegui.dimension.DDimension;
9
+import org.openzen.drawablegui.dimension.DDpDimension;
10
+import org.openzen.drawablegui.style.DStyleDefinition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class AspectBarSelectorButtonStyle {
17
+	public final int width;
18
+	public final int height;
19
+	public final int roundingRadius;
20
+	
21
+	public final int colorNormal;
22
+	public final int colorHover;
23
+	public final int colorPress;
24
+	public final int colorActive;
25
+	
26
+	public final int shadowColor;
27
+	public final float shadowOffsetX;
28
+	public final float shadowOffsetY;
29
+	public final float shadowRadius;
30
+	
31
+	public AspectBarSelectorButtonStyle(DStyleDefinition style) {
32
+		width = style.getDimension("width", new DDpDimension(24));
33
+		height = style.getDimension("height", new DDpDimension(24));
34
+		roundingRadius = style.getDimension("roundingRadius", new DDpDimension(4));
35
+		
36
+		colorNormal = style.getColor("colorNormal", 0xFFFFFFFF);
37
+		colorHover = style.getColor("colorHover", 0xFFCCCCCC);
38
+		colorPress = style.getColor("colorPress", 0xFFBBBBBB);
39
+		colorActive = style.getColor("colorActive", 0xFFBBBBBB);
40
+		
41
+		shadowRadius = style.getDimension("shadowRadius", new DDpDimension(3));
42
+		shadowColor = style.getColor("ashadowColor", 0xFF888888);
43
+		shadowOffsetX = style.getDimension("shadowOffsetX", new DDpDimension(0));
44
+		shadowOffsetY = style.getDimension("shadowOffsetY", new DDpDimension(0.5f));
45
+	}
46
+}

+ 63
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarStyle.java Bestand weergeven

@@ -0,0 +1,63 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.view.aspectbar;
7
+
8
+import org.openzen.drawablegui.dimension.DDpDimension;
9
+import org.openzen.drawablegui.style.DStyleDefinition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class AspectBarStyle {
16
+	public final int height;
17
+	public final int aspectSelectorPaddingLeft;
18
+	public final int aspectSelectorToToolbarSpacing;
19
+	public final int aspectSelectorBottomSize;
20
+	public final int backgroundColor;
21
+	public final int foregroundColor;
22
+	
23
+	public final int aspectSelectorButtonRadius;
24
+	public final int aspectSelectorButtonSpacing;
25
+	public final int aspectSelectorButtonShadowRadius;
26
+	public final int aspectSelectorButtonShadowColor;
27
+	public final float aspectSelectorButtonShadowOffsetX;
28
+	public final float aspectSelectorButtonShadowOffsetY;
29
+	
30
+	public final int aspectBarShadowRadius;
31
+	public final int aspectBarShadowColor;
32
+	public final float aspectBarShadowOffsetX;
33
+	public final float aspectBarShadowOffsetY;
34
+	public final int aspectBarPaddingTop;
35
+	
36
+	public final int controlPaddingTop;
37
+	public final int controlPaddingBottom;
38
+	
39
+	public AspectBarStyle(DStyleDefinition style) {
40
+		height = style.getDimension("height", new DDpDimension(32));
41
+		aspectSelectorPaddingLeft = style.getDimension("aspectSelectorPaddingLeft", new DDpDimension(4));
42
+		aspectSelectorToToolbarSpacing = style.getDimension("aspectSelectorToToolbarSpacing", new DDpDimension(16));
43
+		aspectSelectorBottomSize = style.getDimension("aspectSelectorBottomSize", new DDpDimension(4));
44
+		backgroundColor = style.getColor("backgroundColor", 0xFFF0F0F0);
45
+		foregroundColor = style.getColor("foregroundColor", 0xFFFFFFFF);
46
+		
47
+		aspectSelectorButtonRadius = style.getDimension("aspectSelectorButtonRadius", new DDpDimension(12));
48
+		aspectSelectorButtonSpacing = style.getDimension("aspectSelectorButtonSpacing", new DDpDimension(4));
49
+		aspectSelectorButtonShadowRadius = style.getDimension("aspectSelectorButtonShadowRadius", new DDpDimension(3));
50
+		aspectSelectorButtonShadowColor = style.getColor("aspectSelectorButtonShadowColor", 0xFF888888);
51
+		aspectSelectorButtonShadowOffsetX = style.getDimension("aspectSelectorButtonShadowOffsetX", new DDpDimension(0));
52
+		aspectSelectorButtonShadowOffsetY = style.getDimension("aspectSelectorButtonShadowOffsetY", new DDpDimension(0.5f));
53
+		
54
+		aspectBarShadowRadius = style.getDimension("aspectBarShadowRadius", new DDpDimension(2));
55
+		aspectBarShadowColor = style.getColor("aspectBarShadowColor", 0xFF888888);
56
+		aspectBarShadowOffsetX = style.getDimension("aspectBarShadowOffsetX", new DDpDimension(0));
57
+		aspectBarShadowOffsetY = style.getDimension("aspectBarShadowOffsetX", new DDpDimension(0.5f));
58
+		aspectBarPaddingTop = style.getDimension("aspectBarPaddingTop", new DDpDimension(2));
59
+		
60
+		controlPaddingTop = style.getDimension("controlPaddingTop", new DDpDimension(2));
61
+		controlPaddingBottom = style.getDimension("controlPaddingBottom", new DDpDimension(2));
62
+	}
63
+}

+ 234
- 14
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java Bestand weergeven

@@ -5,30 +5,70 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui.view.aspectbar;
7 7
 
8
-import org.openzen.zenscript.ide.ui.view.*;
9
-import org.openzen.drawablegui.DRectangle;
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import java.util.function.Consumer;
11
+import java.util.function.Predicate;
12
+import org.openzen.drawablegui.BaseComponentGroup;
10 13
 import org.openzen.drawablegui.DCanvas;
11 14
 import org.openzen.drawablegui.DComponent;
12 15
 import org.openzen.drawablegui.DDimensionPreferences;
13
-import org.openzen.drawablegui.DDrawingContext;
16
+import org.openzen.drawablegui.DPath;
17
+import org.openzen.drawablegui.DTransform2D;
18
+import org.openzen.drawablegui.listeners.DIRectangle;
14 19
 import org.openzen.drawablegui.live.LiveObject;
15 20
 import org.openzen.drawablegui.live.SimpleLiveObject;
21
+import org.openzen.zenscript.ide.ui.IDEAspectBar;
22
+import org.openzen.zenscript.ide.ui.IDEAspectToolbar;
23
+import org.openzen.drawablegui.DUIContext;
24
+import org.openzen.drawablegui.listeners.ListenerHandle;
25
+import org.openzen.drawablegui.live.LiveList;
26
+import org.openzen.drawablegui.live.LiveMappedList;
27
+import org.openzen.drawablegui.style.DStyleClass;
28
+import org.openzen.drawablegui.style.DStylePath;
29
+import org.openzen.zenscript.ide.ui.IDEAspectBarControl;
16 30
 
17 31
 /**
18 32
  *
19 33
  * @author Hoofdgebruiker
20 34
  */
21
-public class AspectBarView implements DComponent {
22
-	private static final int COLOR = 0xFFF0F0F0;
23
-	//private static final int COLOR = 0xFFFFFFFF;
35
+public class AspectBarView extends BaseComponentGroup {
36
+	private final SimpleLiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 64));
37
+	private final DStyleClass styleClass;
38
+	private final IDEAspectBar aspectBar;
39
+	private final List<IDEAspectToolbar> contextBars = new ArrayList<>();
40
+	
41
+	private DIRectangle bounds;
42
+	private DUIContext context;
43
+	private DStylePath path;
44
+	private AspectBarStyle style;
45
+	public final LiveObject<IDEAspectToolbar> active = new SimpleLiveObject<>(null);
46
+	private LiveMappedList<IDEAspectBarControl, DComponent> activeToolbarComponents;
47
+	
48
+	private final ListenerHandle<LiveList.Listener<IDEAspectToolbar>> listener;
49
+	private DPath aspectBarShape;
50
+	
51
+	public AspectBarView(DStyleClass styleClass, IDEAspectBar aspectBar) {
52
+		this.styleClass = styleClass;
53
+		this.aspectBar = aspectBar;
54
+		
55
+		active.addListener(this::onActiveChanged);
56
+		listener = aspectBar.aspectToolbars.addListener(new ToolbarListListener());
57
+		
58
+		if (aspectBar.aspectToolbars.size() > 0)
59
+			active.setValue(aspectBar.aspectToolbars.get(0));
60
+	}
24 61
 	
25
-	private final SimpleLiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 40));
26
-	private DRectangle bounds;
27
-	private DDrawingContext context;
28
-
29 62
 	@Override
30
-	public void setContext(DDrawingContext context) {
63
+	public void setContext(DStylePath parent, DUIContext context) {
31 64
 		this.context = context;
65
+		this.path = parent.getChild("aspectbar", styleClass);
66
+		this.style = new AspectBarStyle(context.getStylesheets().get(context, path));
67
+		
68
+		if (bounds != null) {
69
+			calculateAspectBarShape();
70
+			active.setValue(active.getValue());
71
+		}
32 72
 	}
33 73
 	
34 74
 	@Override
@@ -37,17 +77,197 @@ public class AspectBarView implements DComponent {
37 77
 	}
38 78
 	
39 79
 	@Override
40
-	public DRectangle getBounds() {
80
+	public DIRectangle getBounds() {
41 81
 		return bounds;
42 82
 	}
43 83
 
44 84
 	@Override
45
-	public void setBounds(DRectangle bounds) {
85
+	public void setBounds(DIRectangle bounds) {
46 86
 		this.bounds = bounds;
87
+		
88
+		if (context != null) {
89
+			calculateAspectBarShape();
90
+			context.repaint(bounds);
91
+		}
47 92
 	}
48 93
 
49 94
 	@Override
50 95
 	public void paint(DCanvas canvas) {
51
-		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, COLOR);
96
+		canvas.pushBounds(bounds);
97
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
98
+		
99
+		//DPath circle = DPath.circle(0, 0, style.aspectSelectorButtonRadius);
100
+		DPath circle = DPath.roundedRectangle(
101
+				-style.aspectSelectorButtonRadius,
102
+				-style.aspectSelectorButtonRadius,
103
+				2 * style.aspectSelectorButtonRadius,
104
+				2 * style.aspectSelectorButtonRadius,
105
+				8);
106
+		int x = bounds.x + style.aspectSelectorPaddingLeft;
107
+		int y = bounds.y;
108
+		for (IDEAspectToolbar toolbar : aspectBar.aspectToolbars) {
109
+			canvas.shadowPath(
110
+					circle,
111
+					DTransform2D.translate(x + style.aspectSelectorButtonRadius, y + style.height / 2),
112
+					style.aspectSelectorButtonShadowColor,
113
+					style.aspectSelectorButtonShadowOffsetX,
114
+					style.aspectSelectorButtonShadowOffsetY,
115
+					style.aspectSelectorButtonShadowRadius);
116
+			canvas.fillPath(
117
+					circle,
118
+					DTransform2D.translate(x + style.aspectSelectorButtonRadius, y + style.height / 2),
119
+					style.foregroundColor);
120
+			toolbar.icon.draw(canvas, DTransform2D.scaleAndTranslate(
121
+					x + (2 * style.aspectSelectorButtonRadius - toolbar.icon.getNominalWidth() * context.getScale()) / 2,
122
+					y + (style.height - toolbar.icon.getNominalHeight() * context.getScale()) / 2,
123
+					context.getScale()), 0xFF888888);
124
+			x += style.aspectSelectorButtonRadius * 2 + style.aspectSelectorButtonSpacing;
125
+		}
126
+		for (IDEAspectToolbar toolbar : contextBars) {
127
+			canvas.shadowPath(
128
+					circle,
129
+					DTransform2D.translate(x + style.aspectSelectorButtonRadius, y + style.height / 2),
130
+					style.aspectSelectorButtonShadowColor,
131
+					style.aspectSelectorButtonShadowOffsetX,
132
+					style.aspectSelectorButtonShadowOffsetY,
133
+					style.aspectSelectorButtonShadowRadius);
134
+			canvas.fillPath(
135
+					circle,
136
+					DTransform2D.translate(x + style.aspectSelectorButtonRadius, y + style.height / 2),
137
+					style.foregroundColor);
138
+			toolbar.icon.draw(canvas, DTransform2D.scaleAndTranslate(
139
+					x + (2 * style.aspectSelectorButtonRadius - toolbar.icon.getNominalWidth() * context.getScale()) / 2,
140
+					y + (style.height - toolbar.icon.getNominalHeight() * context.getScale()) / 2,
141
+					context.getScale()), 0xFF000000);
142
+			x += style.aspectSelectorButtonRadius * 2 + style.aspectSelectorButtonSpacing;
143
+		}
144
+		
145
+		
146
+		canvas.shadowPath(
147
+				aspectBarShape,
148
+				DTransform2D.IDENTITY,
149
+				style.aspectBarShadowColor,
150
+				style.aspectBarShadowOffsetX,
151
+				style.aspectBarShadowOffsetY,
152
+				style.aspectBarShadowRadius);
153
+		canvas.fillPath(
154
+				aspectBarShape,
155
+				DTransform2D.IDENTITY,
156
+				style.foregroundColor);
157
+		
158
+		if (activeToolbarComponents != null) {
159
+			for (DComponent component : activeToolbarComponents)
160
+				component.paint(canvas);
161
+		}
162
+		
163
+		canvas.popBounds();
164
+	}
165
+
166
+	@Override
167
+	public void close() {
168
+		listener.close();
169
+	}
170
+	
171
+	private void onActiveChanged(IDEAspectToolbar previous, IDEAspectToolbar aspectBar) {
172
+		if (activeToolbarComponents != null)
173
+			activeToolbarComponents.close();
174
+		
175
+		activeToolbarComponents = new LiveMappedList<>(aspectBar.controls, control -> {
176
+			DComponent result = control.instantiate();
177
+			if (context != null)
178
+				result.setContext(path, context);
179
+			return result;
180
+		});
181
+		
182
+		layoutActiveToolbarComponents();
183
+	}
184
+	
185
+	private void layoutActiveToolbarComponents() {
186
+		if (bounds == null)
187
+			return;
188
+		
189
+		int x = bounds.x
190
+				+ style.aspectSelectorPaddingLeft
191
+				+ (style.aspectSelectorButtonRadius * 2 + style.aspectSelectorButtonSpacing) * (aspectBar.aspectToolbars.size() + contextBars.size())
192
+				+ style.aspectSelectorToToolbarSpacing;
193
+		
194
+		int y = style.aspectBarPaddingTop + style.controlPaddingTop;
195
+		int height = bounds.height - y - style.controlPaddingBottom;
196
+		for (DComponent toolbarComponent : activeToolbarComponents) {
197
+			int width = toolbarComponent.getDimensionPreferences().getValue().preferredWidth;
198
+			toolbarComponent.setBounds(
199
+					new DIRectangle(x, bounds.y + y, width, height));
200
+			x += width;
201
+		}
202
+		
203
+		context.repaint(bounds);
204
+	}
205
+
206
+	@Override
207
+	protected void forEachChild(Consumer<DComponent> children) {
208
+		if (activeToolbarComponents == null)
209
+			return;
210
+		
211
+		for (DComponent component : activeToolbarComponents)
212
+			children.accept(component);
213
+	}
214
+
215
+	@Override
216
+	protected DComponent findChild(Predicate<DComponent> predicate) {
217
+		if (activeToolbarComponents == null)
218
+			return null;
219
+		
220
+		for (DComponent component : activeToolbarComponents)
221
+			if (predicate.test(component))
222
+				return component;
223
+		
224
+		return null;
225
+	}
226
+	
227
+	private void calculateAspectBarShape() {
228
+		int toX = bounds.x
229
+				+ style.aspectSelectorPaddingLeft
230
+				+ (style.aspectSelectorButtonRadius * 2 + style.aspectSelectorButtonSpacing) * (aspectBar.aspectToolbars.size() + contextBars.size());
231
+		
232
+		aspectBarShape = tracer -> {
233
+			int baseY = bounds.y + bounds.height - style.aspectSelectorBottomSize;
234
+			tracer.moveTo(bounds.x, baseY);
235
+			tracer.lineTo(toX, baseY);
236
+			tracer.bezierCubic(
237
+					toX + 6 * context.getScale(), baseY,
238
+					toX + style.aspectSelectorToToolbarSpacing - 6 * context.getScale(), bounds.y + style.aspectBarPaddingTop,
239
+					toX + style.aspectSelectorToToolbarSpacing, bounds.y + style.aspectBarPaddingTop);
240
+			tracer.lineTo(bounds.x + bounds.width, bounds.y + style.aspectBarPaddingTop);
241
+			tracer.lineTo(bounds.x + bounds.width, bounds.y + bounds.height);
242
+			tracer.lineTo(bounds.x, bounds.y + bounds.height);
243
+			tracer.close();
244
+		};
245
+	}
246
+	
247
+	private class ToolbarListListener implements LiveList.Listener<IDEAspectToolbar> {
248
+
249
+		@Override
250
+		public void onInserted(int index, IDEAspectToolbar value) {
251
+			if (index == 0 && activeToolbarComponents == null)
252
+				active.setValue(value);
253
+			
254
+			layoutActiveToolbarComponents();
255
+			calculateAspectBarShape();
256
+		}
257
+
258
+		@Override
259
+		public void onChanged(int index, IDEAspectToolbar oldValue, IDEAspectToolbar newValue) {
260
+			if (oldValue == active.getValue())
261
+				active.setValue(newValue);
262
+		}
263
+
264
+		@Override
265
+		public void onRemoved(int index, IDEAspectToolbar oldValue) {
266
+			if (oldValue == active.getValue())
267
+				active.setValue(aspectBar.aspectToolbars.size() == 0 ? null : aspectBar.aspectToolbars.get(0));
268
+			
269
+			layoutActiveToolbarComponents();
270
+			calculateAspectBarShape();
271
+		}
52 272
 	}
53 273
 }

+ 60
- 30
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java Bestand weergeven

@@ -9,32 +9,37 @@ import java.io.IOException;
9 9
 import org.openzen.drawablegui.DCanvas;
10 10
 import org.openzen.drawablegui.DComponent;
11 11
 import org.openzen.drawablegui.DDimensionPreferences;
12
-import org.openzen.drawablegui.DDrawingContext;
13 12
 import org.openzen.drawablegui.DFont;
14 13
 import org.openzen.drawablegui.DFontFamily;
15 14
 import org.openzen.drawablegui.DFontMetrics;
16
-import org.openzen.drawablegui.DIRectangle;
15
+import org.openzen.drawablegui.listeners.DIRectangle;
17 16
 import org.openzen.drawablegui.DKeyEvent;
18
-import org.openzen.drawablegui.DKeyEvent.KeyCode;
19 17
 import org.openzen.drawablegui.DMouseEvent;
20
-import org.openzen.drawablegui.DRectangle;
21 18
 import org.openzen.drawablegui.DTransform2D;
22 19
 import org.openzen.drawablegui.listeners.ListenerHandle;
23 20
 import org.openzen.drawablegui.live.LiveObject;
24 21
 import org.openzen.drawablegui.live.SimpleLiveObject;
25 22
 import org.openzen.zenscript.ide.host.IDESourceFile;
23
+import org.openzen.zenscript.ide.ui.IDEAspectToolbar;
24
+import org.openzen.zenscript.ide.ui.IDEWindow;
25
+import org.openzen.zenscript.ide.ui.icons.ColorableCodeIcon;
26 26
 import org.openzen.zenscript.lexer.ReaderCharReader;
27 27
 import org.openzen.zenscript.lexer.TokenParser;
28 28
 import org.openzen.zenscript.lexer.ZSToken;
29 29
 import org.openzen.zenscript.lexer.ZSTokenParser;
30 30
 import org.openzen.zenscript.lexer.ZSTokenType;
31
+import org.openzen.drawablegui.DUIContext;
32
+import org.openzen.drawablegui.style.DStyleClass;
33
+import org.openzen.drawablegui.style.DStylePath;
34
+import org.openzen.zenscript.ide.ui.icons.SaveIcon;
35
+import org.openzen.zenscript.ide.ui.view.IconButtonControl;
31 36
 
32 37
 /**
33 38
  *
34 39
  * @author Hoofdgebruiker
35 40
  */
36 41
 public class SourceEditor implements DComponent {
37
-	private final SourceEditorStyle style = SourceEditorStyle.DEFAULT;
42
+	private final DStyleClass styleClass;
38 43
 	private final DFont font = new DFont(DFontFamily.CODE, false, false, false, 24);
39 44
 	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 0));
40 45
 	private final String tab = "    ";
@@ -42,8 +47,10 @@ public class SourceEditor implements DComponent {
42 47
 	private final TokenModel tokens;
43 48
 	private final ListenerHandle<TokenModel.Listener> tokenListener;
44 49
 	
45
-	private DRectangle bounds;
46
-	private DDrawingContext context;
50
+	private DIRectangle bounds;
51
+	private DUIContext context;
52
+	private SourceEditorStyle style;
53
+	
47 54
 	private DFontMetrics fontMetrics;
48 55
 	private int textLineHeight;
49 56
 	private int fullLineHeight;
@@ -59,22 +66,41 @@ public class SourceEditor implements DComponent {
59 66
 	private int mouseDownY = -1;
60 67
 	private boolean dragging = false;
61 68
 	
62
-	public SourceEditor(IDESourceFile sourceFile) {
69
+	private final IDEWindow window;
70
+	private final IDEAspectToolbar editToolbar = new IDEAspectToolbar(0, ColorableCodeIcon.INSTANCE, "Edit", "Source code editor");
71
+	
72
+	public SourceEditor(DStyleClass styleClass, IDEWindow window, IDESourceFile sourceFile) {
73
+		this.styleClass = styleClass;
74
+		this.window = window;
63 75
 		this.sourceFile = sourceFile;
76
+		
64 77
 		tokens = new TokenModel(sourceFile.getName(), tab.length());
65 78
 		tokenListener = tokens.addListener(new TokenListener());
66 79
 		
80
+		editToolbar.controls.add(() -> new IconButtonControl(SaveIcon.INSTANCE, e -> save()));
81
+		window.aspectBar.addToolbar(editToolbar);
82
+		
67 83
 		try {
68
-			TokenParser<ZSToken, ZSTokenType> parser = ZSTokenParser.createRaw(sourceFile.getName(), new ReaderCharReader(sourceFile.read()), tab.length());
84
+			TokenParser<ZSToken, ZSTokenType> parser = ZSTokenParser.createRaw(
85
+					sourceFile.getName(),
86
+					new ReaderCharReader(sourceFile.read()),
87
+					tab.length());
69 88
 			tokens.set(parser);
70 89
 		} catch (IOException ex) {
71 90
 			ex.printStackTrace();
72 91
 		}
73 92
 	}
93
+	
94
+	@Override
95
+	public void close() {
96
+		window.aspectBar.removeToolbar(editToolbar);
97
+	}
74 98
 
75 99
 	@Override
76
-	public void setContext(DDrawingContext context) {
100
+	public void setContext(DStylePath parent, DUIContext context) {
77 101
 		this.context = context;
102
+		this.style = new SourceEditorStyle(context.getStylesheets().get(context, parent.getChild("sourceeditor", styleClass)));
103
+		
78 104
 		fontMetrics = context.getFontMetrics(font);
79 105
 		textLineHeight = fontMetrics.getAscent() + fontMetrics.getDescent();
80 106
 		fullLineHeight = textLineHeight + fontMetrics.getLeading() + style.extraLineSpacing;
@@ -90,28 +116,32 @@ public class SourceEditor implements DComponent {
90 116
 	}
91 117
 
92 118
 	@Override
93
-	public DRectangle getBounds() {
119
+	public DIRectangle getBounds() {
94 120
 		return bounds;
95 121
 	}
96 122
 
97 123
 	@Override
98
-	public void setBounds(DRectangle bounds) {
124
+	public void setBounds(DIRectangle bounds) {
99 125
 		this.bounds = bounds;
100 126
 	}
101 127
 
102 128
 	@Override
103 129
 	public void paint(DCanvas canvas) {
104 130
 		DIRectangle canvasBounds = canvas.getBounds();
105
-		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, 0xFFFFFFFF);
106
-		
107
-		lineBarWidth = Math.max(50, fontMetrics.getWidth(Integer.toString(tokens.getLineCount()))) + 5;
108
-		canvas.fillRectangle(bounds.x, bounds.y, lineBarWidth, bounds.height, 0xFFE9E8E2);
109
-		canvas.strokePath(tracer -> {
110
-			tracer.moveTo(bounds.x + lineBarWidth, bounds.y);
111
-			tracer.lineTo(bounds.x + lineBarWidth, bounds.y + bounds.height);
112
-		}, DTransform2D.IDENTITY, 0xFFA0A0A0, 1);
131
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
132
+		
133
+		lineBarWidth = Math.max(style.lineBarMinWidth, fontMetrics.getWidth(Integer.toString(tokens.getLineCount())))
134
+				+ style.lineBarSpacingLeft
135
+				+ style.lineBarSpacingRight;
136
+		canvas.fillRectangle(bounds.x, bounds.y, lineBarWidth, bounds.height, style.lineBarBackgroundColor);
137
+		if (style.lineBarStrokeWidth > 0) {
138
+			canvas.strokePath(tracer -> {
139
+				tracer.moveTo(bounds.x + lineBarWidth, bounds.y);
140
+				tracer.lineTo(bounds.x + lineBarWidth, bounds.y + bounds.height);
141
+			}, DTransform2D.IDENTITY, style.lineBarStrokeColor, style.lineBarStrokeWidth);
142
+		}
113 143
 		
114
-		int x = bounds.x + lineBarWidth + 10;
144
+		int x = bounds.x + lineBarWidth + style.lineBarMargin;
115 145
 		if (cursorEnd != null)
116 146
 			canvas.fillRectangle(x, lineToY(cursorEnd.line), bounds.width - x, selectionLineHeight, style.currentLineHighlight);
117 147
 		
@@ -144,14 +174,14 @@ public class SourceEditor implements DComponent {
144 174
 		for (TokenLine line : tokens.getLines()) {
145 175
 			if (y + textLineHeight  >= canvasBounds.y && y < canvasBounds.y + canvasBounds.height) {
146 176
 				String lineNumber = Integer.toString(lineIndex);
147
-				int lineNumberX = x - 15 - (int)canvas.measureTextLength(font, lineNumber);
148
-				canvas.drawText(font, 0xFFA0A0A0, lineNumberX, y + fontMetrics.getAscent(), lineNumber);
177
+				int lineNumberX = x - style.lineBarSpacingRight - style.lineBarMargin - fontMetrics.getWidth(lineNumber);
178
+				canvas.drawText(font, style.lineBarTextColor, lineNumberX, y + fontMetrics.getAscent(), lineNumber);
149 179
 
150 180
 				int lineX = x;
151 181
 				for (ZSToken token : line.getTokens()) {
152 182
 					String content = getDisplayContent(token);
153 183
 					canvas.drawText(font, TokenClass.get(token.type).color, lineX, y + fontMetrics.getAscent(), content);
154
-					lineX += canvas.measureTextLength(font, content);
184
+					lineX += fontMetrics.getWidth(content);
155 185
 				}
156 186
 			}
157 187
 			
@@ -162,18 +192,18 @@ public class SourceEditor implements DComponent {
162 192
 		if (cursorEnd != null && cursorBlink) {
163 193
 			int cursorX = getX(cursorEnd);
164 194
 			int cursorY = getY(cursorEnd);
165
-			canvas.fillRectangle(cursorX, cursorY, 2, selectionLineHeight, 0xFF000000);
195
+			canvas.fillRectangle(cursorX, cursorY, style.cursorWidth, selectionLineHeight, style.cursorColor);
166 196
 		}
167 197
 	}
168 198
 	
169 199
 	@Override
170 200
 	public void onMouseEnter(DMouseEvent e) {
171
-		context.setCursor(DDrawingContext.Cursor.TEXT);
201
+		context.setCursor(DUIContext.Cursor.TEXT);
172 202
 	}
173 203
 	
174 204
 	@Override
175 205
 	public void onMouseExit(DMouseEvent e) {
176
-		context.setCursor(DDrawingContext.Cursor.NORMAL);
206
+		context.setCursor(DUIContext.Cursor.NORMAL);
177 207
 	}
178 208
 	
179 209
 	@Override
@@ -530,9 +560,9 @@ public class SourceEditor implements DComponent {
530 560
 	
531 561
 	public int getX(SourcePosition position) {
532 562
 		int x = bounds.x + lineBarWidth + 10;
533
-		TokenLine lineData = tokens.getLine(position.line);
534
-		
535 563
 		TokenModel.Position tokenPosition = position.asTokenPosition();
564
+		TokenLine lineData = tokens.getLine(tokenPosition.line);
565
+		
536 566
 		for (int i = 0; i < tokenPosition.token; i++)
537 567
 			x += fontMetrics.getWidth(getDisplayContent(lineData.getToken(i)));
538 568
 		if (tokenPosition.offset > 0)
@@ -553,7 +583,7 @@ public class SourceEditor implements DComponent {
553 583
 		dimensionPreferences.setValue(new DDimensionPreferences(0, fullLineHeight * tokens.getLineCount()));
554 584
 		
555 585
 		if (bounds != null)
556
-			context.repaint(bounds.x, bounds.y, bounds.width, bounds.height);
586
+			context.repaint(bounds);
557 587
 	}
558 588
 	
559 589
 	private class TokenListener implements TokenModel.Listener {

+ 34
- 13
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditorStyle.java Bestand weergeven

@@ -5,29 +5,50 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui.view.editor;
7 7
 
8
+import org.openzen.drawablegui.dimension.DDpDimension;
9
+import org.openzen.drawablegui.dimension.DPxDimension;
10
+import org.openzen.drawablegui.style.DStyleDefinition;
11
+
8 12
 /**
9 13
  *
10 14
  * @author Hoofdgebruiker
11 15
  */
12 16
 public class SourceEditorStyle {
13
-	public static final SourceEditorStyle DEFAULT = new SourceEditorStyle(3, 0xFFE9EFF8, 0xFFB0C5E3, 2, 2);
14
-	
17
+	public final int backgroundColor;
18
+	public final int lineBarBackgroundColor;
19
+	public final int lineBarStrokeColor;
20
+	public final int lineBarStrokeWidth;
21
+	public final int lineBarMinWidth;
22
+	public final int lineBarSpacingLeft;
23
+	public final int lineBarSpacingRight;
24
+	public final int lineBarMargin;
25
+	public final int lineBarTextColor;
15 26
 	public final int extraLineSpacing;
16 27
 	public final int currentLineHighlight;
17 28
 	public final int selectionColor;
18 29
 	public final int selectionPaddingTop;
19 30
 	public final int selectionPaddingBottom;
31
+	public final int cursorWidth;
32
+	public final int cursorColor;
20 33
 	
21
-	public SourceEditorStyle(
22
-			int extraLineSpacing,
23
-			int currentLineHighlight,
24
-			int selectionColor,
25
-			int selectionPaddingTop,
26
-			int selectionPaddingBottom) {
27
-		this.extraLineSpacing = extraLineSpacing;
28
-		this.currentLineHighlight = currentLineHighlight;
29
-		this.selectionColor = selectionColor;
30
-		this.selectionPaddingTop = selectionPaddingTop;
31
-		this.selectionPaddingBottom = selectionPaddingBottom;
34
+	public SourceEditorStyle(DStyleDefinition style) {
35
+		this.backgroundColor = style.getColor("backgroundColor", 0xFFFFFFFF);
36
+		this.lineBarBackgroundColor = style.getColor("lineBarBackgroundColor", 0xFFE9E8E2);
37
+		this.lineBarStrokeColor = style.getColor("lineBarStrokeColor", 0xFFA0A0A0);
38
+		this.lineBarStrokeWidth = style.getDimension("lineBarStrokeWidth", new DPxDimension(1));
39
+		this.lineBarMinWidth = style.getDimension("lineBarMinWidth", new DDpDimension(30));
40
+		this.lineBarSpacingLeft = style.getDimension("lineBarSpacingLeft", new DDpDimension(5));
41
+		this.lineBarSpacingRight = style.getDimension("lineBarSpacingRight", new DDpDimension(2));
42
+		this.lineBarMargin = style.getDimension("lineBarMargin", new DDpDimension(7));
43
+		this.lineBarTextColor = style.getColor("lineBarTextColor", 0xFFA0A0A0);
44
+		
45
+		this.extraLineSpacing = style.getDimension("extraLineSpacing", new DDpDimension(2));
46
+		this.currentLineHighlight = style.getColor("currentLineHighlight", 0xFFE9EFF8);
47
+		this.selectionColor = style.getColor("selectionColor", 0xFFB0C5E3);
48
+		this.selectionPaddingTop = style.getDimension("selectionPaddingTop", new DDpDimension(1));
49
+		this.selectionPaddingBottom = style.getDimension("selectionPaddingBottom", new DDpDimension(1));
50
+		
51
+		this.cursorWidth = style.getDimension("cursorWidth", new DDpDimension(1));
52
+		this.cursorColor = style.getColor("cursorColor", 0xFF000000);
32 53
 	}
33 54
 }

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenModel.java Bestand weergeven

@@ -73,7 +73,7 @@ public class TokenModel {
73 73
 		if (line < 0)
74 74
 			line = 0;
75 75
 		if (line >= lines.size())
76
-			return new Position(lines.size(), lines.get(lines.size() - 1).getTokenCount(), 0);
76
+			return new Position(lines.size() - 1, lines.get(lines.size() - 1).getTokenCount(), 0);
77 77
 		
78 78
 		int token = 0;
79 79
 		int tokenOffset = 0;

Laden…
Annuleren
Opslaan