Переглянути джерело

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

kindlich 6 роки тому
джерело
коміт
1dd51ded5d
Не вдалося знайти GPG ключ що відповідає даному підпису
66 змінених файлів з 1705 додано та 119 видалено
  1. 1
    1
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java
  2. 33
    5
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java
  3. 1
    1
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FileFormatter.java
  4. 4
    4
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java
  5. 2
    2
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java
  6. 2
    1
      CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ZenScriptOperator.java
  7. 0
    14
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/AccessScope.java
  8. 9
    8
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  9. 0
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  10. 2
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java
  11. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationProcessor.java
  12. 2
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java
  13. 1
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java
  14. 0
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/LocalMemberCache.java
  15. 2
    3
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java
  16. 30
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DAnchor.java
  17. 123
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DButton.java
  18. 54
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DButtonStyle.java
  19. 2
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DComponent.java
  20. 5
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DEmptyView.java
  21. 271
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayout.java
  22. 31
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayoutStyle.java
  23. 18
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DIRectangle.java
  24. 148
    7
      DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java
  25. 8
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/DInputFieldStyle.java
  26. 3
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/DMouseEvent.java
  27. 11
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DSideLayout.java
  28. 7
    4
      DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java
  29. 6
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DUIWindow.java
  30. 272
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayout.java
  31. 31
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayoutStyle.java
  32. 6
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/border/DCustomWindowBorder.java
  33. 49
    12
      DrawableGui/src/main/java/org/openzen/drawablegui/form/DForm.java
  34. 2
    1
      DrawableGui/src/main/java/org/openzen/drawablegui/form/DFormStyle.java
  35. 5
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBar.java
  36. 22
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java
  37. 25
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/style/DSpDimension.java
  38. 191
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingDialog.java
  39. 56
    6
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java
  40. 5
    3
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java
  41. 12
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java
  42. 5
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java
  43. 33
    0
      IDE/src/main/java/org/openzen/zenscript/ide/Arguments.java
  44. 4
    1
      IDE/src/main/java/org/openzen/zenscript/ide/Main.java
  45. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBar.java
  46. 63
    2
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java
  47. 1
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/AddBoxIcon.java
  48. 8
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java
  49. 36
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarStyle.java
  50. 26
    4
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarView.java
  51. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java
  52. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTab.java
  53. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTabClose.java
  54. 4
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java
  55. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java
  56. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButtonStyle.java
  57. 2
    2
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarStyle.java
  58. 17
    4
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java
  59. 5
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/WindowActionButton.java
  60. 6
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java
  61. 9
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ModuleTreeNode.java
  62. 1
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/SourceFileTreeNode.java
  63. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  64. 3
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java
  65. 4
    6
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  66. 1
    2
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedGenericParameter.java

+ 1
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java Переглянути файл

@@ -107,7 +107,7 @@ public class DefinitionFormatter implements DefinitionVisitor<Void> {
107 107
 		
108 108
 		List<EnumConstantMember> enumConstants = definition.enumConstants;
109 109
 		boolean first = true;
110
-		ExpressionFormatter expressionFormatter = new ExpressionFormatter(settings, typeFormatter);
110
+		ExpressionFormatter expressionFormatter = new ExpressionFormatter(settings, typeFormatter, indent);
111 111
 		for (EnumConstantMember enumConstant : enumConstants) {
112 112
 			if (first)
113 113
 				first = false;

+ 33
- 5
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java Переглянути файл

@@ -76,7 +76,8 @@ import org.openzen.zenscript.codemodel.expression.TryRethrowAsExceptionExpressio
76 76
 import org.openzen.zenscript.codemodel.expression.TryRethrowAsResultExpression;
77 77
 import org.openzen.zenscript.codemodel.expression.VariantValueExpression;
78 78
 import org.openzen.zenscript.codemodel.expression.WrapOptionalExpression;
79
-import org.openzen.zenscript.formattershared.FormattableOperator;
79
+import org.openzen.zenscript.codemodel.statement.ExpressionStatement;
80
+import org.openzen.zenscript.codemodel.statement.ReturnStatement;
80 81
 
81 82
 /**
82 83
  *
@@ -85,10 +86,12 @@ import org.openzen.zenscript.formattershared.FormattableOperator;
85 86
 public class ExpressionFormatter implements ExpressionVisitor<ExpressionString> {
86 87
 	private final ScriptFormattingSettings settings;
87 88
 	public final TypeFormatter typeFormatter;
89
+	public final String indent;
88 90
 	
89
-	public ExpressionFormatter(ScriptFormattingSettings settings, TypeFormatter typeFormatter) {
91
+	public ExpressionFormatter(ScriptFormattingSettings settings, TypeFormatter typeFormatter, String indent) {
90 92
 		this.settings = settings;
91 93
 		this.typeFormatter = typeFormatter;
94
+		this.indent = indent;
92 95
 	}
93 96
 
94 97
 	@Override
@@ -238,6 +241,11 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
238 241
 				default:
239 242
 					throw new UnsupportedOperationException("Unknown operator: " + expression.member.getOperator());
240 243
 			}
244
+		} else if (expression.member.isCaller()) {
245
+			StringBuilder result = new StringBuilder();
246
+			result.append(expression.target.accept(this).value);
247
+			FormattingUtils.formatCall(result, typeFormatter, this, expression.arguments);
248
+			return new ExpressionString(result.toString(), ZenScriptOperator.PRIMARY);
241 249
 		} else {
242 250
 			StringBuilder result = new StringBuilder();
243 251
 			result.append(expression.target.accept(this).value);
@@ -429,9 +437,29 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
429 437
 
430 438
 	@Override
431 439
 	public ExpressionString visitFunction(FunctionExpression expression) {
432
-		//FIXME
433
-		return new ExpressionString("asdfghj", ZenScriptOperator.PRIMARY);
434
-		//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
440
+		StringBuilder result = new StringBuilder();
441
+		if (expression.header.parameters.length == 1) {
442
+			result.append(expression.header.parameters[0].name);
443
+		} else {
444
+			result.append('(');
445
+			for (int i = 0; i < expression.header.parameters.length; i++) {
446
+				if (i > 0)
447
+					result.append(", ");
448
+				result.append(expression.header.parameters[i].name);
449
+			}
450
+			result.append(')');
451
+		}
452
+		result.append(" => ");
453
+		
454
+		if (expression.body instanceof ReturnStatement) {
455
+			result.append(((ReturnStatement) expression.body).value.accept(this));
456
+		} else if (expression.body instanceof ExpressionStatement) {
457
+			result.append(((ExpressionStatement) expression.body).expression.accept(this));
458
+		} else {
459
+			StatementFormatter formatter = new StatementFormatter(result, indent + settings.indent + settings.indent, settings, this);
460
+			expression.body.accept(formatter);
461
+		}
462
+		return new ExpressionString(result.toString(), ZenScriptOperator.FUNCTION);
435 463
 	}
436 464
 
437 465
 	@Override

+ 1
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FileFormatter.java Переглянути файл

@@ -33,7 +33,7 @@ public class FileFormatter {
33 33
 		FileImporter importer = new FileImporter(pkg);
34 34
 		
35 35
 		TypeFormatter typeFormatter = new TypeFormatter(settings, importer);
36
-		ExpressionFormatter expressionFormatter = new ExpressionFormatter(settings, typeFormatter);
36
+		ExpressionFormatter expressionFormatter = new ExpressionFormatter(settings, typeFormatter, "");
37 37
 		
38 38
 		List<DefinitionFormatter> definitionFormatters = new ArrayList<>();
39 39
 		for (HighLevelDefinition definition : definitions) {

+ 4
- 4
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java Переглянути файл

@@ -93,7 +93,7 @@ public class FormattingUtils {
93 93
 	}
94 94
 	
95 95
 	public static void formatTypeParameters(StringBuilder result, TypeParameter[] parameters, TypeFormatter typeFormatter) {
96
-		if (parameters != null) {
96
+		if (parameters != null && parameters.length > 0) {
97 97
 			result.append("<");
98 98
 			int index = 0;
99 99
 			for (TypeParameter parameter : parameters) {
@@ -160,7 +160,7 @@ public class FormattingUtils {
160 160
 			this.indent = indent;
161 161
 			this.typeFormatter = typeFormatter;
162 162
 			
163
-			statementFormatter = new StatementFormatter(output, indent, settings, new ExpressionFormatter(settings, typeFormatter)); 
163
+			statementFormatter = new StatementFormatter(output, indent, settings, new ExpressionFormatter(settings, typeFormatter, indent)); 
164 164
 		}
165 165
 
166 166
 		@Override
@@ -197,7 +197,7 @@ public class FormattingUtils {
197 197
 				output.append("\n").append(indent).append(settings.indent).append("=> ");
198 198
 			}
199 199
 			
200
-			output.append(statement.expression.accept(new ExpressionFormatter(settings, typeFormatter)));
200
+			output.append(statement.expression.accept(new ExpressionFormatter(settings, typeFormatter, indent)));
201 201
 			output.append(";");
202 202
 			return null;
203 203
 		}
@@ -225,7 +225,7 @@ public class FormattingUtils {
225 225
 				output.append("\n").append(indent).append(settings.indent).append("=> ");
226 226
 			}
227 227
 			
228
-			output.append(statement.value.accept(new ExpressionFormatter(settings, typeFormatter)));
228
+			output.append(statement.value.accept(new ExpressionFormatter(settings, typeFormatter, indent)));
229 229
 			output.append(";");
230 230
 			return null;
231 231
 		}

+ 2
- 2
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/MemberFormatter.java Переглянути файл

@@ -64,7 +64,7 @@ public class MemberFormatter implements MemberVisitor<Void> {
64 64
 				.append(" as ")
65 65
 				.append(member.type.accept(typeFormatter))
66 66
 				.append(" = ")
67
-				.append(member.value.accept(new ExpressionFormatter(settings, typeFormatter)))
67
+				.append(member.value.accept(new ExpressionFormatter(settings, typeFormatter, indent)))
68 68
 				.append(";\n");
69 69
 		return null;
70 70
 	}
@@ -80,7 +80,7 @@ public class MemberFormatter implements MemberVisitor<Void> {
80 80
 		
81 81
 		if (member.initializer != null) {
82 82
 			output.append(" = ")
83
-					.append(member.initializer.accept(new ExpressionFormatter(settings, typeFormatter)));
83
+					.append(member.initializer.accept(new ExpressionFormatter(settings, typeFormatter, indent)));
84 84
 		}
85 85
 		output.append(";\n");
86 86
 		return null;

+ 2
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ZenScriptOperator.java Переглянути файл

@@ -61,7 +61,8 @@ public enum ZenScriptOperator implements FormattableOperator {
61 61
 	CAST(9, null),
62 62
 	
63 63
 	PANIC(10, "panic "),
64
-	PRIMARY(10, null);
64
+	PRIMARY(10, null),
65
+	FUNCTION(10, null);
65 66
 	
66 67
 	private final int priority;
67 68
 	private final String operatorString;

+ 0
- 14
CodeModel/src/main/java/org/openzen/zenscript/codemodel/AccessScope.java Переглянути файл

@@ -1,14 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.zenscript.codemodel;
7
-
8
-/**
9
- *
10
- * @author Hoofdgebruiker
11
- */
12
-public class AccessScope {
13
-	
14
-}

+ 9
- 8
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Переглянути файл

@@ -36,7 +36,7 @@ public class FunctionHeader {
36 36
 		if (returnType == null)
37 37
 			throw new NullPointerException();
38 38
 		
39
-		this.typeParameters = null;
39
+		this.typeParameters = TypeParameter.NONE;
40 40
 		this.returnType = returnType;
41 41
 		this.parameters = NO_PARAMETERS;
42 42
 		this.thrownType = null;
@@ -49,7 +49,7 @@ public class FunctionHeader {
49 49
 		if (returnType == null)
50 50
 			throw new NullPointerException();
51 51
 		
52
-		this.typeParameters = null;
52
+		this.typeParameters = TypeParameter.NONE;
53 53
 		this.returnType = returnType;
54 54
 		this.parameters = new FunctionParameter[parameterTypes.length];
55 55
 		this.thrownType = null;
@@ -65,7 +65,7 @@ public class FunctionHeader {
65 65
 		if (returnType == null)
66 66
 			throw new NullPointerException();
67 67
 		
68
-		this.typeParameters = null;
68
+		this.typeParameters = TypeParameter.NONE;
69 69
 		this.returnType = returnType;
70 70
 		this.parameters = parameters;
71 71
 		this.thrownType = null;
@@ -77,6 +77,8 @@ public class FunctionHeader {
77 77
 	public FunctionHeader(TypeParameter[] genericParameters, ITypeID returnType, ITypeID thrownType, FunctionParameter... parameters) {
78 78
 		if (returnType == null)
79 79
 			throw new NullPointerException();
80
+		if (genericParameters == null)
81
+			throw new NullPointerException();
80 82
 		
81 83
 		this.typeParameters = genericParameters;
82 84
 		this.returnType = returnType;
@@ -88,7 +90,7 @@ public class FunctionHeader {
88 90
 	}
89 91
 	
90 92
 	public int getNumberOfTypeParameters() {
91
-		return typeParameters == null ? 0 : typeParameters.length;
93
+		return typeParameters.length;
92 94
 	}
93 95
 	
94 96
 	public boolean matchesExactly(CallArguments arguments, TypeScope scope) {
@@ -274,9 +276,8 @@ public class FunctionHeader {
274 276
 			return this;
275 277
 		
276 278
 		Map<TypeParameter, ITypeID> typeArguments = new HashMap<>();
277
-		if (typeParameters != null)
278
-			for (int i = 0; i < typeParameters.length; i++)
279
-				typeArguments.put(typeParameters[i], arguments[i]);
279
+		for (int i = 0; i < typeParameters.length; i++)
280
+			typeArguments.put(typeParameters[i], arguments[i]);
280 281
 		GenericMapper mapper = new GenericMapper(registry, typeArguments);
281 282
 		
282 283
 		ITypeID returnType = this.returnType.instance(mapper);
@@ -327,7 +328,7 @@ public class FunctionHeader {
327 328
 	@Override
328 329
 	public String toString() {
329 330
 		StringBuilder result = new StringBuilder();
330
-		if (typeParameters != null && typeParameters.length > 0) {
331
+		if (typeParameters.length > 0) {
331 332
 			result.append("<");
332 333
 			for (int i = 0; i < typeParameters.length; i++) {
333 334
 				if (i > 0)

+ 0
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java Переглянути файл

@@ -28,7 +28,6 @@ public abstract class HighLevelDefinition extends Taggable {
28 28
 	public final String name;
29 29
 	public final int modifiers;
30 30
 	public final List<IDefinitionMember> members = new ArrayList<>();
31
-	public final AccessScope access = new AccessScope();
32 31
 	public TypeParameter[] genericParameters = null;
33 32
 	public DefinitionAnnotation[] annotations = DefinitionAnnotation.NONE;
34 33
 	

+ 2
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/ScriptBlock.java Переглянути файл

@@ -14,16 +14,14 @@ import org.openzen.zenscript.codemodel.statement.Statement;
14 14
  * @author Hoofdgebruiker
15 15
  */
16 16
 public class ScriptBlock extends Taggable {
17
-	public final AccessScope access;
18 17
 	public final List<Statement> statements;
19 18
 	
20
-	public ScriptBlock(AccessScope access, List<Statement> statements) {
21
-		this.access = access;
19
+	public ScriptBlock(List<Statement> statements) {
22 20
 		this.statements = statements;
23 21
 	}
24 22
 	
25 23
 	public ScriptBlock withStatements(List<Statement> newStatements) {
26
-		ScriptBlock result = new ScriptBlock(access, newStatements);
24
+		ScriptBlock result = new ScriptBlock(newStatements);
27 25
 		result.addAllTagsFrom(this);
28 26
 		return result;
29 27
 	}

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/AnnotationProcessor.java Переглянути файл

@@ -67,7 +67,7 @@ public class AnnotationProcessor implements ModuleProcessor {
67 67
 	
68 68
 	@Override
69 69
 	public ScriptBlock process(ScriptBlock block) {
70
-		FileScope fileScope = new FileScope(block.access, rootPackage, packageDefinitions, globalRegistry, expansions, new HashMap<>(), annotations);
70
+		FileScope fileScope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, new HashMap<>(), annotations);
71 71
 		StatementScope scope = new GlobalScriptScope(fileScope);
72 72
 		List<Statement> transformed = new ArrayList<>();
73 73
 		boolean unchanged = true;
@@ -81,7 +81,7 @@ public class AnnotationProcessor implements ModuleProcessor {
81 81
 	
82 82
 	@Override
83 83
 	public void process(HighLevelDefinition definition) {
84
-		FileScope fileScope = new FileScope(definition.access, rootPackage, packageDefinitions, globalRegistry, expansions, new HashMap<>(), annotations);
84
+		FileScope fileScope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, new HashMap<>(), annotations);
85 85
 		DefinitionScope scope = new DefinitionScope(fileScope, definition);
86 86
 		for (DefinitionAnnotation annotation : definition.annotations) {
87 87
 			annotation.apply(definition, scope);

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameter.java Переглянути файл

@@ -18,6 +18,8 @@ import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
18 18
  * @author Hoofdgebruiker
19 19
  */
20 20
 public class TypeParameter {
21
+	public static final TypeParameter[] NONE = new TypeParameter[0];
22
+	
21 23
 	public final CodePosition position;
22 24
 	public final String name;
23 25
 	public final List<GenericParameterBound> bounds = new ArrayList<>();

+ 1
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java Переглянути файл

@@ -12,7 +12,6 @@ import java.util.function.Function;
12 12
 import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zencode.shared.CompileException;
14 14
 import org.openzen.zencode.shared.CompileExceptionCode;
15
-import org.openzen.zenscript.codemodel.AccessScope;
16 15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
17 16
 import org.openzen.zenscript.codemodel.FunctionHeader;
18 17
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
@@ -45,7 +44,6 @@ public class FileScope extends BaseScope {
45 44
 	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
46 45
 	
47 46
 	public FileScope(
48
-			AccessScope access,
49 47
 			ZSPackage rootPackage,
50 48
 			PackageDefinitions packageDefinitions,
51 49
 			GlobalTypeRegistry globalRegistry,
@@ -57,7 +55,7 @@ public class FileScope extends BaseScope {
57 55
 		this.globalRegistry = globalRegistry;
58 56
 		this.globalSymbols = globalSymbols;
59 57
 		
60
-		memberCache = new LocalMemberCache(access, globalRegistry, expansions);
58
+		memberCache = new LocalMemberCache(globalRegistry, expansions);
61 59
 		
62 60
 		for (AnnotationDefinition annotation : annotations) {
63 61
 			this.annotations.put(annotation.getAnnotationName(), annotation);

+ 0
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/LocalMemberCache.java Переглянути файл

@@ -9,7 +9,6 @@ import java.util.ArrayList;
9 9
 import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12
-import org.openzen.zenscript.codemodel.AccessScope;
13 12
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
14 13
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
15 14
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -19,16 +18,13 @@ import org.openzen.zenscript.codemodel.type.ITypeID;
19 18
  * @author Hoofdgebruiker
20 19
  */
21 20
 public class LocalMemberCache {
22
-	private final AccessScope access;
23 21
 	private final GlobalTypeRegistry registry;
24 22
 	private final Map<ITypeID, TypeMembers> types = new HashMap<>();
25 23
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
26 24
 	
27 25
 	public LocalMemberCache(
28
-			AccessScope access,
29 26
 			GlobalTypeRegistry registry,
30 27
 			List<ExpansionDefinition> expansions) {
31
-		this.access = access;
32 28
 		this.registry = registry;
33 29
 		this.expansions.addAll(expansions);
34 30
 	}

+ 2
- 3
CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java Переглянути файл

@@ -8,7 +8,6 @@ package org.openzen.zenscript.compiler;
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11
-import org.openzen.zenscript.codemodel.AccessScope;
12 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13 12
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
14 13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
@@ -27,10 +26,10 @@ public class CompileScope implements TypeScope {
27 26
 	private final LocalMemberCache cache;
28 27
 	private final Map<String, AnnotationDefinition> annotations = new HashMap<>();
29 28
 	
30
-	public CompileScope(AccessScope access, GlobalTypeRegistry globalRegistry, List<ExpansionDefinition> expansions, List<AnnotationDefinition> annotations) {
29
+	public CompileScope(GlobalTypeRegistry globalRegistry, List<ExpansionDefinition> expansions, List<AnnotationDefinition> annotations) {
31 30
 		this.globalRegistry = globalRegistry;
32 31
 		this.expansions = expansions;
33
-		this.cache = new LocalMemberCache(access, globalRegistry, expansions);
32
+		this.cache = new LocalMemberCache(globalRegistry, expansions);
34 33
 		
35 34
 		for (AnnotationDefinition annotation : annotations) {
36 35
 			this.annotations.put(annotation.getAnnotationName(), annotation);

+ 30
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DAnchor.java Переглянути файл

@@ -0,0 +1,30 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public enum DAnchor {
13
+	TOP_LEFT(0, 0),
14
+	TOP_CENTER(0.5f, 0),
15
+	TOP_RIGHT(1, 0),
16
+	MIDDLE_LEFT(0, 0.5f),
17
+	MIDDLE_CENTER(0.5f, 0.5f),
18
+	MIDDLE_RIGHT(1, 0.5f),
19
+	BOTTOM_LEFT(0, 1),
20
+	BOTTOM_CENTER(0.5f, 1),
21
+	BOTTOM_RIGHT(1, 1);
22
+	
23
+	public final float alignX;
24
+	public final float alignY;
25
+	
26
+	DAnchor(float alignX, float alignY) {
27
+		this.alignX = alignX;
28
+		this.alignY = alignY;
29
+	}
30
+}

+ 123
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DButton.java Переглянути файл

@@ -0,0 +1,123 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.live.LiveBool;
9
+import org.openzen.drawablegui.live.LiveObject;
10
+import org.openzen.drawablegui.live.LiveString;
11
+import org.openzen.drawablegui.live.SimpleLiveObject;
12
+import org.openzen.drawablegui.style.DStyleClass;
13
+import org.openzen.drawablegui.style.DStylePath;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class DButton implements DComponent {
20
+	private final DStyleClass styleClass;
21
+	private final LiveString label;
22
+	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
23
+	private final LiveBool disabled;
24
+	
25
+	private DUIContext context;
26
+	private DIRectangle bounds;
27
+	
28
+	private DButtonStyle style;
29
+	private DFontMetrics fontMetrics;
30
+	
31
+	private boolean hovering = false;
32
+	private boolean pressing = false;
33
+	
34
+	public DButton(DStyleClass styleClass, LiveString label, LiveBool disabled) {
35
+		this.styleClass = styleClass;
36
+		this.label = label;
37
+		this.disabled = disabled;
38
+	}
39
+
40
+	@Override
41
+	public void setContext(DStylePath parent, DUIContext context) {
42
+		this.context = context;
43
+		
44
+		DStylePath path = parent.getChild("Button", styleClass);
45
+		this.style = new DButtonStyle(context.getStylesheets().get(context, path));
46
+		fontMetrics = context.getFontMetrics(style.font);
47
+	}
48
+
49
+	@Override
50
+	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
51
+		return dimensionPreferences;
52
+	}
53
+
54
+	@Override
55
+	public DIRectangle getBounds() {
56
+		return bounds;
57
+	}
58
+
59
+	@Override
60
+	public int getBaselineY() {
61
+		return style.paddingTop + fontMetrics.getAscent();
62
+	}
63
+
64
+	@Override
65
+	public void setBounds(DIRectangle bounds) {
66
+		this.bounds = bounds;
67
+	}
68
+
69
+	@Override
70
+	public void paint(DCanvas canvas) {
71
+		int backgroundColor = style.backgroundColorNormal;
72
+		if (hovering)
73
+			backgroundColor = style.backgroundColorHover;
74
+		if (pressing)
75
+			backgroundColor = style.backgroundColorPress;
76
+		if (disabled.getValue())
77
+			backgroundColor = style.backgroundColorDisabled;
78
+		
79
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, backgroundColor);
80
+	}
81
+
82
+	@Override
83
+	public void close() {
84
+		
85
+	}
86
+	
87
+	@Override
88
+	public void onMouseEnter(DMouseEvent e) {
89
+		hovering = true;
90
+		repaint();
91
+	}
92
+	
93
+	@Override
94
+	public void onMouseExit(DMouseEvent e) {
95
+		hovering = false;
96
+		pressing = false;
97
+		repaint();
98
+	}
99
+	
100
+	@Override
101
+	public void onMouseDown(DMouseEvent e) {
102
+		pressing = true;
103
+		repaint();
104
+	}
105
+	
106
+	@Override
107
+	public void onMouseRelease(DMouseEvent e) {
108
+		pressing = false;
109
+		
110
+		if (!disabled.getValue()) {
111
+			// TODO
112
+		}
113
+		
114
+		repaint();
115
+	}
116
+	
117
+	private void repaint() {
118
+		if (context == null || bounds == null)
119
+			return;
120
+		
121
+		context.repaint(bounds);
122
+	}
123
+}

+ 54
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DButtonStyle.java Переглянути файл

@@ -0,0 +1,54 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.style.DDpDimension;
9
+import org.openzen.drawablegui.style.DShadow;
10
+import org.openzen.drawablegui.style.DStyleDefinition;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class DButtonStyle {
17
+	public final int paddingTop;
18
+	public final int paddingLeft;
19
+	public final int paddingRight;
20
+	public final int paddingBottom;
21
+	public final DFont font;
22
+	public final int textColor;
23
+	public final int textColorDisabled;
24
+	
25
+	public final int backgroundColorNormal;
26
+	public final int backgroundColorHover;
27
+	public final int backgroundColorPress;
28
+	public final int backgroundColorDisabled;
29
+	
30
+	public final DShadow shadowNormal;
31
+	public final DShadow shadowHover;
32
+	public final DShadow shadowPress;
33
+	public final DShadow shadowDisabled;
34
+	
35
+	public DButtonStyle(DStyleDefinition style) {
36
+		this.paddingTop = style.getDimension("paddingTop", new DDpDimension(4));
37
+		this.paddingBottom = style.getDimension("paddingBottom", new DDpDimension(4));
38
+		this.paddingLeft = style.getDimension("paddingLeft", new DDpDimension(4));
39
+		this.paddingRight = style.getDimension("paddingRight", new DDpDimension(4));
40
+		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, (int)(14 * context.getTextScale())));
41
+		textColor = style.getColor("textColor", 0xFF000000);
42
+		textColorDisabled = style.getColor("textColorDisabled", 0xFF888888);
43
+		
44
+		backgroundColorNormal = style.getColor("backgroundColorNormal", 0xFFE1E1E1);
45
+		backgroundColorHover = style.getColor("backgroundColorHover", 0xFFE5EFF8);
46
+		backgroundColorPress = style.getColor("backgroundColorPress", 0xFFE5EFF8);
47
+		backgroundColorDisabled = style.getColor("backgroundColorDisabled", 0xFFE5EFF8);
48
+		
49
+		shadowNormal = style.getShadow("shadowNormal", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
50
+		shadowHover = style.getShadow("shadowHover", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
51
+		shadowPress = style.getShadow("shadowPress", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
52
+		shadowDisabled = style.getShadow("shadowDisabled", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
53
+	}
54
+}

+ 2
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DComponent.java Переглянути файл

@@ -20,6 +20,8 @@ public interface DComponent extends Closeable {
20 20
 	
21 21
 	DIRectangle getBounds();
22 22
 	
23
+	int getBaselineY();
24
+	
23 25
 	void setBounds(DIRectangle bounds);
24 26
 	
25 27
 	void paint(DCanvas canvas);

+ 5
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DEmptyView.java Переглянути файл

@@ -36,6 +36,11 @@ public class DEmptyView implements DComponent {
36 36
 		return NO_BOUNDS;
37 37
 	}
38 38
 
39
+	@Override
40
+	public int getBaselineY() {
41
+		return -1;
42
+	}
43
+	
39 44
 	@Override
40 45
 	public void setBounds(DIRectangle bounds) {
41 46
 		

+ 271
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayout.java Переглянути файл

@@ -0,0 +1,271 @@
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.Consumer;
9
+import java.util.function.Predicate;
10
+import org.openzen.drawablegui.listeners.ListenerHandle;
11
+import org.openzen.drawablegui.live.LiveObject;
12
+import org.openzen.drawablegui.live.SimpleLiveObject;
13
+import org.openzen.drawablegui.style.DStyleClass;
14
+import org.openzen.drawablegui.style.DStylePath;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public class DHorizontalLayout extends BaseComponentGroup {
21
+	private final DStyleClass styleClass;
22
+	private final Alignment alignment;
23
+	private final Element[] components;
24
+	private final ListenerHandle<LiveObject.Listener<DDimensionPreferences>>[] componentSizeListeners;
25
+	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
26
+	
27
+	private DUIContext context;
28
+	private DHorizontalLayoutStyle style;
29
+	private DIRectangle bounds;
30
+	private float totalGrow;
31
+	private float totalShrink;
32
+	
33
+	public DHorizontalLayout(DStyleClass styleClass, Alignment alignment, Element... components) {
34
+		this.styleClass = styleClass;
35
+		this.alignment = alignment;
36
+		this.components = components;
37
+		
38
+		componentSizeListeners = new ListenerHandle[components.length];
39
+		totalGrow = 0;
40
+		totalShrink = 0;
41
+		
42
+		for (int i = 0; i < componentSizeListeners.length; i++) {
43
+			componentSizeListeners[i] = components[i].component.getDimensionPreferences().addListener((oldValue, newValue) -> updateDimensionPreferences());
44
+			
45
+			totalGrow += components[i].grow;
46
+			totalShrink += components[i].shrink;
47
+		}
48
+	}
49
+
50
+	@Override
51
+	protected void forEachChild(Consumer<DComponent> children) {
52
+		for (Element element : components)
53
+			children.accept(element.component);
54
+	}
55
+
56
+	@Override
57
+	protected DComponent findChild(Predicate<DComponent> predicate) {
58
+		for (Element element : components)
59
+			if (predicate.test(element.component))
60
+				return element.component;
61
+		
62
+		return null;
63
+	}
64
+
65
+	@Override
66
+	public void setContext(DStylePath parent, DUIContext context) {
67
+		this.context = context;
68
+		
69
+		DStylePath path = parent.getChild("horizontalLayout", styleClass);
70
+		style = new DHorizontalLayoutStyle(context.getStylesheets().get(context, path));
71
+		
72
+		for (Element element : components)
73
+			element.component.setContext(parent, context);
74
+		
75
+		layout();
76
+	}
77
+
78
+	@Override
79
+	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
80
+		return dimensionPreferences;
81
+	}
82
+
83
+	@Override
84
+	public DIRectangle getBounds() {
85
+		return bounds;
86
+	}
87
+
88
+	@Override
89
+	public int getBaselineY() {
90
+		return components[0].component.getBaselineY();
91
+	}
92
+
93
+	@Override
94
+	public void setBounds(DIRectangle bounds) {
95
+		this.bounds = bounds;
96
+	}
97
+
98
+	@Override
99
+	public void paint(DCanvas canvas) {
100
+		for (Element element : components) {
101
+			element.component.paint(canvas);
102
+		}
103
+	}
104
+
105
+	@Override
106
+	public void close() {
107
+		for (int i = 0; i < componentSizeListeners.length; i++) {
108
+			componentSizeListeners[i].close();
109
+		}
110
+	}
111
+	
112
+	public static enum Alignment {
113
+		LEFT(0),
114
+		CENTER(0.5f),
115
+		RIGHT(1);
116
+		
117
+		public final float align;
118
+		
119
+		Alignment(float align) {
120
+			this.align = align;
121
+		}
122
+	}
123
+	
124
+	public static enum ElementAlignment {
125
+		TOP,
126
+		MIDDLE,
127
+		BOTTOM,
128
+		STRETCH
129
+	}
130
+	
131
+	public static class Element {
132
+		public final DComponent component;
133
+		public final float grow;
134
+		public final float shrink;
135
+		public final ElementAlignment alignment;
136
+		
137
+		public Element(DComponent component, float grow, float shrink, ElementAlignment alignment) {
138
+			this.component = component;
139
+			this.grow = grow;
140
+			this.shrink = shrink;
141
+			this.alignment = alignment;
142
+		}
143
+	}
144
+	
145
+	private void layout() {
146
+		if (bounds == null || context == null)
147
+			return;
148
+		
149
+		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
150
+		if (bounds.width < myPreferences.preferredWidth) {
151
+			layoutShrinked();
152
+		} else {
153
+			layoutGrown();
154
+		}
155
+	}
156
+	
157
+	private void layoutShrinked() {
158
+		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
159
+		if (totalShrink == 0) {
160
+			// now what?
161
+			// shrink proportionally, we have to shrink...
162
+			float scale = (float)(bounds.width - (components.length - 1) * style.spacing) / (myPreferences.preferredWidth - (components.length - 1) * style.spacing);
163
+			int x = 0;
164
+			
165
+			for (int i = 0; i < components.length; i++) {
166
+				Element element = components[i];
167
+				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
168
+				int newX = x + preferences.preferredWidth;
169
+				float idealUnspacedX = newX * scale;
170
+				int idealX = (int)(idealUnspacedX + 0.5f + i * style.spacing);
171
+				layout(element, x, idealX - x);
172
+				x = idealX;
173
+			}
174
+		} else {
175
+			int delta = bounds.width - myPreferences.preferredWidth;
176
+			float deltaScaled = delta / totalShrink;
177
+			int x = 0;
178
+			for (Element element : components) {
179
+				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
180
+				float scaledSize = preferences.preferredWidth + deltaScaled * element.shrink;
181
+				float idealUnspacedX = x + scaledSize;
182
+				int newX = (int)(idealUnspacedX + 0.5f);
183
+				layout(element, x, newX - x);
184
+				x = newX + style.spacing;
185
+			}
186
+		}
187
+	}
188
+	
189
+	private void layoutGrown() {
190
+		// resize according to grow values
191
+		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
192
+		
193
+		if (totalGrow == 0) {
194
+			int deltaX = (int)(myPreferences.preferredWidth - bounds.width);
195
+			int x = bounds.x + (int)(deltaX * alignment.align);
196
+			for (Element element : components) {
197
+				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
198
+				int newX = x + preferences.preferredWidth;
199
+				layout(element, x, newX - x);
200
+				x = newX;
201
+			}
202
+		} else {
203
+			int delta = bounds.width - myPreferences.preferredWidth;
204
+			float deltaScaled = delta / totalGrow;
205
+			int x = 0;
206
+			for (Element element : components) {
207
+				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
208
+				float scaledSize = preferences.preferredWidth + deltaScaled * element.grow;
209
+				float idealUnspacedX = x + scaledSize;
210
+				int newX = (int)(idealUnspacedX + 0.5f);
211
+				layout(element, x, newX - x);
212
+				x = newX + style.spacing;
213
+			}
214
+		}
215
+	}
216
+	
217
+	private void layout(Element element, int x, int width) {
218
+		DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
219
+		int height;
220
+		int y;
221
+		switch (element.alignment) {
222
+			case BOTTOM:
223
+				height = Math.min(preferences.preferredHeight, bounds.height - style.paddingTop - style.paddingBottom);
224
+				y = bounds.y + style.paddingTop;
225
+				break;
226
+			case MIDDLE:
227
+				height = Math.min(preferences.preferredHeight, bounds.height - style.paddingTop - style.paddingBottom);
228
+				y = bounds.y + style.paddingTop + (bounds.height - style.paddingTop - style.paddingBottom - height) / 2;
229
+				break;
230
+			case TOP:
231
+				height = Math.min(preferences.preferredHeight, bounds.height - style.paddingTop - style.paddingBottom);
232
+				y = bounds.y + bounds.height - style.paddingBottom - height;
233
+				break;
234
+			case STRETCH:
235
+			default:
236
+				height = bounds.height - style.paddingTop - style.paddingBottom;
237
+				y = bounds.y + style.paddingTop;
238
+				break;
239
+		}
240
+		element.component.setBounds(new DIRectangle(bounds.x + x, y, width, height));
241
+	}
242
+	
243
+	private void updateDimensionPreferences() {
244
+		int preferredWidth = -style.spacing;
245
+		int preferredHeight = 0;
246
+		int minimumWidth = -style.spacing;
247
+		int minimumHeight = 0;
248
+		int maximumWidth = -style.spacing;
249
+		int maximumHeight = Integer.MAX_VALUE;
250
+		for (Element element : components) {
251
+			DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
252
+			preferredWidth += preferences.preferredWidth + style.spacing;
253
+			preferredHeight = Math.max(preferredHeight, preferences.preferredHeight);
254
+			
255
+			minimumWidth += preferences.minimumWidth + style.spacing;
256
+			minimumHeight = Math.max(minimumHeight, preferences.minimumHeight);
257
+			
258
+			maximumWidth += preferences.maximumWidth + style.spacing;
259
+			maximumHeight = Math.min(maximumHeight, preferences.maximumHeight);
260
+		}
261
+		
262
+		DDimensionPreferences preferences = new DDimensionPreferences(
263
+				minimumWidth + style.paddingLeft + style.paddingRight,
264
+				minimumHeight + style.paddingTop + style.paddingBottom,
265
+				preferredWidth + style.paddingLeft + style.paddingRight,
266
+				preferredHeight + style.paddingTop + style.paddingBottom,
267
+				maximumWidth + style.paddingLeft + style.paddingRight,
268
+				maximumHeight + style.paddingTop + style.paddingBottom);
269
+		dimensionPreferences.setValue(preferences);
270
+	}
271
+}

+ 31
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DHorizontalLayoutStyle.java Переглянути файл

@@ -0,0 +1,31 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.style.DDpDimension;
9
+import org.openzen.drawablegui.style.DStyleDefinition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class DHorizontalLayoutStyle {
16
+	public final int spacing;
17
+	
18
+	public final int paddingTop;
19
+	public final int paddingLeft;
20
+	public final int paddingRight;
21
+	public final int paddingBottom;
22
+	
23
+	public DHorizontalLayoutStyle(DStyleDefinition style) {
24
+		spacing = style.getDimension("spacing", new DDpDimension(8));
25
+		
26
+		paddingTop = style.getDimension("paddingTop", new DDpDimension(8));
27
+		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(8));
28
+		paddingRight = style.getDimension("paddingRight", new DDpDimension(8));
29
+		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(8));
30
+	}
31
+}

+ 18
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DIRectangle.java Переглянути файл

@@ -18,14 +18,32 @@ public class DIRectangle {
18 18
 	public final int height;
19 19
 	
20 20
 	public DIRectangle(int x, int y, int width, int height) {
21
+		if (width < 0)
22
+			throw new IllegalArgumentException("Width must be >= 0");
23
+		if (height < 0)
24
+			throw new IllegalArgumentException("Height must be >= 0");
25
+		
21 26
 		this.x = x;
22 27
 		this.y = y;
23 28
 		this.width = width;
24 29
 		this.height = height;
25 30
 	}
26 31
 	
32
+	public int getCenterX() {
33
+		return (x + width) / 2;
34
+	}
35
+	
36
+	public int getCenterY() {
37
+		return (y + height) / 2;
38
+	}
39
+	
27 40
 	public boolean contains(int x, int y) {
28 41
 		return x >= this.x && x < (this.x + this.width)
29 42
 				&& y >= this.y && y < (this.y + this.height);
30 43
 	}
44
+	
45
+	@Override
46
+	public String toString() {
47
+		return "(x = " + x + ", y = " + y + ", width = " + width + ", height = " + height + ")";
48
+	}
31 49
 }

+ 148
- 7
DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java Переглянути файл

@@ -9,6 +9,7 @@ import org.openzen.drawablegui.listeners.ListenerHandle;
9 9
 import org.openzen.drawablegui.live.LiveObject;
10 10
 import org.openzen.drawablegui.live.LiveString;
11 11
 import org.openzen.drawablegui.live.SimpleLiveObject;
12
+import org.openzen.drawablegui.style.DDimension;
12 13
 import org.openzen.drawablegui.style.DStyleClass;
13 14
 import org.openzen.drawablegui.style.DStylePath;
14 15
 
@@ -23,6 +24,7 @@ public class DInputField implements DComponent {
23 24
 	private final DStyleClass styleClass;
24 25
 	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
25 26
 	private DIRectangle bounds = DIRectangle.EMPTY;
27
+	private final DDimension preferredWidth;
26 28
 	
27 29
 	private DUIContext context;
28 30
 	private DInputFieldStyle style;
@@ -30,10 +32,23 @@ public class DInputField implements DComponent {
30 32
 	private int cursorFrom = -1;
31 33
 	private int cursorTo = -1;
32 34
 	
33
-	public DInputField(DStyleClass styleClass, LiveString value) {
35
+	private boolean cursorBlink = true;
36
+	private DTimerHandle blinkTimer;
37
+	
38
+	public DInputField(DStyleClass styleClass, LiveString value, DDimension preferredWidth) {
34 39
 		this.styleClass = styleClass;
35 40
 		this.value = value;
41
+		this.preferredWidth = preferredWidth;
42
+		
36 43
 		valueListener = value.addListener((oldValue, newValue) -> handleValueUpdated(newValue));
44
+		cursorFrom = 0;
45
+		cursorTo = value.getValue().length();
46
+	}
47
+	
48
+	@Override
49
+	public void close() {
50
+		valueListener.close();
51
+		blinkTimer.close();
37 52
 	}
38 53
 
39 54
 	@Override
@@ -43,6 +58,18 @@ public class DInputField implements DComponent {
43 58
 		DStylePath path = parent.getChild("input", styleClass);
44 59
 		style = new DInputFieldStyle(context.getStylesheets().get(context, path));
45 60
 		fontMetrics = context.getFontMetrics(style.font);
61
+		dimensionPreferences.setValue(new DDimensionPreferences(
62
+				preferredWidth.evalInt(context) + style.paddingLeft + style.paddingRight + 2 * style.borderWidth,
63
+				fontMetrics.getAscent() + fontMetrics.getDescent() + style.paddingTop + style.paddingBottom + 2 * style.borderWidth));
64
+		
65
+		if (blinkTimer != null)
66
+			blinkTimer.close();
67
+		blinkTimer = context.setTimer(300, this::blink);
68
+	}
69
+	
70
+	private void blink() {
71
+		cursorBlink = !cursorBlink;
72
+		context.repaint(bounds);
46 73
 	}
47 74
 
48 75
 	@Override
@@ -54,6 +81,11 @@ public class DInputField implements DComponent {
54 81
 	public DIRectangle getBounds() {
55 82
 		return bounds;
56 83
 	}
84
+	
85
+	@Override
86
+	public int getBaselineY() {
87
+		return style.borderWidth + style.paddingTop + fontMetrics.getAscent();
88
+	}
57 89
 
58 90
 	@Override
59 91
 	public void setBounds(DIRectangle bounds) {
@@ -63,20 +95,129 @@ public class DInputField implements DComponent {
63 95
 	@Override
64 96
 	public void paint(DCanvas canvas) {
65 97
 		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
66
-		canvas.drawText(style.font, style.color, bounds.x + style.paddingLeft, bounds.y + style.paddingBottom, value.getValue());
98
+		if (style.borderWidth > 0) {
99
+			canvas.strokePath(
100
+					DPath.rectangle(bounds.x, bounds.y, bounds.width - style.borderWidth, bounds.height - style.borderWidth),
101
+					DTransform2D.IDENTITY,
102
+					style.borderColor,
103
+					style.borderWidth);
104
+		}
105
+		
106
+		int cursorXFrom = fontMetrics.getWidth(value.getValue(), 0, Math.min(cursorFrom, cursorTo));
107
+		int cursorXTo = fontMetrics.getWidth(value.getValue(), 0, Math.max(cursorFrom, cursorTo));
108
+		if (cursorFrom != cursorTo) {
109
+			canvas.fillRectangle(
110
+					bounds.x + style.paddingLeft + cursorXFrom,
111
+					bounds.y + style.paddingTop,
112
+					cursorXTo - cursorXFrom,
113
+					fontMetrics.getAscent() + fontMetrics.getDescent(),
114
+					style.selectionColor);
115
+		}
116
+		
117
+		canvas.drawText(style.font, style.color, bounds.x + style.paddingLeft + style.borderWidth, bounds.y + style.paddingBottom + style.borderWidth + fontMetrics.getAscent(), value.getValue());
118
+		
119
+		if (cursorBlink) {
120
+			canvas.fillRectangle(
121
+					bounds.x + style.paddingLeft + cursorXTo,
122
+					bounds.y + style.paddingTop,
123
+					style.cursorWidth,
124
+					fontMetrics.getAscent() + fontMetrics.getDescent(),
125
+					style.cursorColor);
126
+		}
67 127
 	}
68
-
128
+	
69 129
 	@Override
70
-	public void close() {
71
-		valueListener.close();
130
+	public void onMouseClick(DMouseEvent e) {
131
+		context.getWindow().focus(this);
72 132
 	}
73 133
 	
74 134
 	@Override
75
-	public void onMouseClick(DMouseEvent e) {
76
-		context.focus(this);
135
+	public void onKeyPressed(DKeyEvent e) {
136
+		boolean shift = e.has(DKeyEvent.SHIFT);
137
+		switch (e.keyCode) {
138
+			case UP:
139
+				setCursor(0, 0);
140
+				break;
141
+			case DOWN:
142
+				setCursor(value.getValue().length(), value.getValue().length());
143
+				break;
144
+			case LEFT: {
145
+				int to = Math.max(0, cursorTo - 1);
146
+				setCursor(shift ? cursorFrom : to, to);
147
+				break;
148
+			}
149
+			case RIGHT: {
150
+				int to = Math.min(value.getValue().length(), cursorTo + 1);
151
+				setCursor(shift ? cursorFrom : to, to);
152
+				break;
153
+			}
154
+			case DELETE:
155
+				delete();
156
+				break;
157
+			case BACKSPACE:
158
+				backspace();
159
+				break;
160
+			case ENTER:
161
+				enter();
162
+				break;
163
+			default:
164
+				if (e.character == DKeyEvent.CHAR_UNDEFINED)
165
+					return;
166
+				
167
+				insert(Character.toString(e.character));
168
+				break;
169
+		}
170
+	}
171
+	
172
+	private void setCursor(int from, int to) {
173
+		cursorFrom = from;
174
+		cursorTo = to;
175
+		context.repaint(bounds);
77 176
 	}
78 177
 	
79 178
 	private void handleValueUpdated(String newValue) {
179
+		context.repaint(bounds);
180
+	}
181
+	
182
+	private void backspace() {
183
+		if (cursorFrom == 0 && cursorTo == 0)
184
+			return;
185
+		
186
+		if (cursorFrom == cursorTo) {
187
+			value.setValue(value.getValue().substring(0, cursorFrom - 1) + value.getValue().substring(cursorFrom));
188
+			setCursor(cursorFrom - 1, cursorTo - 1);
189
+		} else {
190
+			int from = Math.min(cursorFrom, cursorTo);
191
+			int to = Math.max(cursorFrom, cursorTo);
192
+			setCursor(from, from);
193
+			value.setValue(value.getValue().substring(0, from) + value.getValue().substring(to));
194
+		}
195
+	}
196
+	
197
+	private void delete() {
198
+		if (cursorFrom == 0 && cursorTo == 0)
199
+			return;
200
+		
201
+		if (cursorFrom == cursorTo) {
202
+			if (cursorFrom < value.getValue().length()) {
203
+				value.setValue(value.getValue().substring(0, cursorFrom) + value.getValue().substring(cursorFrom + 1));
204
+			}
205
+		} else {
206
+			int from = Math.min(cursorFrom, cursorTo);
207
+			int to = Math.max(cursorFrom, cursorTo);
208
+			setCursor(from, from);
209
+			value.setValue(value.getValue().substring(0, from) + value.getValue().substring(to));
210
+		}
211
+	}
212
+	
213
+	private void insert(String value) {
214
+		int from = Math.min(cursorFrom, cursorTo);
215
+		int to = Math.max(cursorFrom, cursorTo);
216
+		this.value.setValue(this.value.getValue().substring(0, from) + value + this.value.getValue().substring(to));
217
+		setCursor(from + value.length(), from + value.length());
218
+	}
219
+	
220
+	private void enter() {
80 221
 		
81 222
 	}
82 223
 }

+ 8
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/DInputFieldStyle.java Переглянути файл

@@ -6,6 +6,7 @@
6 6
 package org.openzen.drawablegui;
7 7
 
8 8
 import org.openzen.drawablegui.style.DDpDimension;
9
+import org.openzen.drawablegui.style.DPxDimension;
9 10
 import org.openzen.drawablegui.style.DStyleDefinition;
10 11
 
11 12
 /**
@@ -19,6 +20,9 @@ public class DInputFieldStyle {
19 20
 	public final int paddingRight;
20 21
 	public final int paddingBottom;
21 22
 	
23
+	public final int borderWidth;
24
+	public final int borderColor;
25
+	
22 26
 	public final int color;
23 27
 	public final DFont font;
24 28
 	
@@ -28,12 +32,15 @@ public class DInputFieldStyle {
28 32
 	public final int selectionColor;
29 33
 	
30 34
 	public DInputFieldStyle(DStyleDefinition style) {
31
-		backgroundColor = style.getColor("backgroundColor", 0);
35
+		backgroundColor = style.getColor("backgroundColor", 0xFFFFFFFF);
32 36
 		paddingTop = style.getDimension("paddingTop", new DDpDimension(2));
33 37
 		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(2));
34 38
 		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(2));
35 39
 		paddingRight = style.getDimension("paddingRight", new DDpDimension(2));
36 40
 		
41
+		borderWidth = style.getDimension("borderWidth", new DPxDimension(1));
42
+		borderColor = style.getColor("borderColor", 0xFFABADB3);
43
+		
37 44
 		color = style.getColor("color", 0xFF000000);
38 45
 		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, (int)(14 * context.getScale())));
39 46
 		

+ 3
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/DMouseEvent.java Переглянути файл

@@ -19,13 +19,15 @@ public class DMouseEvent {
19 19
 	public static final int META = 2048;
20 20
 	public static final int ALT_GRAPH = 4096;
21 21
 	
22
+	public final DUIWindow window;
22 23
 	public final int x;
23 24
 	public final int y;
24 25
 	public final int modifiers;
25 26
 	public final int deltaZ;
26 27
 	public final int clickCount;
27 28
 	
28
-	public DMouseEvent(int x, int y, int modifiers, int deltaZ, int clickCount) {
29
+	public DMouseEvent(DUIWindow window, int x, int y, int modifiers, int deltaZ, int clickCount) {
30
+		this.window = window;
29 31
 		this.x = x;
30 32
 		this.y = y;
31 33
 		this.modifiers = modifiers;

+ 11
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DSideLayout.java Переглянути файл

@@ -70,6 +70,17 @@ public class DSideLayout extends BaseComponentGroup {
70 70
 	public DIRectangle getBounds() {
71 71
 		return bounds;
72 72
 	}
73
+	
74
+	@Override
75
+	public int getBaselineY() {
76
+		for (int i = sides.size() - 1; i >= 0; i--) {
77
+			SideComponent side = sides.get(i);
78
+			if (side.side == Side.TOP)
79
+				return side.component.getBaselineY();
80
+		}
81
+		
82
+		return main.getBaselineY();
83
+	}
73 84
 
74 85
 	@Override
75 86
 	public LiveObject<DDimensionPreferences> getDimensionPreferences() {

+ 7
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java Переглянути файл

@@ -5,7 +5,6 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
-import org.openzen.drawablegui.live.LiveObject;
9 8
 import org.openzen.drawablegui.style.DStyleSheets;
10 9
 
11 10
 /**
@@ -17,6 +16,8 @@ public interface DUIContext {
17 16
 	
18 17
 	float getScale();
19 18
 	
19
+	float getTextScale();
20
+	
20 21
 	void repaint(int x, int y, int width, int height);
21 22
 	
22 23
 	default void repaint(DIRectangle rectangle) {
@@ -25,8 +26,6 @@ public interface DUIContext {
25 26
 	
26 27
 	void setCursor(Cursor cursor);
27 28
 	
28
-	void focus(DComponent component);
29
-	
30 29
 	void scrollInView(int x, int y, int width, int height);
31 30
 	
32 31
 	DTimerHandle setTimer(int millis, Runnable target);
@@ -36,7 +35,11 @@ public interface DUIContext {
36 35
 	DFontMetrics getFontMetrics(DFont font);
37 36
 	
38 37
 	DUIWindow getWindow();
39
-		
38
+	
39
+	DUIWindow openDialog(int x, int y, DAnchor anchor, String title, DComponent root);
40
+	
41
+	DUIWindow openView(int x, int y, DAnchor anchor, DComponent root);
42
+	
40 43
 	enum Cursor {
41 44
 		NORMAL,
42 45
 		HAND,

+ 6
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DUIWindow.java Переглянути файл

@@ -13,6 +13,10 @@ import org.openzen.drawablegui.live.LiveObject;
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public interface DUIWindow {
16
+	DIRectangle getWindowBounds();
17
+	
18
+	DUIContext getContext();
19
+	
16 20
 	boolean hasTitleBar();
17 21
 	
18 22
 	void close();
@@ -27,6 +31,8 @@ public interface DUIWindow {
27 31
 	
28 32
 	LiveBool getActive();
29 33
 	
34
+	void focus(DComponent component);
35
+	
30 36
 	DUIWindow openModal(String title, DComponent root);
31 37
 	
32 38
 	enum State {

+ 272
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayout.java Переглянути файл

@@ -0,0 +1,272 @@
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.Consumer;
9
+import java.util.function.Predicate;
10
+import org.openzen.drawablegui.listeners.ListenerHandle;
11
+import org.openzen.drawablegui.live.LiveObject;
12
+import org.openzen.drawablegui.live.SimpleLiveObject;
13
+import org.openzen.drawablegui.style.DStyleClass;
14
+import org.openzen.drawablegui.style.DStylePath;
15
+
16
+/**
17
+ *
18
+ * @author Hoofdgebruiker
19
+ */
20
+public class DVerticalLayout extends BaseComponentGroup {
21
+	private final DStyleClass styleClass;
22
+	private final Alignment alignment;
23
+	private final Element[] components;
24
+	private final ListenerHandle<LiveObject.Listener<DDimensionPreferences>>[] componentSizeListeners;
25
+	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
26
+	
27
+	private DUIContext context;
28
+	private DHorizontalLayoutStyle style;
29
+	private DIRectangle bounds;
30
+	private float totalGrow;
31
+	private float totalShrink;
32
+	
33
+	public DVerticalLayout(DStyleClass styleClass, Alignment alignment, Element... components) {
34
+		this.styleClass = styleClass;
35
+		this.alignment = alignment;
36
+		this.components = components;
37
+		
38
+		componentSizeListeners = new ListenerHandle[components.length];
39
+		totalGrow = 0;
40
+		totalShrink = 0;
41
+		
42
+		for (int i = 0; i < componentSizeListeners.length; i++) {
43
+			componentSizeListeners[i] = components[i].component.getDimensionPreferences().addListener((oldValue, newValue) -> updateDimensionPreferences());
44
+			
45
+			totalGrow += components[i].grow;
46
+			totalShrink += components[i].shrink;
47
+		}
48
+	}
49
+
50
+	@Override
51
+	protected void forEachChild(Consumer<DComponent> children) {
52
+		for (Element element : components)
53
+			children.accept(element.component);
54
+	}
55
+
56
+	@Override
57
+	protected DComponent findChild(Predicate<DComponent> predicate) {
58
+		for (Element element : components)
59
+			if (predicate.test(element.component))
60
+				return element.component;
61
+		
62
+		return null;
63
+	}
64
+
65
+	@Override
66
+	public void setContext(DStylePath parent, DUIContext context) {
67
+		this.context = context;
68
+		
69
+		DStylePath path = parent.getChild("verticalLayout", styleClass);
70
+		style = new DHorizontalLayoutStyle(context.getStylesheets().get(context, path));
71
+		
72
+		for (Element element : components)
73
+			element.component.setContext(parent, context);
74
+		
75
+		layout();
76
+	}
77
+
78
+	@Override
79
+	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
80
+		return dimensionPreferences;
81
+	}
82
+
83
+	@Override
84
+	public DIRectangle getBounds() {
85
+		return bounds;
86
+	}
87
+
88
+	@Override
89
+	public int getBaselineY() {
90
+		return components[0].component.getBaselineY();
91
+	}
92
+
93
+	@Override
94
+	public void setBounds(DIRectangle bounds) {
95
+		this.bounds = bounds;
96
+	}
97
+
98
+	@Override
99
+	public void paint(DCanvas canvas) {
100
+		for (Element element : components) {
101
+			element.component.paint(canvas);
102
+		}
103
+	}
104
+
105
+	@Override
106
+	public void close() {
107
+		for (int i = 0; i < componentSizeListeners.length; i++) {
108
+			componentSizeListeners[i].close();
109
+		}
110
+	}
111
+	
112
+	public static enum Alignment {
113
+		TOP(0),
114
+		MIDDLE(0.5f),
115
+		BOTTOM(1);
116
+		
117
+		public final float align;
118
+		
119
+		Alignment(float align) {
120
+			this.align = align;
121
+		}
122
+	}
123
+	
124
+	public static enum ElementAlignment {
125
+		LEFT,
126
+		CENTER,
127
+		RIGHT,
128
+		STRETCH
129
+	}
130
+	
131
+	public static class Element {
132
+		public final DComponent component;
133
+		public final float grow;
134
+		public final float shrink;
135
+		public final ElementAlignment alignment;
136
+		
137
+		public Element(DComponent component, float grow, float shrink, ElementAlignment alignment) {
138
+			this.component = component;
139
+			this.grow = grow;
140
+			this.shrink = shrink;
141
+			this.alignment = alignment;
142
+		}
143
+	}
144
+	
145
+	private void layout() {
146
+		if (bounds == null || context == null)
147
+			return;
148
+		
149
+		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
150
+		if (bounds.height < myPreferences.preferredHeight) {
151
+			layoutShrinked();
152
+		} else {
153
+			layoutGrown();
154
+		}
155
+	}
156
+	
157
+	private void layoutShrinked() {
158
+		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
159
+		if (totalShrink == 0) {
160
+			// now what?
161
+			// shrink proportionally, we have to shrink...
162
+			float scale = (float)(bounds.height - (components.length - 1) * style.spacing) / (myPreferences.preferredHeight - (components.length - 1) * style.spacing);
163
+			int y = 0;
164
+			
165
+			for (int i = 0; i < components.length; i++) {
166
+				Element element = components[i];
167
+				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
168
+				int newY = y + preferences.preferredHeight;
169
+				float idealUnspacedY = newY * scale;
170
+				int idealY = (int)(idealUnspacedY + 0.5f + i * style.spacing);
171
+				layout(element, bounds.y + y, idealY - y);
172
+				y = idealY;
173
+			}
174
+		} else {
175
+			int delta = bounds.height - myPreferences.preferredHeight;
176
+			float deltaScaled = delta / totalShrink;
177
+			int y = bounds.y;
178
+			for (Element element : components) {
179
+				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
180
+				float scaledSize = preferences.preferredHeight + deltaScaled * element.shrink;
181
+				float idealUnspacedY = y + scaledSize;
182
+				int newY = (int)(idealUnspacedY + 0.5f);
183
+				layout(element, y, newY - y);
184
+				y = newY + style.spacing;
185
+			}
186
+		}
187
+	}
188
+	
189
+	private void layoutGrown() {
190
+		// resize according to grow values
191
+		DDimensionPreferences myPreferences = dimensionPreferences.getValue();
192
+		
193
+		if (totalGrow == 0) {
194
+			int deltaY = (int)(myPreferences.preferredHeight - bounds.height);
195
+			int y = bounds.y + (int)(deltaY * alignment.align);
196
+			for (Element element : components) {
197
+				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
198
+				int newY = y + preferences.preferredHeight;
199
+				layout(element, y, newY - y);
200
+				y = newY;
201
+			}
202
+		} else {
203
+			int delta = bounds.width - myPreferences.preferredWidth;
204
+			float deltaScaled = delta / totalGrow;
205
+			int y = bounds.y;
206
+			for (Element element : components) {
207
+				DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
208
+				float scaledSize = preferences.preferredHeight + deltaScaled * element.grow;
209
+				float idealUnspacedX = y + scaledSize;
210
+				int newY = (int)(idealUnspacedX + 0.5f);
211
+				layout(element, y, newY - y);
212
+				y = newY + style.spacing;
213
+			}
214
+		}
215
+	}
216
+	
217
+	private void layout(Element element, int y, int height) {
218
+		DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
219
+		int x;
220
+		int width;
221
+		switch (element.alignment) {
222
+			case LEFT:
223
+				width = Math.min(preferences.preferredWidth, bounds.width - style.paddingLeft - style.paddingRight);
224
+				x = bounds.x + style.paddingLeft;
225
+				break;
226
+			case CENTER:
227
+				width = Math.min(preferences.preferredWidth, bounds.width - style.paddingLeft - style.paddingRight);
228
+				x = bounds.x + style.paddingLeft + (bounds.width - style.paddingLeft - style.paddingRight - width) / 2;
229
+				break;
230
+			case RIGHT:
231
+				width = Math.min(preferences.preferredWidth, bounds.width - style.paddingLeft - style.paddingRight);
232
+				x = bounds.x + bounds.width - style.paddingLeft - width;
233
+				break;
234
+			case STRETCH:
235
+			default:
236
+				width = bounds.width - style.paddingLeft - style.paddingRight;
237
+				x = bounds.x + style.paddingLeft;
238
+				break;
239
+		}
240
+		element.component.setBounds(new DIRectangle(x, y, width, height));
241
+	}
242
+	
243
+	private void updateDimensionPreferences() {
244
+		int preferredWidth = 0;
245
+		int preferredHeight = -style.spacing;
246
+		int minimumWidth = 0;
247
+		int minimumHeight = -style.spacing;
248
+		int maximumWidth = Integer.MAX_VALUE;
249
+		int maximumHeight = -style.spacing;
250
+		
251
+		for (Element element : components) {
252
+			DDimensionPreferences preferences = element.component.getDimensionPreferences().getValue();
253
+			preferredWidth = Math.max(preferredWidth, preferences.preferredWidth);
254
+			preferredHeight += preferences.preferredHeight + style.spacing;
255
+			
256
+			minimumWidth = Math.max(minimumWidth, preferences.minimumWidth);
257
+			minimumHeight += preferences.minimumHeight + style.spacing;
258
+			
259
+			maximumWidth = Math.min(maximumWidth, preferences.maximumWidth);
260
+			maximumHeight += preferences.maximumHeight + style.spacing;
261
+		}
262
+		
263
+		DDimensionPreferences preferences = new DDimensionPreferences(
264
+				minimumWidth + style.paddingLeft + style.paddingRight,
265
+				minimumHeight + style.paddingTop + style.paddingBottom,
266
+				preferredWidth + style.paddingLeft + style.paddingRight,
267
+				preferredHeight + style.paddingTop + style.paddingBottom,
268
+				maximumWidth + style.paddingLeft + style.paddingRight,
269
+				maximumHeight + style.paddingTop + style.paddingBottom);
270
+		dimensionPreferences.setValue(preferences);
271
+	}
272
+}

+ 31
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DVerticalLayoutStyle.java Переглянути файл

@@ -0,0 +1,31 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.style.DDpDimension;
9
+import org.openzen.drawablegui.style.DStyleDefinition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class DVerticalLayoutStyle {
16
+	public final int spacing;
17
+	
18
+	public final int paddingTop;
19
+	public final int paddingLeft;
20
+	public final int paddingRight;
21
+	public final int paddingBottom;
22
+	
23
+	public DVerticalLayoutStyle(DStyleDefinition style) {
24
+		spacing = style.getDimension("spacing", new DDpDimension(8));
25
+		
26
+		paddingTop = style.getDimension("paddingTop", new DDpDimension(8));
27
+		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(8));
28
+		paddingRight = style.getDimension("paddingRight", new DDpDimension(8));
29
+		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(8));
30
+	}
31
+}

+ 6
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/border/DCustomWindowBorder.java Переглянути файл

@@ -72,6 +72,12 @@ public class DCustomWindowBorder implements DComponent {
72 72
 	public DIRectangle getBounds() {
73 73
 		return bounds;
74 74
 	}
75
+	
76
+	@Override
77
+	public int getBaselineY() {
78
+		int contentBaseline = content.getBaselineY();
79
+		return contentBaseline == -1 ? -1 : style.padding + style.borderWidth + contentBaseline;
80
+	}
75 81
 
76 82
 	@Override
77 83
 	public void setBounds(DIRectangle bounds) {

+ 49
- 12
DrawableGui/src/main/java/org/openzen/drawablegui/form/DForm.java Переглянути файл

@@ -5,6 +5,9 @@
5 5
  */
6 6
 package org.openzen.drawablegui.form;
7 7
 
8
+import java.util.function.Consumer;
9
+import java.util.function.Predicate;
10
+import org.openzen.drawablegui.BaseComponentGroup;
8 11
 import org.openzen.drawablegui.DCanvas;
9 12
 import org.openzen.drawablegui.DComponent;
10 13
 import org.openzen.drawablegui.DDimensionPreferences;
@@ -20,7 +23,7 @@ import org.openzen.drawablegui.style.DStylePath;
20 23
  *
21 24
  * @author Hoofdgebruiker
22 25
  */
23
-public class DForm implements DComponent {
26
+public class DForm extends BaseComponentGroup {
24 27
 	private final DFormComponent[] components;
25 28
 	private final DStyleClass styleClass;
26 29
 	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
@@ -29,6 +32,8 @@ public class DForm implements DComponent {
29 32
 	private DUIContext context;
30 33
 	private DFormStyle style;
31 34
 	private DFontMetrics fontMetrics;
35
+	private int maxFieldWidth;
36
+	private int maxLabelWidth;
32 37
 	
33 38
 	public DForm(DStyleClass styleClass, DFormComponent... components) {
34 39
 		this.styleClass = styleClass;
@@ -46,13 +51,13 @@ public class DForm implements DComponent {
46 51
 			component.component.setContext(path, context);
47 52
 		
48 53
 		int height = style.paddingBottom + style.paddingTop;
49
-		int maxTextWidth = style.minimumLabelSize;
50
-		int maxComponentWidth = style.minimumFieldSize;
54
+		int maxLabelWidth = style.minimumLabelSize;
55
+		int maxFieldWidth = style.minimumFieldSize;
51 56
 		
52 57
 		for (DFormComponent component : components) {
53
-			maxTextWidth = Math.max(maxTextWidth, fontMetrics.getWidth(component.label));
58
+			maxLabelWidth = Math.max(maxLabelWidth, fontMetrics.getWidth(component.label));
54 59
 			int componentWidth = component.component.getDimensionPreferences().getValue().preferredWidth;
55
-			maxComponentWidth = Math.max(maxComponentWidth, componentWidth);
60
+			maxFieldWidth = Math.max(maxFieldWidth, componentWidth);
56 61
 		}
57 62
 		
58 63
 		for (DFormComponent component : components) {
@@ -60,7 +65,12 @@ public class DForm implements DComponent {
60 65
 			height += style.spacing;
61 66
 		}
62 67
 		
63
-		preferences.setValue(new DDimensionPreferences(maxTextWidth + maxComponentWidth, height));
68
+		this.maxFieldWidth = maxFieldWidth;
69
+		this.maxLabelWidth = maxLabelWidth;
70
+		preferences.setValue(new DDimensionPreferences(maxLabelWidth + maxFieldWidth + style.paddingLeft + style.paddingRight + style.spacing, height));
71
+		
72
+		if (bounds != null)
73
+			layout();
64 74
 	}
65 75
 
66 76
 	@Override
@@ -72,17 +82,33 @@ public class DForm implements DComponent {
72 82
 	public DIRectangle getBounds() {
73 83
 		return bounds;
74 84
 	}
85
+	
86
+	@Override
87
+	public int getBaselineY() {
88
+		int contentBaseline = components[0].component.getBaselineY();
89
+		return contentBaseline == -1 ? -1 : contentBaseline + style.paddingTop;
90
+	}
75 91
 
76 92
 	@Override
77 93
 	public void setBounds(DIRectangle bounds) {
78 94
 		this.bounds = bounds;
79
-		layout();
95
+		
96
+		if (context != null)
97
+			layout();
80 98
 	}
81 99
 
82 100
 	@Override
83 101
 	public void paint(DCanvas canvas) {
102
+		int x = style.paddingLeft;
103
+		int y = style.paddingTop;
84 104
 		for (DFormComponent component : components) {
105
+			int baseline = component.component.getBaselineY();
106
+			if (baseline == -1)
107
+				baseline = fontMetrics.getAscent();
108
+			canvas.drawText(style.labelFont, style.labelColor, x, y + baseline, component.label);
109
+			component.component.paint(canvas);
85 110
 			
111
+			y += component.component.getDimensionPreferences().getValue().preferredHeight + style.spacing;
86 112
 		}
87 113
 	}
88 114
 
@@ -94,17 +120,28 @@ public class DForm implements DComponent {
94 120
 	private void layout() {
95 121
 		int x = bounds.x + style.paddingLeft;
96 122
 		int y = bounds.y + style.paddingBottom;
97
-		int maxTextWidth = style.minimumLabelSize;
98
-		
99
-		for (DFormComponent component : components)
100
-			maxTextWidth = Math.max(maxTextWidth, fontMetrics.getWidth(component.label));
101 123
 		
102 124
 		for (DFormComponent component : components) {
103 125
 			int preferredHeight = component.component.getDimensionPreferences().getValue().preferredHeight;
104
-			DIRectangle componentBounds = new DIRectangle(x + maxTextWidth, y, bounds.width - maxTextWidth, preferredHeight);
126
+			DIRectangle componentBounds = new DIRectangle(x + maxLabelWidth, y, bounds.width - maxLabelWidth - style.paddingLeft - style.paddingRight - style.spacing, preferredHeight);
105 127
 			component.component.setBounds(componentBounds);
106 128
 			
107 129
 			y += preferredHeight + style.spacing;
108 130
 		}
109 131
 	}
132
+
133
+	@Override
134
+	protected void forEachChild(Consumer<DComponent> children) {
135
+		for (DFormComponent component : components)
136
+			children.accept(component.component);
137
+	}
138
+
139
+	@Override
140
+	protected DComponent findChild(Predicate<DComponent> predicate) {
141
+		for (DFormComponent component : components)
142
+			if (predicate.test(component.component))
143
+				return component.component;
144
+		
145
+		return null;
146
+	}
110 147
 }

+ 2
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/form/DFormStyle.java Переглянути файл

@@ -8,6 +8,7 @@ package org.openzen.drawablegui.form;
8 8
 import org.openzen.drawablegui.DFont;
9 9
 import org.openzen.drawablegui.DFontFamily;
10 10
 import org.openzen.drawablegui.style.DDpDimension;
11
+import org.openzen.drawablegui.style.DPxDimension;
11 12
 import org.openzen.drawablegui.style.DStyleDefinition;
12 13
 
13 14
 /**
@@ -34,7 +35,7 @@ public class DFormStyle {
34 35
 		spacing = style.getDimension("spacing", new DDpDimension(8));
35 36
 		
36 37
 		labelColor = style.getColor("labelColor", 0xFF000000);
37
-		labelFont = style.getFont("labelFont", context -> new DFont(DFontFamily.UI, false, false, false, (int)(16 * context.getScale())));
38
+		labelFont = style.getFont("labelFont", context -> new DFont(DFontFamily.UI, false, false, false, (int)(14 * context.getScale())));
38 39
 		minimumLabelSize = style.getDimension("minimumLabelSize", new DDpDimension(150));
39 40
 		minimumFieldSize = style.getDimension("minimumFieldSize", new DDpDimension(150));
40 41
 	}

+ 5
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollBar.java Переглянути файл

@@ -69,6 +69,11 @@ public class DScrollBar implements DComponent {
69 69
 	public DIRectangle getBounds() {
70 70
 		return bounds;
71 71
 	}
72
+	
73
+	@Override
74
+	public int getBaselineY() {
75
+		return -1;
76
+	}
72 77
 
73 78
 	@Override
74 79
 	public void setBounds(DIRectangle bounds) {

+ 22
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java Переглянути файл

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.drawablegui.scroll;
7 7
 
8
+import org.openzen.drawablegui.DAnchor;
8 9
 import org.openzen.drawablegui.DCanvas;
9 10
 import org.openzen.drawablegui.DClipboard;
10 11
 import org.openzen.drawablegui.DComponent;
@@ -101,6 +102,11 @@ public class DScrollPane implements DComponent {
101 102
 	public DIRectangle getBounds() {
102 103
 		return bounds;
103 104
 	}
105
+	
106
+	@Override
107
+	public int getBaselineY() {
108
+		return -1;
109
+	}
104 110
 
105 111
 	@Override
106 112
 	public void setBounds(DIRectangle bounds) {
@@ -225,6 +231,7 @@ public class DScrollPane implements DComponent {
225 231
 	
226 232
 	private DMouseEvent translateMouseEvent(DMouseEvent e) {
227 233
 		return new DMouseEvent(
234
+				e.window,
228 235
 				e.x - bounds.x + offsetX.getValue(),
229 236
 				e.y - bounds.y + offsetY.getValue(),
230 237
 				e.modifiers,
@@ -243,6 +250,11 @@ public class DScrollPane implements DComponent {
243 250
 		public float getScale() {
244 251
 			return context.getScale();
245 252
 		}
253
+		
254
+		@Override
255
+		public float getTextScale() {
256
+			return context.getTextScale();
257
+		}
246 258
 
247 259
 		@Override
248 260
 		public void repaint(int x, int y, int width, int height) {
@@ -272,11 +284,6 @@ public class DScrollPane implements DComponent {
272 284
 			return context.getFontMetrics(font);
273 285
 		}
274 286
 
275
-		@Override
276
-		public void focus(DComponent component) {
277
-			context.focus(component);
278
-		}
279
-
280 287
 		@Override
281 288
 		public void scrollInView(int x, int y, int width, int height) {
282 289
 			if (y < offsetY.getValue())
@@ -299,6 +306,16 @@ public class DScrollPane implements DComponent {
299 306
 		public DUIWindow getWindow() {
300 307
 			return context.getWindow();
301 308
 		}
309
+
310
+		@Override
311
+		public DUIWindow openDialog(int x, int y, DAnchor anchor, String title, DComponent root) {
312
+			return context.openDialog(x, y, anchor, title, root);
313
+		}
314
+
315
+		@Override
316
+		public DUIWindow openView(int x, int y, DAnchor anchor, DComponent root) {
317
+			return context.openView(x, y, anchor, root);
318
+		}
302 319
 	}
303 320
 	
304 321
 	private class ScrollListener implements LiveInt.Listener {

+ 25
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/style/DSpDimension.java Переглянути файл

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

+ 191
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingDialog.java Переглянути файл

@@ -0,0 +1,191 @@
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.swing;
7
+
8
+import java.awt.BorderLayout;
9
+import java.awt.Color;
10
+import java.awt.event.WindowEvent;
11
+import java.awt.event.WindowListener;
12
+import java.awt.event.WindowStateListener;
13
+import javax.swing.JDialog;
14
+import javax.swing.JFrame;
15
+import org.openzen.drawablegui.DComponent;
16
+import org.openzen.drawablegui.DDimensionPreferences;
17
+import org.openzen.drawablegui.DIRectangle;
18
+import org.openzen.drawablegui.DUIContext;
19
+import org.openzen.drawablegui.DUIWindow;
20
+import org.openzen.drawablegui.border.DCustomWindowBorder;
21
+import org.openzen.drawablegui.live.LiveBool;
22
+import org.openzen.drawablegui.live.LiveObject;
23
+import org.openzen.drawablegui.live.SimpleLiveBool;
24
+import org.openzen.drawablegui.live.SimpleLiveObject;
25
+import org.openzen.drawablegui.style.DStyleClass;
26
+
27
+/**
28
+ *
29
+ * @author Hoofdgebruiker
30
+ */
31
+public final class SwingDialog extends JDialog implements WindowListener, WindowStateListener, DUIWindow {
32
+	public final SwingRoot swingComponent;
33
+	private final boolean noTitleBar;
34
+	private final SimpleLiveObject<State> state = new SimpleLiveObject<>(State.NORMAL);
35
+	private final SimpleLiveBool active = new SimpleLiveBool(true);
36
+	
37
+	public SwingDialog(SwingWindow owner, String title, DComponent root, boolean noTitleBar) {
38
+		super(owner, title);
39
+		this.noTitleBar = noTitleBar;
40
+		
41
+		if (noTitleBar) {
42
+		    setUndecorated(true);
43
+			root = new DCustomWindowBorder(DStyleClass.EMPTY, root);
44
+			setBackground(new Color(0, 0, 0, 0));
45
+		}
46
+		
47
+		addWindowListener(this);
48
+		addWindowStateListener(this);
49
+		
50
+		getContentPane().add(swingComponent = new SwingRoot(root), BorderLayout.CENTER);
51
+		swingComponent.setWindow(this);
52
+		swingComponent.requestFocusInWindow();
53
+	}
54
+	
55
+	public SwingDialog(SwingDialog owner, String title, DComponent root, boolean noTitleBar) {
56
+		super(owner, title);
57
+		this.noTitleBar = noTitleBar;
58
+		
59
+		if (noTitleBar) {
60
+		    setUndecorated(true);
61
+			root = new DCustomWindowBorder(DStyleClass.EMPTY, root);
62
+			setBackground(new Color(0, 0, 0, 0));
63
+		}
64
+		
65
+		addWindowListener(this);
66
+		addWindowStateListener(this);
67
+		
68
+		getContentPane().add(swingComponent = new SwingRoot(root), BorderLayout.CENTER);
69
+		swingComponent.setWindow(this);
70
+		swingComponent.requestFocusInWindow();
71
+	}
72
+	
73
+	@Override
74
+	public DUIContext getContext() {
75
+		return swingComponent.context;
76
+	}
77
+
78
+	@Override
79
+	public DIRectangle getWindowBounds() {
80
+		return new DIRectangle(getX(), getY(), getWidth(), getHeight());
81
+	}
82
+
83
+	@Override
84
+	public boolean hasTitleBar() {
85
+		return !noTitleBar;
86
+	}
87
+
88
+	@Override
89
+	public void close() {
90
+		System.exit(0);
91
+	}
92
+
93
+	@Override
94
+	public void maximize() {
95
+		// cannot maximize
96
+	}
97
+
98
+	@Override
99
+	public void restore() {
100
+		// cannot restore
101
+	}
102
+
103
+	@Override
104
+	public void minimize() {
105
+		// TODO
106
+	}
107
+
108
+	@Override
109
+	public LiveObject<State> getWindowState() {
110
+		return state;
111
+	}
112
+	
113
+	@Override
114
+	public LiveBool getActive() {
115
+		return active;
116
+	}
117
+	
118
+	@Override
119
+	public void focus(DComponent component) {
120
+		swingComponent.focus(component);
121
+	}
122
+	
123
+	@Override
124
+	public DUIWindow openModal(String title, DComponent component) {
125
+		SwingDialog result = new SwingDialog(this, title, component, false);
126
+		result.setResizable(false);
127
+		
128
+		DDimensionPreferences size = component.getDimensionPreferences().getValue();
129
+		result.setLocation(
130
+				getX() + (getWidth() - size.preferredWidth) / 2,
131
+				getY() + (getHeight() - size.preferredHeight) / 2);
132
+		result.setSize(size.preferredWidth, size.preferredHeight);
133
+		return result;
134
+	}
135
+
136
+	@Override
137
+	public void windowOpened(WindowEvent e) {
138
+		
139
+	}
140
+
141
+	@Override
142
+	public void windowClosing(WindowEvent e) {
143
+		
144
+	}
145
+
146
+	@Override
147
+	public void windowClosed(WindowEvent e) {
148
+		
149
+	}
150
+
151
+	@Override
152
+	public void windowIconified(WindowEvent e) {
153
+		
154
+	}
155
+
156
+	@Override
157
+	public void windowDeiconified(WindowEvent e) {
158
+		
159
+	}
160
+
161
+	@Override
162
+	public void windowActivated(WindowEvent e) {
163
+		active.setValue(true);
164
+	}
165
+
166
+	@Override
167
+	public void windowDeactivated(WindowEvent e) {
168
+		active.setValue(false);
169
+	}
170
+
171
+	@Override
172
+	public void windowStateChanged(WindowEvent e) {
173
+		state.setValue(getStateFromWindowState());
174
+	}
175
+	
176
+	private State getStateFromWindowState() {
177
+		/*switch (ge()) {
178
+			case NORMAL:
179
+				return State.NORMAL;
180
+			case ICONIFIED:
181
+				return State.MINIMIZED;
182
+			case MAXIMIZED_HORIZ:
183
+			case MAXIMIZED_VERT:
184
+			case MAXIMIZED_BOTH:
185
+				return State.MAXIMIZED;
186
+			default:
187
+				return State.NORMAL;
188
+		}*/
189
+		return State.NORMAL;
190
+	}
191
+}

+ 56
- 6
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java Переглянути файл

@@ -5,13 +5,17 @@
5 5
  */
6 6
 package org.openzen.drawablegui.swing;
7 7
 
8
+import java.awt.Dimension;
8 9
 import java.awt.Font;
9 10
 import java.awt.Graphics;
10 11
 import java.awt.geom.GeneralPath;
11 12
 import java.util.WeakHashMap;
13
+import javax.swing.JFrame;
12 14
 import javax.swing.Timer;
15
+import org.openzen.drawablegui.DAnchor;
13 16
 import org.openzen.drawablegui.DClipboard;
14 17
 import org.openzen.drawablegui.DComponent;
18
+import org.openzen.drawablegui.DDimensionPreferences;
15 19
 import org.openzen.drawablegui.DPath;
16 20
 import org.openzen.drawablegui.DFont;
17 21
 import org.openzen.drawablegui.DFontMetrics;
@@ -19,6 +23,7 @@ import org.openzen.drawablegui.DPathTracer;
19 23
 import org.openzen.drawablegui.DTimerHandle;
20 24
 import org.openzen.drawablegui.DUIContext;
21 25
 import org.openzen.drawablegui.DUIWindow;
26
+import org.openzen.drawablegui.style.DStylePathRoot;
22 27
 import org.openzen.drawablegui.style.DStyleSheets;
23 28
 
24 29
 /**
@@ -28,15 +33,17 @@ import org.openzen.drawablegui.style.DStyleSheets;
28 33
 public class SwingGraphicsContext implements DUIContext {
29 34
 	private final DStyleSheets stylesheets;
30 35
 	private final float scale;
36
+	private final float textScale;
31 37
 	private final WeakHashMap<DPath, GeneralPath> preparedPaths = new WeakHashMap<>();
32 38
 	private final SwingRoot root;
33 39
 	private final JavaClipboard clipboard = new JavaClipboard();
34 40
 	private Graphics graphics;
35 41
 	private DUIWindow window;
36 42
 	
37
-	public SwingGraphicsContext(DStyleSheets stylesheets, float scale, SwingRoot root) {
43
+	public SwingGraphicsContext(DStyleSheets stylesheets, float scale, float textScale, SwingRoot root) {
38 44
 		this.stylesheets = stylesheets;
39 45
 		this.scale = scale;
46
+		this.textScale = textScale;
40 47
 		this.root = root;
41 48
 	}
42 49
 	
@@ -64,6 +71,11 @@ public class SwingGraphicsContext implements DUIContext {
64 71
 		return scale;
65 72
 	}
66 73
 	
74
+	@Override
75
+	public float getTextScale() {
76
+		return textScale;
77
+	}
78
+	
67 79
 	@Override
68 80
 	public void repaint(int x, int y, int width, int height) {
69 81
 		root.repaint(x, y, width, height);
@@ -106,14 +118,12 @@ public class SwingGraphicsContext implements DUIContext {
106 118
 		if (graphics == null)
107 119
 			graphics = root.getGraphics();
108 120
 		
121
+		if (graphics == null)
122
+			throw new AssertionError("No graphics available!");
123
+		
109 124
 		SwingCanvas.prepare(font);
110 125
 		return new SwingFontMetrics(graphics.getFontMetrics((Font) font.cached), graphics);
111 126
 	}
112
-	
113
-	@Override
114
-	public void focus(DComponent component) {
115
-		this.root.focus(component);
116
-	}
117 127
 
118 128
 	@Override
119 129
 	public void scrollInView(int x, int y, int width, int height) {
@@ -136,6 +146,46 @@ public class SwingGraphicsContext implements DUIContext {
136 146
 	public DUIWindow getWindow() {
137 147
 		return window;
138 148
 	}
149
+
150
+	@Override
151
+	public DUIWindow openDialog(int x, int y, DAnchor anchor, String title, DComponent root) {
152
+		SwingDialog window = new SwingDialog((SwingWindow)this.window, title, root, false);
153
+		SwingGraphicsContext windowContext = new SwingGraphicsContext(stylesheets, scale, textScale, window.swingComponent);
154
+		windowContext.setWindow(window);
155
+		windowContext.graphics = this.graphics; // help a little...
156
+		
157
+		root.setContext(DStylePathRoot.INSTANCE, windowContext);
158
+		DDimensionPreferences dimension = root.getDimensionPreferences().getValue();
159
+		int tx = (int)(x - anchor.alignX * dimension.preferredWidth);
160
+		int ty = (int)(y - anchor.alignY * dimension.preferredHeight);
161
+		
162
+		window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
163
+		window.swingComponent.setPreferredSize(new Dimension(dimension.preferredWidth, dimension.preferredHeight));
164
+		window.setLocation(tx, ty);
165
+		window.pack();
166
+		window.setVisible(true);
167
+		return window;
168
+	}
169
+
170
+	@Override
171
+	public DUIWindow openView(int x, int y, DAnchor anchor, DComponent root) {
172
+		SwingDialog window = new SwingDialog((SwingWindow)this.window, "", root, false);
173
+		SwingGraphicsContext windowContext = new SwingGraphicsContext(stylesheets, scale, textScale, window.swingComponent);
174
+		windowContext.setWindow(window);
175
+		windowContext.graphics = this.graphics; // help a little...
176
+		
177
+		root.setContext(DStylePathRoot.INSTANCE, windowContext);
178
+		DDimensionPreferences dimension = root.getDimensionPreferences().getValue();
179
+		int tx = (int)(x - anchor.alignX * dimension.preferredWidth);
180
+		int ty = (int)(y - anchor.alignY * dimension.preferredHeight);
181
+		
182
+		window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
183
+		window.swingComponent.setPreferredSize(new Dimension(dimension.preferredWidth, dimension.preferredHeight));
184
+		window.setLocation(tx, ty);
185
+		window.pack();
186
+		window.setVisible(true);
187
+		return window;
188
+	}
139 189
 	
140 190
 	private class PathTracer implements DPathTracer {
141 191
 		private final GeneralPath path;

+ 5
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java Переглянути файл

@@ -46,8 +46,9 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
46 46
 		context = new SwingGraphicsContext(
47 47
 				DEmptyStylesheets.INSTANCE,
48 48
 				Toolkit.getDefaultToolkit().getScreenResolution() / 96.0f,
49
+				Toolkit.getDefaultToolkit().getScreenResolution() / 96.0f,
49 50
 				this);
50
-		component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
51
+		
51 52
 		addComponentListener(this);
52 53
 		addMouseListener(this);
53 54
 		addMouseMotionListener(this);
@@ -75,6 +76,7 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
75 76
 		if (firstPaint) {
76 77
 			firstPaint = false;
77 78
 			component.setContext(DStylePathRoot.INSTANCE, context);
79
+			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
78 80
 		}
79 81
 		
80 82
 		Rectangle clipBounds = g.getClipBounds();
@@ -172,11 +174,11 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
172 174
 	}
173 175
 
174 176
 	private DMouseEvent translateMouseEvent(MouseEvent e) {
175
-		return new DMouseEvent(e.getX(), e.getY(), getModifiers(e.getModifiersEx()), 0, e.getClickCount());
177
+		return new DMouseEvent(context.getWindow(), e.getX(), e.getY(), getModifiers(e.getModifiersEx()), 0, e.getClickCount());
176 178
 	}
177 179
 
178 180
 	private DMouseEvent translateScrollEvent(MouseWheelEvent e) {
179
-		return new DMouseEvent(e.getX(), e.getY(), getModifiers(e.getModifiersEx()), e.getUnitsToScroll(), e.getClickCount());
181
+		return new DMouseEvent(context.getWindow(), e.getX(), e.getY(), getModifiers(e.getModifiersEx()), e.getUnitsToScroll(), e.getClickCount());
180 182
 	}
181 183
 	
182 184
 	private DKeyEvent translateKeyEvent(KeyEvent e) {

+ 12
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java Переглянути файл

@@ -13,6 +13,7 @@ import java.awt.event.WindowStateListener;
13 13
 import javax.swing.JFrame;
14 14
 import org.openzen.drawablegui.DComponent;
15 15
 import org.openzen.drawablegui.DDimensionPreferences;
16
+import org.openzen.drawablegui.DIRectangle;
16 17
 import org.openzen.drawablegui.DUIContext;
17 18
 import org.openzen.drawablegui.DUIWindow;
18 19
 import org.openzen.drawablegui.border.DCustomWindowBorder;
@@ -50,10 +51,16 @@ public final class SwingWindow extends JFrame implements WindowListener, WindowS
50 51
 		swingComponent.requestFocusInWindow();
51 52
 	}
52 53
 	
54
+	@Override
53 55
 	public DUIContext getContext() {
54 56
 		return swingComponent.context;
55 57
 	}
56 58
 
59
+	@Override
60
+	public DIRectangle getWindowBounds() {
61
+		return new DIRectangle(getX(), getY(), getWidth(), getHeight());
62
+	}
63
+
57 64
 	@Override
58 65
 	public boolean hasTitleBar() {
59 66
 		return !noTitleBar;
@@ -89,6 +96,11 @@ public final class SwingWindow extends JFrame implements WindowListener, WindowS
89 96
 		return active;
90 97
 	}
91 98
 	
99
+	@Override
100
+	public void focus(DComponent component) {
101
+		swingComponent.focus(component);
102
+	}
103
+	
92 104
 	@Override
93 105
 	public DUIWindow openModal(String title, DComponent component) {
94 106
 		SwingWindow result = new SwingWindow(title, component, false);

+ 5
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/tree/DTreeView.java Переглянути файл

@@ -67,6 +67,11 @@ public class DTreeView<N extends DTreeNode<N>> implements DComponent {
67 67
 	public DIRectangle getBounds() {
68 68
 		return bounds;
69 69
 	}
70
+	
71
+	@Override
72
+	public int getBaselineY() {
73
+		return -1;
74
+	}
70 75
 
71 76
 	@Override
72 77
 	public void setBounds(DIRectangle bounds) {

+ 33
- 0
IDE/src/main/java/org/openzen/zenscript/ide/Arguments.java Переглянути файл

@@ -0,0 +1,33 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide;
7
+
8
+import java.io.File;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class Arguments {
15
+	public final File projectDirectory;
16
+	
17
+	public Arguments(String[] arguments) {
18
+		File projectDir = new File("../../ZenCode"); // TODO: remove this and open a project chooser/creator instead
19
+		int positional = 0;
20
+		for (int i = 0; i < arguments.length; i++) {
21
+			switch (positional) {
22
+				case 0:
23
+					projectDir = new File(arguments[0]);
24
+					break;
25
+				default:
26
+					throw new IllegalArgumentException("Too many arguments");
27
+			}
28
+			positional++;
29
+		}
30
+		
31
+		this.projectDirectory = projectDir;
32
+	}
33
+}

+ 4
- 1
IDE/src/main/java/org/openzen/zenscript/ide/Main.java Переглянути файл

@@ -2,6 +2,7 @@ package org.openzen.zenscript.ide;
2 2
 
3 3
 import java.io.File;
4 4
 import java.io.IOException;
5
+import java.util.Arrays;
5 6
 import javax.swing.JFrame;
6 7
 import org.openzen.zenscript.ide.host.DevelopmentHost;
7 8
 import org.openzen.zenscript.ide.host.local.LocalProjectDevelopmentHost;
@@ -17,7 +18,9 @@ public class Main {
17 18
      * @param args the command line arguments
18 19
      */
19 20
     public static void main(String[] args) throws IOException {
20
-		File directory = new File("../../ZenCode");
21
+		Arguments arguments = new Arguments(args);
22
+		File directory = arguments.projectDirectory;
23
+		
21 24
 		CompilationUnit compilationUnit = new CompilationUnit();
22 25
 		ModuleLoader loader = new ModuleLoader(compilationUnit);
23 26
 		Project project = new Project(loader, directory);

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEAspectBar.java Переглянути файл

@@ -15,6 +15,6 @@ import org.openzen.drawablegui.live.SimpleLiveObject;
15 15
  * @author Hoofdgebruiker
16 16
  */
17 17
 public class IDEAspectBar {
18
-	public final LiveList<IDEAspectToolbar> toolbars = new LiveArrayList<>(); // TODO: only expose read-only variant
18
+	public final LiveList<IDEAspectToolbar> toolbars = new LiveArrayList<>();
19 19
 	public final LiveObject<IDEAspectToolbar> active = new SimpleLiveObject<>(null);
20 20
 }

+ 63
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java Переглянути файл

@@ -5,8 +5,25 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui;
7 7
 
8
+import org.openzen.drawablegui.DAnchor;
9
+import org.openzen.drawablegui.DComponent;
10
+import org.openzen.drawablegui.DEmptyView;
11
+import org.openzen.drawablegui.DIRectangle;
12
+import org.openzen.drawablegui.DInputField;
13
+import org.openzen.drawablegui.DUIWindow;
14
+import org.openzen.drawablegui.form.DForm;
15
+import org.openzen.drawablegui.form.DFormComponent;
16
+import org.openzen.drawablegui.live.LiveBool;
17
+import org.openzen.drawablegui.live.LiveObject;
18
+import org.openzen.drawablegui.live.LivePredicateBool;
19
+import org.openzen.drawablegui.live.SimpleLiveBool;
20
+import org.openzen.drawablegui.live.SimpleLiveObject;
21
+import org.openzen.drawablegui.live.SimpleLiveString;
22
+import org.openzen.drawablegui.style.DDpDimension;
8 23
 import org.openzen.drawablegui.style.DStyleClass;
9 24
 import org.openzen.zenscript.ide.host.DevelopmentHost;
25
+import org.openzen.zenscript.ide.host.IDEModule;
26
+import org.openzen.zenscript.ide.host.IDEPackage;
10 27
 import org.openzen.zenscript.ide.host.IDESourceFile;
11 28
 import org.openzen.zenscript.ide.host.IDETarget;
12 29
 import org.openzen.zenscript.ide.ui.icons.AddBoxIcon;
@@ -29,6 +46,11 @@ public class IDEWindow {
29 46
 	
30 47
 	public IDEAspectToolbar projectToolbar;
31 48
 	
49
+	private final LiveObject<IDEModule> contextModule = new SimpleLiveObject<>(null);
50
+	private final LiveObject<IDEPackage> contextPackage = new SimpleLiveObject<>(null);
51
+	private final LiveObject<IDESourceFile> contextFile = new SimpleLiveObject<>(null);
52
+	private final LiveBool addContentDisabled = new LivePredicateBool(contextPackage, pkg -> pkg == null);
53
+	
32 54
 	public IDEWindow(DevelopmentHost host) {
33 55
 		this.host = host;
34 56
 		
@@ -53,8 +75,29 @@ public class IDEWindow {
53 75
 	
54 76
 	private void init() {
55 77
 		projectToolbar = new IDEAspectToolbar(0, ShadedProjectIcon.PURPLE, "Project", "Project management");
56
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.ORANGE, e -> {}));
57
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, SettingsIcon.PURPLE, e -> {}));
78
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.BLUE, AddBoxIcon.GRAY, addContentDisabled, e -> {
79
+			DComponent input = new DInputField(DStyleClass.EMPTY, new SimpleLiveString(""), new DDpDimension(100));
80
+			DForm root = new DForm(DStyleClass.EMPTY, new DFormComponent("Package name:", input));
81
+			
82
+			DUIWindow window = e.window;
83
+			DIRectangle rectangle = window.getWindowBounds();
84
+			DUIWindow newWindow = e.window.getContext().openDialog(rectangle.getCenterX(), rectangle.getCenterY(), DAnchor.MIDDLE_LEFT, "Create package", root);
85
+			
86
+			newWindow.focus(input);
87
+		}));
88
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.ORANGE, AddBoxIcon.GRAY, addContentDisabled, e -> {
89
+			DComponent input = new DInputField(DStyleClass.EMPTY, new SimpleLiveString(""), new DDpDimension(100));
90
+			DForm root = new DForm(DStyleClass.EMPTY, new DFormComponent("Filename:", input));
91
+			
92
+			DUIWindow window = e.window;
93
+			DIRectangle rectangle = window.getWindowBounds();
94
+			DUIWindow newWindow = e.window.getContext().openDialog(rectangle.getCenterX(), rectangle.getCenterY(), DAnchor.MIDDLE_LEFT, "Create file", root);
95
+			
96
+			newWindow.focus(input);
97
+		}));
98
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, SettingsIcon.PURPLE, e -> {
99
+			
100
+		}));
58 101
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, BuildIcon.BLUE, e -> {
59 102
 			for (IDETarget target : host.getTargets()) {
60 103
 				if (target.canBuild())
@@ -69,4 +112,22 @@ public class IDEWindow {
69 112
 		}));
70 113
 		aspectBar.toolbars.add(projectToolbar);
71 114
 	}
115
+	
116
+	public void setContextModule(IDEModule module) {
117
+		contextModule.setValue(module);
118
+		contextPackage.setValue(module.getRootPackage());
119
+		contextFile.setValue(null);
120
+	}
121
+	
122
+	public void setContextPackage(IDEPackage pkg) {
123
+		contextModule.setValue(null);
124
+		contextPackage.setValue(pkg);
125
+		contextFile.setValue(null);
126
+	}
127
+	
128
+	public void setContextFile(IDESourceFile file) {
129
+		contextModule.setValue(null);
130
+		contextPackage.setValue(null);
131
+		contextFile.setValue(file);
132
+	}
72 133
 }

+ 1
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/icons/AddBoxIcon.java Переглянути файл

@@ -16,6 +16,7 @@ public class AddBoxIcon implements DColorableIcon {
16 16
 	public static final ColoredIcon BLUE = new ColoredIcon(INSTANCE, 0xFF1B1464);
17 17
 	public static final ColoredIcon GREEN = new ColoredIcon(INSTANCE, 0xFF006266);
18 18
 	public static final ColoredIcon ORANGE = new ColoredIcon(INSTANCE, 0xFFEE5A24);
19
+	public static final ColoredIcon GRAY = new ColoredIcon(INSTANCE, 0xFF888888);
19 20
 	
20 21
 	private AddBoxIcon() {}
21 22
 	

+ 8
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java Переглянути файл

@@ -81,6 +81,11 @@ public class IconButtonControl implements DComponent {
81 81
 	public DIRectangle getBounds() {
82 82
 		return bounds;
83 83
 	}
84
+	
85
+	@Override
86
+	public int getBaselineY() {
87
+		return -1;
88
+	}
84 89
 
85 90
 	@Override
86 91
 	public void setBounds(DIRectangle bounds) {
@@ -154,6 +159,9 @@ public class IconButtonControl implements DComponent {
154 159
 	}
155 160
 	
156 161
 	private void repaint() {
162
+		if (context == null || bounds == null)
163
+			return;
164
+		
157 165
 		context.repaint(bounds);
158 166
 	}
159 167
 }

+ 36
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarStyle.java Переглянути файл

@@ -0,0 +1,36 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.ui.view;
7
+
8
+import org.openzen.drawablegui.DFont;
9
+import org.openzen.drawablegui.DFontFamily;
10
+import org.openzen.drawablegui.style.DDpDimension;
11
+import org.openzen.drawablegui.style.DStyleDefinition;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class StatusBarStyle {
18
+	public final int paddingTop;
19
+	public final int paddingBottom;
20
+	public final int paddingLeft;
21
+	public final int paddingRight;
22
+	public final DFont font;
23
+	public final int backgroundColor;
24
+	public final int textColor;
25
+	
26
+	public StatusBarStyle(DStyleDefinition style) {
27
+		paddingTop = style.getDimension("paddingTop", new DDpDimension(4));
28
+		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(4));
29
+		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(4));
30
+		paddingRight = style.getDimension("paddingRight", new DDpDimension(4));
31
+		
32
+		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, (int)(14 * context.getScale())));
33
+		backgroundColor = style.getColor("backgroundColor", 0xFFF0F0F0);
34
+		textColor = style.getColor("textColor", 0xFF000000);
35
+	}
36
+}

+ 26
- 4
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/StatusBarView.java Переглянути файл

@@ -8,10 +8,13 @@ package org.openzen.zenscript.ide.ui.view;
8 8
 import org.openzen.drawablegui.DCanvas;
9 9
 import org.openzen.drawablegui.DComponent;
10 10
 import org.openzen.drawablegui.DDimensionPreferences;
11
+import org.openzen.drawablegui.DFontMetrics;
11 12
 import org.openzen.drawablegui.DIRectangle;
12 13
 import org.openzen.drawablegui.live.LiveObject;
13 14
 import org.openzen.drawablegui.live.SimpleLiveObject;
14 15
 import org.openzen.drawablegui.DUIContext;
16
+import org.openzen.drawablegui.live.LiveString;
17
+import org.openzen.drawablegui.style.DStyleClass;
15 18
 import org.openzen.drawablegui.style.DStylePath;
16 19
 
17 20
 /**
@@ -19,16 +22,29 @@ import org.openzen.drawablegui.style.DStylePath;
19 22
  * @author Hoofdgebruiker
20 23
  */
21 24
 public class StatusBarView implements DComponent {
22
-	private static final int COLOR = 0xFFF0F0F0;
23
-	//private static final int COLOR = 0xFFFFFFFF;
25
+	private final SimpleLiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 0));
24 26
 	
25
-	private final SimpleLiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(new DDimensionPreferences(0, 40));
27
+	private final DStyleClass styleClass;
28
+	private final LiveString content;
26 29
 	private DIRectangle bounds;
27 30
 	private DUIContext context;
31
+	private StatusBarStyle style;
32
+	private DFontMetrics fontMetrics;
28 33
 
34
+	public StatusBarView(DStyleClass styleClass, LiveString content) {
35
+		this.styleClass = styleClass;
36
+		this.content = content;
37
+	}
38
+	
29 39
 	@Override
30 40
 	public void setContext(DStylePath parent, DUIContext context) {
31 41
 		this.context = context;
42
+		
43
+		DStylePath path = parent.getChild("StatusBar", styleClass);
44
+		style = new StatusBarStyle(context.getStylesheets().get(context, path));
45
+		fontMetrics = context.getFontMetrics(style.font);
46
+		
47
+		dimensionPreferences.setValue(new DDimensionPreferences(0, style.paddingTop + fontMetrics.getAscent() + fontMetrics.getDescent() + style.paddingBottom));
32 48
 	}
33 49
 	
34 50
 	@Override
@@ -40,6 +56,11 @@ public class StatusBarView implements DComponent {
40 56
 	public DIRectangle getBounds() {
41 57
 		return bounds;
42 58
 	}
59
+	
60
+	@Override
61
+	public int getBaselineY() {
62
+		return style.paddingTop + fontMetrics.getAscent();
63
+	}
43 64
 
44 65
 	@Override
45 66
 	public void setBounds(DIRectangle bounds) {
@@ -48,7 +69,8 @@ public class StatusBarView implements DComponent {
48 69
 
49 70
 	@Override
50 71
 	public void paint(DCanvas canvas) {
51
-		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, COLOR);
72
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
73
+		canvas.drawText(style.font, style.textColor, style.paddingLeft, style.paddingTop + fontMetrics.getAscent(), content.getValue());
52 74
 	}
53 75
 
54 76
 	@Override

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java Переглянути файл

@@ -89,6 +89,11 @@ public class TabbedView extends BaseComponentGroup {
89 89
 	public DIRectangle getBounds() {
90 90
 		return bounds;
91 91
 	}
92
+	
93
+	@Override
94
+	public int getBaselineY() {
95
+		return -1;
96
+	}
92 97
 
93 98
 	@Override
94 99
 	public void setBounds(DIRectangle bounds) {

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTab.java Переглянути файл

@@ -77,6 +77,11 @@ public class TabbedViewTab implements DComponent {
77 77
 	public DIRectangle getBounds() {
78 78
 		return bounds;
79 79
 	}
80
+	
81
+	@Override
82
+	public int getBaselineY() {
83
+		return -1;
84
+	}
80 85
 
81 86
 	@Override
82 87
 	public void setBounds(DIRectangle bounds) {

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTabClose.java Переглянути файл

@@ -60,6 +60,11 @@ public class TabbedViewTabClose implements DComponent {
60 60
 	public DIRectangle getBounds() {
61 61
 		return bounds;
62 62
 	}
63
+	
64
+	@Override
65
+	public int getBaselineY() {
66
+		return -1;
67
+	}
63 68
 
64 69
 	@Override
65 70
 	public void setBounds(DIRectangle bounds) {

+ 4
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java Переглянути файл

@@ -9,6 +9,8 @@ import org.openzen.drawablegui.DDimensionPreferences;
9 9
 import org.openzen.drawablegui.DEmptyView;
10 10
 import org.openzen.drawablegui.scroll.DScrollPane;
11 11
 import org.openzen.drawablegui.DSideLayout;
12
+import org.openzen.drawablegui.live.LiveString;
13
+import org.openzen.drawablegui.live.SimpleLiveString;
12 14
 import org.openzen.drawablegui.style.DStyleClass;
13 15
 import org.openzen.drawablegui.tree.DTreeView;
14 16
 import org.openzen.drawablegui.tree.DTreeViewStyle;
@@ -27,6 +29,7 @@ import org.openzen.zenscript.ide.ui.view.project.RootTreeNode;
27 29
 public final class WindowView extends DSideLayout {
28 30
 	private final IDEWindow window;
29 31
 	private final TabbedView tabs;
32
+	public final LiveString status = new SimpleLiveString("IDE initialized");
30 33
 	
31 34
 	public WindowView(IDEWindow window, DevelopmentHost host) {
32 35
 		super(DStyleClass.EMPTY, DEmptyView.INSTANCE);
@@ -36,7 +39,7 @@ public final class WindowView extends DSideLayout {
36 39
 		projectView.getDimensionPreferences().setValue(new DDimensionPreferences(500, 500));
37 40
 		setMain(tabs = new TabbedView(DStyleClass.EMPTY));
38 41
 		add(Side.LEFT, new DScrollPane(DStyleClass.forId("projectView"), projectView));
39
-		add(Side.BOTTOM, new StatusBarView());
42
+		add(Side.BOTTOM, new StatusBarView(DStyleClass.EMPTY, status));
40 43
 		add(Side.TOP, new AspectBarView(DStyleClass.EMPTY, window.aspectBar));
41 44
 		
42 45
 		window.dockWindow.addListener(new DockWindowListener());

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java Переглянути файл

@@ -76,6 +76,11 @@ public class AspectBarSelectorButton implements DComponent {
76 76
 	public DIRectangle getBounds() {
77 77
 		return bounds;
78 78
 	}
79
+	
80
+	@Override
81
+	public int getBaselineY() {
82
+		return -1;
83
+	}
79 84
 
80 85
 	@Override
81 86
 	public void setBounds(DIRectangle bounds) {

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButtonStyle.java Переглянути файл

@@ -36,7 +36,7 @@ public class AspectBarSelectorButtonStyle {
36 36
 		colorNormal = style.getColor("colorNormal", 0xFFFFFFFF);
37 37
 		colorHover = style.getColor("colorHover", 0xFFE0E0E0);
38 38
 		colorPress = style.getColor("colorPress", 0xFFCCCCCC);
39
-		colorActive = style.getColor("colorActive", 0xFFCCCCCC);
39
+		colorActive = style.getColor("colorActive", 0xFFF0F0F0);
40 40
 		
41 41
 		shadowNormal = style.getShadow("shadowNormal", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));
42 42
 		shadowHover = style.getShadow("shadowNormal", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()));

+ 2
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarStyle.java Переглянути файл

@@ -45,13 +45,13 @@ public class AspectBarStyle {
45 45
 		aspectSelectorToToolbarSpacing = style.getDimension("aspectSelectorToToolbarSpacing", new DDpDimension(16));
46 46
 		toolbarTitleToControlsSpacing = style.getDimension("toolbarTitleToControlsSpacing", new DDpDimension(8));
47 47
 		aspectSelectorBottomSize = style.getDimension("aspectSelectorBottomSize", new DDpDimension(4));
48
-		backgroundColor = style.getColor("backgroundColor", 0xFFF0F0F0);
48
+		backgroundColor = style.getColor("backgroundColor", 0xFFCCCCCC); // 0xFFF0F0F0
49 49
 		foregroundColor = style.getColor("foregroundColor", 0xFFFFFFFF);
50 50
 		
51 51
 		aspectSelectorButtonSpacing = style.getDimension("aspectSelectorButtonSpacing", new DDpDimension(4));
52 52
 		
53 53
 		aspectBarShadow = style.getShadow("aspectBarShadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 2 * context.getScale()));
54
-		aspectBarPaddingTop = style.getDimension("aspectBarPaddingTop", new DDpDimension(2));
54
+		aspectBarPaddingTop = style.getDimension("aspectBarPaddingTop", new DDpDimension(4));
55 55
 		
56 56
 		controlPaddingTop = style.getDimension("controlPaddingTop", new DDpDimension(2));
57 57
 		controlPaddingBottom = style.getDimension("controlPaddingBottom", new DDpDimension(2));

+ 17
- 4
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarView.java Переглянути файл

@@ -137,6 +137,11 @@ public class AspectBarView extends BaseComponentGroup {
137 137
 	public DIRectangle getBounds() {
138 138
 		return bounds;
139 139
 	}
140
+	
141
+	@Override
142
+	public int getBaselineY() {
143
+		return -1;
144
+	}
140 145
 
141 146
 	@Override
142 147
 	public void setBounds(DIRectangle bounds) {
@@ -326,12 +331,20 @@ public class AspectBarView extends BaseComponentGroup {
326 331
 		
327 332
 		aspectBarShape = tracer -> {
328 333
 			int baseY = bounds.y + bounds.height - style.aspectSelectorBottomSize;
334
+			int barBaseX = toX + style.aspectSelectorToToolbarSpacing;
335
+			int barBaseY = bounds.y + style.aspectBarPaddingTop;
336
+			
329 337
 			tracer.moveTo(bounds.x, baseY);
330
-			tracer.lineTo(toX, baseY);
338
+			tracer.lineTo(toX - 3 * context.getScale(), baseY);
339
+			tracer.bezierCubic(
340
+					toX + 0 * context.getScale(), baseY,
341
+					toX + 2 * context.getScale(), baseY,
342
+					toX + 3.5f * context.getScale(), baseY - 4 * context.getScale());
343
+			tracer.lineTo(barBaseX - 3.5f * context.getScale(), barBaseY + 4 * context.getScale());
331 344
 			tracer.bezierCubic(
332
-					toX + 6 * context.getScale(), baseY,
333
-					toX + style.aspectSelectorToToolbarSpacing - 6 * context.getScale(), bounds.y + style.aspectBarPaddingTop,
334
-					toX + style.aspectSelectorToToolbarSpacing, bounds.y + style.aspectBarPaddingTop);
345
+					barBaseX - 2 * context.getScale(), barBaseY,
346
+					barBaseX - 0 * context.getScale(), barBaseY,
347
+					barBaseX + 3 * context.getScale(), barBaseY);
335 348
 			
336 349
 			if (showWindowControls) {
337 350
 				int spacingLeft = style.windowControlSpacingLeft;

+ 5
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/WindowActionButton.java Переглянути файл

@@ -68,6 +68,11 @@ public class WindowActionButton implements DComponent {
68 68
 	public DIRectangle getBounds() {
69 69
 		return bounds;
70 70
 	}
71
+	
72
+	@Override
73
+	public int getBaselineY() {
74
+		return -1;
75
+	}
71 76
 
72 77
 	@Override
73 78
 	public void setBounds(DIRectangle bounds) {

+ 6
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java Переглянути файл

@@ -140,6 +140,11 @@ public class SourceEditor implements DComponent {
140 140
 	public DIRectangle getBounds() {
141 141
 		return bounds;
142 142
 	}
143
+	
144
+	@Override
145
+	public int getBaselineY() {
146
+		return -1;
147
+	}
143 148
 
144 149
 	@Override
145 150
 	public void setBounds(DIRectangle bounds) {
@@ -229,7 +234,7 @@ public class SourceEditor implements DComponent {
229 234
 	
230 235
 	@Override
231 236
 	public void onMouseClick(DMouseEvent e) {
232
-		context.focus(this);
237
+		context.getWindow().focus(this);
233 238
 		
234 239
 		SourcePosition position = getPositionAt(e.x, e.y);
235 240
 		if (e.isDoubleClick()) {

+ 9
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ModuleTreeNode.java Переглянути файл

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.ide.ui.view.project;
7 7
 
8 8
 import org.openzen.drawablegui.DColorableIcon;
9
+import org.openzen.drawablegui.DMouseEvent;
9 10
 import org.openzen.zenscript.ide.host.IDEModule;
10 11
 import org.openzen.zenscript.ide.ui.IDEWindow;
11 12
 import org.openzen.zenscript.ide.ui.icons.ModuleIcon;
@@ -16,10 +17,13 @@ import org.openzen.zenscript.ide.ui.icons.ModuleIcon;
16 17
  */
17 18
 public class ModuleTreeNode extends PackageTreeNode {
18 19
 	private final IDEModule module;
20
+	private final IDEWindow window;
19 21
 	
20 22
 	public ModuleTreeNode(IDEWindow window, IDEModule module) {
21 23
 		super(window, module.getRootPackage());
24
+		
22 25
 		this.module = module;
26
+		this.window = window;
23 27
 	}
24 28
 
25 29
 	@Override
@@ -36,6 +40,11 @@ public class ModuleTreeNode extends PackageTreeNode {
36 40
 	public String getTitle() {
37 41
 		return module.getName();
38 42
 	}
43
+	
44
+	@Override
45
+	public void onMouseClick(DMouseEvent e) {
46
+		window.setContextModule(module);
47
+	}
39 48
 
40 49
 	@Override
41 50
 	public boolean isLeaf() {

+ 1
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/SourceFileTreeNode.java Переглянути файл

@@ -53,6 +53,7 @@ public class SourceFileTreeNode extends ProjectOverviewNode {
53 53
 	
54 54
 	@Override
55 55
 	public void onMouseClick(DMouseEvent e) {
56
+		window.setContextFile(sourceFile);
56 57
 		if (e.isDoubleClick()) {
57 58
 			window.open(sourceFile);
58 59
 		}

+ 1
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java Переглянути файл

@@ -62,7 +62,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
62 62
 	
63 63
 	private JavaSourceFileScope createScope(HighLevelDefinition definition) {
64 64
 		SemanticModule module = modules.get(definition);
65
-		CompileScope scope = new CompileScope(definition.access, module.compilationUnit.globalTypeRegistry, module.expansions, module.annotations);
65
+		CompileScope scope = new CompileScope(module.compilationUnit.globalTypeRegistry, module.expansions, module.annotations);
66 66
 		return new JavaSourceFileScope(file.importer, compiler.typeGenerator, compiler.helperGenerator, cls, scope, definition instanceof InterfaceDefinition);
67 67
 	}
68 68
 

+ 3
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java Переглянути файл

@@ -67,8 +67,11 @@ public class JavaSourcePrepareDefinitionVisitor implements DefinitionVisitor<Jav
67 67
 			list.addMethod("constructor", new JavaSourceMethod(arrayList, JavaSourceMethod.Kind.CONSTRUCTOR, "", false));
68 68
 			list.addInstanceMethod("add", "add");
69 69
 			list.addInstanceMethod("insert", "add");
70
+			list.addInstanceMethod("remove", "remove");
71
+			list.addInstanceMethod("indexOf", "indexOf");
70 72
 			list.addInstanceMethod("getAtIndex", "get");
71 73
 			list.addInstanceMethod("setAtIndex", "set");
74
+			list.addInstanceMethod("contains", "contains");
72 75
 			list.addMethod("toArray", new JavaSourceMethod((formatter, call) -> formatter.listToArray((CastExpression)call)));
73 76
 			list.addInstanceMethod("length", "length");
74 77
 			list.addInstanceMethod("isEmpty", "isEmpty");

+ 4
- 6
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java Переглянути файл

@@ -17,7 +17,6 @@ import org.openzen.zencode.shared.CodePosition;
17 17
 import org.openzen.zencode.shared.CompileException;
18 18
 import org.openzen.zencode.shared.CompileExceptionCode;
19 19
 import org.openzen.zencode.shared.SourceFile;
20
-import org.openzen.zenscript.codemodel.AccessScope;
21 20
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
22 21
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
23 22
 import org.openzen.zenscript.codemodel.Modifiers;
@@ -130,7 +129,6 @@ public class ParsedFile {
130 129
 	private final List<ParsedImport> imports = new ArrayList<>();
131 130
 	private final List<ParsedDefinition> definitions = new ArrayList<>();
132 131
 	private final List<ParsedStatement> statements = new ArrayList<>();
133
-	private final AccessScope access = new AccessScope();
134 132
 	private WhitespacePostComment postComment = null;
135 133
 	
136 134
 	public ParsedFile(String filename) {
@@ -161,7 +159,7 @@ public class ParsedFile {
161 159
 			List<ExpansionDefinition> expansions,
162 160
 			Map<String, ISymbol> globalSymbols,
163 161
 			List<AnnotationDefinition> annotations) {
164
-		FileScope scope = new FileScope(access, rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
162
+		FileScope scope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
165 163
 		loadImports(scope, rootPackage, modulePackage);
166 164
 		for (ParsedDefinition definition : this.definitions) {
167 165
 			definition.compileTypes(scope);
@@ -176,7 +174,7 @@ public class ParsedFile {
176 174
 			List<ExpansionDefinition> expansions,
177 175
 			Map<String, ISymbol> globalSymbols,
178 176
 			List<AnnotationDefinition> annotations) {
179
-		FileScope scope = new FileScope(access, rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
177
+		FileScope scope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
180 178
 		loadImports(scope, rootPackage, modulePackage);
181 179
 		for (ParsedDefinition definition : this.definitions) {
182 180
 			definition.compileMembers(scope);
@@ -192,7 +190,7 @@ public class ParsedFile {
192 190
 			List<ScriptBlock> scripts,
193 191
 			Map<String, ISymbol> globalSymbols,
194 192
 			List<AnnotationDefinition> annotations) {
195
-		FileScope scope = new FileScope(access, rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
193
+		FileScope scope = new FileScope(rootPackage, packageDefinitions, globalRegistry, expansions, globalSymbols, annotations);
196 194
 		loadImports(scope, rootPackage, modulePackage);
197 195
 		for (ParsedDefinition definition : this.definitions) {
198 196
 			definition.compileCode(scope);
@@ -205,7 +203,7 @@ public class ParsedFile {
205 203
 				statements.add(statement.compile(statementScope));
206 204
 			}
207 205
 			
208
-			ScriptBlock block = new ScriptBlock(access, statements);
206
+			ScriptBlock block = new ScriptBlock(statements);
209 207
 			block.setTag(SourceFile.class, new SourceFile(filename));
210 208
 			block.setTag(WhitespacePostComment.class, postComment);
211 209
 			scripts.add(block);

+ 1
- 2
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedGenericParameter.java Переглянути файл

@@ -58,10 +58,9 @@ public class ParsedGenericParameter {
58 58
 		}
59 59
 	}
60 60
 	
61
-	private static TypeParameter[] NO_TYPE_PARAMETERS = new TypeParameter[0];
62 61
 	public static TypeParameter[] getCompiled(List<ParsedGenericParameter> parameters) {
63 62
 		if (parameters == null)
64
-			return null;
63
+			return TypeParameter.NONE;
65 64
 		
66 65
 		TypeParameter[] result = new TypeParameter[parameters.size()];
67 66
 		for (int i = 0; i < result.length; i++)

Завантаження…
Відмінити
Зберегти