Browse Source

- Added bracket handlers

- Fixed crash formatting scripts without script statements
- Fixed bug causing lambda headers not to be inferred anymore
- Refactored some IDE code, also fixes scrolling not working properly
Stan Hebben 6 years ago
parent
commit
d577ffa6c3
70 changed files with 835 additions and 528 deletions
  1. 6
    4
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FileFormatter.java
  2. 0
    15
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  3. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstExpression.java
  4. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java
  5. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFieldExpression.java
  6. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetStaticFieldExpression.java
  7. 10
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/IPartialExpression.java
  8. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  9. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java
  10. 6
    4
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  11. 14
    20
      DrawableGui/src/main/java/org/openzen/drawablegui/DButton.java
  12. 1
    7
      DrawableGui/src/main/java/org/openzen/drawablegui/DComponent.java
  13. 92
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DComponentContext.java
  14. 1
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/DEmptyView.java
  15. 18
    24
      DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java
  16. 9
    16
      DrawableGui/src/main/java/org/openzen/drawablegui/DLabel.java
  17. 11
    17
      DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltipComponent.java
  18. 0
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java
  19. 2
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DBorder.java
  20. 3
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DCompositeBorder.java
  21. 12
    16
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DCustomWindowBorder.java
  22. 2
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DEmptyBorder.java
  23. 3
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DLineBorder.java
  24. 2
    2
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DPaddedBorder.java
  25. 6
    6
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DSideBorder.java
  26. 8
    11
      DrawableGui/src/main/java/org/openzen/drawablegui/form/DForm.java
  27. 11
    19
      DrawableGui/src/main/java/org/openzen/drawablegui/layout/DLinearLayout.java
  28. 12
    17
      DrawableGui/src/main/java/org/openzen/drawablegui/layout/DSideLayout.java
  29. 6
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveArrayList.java
  30. 2
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveList.java
  31. 7
    10
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBar.java
  32. 18
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollContext.java
  33. 33
    34
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java
  34. 10
    10
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java
  35. 2
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java
  36. 15
    15
      DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java
  37. 6
    1
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  38. 1
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java
  39. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreateSourceFileDialog.java
  40. 17
    22
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java
  41. 9
    14
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarView.java
  42. 14
    22
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java
  43. 15
    18
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTab.java
  44. 8
    13
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTabClose.java
  45. 16
    19
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java
  46. 41
    45
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java
  47. 11
    15
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/WindowActionButton.java
  48. 64
    55
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java
  49. 10
    15
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/output/OutputView.java
  50. 8
    4
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenParser.java
  51. 27
    0
      Parser/src/main/java/org/openzen/zenscript/parser/BracketExpressionParser.java
  52. 2
    0
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java
  53. 9
    7
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  54. 57
    0
      Parser/src/main/java/org/openzen/zenscript/parser/PrefixedBracketParser.java
  55. 73
    0
      Parser/src/main/java/org/openzen/zenscript/parser/SimpleBracketSubParser.java
  56. 7
    0
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java
  57. 5
    0
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedAlias.java
  58. 8
    5
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java
  59. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java
  60. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java
  61. 11
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java
  62. 5
    1
      Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedNamedType.java
  63. 2
    0
      ScriptingExample/scripts/helloworld.zs
  64. 22
    1
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  65. 3
    1
      Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java
  66. 10
    2
      Shared/src/main/java/org/openzen/zencode/shared/FileSourceFile.java
  67. 5
    0
      Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java
  68. 2
    0
      Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java
  69. 5
    0
      Shared/src/main/java/org/openzen/zencode/shared/VirtualSourceFile.java
  70. 1
    1
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java

+ 6
- 4
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FileFormatter.java View File

43
 		}
43
 		}
44
 		
44
 		
45
 		StringBuilder scriptOutput = new StringBuilder();
45
 		StringBuilder scriptOutput = new StringBuilder();
46
-		StatementFormatter scriptFormatter = new StatementFormatter(scriptOutput, "", settings, expressionFormatter);
47
-		for (Statement statement : script.statements) {
48
-			statement.accept(scriptFormatter);
46
+		if (script != null) {
47
+			StatementFormatter scriptFormatter = new StatementFormatter(scriptOutput, "", settings, expressionFormatter);
48
+			for (Statement statement : script.statements) {
49
+				statement.accept(scriptFormatter);
50
+			}
49
 		}
51
 		}
50
 		
52
 		
51
 		StringBuilder output = new StringBuilder();
53
 		StringBuilder output = new StringBuilder();
61
 			output.append(definition.toString());
63
 			output.append(definition.toString());
62
 		}
64
 		}
63
 		
65
 		
64
-		if (script.statements.size() > 0) {
66
+		if (script != null && script.statements.size() > 0) {
65
 			if (definitionFormatters.size() > 0)
67
 			if (definitionFormatters.size() > 0)
66
 				output.append("\n");
68
 				output.append("\n");
67
 			
69
 			

+ 0
- 15
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java View File

229
 		return false;
229
 		return false;
230
 	}
230
 	}
231
 	
231
 	
232
-	public boolean canCastTo(TypeScope scope, FunctionHeader header) {
233
-		if (parameters.length != header.parameters.length)
234
-			return false;
235
-		
236
-		if (!scope.getTypeMembers(returnType).canCastImplicit(header.returnType))
237
-			return false;
238
-		
239
-		for (int i = 0; i < parameters.length; i++) {
240
-			if (!scope.getTypeMembers(header.parameters[i].type).canCastImplicit(parameters[i].type))
241
-				return false;
242
-		}
243
-		
244
-		return true;
245
-	}
246
-	
247
 	public boolean accepts(TypeScope scope, Expression... arguments) {
232
 	public boolean accepts(TypeScope scope, Expression... arguments) {
248
 		if (parameters.length != arguments.length)
233
 		if (parameters.length != arguments.length)
249
 			return false;
234
 			return false;

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ConstExpression.java View File

7
 
7
 
8
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
9
 import org.openzen.zenscript.codemodel.member.EnumConstantMember;
10
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
10
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
11
 import org.openzen.zenscript.codemodel.member.ref.ConstMemberRef;
11
 
12
 
12
 /**
13
 /**
41
 	public EnumConstantMember evaluateEnumConstant() {
42
 	public EnumConstantMember evaluateEnumConstant() {
42
 		return constant.member.value.evaluateEnumConstant();
43
 		return constant.member.value.evaluateEnumConstant();
43
 	}
44
 	}
45
+	
46
+	@Override
47
+	public IDefinitionMember getMember() {
48
+		return constant.member;
49
+	}
44
 }
50
 }

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/Expression.java View File

22
 import org.openzen.zenscript.codemodel.scope.TypeScope;
22
 import org.openzen.zenscript.codemodel.scope.TypeScope;
23
 import org.openzen.zenscript.codemodel.statement.Statement;
23
 import org.openzen.zenscript.codemodel.statement.Statement;
24
 import org.openzen.zenscript.codemodel.statement.StatementTransformer;
24
 import org.openzen.zenscript.codemodel.statement.StatementTransformer;
25
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
25
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
26
 import org.openzen.zenscript.codemodel.type.FunctionTypeID;
26
 
27
 
27
 /**
28
 /**
38
 	public Expression(CodePosition position, ITypeID type, ITypeID thrownType) {
39
 	public Expression(CodePosition position, ITypeID type, ITypeID thrownType) {
39
 		if (type == null)
40
 		if (type == null)
40
 			throw new NullPointerException();
41
 			throw new NullPointerException();
42
+		if (type == BasicTypeID.UNDETERMINED)
43
+			throw new IllegalArgumentException("Cannot use undetermined type as expression type");
41
 		
44
 		
42
 		this.position = position;
45
 		this.position = position;
43
 		this.type = type;
46
 		this.type = type;

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetFieldExpression.java View File

8
 import java.util.Collections;
8
 import java.util.Collections;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
12
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
12
 import org.openzen.zenscript.codemodel.scope.TypeScope;
13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
14
 import org.openzen.zenscript.codemodel.type.ITypeID;
52
 		Expression tTarget = target.transform(transformer);
53
 		Expression tTarget = target.transform(transformer);
53
 		return tTarget == target ? this : new GetFieldExpression(position, tTarget, field);
54
 		return tTarget == target ? this : new GetFieldExpression(position, tTarget, field);
54
 	}
55
 	}
56
+	
57
+	@Override
58
+	public IDefinitionMember getMember() {
59
+		return field.member;
60
+	}
55
 }
61
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/GetStaticFieldExpression.java View File

8
 import java.util.Collections;
8
 import java.util.Collections;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
11
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
12
 import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
12
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 import org.openzen.zenscript.codemodel.type.ITypeID;
13
 
14
 
43
 	public Expression transform(ExpressionTransformer transformer) {
44
 	public Expression transform(ExpressionTransformer transformer) {
44
 		return this;
45
 		return this;
45
 	}
46
 	}
47
+	
48
+	@Override
49
+	public IDefinitionMember getMember() {
50
+		return field.member;
51
+	}
46
 }
52
 }

+ 10
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/IPartialExpression.java View File

14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
14
 import org.openzen.zenscript.codemodel.expression.CallArguments;
15
 import org.openzen.zenscript.codemodel.expression.Expression;
15
 import org.openzen.zenscript.codemodel.expression.Expression;
16
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
16
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
17
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
17
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.GenericName;
18
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.type.ITypeID;
19
 import org.openzen.zenscript.codemodel.scope.TypeScope;
20
 import org.openzen.zenscript.codemodel.scope.TypeScope;
39
 	
40
 	
40
 	ITypeID[] getGenericCallTypes();
41
 	ITypeID[] getGenericCallTypes();
41
 	
42
 	
43
+	/**
44
+	 * Retrieves the (primary) member this expression refers to, or null if there is no primary target.
45
+	 * 
46
+	 * @return 
47
+	 */
48
+	default IDefinitionMember getMember() {
49
+		return null;
50
+	}
51
+	
42
 	default Expression assign(CodePosition position, TypeScope scope, Expression value) {
52
 	default Expression assign(CodePosition position, TypeScope scope, Expression value) {
43
 		throw new CompileException(position, CompileExceptionCode.CANNOT_ASSIGN, "This expression is not assignable");
53
 		throw new CompileException(position, CompileExceptionCode.CANNOT_ASSIGN, "This expression is not assignable");
44
 	}
54
 	}

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java View File

147
 	}
147
 	}
148
 	
148
 	
149
 	public OptionalTypeID getOptional(ITypeID original) {
149
 	public OptionalTypeID getOptional(ITypeID original) {
150
+		if (original == null)
151
+			throw new NullPointerException("original cannot be null");
152
+		
150
 		if (optionalTypes.containsKey(original)) {
153
 		if (optionalTypes.containsKey(original)) {
151
 			return optionalTypes.get(original);
154
 			return optionalTypes.get(original);
152
 		} else {
155
 		} else {

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java View File

20
 	public final ITypeID baseType;
20
 	public final ITypeID baseType;
21
 	
21
 	
22
 	public OptionalTypeID(ITypeID baseType) {
22
 	public OptionalTypeID(ITypeID baseType) {
23
+		if (baseType == null)
24
+			throw new NullPointerException("baseType cannot be null");
25
+		
23
 		this.baseType = baseType;
26
 		this.baseType = baseType;
24
 	}
27
 	}
25
 	
28
 	
26
 	@Override
29
 	@Override
27
 	public ITypeID instance(GenericMapper mapper) {
30
 	public ITypeID instance(GenericMapper mapper) {
31
+		if (mapper == null)
32
+			throw new NullPointerException("mapper cannot be null");
33
+		
28
 		return mapper.registry.getModified(TypeMembers.MODIFIER_OPTIONAL, baseType.instance(mapper));
34
 		return mapper.registry.getModified(TypeMembers.MODIFIER_OPTIONAL, baseType.instance(mapper));
29
 	}
35
 	}
30
 
36
 

+ 6
- 4
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java View File

25
 import org.openzen.zenscript.constructor.module.ModuleSpace;
25
 import org.openzen.zenscript.constructor.module.ModuleSpace;
26
 import org.openzen.zenscript.compiler.SemanticModule;
26
 import org.openzen.zenscript.compiler.SemanticModule;
27
 import org.openzen.zenscript.codemodel.type.ISymbol;
27
 import org.openzen.zenscript.codemodel.type.ISymbol;
28
+import org.openzen.zenscript.parser.BracketExpressionParser;
28
 import org.openzen.zenscript.parser.ParsedFile;
29
 import org.openzen.zenscript.parser.ParsedFile;
29
 
30
 
30
 /**
31
 /**
59
 	}
60
 	}
60
 	
61
 	
61
 	public ParsedFile[] parse(ZSPackage pkg) throws IOException {
62
 	public ParsedFile[] parse(ZSPackage pkg) throws IOException {
63
+		// TODO: load bracket parsers from host plugins
62
 		List<ParsedFile> files = new ArrayList<>();
64
 		List<ParsedFile> files = new ArrayList<>();
63
-		parse(files, pkg, sourceDirectory);
65
+		parse(files, pkg, null, sourceDirectory);
64
 		return files.toArray(new ParsedFile[files.size()]);
66
 		return files.toArray(new ParsedFile[files.size()]);
65
 	}
67
 	}
66
 	
68
 	
67
-	private void parse(List<ParsedFile> files, ZSPackage pkg, File directory) throws IOException {
69
+	private void parse(List<ParsedFile> files, ZSPackage pkg, BracketExpressionParser bracketParser, File directory) throws IOException {
68
 		for (File file : directory.listFiles()) {
70
 		for (File file : directory.listFiles()) {
69
 			if (file.getName().endsWith(".zs")) {
71
 			if (file.getName().endsWith(".zs")) {
70
 				try {
72
 				try {
71
-					files.add(ParsedFile.parse(pkg, file));
73
+					files.add(ParsedFile.parse(pkg, bracketParser, file));
72
 				} catch (CompileException ex) {
74
 				} catch (CompileException ex) {
73
 					exceptionLogger.accept(ex);
75
 					exceptionLogger.accept(ex);
74
 				}
76
 				}
75
 			} else if (file.isDirectory()) {
77
 			} else if (file.isDirectory()) {
76
-				parse(files, pkg.getOrCreatePackage(file.getName()), file);
78
+				parse(files, pkg.getOrCreatePackage(file.getName()), bracketParser, file);
77
 			}
79
 			}
78
 		}
80
 		}
79
 	}
81
 	}

+ 14
- 20
DrawableGui/src/main/java/org/openzen/drawablegui/DButton.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui;
6
 package org.openzen.drawablegui;
7
 
7
 
8
-import org.openzen.drawablegui.draw.DDrawSurface;
9
 import org.openzen.drawablegui.draw.DDrawnShape;
8
 import org.openzen.drawablegui.draw.DDrawnShape;
10
 import org.openzen.drawablegui.draw.DDrawnText;
9
 import org.openzen.drawablegui.draw.DDrawnText;
11
 import org.openzen.drawablegui.live.LiveBool;
10
 import org.openzen.drawablegui.live.LiveBool;
14
 import org.openzen.drawablegui.live.MutableLiveObject;
13
 import org.openzen.drawablegui.live.MutableLiveObject;
15
 import org.openzen.drawablegui.style.DShadow;
14
 import org.openzen.drawablegui.style.DShadow;
16
 import org.openzen.drawablegui.style.DStyleClass;
15
 import org.openzen.drawablegui.style.DStyleClass;
17
-import org.openzen.drawablegui.style.DStylePath;
18
 
16
 
19
 /**
17
 /**
20
  *
18
  *
27
 	private final LiveBool disabled;
25
 	private final LiveBool disabled;
28
 	private final Runnable action;
26
 	private final Runnable action;
29
 	
27
 	
30
-	private DDrawSurface surface;
31
-	private int z;
28
+	private DComponentContext context;
32
 	private DIRectangle bounds;
29
 	private DIRectangle bounds;
33
 	
30
 	
34
 	private DButtonStyle style;
31
 	private DButtonStyle style;
49
 	}
46
 	}
50
 	
47
 	
51
 	@Override
48
 	@Override
52
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
53
-		this.surface = surface;
54
-		this.z = z;
55
-		
56
-		DStylePath path = parent.getChild("Button", styleClass);
57
-		this.style = new DButtonStyle(surface.getStylesheet(path));
58
-		fontMetrics = surface.getFontMetrics(style.font);
49
+	public void mount(DComponentContext parent) {
50
+		context = parent.getChildContext("button", styleClass);
51
+		style = context.getStyle(DButtonStyle::new);
52
+		fontMetrics = context.getFontMetrics(style.font);
59
 		
53
 		
60
 		sizing.setValue(new DSizing(
54
 		sizing.setValue(new DSizing(
61
 				style.paddingLeft + style.paddingRight + fontMetrics.getWidth(label.getValue()),
55
 				style.paddingLeft + style.paddingRight + fontMetrics.getWidth(label.getValue()),
65
 	
59
 	
66
 	@Override
60
 	@Override
67
 	public void unmount() {
61
 	public void unmount() {
68
-		surface = null;
62
+		context = null;
69
 		
63
 		
70
 		if (shape != null)
64
 		if (shape != null)
71
 			shape.close();
65
 			shape.close();
97
 		if (text != null)
91
 		if (text != null)
98
 			text.close();
92
 			text.close();
99
 		
93
 		
100
-		shape = surface.shadowPath(
101
-				z,
102
-				DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, 2 * surface.getScale()),
94
+		shape = context.shadowPath(
95
+				0,
96
+				DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, 2 * context.getScale()),
103
 				DTransform2D.IDENTITY,
97
 				DTransform2D.IDENTITY,
104
 				getBackgroundColor(),
98
 				getBackgroundColor(),
105
 				currentShadow);
99
 				currentShadow);
106
-		text = surface.drawText(
107
-				z +  1, 
100
+		text = context.drawText(
101
+				1, 
108
 				style.font,
102
 				style.font,
109
 				style.textColor,
103
 				style.textColor,
110
 				bounds.x + style.paddingLeft,
104
 				bounds.x + style.paddingLeft,
155
 			if (shape != null)
149
 			if (shape != null)
156
 				shape.close();
150
 				shape.close();
157
 			
151
 			
158
-			shape = surface.shadowPath(
159
-				z,
160
-				DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, 2 * surface.getScale()),
152
+			shape = context.shadowPath(
153
+				0,
154
+				DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, 2 * context.getScale()),
161
 				DTransform2D.IDENTITY,
155
 				DTransform2D.IDENTITY,
162
 				getBackgroundColor(),
156
 				getBackgroundColor(),
163
 				currentShadow);
157
 				currentShadow);

+ 1
- 7
DrawableGui/src/main/java/org/openzen/drawablegui/DComponent.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui;
6
 package org.openzen.drawablegui;
7
 
7
 
8
-import org.openzen.drawablegui.draw.DDrawSurface;
9
 import org.openzen.drawablegui.live.LiveObject;
8
 import org.openzen.drawablegui.live.LiveObject;
10
-import org.openzen.drawablegui.style.DStylePath;
11
 
9
 
12
 /**
10
 /**
13
  *
11
  *
14
  * @author Hoofdgebruiker
12
  * @author Hoofdgebruiker
15
  */
13
  */
16
 public interface DComponent extends Destructible {
14
 public interface DComponent extends Destructible {
17
-	void mount(DStylePath parent, int z, DDrawSurface surface);
15
+	void mount(DComponentContext context);
18
 	
16
 	
19
 	void unmount();
17
 	void unmount();
20
 	
18
 	
26
 	
24
 	
27
 	void setBounds(DIRectangle bounds);
25
 	void setBounds(DIRectangle bounds);
28
 	
26
 	
29
-	default void onMounted() {}
30
-	
31
-	default void onUnmounted() {}
32
-	
33
 	default void onMouseEnter(DMouseEvent e) {}
27
 	default void onMouseEnter(DMouseEvent e) {}
34
 	
28
 	
35
 	default void onMouseExit(DMouseEvent e) {}
29
 	default void onMouseExit(DMouseEvent e) {}

+ 92
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DComponentContext.java View File

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 java.util.function.Function;
9
+import org.openzen.drawablegui.draw.DDrawSurface;
10
+import org.openzen.drawablegui.draw.DDrawnRectangle;
11
+import org.openzen.drawablegui.draw.DDrawnShape;
12
+import org.openzen.drawablegui.draw.DDrawnText;
13
+import org.openzen.drawablegui.draw.DSubSurface;
14
+import org.openzen.drawablegui.scroll.DScrollContext;
15
+import org.openzen.drawablegui.style.DShadow;
16
+import org.openzen.drawablegui.style.DStyleClass;
17
+import org.openzen.drawablegui.style.DStyleDefinition;
18
+import org.openzen.drawablegui.style.DStylePath;
19
+
20
+/**
21
+ *
22
+ * @author Hoofdgebruiker
23
+ */
24
+public class DComponentContext {
25
+	public final DScrollContext scrollContext;
26
+	public final DStylePath path;
27
+	public final int z;
28
+	public final DDrawSurface surface;
29
+	
30
+	public DComponentContext(DScrollContext scrollContext, DStylePath path, int z, DDrawSurface surface) {
31
+		this.scrollContext = scrollContext;
32
+		this.path = path;
33
+		this.z = z;
34
+		this.surface = surface;
35
+	}
36
+	
37
+	public DComponentContext getChildContext(String component, DStyleClass styleClass) {
38
+		return getChildContext(10, component, styleClass);
39
+	}
40
+	
41
+	public DComponentContext getChildContext(int deltaz, String component, DStyleClass styleClass) {
42
+		return new DComponentContext(scrollContext, path.getChild(component, styleClass), z + deltaz, surface);
43
+	}
44
+	
45
+	public DUIContext getUIContext() {
46
+		return surface.getContext();
47
+	}
48
+	
49
+	public DStyleDefinition getStyle() {
50
+		return surface.getStylesheet(path);
51
+	}
52
+	
53
+	public <S> S getStyle(Function<DStyleDefinition, S> factory) {
54
+		return factory.apply(surface.getStylesheet(path));
55
+	}
56
+
57
+	public DFontMetrics getFontMetrics(DFont font) {
58
+		return surface.getFontMetrics(font);
59
+	}
60
+	
61
+	public float getScale() {
62
+		return surface.getScale();
63
+	}
64
+	
65
+	public float getTextScale() {
66
+		return surface.getTextScale();
67
+	}
68
+	
69
+	public DDrawnText drawText(int deltaz, DFont font, int color, float x, float y, String text) {
70
+		return surface.drawText(z + deltaz, font, color, x, y, text);
71
+	}
72
+	
73
+	public DDrawnRectangle fillRect(int deltaz, DIRectangle rectangle, int color) {
74
+		return surface.fillRect(z + deltaz, rectangle, color);
75
+	}
76
+	
77
+	public DDrawnShape strokePath(int deltaz, DPath path, DTransform2D transform, int color, float lineWidth) {
78
+		return surface.strokePath(z + deltaz, path, transform, color, lineWidth);
79
+	}
80
+	
81
+	public DDrawnShape fillPath(int deltaz, DPath path, DTransform2D transform, int color) {
82
+		return surface.fillPath(z + deltaz, path, transform, color);
83
+	}
84
+	
85
+	public DDrawnShape shadowPath(int deltaz, DPath path, DTransform2D transform, int color, DShadow shadow) {
86
+		return surface.shadowPath(z + deltaz, path, transform, color, shadow);
87
+	}
88
+	
89
+	public DSubSurface createSubSurface(int deltaz) {
90
+		return surface.createSubSurface(z + deltaz);
91
+	}
92
+}

+ 1
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/DEmptyView.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui;
6
 package org.openzen.drawablegui;
7
 
7
 
8
-import org.openzen.drawablegui.draw.DDrawSurface;
9
 import org.openzen.drawablegui.live.ImmutableLiveObject;
8
 import org.openzen.drawablegui.live.ImmutableLiveObject;
10
 import org.openzen.drawablegui.live.LiveObject;
9
 import org.openzen.drawablegui.live.LiveObject;
11
-import org.openzen.drawablegui.style.DStylePath;
12
 
10
 
13
 /**
11
 /**
14
  *
12
  *
22
 	private DEmptyView() {}
20
 	private DEmptyView() {}
23
 
21
 
24
 	@Override
22
 	@Override
25
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
23
+	public void mount(DComponentContext parent) {
26
 		
24
 		
27
 	}
25
 	}
28
 	
26
 	

+ 18
- 24
DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui;
6
 package org.openzen.drawablegui;
7
 
7
 
8
-import org.openzen.drawablegui.draw.DDrawSurface;
9
 import org.openzen.drawablegui.draw.DDrawnRectangle;
8
 import org.openzen.drawablegui.draw.DDrawnRectangle;
10
 import org.openzen.drawablegui.draw.DDrawnShape;
9
 import org.openzen.drawablegui.draw.DDrawnShape;
11
 import org.openzen.drawablegui.draw.DDrawnText;
10
 import org.openzen.drawablegui.draw.DDrawnText;
16
 import org.openzen.drawablegui.live.MutableLiveString;
15
 import org.openzen.drawablegui.live.MutableLiveString;
17
 import org.openzen.drawablegui.style.DDimension;
16
 import org.openzen.drawablegui.style.DDimension;
18
 import org.openzen.drawablegui.style.DStyleClass;
17
 import org.openzen.drawablegui.style.DStyleClass;
19
-import org.openzen.drawablegui.style.DStylePath;
20
 
18
 
21
 /**
19
 /**
22
  *
20
  *
31
 	private DIRectangle bounds = DIRectangle.EMPTY;
29
 	private DIRectangle bounds = DIRectangle.EMPTY;
32
 	private final DDimension preferredWidth;
30
 	private final DDimension preferredWidth;
33
 	
31
 	
34
-	private DDrawSurface surface;
35
-	private int z;
32
+	private DComponentContext context;
36
 	private DInputFieldStyle style;
33
 	private DInputFieldStyle style;
37
 	private DFontMetrics fontMetrics;
34
 	private DFontMetrics fontMetrics;
38
 	private int cursorFrom = -1;
35
 	private int cursorFrom = -1;
74
 	}
71
 	}
75
 
72
 
76
 	@Override
73
 	@Override
77
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
78
-		this.surface = surface;
79
-		this.z = z;
80
-		
81
-		DStylePath path = parent.getChild("input", styleClass);
82
-		style = new DInputFieldStyle(surface.getStylesheet(path));
83
-		fontMetrics = surface.getFontMetrics(style.font);
74
+	public void mount(DComponentContext parent) {
75
+		context = parent.getChildContext("input", styleClass);
76
+		style = context.getStyle(DInputFieldStyle::new);
77
+		fontMetrics = context.getFontMetrics(style.font);
84
 		
78
 		
85
 		sizing.setValue(new DSizing(
79
 		sizing.setValue(new DSizing(
86
-				preferredWidth.evalInt(surface.getContext()) + style.margin.getHorizontal() + style.border.getPaddingHorizontal(),
80
+				preferredWidth.evalInt(context.getUIContext()) + style.margin.getHorizontal() + style.border.getPaddingHorizontal(),
87
 				fontMetrics.getAscent() + fontMetrics.getDescent() + style.margin.getVertical() + style.border.getPaddingVertical()));
81
 				fontMetrics.getAscent() + fontMetrics.getDescent() + style.margin.getVertical() + style.border.getPaddingVertical()));
88
 		
82
 		
89
 		if (blinkTimer != null)
83
 		if (blinkTimer != null)
90
 			blinkTimer.close();
84
 			blinkTimer.close();
91
-		blinkTimer = surface.getContext().setTimer(300, this::blink);
85
+		blinkTimer = context.getUIContext().setTimer(300, this::blink);
92
 		
86
 		
93
 		if (text != null)
87
 		if (text != null)
94
 			text.close();
88
 			text.close();
95
-		text = surface.drawText(
96
-				z + 2,
89
+		text = parent.drawText(
90
+				2,
97
 				style.font,
91
 				style.font,
98
 				style.color,
92
 				style.color,
99
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
93
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
102
 		
96
 		
103
 		if (cursor != null)
97
 		if (cursor != null)
104
 			cursor.close();
98
 			cursor.close();
105
-		cursor = surface.fillRect(z + 2, DIRectangle.EMPTY, cursorBlink ? style.cursorColor : 0);
99
+		cursor = parent.fillRect(2, DIRectangle.EMPTY, cursorBlink ? style.cursorColor : 0);
106
 		
100
 		
107
 		if (selection != null)
101
 		if (selection != null)
108
 			selection.close();
102
 			selection.close();
109
-		selection = surface.fillRect(z + 1, DIRectangle.EMPTY, 0);
103
+		selection = parent.fillRect(1, DIRectangle.EMPTY, 0);
110
 		
104
 		
111
 		setCursor(cursorFrom, cursorTo);
105
 		setCursor(cursorFrom, cursorTo);
112
 	}
106
 	}
154
 		
148
 		
155
 		if (shape != null)
149
 		if (shape != null)
156
 			shape.close();
150
 			shape.close();
157
-		shape = surface.fillPath(z, style.shape.instance(style.margin.apply(bounds)), DTransform2D.IDENTITY, style.backgroundColor);
151
+		shape = context.fillPath(0, style.shape.instance(style.margin.apply(bounds)), DTransform2D.IDENTITY, style.backgroundColor);
158
 		text.setPosition(
152
 		text.setPosition(
159
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
153
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
160
 				bounds.y + style.margin.top + style.border.getPaddingTop() + fontMetrics.getAscent());
154
 				bounds.y + style.margin.top + style.border.getPaddingTop() + fontMetrics.getAscent());
161
-		style.border.update(surface, z, bounds);
155
+		style.border.update(context, bounds);
162
 	}
156
 	}
163
 	
157
 	
164
 	@Override
158
 	@Override
165
 	public void onMouseEnter(DMouseEvent e) {
159
 	public void onMouseEnter(DMouseEvent e) {
166
-		surface.getContext().setCursor(DUIContext.Cursor.TEXT);
160
+		context.getUIContext().setCursor(DUIContext.Cursor.TEXT);
167
 	}
161
 	}
168
 	
162
 	
169
 	@Override
163
 	@Override
170
 	public void onMouseExit(DMouseEvent e) {
164
 	public void onMouseExit(DMouseEvent e) {
171
-		surface.getContext().setCursor(DUIContext.Cursor.NORMAL);
165
+		context.getUIContext().setCursor(DUIContext.Cursor.NORMAL);
172
 	}
166
 	}
173
 	
167
 	
174
 	@Override
168
 	@Override
175
 	public void onMouseClick(DMouseEvent e) {
169
 	public void onMouseClick(DMouseEvent e) {
176
-		surface.getContext().getWindow().focus(this);
170
+		context.getUIContext().getWindow().focus(this);
177
 	}
171
 	}
178
 	
172
 	
179
 	@Override
173
 	@Override
244
 	private void handleValueUpdated(String newValue) {
238
 	private void handleValueUpdated(String newValue) {
245
 		if (text != null)
239
 		if (text != null)
246
 			text.close();
240
 			text.close();
247
-		text = surface.drawText(
248
-				z + 2,
241
+		text = context.drawText(
242
+				2,
249
 				style.font,
243
 				style.font,
250
 				style.color,
244
 				style.color,
251
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
245
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),

+ 9
- 16
DrawableGui/src/main/java/org/openzen/drawablegui/DLabel.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui;
6
 package org.openzen.drawablegui;
7
 
7
 
8
-import org.openzen.drawablegui.draw.DDrawSurface;
9
 import org.openzen.drawablegui.draw.DDrawnText;
8
 import org.openzen.drawablegui.draw.DDrawnText;
10
 import org.openzen.drawablegui.listeners.ListenerHandle;
9
 import org.openzen.drawablegui.listeners.ListenerHandle;
11
 import org.openzen.drawablegui.live.LiveObject;
10
 import org.openzen.drawablegui.live.LiveObject;
12
 import org.openzen.drawablegui.live.LiveString;
11
 import org.openzen.drawablegui.live.LiveString;
13
 import org.openzen.drawablegui.live.MutableLiveObject;
12
 import org.openzen.drawablegui.live.MutableLiveObject;
14
 import org.openzen.drawablegui.style.DStyleClass;
13
 import org.openzen.drawablegui.style.DStyleClass;
15
-import org.openzen.drawablegui.style.DStylePath;
16
 
14
 
17
 /**
15
 /**
18
  *
16
  *
24
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
22
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
25
 	private final ListenerHandle<LiveString.Listener> labelListener;
23
 	private final ListenerHandle<LiveString.Listener> labelListener;
26
 	
24
 	
27
-	private DDrawSurface surface;
28
-	private int z;
25
+	private DComponentContext context;
29
 	private DIRectangle bounds;
26
 	private DIRectangle bounds;
30
 	private DLabelStyle style;
27
 	private DLabelStyle style;
31
 	private DFontMetrics fontMetrics;
28
 	private DFontMetrics fontMetrics;
40
 	}
37
 	}
41
 
38
 
42
 	@Override
39
 	@Override
43
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
44
-		this.surface = surface;
45
-		this.z = z;
46
-		
47
-		DStylePath path = parent.getChild("label", styleClass);
48
-		style = new DLabelStyle(surface.getStylesheet(path));
49
-		
50
-		fontMetrics = surface.getFontMetrics(style.font);
40
+	public void mount(DComponentContext parent) {
41
+		context = parent.getChildContext("label", styleClass);
42
+		style = context.getStyle(DLabelStyle::new);
43
+		fontMetrics = context.getFontMetrics(style.font);
51
 		calculateDimension();
44
 		calculateDimension();
52
 		
45
 		
53
 		if (text != null)
46
 		if (text != null)
54
 			text.close();
47
 			text.close();
55
-		text = surface.drawText(z, style.font, style.color, 0, 0, label.getValue());
48
+		text = context.drawText(0, style.font, style.color, 0, 0, label.getValue());
56
 	}
49
 	}
57
 	
50
 	
58
 	@Override
51
 	@Override
81
 	@Override
74
 	@Override
82
 	public void setBounds(DIRectangle bounds) {
75
 	public void setBounds(DIRectangle bounds) {
83
 		this.bounds = bounds;
76
 		this.bounds = bounds;
84
-		style.border.update(surface, z + 1, bounds);
77
+		style.border.update(context, bounds);
85
 		text.setPosition(
78
 		text.setPosition(
86
 				bounds.x + style.border.getPaddingLeft(),
79
 				bounds.x + style.border.getPaddingLeft(),
87
 				bounds.y + style.border.getPaddingTop() + fontMetrics.getAscent());
80
 				bounds.y + style.border.getPaddingTop() + fontMetrics.getAscent());
98
 		
91
 		
99
 		if (text != null)
92
 		if (text != null)
100
 			text.close();
93
 			text.close();
101
-		text = surface.drawText(
102
-				z,
94
+		text = context.drawText(
95
+				0,
103
 				style.font,
96
 				style.font,
104
 				style.color,
97
 				style.color,
105
 				bounds.x + style.border.getPaddingLeft(),
98
 				bounds.x + style.border.getPaddingLeft(),

+ 11
- 17
DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltipComponent.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui;
6
 package org.openzen.drawablegui;
7
 
7
 
8
-import org.openzen.drawablegui.draw.DDrawSurface;
9
 import org.openzen.drawablegui.draw.DDrawnRectangle;
8
 import org.openzen.drawablegui.draw.DDrawnRectangle;
10
 import org.openzen.drawablegui.draw.DDrawnText;
9
 import org.openzen.drawablegui.draw.DDrawnText;
11
 import org.openzen.drawablegui.listeners.ListenerHandle;
10
 import org.openzen.drawablegui.listeners.ListenerHandle;
13
 import org.openzen.drawablegui.live.LiveString;
12
 import org.openzen.drawablegui.live.LiveString;
14
 import org.openzen.drawablegui.live.MutableLiveObject;
13
 import org.openzen.drawablegui.live.MutableLiveObject;
15
 import org.openzen.drawablegui.style.DStyleClass;
14
 import org.openzen.drawablegui.style.DStyleClass;
16
-import org.openzen.drawablegui.style.DStylePath;
17
 
15
 
18
 /**
16
 /**
19
  *
17
  *
25
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
23
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
26
 	private final ListenerHandle<LiveString.Listener> tooltipListener;
24
 	private final ListenerHandle<LiveString.Listener> tooltipListener;
27
 	
25
 	
28
-	private DDrawSurface surface;
29
-	private int z;
26
+	private DComponentContext context;
30
 	private DIRectangle bounds;
27
 	private DIRectangle bounds;
31
 	private DFontMetrics fontMetrics;
28
 	private DFontMetrics fontMetrics;
32
 	private DSimpleTooltipStyle style;
29
 	private DSimpleTooltipStyle style;
41
 	}
38
 	}
42
 	
39
 	
43
 	private void onTooltipChanged(String oldValue, String newValue) {
40
 	private void onTooltipChanged(String oldValue, String newValue) {
44
-		if (surface == null || bounds == null)
41
+		if (context == null || bounds == null)
45
 			return;
42
 			return;
46
 		
43
 		
47
 		calculateSize();
44
 		calculateSize();
54
 		if (text != null)
51
 		if (text != null)
55
 			text.close();
52
 			text.close();
56
 		
53
 		
57
-		text = surface.drawText(
58
-				z,
54
+		text = context.drawText(
55
+				0,
59
 				style.font,
56
 				style.font,
60
 				style.textColor,
57
 				style.textColor,
61
 				bounds.x + style.border.getPaddingLeft(),
58
 				bounds.x + style.border.getPaddingLeft(),
66
 	@Override
63
 	@Override
67
 	public void setBounds(DIRectangle bounds) {
64
 	public void setBounds(DIRectangle bounds) {
68
 		this.bounds = bounds;
65
 		this.bounds = bounds;
69
-		style.border.update(surface, z + 1, bounds);
66
+		style.border.update(context, bounds);
70
 		
67
 		
71
 		if (background != null)
68
 		if (background != null)
72
 			background.close();
69
 			background.close();
73
-		background = surface.fillRect(z, bounds, style.backgroundColor);
70
+		background = context.fillRect(0, bounds, style.backgroundColor);
74
 		text.setPosition(
71
 		text.setPosition(
75
 				bounds.x + style.border.getPaddingLeft(),
72
 				bounds.x + style.border.getPaddingLeft(),
76
 				bounds.y + style.border.getPaddingTop() + fontMetrics.getAscent());
73
 				bounds.y + style.border.getPaddingTop() + fontMetrics.getAscent());
92
 	}
89
 	}
93
 	
90
 	
94
 	@Override
91
 	@Override
95
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
96
-		this.surface = surface;
97
-		this.z = z;
98
-		
99
-		DStylePath path = parent.getChild("tooltip", styleClass);
100
-		style = new DSimpleTooltipStyle(surface.getStylesheet(path));
101
-		fontMetrics = surface.getFontMetrics(style.font);
92
+	public void mount(DComponentContext parent) {
93
+		context = parent.getChildContext("tooltip", styleClass);
94
+		style = context.getStyle(DSimpleTooltipStyle::new);
95
+		fontMetrics = context.getFontMetrics(style.font);
102
 		calculateSize();
96
 		calculateSize();
103
 		
97
 		
104
 		if (text != null)
98
 		if (text != null)
105
 			text.close();
99
 			text.close();
106
-		text = surface.drawText(z + 1, style.font, style.textColor, 0, 0, tooltip.getValue());
100
+		text = parent.drawText(1, style.font, style.textColor, 0, 0, tooltip.getValue());
107
 	}
101
 	}
108
 	
102
 	
109
 	@Override
103
 	@Override

+ 0
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java View File

26
 	
26
 	
27
 	void setCursor(Cursor cursor);
27
 	void setCursor(Cursor cursor);
28
 	
28
 	
29
-	void scrollInView(int x, int y, int width, int height);
30
-	
31
 	DTimerHandle setTimer(int millis, Runnable target);
29
 	DTimerHandle setTimer(int millis, Runnable target);
32
 	
30
 	
33
 	DClipboard getClipboard();
31
 	DClipboard getClipboard();

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/border/DBorder.java View File

6
 package org.openzen.drawablegui.border;
6
 package org.openzen.drawablegui.border;
7
 
7
 
8
 import java.io.Closeable;
8
 import java.io.Closeable;
9
+import org.openzen.drawablegui.DComponentContext;
9
 import org.openzen.drawablegui.DIRectangle;
10
 import org.openzen.drawablegui.DIRectangle;
10
-import org.openzen.drawablegui.draw.DDrawSurface;
11
 
11
 
12
 /**
12
 /**
13
  *
13
  *
14
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
15
  */
15
  */
16
 public interface DBorder extends Closeable {
16
 public interface DBorder extends Closeable {
17
-	public void update(DDrawSurface surface, int z, DIRectangle bounds);
17
+	public void update(DComponentContext context, DIRectangle bounds);
18
 	
18
 	
19
 	public int getPaddingLeft();
19
 	public int getPaddingLeft();
20
 	
20
 	

+ 3
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/border/DCompositeBorder.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui.border;
6
 package org.openzen.drawablegui.border;
7
 
7
 
8
+import org.openzen.drawablegui.DComponentContext;
8
 import org.openzen.drawablegui.DIRectangle;
9
 import org.openzen.drawablegui.DIRectangle;
9
-import org.openzen.drawablegui.draw.DDrawSurface;
10
 
10
 
11
 /**
11
 /**
12
  *
12
  *
20
 	}
20
 	}
21
 
21
 
22
 	@Override
22
 	@Override
23
-	public void update(DDrawSurface surface, int z, DIRectangle bounds) {
23
+	public void update(DComponentContext context, DIRectangle bounds) {
24
 		for (DBorder border : borders) {
24
 		for (DBorder border : borders) {
25
-			border.update(surface, z, bounds);
25
+			border.update(context, bounds);
26
 			bounds = new DIRectangle(
26
 			bounds = new DIRectangle(
27
 					bounds.x + border.getPaddingLeft(),
27
 					bounds.x + border.getPaddingLeft(),
28
 					bounds.y + border.getPaddingTop(),
28
 					bounds.y + border.getPaddingTop(),

+ 12
- 16
DrawableGui/src/main/java/org/openzen/drawablegui/border/DCustomWindowBorder.java View File

6
 package org.openzen.drawablegui.border;
6
 package org.openzen.drawablegui.border;
7
 
7
 
8
 import org.openzen.drawablegui.DComponent;
8
 import org.openzen.drawablegui.DComponent;
9
+import org.openzen.drawablegui.DComponentContext;
9
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DMouseEvent;
11
 import org.openzen.drawablegui.DMouseEvent;
11
 import org.openzen.drawablegui.DPath;
12
 import org.openzen.drawablegui.DPath;
12
 import org.openzen.drawablegui.DTransform2D;
13
 import org.openzen.drawablegui.DTransform2D;
13
 import org.openzen.drawablegui.DUIWindow;
14
 import org.openzen.drawablegui.DUIWindow;
14
 import org.openzen.drawablegui.DIRectangle;
15
 import org.openzen.drawablegui.DIRectangle;
15
-import org.openzen.drawablegui.draw.DDrawSurface;
16
 import org.openzen.drawablegui.draw.DDrawnRectangle;
16
 import org.openzen.drawablegui.draw.DDrawnRectangle;
17
 import org.openzen.drawablegui.draw.DDrawnShape;
17
 import org.openzen.drawablegui.draw.DDrawnShape;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
20
 import org.openzen.drawablegui.live.LiveBool;
20
 import org.openzen.drawablegui.live.LiveBool;
21
 import org.openzen.drawablegui.live.LiveObject;
21
 import org.openzen.drawablegui.live.LiveObject;
22
 import org.openzen.drawablegui.style.DStyleClass;
22
 import org.openzen.drawablegui.style.DStyleClass;
23
-import org.openzen.drawablegui.style.DStylePath;
24
 
23
 
25
 /**
24
 /**
26
  *
25
  *
31
 	private final DComponent content;
30
 	private final DComponent content;
32
 	private final LiveObject<DSizing> sizing = new ImmutableLiveObject<>(DSizing.EMPTY);
31
 	private final LiveObject<DSizing> sizing = new ImmutableLiveObject<>(DSizing.EMPTY);
33
 	
32
 	
34
-	private DDrawSurface surface;
35
-	private int z;
33
+	private DComponentContext context;
36
 	private DCustomWindowBorderStyle style;
34
 	private DCustomWindowBorderStyle style;
37
 	private DIRectangle bounds;
35
 	private DIRectangle bounds;
38
 	
36
 	
52
 	}
50
 	}
53
 
51
 
54
 	@Override
52
 	@Override
55
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
56
-		this.surface = surface;
57
-		this.z = z;
58
-		content.mount(parent, z + 1, surface);
53
+	public void mount(DComponentContext parent) {
54
+		context = parent.getChildContext("customwindowborder", styleClass);
55
+		content.mount(context);
59
 		
56
 		
60
-		state = surface.getContext().getWindow().getWindowState();
61
-		active = surface.getContext().getWindow().getActive();
57
+		state = parent.getUIContext().getWindow().getWindowState();
58
+		active = parent.getUIContext().getWindow().getActive();
62
 		stateListener = state.addListener(this::onStateChanged);
59
 		stateListener = state.addListener(this::onStateChanged);
63
 		activeListener = active.addListener(this::onActiveChanged);
60
 		activeListener = active.addListener(this::onActiveChanged);
64
 		
61
 		
65
-		DStylePath path = parent.getChild("customwindowborder", styleClass);
66
-		style = new DCustomWindowBorderStyle(surface.getStylesheet(path));
62
+		style = parent.getStyle(DCustomWindowBorderStyle::new);
67
 		
63
 		
68
 		if (bounds != null)
64
 		if (bounds != null)
69
 			layout();
65
 			layout();
113
 					bounds.height - 2 * style.padding - style.borderWidth);
109
 					bounds.height - 2 * style.padding - style.borderWidth);
114
 			if (border != null)
110
 			if (border != null)
115
 				border.close();
111
 				border.close();
116
-			border = surface.strokePath(
117
-					z + 1,
112
+			border = context.strokePath(
113
+					1,
118
 					path,
114
 					path,
119
 					DTransform2D.IDENTITY,
115
 					DTransform2D.IDENTITY,
120
 					active.getValue() ? style.focusedBorderColor : style.inactiveBorderColor,
116
 					active.getValue() ? style.focusedBorderColor : style.inactiveBorderColor,
135
 				background.close();
131
 				background.close();
136
 				background = null;
132
 				background = null;
137
 			}
133
 			}
138
-			shadowedBackground = surface.shadowPath(z, path, DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
134
+			shadowedBackground = context.shadowPath(0, path, DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
139
 		} else {
135
 		} else {
140
 			content.setBounds(bounds);
136
 			content.setBounds(bounds);
141
 			
137
 			
148
 				border = null;
144
 				border = null;
149
 			}
145
 			}
150
 			if (background == null) {
146
 			if (background == null) {
151
-				background = surface.fillRect(z, bounds, style.backgroundColor);
147
+				background = context.fillRect(0, bounds, style.backgroundColor);
152
 			} else {
148
 			} else {
153
 				background.setRectangle(bounds);
149
 				background.setRectangle(bounds);
154
 			}
150
 			}

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/border/DEmptyBorder.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui.border;
6
 package org.openzen.drawablegui.border;
7
 
7
 
8
+import org.openzen.drawablegui.DComponentContext;
8
 import org.openzen.drawablegui.DIRectangle;
9
 import org.openzen.drawablegui.DIRectangle;
9
-import org.openzen.drawablegui.draw.DDrawSurface;
10
 import org.openzen.drawablegui.style.DBorderElement;
10
 import org.openzen.drawablegui.style.DBorderElement;
11
 
11
 
12
 /**
12
 /**
20
 	private DEmptyBorder() {}
20
 	private DEmptyBorder() {}
21
 	
21
 	
22
 	@Override
22
 	@Override
23
-	public void update(DDrawSurface surface, int z, DIRectangle bounds) {
23
+	public void update(DComponentContext context, DIRectangle bounds) {
24
 		
24
 		
25
 	}
25
 	}
26
 
26
 

+ 3
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/border/DLineBorder.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui.border;
6
 package org.openzen.drawablegui.border;
7
 
7
 
8
+import org.openzen.drawablegui.DComponentContext;
8
 import org.openzen.drawablegui.DTransform2D;
9
 import org.openzen.drawablegui.DTransform2D;
9
 import org.openzen.drawablegui.DIRectangle;
10
 import org.openzen.drawablegui.DIRectangle;
10
-import org.openzen.drawablegui.draw.DDrawSurface;
11
 import org.openzen.drawablegui.draw.DDrawnShape;
11
 import org.openzen.drawablegui.draw.DDrawnShape;
12
 
12
 
13
 /**
13
 /**
26
 	}
26
 	}
27
 
27
 
28
 	@Override
28
 	@Override
29
-	public void update(DDrawSurface surface, int z, DIRectangle bounds) {
29
+	public void update(DComponentContext context, DIRectangle bounds) {
30
 		if (shape != null)
30
 		if (shape != null)
31
 			shape.close();
31
 			shape.close();
32
 		
32
 		
33
-		shape = surface.strokePath(z, tracer -> {
33
+		shape = context.strokePath(1, tracer -> {
34
 				tracer.moveTo(bounds.x, bounds.y);
34
 				tracer.moveTo(bounds.x, bounds.y);
35
 				tracer.lineTo(bounds.x + bounds.width - borderWidth, bounds.y);
35
 				tracer.lineTo(bounds.x + bounds.width - borderWidth, bounds.y);
36
 				tracer.lineTo(bounds.x + bounds.width - borderWidth, bounds.y + bounds.height - borderWidth);
36
 				tracer.lineTo(bounds.x + bounds.width - borderWidth, bounds.y + bounds.height - borderWidth);

+ 2
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/border/DPaddedBorder.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui.border;
6
 package org.openzen.drawablegui.border;
7
 
7
 
8
+import org.openzen.drawablegui.DComponentContext;
8
 import org.openzen.drawablegui.DIRectangle;
9
 import org.openzen.drawablegui.DIRectangle;
9
-import org.openzen.drawablegui.draw.DDrawSurface;
10
 
10
 
11
 /**
11
 /**
12
  *
12
  *
30
 	}
30
 	}
31
 
31
 
32
 	@Override
32
 	@Override
33
-	public void update(DDrawSurface surface, int z, DIRectangle bounds) {
33
+	public void update(DComponentContext context, DIRectangle bounds) {
34
 		// nothing to paint
34
 		// nothing to paint
35
 	}
35
 	}
36
 
36
 

+ 6
- 6
DrawableGui/src/main/java/org/openzen/drawablegui/border/DSideBorder.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui.border;
6
 package org.openzen.drawablegui.border;
7
 
7
 
8
+import org.openzen.drawablegui.DComponentContext;
8
 import org.openzen.drawablegui.DIRectangle;
9
 import org.openzen.drawablegui.DIRectangle;
9
 import org.openzen.drawablegui.DPath;
10
 import org.openzen.drawablegui.DPath;
10
 import org.openzen.drawablegui.DTransform2D;
11
 import org.openzen.drawablegui.DTransform2D;
11
-import org.openzen.drawablegui.draw.DDrawSurface;
12
 import org.openzen.drawablegui.draw.DDrawnShape;
12
 import org.openzen.drawablegui.draw.DDrawnShape;
13
 
13
 
14
 /**
14
 /**
46
 	}
46
 	}
47
 
47
 
48
 	@Override
48
 	@Override
49
-	public void update(DDrawSurface surface, int z, DIRectangle bounds) {
49
+	public void update(DComponentContext context, DIRectangle bounds) {
50
 		if (leftWidth > 0) {
50
 		if (leftWidth > 0) {
51
 			int x = bounds.x;
51
 			int x = bounds.x;
52
 			if (left != null)
52
 			if (left != null)
53
 				left.close();
53
 				left.close();
54
-			left = surface.strokePath(z, DPath.line(x, bounds.y, x, bounds.y + bounds.height), DTransform2D.IDENTITY, topColor, topWidth);
54
+			left = context.strokePath(1, DPath.line(x, bounds.y, x, bounds.y + bounds.height), DTransform2D.IDENTITY, topColor, topWidth);
55
 		}
55
 		}
56
 		if (topWidth > 0) {
56
 		if (topWidth > 0) {
57
 			int y = bounds.y;
57
 			int y = bounds.y;
58
 			if (top != null)
58
 			if (top != null)
59
 				top.close();
59
 				top.close();
60
-			top = surface.strokePath(z, DPath.line(bounds.x, y, bounds.x + bounds.width, y), DTransform2D.IDENTITY, topColor, topWidth);
60
+			top = context.strokePath(1, DPath.line(bounds.x, y, bounds.x + bounds.width, y), DTransform2D.IDENTITY, topColor, topWidth);
61
 		}
61
 		}
62
 		if (rightWidth > 0) {
62
 		if (rightWidth > 0) {
63
 			int x = bounds.x + bounds.width - rightWidth;
63
 			int x = bounds.x + bounds.width - rightWidth;
64
 			if (right != null)
64
 			if (right != null)
65
 				right.close();
65
 				right.close();
66
-			right = surface.strokePath(z, DPath.line(x, bounds.y, x, bounds.y + bounds.height), DTransform2D.IDENTITY, topColor, topWidth);
66
+			right = context.strokePath(1, DPath.line(x, bounds.y, x, bounds.y + bounds.height), DTransform2D.IDENTITY, topColor, topWidth);
67
 		}
67
 		}
68
 		if (bottomWidth > 0) {
68
 		if (bottomWidth > 0) {
69
 			int y = bounds.y + bounds.height - bottomWidth;
69
 			int y = bounds.y + bounds.height - bottomWidth;
70
 			if (bottom != null)
70
 			if (bottom != null)
71
 				bottom.close();
71
 				bottom.close();
72
-			bottom = surface.strokePath(z, DPath.line(bounds.x, y, bounds.x + bounds.width, y), DTransform2D.IDENTITY, topColor, topWidth);
72
+			bottom = context.strokePath(1, DPath.line(bounds.x, y, bounds.x + bounds.width, y), DTransform2D.IDENTITY, topColor, topWidth);
73
 		}
73
 		}
74
 	}
74
 	}
75
 
75
 

+ 8
- 11
DrawableGui/src/main/java/org/openzen/drawablegui/form/DForm.java View File

9
 import java.util.function.Predicate;
9
 import java.util.function.Predicate;
10
 import org.openzen.drawablegui.BaseComponentGroup;
10
 import org.openzen.drawablegui.BaseComponentGroup;
11
 import org.openzen.drawablegui.DComponent;
11
 import org.openzen.drawablegui.DComponent;
12
+import org.openzen.drawablegui.DComponentContext;
12
 import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DIRectangle;
15
 import org.openzen.drawablegui.DIRectangle;
15
-import org.openzen.drawablegui.draw.DDrawSurface;
16
 import org.openzen.drawablegui.draw.DDrawnText;
16
 import org.openzen.drawablegui.draw.DDrawnText;
17
 import org.openzen.drawablegui.live.LiveObject;
17
 import org.openzen.drawablegui.live.LiveObject;
18
 import org.openzen.drawablegui.live.MutableLiveObject;
18
 import org.openzen.drawablegui.live.MutableLiveObject;
19
 import org.openzen.drawablegui.style.DStyleClass;
19
 import org.openzen.drawablegui.style.DStyleClass;
20
-import org.openzen.drawablegui.style.DStylePath;
21
 
20
 
22
 /**
21
 /**
23
  *
22
  *
28
 	private final DStyleClass styleClass;
27
 	private final DStyleClass styleClass;
29
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
28
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
30
 	
29
 	
30
+	private DComponentContext context;
31
 	private DIRectangle bounds;
31
 	private DIRectangle bounds;
32
-	private DDrawSurface context;
33
 	private DFormStyle style;
32
 	private DFormStyle style;
34
 	private DFontMetrics fontMetrics;
33
 	private DFontMetrics fontMetrics;
35
 	private int maxFieldWidth;
34
 	private int maxFieldWidth;
45
 	}
44
 	}
46
 
45
 
47
 	@Override
46
 	@Override
48
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
49
-		this.context = surface;
50
-		
51
-		DStylePath path = parent.getChild("form", styleClass);
52
-		style = new DFormStyle(surface.getStylesheet(path));
53
-		fontMetrics = surface.getFontMetrics(style.labelFont);
47
+	public void mount(DComponentContext parent) {
48
+		context = parent.getChildContext("form", styleClass);
49
+		style = context.getStyle(DFormStyle::new);
50
+		fontMetrics = context.getFontMetrics(style.labelFont);
54
 		
51
 		
55
 		for (DFormComponent component : components)
52
 		for (DFormComponent component : components)
56
-			component.component.mount(path, z + 1, surface);
53
+			component.component.mount(context);
57
 		
54
 		
58
 		int height = style.paddingBottom + style.paddingTop;
55
 		int height = style.paddingBottom + style.paddingTop;
59
 		int maxLabelWidth = style.minimumLabelSize;
56
 		int maxLabelWidth = style.minimumLabelSize;
80
 		for (int i = 0; i < labels.length; i++) {
77
 		for (int i = 0; i < labels.length; i++) {
81
 			if (labels[i] != null)
78
 			if (labels[i] != null)
82
 				labels[i].close();
79
 				labels[i].close();
83
-			labels[i] = surface.drawText(z + 1, style.labelFont, style.labelColor, 0, 0, components[i].label);
80
+			labels[i] = parent.drawText(1, style.labelFont, style.labelColor, 0, 0, components[i].label);
84
 		}
81
 		}
85
 	}
82
 	}
86
 	
83
 	

+ 11
- 19
DrawableGui/src/main/java/org/openzen/drawablegui/layout/DLinearLayout.java View File

9
 import java.util.function.Predicate;
9
 import java.util.function.Predicate;
10
 import org.openzen.drawablegui.BaseComponentGroup;
10
 import org.openzen.drawablegui.BaseComponentGroup;
11
 import org.openzen.drawablegui.DComponent;
11
 import org.openzen.drawablegui.DComponent;
12
+import org.openzen.drawablegui.DComponentContext;
12
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DTransform2D;
15
 import org.openzen.drawablegui.DTransform2D;
15
-import org.openzen.drawablegui.draw.DDrawSurface;
16
 import org.openzen.drawablegui.draw.DDrawnShape;
16
 import org.openzen.drawablegui.draw.DDrawnShape;
17
 import org.openzen.drawablegui.listeners.ListenerHandle;
17
 import org.openzen.drawablegui.listeners.ListenerHandle;
18
 import org.openzen.drawablegui.live.LiveObject;
18
 import org.openzen.drawablegui.live.LiveObject;
19
 import org.openzen.drawablegui.live.MutableLiveObject;
19
 import org.openzen.drawablegui.live.MutableLiveObject;
20
 import org.openzen.drawablegui.style.DStyleClass;
20
 import org.openzen.drawablegui.style.DStyleClass;
21
-import org.openzen.drawablegui.style.DStylePath;
22
 
21
 
23
 /**
22
 /**
24
  *
23
  *
32
 	private final ListenerHandle<LiveObject.Listener<DSizing>>[] componentSizeListeners;
31
 	private final ListenerHandle<LiveObject.Listener<DSizing>>[] componentSizeListeners;
33
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
32
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
34
 	
33
 	
35
-	private DDrawSurface surface;
36
-	private int z;
34
+	private DComponentContext context;
37
 	private DLinearLayoutStyle style;
35
 	private DLinearLayoutStyle style;
38
 	private DIRectangle bounds;
36
 	private DIRectangle bounds;
39
 	private float totalGrow;
37
 	private float totalGrow;
74
 	}
72
 	}
75
 
73
 
76
 	@Override
74
 	@Override
77
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
78
-		this.surface = surface;
79
-		this.z = z;
80
-		
81
-		DStylePath path = parent.getChild("linearlayout", styleClass);
82
-		style = new DLinearLayoutStyle(surface.getStylesheet(path));
75
+	public void mount(DComponentContext parent) {
76
+		context = parent.getChildContext("linearlayout", styleClass);
77
+		style = context.getStyle(DLinearLayoutStyle::new);
83
 		
78
 		
84
 		for (Element element : components)
79
 		for (Element element : components)
85
-			element.component.mount(parent, z + 1, surface);
80
+			element.component.mount(context);
86
 	}
81
 	}
87
 	
82
 	
88
 	@Override
83
 	@Override
112
 			return;
107
 			return;
113
 		
108
 		
114
 		this.bounds = bounds;
109
 		this.bounds = bounds;
115
-		style.border.update(surface, z + 1, bounds);
110
+		style.border.update(context, bounds);
116
 		
111
 		
117
 		if (shape != null)
112
 		if (shape != null)
118
 			shape.close();
113
 			shape.close();
119
-		shape = surface.shadowPath(z, style.shape.instance(style.margin.apply(bounds)), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
114
+		shape = context.shadowPath(0, style.shape.instance(style.margin.apply(bounds)), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
120
 		
115
 		
121
 		layout();
116
 		layout();
122
 	}
117
 	}
149
 	}
144
 	}
150
 	
145
 	
151
 	private void layout() {
146
 	private void layout() {
147
+		if (bounds == null || context == null)
148
+			return;
149
+		
152
 		if (orientation == Orientation.HORIZONTAL) {
150
 		if (orientation == Orientation.HORIZONTAL) {
153
 			layoutHorizontal();
151
 			layoutHorizontal();
154
 		} else {
152
 		} else {
157
 	}
155
 	}
158
 	
156
 	
159
 	private void layoutHorizontal() {
157
 	private void layoutHorizontal() {
160
-		if (bounds == null || surface == null)
161
-			return;
162
-		
163
 		DSizing myPreferences = sizing.getValue();
158
 		DSizing myPreferences = sizing.getValue();
164
 		if (bounds.width < myPreferences.preferredWidth) {
159
 		if (bounds.width < myPreferences.preferredWidth) {
165
 			layoutHorizontalShrinked();
160
 			layoutHorizontalShrinked();
169
 	}
164
 	}
170
 	
165
 	
171
 	private void layoutVertical() {
166
 	private void layoutVertical() {
172
-		if (bounds == null || surface == null)
173
-			return;
174
-		
175
 		DSizing myPreferences = sizing.getValue();
167
 		DSizing myPreferences = sizing.getValue();
176
 		if (bounds.height < myPreferences.preferredHeight) {
168
 		if (bounds.height < myPreferences.preferredHeight) {
177
 			layoutVerticalShrinked();
169
 			layoutVerticalShrinked();

+ 12
- 17
DrawableGui/src/main/java/org/openzen/drawablegui/layout/DSideLayout.java View File

12
 import java.util.function.Predicate;
12
 import java.util.function.Predicate;
13
 import org.openzen.drawablegui.BaseComponentGroup;
13
 import org.openzen.drawablegui.BaseComponentGroup;
14
 import org.openzen.drawablegui.DComponent;
14
 import org.openzen.drawablegui.DComponent;
15
+import org.openzen.drawablegui.DComponentContext;
15
 import org.openzen.drawablegui.DIRectangle;
16
 import org.openzen.drawablegui.DIRectangle;
16
 import org.openzen.drawablegui.DSizing;
17
 import org.openzen.drawablegui.DSizing;
17
-import org.openzen.drawablegui.draw.DDrawSurface;
18
 import org.openzen.drawablegui.draw.DDrawnRectangle;
18
 import org.openzen.drawablegui.draw.DDrawnRectangle;
19
 import org.openzen.drawablegui.listeners.ListenerHandle;
19
 import org.openzen.drawablegui.listeners.ListenerHandle;
20
 import org.openzen.drawablegui.live.LiveObject;
20
 import org.openzen.drawablegui.live.LiveObject;
21
 import org.openzen.drawablegui.live.MutableLiveObject;
21
 import org.openzen.drawablegui.live.MutableLiveObject;
22
 import org.openzen.drawablegui.style.DStyleClass;
22
 import org.openzen.drawablegui.style.DStyleClass;
23
-import org.openzen.drawablegui.style.DStylePath;
24
 
23
 
25
 /**
24
 /**
26
  *
25
  *
33
 	private final List<SideComponent> sides = new ArrayList<>();
32
 	private final List<SideComponent> sides = new ArrayList<>();
34
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
33
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
35
 	
34
 	
36
-	private DStylePath path;
37
-	private DDrawSurface surface;
38
-	private int z;
35
+	private DComponentContext context;
39
 	private DSideLayoutStyle style;
36
 	private DSideLayoutStyle style;
40
 	private DIRectangle bounds;
37
 	private DIRectangle bounds;
41
 	
38
 	
47
 	}
44
 	}
48
 	
45
 	
49
 	public void add(Side side, DComponent component) {
46
 	public void add(Side side, DComponent component) {
50
-		if (surface != null)
51
-			component.mount(path, z + 1, surface);
47
+		if (context != null)
48
+			component.mount(context);
52
 		
49
 		
53
 		sides.add(new SideComponent(side, component));
50
 		sides.add(new SideComponent(side, component));
54
 	}
51
 	}
59
 		
56
 		
60
 		this.main = component;
57
 		this.main = component;
61
 		
58
 		
62
-		if (surface != null && bounds != null) {
63
-			main.mount(path, z + 1, surface);
59
+		if (context != null && bounds != null) {
60
+			main.mount(context);
64
 			setBounds(bounds);
61
 			setBounds(bounds);
65
 		}
62
 		}
66
 	}
63
 	}
67
 
64
 
68
 	@Override
65
 	@Override
69
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
70
-		this.surface = surface;
71
-		this.z = z;
72
-		this.path = parent.getChild("sidelayout", styleClass);
73
-		style = new DSideLayoutStyle(surface.getStylesheet(path));
66
+	public void mount(DComponentContext parent) {
67
+		context = parent.getChildContext("sidelayout", styleClass);
68
+		style = context.getStyle(DSideLayoutStyle::new);
74
 		
69
 		
75
-		main.mount(path, z + 1, surface);
70
+		main.mount(context);
76
 		for (SideComponent side : sides)
71
 		for (SideComponent side : sides)
77
-			side.component.mount(path, z + 1, surface);
72
+			side.component.mount(context);
78
 		
73
 		
79
 		if (background != null)
74
 		if (background != null)
80
 			background.close();
75
 			background.close();
81
-		background = surface.fillRect(z, DIRectangle.EMPTY, style.backgroundColor);
76
+		background = context.fillRect(0, DIRectangle.EMPTY, style.backgroundColor);
82
 	}
77
 	}
83
 	
78
 	
84
 	@Override
79
 	@Override

+ 6
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveArrayList.java View File

52
 		
52
 		
53
 		remove(index);
53
 		remove(index);
54
 	}
54
 	}
55
+	
56
+	@Override
57
+	public void clear() {
58
+		for (int i = size() - 1; i >= 0; i--)
59
+			remove(i);
60
+	}
55
 
61
 
56
 	@Override
62
 	@Override
57
 	public int indexOf(T value) {
63
 	public int indexOf(T value) {

+ 2
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/MutableLiveList.java View File

19
 	void remove(int index);
19
 	void remove(int index);
20
 	
20
 	
21
 	void remove(T value);
21
 	void remove(T value);
22
+	
23
+	void clear();
22
 }
24
 }

+ 7
- 10
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBar.java View File

6
 package org.openzen.drawablegui.scroll;
6
 package org.openzen.drawablegui.scroll;
7
 
7
 
8
 import org.openzen.drawablegui.DComponent;
8
 import org.openzen.drawablegui.DComponent;
9
+import org.openzen.drawablegui.DComponentContext;
9
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DMouseEvent;
11
 import org.openzen.drawablegui.DMouseEvent;
11
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DIRectangle;
14
 import org.openzen.drawablegui.listeners.ListenerHandle;
15
 import org.openzen.drawablegui.listeners.ListenerHandle;
15
 import org.openzen.drawablegui.live.LiveInt;
16
 import org.openzen.drawablegui.live.LiveInt;
16
 import org.openzen.drawablegui.live.LiveObject;
17
 import org.openzen.drawablegui.live.LiveObject;
17
-import org.openzen.drawablegui.draw.DDrawSurface;
18
 import org.openzen.drawablegui.draw.DDrawnRectangle;
18
 import org.openzen.drawablegui.draw.DDrawnRectangle;
19
 import org.openzen.drawablegui.draw.DDrawnShape;
19
 import org.openzen.drawablegui.draw.DDrawnShape;
20
 import org.openzen.drawablegui.live.MutableLiveObject;
20
 import org.openzen.drawablegui.live.MutableLiveObject;
21
 import org.openzen.drawablegui.style.DStyleClass;
21
 import org.openzen.drawablegui.style.DStyleClass;
22
-import org.openzen.drawablegui.style.DStylePath;
23
 
22
 
24
 /**
23
 /**
25
  *
24
  *
35
 	private final ListenerHandle<LiveInt.Listener> targetHeightListener;
34
 	private final ListenerHandle<LiveInt.Listener> targetHeightListener;
36
 	private final ListenerHandle<LiveInt.Listener> offsetListener;
35
 	private final ListenerHandle<LiveInt.Listener> offsetListener;
37
 	
36
 	
38
-	private DDrawSurface surface;
37
+	private DComponentContext context;
39
 	private DScrollBarStyle style;
38
 	private DScrollBarStyle style;
40
-	private int z;
41
 	private DIRectangle bounds;
39
 	private DIRectangle bounds;
42
 	
40
 	
43
 	private int fromY = 0;
41
 	private int fromY = 0;
60
 	}
58
 	}
61
 
59
 
62
 	@Override
60
 	@Override
63
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
64
-		this.surface = surface;
65
-		this.z = z;
66
-		this.style = new DScrollBarStyle(surface.getStylesheet(parent.getChild("scrollbar", styleClass)));
61
+	public void mount(DComponentContext parent) {
62
+		context = parent.getChildContext("scrollbar", styleClass);
63
+		style = context.getStyle(DScrollBarStyle::new);
67
 		sizing.setValue(new DSizing(style.width, 0));
64
 		sizing.setValue(new DSizing(style.width, 0));
68
 		
65
 		
69
-		background = surface.fillRect(z, DIRectangle.EMPTY, style.scrollBarBackgroundColor);
66
+		background = context.fillRect(0, DIRectangle.EMPTY, style.scrollBarBackgroundColor);
70
 	}
67
 	}
71
 	
68
 	
72
 	@Override
69
 	@Override
190
 		
187
 		
191
 		if (bar != null)
188
 		if (bar != null)
192
 			bar.close();
189
 			bar.close();
193
-		bar = surface.fillPath(z + 1, DPath.rectangle(bounds.x, fromY, bounds.width, toY - fromY), DTransform2D.IDENTITY, style.scrollBarNormalColor);
190
+		bar = context.fillPath(1, DPath.rectangle(bounds.x, fromY, bounds.width, toY - fromY), DTransform2D.IDENTITY, style.scrollBarNormalColor);
194
 		updateBarColor();
191
 		updateBarColor();
195
 	}
192
 	}
196
 	
193
 	

+ 18
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollContext.java View File

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.scroll;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface DScrollContext {
13
+	void scrollInView(int x, int y, int width, int height);
14
+	
15
+	int getViewportWidth();
16
+	
17
+	int getViewportHeight();
18
+}

+ 33
- 34
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java View File

5
  */
5
  */
6
 package org.openzen.drawablegui.scroll;
6
 package org.openzen.drawablegui.scroll;
7
 
7
 
8
-import org.openzen.drawablegui.DAnchor;
9
-import org.openzen.drawablegui.DClipboard;
10
 import org.openzen.drawablegui.DComponent;
8
 import org.openzen.drawablegui.DComponent;
9
+import org.openzen.drawablegui.DComponentContext;
11
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DSizing;
12
-import org.openzen.drawablegui.DFont;
13
-import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DIRectangle;
11
 import org.openzen.drawablegui.DIRectangle;
15
 import org.openzen.drawablegui.DMouseEvent;
12
 import org.openzen.drawablegui.DMouseEvent;
16
-import org.openzen.drawablegui.DTimerHandle;
17
 import org.openzen.drawablegui.DTransform2D;
13
 import org.openzen.drawablegui.DTransform2D;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
14
 import org.openzen.drawablegui.listeners.ListenerHandle;
19
 import org.openzen.drawablegui.live.LiveInt;
15
 import org.openzen.drawablegui.live.LiveInt;
20
 import org.openzen.drawablegui.live.LiveObject;
16
 import org.openzen.drawablegui.live.LiveObject;
21
 import org.openzen.drawablegui.live.SimpleLiveInt;
17
 import org.openzen.drawablegui.live.SimpleLiveInt;
22
-import org.openzen.drawablegui.DUIContext;
23
-import org.openzen.drawablegui.DUIWindow;
24
-import org.openzen.drawablegui.draw.DDrawSurface;
25
 import org.openzen.drawablegui.draw.DDrawnShape;
18
 import org.openzen.drawablegui.draw.DDrawnShape;
26
 import org.openzen.drawablegui.draw.DSubSurface;
19
 import org.openzen.drawablegui.draw.DSubSurface;
27
 import org.openzen.drawablegui.style.DStyleClass;
20
 import org.openzen.drawablegui.style.DStyleClass;
28
-import org.openzen.drawablegui.style.DStylePath;
29
-import org.openzen.drawablegui.style.DStyleSheets;
30
 
21
 
31
 /**
22
 /**
32
  *
23
  *
33
  * @author Hoofdgebruiker
24
  * @author Hoofdgebruiker
34
  */
25
  */
35
-public class DScrollPane implements DComponent {
26
+public class DScrollPane implements DComponent, DScrollContext {
36
 	private final DStyleClass styleClass;
27
 	private final DStyleClass styleClass;
37
 	private final DComponent contents;
28
 	private final DComponent contents;
38
 	private final DScrollBar scrollBar;
29
 	private final DScrollBar scrollBar;
39
-	private DDrawSurface surface;
40
-	private DIRectangle bounds;
41
 	
30
 	
31
+	private DComponentContext context;
42
 	private DScrollPaneStyle style;
32
 	private DScrollPaneStyle style;
43
-	private int z;
33
+	private DIRectangle bounds;
34
+	
44
 	private DDrawnShape shape;
35
 	private DDrawnShape shape;
45
 	private final LiveInt contentsHeight;
36
 	private final LiveInt contentsHeight;
46
 	private final LiveInt offsetX;
37
 	private final LiveInt offsetX;
80
 			contentsHeight.setValue(newPreferences.preferredHeight);
71
 			contentsHeight.setValue(newPreferences.preferredHeight);
81
 		});
72
 		});
82
 	}
73
 	}
83
-	
84
-	@Override
85
-	public void onMounted() {
86
-		contents.onMounted();
87
-	}
88
-	
89
-	@Override
90
-	public void onUnmounted() {
91
-		contents.onUnmounted();
92
-	}
93
 
74
 
94
 	@Override
75
 	@Override
95
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
96
-		this.surface = surface;
97
-		this.z = z;
76
+	public void mount(DComponentContext parent) {
77
+		context = parent.getChildContext("scrollpane", styleClass);
78
+		style = context.getStyle(DScrollPaneStyle::new);
98
 		
79
 		
99
-		DStylePath path = parent.getChild("scrollpane", styleClass);
100
-		subSurface = surface.createSubSurface(z + 1);
101
-		contents.mount(path, 1, subSurface);
102
-		scrollBar.mount(path, z + 2, surface);
103
-		style = new DScrollPaneStyle(surface.getStylesheet(path));
80
+		subSurface = context.createSubSurface(1);
81
+		DComponentContext newContext = new DComponentContext(this, context.path, 0, subSurface);
82
+		contents.mount(newContext);
83
+		scrollBar.mount(context);
104
 	}
84
 	}
105
 	
85
 	
106
 	@Override
86
 	@Override
107
 	public void unmount() {
87
 	public void unmount() {
108
 		subSurface.close();
88
 		subSurface.close();
89
+		style.border.close();
109
 		
90
 		
110
 		contents.unmount();
91
 		contents.unmount();
111
 		scrollBar.unmount();
92
 		scrollBar.unmount();
132
 		
113
 		
133
 		if (shape != null)
114
 		if (shape != null)
134
 			shape.close();
115
 			shape.close();
135
-		shape = surface.shadowPath(z, style.shape.instance(style.margin.apply(bounds)), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
136
-		style.border.update(surface, z + 1, style.margin.apply(bounds));
116
+		shape = context.shadowPath(0, style.shape.instance(style.margin.apply(bounds)), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
117
+		style.border.update(context, style.margin.apply(bounds));
137
 		
118
 		
138
 		int height = Math.max(
119
 		int height = Math.max(
139
 				bounds.height - style.border.getPaddingHorizontal(),
120
 				bounds.height - style.border.getPaddingHorizontal(),
268
 	private int toLocalY(int y) {
249
 	private int toLocalY(int y) {
269
 		return y - bounds.y + offsetY.getValue();
250
 		return y - bounds.y + offsetY.getValue();
270
 	}
251
 	}
252
+
253
+	@Override
254
+	public void scrollInView(int x, int y, int width, int height) {
255
+		if (y < offsetY.getValue())
256
+			offsetY.setValue(y);
257
+		if (y + height > offsetY.getValue() + bounds.height)
258
+			offsetY.setValue(y + height - bounds.height);
259
+	}
260
+
261
+	@Override
262
+	public int getViewportWidth() {
263
+		return bounds.width;
264
+	}
265
+
266
+	@Override
267
+	public int getViewportHeight() {
268
+		return bounds.height;
269
+	}
271
 	
270
 	
272
 	private class ScrollListener implements LiveInt.Listener {
271
 	private class ScrollListener implements LiveInt.Listener {
273
 
272
 

+ 10
- 10
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java View File

16
 import org.openzen.drawablegui.DAnchor;
16
 import org.openzen.drawablegui.DAnchor;
17
 import org.openzen.drawablegui.DClipboard;
17
 import org.openzen.drawablegui.DClipboard;
18
 import org.openzen.drawablegui.DComponent;
18
 import org.openzen.drawablegui.DComponent;
19
+import org.openzen.drawablegui.DComponentContext;
19
 import org.openzen.drawablegui.DSizing;
20
 import org.openzen.drawablegui.DSizing;
20
 import org.openzen.drawablegui.DPath;
21
 import org.openzen.drawablegui.DPath;
21
 import org.openzen.drawablegui.DFont;
22
 import org.openzen.drawablegui.DFont;
132
 		return new SwingFontMetrics(graphics.getFontMetrics((Font) font.cached), graphics);
133
 		return new SwingFontMetrics(graphics.getFontMetrics((Font) font.cached), graphics);
133
 	}
134
 	}
134
 
135
 
135
-	@Override
136
-	public void scrollInView(int x, int y, int width, int height) {
137
-		// not in a scrollable context
138
-	}
139
-
140
 	@Override
136
 	@Override
141
 	public DTimerHandle setTimer(int millis, Runnable target) {
137
 	public DTimerHandle setTimer(int millis, Runnable target) {
142
 		Timer timer = new Timer(millis, e -> target.run());
138
 		Timer timer = new Timer(millis, e -> target.run());
165
 		
161
 		
166
 		Point rootLocation = swingWindow.swingComponent.getLocationOnScreen();
162
 		Point rootLocation = swingWindow.swingComponent.getLocationOnScreen();
167
 		
163
 		
168
-		root.mount(DStylePathRoot.INSTANCE, 0, windowContext.surface);
164
+		root.mount(new DComponentContext(null, DStylePathRoot.INSTANCE, 0, windowContext.surface));
169
 		DSizing dimension = root.getSizing().getValue();
165
 		DSizing dimension = root.getSizing().getValue();
170
-		int tx = (int)(x + rootLocation.x - anchor.alignX * dimension.preferredWidth);
171
-		int ty = (int)(y + rootLocation.y - anchor.alignY * dimension.preferredHeight);
166
+		//int tx = (int)(x + rootLocation.x - anchor.alignX * dimension.preferredWidth);
167
+		//int ty = (int)(y + rootLocation.y - anchor.alignY * dimension.preferredHeight);
168
+		int dx = (int)(anchor.alignX * dimension.preferredWidth);
169
+		int dy = (int)(anchor.alignY * dimension.preferredHeight);
170
+		int tx = rootLocation.x + x - dx;
171
+		int ty = rootLocation.y + y - dy;
172
 		
172
 		
173
 		window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
173
 		window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
174
 		window.swingComponent.setPreferredSize(new Dimension(dimension.preferredWidth, dimension.preferredHeight));
174
 		window.swingComponent.setPreferredSize(new Dimension(dimension.preferredWidth, dimension.preferredHeight));
175
-		window.setLocation(tx, ty);
176
 		window.pack();
175
 		window.pack();
176
+		window.setLocation(tx, ty);
177
 		window.setVisible(true);
177
 		window.setVisible(true);
178
 		return window;
178
 		return window;
179
 	}
179
 	}
187
 		windowContext.graphics = this.graphics; // help a little...
187
 		windowContext.graphics = this.graphics; // help a little...
188
 		windowContext.setSurface(window.swingComponent.surface);
188
 		windowContext.setSurface(window.swingComponent.surface);
189
 		
189
 		
190
-		root.mount(DStylePathRoot.INSTANCE, 0, windowContext.surface);
190
+		root.mount(new DComponentContext(null, DStylePathRoot.INSTANCE, 0, windowContext.surface));
191
 		DSizing dimension = root.getSizing().getValue();
191
 		DSizing dimension = root.getSizing().getValue();
192
 		
192
 		
193
 		Point rootLocation = swingWindow.swingComponent.getLocationOnScreen();
193
 		Point rootLocation = swingWindow.swingComponent.getLocationOnScreen();

+ 2
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java View File

21
 import java.awt.event.MouseWheelEvent;
21
 import java.awt.event.MouseWheelEvent;
22
 import java.awt.event.MouseWheelListener;
22
 import java.awt.event.MouseWheelListener;
23
 import org.openzen.drawablegui.DComponent;
23
 import org.openzen.drawablegui.DComponent;
24
+import org.openzen.drawablegui.DComponentContext;
24
 import org.openzen.drawablegui.DIRectangle;
25
 import org.openzen.drawablegui.DIRectangle;
25
 import org.openzen.drawablegui.DKeyEvent;
26
 import org.openzen.drawablegui.DKeyEvent;
26
 import static org.openzen.drawablegui.DKeyEvent.KeyCode.*;
27
 import static org.openzen.drawablegui.DKeyEvent.KeyCode.*;
79
 	public void paint(Graphics g) {
80
 	public void paint(Graphics g) {
80
 		if (firstPaint) {
81
 		if (firstPaint) {
81
 			firstPaint = false;
82
 			firstPaint = false;
82
-			component.mount(DStylePathRoot.INSTANCE, 0, surface);
83
+			component.mount(new DComponentContext(null, DStylePathRoot.INSTANCE, 0, surface));
83
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
84
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
84
 		}
85
 		}
85
 		
86
 		

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

9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.drawablegui.DColorableIconInstance;
10
 import org.openzen.drawablegui.DColorableIconInstance;
11
 import org.openzen.drawablegui.DComponent;
11
 import org.openzen.drawablegui.DComponent;
12
+import org.openzen.drawablegui.DComponentContext;
12
 import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DDrawable;
14
 import org.openzen.drawablegui.DDrawable;
14
 import org.openzen.drawablegui.DFontMetrics;
15
 import org.openzen.drawablegui.DFontMetrics;
26
 import org.openzen.drawablegui.live.LiveObject;
27
 import org.openzen.drawablegui.live.LiveObject;
27
 import org.openzen.drawablegui.live.MutableLiveObject;
28
 import org.openzen.drawablegui.live.MutableLiveObject;
28
 import org.openzen.drawablegui.style.DStyleClass;
29
 import org.openzen.drawablegui.style.DStyleClass;
29
-import org.openzen.drawablegui.style.DStylePath;
30
 
30
 
31
 /**
31
 /**
32
  *
32
  *
35
 public class DTreeView<N extends DTreeNode<N>> implements DComponent {
35
 public class DTreeView<N extends DTreeNode<N>> implements DComponent {
36
 	private final DStyleClass styleClass;
36
 	private final DStyleClass styleClass;
37
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
37
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
38
+	
39
+	private DComponentContext context;
38
 	private DIRectangle bounds = DIRectangle.EMPTY;
40
 	private DIRectangle bounds = DIRectangle.EMPTY;
39
-	private int z;
40
 	
41
 	
41
 	private int selectedRow = -1;
42
 	private int selectedRow = -1;
42
 	private N selectedNode = null;
43
 	private N selectedNode = null;
47
 	private final DDrawable nodeOpenedIcon;
48
 	private final DDrawable nodeOpenedIcon;
48
 	private final DDrawable nodeClosedIcon;
49
 	private final DDrawable nodeClosedIcon;
49
 	
50
 	
50
-	private DDrawSurface surface;
51
 	private final N root;
51
 	private final N root;
52
 	private final boolean showRoot;
52
 	private final boolean showRoot;
53
 	private final List<Row> rows = new ArrayList<>();
53
 	private final List<Row> rows = new ArrayList<>();
72
 	}
72
 	}
73
 
73
 
74
 	@Override
74
 	@Override
75
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
76
-		this.surface = surface;
77
-		style = new DTreeViewStyle(surface.getStylesheet(parent.getChild("tree", styleClass)));
78
-		fontMetrics = surface.getFontMetrics(style.font);
75
+	public void mount(DComponentContext parent) {
76
+		context = parent.getChildContext("tree", styleClass);
77
+		style = context.getStyle(DTreeViewStyle::new);
78
+		fontMetrics = context.getFontMetrics(style.font);
79
 		
79
 		
80
-		background = surface.fillRect(z, DIRectangle.EMPTY, style.backgroundColor);
81
-		selectedBackground = surface.fillRect(z + 1, DIRectangle.EMPTY, 0);
80
+		background = context.fillRect(0, DIRectangle.EMPTY, style.backgroundColor);
81
+		selectedBackground = context.fillRect(1, DIRectangle.EMPTY, 0);
82
 		
82
 		
83
 		updateLayout();
83
 		updateLayout();
84
 	}
84
 	}
261
 			
261
 			
262
 			icon = node.isCollapsed().getValue() ? nodeClosedIcon : nodeOpenedIcon;
262
 			icon = node.isCollapsed().getValue() ? nodeClosedIcon : nodeOpenedIcon;
263
 			nodeIcon = new DColorableIconInstance(
263
 			nodeIcon = new DColorableIconInstance(
264
-					surface,
265
-					z + 2,
264
+					context.surface,
265
+					context.z + 2,
266
 					node.getIcon(),
266
 					node.getIcon(),
267
 					DTransform2D.translate(baseX + icon.getNominalWidth() + style.iconTextSpacing, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()),
267
 					DTransform2D.translate(baseX + icon.getNominalWidth() + style.iconTextSpacing, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()),
268
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor);
268
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor);
269
 			
269
 			
270
 			if (!node.isLeaf())
270
 			if (!node.isLeaf())
271
 				collapseIcon = new DDrawableInstance(
271
 				collapseIcon = new DDrawableInstance(
272
-						surface, 
273
-						z + 2,
272
+						context.surface, 
273
+						context.z + 2,
274
 						icon,
274
 						icon,
275
 						DTransform2D.translate(baseX, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()));
275
 						DTransform2D.translate(baseX, baseY + fontMetrics.getAscent() + fontMetrics.getDescent() - icon.getNominalHeight()));
276
 			
276
 			
277
-			text = surface.drawText(
278
-					z + 2,
277
+			text = context.drawText(
278
+					2,
279
 					style.font,
279
 					style.font,
280
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor,
280
 					node == selectedNode ? style.selectedNodeTextColor : style.nodeTextColor,
281
 					baseX + style.iconTextSpacing + icon.getNominalWidth() + style.iconTextSpacing + node.getIcon().getNominalWidth(),
281
 					baseX + style.iconTextSpacing + icon.getNominalWidth() + style.iconTextSpacing + node.getIcon().getNominalWidth(),

+ 6
- 1
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java View File

66
 	
66
 	
67
 	private ZenCodeCompiler buildInternal(Consumer<OutputLine> output) {
67
 	private ZenCodeCompiler buildInternal(Consumer<OutputLine> output) {
68
 		CompilationUnit compilationUnit = new CompilationUnit();
68
 		CompilationUnit compilationUnit = new CompilationUnit();
69
-		ModuleLoader moduleLoader = new ModuleLoader(compilationUnit, exception -> output.accept(new OutputLine(new ErrorOutputSpan(exception.getMessage()))));
69
+		ModuleLoader moduleLoader = new ModuleLoader(compilationUnit, exception -> {
70
+			String[] lines = Strings.split(exception.getMessage(), '\n');
71
+			for (String line : lines) {
72
+				output.accept(new OutputLine(new ErrorOutputSpan(line)));
73
+			}
74
+		});
70
 		moduleLoader.register("stdlib", new DirectoryModuleReference("stdlib", new File("../../StdLibs/stdlib"), true));
75
 		moduleLoader.register("stdlib", new DirectoryModuleReference("stdlib", new File("../../StdLibs/stdlib"), true));
71
 		Set<String> compiledModules = new HashSet<>();
76
 		Set<String> compiledModules = new HashSet<>();
72
 		
77
 		

+ 1
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java View File

61
 			
61
 			
62
 		}));
62
 		}));
63
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, BuildIcon.BLUE, new ImmutableLiveString("Build"), e -> {
63
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, BuildIcon.BLUE, new ImmutableLiveString("Build"), e -> {
64
+			output.clear();
64
 			for (IDETarget target : host.getTargets()) {
65
 			for (IDETarget target : host.getTargets()) {
65
 				if (target.canBuild())
66
 				if (target.canBuild())
66
 					target.build(line -> output.add(line));
67
 					target.build(line -> output.add(line));

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/dialog/CreateSourceFileDialog.java View File

80
 	
80
 	
81
 	public void open(DUIWindow parent) {
81
 	public void open(DUIWindow parent) {
82
 		DIRectangle rectangle = parent.getWindowBounds().getValue();
82
 		DIRectangle rectangle = parent.getWindowBounds().getValue();
83
-		window = parent.getContext().openDialog(rectangle.getCenterX(), rectangle.getCenterY(), DAnchor.MIDDLE_CENTER, "Create source file", root);
83
+		window = parent.getContext().openDialog(rectangle.width / 2, rectangle.height / 2, DAnchor.MIDDLE_CENTER, "Create source file", root);
84
 		window.focus(input);
84
 		window.focus(input);
85
 	}
85
 	}
86
 	
86
 	

+ 17
- 22
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java View File

7
 
7
 
8
 import java.util.function.Consumer;
8
 import java.util.function.Consumer;
9
 import org.openzen.drawablegui.DComponent;
9
 import org.openzen.drawablegui.DComponent;
10
+import org.openzen.drawablegui.DComponentContext;
10
 import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DDrawable;
12
 import org.openzen.drawablegui.DDrawable;
12
 import org.openzen.drawablegui.DDrawableInstance;
13
 import org.openzen.drawablegui.DDrawableInstance;
15
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DIRectangle;
17
 import org.openzen.drawablegui.DIRectangle;
17
 import org.openzen.drawablegui.DSimpleTooltip;
18
 import org.openzen.drawablegui.DSimpleTooltip;
18
-import org.openzen.drawablegui.draw.DDrawSurface;
19
 import org.openzen.drawablegui.draw.DDrawnShape;
19
 import org.openzen.drawablegui.draw.DDrawnShape;
20
 import org.openzen.drawablegui.listeners.ListenerHandle;
20
 import org.openzen.drawablegui.listeners.ListenerHandle;
21
 import org.openzen.drawablegui.live.ImmutableLiveBool;
21
 import org.openzen.drawablegui.live.ImmutableLiveBool;
25
 import org.openzen.drawablegui.live.MutableLiveObject;
25
 import org.openzen.drawablegui.live.MutableLiveObject;
26
 import org.openzen.drawablegui.style.DShadow;
26
 import org.openzen.drawablegui.style.DShadow;
27
 import org.openzen.drawablegui.style.DStyleClass;
27
 import org.openzen.drawablegui.style.DStyleClass;
28
-import org.openzen.drawablegui.style.DStylePath;
29
 
28
 
30
 /**
29
 /**
31
  *
30
  *
39
 	private final LiveBool disabled;
38
 	private final LiveBool disabled;
40
 	private final ListenerHandle<LiveBool.Listener> disabledListener;
39
 	private final ListenerHandle<LiveBool.Listener> disabledListener;
41
 	private final DSimpleTooltip tooltip;
40
 	private final DSimpleTooltip tooltip;
41
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
42
 	
42
 	
43
-	private DDrawSurface surface;
44
-	private int z;
43
+	private DComponentContext context;
45
 	private IconButtonControlStyle style;
44
 	private IconButtonControlStyle style;
46
 	private DIRectangle bounds;
45
 	private DIRectangle bounds;
47
-	private final MutableLiveObject<DSizing> preferences = DSizing.create();
48
 	private boolean hover;
46
 	private boolean hover;
49
 	private boolean press;
47
 	private boolean press;
50
 	
48
 	
67
 	}
65
 	}
68
 
66
 
69
 	@Override
67
 	@Override
70
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
71
-		this.surface = surface;
72
-		this.z = z;
68
+	public void mount(DComponentContext parent) {
69
+		context = parent.getChildContext("iconbutton", styleClass);
70
+		style = context.getStyle(IconButtonControlStyle::new);
73
 		
71
 		
74
-		tooltip.setContext(surface.getContext());
72
+		tooltip.setContext(context.getUIContext());
75
 		
73
 		
76
-		DStylePath path = parent.getChild("iconbutton", styleClass);
77
-		style = new IconButtonControlStyle(surface.getStylesheet(path));
78
-		
79
-		int iconWidth = (int)(icon.getNominalWidth() * surface.getScale() + 0.5f);
80
-		int iconHeight = (int)(icon.getNominalWidth() * surface.getScale() + 0.5f);
74
+		int iconWidth = (int)(icon.getNominalWidth() * context.getScale() + 0.5f);
75
+		int iconHeight = (int)(icon.getNominalWidth() * context.getScale() + 0.5f);
81
 		int width = iconWidth + 2 * style.padding + 2 * style.margin;
76
 		int width = iconWidth + 2 * style.padding + 2 * style.margin;
82
 		int height = iconHeight + 2 * style.padding + 2 * style.margin;
77
 		int height = iconHeight + 2 * style.padding + 2 * style.margin;
83
-		preferences.setValue(new DSizing(width, height));
78
+		sizing.setValue(new DSizing(width, height));
84
 		
79
 		
85
 		if (bounds != null)
80
 		if (bounds != null)
86
 			setBounds(bounds);
81
 			setBounds(bounds);
96
 
91
 
97
 	@Override
92
 	@Override
98
 	public LiveObject<DSizing> getSizing() {
93
 	public LiveObject<DSizing> getSizing() {
99
-		return preferences;
94
+		return sizing;
100
 	}
95
 	}
101
 
96
 
102
 	@Override
97
 	@Override
117
 			shape.close();
112
 			shape.close();
118
 		
113
 		
119
 		shadow = getShadow();
114
 		shadow = getShadow();
120
-		shape = surface.shadowPath(z, DPath.roundedRectangle(
115
+		shape = context.shadowPath(0, DPath.roundedRectangle(
121
 				bounds.x + style.margin,
116
 				bounds.x + style.margin,
122
 				bounds.y + style.margin,
117
 				bounds.y + style.margin,
123
 				bounds.width - 2 * style.margin,
118
 				bounds.width - 2 * style.margin,
176
 		if (drawnIcon != null)
171
 		if (drawnIcon != null)
177
 			drawnIcon.close();
172
 			drawnIcon.close();
178
 		
173
 		
179
-		drawnIcon = new DDrawableInstance(surface, z + 1, icon, DTransform2D.scaleAndTranslate(
180
-				bounds.x + (bounds.width - icon.getNominalWidth() * surface.getScale()) / 2,
181
-				bounds.y + (bounds.height - icon.getNominalHeight() * surface.getScale()) / 2,
182
-				surface.getScale()));
174
+		drawnIcon = new DDrawableInstance(context.surface, context.z + 1, icon, DTransform2D.scaleAndTranslate(
175
+				bounds.x + (bounds.width - icon.getNominalWidth() * context.getScale()) / 2,
176
+				bounds.y + (bounds.height - icon.getNominalHeight() * context.getScale()) / 2,
177
+				context.getScale()));
183
 	}
178
 	}
184
 	
179
 	
185
 	private void update() {
180
 	private void update() {
189
 				shape.close();
184
 				shape.close();
190
 			
185
 			
191
 			shadow = newShadow;
186
 			shadow = newShadow;
192
-			shape = surface.shadowPath(z, DPath.roundedRectangle(
187
+			shape = context.shadowPath(0, DPath.roundedRectangle(
193
 					bounds.x + style.margin,
188
 					bounds.x + style.margin,
194
 					bounds.y + style.margin,
189
 					bounds.y + style.margin,
195
 					bounds.width - 2 * style.margin,
190
 					bounds.width - 2 * style.margin,

+ 9
- 14
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarView.java View File

6
 package org.openzen.zenscript.ide.ui.view;
6
 package org.openzen.zenscript.ide.ui.view;
7
 
7
 
8
 import org.openzen.drawablegui.DComponent;
8
 import org.openzen.drawablegui.DComponent;
9
+import org.openzen.drawablegui.DComponentContext;
9
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DFontMetrics;
11
 import org.openzen.drawablegui.DFontMetrics;
11
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.DTransform2D;
14
 import org.openzen.drawablegui.DTransform2D;
14
 import org.openzen.drawablegui.live.LiveObject;
15
 import org.openzen.drawablegui.live.LiveObject;
15
 import org.openzen.drawablegui.live.SimpleLiveObject;
16
 import org.openzen.drawablegui.live.SimpleLiveObject;
16
-import org.openzen.drawablegui.draw.DDrawSurface;
17
 import org.openzen.drawablegui.draw.DDrawnShape;
17
 import org.openzen.drawablegui.draw.DDrawnShape;
18
 import org.openzen.drawablegui.draw.DDrawnText;
18
 import org.openzen.drawablegui.draw.DDrawnText;
19
 import org.openzen.drawablegui.live.LiveString;
19
 import org.openzen.drawablegui.live.LiveString;
20
 import org.openzen.drawablegui.style.DStyleClass;
20
 import org.openzen.drawablegui.style.DStyleClass;
21
-import org.openzen.drawablegui.style.DStylePath;
22
 
21
 
23
 /**
22
 /**
24
  *
23
  *
29
 	
28
 	
30
 	private final DStyleClass styleClass;
29
 	private final DStyleClass styleClass;
31
 	private final LiveString content;
30
 	private final LiveString content;
32
-	private DIRectangle bounds;
33
-	private DDrawSurface surface;
34
-	private int z;
31
+	private DComponentContext context;
35
 	private StatusBarStyle style;
32
 	private StatusBarStyle style;
36
 	private DFontMetrics fontMetrics;
33
 	private DFontMetrics fontMetrics;
34
+	private DIRectangle bounds;
37
 
35
 
38
 	private DDrawnShape shape;
36
 	private DDrawnShape shape;
39
 	private DDrawnText text;
37
 	private DDrawnText text;
44
 	}
42
 	}
45
 	
43
 	
46
 	@Override
44
 	@Override
47
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
48
-		this.surface = surface;
49
-		this.z = z;
50
-		
51
-		DStylePath path = parent.getChild("StatusBar", styleClass);
52
-		style = new StatusBarStyle(surface.getStylesheet(path));
53
-		fontMetrics = surface.getFontMetrics(style.font);
45
+	public void mount(DComponentContext parent) {
46
+		context = parent.getChildContext("statusbar", styleClass);
47
+		style = context.getStyle(StatusBarStyle::new);
48
+		fontMetrics = context.getFontMetrics(style.font);
54
 		
49
 		
55
 		dimensionPreferences.setValue(new DSizing(0, style.paddingTop + fontMetrics.getAscent() + fontMetrics.getDescent() + style.paddingBottom));
50
 		dimensionPreferences.setValue(new DSizing(0, style.paddingTop + fontMetrics.getAscent() + fontMetrics.getDescent() + style.paddingBottom));
56
-		text = surface.drawText(z + 1, style.font, style.textColor, 0, 0, content.getValue());
51
+		text = context.drawText(1, style.font, style.textColor, 0, 0, content.getValue());
57
 	}
52
 	}
58
 	
53
 	
59
 	@Override
54
 	@Override
85
 		
80
 		
86
 		if (shape != null)
81
 		if (shape != null)
87
 			shape.close();
82
 			shape.close();
88
-		shape = surface.shadowPath(z, DPath.rectangle(bounds.x, bounds.y, bounds.width, bounds.height), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
83
+		shape = context.shadowPath(0, DPath.rectangle(bounds.x, bounds.y, bounds.width, bounds.height), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
89
 		text.setPosition(bounds.x + style.paddingLeft, bounds.y + style.paddingTop + fontMetrics.getAscent());
84
 		text.setPosition(bounds.x + style.paddingLeft, bounds.y + style.paddingTop + fontMetrics.getAscent());
90
 	}
85
 	}
91
 
86
 

+ 14
- 22
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java View File

11
 import java.util.function.Predicate;
11
 import java.util.function.Predicate;
12
 import org.openzen.drawablegui.BaseComponentGroup;
12
 import org.openzen.drawablegui.BaseComponentGroup;
13
 import org.openzen.drawablegui.DComponent;
13
 import org.openzen.drawablegui.DComponent;
14
+import org.openzen.drawablegui.DComponentContext;
14
 import org.openzen.drawablegui.DSizing;
15
 import org.openzen.drawablegui.DSizing;
15
 import org.openzen.drawablegui.DFontMetrics;
16
 import org.openzen.drawablegui.DFontMetrics;
16
 import org.openzen.drawablegui.DIRectangle;
17
 import org.openzen.drawablegui.DIRectangle;
38
 	
39
 	
39
 	private final Map<TabbedViewTab, ListenerHandle<LiveObject.Listener<DSizing>>> tabSizeListeners = new HashMap<>();
40
 	private final Map<TabbedViewTab, ListenerHandle<LiveObject.Listener<DSizing>>> tabSizeListeners = new HashMap<>();
40
 	
41
 	
41
-	private DDrawSurface surface;
42
-	private DStylePath path;
43
-	private DIRectangle bounds;
42
+	private DComponentContext context;
44
 	private TabbedViewStyle style;
43
 	private TabbedViewStyle style;
44
+	private DIRectangle bounds;
45
 	private int totalTabHeight;
45
 	private int totalTabHeight;
46
 	private DFontMetrics fontMetrics;
46
 	private DFontMetrics fontMetrics;
47
-	private int z;
48
 
47
 
49
 	private final LiveList<TabbedViewTab> tabComponents = new LiveMappedList<>(tabs, tab -> {
48
 	private final LiveList<TabbedViewTab> tabComponents = new LiveMappedList<>(tabs, tab -> {
50
-		TabbedViewTab result = new TabbedViewTab(this, currentTab, tab);
51
-		if (surface != null)
52
-			result.mount(path, z + 2, surface);
49
+		TabbedViewTab result = new TabbedViewTab(DStyleClass.EMPTY, this, currentTab, tab);
50
+		if (context != null)
51
+			result.mount(context);
53
 		
52
 		
54
 		tabSizeListeners.put(result, result.getSizing().addListener((oldSize, newSize) -> layoutTabs()));
53
 		tabSizeListeners.put(result, result.getSizing().addListener((oldSize, newSize) -> layoutTabs()));
55
 		return result;
54
 		return result;
60
 		tabs.addListener(new TabListListener());
59
 		tabs.addListener(new TabListListener());
61
 		
60
 		
62
 		currentTab.addListener((oldValue, newValue) -> {
61
 		currentTab.addListener((oldValue, newValue) -> {
63
-			if (oldValue != null) {
64
-				oldValue.content.onUnmounted();
62
+			if (oldValue != null)
65
 				oldValue.content.unmount();
63
 				oldValue.content.unmount();
66
-			}
67
-			if (newValue != null) {
68
-				newValue.content.onMounted();
69
-				newValue.content.mount(path, z + 1, surface);
70
-			}
64
+			if (newValue != null)
65
+				newValue.content.mount(context);
71
 			
66
 			
72
 			if (newValue != null && bounds != null) {
67
 			if (newValue != null && bounds != null) {
73
 				DIRectangle contentBounds = new DIRectangle(
68
 				DIRectangle contentBounds = new DIRectangle(
81
 	}
76
 	}
82
 	
77
 	
83
 	@Override
78
 	@Override
84
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
85
-		this.surface = surface;
86
-		this.z = z;
87
-		
88
-		path = parent.getChild("tabbedView", styleClass);
89
-		style = new TabbedViewStyle(surface.getStylesheet(path));
90
-		fontMetrics = surface.getFontMetrics(style.tabFont);
79
+	public void mount(DComponentContext parent) {
80
+		context = parent.getChildContext("tabbedview", styleClass);
81
+		style = context.getStyle(TabbedViewStyle::new);
82
+		fontMetrics = context.getFontMetrics(style.tabFont);
91
 		totalTabHeight = style.tabBorder.getPaddingVertical() + fontMetrics.getAscent() + fontMetrics.getDescent();
83
 		totalTabHeight = style.tabBorder.getPaddingVertical() + fontMetrics.getAscent() + fontMetrics.getDescent();
92
 		
84
 		
93
 		for (TabbedViewComponent tab : tabs)
85
 		for (TabbedViewComponent tab : tabs)
146
 	}
138
 	}
147
 	
139
 	
148
 	private void prepare(TabbedViewComponent tab) {
140
 	private void prepare(TabbedViewComponent tab) {
149
-		tab.content.mount(path, z + 1, surface);
141
+		tab.content.mount(context);
150
 	}
142
 	}
151
 	
143
 	
152
 	private void layoutTabs() {
144
 	private void layoutTabs() {

+ 15
- 18
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTab.java View File

6
 package org.openzen.zenscript.ide.ui.view;
6
 package org.openzen.zenscript.ide.ui.view;
7
 
7
 
8
 import org.openzen.drawablegui.DComponent;
8
 import org.openzen.drawablegui.DComponent;
9
+import org.openzen.drawablegui.DComponentContext;
9
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DFontMetrics;
11
 import org.openzen.drawablegui.DFontMetrics;
11
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DMouseEvent;
13
 import org.openzen.drawablegui.DMouseEvent;
13
 import org.openzen.drawablegui.DPath;
14
 import org.openzen.drawablegui.DPath;
14
 import org.openzen.drawablegui.DTransform2D;
15
 import org.openzen.drawablegui.DTransform2D;
15
-import org.openzen.drawablegui.draw.DDrawSurface;
16
 import org.openzen.drawablegui.draw.DDrawnShape;
16
 import org.openzen.drawablegui.draw.DDrawnShape;
17
 import org.openzen.drawablegui.draw.DDrawnText;
17
 import org.openzen.drawablegui.draw.DDrawnText;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
18
 import org.openzen.drawablegui.listeners.ListenerHandle;
21
 import org.openzen.drawablegui.live.LiveString;
21
 import org.openzen.drawablegui.live.LiveString;
22
 import org.openzen.drawablegui.live.MutableLiveObject;
22
 import org.openzen.drawablegui.live.MutableLiveObject;
23
 import org.openzen.drawablegui.style.DStyleClass;
23
 import org.openzen.drawablegui.style.DStyleClass;
24
-import org.openzen.drawablegui.style.DStylePath;
25
 
24
 
26
 /**
25
 /**
27
  *
26
  *
32
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
31
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
33
 	private final MutableLiveObject<TabbedViewComponent> currentTab;
32
 	private final MutableLiveObject<TabbedViewComponent> currentTab;
34
 	
33
 	
34
+	private final DStyleClass styleClass;
35
 	private final TabbedView parent;
35
 	private final TabbedView parent;
36
 	public final TabbedViewTabClose closeButton;
36
 	public final TabbedViewTabClose closeButton;
37
 	
37
 	
38
-	private DDrawSurface surface;
39
-	private int z;
38
+	private DComponentContext context;
40
 	private TabbedViewTabStyle style;
39
 	private TabbedViewTabStyle style;
41
 	private DFontMetrics fontMetrics;
40
 	private DFontMetrics fontMetrics;
42
 	private int textWidth;
41
 	private int textWidth;
53
 	private DDrawnShape updated;
52
 	private DDrawnShape updated;
54
 	private DDrawnText text;
53
 	private DDrawnText text;
55
 	
54
 	
56
-	public TabbedViewTab(TabbedView parent, MutableLiveObject<TabbedViewComponent> currentTab, TabbedViewComponent tab) {
55
+	public TabbedViewTab(DStyleClass styleClass, TabbedView parent, MutableLiveObject<TabbedViewComponent> currentTab, TabbedViewComponent tab) {
56
+		this.styleClass = styleClass;
57
 		this.parent = parent;
57
 		this.parent = parent;
58
 		this.currentTab = currentTab;
58
 		this.currentTab = currentTab;
59
 		this.tab = tab;
59
 		this.tab = tab;
69
 	}
69
 	}
70
 
70
 
71
 	@Override
71
 	@Override
72
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
73
-		this.surface = surface;
74
-		this.z = z;
72
+	public void mount(DComponentContext parent) {
73
+		context = parent.getChildContext("tab", styleClass);
74
+		style = context.getStyle(TabbedViewTabStyle::new);
75
+		fontMetrics = context.getFontMetrics(style.tabFont);
76
+		closeButton.mount(context);
75
 		
77
 		
76
-		DStylePath path = parent.getChild("tab", DStyleClass.EMPTY);
77
-		style = new TabbedViewTabStyle(surface.getStylesheet(path));
78
-		fontMetrics = surface.getFontMetrics(style.tabFont);
79
-		closeButton.mount(path, z + 1, surface);
80
-		
81
-		text = surface.drawText(z + 1, style.tabFont, style.tabFontColor, 0, 0, tab.title.getValue());
78
+		text = context.drawText(1, style.tabFont, style.tabFontColor, 0, 0, tab.title.getValue());
82
 		calculateSizing();
79
 		calculateSizing();
83
 	}
80
 	}
84
 	
81
 	
130
 		this.bounds = bounds;
127
 		this.bounds = bounds;
131
 		
128
 		
132
 		DSizing close = closeButton.getSizing().getValue();
129
 		DSizing close = closeButton.getSizing().getValue();
133
-		style.border.update(surface, z + 1, style.margin.apply(bounds));
130
+		style.border.update(context, style.margin.apply(bounds));
134
 		
131
 		
135
 		closeButton.setBounds(new DIRectangle(
132
 		closeButton.setBounds(new DIRectangle(
136
 				bounds.x + bounds.width - close.preferredWidth - style.border.getPaddingRight(),
133
 				bounds.x + bounds.width - close.preferredWidth - style.border.getPaddingRight(),
140
 		
137
 		
141
 		if (shape != null)
138
 		if (shape != null)
142
 			shape.close();
139
 			shape.close();
143
-		shape = surface.shadowPath(z, style.shape.instance(style.margin.apply(bounds)), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
140
+		shape = context.shadowPath(0, style.shape.instance(style.margin.apply(bounds)), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
144
 		text.setPosition(
141
 		text.setPosition(
145
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
142
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
146
 				bounds.y + style.margin.top + style.border.getPaddingTop() + fontMetrics.getAscent());
143
 				bounds.y + style.margin.top + style.border.getPaddingTop() + fontMetrics.getAscent());
148
 		if (tab.updated.getValue()) {
145
 		if (tab.updated.getValue()) {
149
 			if (updated != null)
146
 			if (updated != null)
150
 				updated.close();
147
 				updated.close();
151
-			updated = surface.fillPath(
152
-					z + 1,
148
+			updated = context.fillPath(
149
+					1,
153
 					DPath.circle(
150
 					DPath.circle(
154
 						bounds.x + bounds.width - style.margin.right - style.border.getPaddingRight() - closeButton.getBounds().width - style.closeIconPadding - style.updatedDiameter / 2,
151
 						bounds.x + bounds.width - style.margin.right - style.border.getPaddingRight() - closeButton.getBounds().width - style.closeIconPadding - style.updatedDiameter / 2,
155
 						bounds.y + style.margin.top + style.border.getPaddingTop() + ((bounds.height - style.margin.getVertical() - style.border.getPaddingVertical()) / 2), style.updatedDiameter / 2),
152
 						bounds.y + style.margin.top + style.border.getPaddingTop() + ((bounds.height - style.margin.getVertical() - style.border.getPaddingVertical()) / 2), style.updatedDiameter / 2),

+ 8
- 13
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTabClose.java View File

8
 import org.openzen.drawablegui.DColorableIcon;
8
 import org.openzen.drawablegui.DColorableIcon;
9
 import org.openzen.drawablegui.DColorableIconInstance;
9
 import org.openzen.drawablegui.DColorableIconInstance;
10
 import org.openzen.drawablegui.DComponent;
10
 import org.openzen.drawablegui.DComponent;
11
+import org.openzen.drawablegui.DComponentContext;
11
 import org.openzen.drawablegui.DSizing;
12
 import org.openzen.drawablegui.DSizing;
12
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.DMouseEvent;
14
 import org.openzen.drawablegui.DMouseEvent;
14
 import org.openzen.drawablegui.DTransform2D;
15
 import org.openzen.drawablegui.DTransform2D;
15
-import org.openzen.drawablegui.draw.DDrawSurface;
16
 import org.openzen.drawablegui.draw.DDrawnRectangle;
16
 import org.openzen.drawablegui.draw.DDrawnRectangle;
17
 import org.openzen.drawablegui.live.LiveObject;
17
 import org.openzen.drawablegui.live.LiveObject;
18
 import org.openzen.drawablegui.live.MutableLiveObject;
18
 import org.openzen.drawablegui.live.MutableLiveObject;
19
 import org.openzen.drawablegui.style.DStyleClass;
19
 import org.openzen.drawablegui.style.DStyleClass;
20
-import org.openzen.drawablegui.style.DStylePath;
21
 import org.openzen.zenscript.ide.ui.icons.ScalableCloseIcon;
20
 import org.openzen.zenscript.ide.ui.icons.ScalableCloseIcon;
22
 
21
 
23
 /**
22
 /**
28
 	private final TabbedViewTab tab;
27
 	private final TabbedViewTab tab;
29
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
28
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
30
 	
29
 	
31
-	private DDrawSurface surface;
32
-	private int z;
30
+	private DComponentContext context;
33
 	private DIRectangle bounds;
31
 	private DIRectangle bounds;
34
 	private TabbedViewTabCloseStyle style;
32
 	private TabbedViewTabCloseStyle style;
35
 	private DColorableIcon icon;
33
 	private DColorableIcon icon;
45
 	}
43
 	}
46
 
44
 
47
 	@Override
45
 	@Override
48
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
49
-		this.surface = surface;
50
-		this.z = z;
51
-		
52
-		DStylePath path = parent.getChild("tabClose", DStyleClass.EMPTY);
53
-		style = new TabbedViewTabCloseStyle(surface.getStylesheet(path));
46
+	public void mount(DComponentContext parent) {
47
+		context = parent.getChildContext("tabclose", DStyleClass.EMPTY);
48
+		style = context.getStyle(TabbedViewTabCloseStyle::new);
54
 		sizing.setValue(new DSizing(style.size, style.size));
49
 		sizing.setValue(new DSizing(style.size, style.size));
55
 		icon = new ScalableCloseIcon(style.size / 24);
50
 		icon = new ScalableCloseIcon(style.size / 24);
56
 		
51
 		
57
 		if (background != null)
52
 		if (background != null)
58
 			background.close();
53
 			background.close();
59
-		background = surface.fillRect(z, DIRectangle.EMPTY, hover ? 0xFFE81123 : 0);
54
+		background = context.fillRect(9, DIRectangle.EMPTY, hover ? 0xFFE81123 : 0);
60
 		if (drawnIcon != null)
55
 		if (drawnIcon != null)
61
 			drawnIcon.close();
56
 			drawnIcon.close();
62
-		drawnIcon = new DColorableIconInstance(surface, z + 1, icon, DTransform2D.IDENTITY, 0xFF000000);
57
+		drawnIcon = new DColorableIconInstance(context.surface, context.z + 1, icon, DTransform2D.IDENTITY, 0xFF000000);
63
 	}
58
 	}
64
 	
59
 	
65
 	@Override
60
 	@Override
93
 		
88
 		
94
 		if (drawnIcon != null)
89
 		if (drawnIcon != null)
95
 			drawnIcon.close();
90
 			drawnIcon.close();
96
-		drawnIcon = new DColorableIconInstance(surface, z + 1, icon, DTransform2D.translate(
91
+		drawnIcon = new DColorableIconInstance(context.surface, context.z + 1, icon, DTransform2D.translate(
97
 				bounds.x + (bounds.width - icon.getNominalWidth()) / 2,
92
 				bounds.x + (bounds.width - icon.getNominalWidth()) / 2,
98
 				bounds.y + (bounds.height - icon.getNominalHeight()) / 2), 0xFF000000);
93
 				bounds.y + (bounds.height - icon.getNominalHeight()) / 2), 0xFF000000);
99
 	}
94
 	}

+ 16
- 19
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java View File

7
 
7
 
8
 import java.util.function.Consumer;
8
 import java.util.function.Consumer;
9
 import org.openzen.drawablegui.DComponent;
9
 import org.openzen.drawablegui.DComponent;
10
+import org.openzen.drawablegui.DComponentContext;
10
 import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DDrawable;
12
 import org.openzen.drawablegui.DDrawable;
12
 import org.openzen.drawablegui.DDrawableInstance;
13
 import org.openzen.drawablegui.DDrawableInstance;
15
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DIRectangle;
17
 import org.openzen.drawablegui.DIRectangle;
17
 import org.openzen.drawablegui.DSimpleTooltip;
18
 import org.openzen.drawablegui.DSimpleTooltip;
18
-import org.openzen.drawablegui.draw.DDrawSurface;
19
 import org.openzen.drawablegui.draw.DDrawnShape;
19
 import org.openzen.drawablegui.draw.DDrawnShape;
20
 import org.openzen.drawablegui.listeners.ListenerHandle;
20
 import org.openzen.drawablegui.listeners.ListenerHandle;
21
 import org.openzen.drawablegui.live.ImmutableLiveString;
21
 import org.openzen.drawablegui.live.ImmutableLiveString;
24
 import org.openzen.drawablegui.live.MutableLiveObject;
24
 import org.openzen.drawablegui.live.MutableLiveObject;
25
 import org.openzen.drawablegui.style.DShadow;
25
 import org.openzen.drawablegui.style.DShadow;
26
 import org.openzen.drawablegui.style.DStyleClass;
26
 import org.openzen.drawablegui.style.DStyleClass;
27
-import org.openzen.drawablegui.style.DStylePath;
28
 
27
 
29
 /**
28
 /**
30
  *
29
  *
37
 	private final DDrawable icon;
36
 	private final DDrawable icon;
38
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
37
 	private final MutableLiveObject<DSizing> sizing = DSizing.create();
39
 	private final Consumer<DMouseEvent> onClick;
38
 	private final Consumer<DMouseEvent> onClick;
40
-	private DDrawSurface surface;
41
-	private int z;
39
+	
40
+	private DComponentContext context;
42
 	private AspectBarSelectorButtonStyle style;
41
 	private AspectBarSelectorButtonStyle style;
43
 	private DIRectangle bounds = DIRectangle.EMPTY;
42
 	private DIRectangle bounds = DIRectangle.EMPTY;
44
 	private DDrawnShape shape;
43
 	private DDrawnShape shape;
62
 	}
61
 	}
63
 
62
 
64
 	@Override
63
 	@Override
65
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
66
-		this.surface = surface;
67
-		this.z = z;
68
-		DStylePath path = parent.getChild("selectorbutton", styleClass);
69
-		style = new AspectBarSelectorButtonStyle(surface.getStylesheet(path));
64
+	public void mount(DComponentContext parent) {
65
+		context = parent.getChildContext("selectorbutton", styleClass);
66
+		style = context.getStyle(AspectBarSelectorButtonStyle::new);
70
 		sizing.setValue(new DSizing(style.width, style.height));
67
 		sizing.setValue(new DSizing(style.width, style.height));
71
 		
68
 		
72
-		tooltip.setContext(surface.getContext());
69
+		tooltip.setContext(context.getUIContext());
73
 	}
70
 	}
74
 
71
 
75
 	@Override
72
 	@Override
95
 			shape.close();
92
 			shape.close();
96
 		
93
 		
97
 		shadow = getShadow();
94
 		shadow = getShadow();
98
-		shape = surface.shadowPath(
99
-				z,
95
+		shape = context.shadowPath(
96
+				0,
100
 				DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.roundingRadius),
97
 				DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.roundingRadius),
101
 				DTransform2D.IDENTITY,
98
 				DTransform2D.IDENTITY,
102
 				getColor(),
99
 				getColor(),
104
 		
101
 		
105
 		if (iconInstance != null)
102
 		if (iconInstance != null)
106
 			iconInstance.close();
103
 			iconInstance.close();
107
-		iconInstance = new DDrawableInstance(surface, z + 1, icon, DTransform2D.scaleAndTranslate(
108
-				bounds.x + (style.width - icon.getNominalWidth() * surface.getScale()) / 2,
109
-				bounds.y + (style.height - icon.getNominalHeight() * surface.getScale()) / 2,
110
-				surface.getScale()));
104
+		iconInstance = new DDrawableInstance(context.surface, context.z + 1, icon, DTransform2D.scaleAndTranslate(
105
+				bounds.x + (style.width - icon.getNominalWidth() * context.getScale()) / 2,
106
+				bounds.y + (style.height - icon.getNominalHeight() * context.getScale()) / 2,
107
+				context.getScale()));
111
 	}
108
 	}
112
 	
109
 	
113
 	@Override
110
 	@Override
164
 	}
161
 	}
165
 	
162
 	
166
 	private void update() {
163
 	private void update() {
167
-		if (surface == null)
164
+		if (context == null)
168
 			return;
165
 			return;
169
 		
166
 		
170
 		DShadow newShadow = getShadow();
167
 		DShadow newShadow = getShadow();
174
 			if (shape != null)
171
 			if (shape != null)
175
 				shape.close();
172
 				shape.close();
176
 			
173
 			
177
-			shape = surface.shadowPath(
178
-				z,
174
+			shape = context.shadowPath(
175
+				0,
179
 				DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.roundingRadius),
176
 				DPath.roundedRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.roundingRadius),
180
 				DTransform2D.IDENTITY,
177
 				DTransform2D.IDENTITY,
181
 				getColor(),
178
 				getColor(),

+ 41
- 45
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java View File

9
 import java.util.function.Predicate;
9
 import java.util.function.Predicate;
10
 import org.openzen.drawablegui.BaseComponentGroup;
10
 import org.openzen.drawablegui.BaseComponentGroup;
11
 import org.openzen.drawablegui.DComponent;
11
 import org.openzen.drawablegui.DComponent;
12
+import org.openzen.drawablegui.DComponentContext;
12
 import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DFontMetrics;
14
 import org.openzen.drawablegui.DPath;
15
 import org.openzen.drawablegui.DPath;
44
 	private final DStyleClass styleClass;
45
 	private final DStyleClass styleClass;
45
 	private final IDEAspectBar aspectBar;
46
 	private final IDEAspectBar aspectBar;
46
 	
47
 	
47
-	private DIRectangle bounds;
48
-	private DDrawSurface surface;
49
-	private int z;
50
-	
51
-	private DStylePath path;
48
+	private DComponentContext context;
52
 	private AspectBarStyle style;
49
 	private AspectBarStyle style;
50
+	private DIRectangle bounds;
53
 	private DFontMetrics activeToolbarTitleFontMetrics;
51
 	private DFontMetrics activeToolbarTitleFontMetrics;
54
 	private boolean showWindowControls;
52
 	private boolean showWindowControls;
55
 	
53
 	
83
 		aspectBar.active.addListener(this::onActiveChanged);
81
 		aspectBar.active.addListener(this::onActiveChanged);
84
 		listener = aspectBar.toolbars.addListener(new ToolbarListListener());
82
 		listener = aspectBar.toolbars.addListener(new ToolbarListListener());
85
 		
83
 		
86
-		minimize = new WindowActionButton(scale -> new ScalableMinimizeIcon(scale), e -> surface.getContext().getWindow().minimize());
84
+		minimize = new WindowActionButton(scale -> new ScalableMinimizeIcon(scale), e -> context.getUIContext().getWindow().minimize());
87
 		minimizeRelayout = minimize.getSizing().addListener((a, b) -> layout());
85
 		minimizeRelayout = minimize.getSizing().addListener((a, b) -> layout());
88
 		maximizeRestore = new WindowActionButton(ScalableMaximizeIcon::new, e -> {
86
 		maximizeRestore = new WindowActionButton(ScalableMaximizeIcon::new, e -> {
89
-			if (surface.getContext().getWindow().getWindowState().getValue() == DUIWindow.State.MAXIMIZED)
90
-				surface.getContext().getWindow().restore();
87
+			if (context.getUIContext().getWindow().getWindowState().getValue() == DUIWindow.State.MAXIMIZED)
88
+				context.getUIContext().getWindow().restore();
91
 			else
89
 			else
92
-				surface.getContext().getWindow().maximize();
90
+				context.getUIContext().getWindow().maximize();
93
 		});
91
 		});
94
 		maximizeRestoreRelayout = maximizeRestore.getSizing().addListener((a, b) -> layout());
92
 		maximizeRestoreRelayout = maximizeRestore.getSizing().addListener((a, b) -> layout());
95
-		close = new WindowActionButton(scale -> new ScalableCloseIcon(scale), e -> surface.getContext().getWindow().close());
93
+		close = new WindowActionButton(scale -> new ScalableCloseIcon(scale), e -> context.getUIContext().getWindow().close());
96
 		closeRelayout = close.getSizing().addListener((a, b) -> layout());
94
 		closeRelayout = close.getSizing().addListener((a, b) -> layout());
97
 		
95
 		
98
 		selectorButtons = new LiveMappedList<>(
96
 		selectorButtons = new LiveMappedList<>(
100
 				bar -> {
98
 				bar -> {
101
 					LiveBool buttonActive = new LivePredicateBool<>(aspectBar.active, activeBar -> activeBar == bar);
99
 					LiveBool buttonActive = new LivePredicateBool<>(aspectBar.active, activeBar -> activeBar == bar);
102
 					AspectBarSelectorButton button = new AspectBarSelectorButton(DStyleClass.EMPTY, bar.icon, buttonActive, bar.description, e -> aspectBar.active.setValue(bar));
100
 					AspectBarSelectorButton button = new AspectBarSelectorButton(DStyleClass.EMPTY, bar.icon, buttonActive, bar.description, e -> aspectBar.active.setValue(bar));
103
-					if (surface != null)
104
-						button.mount(path, z + 1, surface);
101
+					if (context != null)
102
+						button.mount(context);
105
 					
103
 					
106
 					return button;
104
 					return button;
107
 				});
105
 				});
112
 	}
110
 	}
113
 	
111
 	
114
 	@Override
112
 	@Override
115
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
116
-		this.surface = surface;
117
-		this.z = z;
118
-		this.path = parent.getChild("aspectbar", styleClass);
119
-		this.style = new AspectBarStyle(surface.getStylesheet(path));
113
+	public void mount(DComponentContext parent) {
114
+		context = parent.getChildContext("aspectbar", styleClass);
115
+		style = context.getStyle(AspectBarStyle::new);
120
 		
116
 		
121
-		activeToolbarTitleFontMetrics = surface.getFontMetrics(style.activeToolbarTitleFont);
122
-		showWindowControls = !surface.getContext().getWindow().hasTitleBar();
117
+		activeToolbarTitleFontMetrics = context.getFontMetrics(style.activeToolbarTitleFont);
118
+		showWindowControls = !context.getUIContext().getWindow().hasTitleBar();
123
 		
119
 		
124
 		sizing.setValue(new DSizing(0, style.height));
120
 		sizing.setValue(new DSizing(0, style.height));
125
 		
121
 		
126
 		for (DComponent selectorButton : selectorButtons)
122
 		for (DComponent selectorButton : selectorButtons)
127
-			selectorButton.mount(path, z + 2, surface);
123
+			selectorButton.mount(context);
128
 		
124
 		
129
 		if (activeToolbarComponents != null)
125
 		if (activeToolbarComponents != null)
130
 			for (DComponent component : activeToolbarComponents)
126
 			for (DComponent component : activeToolbarComponents)
131
-				component.mount(path, z + 2, surface);
127
+				component.mount(context);
132
 		
128
 		
133
-		minimize.mount(path, z + 2, surface);
134
-		maximizeRestore.mount(path, z + 2, surface);
135
-		close.mount(path, z + 2, surface);
129
+		minimize.mount(context);
130
+		maximizeRestore.mount(context);
131
+		close.mount(context);
136
 		
132
 		
137
 		if (topBackground != null)
133
 		if (topBackground != null)
138
 			topBackground.close();
134
 			topBackground.close();
139
 		if (bottomBackground != null)
135
 		if (bottomBackground != null)
140
 			bottomBackground.close();
136
 			bottomBackground.close();
141
 		
137
 		
142
-		topBackground = surface.fillRect(z, DIRectangle.EMPTY, style.backgroundColor);
143
-		bottomBackground = surface.fillRect(z, DIRectangle.EMPTY, style.backgroundColorBottom);
138
+		topBackground = context.fillRect(0, DIRectangle.EMPTY, style.backgroundColor);
139
+		bottomBackground = context.fillRect(0, DIRectangle.EMPTY, style.backgroundColorBottom);
144
 	}
140
 	}
145
 	
141
 	
146
 	@Override
142
 	@Override
182
 	public void setBounds(DIRectangle bounds) {
178
 	public void setBounds(DIRectangle bounds) {
183
 		this.bounds = bounds;
179
 		this.bounds = bounds;
184
 		
180
 		
185
-		if (surface != null) {
181
+		if (context != null) {
186
 			layout();
182
 			layout();
187
 			setupActiveBarText();
183
 			setupActiveBarText();
188
 		}
184
 		}
208
 		
204
 		
209
 		activeToolbarComponents = new LiveMappedList<>(aspectBar.controls, control -> {
205
 		activeToolbarComponents = new LiveMappedList<>(aspectBar.controls, control -> {
210
 			DComponent result = control.instantiate();
206
 			DComponent result = control.instantiate();
211
-			if (surface != null)
212
-				result.mount(path, z + 2, surface);
207
+			if (context != null)
208
+				result.mount(context);
213
 			return result;
209
 			return result;
214
 		});
210
 		});
215
 		
211
 		
237
 				+ (int)(activeToolbarTitleFontMetrics.getAscent() * 0.35f)
233
 				+ (int)(activeToolbarTitleFontMetrics.getAscent() * 0.35f)
238
 				+ (bounds.height - style.aspectBarPaddingTop) / 2;
234
 				+ (bounds.height - style.aspectBarPaddingTop) / 2;
239
 		int x = aspectSelectorEndX + style.aspectSelectorToToolbarSpacing;
235
 		int x = aspectSelectorEndX + style.aspectSelectorToToolbarSpacing;
240
-		activeBarText = surface.drawText(z + 3, style.activeToolbarTitleFont, style.activeToolbarTitleColor, x, y, aspectBar.active.getValue().title);
241
-		activeBarSeparator = surface.fillRect(
242
-				z + 3,
236
+		activeBarText = context.drawText(3, style.activeToolbarTitleFont, style.activeToolbarTitleColor, x, y, aspectBar.active.getValue().title);
237
+		activeBarSeparator = context.fillRect(
238
+				3,
243
 				new DIRectangle(
239
 				new DIRectangle(
244
 					x + activeBarText.getBounds().width + 8,
240
 					x + activeBarText.getBounds().width + 8,
245
 					bounds.y + style.aspectBarPaddingTop + 8,
241
 					bounds.y + style.aspectBarPaddingTop + 8,
282
 			activeBarText.setPosition(activeBarX, activeBarY);
278
 			activeBarText.setPosition(activeBarX, activeBarY);
283
 			
279
 			
284
 			activeBarSeparator.close();
280
 			activeBarSeparator.close();
285
-			activeBarSeparator = surface.fillRect(
286
-				z + 3,
281
+			activeBarSeparator = context.fillRect(
282
+				3,
287
 				new DIRectangle(
283
 				new DIRectangle(
288
 					activeBarX + activeBarText.getBounds().width + 8,
284
 					activeBarX + activeBarText.getBounds().width + 8,
289
 					bounds.y + style.aspectBarPaddingTop + 8,
285
 					bounds.y + style.aspectBarPaddingTop + 8,
298
 			if (windowControlsBackground != null)
294
 			if (windowControlsBackground != null)
299
 				windowControlsBackground.close();
295
 				windowControlsBackground.close();
300
 			
296
 			
301
-			windowControlsBackground = surface.shadowPath(
302
-					z + 1,
297
+			windowControlsBackground = context.shadowPath(
298
+					1,
303
 					windowControlsShape,
299
 					windowControlsShape,
304
 					DTransform2D.IDENTITY,
300
 					DTransform2D.IDENTITY,
305
 					style.backgroundColor,
301
 					style.backgroundColor,
392
 		if (aspectBarShape != null)
388
 		if (aspectBarShape != null)
393
 			aspectBarShape.close();
389
 			aspectBarShape.close();
394
 		
390
 		
395
-		aspectBarShape = surface.shadowPath(z + 1, tracer -> {
391
+		aspectBarShape = context.shadowPath(1, tracer -> {
396
 			int height = bounds.height - style.marginBottom;
392
 			int height = bounds.height - style.marginBottom;
397
 			int baseY = bounds.y + height - style.aspectSelectorBottomSize;
393
 			int baseY = bounds.y + height - style.aspectSelectorBottomSize;
398
 			int barBaseX = toX + style.aspectSelectorToToolbarSpacing;
394
 			int barBaseX = toX + style.aspectSelectorToToolbarSpacing;
399
 			int barBaseY = bounds.y + style.aspectBarPaddingTop;
395
 			int barBaseY = bounds.y + style.aspectBarPaddingTop;
400
 			
396
 			
401
 			tracer.moveTo(bounds.x, baseY);
397
 			tracer.moveTo(bounds.x, baseY);
402
-			tracer.lineTo(toX - 3 * surface.getScale(), baseY);
398
+			tracer.lineTo(toX - 3 * context.getScale(), baseY);
403
 			tracer.bezierCubic(
399
 			tracer.bezierCubic(
404
-					toX + 0 * surface.getScale(), baseY,
405
-					toX + 2 * surface.getScale(), baseY,
406
-					toX + 3.5f * surface.getScale(), baseY - 4 * surface.getScale());
407
-			tracer.lineTo(barBaseX - 3.5f * surface.getScale(), barBaseY + 4 * surface.getScale());
400
+					toX + 0 * context.getScale(), baseY,
401
+					toX + 2 * context.getScale(), baseY,
402
+					toX + 3.5f * context.getScale(), baseY - 4 * context.getScale());
403
+			tracer.lineTo(barBaseX - 3.5f * context.getScale(), barBaseY + 4 * context.getScale());
408
 			tracer.bezierCubic(
404
 			tracer.bezierCubic(
409
-					barBaseX - 2 * surface.getScale(), barBaseY,
410
-					barBaseX - 0 * surface.getScale(), barBaseY,
411
-					barBaseX + 3 * surface.getScale(), barBaseY);
405
+					barBaseX - 2 * context.getScale(), barBaseY,
406
+					barBaseX - 0 * context.getScale(), barBaseY,
407
+					barBaseX + 3 * context.getScale(), barBaseY);
412
 			
408
 			
413
 			if (showWindowControls) {
409
 			if (showWindowControls) {
414
 				int spacingLeft = style.windowControlSpacingLeft;
410
 				int spacingLeft = style.windowControlSpacingLeft;

+ 11
- 15
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/WindowActionButton.java View File

10
 import org.openzen.drawablegui.DColorableIcon;
10
 import org.openzen.drawablegui.DColorableIcon;
11
 import org.openzen.drawablegui.DColorableIconInstance;
11
 import org.openzen.drawablegui.DColorableIconInstance;
12
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
13
+import org.openzen.drawablegui.DComponentContext;
13
 import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DMouseEvent;
15
 import org.openzen.drawablegui.DMouseEvent;
15
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DTransform2D;
16
 import org.openzen.drawablegui.DIRectangle;
17
 import org.openzen.drawablegui.DIRectangle;
17
-import org.openzen.drawablegui.draw.DDrawSurface;
18
 import org.openzen.drawablegui.draw.DDrawnRectangle;
18
 import org.openzen.drawablegui.draw.DDrawnRectangle;
19
 import org.openzen.drawablegui.listeners.ListenerHandle;
19
 import org.openzen.drawablegui.listeners.ListenerHandle;
20
 import org.openzen.drawablegui.live.LiveBool;
20
 import org.openzen.drawablegui.live.LiveBool;
21
 import org.openzen.drawablegui.live.LiveObject;
21
 import org.openzen.drawablegui.live.LiveObject;
22
 import org.openzen.drawablegui.live.MutableLiveObject;
22
 import org.openzen.drawablegui.live.MutableLiveObject;
23
-import org.openzen.drawablegui.style.DStylePath;
23
+import org.openzen.drawablegui.style.DStyleClass;
24
 import org.openzen.zenscript.ide.ui.icons.ScalableCloseIcon;
24
 import org.openzen.zenscript.ide.ui.icons.ScalableCloseIcon;
25
 
25
 
26
 /**
26
 /**
36
 	private LiveBool windowFocused;
36
 	private LiveBool windowFocused;
37
 	private ListenerHandle<LiveBool.Listener> windowFocusedListener;
37
 	private ListenerHandle<LiveBool.Listener> windowFocusedListener;
38
 	
38
 	
39
+	private DComponentContext context;
39
 	private DColorableIcon icon;
40
 	private DColorableIcon icon;
40
 	private DIRectangle bounds;
41
 	private DIRectangle bounds;
41
 	private boolean hover;
42
 	private boolean hover;
42
 	private boolean press;
43
 	private boolean press;
43
-	private DDrawSurface surface;
44
-	private int z;
45
 	
44
 	
46
 	private DDrawnRectangle background;
45
 	private DDrawnRectangle background;
47
 	private DColorableIconInstance drawnIcon;
46
 	private DColorableIconInstance drawnIcon;
52
 	}
51
 	}
53
 
52
 
54
 	@Override
53
 	@Override
55
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
56
-		this.surface = surface;
57
-		this.z = z;
54
+	public void mount(DComponentContext parent) {
55
+		context = parent.getChildContext("windowactionbutton", DStyleClass.EMPTY);
58
 		
56
 		
59
-		windowFocused = surface.getContext().getWindow().getActive();
57
+		windowFocused = context.getUIContext().getWindow().getActive();
60
 		windowFocusedListener = windowFocused.addListener((a, b) -> update());
58
 		windowFocusedListener = windowFocused.addListener((a, b) -> update());
61
 		
59
 		
62
-		icon = scalableIcon == null ? null : scalableIcon.apply(surface.getScale());
60
+		icon = scalableIcon == null ? null : scalableIcon.apply(context.getScale());
63
 		sizing.setValue(new DSizing(
61
 		sizing.setValue(new DSizing(
64
-				(int)(48 * surface.getScale()),
65
-				(int)(24 * surface.getScale())));
62
+				(int)(48 * context.getScale()),
63
+				(int)(24 * context.getScale())));
66
 		
64
 		
67
-		background = surface.fillRect(z, DIRectangle.EMPTY, getBackgroundColor());
65
+		background = context.fillRect(0, DIRectangle.EMPTY, getBackgroundColor());
68
 	}
66
 	}
69
 	
67
 	
70
 	@Override
68
 	@Override
105
 			
103
 			
106
 			int iconX = bounds.x + (int)(bounds.width - icon.getNominalWidth()) / 2;
104
 			int iconX = bounds.x + (int)(bounds.width - icon.getNominalWidth()) / 2;
107
 			int iconY = bounds.y + (int)(bounds.height - icon.getNominalHeight()) / 2;
105
 			int iconY = bounds.y + (int)(bounds.height - icon.getNominalHeight()) / 2;
108
-			drawnIcon = new DColorableIconInstance(surface, z + 1, icon, DTransform2D.translate(iconX, iconY), getIconColor());
106
+			drawnIcon = new DColorableIconInstance(context.surface, context.z + 1, icon, DTransform2D.translate(iconX, iconY), getIconColor());
109
 		}
107
 		}
110
 	}
108
 	}
111
 
109
 
151
 	
149
 	
152
 	private int getBackgroundColor() {
150
 	private int getBackgroundColor() {
153
 		int color = 0xFFFFFFFF;
151
 		int color = 0xFFFFFFFF;
154
-		int iconColor = windowFocused.getValue() ? 0xFF000000 : 0xFF999999;
155
 		
152
 		
156
 		if (hover) {
153
 		if (hover) {
157
 			if (icon instanceof ScalableCloseIcon) {
154
 			if (icon instanceof ScalableCloseIcon) {
158
 				color = 0xFFE81123;
155
 				color = 0xFFE81123;
159
-				iconColor = 0xFFFFFFFF;
160
 			} else {
156
 			} else {
161
 				color = 0xFFE0E0E0;
157
 				color = 0xFFE0E0E0;
162
 			}
158
 			}

+ 64
- 55
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java View File

10
 import java.util.ArrayList;
10
 import java.util.ArrayList;
11
 import java.util.List;
11
 import java.util.List;
12
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
13
+import org.openzen.drawablegui.DComponentContext;
13
 import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DFont;
15
 import org.openzen.drawablegui.DFont;
15
 import org.openzen.drawablegui.DFontFamily;
16
 import org.openzen.drawablegui.DFontFamily;
31
 import org.openzen.zenscript.lexer.ZSTokenType;
32
 import org.openzen.zenscript.lexer.ZSTokenType;
32
 import org.openzen.drawablegui.DUIContext;
33
 import org.openzen.drawablegui.DUIContext;
33
 import org.openzen.drawablegui.Destructible;
34
 import org.openzen.drawablegui.Destructible;
34
-import org.openzen.drawablegui.draw.DDrawSurface;
35
 import org.openzen.drawablegui.draw.DDrawnRectangle;
35
 import org.openzen.drawablegui.draw.DDrawnRectangle;
36
 import org.openzen.drawablegui.draw.DDrawnShape;
36
 import org.openzen.drawablegui.draw.DDrawnShape;
37
 import org.openzen.drawablegui.draw.DDrawnText;
37
 import org.openzen.drawablegui.draw.DDrawnText;
41
 import org.openzen.drawablegui.live.MutableLiveObject;
41
 import org.openzen.drawablegui.live.MutableLiveObject;
42
 import org.openzen.drawablegui.live.SimpleLiveBool;
42
 import org.openzen.drawablegui.live.SimpleLiveBool;
43
 import org.openzen.drawablegui.style.DStyleClass;
43
 import org.openzen.drawablegui.style.DStyleClass;
44
-import org.openzen.drawablegui.style.DStylePath;
45
 import org.openzen.zenscript.ide.ui.icons.SaveIcon;
44
 import org.openzen.zenscript.ide.ui.icons.SaveIcon;
46
 import org.openzen.zenscript.ide.ui.icons.ShadedCodeIcon;
45
 import org.openzen.zenscript.ide.ui.icons.ShadedCodeIcon;
47
 import org.openzen.zenscript.ide.ui.icons.ShadedSaveIcon;
46
 import org.openzen.zenscript.ide.ui.icons.ShadedSaveIcon;
61
 	private final ListenerHandle<TokenModel.Listener> tokenListener;
60
 	private final ListenerHandle<TokenModel.Listener> tokenListener;
62
 	private final SimpleLiveBool unchanged = new SimpleLiveBool(true);
61
 	private final SimpleLiveBool unchanged = new SimpleLiveBool(true);
63
 	
62
 	
63
+	private DComponentContext context;
64
 	private DIRectangle bounds;
64
 	private DIRectangle bounds;
65
-	private int z;
66
-	private DDrawSurface surface;
67
 	private SourceEditorStyle style;
65
 	private SourceEditorStyle style;
68
 	private DTimerHandle blinkTimer;
66
 	private DTimerHandle blinkTimer;
69
 	
67
 	
136
 	}
134
 	}
137
 
135
 
138
 	@Override
136
 	@Override
139
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
140
-		if (surface != null)
137
+	public void mount(DComponentContext parent) {
138
+		if (context != null)
141
 			unmount();
139
 			unmount();
142
 		
140
 		
143
-		this.surface = surface;
144
-		this.z = z;
145
-		this.style = new SourceEditorStyle(surface.getStylesheet(parent.getChild("sourceeditor", styleClass)));
141
+		context = parent.getChildContext("sourceeditor", styleClass);
142
+		style = context.getStyle(SourceEditorStyle::new);
146
 		
143
 		
147
-		fontMetrics = surface.getFontMetrics(font);
144
+		fontMetrics = context.getFontMetrics(font);
148
 		textLineHeight = fontMetrics.getAscent() + fontMetrics.getDescent();
145
 		textLineHeight = fontMetrics.getAscent() + fontMetrics.getDescent();
149
 		fullLineHeight = textLineHeight + fontMetrics.getLeading() + style.extraLineSpacing;
146
 		fullLineHeight = textLineHeight + fontMetrics.getLeading() + style.extraLineSpacing;
150
 		selectionLineHeight = textLineHeight + style.selectionPaddingTop + style.selectionPaddingBottom;
147
 		selectionLineHeight = textLineHeight + style.selectionPaddingTop + style.selectionPaddingBottom;
151
 		
148
 		
152
 		sizing.setValue(new DSizing(0, fullLineHeight * tokens.getLineCount()));
149
 		sizing.setValue(new DSizing(0, fullLineHeight * tokens.getLineCount()));
153
 		
150
 		
154
-		blinkTimer = surface.getContext().setTimer(300, this::blink);
151
+		blinkTimer = context.getUIContext().setTimer(300, this::blink);
155
 		
152
 		
156
-		selection = surface.fillRect(z + 2, DIRectangle.EMPTY, style.selectionColor);
157
-		cursor = surface.fillRect(z + 4, DIRectangle.EMPTY, style.cursorColor);
158
-		currentLineHighlight = surface.fillRect(z + 1, DIRectangle.EMPTY, style.currentLineHighlight);
153
+		selection = context.fillRect(2, DIRectangle.EMPTY, style.selectionColor);
154
+		cursor = context.fillRect(4, DIRectangle.EMPTY, style.cursorColor);
155
+		currentLineHighlight = context.fillRect(1, DIRectangle.EMPTY, style.currentLineHighlight);
159
 		
156
 		
160
 		for (int i = 0; i < tokens.getLineCount(); i++)
157
 		for (int i = 0; i < tokens.getLineCount(); i++)
161
-			lineNumbers.add(surface.drawText(z + 3, font, style.lineBarTextColor, 0, 0, Integer.toString(i + 1)));
158
+			lineNumbers.add(context.drawText(3, font, style.lineBarTextColor, 0, 0, Integer.toString(i + 1)));
162
 		
159
 		
163
 		for (TokenLine line : tokens.getLines())
160
 		for (TokenLine line : tokens.getLines())
164
 			drawnTokens.add(lineToTokens(line));
161
 			drawnTokens.add(lineToTokens(line));
171
 	public void unmount() {
168
 	public void unmount() {
172
 		window.aspectBar.toolbars.remove(editToolbar);
169
 		window.aspectBar.toolbars.remove(editToolbar);
173
 		
170
 		
174
-		surface = null;
171
+		context = null;
175
 		
172
 		
176
 		if (background != null) {
173
 		if (background != null) {
177
 			background.close();
174
 			background.close();
249
 			lineBarBackground.close();
246
 			lineBarBackground.close();
250
 		if (lineBarLine != null)
247
 		if (lineBarLine != null)
251
 			lineBarLine.close();
248
 			lineBarLine.close();
252
-		background = surface.fillRect(z, new DIRectangle(bounds.x + lineBarWidth, bounds.y, bounds.width - lineBarWidth, bounds.height), style.backgroundColor);
253
-		lineBarBackground = surface.fillRect(z, new DIRectangle(bounds.x, bounds.y, lineBarWidth, bounds.height), style.lineBarBackgroundColor);
254
-		lineBarLine = surface.strokePath(z + 1, tracer -> {
249
+		background = context.fillRect(0, new DIRectangle(bounds.x + lineBarWidth, bounds.y, bounds.width - lineBarWidth, bounds.height), style.backgroundColor);
250
+		lineBarBackground = context.fillRect(0, new DIRectangle(bounds.x, bounds.y, lineBarWidth, bounds.height), style.lineBarBackgroundColor);
251
+		lineBarLine = context.strokePath(1, tracer -> {
255
 				tracer.moveTo(bounds.x + lineBarWidth, bounds.y);
252
 				tracer.moveTo(bounds.x + lineBarWidth, bounds.y);
256
 				tracer.lineTo(bounds.x + lineBarWidth, bounds.y + bounds.height);
253
 				tracer.lineTo(bounds.x + lineBarWidth, bounds.y + bounds.height);
257
 			}, DTransform2D.IDENTITY, style.lineBarStrokeColor, style.lineBarStrokeWidth);
254
 			}, DTransform2D.IDENTITY, style.lineBarStrokeColor, style.lineBarStrokeWidth);
269
 	
266
 	
270
 	@Override
267
 	@Override
271
 	public void onMouseEnter(DMouseEvent e) {
268
 	public void onMouseEnter(DMouseEvent e) {
272
-		surface.getContext().setCursor(DUIContext.Cursor.TEXT);
269
+		context.getUIContext().setCursor(DUIContext.Cursor.TEXT);
273
 	}
270
 	}
274
 	
271
 	
275
 	@Override
272
 	@Override
276
 	public void onMouseExit(DMouseEvent e) {
273
 	public void onMouseExit(DMouseEvent e) {
277
-		surface.getContext().setCursor(DUIContext.Cursor.NORMAL);
274
+		context.getUIContext().setCursor(DUIContext.Cursor.NORMAL);
278
 	}
275
 	}
279
 	
276
 	
280
 	@Override
277
 	@Override
281
 	public void onMouseClick(DMouseEvent e) {
278
 	public void onMouseClick(DMouseEvent e) {
282
-		surface.getContext().getWindow().focus(this);
279
+		context.getUIContext().getWindow().focus(this);
283
 		
280
 		
284
 		SourcePosition position = getPositionAt(e.x, e.y);
281
 		SourcePosition position = getPositionAt(e.x, e.y);
285
 		if (e.isDoubleClick()) {
282
 		if (e.isDoubleClick()) {
329
 				SourcePosition to = SourcePosition.max(cursorStart, cursorEnd);
326
 				SourcePosition to = SourcePosition.max(cursorStart, cursorEnd);
330
 				
327
 				
331
 				int fromX = getX(from);
328
 				int fromX = getX(from);
332
-				multiLineSelection.add(surface.fillRect(
333
-						z + 2,
329
+				multiLineSelection.add(context.fillRect(
330
+						2,
334
 						new DIRectangle(fromX, getY(from), bounds.width - fromX, selectionLineHeight),
331
 						new DIRectangle(fromX, getY(from), bounds.width - fromX, selectionLineHeight),
335
 						style.selectionColor));
332
 						style.selectionColor));
336
 				
333
 				
337
 				for (int i = from.line + 1; i < to.line; i++) {
334
 				for (int i = from.line + 1; i < to.line; i++) {
338
-					multiLineSelection.add(surface.fillRect(z + 2, new DIRectangle(x, lineToY(i), bounds.width - x, selectionLineHeight), style.selectionColor));
335
+					multiLineSelection.add(context.fillRect(2, new DIRectangle(x, lineToY(i), bounds.width - x, selectionLineHeight), style.selectionColor));
339
 				}
336
 				}
340
 				
337
 				
341
 				int toX = getX(to);
338
 				int toX = getX(to);
342
-				multiLineSelection.add(surface.fillRect(z + 2, new DIRectangle(x, getY(to), Math.max(0, toX - x), selectionLineHeight), style.selectionColor));
339
+				multiLineSelection.add(context.fillRect(2, new DIRectangle(x, getY(to), Math.max(0, toX - x), selectionLineHeight), style.selectionColor));
343
 				selection.setRectangle(DIRectangle.EMPTY);
340
 				selection.setRectangle(DIRectangle.EMPTY);
344
 			}
341
 			}
345
 		} else {
342
 		} else {
364
 		setCursor(start, getPositionAt(e.x, e.y));
361
 		setCursor(start, getPositionAt(e.x, e.y));
365
 	}
362
 	}
366
 	
363
 	
364
+	private void moveLines(boolean shift, int lines) {
365
+		if (cursorEnd == null)
366
+			return;
367
+		
368
+		int line = cursorEnd.line + lines;
369
+		if (line < 0)
370
+			line = 0;
371
+		if (line >= tokens.getLineCount())
372
+			line = tokens.getLineCount() - 1;
373
+		
374
+		SourcePosition position = new SourcePosition(
375
+				tokens,
376
+				line,
377
+				Math.min(tokens.getLineLength(line), cursorEnd.offset));
378
+		setCursor(shift ? cursorStart : position, position);
379
+	}
380
+	
367
 	@Override
381
 	@Override
368
 	public void onKeyPressed(DKeyEvent e) {
382
 	public void onKeyPressed(DKeyEvent e) {
369
 		boolean shift = e.has(DKeyEvent.SHIFT);
383
 		boolean shift = e.has(DKeyEvent.SHIFT);
370
 		switch (e.keyCode) {
384
 		switch (e.keyCode) {
385
+			case PAGE_UP:
386
+				moveLines(shift, -getWindowLines());
387
+				break;
388
+			case PAGE_DOWN:
389
+				moveLines(shift, getWindowLines());
390
+				break;
371
 			case UP:
391
 			case UP:
372
-				if (cursorEnd == null || cursorEnd.line == 0)
373
-					return;
374
-				
375
-				{
376
-					int line = cursorEnd.line - 1;
377
-					SourcePosition position = new SourcePosition(
378
-							tokens,
379
-							line,
380
-							Math.min(tokens.getLineLength(line), cursorEnd.offset));
381
-					setCursor(shift ? cursorStart : position, position);
382
-				}
392
+				moveLines(shift, -1);
383
 				break;
393
 				break;
384
 			case DOWN:
394
 			case DOWN:
385
-				if (cursorEnd == null || cursorEnd.line >= tokens.getLineCount() - 1)
386
-					return;
387
-				
388
-				{
389
-					int line = cursorEnd.line + 1;
390
-					SourcePosition position = new SourcePosition(
391
-							tokens,
392
-							line,
393
-							Math.min(tokens.getLineLength(line), cursorEnd.offset));
394
-					setCursor(shift ? cursorStart : position, position);
395
-				}
395
+				moveLines(shift, 1);
396
 				break;
396
 				break;
397
 			case LEFT:
397
 			case LEFT:
398
 				if (cursorEnd == null || (cursorEnd.line == 0 && cursorEnd.offset == 0))
398
 				if (cursorEnd == null || (cursorEnd.line == 0 && cursorEnd.offset == 0))
470
 		String extract = tokens.extract(
470
 		String extract = tokens.extract(
471
 				SourcePosition.min(cursorStart, cursorEnd),
471
 				SourcePosition.min(cursorStart, cursorEnd),
472
 				SourcePosition.max(cursorStart, cursorEnd));
472
 				SourcePosition.max(cursorStart, cursorEnd));
473
-		surface.getContext().getClipboard().copyAsString(extract);
473
+		context.getUIContext().getClipboard().copyAsString(extract);
474
 	}
474
 	}
475
 	
475
 	
476
 	private void cut() {
476
 	private void cut() {
483
 	}
483
 	}
484
 	
484
 	
485
 	private void paste() {
485
 	private void paste() {
486
-		String text = surface.getContext().getClipboard().getAsString();
486
+		String text = context.getUIContext().getClipboard().getAsString();
487
 		if (text == null)
487
 		if (text == null)
488
 			return;
488
 			return;
489
 		
489
 		
540
 		if (deleteSelection())
540
 		if (deleteSelection())
541
 			return;
541
 			return;
542
 		
542
 		
543
-		if (cursorEnd.line > 0) {
543
+		/*if (cursorEnd.line > 0) {
544
 			String indent = tokens.getLine(cursorEnd.line - 1).getIndent(); // TODO: get nominal indent for current scope
544
 			String indent = tokens.getLine(cursorEnd.line - 1).getIndent(); // TODO: get nominal indent for current scope
545
 			if (cursorEnd.offset == indent.length()) {
545
 			if (cursorEnd.offset == indent.length()) {
546
 				// remove entire indent
546
 				// remove entire indent
550
 				setCursor(deleteFrom, deleteFrom);
550
 				setCursor(deleteFrom, deleteFrom);
551
 				return;
551
 				return;
552
 			}
552
 			}
553
-		}
553
+		}*/
554
 		
554
 		
555
 		if (cursorEnd.offset == 0) {
555
 		if (cursorEnd.offset == 0) {
556
 			if (cursorEnd.line == 0)
556
 			if (cursorEnd.line == 0)
614
 	}
614
 	}
615
 	
615
 	
616
 	public void scrollTo(SourcePosition position) {
616
 	public void scrollTo(SourcePosition position) {
617
-		surface.getContext().scrollInView(getX(position), getY(position), 2, selectionLineHeight);
617
+		if (context.scrollContext != null)
618
+			context.scrollContext.scrollInView(getX(position), getY(position), 2, selectionLineHeight);
618
 	}
619
 	}
619
 	
620
 	
620
 	private void blink() {
621
 	private void blink() {
624
 		}
625
 		}
625
 	}
626
 	}
626
 	
627
 	
628
+	private int getWindowLines() {
629
+		if (context.scrollContext == null) {
630
+			return 20;
631
+		} else {
632
+			return context.scrollContext.getViewportHeight() / fullLineHeight;
633
+		}
634
+	}
635
+	
627
 	public SourcePosition getPositionAt(int x, int y) {
636
 	public SourcePosition getPositionAt(int x, int y) {
628
 		int line = yToLine(y);
637
 		int line = yToLine(y);
629
 		int offset = xToOffset(line, x);
638
 		int offset = xToOffset(line, x);
730
 		List<DDrawnText> tokenLine = new ArrayList<>();
739
 		List<DDrawnText> tokenLine = new ArrayList<>();
731
 		for (ZSToken token : line.getTokens()) {
740
 		for (ZSToken token : line.getTokens()) {
732
 			String content = getDisplayContent(token);
741
 			String content = getDisplayContent(token);
733
-			tokenLine.add(surface.drawText(z + 3, font, TokenClass.get(token.type).color, 0, 0, content));
742
+			tokenLine.add(context.drawText(3, font, TokenClass.get(token.type).color, 0, 0, content));
734
 		}
743
 		}
735
 		return tokenLine;
744
 		return tokenLine;
736
 	}
745
 	}
745
 				String str = Integer.toString(lineNumbers.size() + 1);
754
 				String str = Integer.toString(lineNumbers.size() + 1);
746
 				int x = bounds.x + lineBarWidth - style.lineBarSpacingRight - style.lineBarMargin - fontMetrics.getWidth(str);
755
 				int x = bounds.x + lineBarWidth - style.lineBarSpacingRight - style.lineBarMargin - fontMetrics.getWidth(str);
747
 				int y = bounds.y + style.selectionPaddingTop + lineNumbers.size() * fullLineHeight + fontMetrics.getAscent();
756
 				int y = bounds.y + style.selectionPaddingTop + lineNumbers.size() * fullLineHeight + fontMetrics.getAscent();
748
-				lineNumbers.add(surface.drawText(z + 3, font, style.lineBarTextColor, x, y, str));
757
+				lineNumbers.add(context.drawText(3, font, style.lineBarTextColor, x, y, str));
749
 				
758
 				
750
 				drawnTokens.add(index, lineToTokens(tokens.getLine(index)));
759
 				drawnTokens.add(index, lineToTokens(tokens.getLine(index)));
751
 				layoutLines(index);
760
 				layoutLines(index);

+ 10
- 15
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/output/OutputView.java View File

8
 import java.util.ArrayList;
8
 import java.util.ArrayList;
9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.drawablegui.DComponent;
10
 import org.openzen.drawablegui.DComponent;
11
+import org.openzen.drawablegui.DComponentContext;
11
 import org.openzen.drawablegui.DFontMetrics;
12
 import org.openzen.drawablegui.DFontMetrics;
12
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.DIRectangle;
13
 import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DSizing;
14
 import org.openzen.drawablegui.DTransform2D;
15
 import org.openzen.drawablegui.DTransform2D;
15
 import org.openzen.drawablegui.Destructible;
16
 import org.openzen.drawablegui.Destructible;
16
-import org.openzen.drawablegui.draw.DDrawSurface;
17
 import org.openzen.drawablegui.draw.DDrawnShape;
17
 import org.openzen.drawablegui.draw.DDrawnShape;
18
 import org.openzen.drawablegui.draw.DDrawnText;
18
 import org.openzen.drawablegui.draw.DDrawnText;
19
 import org.openzen.drawablegui.listeners.ListenerHandle;
19
 import org.openzen.drawablegui.listeners.ListenerHandle;
21
 import org.openzen.drawablegui.live.LiveObject;
21
 import org.openzen.drawablegui.live.LiveObject;
22
 import org.openzen.drawablegui.live.MutableLiveObject;
22
 import org.openzen.drawablegui.live.MutableLiveObject;
23
 import org.openzen.drawablegui.style.DStyleClass;
23
 import org.openzen.drawablegui.style.DStyleClass;
24
-import org.openzen.drawablegui.style.DStylePath;
25
 
24
 
26
 /**
25
 /**
27
  *
26
  *
32
 	private final DStyleClass styleClass;
31
 	private final DStyleClass styleClass;
33
 	private final LiveList<OutputLine> lines;
32
 	private final LiveList<OutputLine> lines;
34
 	
33
 	
35
-	private DDrawSurface surface;
36
-	private int z;
34
+	private DComponentContext context;
37
 	private DIRectangle bounds;
35
 	private DIRectangle bounds;
38
 	private OutputViewStyle style;
36
 	private OutputViewStyle style;
39
 	private DFontMetrics fontMetrics;
37
 	private DFontMetrics fontMetrics;
48
 	}
46
 	}
49
 
47
 
50
 	@Override
48
 	@Override
51
-	public void mount(DStylePath parent, int z, DDrawSurface surface) {
52
-		if (this.surface != null)
49
+	public void mount(DComponentContext parent) {
50
+		if (context != null)
53
 			unmount();
51
 			unmount();
54
 		
52
 		
55
-		this.surface = surface;
56
-		this.z = z;
57
-		
58
-		DStylePath path = parent.getChild("outputview", styleClass);
59
-		style = new OutputViewStyle(surface.getStylesheet(path));
60
-		fontMetrics = surface.getFontMetrics(style.font);
53
+		context = parent.getChildContext("outputview", styleClass);
54
+		style = context.getStyle(OutputViewStyle::new);
55
+		fontMetrics = context.getFontMetrics(style.font);
61
 		
56
 		
62
 		for (OutputLine line : lines)
57
 		for (OutputLine line : lines)
63
 			outputText.add(draw(line));
58
 			outputText.add(draw(line));
68
 	
63
 	
69
 	@Override
64
 	@Override
70
 	public void unmount() {
65
 	public void unmount() {
71
-		surface = null;
66
+		context = null;
72
 		
67
 		
73
 		if (shape != null) {
68
 		if (shape != null) {
74
 			shape.close();
69
 			shape.close();
102
 		this.bounds = bounds;
97
 		this.bounds = bounds;
103
 		
98
 		
104
 		DIRectangle available = style.margin.apply(bounds);
99
 		DIRectangle available = style.margin.apply(bounds);
105
-		shape = surface.shadowPath(z, style.shape.instance(available), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
100
+		shape = context.shadowPath(0, style.shape.instance(available), DTransform2D.IDENTITY, style.backgroundColor, style.shadow);
106
 		
101
 		
107
 		layout(0);
102
 		layout(0);
108
 	}
103
 	}
119
 	private List<DDrawnText> draw(OutputLine line) {
114
 	private List<DDrawnText> draw(OutputLine line) {
120
 		List<DDrawnText> lineText = new ArrayList<>();
115
 		List<DDrawnText> lineText = new ArrayList<>();
121
 		for (OutputSpan span : line.spans)
116
 		for (OutputSpan span : line.spans)
122
-			lineText.add(surface.drawText(z + 1, style.font, span.getColor(), 0, 0, span.getText()));
117
+			lineText.add(context.drawText(1, style.font, span.getColor(), 0, 0, span.getText()));
123
 		return lineText;
118
 		return lineText;
124
 	}
119
 	}
125
 	
120
 	

+ 8
- 4
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenParser.java View File

6
 package org.openzen.zenscript.lexer;
6
 package org.openzen.zenscript.lexer;
7
 
7
 
8
 import java.io.IOException;
8
 import java.io.IOException;
9
-import java.io.Reader;
10
 import org.openzen.zencode.shared.SourceFile;
9
 import org.openzen.zencode.shared.SourceFile;
11
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
10
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
11
+import org.openzen.zenscript.parser.BracketExpressionParser;
12
 
12
 
13
 /**
13
 /**
14
  *
14
  *
27
 				new ZSTokenFactory(spacesPerTab));
27
 				new ZSTokenFactory(spacesPerTab));
28
 	}
28
 	}
29
 	
29
 	
30
-	public static ZSTokenParser create(SourceFile file, int spacesPerTab) throws IOException {
31
-		return new ZSTokenParser(createRaw(file, new ReaderCharReader(file.open()), spacesPerTab));
30
+	public static ZSTokenParser create(SourceFile file, BracketExpressionParser bracketParser, int spacesPerTab) throws IOException {
31
+		return new ZSTokenParser(createRaw(file, new ReaderCharReader(file.open()), spacesPerTab), bracketParser);
32
 	}
32
 	}
33
 	
33
 	
34
-	public ZSTokenParser(TokenStream<ZSTokenType, ZSToken> parser) {
34
+	public final BracketExpressionParser bracketParser;
35
+	
36
+	public ZSTokenParser(TokenStream<ZSTokenType, ZSToken> parser, BracketExpressionParser bracketParser) {
35
 		super(parser);
37
 		super(parser);
38
+		
39
+		this.bracketParser = bracketParser;
36
 	}
40
 	}
37
 	
41
 	
38
 	public SourceFile getFile() {
42
 	public SourceFile getFile() {

+ 27
- 0
Parser/src/main/java/org/openzen/zenscript/parser/BracketExpressionParser.java View File

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.parser;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zenscript.lexer.ZSTokenParser;
11
+import org.openzen.zenscript.parser.expression.ParsedExpression;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public interface BracketExpressionParser {
18
+	/**
19
+	 * Parses the given bracket expression. Note that the "&lt;" token is already
20
+	 * processed.
21
+	 * 
22
+	 * @param position start of the expression (which is the location of the &gt; token)
23
+	 * @param tokens tokens to be parsed
24
+	 * @return parsed expression
25
+	 */
26
+	ParsedExpression parse(CodePosition position, ZSTokenParser tokens) throws CompileException;
27
+}

+ 2
- 0
Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java View File

78
 	
78
 	
79
 	public abstract void listMembers(BaseScope scope, PrecompilationState state);
79
 	public abstract void listMembers(BaseScope scope, PrecompilationState state);
80
 	
80
 	
81
+	public abstract void precompile(BaseScope scope, PrecompilationState state);
82
+	
81
 	public abstract void compileCode(BaseScope scope, PrecompilationState state);
83
 	public abstract void compileCode(BaseScope scope, PrecompilationState state);
82
 }
84
 }

+ 9
- 7
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java View File

40
  * @author Hoofdgebruiker
40
  * @author Hoofdgebruiker
41
  */
41
  */
42
 public class ParsedFile {
42
 public class ParsedFile {
43
-	public static ParsedFile parse(ZSPackage pkg, File file) throws IOException {
44
-		return parse(pkg, new FileSourceFile(file.getName(), file));
43
+	public static ParsedFile parse(ZSPackage pkg, BracketExpressionParser bracketParser, File file) throws IOException {
44
+		return parse(pkg, bracketParser, new FileSourceFile(file.getName(), file));
45
 	}
45
 	}
46
 	
46
 	
47
-	public static ParsedFile parse(ZSPackage pkg, String filename, String content) {
47
+	public static ParsedFile parse(ZSPackage pkg, BracketExpressionParser bracketParser, String filename, String content) {
48
 		try {
48
 		try {
49
-			return parse(pkg, new LiteralSourceFile(filename, content));
49
+			return parse(pkg, bracketParser, new LiteralSourceFile(filename, content));
50
 		} catch (IOException ex) {
50
 		} catch (IOException ex) {
51
 			throw new AssertionError(); // shouldn't happen
51
 			throw new AssertionError(); // shouldn't happen
52
 		}
52
 		}
53
 	}
53
 	}
54
 	
54
 	
55
-	public static ParsedFile parse(ZSPackage pkg, SourceFile file) throws IOException {
56
-		ZSTokenParser tokens = ZSTokenParser.create(file, 4);
55
+	public static ParsedFile parse(ZSPackage pkg, BracketExpressionParser bracketParser, SourceFile file) throws IOException {
56
+		ZSTokenParser tokens = ZSTokenParser.create(file, bracketParser, 4);
57
 		return parse(pkg, tokens);
57
 		return parse(pkg, tokens);
58
 	}
58
 	}
59
 	
59
 	
193
 		for (ParsedDefinition definition : this.definitions) {
193
 		for (ParsedDefinition definition : this.definitions) {
194
 			definition.listMembers(scope, state);
194
 			definition.listMembers(scope, state);
195
 		}
195
 		}
196
-		
196
+		for (ParsedDefinition definition : this.definitions) {
197
+			definition.precompile(scope, state);
198
+		}
197
 		for (ParsedDefinition definition : this.definitions) {
199
 		for (ParsedDefinition definition : this.definitions) {
198
 			definition.compileCode(scope, state);
200
 			definition.compileCode(scope, state);
199
 		}
201
 		}

+ 57
- 0
Parser/src/main/java/org/openzen/zenscript/parser/PrefixedBracketParser.java View File

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.parser;
7
+
8
+import java.util.HashMap;
9
+import java.util.Map;
10
+import org.openzen.zencode.shared.CodePosition;
11
+import org.openzen.zencode.shared.CompileException;
12
+import org.openzen.zencode.shared.CompileExceptionCode;
13
+import org.openzen.zenscript.lexer.ZSToken;
14
+import org.openzen.zenscript.lexer.ZSTokenParser;
15
+import org.openzen.zenscript.lexer.ZSTokenType;
16
+import org.openzen.zenscript.parser.expression.ParsedExpression;
17
+
18
+/**
19
+ *
20
+ * @author Hoofdgebruiker
21
+ */
22
+public class PrefixedBracketParser implements BracketExpressionParser {
23
+	private final Map<String, BracketExpressionParser> subParsers = new HashMap<>();
24
+	private final BracketExpressionParser defaultParser;
25
+	
26
+	public PrefixedBracketParser(BracketExpressionParser defaultParser) {
27
+		this.defaultParser = defaultParser;
28
+	}
29
+	
30
+	public void register(String name, BracketExpressionParser parser) {
31
+		subParsers.put(name, parser);
32
+	}
33
+
34
+	@Override
35
+	public ParsedExpression parse(CodePosition position, ZSTokenParser tokens) {
36
+		if (defaultParser == null) {
37
+			ZSToken start = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected");
38
+			tokens.required(ZSTokenType.T_COLON, ": expected");
39
+			BracketExpressionParser subParser = subParsers.get(start.content);
40
+			if (subParser == null)
41
+				throw new CompileException(position, CompileExceptionCode.INVALID_BRACKET_EXPRESSION, "Invalid bracket expression");
42
+			
43
+			return subParser.parse(position, tokens);
44
+		} else {
45
+			tokens.pushMark();
46
+			ZSToken start = tokens.next();
47
+			if (start.type == ZSTokenType.T_IDENTIFIER && subParsers.containsKey(start.content)) {
48
+				tokens.popMark();
49
+				tokens.required(ZSTokenType.T_COLON, ": expected");
50
+				return subParsers.get(start.content).parse(position, tokens);
51
+			} else {
52
+				tokens.reset();
53
+				return defaultParser.parse(position, tokens);
54
+			}
55
+		}
56
+	}
57
+}

+ 73
- 0
Parser/src/main/java/org/openzen/zenscript/parser/SimpleBracketSubParser.java View File

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.parser;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.codemodel.expression.CallArguments;
10
+import org.openzen.zenscript.codemodel.expression.CallStaticExpression;
11
+import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
12
+import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
13
+import org.openzen.zenscript.codemodel.partial.IPartialExpression;
14
+import org.openzen.zenscript.codemodel.scope.ExpressionScope;
15
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16
+import org.openzen.zenscript.codemodel.type.ITypeID;
17
+import org.openzen.zenscript.lexer.ZSTokenParser;
18
+import org.openzen.zenscript.lexer.ZSTokenType;
19
+import org.openzen.zenscript.parser.expression.ParsedExpression;
20
+
21
+/**
22
+ *
23
+ * @author Hoofdgebruiker
24
+ */
25
+public class SimpleBracketSubParser implements BracketExpressionParser {
26
+	private final FunctionalMemberRef method;
27
+	private final ITypeID targetType;
28
+	
29
+	public SimpleBracketSubParser(GlobalTypeRegistry registry, FunctionalMemberRef method) {
30
+		if (!method.isStatic())
31
+			throw new IllegalArgumentException("Method must be static");
32
+		if (method.header.getNumberOfTypeParameters() > 0)
33
+			throw new IllegalArgumentException("Method cannot have type parameters");
34
+		
35
+		this.method = method;
36
+		this.targetType = registry.getForDefinition(method.getTarget().definition);
37
+	}
38
+
39
+	@Override
40
+	public ParsedExpression parse(CodePosition position, ZSTokenParser tokens) {
41
+		StringBuilder string = new StringBuilder();
42
+		while (tokens.optional(ZSTokenType.T_GREATER) == null) {
43
+			string.append(tokens.next().content);
44
+			string.append(tokens.getLastWhitespace());
45
+		}
46
+		return new StaticMethodCallExpression(position, string.toString());
47
+	}
48
+	
49
+	private class StaticMethodCallExpression extends ParsedExpression {
50
+		private final String value;
51
+		
52
+		public StaticMethodCallExpression(CodePosition position, String value) {
53
+			super(position);
54
+			
55
+			this.value = value;
56
+		}
57
+
58
+		@Override
59
+		public IPartialExpression compile(ExpressionScope scope) {
60
+			return new CallStaticExpression(position, targetType, method, method.header, new CallArguments(new ConstantStringExpression(position, value)), scope);
61
+		}
62
+
63
+		@Override
64
+		public boolean hasStrongType() {
65
+			return true;
66
+		}
67
+
68
+		@Override
69
+		public ITypeID precompileForType(ExpressionScope scope, PrecompilationState state) {
70
+			return method.header.returnType;
71
+		}
72
+	}
73
+}

+ 7
- 0
Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java View File

53
 		for (ParsedDefinitionMember member : members)
53
 		for (ParsedDefinitionMember member : members)
54
 			state.register(innerScope, member);
54
 			state.register(innerScope, member);
55
 	}
55
 	}
56
+	
57
+	@Override
58
+	public void precompile(BaseScope scope, PrecompilationState state) {
59
+		DefinitionScope innerScope = new DefinitionScope(scope, getCompiled());
60
+		for (ParsedDefinitionMember member : members)
61
+			state.precompile(member.getCompiled());
62
+	}
56
 
63
 
57
 	@Override
64
 	@Override
58
 	public void compileCode(BaseScope scope, PrecompilationState state) {
65
 	public void compileCode(BaseScope scope, PrecompilationState state) {

+ 5
- 0
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedAlias.java View File

79
 	public void listMembers(BaseScope scope, PrecompilationState state) {
79
 	public void listMembers(BaseScope scope, PrecompilationState state) {
80
 		// nothing to do
80
 		// nothing to do
81
 	}
81
 	}
82
+	
83
+	@Override
84
+	public void precompile(BaseScope scope, PrecompilationState state) {
85
+		// nothing to do
86
+	}
82
 
87
 
83
 	@Override
88
 	@Override
84
 	public void compileCode(BaseScope scope, PrecompilationState state) {
89
 	public void compileCode(BaseScope scope, PrecompilationState state) {

+ 8
- 5
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java View File

69
 	public void listMembers(BaseScope scope, PrecompilationState state) {
69
 	public void listMembers(BaseScope scope, PrecompilationState state) {
70
 		
70
 		
71
 	}
71
 	}
72
-
72
+	
73
 	@Override
73
 	@Override
74
-	public void compileCode(BaseScope scope, PrecompilationState state) {
75
-		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
76
-		compiled.setCode(body.compile(innerScope, compiled.header));
77
-		
74
+	public void precompile(BaseScope scope, PrecompilationState state) {
78
 		if (compiled.header.returnType == BasicTypeID.UNDETERMINED) {
75
 		if (compiled.header.returnType == BasicTypeID.UNDETERMINED) {
79
 			ITypeID result = body.precompileForResultType(new FunctionScope(scope, compiled.header), state);
76
 			ITypeID result = body.precompileForResultType(new FunctionScope(scope, compiled.header), state);
80
 			if (result == null)
77
 			if (result == null)
82
 			compiled.header = compiled.header.withReturnType(result);
79
 			compiled.header = compiled.header.withReturnType(result);
83
 		}
80
 		}
84
 	}
81
 	}
82
+
83
+	@Override
84
+	public void compileCode(BaseScope scope, PrecompilationState state) {
85
+		FunctionScope innerScope = new FunctionScope(scope, compiled.header);
86
+		compiled.setCode(body.compile(innerScope, compiled.header));
87
+	}
85
 }
88
 }

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpression.java View File

358
 					// try! can thus be used to convert from exception-based to result-based and vice versa
358
 					// try! can thus be used to convert from exception-based to result-based and vice versa
359
 					return new ParsedTryRethrowExpression(position, readUnaryExpression(position, parser, options));
359
 					return new ParsedTryRethrowExpression(position, readUnaryExpression(position, parser, options));
360
 				}
360
 				}
361
+			case T_LESS:// bracket expression
362
+				parser.next();
363
+				if (parser.bracketParser == null)
364
+					throw new CompileException(position, CompileExceptionCode.NO_BRACKET_PARSER, "Bracket expression detected but no bracket parser present");
365
+				
366
+				return parser.bracketParser.parse(position, parser);
361
 			default:
367
 			default:
362
 				return readPostfixExpression(position, parser, options);
368
 				return readPostfixExpression(position, parser, options);
363
 		}
369
 		}

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionFunction.java View File

50
 		for (ITypeID hint : scope.hints) {
50
 		for (ITypeID hint : scope.hints) {
51
 			if (hint instanceof FunctionTypeID) {
51
 			if (hint instanceof FunctionTypeID) {
52
 				FunctionTypeID functionHint = (FunctionTypeID) hint;
52
 				FunctionTypeID functionHint = (FunctionTypeID) hint;
53
-				if (header.canCastTo(scope, functionHint.header)) {
53
+				if (header.canOverride(scope, functionHint.header)) {
54
 					if (header != definedHeader)
54
 					if (header != definedHeader)
55
 						throw new CompileException(position, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Ambiguity trying to resolve function types, can't decide for the type");
55
 						throw new CompileException(position, CompileExceptionCode.MULTIPLE_MATCHING_HINTS, "Ambiguity trying to resolve function types, can't decide for the type");
56
 					
56
 					
87
 		if (type instanceof FunctionTypeID) {
87
 		if (type instanceof FunctionTypeID) {
88
 			FunctionHeader definedHeader = header.compile(scope);
88
 			FunctionHeader definedHeader = header.compile(scope);
89
 			FunctionTypeID targetFunction = (FunctionTypeID) type;
89
 			FunctionTypeID targetFunction = (FunctionTypeID) type;
90
-			return definedHeader.canCastTo(scope, targetFunction.header);
90
+			return definedHeader.canOverride(scope, targetFunction.header);
91
 		} else {
91
 		} else {
92
 			return false;
92
 			return false;
93
 		}
93
 		}

+ 11
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java View File

26
 import org.openzen.zenscript.codemodel.type.ITypeID;
26
 import org.openzen.zenscript.codemodel.type.ITypeID;
27
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
27
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
28
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
28
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
29
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
29
 import org.openzen.zenscript.parser.ParsedAnnotation;
30
 import org.openzen.zenscript.parser.ParsedAnnotation;
30
 import org.openzen.zenscript.parser.PrecompilationState;
31
 import org.openzen.zenscript.parser.PrecompilationState;
31
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
32
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
144
 			
145
 			
145
 			throw new CompileException(position, CompileExceptionCode.UNDEFINED_VARIABLE, "No such symbol: " + name);
146
 			throw new CompileException(position, CompileExceptionCode.UNDEFINED_VARIABLE, "No such symbol: " + name);
146
 		} else {
147
 		} else {
147
-			return result.eval().type;
148
+			if (result.getMember() != null) {
149
+				state.precompile(result.getMember());
150
+				result = scope.get(position, new GenericName(name, genericArguments));
151
+			}
152
+			
153
+			Expression resultExpression = result.eval();
154
+			if (resultExpression.type == BasicTypeID.UNDETERMINED)
155
+				System.out.println("Could not determine type");
156
+			
157
+			return resultExpression.type;
148
 		}
158
 		}
149
 	}
159
 	}
150
 }
160
 }

+ 5
- 1
Parser/src/main/java/org/openzen/zenscript/parser/type/ParsedNamedType.java View File

46
 		for (ParsedNamePart namePart : name)
46
 		for (ParsedNamePart namePart : name)
47
 			genericNames.add(namePart.compile(scope));
47
 			genericNames.add(namePart.compile(scope));
48
 		
48
 		
49
-		ITypeID result = scope.getTypeRegistry().getModified(modifiers, scope.getType(position, genericNames));
49
+		ITypeID baseType = scope.getType(position, genericNames);
50
+		if (baseType == null)
51
+			throw new CompileException(position, CompileExceptionCode.NO_SUCH_TYPE, "Type not found: " + toString());
52
+		
53
+		ITypeID result = scope.getTypeRegistry().getModified(modifiers, baseType);
50
 		if (result == null)
54
 		if (result == null)
51
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_TYPE, "Type not found: " + toString());
55
 			throw new CompileException(position, CompileExceptionCode.NO_SUCH_TYPE, "Type not found: " + toString());
52
 		
56
 		

+ 2
- 0
ScriptingExample/scripts/helloworld.zs View File

3
 println(2 + 5);
3
 println(2 + 5);
4
 println(1 - 2);
4
 println(1 - 2);
5
 println(1 + 3 as long);
5
 println(1 + 3 as long);
6
+
7
+println(<hello world in bracket parser>);

+ 22
- 1
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java View File

8
 import java.util.List;
8
 import java.util.List;
9
 import java.util.Map;
9
 import java.util.Map;
10
 import java.util.Optional;
10
 import java.util.Optional;
11
+import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.SourceFile;
12
 import org.openzen.zencode.shared.SourceFile;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 
14
 
22
 import org.openzen.zenscript.javabytecode.JavaCompiler;
23
 import org.openzen.zenscript.javabytecode.JavaCompiler;
23
 import org.openzen.zenscript.javabytecode.JavaModule;
24
 import org.openzen.zenscript.javabytecode.JavaModule;
24
 import org.openzen.zenscript.codemodel.type.ISymbol;
25
 import org.openzen.zenscript.codemodel.type.ISymbol;
26
+import org.openzen.zenscript.lexer.ZSToken;
27
+import org.openzen.zenscript.lexer.ZSTokenParser;
28
+import org.openzen.zenscript.lexer.ZSTokenType;
29
+import org.openzen.zenscript.parser.BracketExpressionParser;
25
 import org.openzen.zenscript.parser.ParsedFile;
30
 import org.openzen.zenscript.parser.ParsedFile;
31
+import org.openzen.zenscript.parser.expression.ParsedExpression;
32
+import org.openzen.zenscript.parser.expression.ParsedExpressionString;
26
 
33
 
27
 public class Main {
34
 public class Main {
28
     /**
35
     /**
53
 	private static ParsedFile[] parse(ZSPackage pkg, File[] files) throws IOException {
60
 	private static ParsedFile[] parse(ZSPackage pkg, File[] files) throws IOException {
54
 		ParsedFile[] parsedFiles = new ParsedFile[files.length];
61
 		ParsedFile[] parsedFiles = new ParsedFile[files.length];
55
 		for (int i = 0; i < files.length; i++) {
62
 		for (int i = 0; i < files.length; i++) {
56
-			parsedFiles[i] = ParsedFile.parse(pkg, files[i]);
63
+			parsedFiles[i] = ParsedFile.parse(pkg, new TestBracketParser(), files[i]);
57
 		}
64
 		}
58
 		return parsedFiles;
65
 		return parsedFiles;
59
 	}
66
 	}
158
 		}
165
 		}
159
 		return compiler.finishAndGetModule();
166
 		return compiler.finishAndGetModule();
160
 	}
167
 	}
168
+	
169
+	private static class TestBracketParser implements BracketExpressionParser {
170
+		@Override
171
+		public ParsedExpression parse(CodePosition position, ZSTokenParser tokens) {
172
+			StringBuilder result = new StringBuilder();
173
+			while (tokens.optional(ZSTokenType.T_GREATER) == null) {
174
+				ZSToken token = tokens.next();
175
+				result.append(token.content);
176
+				result.append(tokens.getLastWhitespace());
177
+			}
178
+			
179
+			return new ParsedExpressionString(position.until(tokens.getPosition()), result.toString());
180
+		}
181
+	}
161
 }
182
 }

+ 3
- 1
Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java View File

63
 	PRECOMPILE_FAILED,
63
 	PRECOMPILE_FAILED,
64
 	UNTYPED_EMPTY_ARRAY,
64
 	UNTYPED_EMPTY_ARRAY,
65
 	UNTYPED_EMPTY_MAP,
65
 	UNTYPED_EMPTY_MAP,
66
-	VAR_WITHOUT_TYPE_OR_INITIALIZER
66
+	VAR_WITHOUT_TYPE_OR_INITIALIZER,
67
+	NO_BRACKET_PARSER,
68
+	INVALID_BRACKET_EXPRESSION
67
 }
69
 }

+ 10
- 2
Shared/src/main/java/org/openzen/zencode/shared/FileSourceFile.java View File

6
 package org.openzen.zencode.shared;
6
 package org.openzen.zencode.shared;
7
 
7
 
8
 import java.io.BufferedInputStream;
8
 import java.io.BufferedInputStream;
9
-import java.io.BufferedReader;
9
+import java.io.BufferedOutputStream;
10
 import java.io.File;
10
 import java.io.File;
11
 import java.io.FileInputStream;
11
 import java.io.FileInputStream;
12
-import java.io.FileReader;
12
+import java.io.FileOutputStream;
13
 import java.io.IOException;
13
 import java.io.IOException;
14
 import java.io.InputStreamReader;
14
 import java.io.InputStreamReader;
15
+import java.io.OutputStreamWriter;
15
 import java.io.Reader;
16
 import java.io.Reader;
16
 import java.nio.charset.StandardCharsets;
17
 import java.nio.charset.StandardCharsets;
17
 
18
 
39
 				new BufferedInputStream(new FileInputStream(file)),
40
 				new BufferedInputStream(new FileInputStream(file)),
40
 				StandardCharsets.UTF_8);
41
 				StandardCharsets.UTF_8);
41
 	}
42
 	}
43
+
44
+	@Override
45
+	public void update(String content) throws IOException {
46
+		try (OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file, false)), StandardCharsets.UTF_8)) {
47
+			writer.write(content);
48
+		}
49
+	}
42
 }
50
 }

+ 5
- 0
Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java View File

31
 	public Reader open() throws IOException {
31
 	public Reader open() throws IOException {
32
 		return new StringReader(contents);
32
 		return new StringReader(contents);
33
 	}
33
 	}
34
+
35
+	@Override
36
+	public void update(String content) throws IOException {
37
+		throw new UnsupportedOperationException("Cannot update literal source files");
38
+	}
34
 }
39
 }

+ 2
- 0
Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java View File

7
 	String getFilename();
7
 	String getFilename();
8
 	
8
 	
9
 	Reader open() throws IOException;
9
 	Reader open() throws IOException;
10
+	
11
+	void update(String content) throws IOException;
10
 }
12
 }

+ 5
- 0
Shared/src/main/java/org/openzen/zencode/shared/VirtualSourceFile.java View File

28
 	public Reader open() throws IOException {
28
 	public Reader open() throws IOException {
29
 		throw new UnsupportedOperationException("Cannot open virtual source files");
29
 		throw new UnsupportedOperationException("Cannot open virtual source files");
30
 	}
30
 	}
31
+
32
+	@Override
33
+	public void update(String content) throws IOException {
34
+		throw new UnsupportedOperationException("Cannot write to virtual source files");
35
+	}
31
 }
36
 }

+ 1
- 1
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ValidationUtils.java View File

37
 	private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("^[a-zA-Z_][a-zA-Z_0-9]*$");
37
 	private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("^[a-zA-Z_][a-zA-Z_0-9]*$");
38
 
38
 
39
 	public static void validateValidOverride(Validator target, CodePosition position, TypeScope scope, FunctionHeader header, FunctionHeader overridden) {
39
 	public static void validateValidOverride(Validator target, CodePosition position, TypeScope scope, FunctionHeader header, FunctionHeader overridden) {
40
-		if (!header.canCastTo(scope, overridden))
40
+		if (!header.canOverride(scope, overridden))
41
 			target.logError(INVALID_OVERRIDE, position, "Invalid override: incompatible parameters or return type");
41
 			target.logError(INVALID_OVERRIDE, position, "Invalid override: incompatible parameters or return type");
42
 	}
42
 	}
43
 	
43
 	

Loading…
Cancel
Save