Browse Source

- Fixed scaling (hopefully) on different DPI devices

- Fixed some minor ui issues
Stan Hebben 6 years ago
parent
commit
dd47b2621c

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

96
 		
96
 		
97
 		if (cursor != null)
97
 		if (cursor != null)
98
 			cursor.close();
98
 			cursor.close();
99
-		cursor = parent.fillRect(2, DIRectangle.EMPTY, cursorBlink ? style.cursorColor : 0);
99
+		cursor = parent.fillRect(3, DIRectangle.EMPTY, cursorBlink ? style.cursorColor : 0);
100
 		
100
 		
101
 		if (selection != null)
101
 		if (selection != null)
102
 			selection.close();
102
 			selection.close();
152
 		text.setPosition(
152
 		text.setPosition(
153
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
153
 				bounds.x + style.margin.left + style.border.getPaddingLeft(),
154
 				bounds.y + style.margin.top + style.border.getPaddingTop() + fontMetrics.getAscent());
154
 				bounds.y + style.margin.top + style.border.getPaddingTop() + fontMetrics.getAscent());
155
+		
155
 		style.border.update(context, bounds);
156
 		style.border.update(context, bounds);
156
 	}
157
 	}
157
 	
158
 	

+ 22
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DScalableSize.java View File

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

+ 4
- 4
DrawableGui/src/main/java/org/openzen/drawablegui/form/DFormStyle.java View File

28
 	public final int minimumFieldSize;
28
 	public final int minimumFieldSize;
29
 	
29
 	
30
 	public DFormStyle(DStyleDefinition style) {
30
 	public DFormStyle(DStyleDefinition style) {
31
-		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(16));
32
-		paddingTop = style.getDimension("paddingTop", new DDpDimension(16));
33
-		paddingRight = style.getDimension("paddingRight", new DDpDimension(16));
34
-		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(16));
31
+		paddingLeft = style.getDimension("paddingLeft", DPxDimension.ZERO);
32
+		paddingTop = style.getDimension("paddingTop", DPxDimension.ZERO);
33
+		paddingRight = style.getDimension("paddingRight", DPxDimension.ZERO);
34
+		paddingBottom = style.getDimension("paddingBottom", DPxDimension.ZERO);
35
 		spacing = style.getDimension("spacing", new DDpDimension(8));
35
 		spacing = style.getDimension("spacing", new DDpDimension(8));
36
 		
36
 		
37
 		labelColor = style.getColor("labelColor", 0xFF000000);
37
 		labelColor = style.getColor("labelColor", 0xFF000000);

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

244
 				DSizing preferences = element.component.getSizing().getValue();
244
 				DSizing preferences = element.component.getSizing().getValue();
245
 				int newX = x + preferences.preferredWidth;
245
 				int newX = x + preferences.preferredWidth;
246
 				layoutHorizontal(element, x, newX - x);
246
 				layoutHorizontal(element, x, newX - x);
247
-				x = newX;
247
+				x = newX + style.spacing;
248
 			}
248
 			}
249
 		} else {
249
 		} else {
250
 			float deltaScaled = delta / totalGrow;
250
 			float deltaScaled = delta / totalGrow;
269
 				DSizing preferences = element.component.getSizing().getValue();
269
 				DSizing preferences = element.component.getSizing().getValue();
270
 				int newY = y + preferences.preferredHeight;
270
 				int newY = y + preferences.preferredHeight;
271
 				layoutVertical(element, y, newY - y);
271
 				layoutVertical(element, y, newY - y);
272
-				y = newY;
272
+				y = newY + style.spacing;
273
 			}
273
 			}
274
 		} else {
274
 		} else {
275
 			float deltaScaled = delta / totalGrow;
275
 			float deltaScaled = delta / totalGrow;

+ 10
- 3
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java View File

10
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DSizing;
11
 import org.openzen.drawablegui.DIRectangle;
11
 import org.openzen.drawablegui.DIRectangle;
12
 import org.openzen.drawablegui.DMouseEvent;
12
 import org.openzen.drawablegui.DMouseEvent;
13
+import org.openzen.drawablegui.DScalableSize;
13
 import org.openzen.drawablegui.DTransform2D;
14
 import org.openzen.drawablegui.DTransform2D;
14
 import org.openzen.drawablegui.listeners.ListenerHandle;
15
 import org.openzen.drawablegui.listeners.ListenerHandle;
15
 import org.openzen.drawablegui.live.LiveInt;
16
 import org.openzen.drawablegui.live.LiveInt;
17
 import org.openzen.drawablegui.live.SimpleLiveInt;
18
 import org.openzen.drawablegui.live.SimpleLiveInt;
18
 import org.openzen.drawablegui.draw.DDrawnShape;
19
 import org.openzen.drawablegui.draw.DDrawnShape;
19
 import org.openzen.drawablegui.draw.DSubSurface;
20
 import org.openzen.drawablegui.draw.DSubSurface;
21
+import org.openzen.drawablegui.live.SimpleLiveObject;
20
 import org.openzen.drawablegui.style.DStyleClass;
22
 import org.openzen.drawablegui.style.DStyleClass;
21
 
23
 
22
 /**
24
 /**
37
 	private final LiveInt offsetX;
39
 	private final LiveInt offsetX;
38
 	private final LiveInt offsetY;
40
 	private final LiveInt offsetY;
39
 	
41
 	
40
-	private final LiveObject<DSizing> sizing;
42
+	private final SimpleLiveObject<DSizing> sizing = new SimpleLiveObject<>(DSizing.EMPTY);
43
+	private final LiveObject<DScalableSize> size;
41
 	
44
 	
42
 	private final ListenerHandle<LiveInt.Listener> contentsHeightListener;
45
 	private final ListenerHandle<LiveInt.Listener> contentsHeightListener;
43
 	private final ListenerHandle<LiveInt.Listener> offsetXListener;
46
 	private final ListenerHandle<LiveInt.Listener> offsetXListener;
48
 	
51
 	
49
 	private DSubSurface subSurface;
52
 	private DSubSurface subSurface;
50
 	
53
 	
51
-	public DScrollPane(DStyleClass styleClass, DComponent contents, LiveObject<DSizing> sizing) {
52
-		this.sizing = sizing;
54
+	public DScrollPane(DStyleClass styleClass, DComponent contents, LiveObject<DScalableSize> size) {
55
+		this.size = size;
53
 		this.styleClass = styleClass;
56
 		this.styleClass = styleClass;
54
 		this.contents = contents;
57
 		this.contents = contents;
55
 		
58
 		
81
 		DComponentContext newContext = new DComponentContext(this, context.path, 0, subSurface);
84
 		DComponentContext newContext = new DComponentContext(this, context.path, 0, subSurface);
82
 		contents.mount(newContext);
85
 		contents.mount(newContext);
83
 		scrollBar.mount(context);
86
 		scrollBar.mount(context);
87
+		
88
+		sizing.setValue(new DSizing(
89
+				size.getValue().width.evalInt(parent.getUIContext()),
90
+				size.getValue().height.evalInt(parent.getUIContext())));
84
 	}
91
 	}
85
 	
92
 	
86
 	@Override
93
 	@Override

+ 1
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingDrawnRectangle.java View File

53
 	public void paint(Graphics2D g, DIRectangle clip) {
53
 	public void paint(Graphics2D g, DIRectangle clip) {
54
 		g.setColor(awtColor);
54
 		g.setColor(awtColor);
55
 		g.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
55
 		g.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
56
+		g.fillRect(clip.x, clip.y, 3, 3);
56
 	}
57
 	}
57
 }
58
 }

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

88
 		Rectangle clipBounds = g.getClipBounds();
88
 		Rectangle clipBounds = g.getClipBounds();
89
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
89
 		DIRectangle clipBounds2 = clipBounds == null ? null : new DIRectangle(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height);
90
 		Graphics2D g2d = (Graphics2D) g;
90
 		Graphics2D g2d = (Graphics2D) g;
91
+		//System.out.println("Transform: " + g2d.getTransform().getTranslateX() + ", " + g2d.getTransform().getTranslateY());
91
 		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
92
 		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
92
 		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
93
 		g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
93
 		surface.paint(g2d, clipBounds2);
94
 		surface.paint(g2d, clipBounds2);

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

23
 import org.openzen.drawablegui.live.ImmutableLiveString;
23
 import org.openzen.drawablegui.live.ImmutableLiveString;
24
 import org.openzen.drawablegui.live.SimpleLiveString;
24
 import org.openzen.drawablegui.live.SimpleLiveString;
25
 import org.openzen.drawablegui.style.DDpDimension;
25
 import org.openzen.drawablegui.style.DDpDimension;
26
+import org.openzen.drawablegui.style.DSimpleStylesheet;
26
 import org.openzen.drawablegui.style.DStyleClass;
27
 import org.openzen.drawablegui.style.DStyleClass;
28
+import org.openzen.drawablegui.style.DStylesheetBuilder;
27
 import org.openzen.zenscript.ide.host.IDEModule;
29
 import org.openzen.zenscript.ide.host.IDEModule;
28
 import org.openzen.zenscript.ide.host.IDEPackage;
30
 import org.openzen.zenscript.ide.host.IDEPackage;
29
 import org.openzen.zenscript.ide.host.IDESourceFile;
31
 import org.openzen.zenscript.ide.host.IDESourceFile;
64
 		DButton ok = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Create"), ImmutableLiveBool.FALSE, this::ok);
66
 		DButton ok = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Create"), ImmutableLiveBool.FALSE, this::ok);
65
 		DButton cancel = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Cancel"), ImmutableLiveBool.FALSE, this::cancel);
67
 		DButton cancel = new DButton(DStyleClass.EMPTY, new SimpleLiveString("Cancel"), ImmutableLiveBool.FALSE, this::cancel);
66
 		DLinearLayout buttons = new DLinearLayout(
68
 		DLinearLayout buttons = new DLinearLayout(
67
-				DStyleClass.EMPTY,
69
+				DStyleClass.inline(new DStylesheetBuilder()
70
+					.dimensionDp("spacing", 8)
71
+					.build()),
68
 				Orientation.HORIZONTAL,
72
 				Orientation.HORIZONTAL,
69
 				Alignment.RIGHT,
73
 				Alignment.RIGHT,
70
 				new Element(cancel, 0, 0, ElementAlignment.TOP),
74
 				new Element(cancel, 0, 0, ElementAlignment.TOP),
71
 				new Element(ok, 0, 0, ElementAlignment.TOP));
75
 				new Element(ok, 0, 0, ElementAlignment.TOP));
72
 
76
 
73
 		root = new DLinearLayout(
77
 		root = new DLinearLayout(
74
-				DStyleClass.EMPTY,
78
+				DStyleClass.inline(new DStylesheetBuilder()
79
+						.marginDp("margin", 16)
80
+						.build()),
75
 				Orientation.VERTICAL,
81
 				Orientation.VERTICAL,
76
 				Alignment.MIDDLE,
82
 				Alignment.MIDDLE,
77
 				new Element(form, 1, 1, ElementAlignment.CENTER),
83
 				new Element(form, 1, 1, ElementAlignment.CENTER),

+ 6
- 7
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/WindowView.java View File

6
 package org.openzen.zenscript.ide.ui.view;
6
 package org.openzen.zenscript.ide.ui.view;
7
 
7
 
8
 import org.openzen.drawablegui.DEmptyView;
8
 import org.openzen.drawablegui.DEmptyView;
9
+import org.openzen.drawablegui.DScalableSize;
9
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.DSizing;
10
 import org.openzen.drawablegui.border.DLineBorder;
11
 import org.openzen.drawablegui.border.DLineBorder;
11
 import org.openzen.drawablegui.scroll.DScrollPane;
12
 import org.openzen.drawablegui.scroll.DScrollPane;
12
 import org.openzen.drawablegui.layout.DSideLayout;
13
 import org.openzen.drawablegui.layout.DSideLayout;
13
-import org.openzen.drawablegui.live.LiveArrayList;
14
 import org.openzen.drawablegui.live.LiveString;
14
 import org.openzen.drawablegui.live.LiveString;
15
-import org.openzen.drawablegui.live.MutableLiveList;
16
-import org.openzen.drawablegui.live.SimpleLiveInt;
17
 import org.openzen.drawablegui.live.SimpleLiveObject;
15
 import org.openzen.drawablegui.live.SimpleLiveObject;
18
 import org.openzen.drawablegui.live.SimpleLiveString;
16
 import org.openzen.drawablegui.live.SimpleLiveString;
17
+import org.openzen.drawablegui.style.DDpDimension;
19
 import org.openzen.drawablegui.style.DShadow;
18
 import org.openzen.drawablegui.style.DShadow;
20
 import org.openzen.drawablegui.style.DStyleClass;
19
 import org.openzen.drawablegui.style.DStyleClass;
21
 import org.openzen.drawablegui.style.DStylesheetBuilder;
20
 import org.openzen.drawablegui.style.DStylesheetBuilder;
25
 import org.openzen.zenscript.ide.ui.IDEWindow;
24
 import org.openzen.zenscript.ide.ui.IDEWindow;
26
 import org.openzen.zenscript.ide.ui.view.aspectbar.AspectBarView;
25
 import org.openzen.zenscript.ide.ui.view.aspectbar.AspectBarView;
27
 import org.openzen.zenscript.ide.ui.view.editor.SourceEditor;
26
 import org.openzen.zenscript.ide.ui.view.editor.SourceEditor;
28
-import org.openzen.zenscript.ide.ui.view.output.OutputLine;
29
 import org.openzen.zenscript.ide.ui.view.output.OutputView;
27
 import org.openzen.zenscript.ide.ui.view.output.OutputView;
30
 import org.openzen.zenscript.ide.ui.view.project.ProjectBrowser;
28
 import org.openzen.zenscript.ide.ui.view.project.ProjectBrowser;
31
 
29
 
49
 		
47
 		
50
 		OutputView output = new OutputView(DStyleClass.EMPTY, window.output);
48
 		OutputView output = new OutputView(DStyleClass.EMPTY, window.output);
51
 		
49
 		
50
+		DScalableSize outputSize = new DScalableSize(new DDpDimension(250), new DDpDimension(250));
52
 		DScrollPane scrollOutput = new DScrollPane(DStyleClass.inline(new DStylesheetBuilder()
51
 		DScrollPane scrollOutput = new DScrollPane(DStyleClass.inline(new DStylesheetBuilder()
53
-							//.border("border", context -> new DLineBorder(0xFF888888, 1))
54
 							.marginDp("margin", 3)
52
 							.marginDp("margin", 3)
55
 							.color("backgroundColor", 0xFFFFFFFF)
53
 							.color("backgroundColor", 0xFFFFFFFF)
56
 							.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
54
 							.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
57
-							.build()), output, new SimpleLiveObject<>(new DSizing(400, 400)));
55
+							.build()), output, new SimpleLiveObject<>(outputSize));
58
 		
56
 		
59
 		setMain(tabs = new TabbedView(DStyleClass.inline(new DStylesheetBuilder()
57
 		setMain(tabs = new TabbedView(DStyleClass.inline(new DStylesheetBuilder()
60
 				.marginDp("margin", 3)
58
 				.marginDp("margin", 3)
71
 		@Override
69
 		@Override
72
 		public void onOpen(IDESourceFile sourceFile) {
70
 		public void onOpen(IDESourceFile sourceFile) {
73
 			SourceEditor editor = new SourceEditor(DStyleClass.EMPTY, window, sourceFile);
71
 			SourceEditor editor = new SourceEditor(DStyleClass.EMPTY, window, sourceFile);
72
+			DScalableSize size = new DScalableSize(new DDpDimension(280), new DDpDimension(280));
74
 			TabbedViewComponent tab = new TabbedViewComponent(
73
 			TabbedViewComponent tab = new TabbedViewComponent(
75
 					sourceFile.getName(),
74
 					sourceFile.getName(),
76
 					null,
75
 					null,
77
 					new DScrollPane(DStyleClass.inline(new DStylesheetBuilder()
76
 					new DScrollPane(DStyleClass.inline(new DStylesheetBuilder()
78
 							.border("border", context -> new DLineBorder(0xFF888888, 1))
77
 							.border("border", context -> new DLineBorder(0xFF888888, 1))
79
 							//.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
78
 							//.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
80
-							.build()), editor, new SimpleLiveObject<>(new DSizing(500, 500))),
79
+							.build()), editor, new SimpleLiveObject<>(size)),
81
 					editor.isUpdated());
80
 					editor.isUpdated());
82
 			tabs.tabs.add(tab);
81
 			tabs.tabs.add(tab);
83
 			tabs.currentTab.setValue(tab);
82
 			tabs.currentTab.setValue(tab);

+ 5
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/project/ProjectBrowser.java View File

9
 import org.openzen.drawablegui.DFont;
9
 import org.openzen.drawablegui.DFont;
10
 import org.openzen.drawablegui.DFontFamily;
10
 import org.openzen.drawablegui.DFontFamily;
11
 import org.openzen.drawablegui.DLabel;
11
 import org.openzen.drawablegui.DLabel;
12
+import org.openzen.drawablegui.DScalableSize;
12
 import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.DSizing;
13
 import org.openzen.drawablegui.border.DEmptyBorder;
14
 import org.openzen.drawablegui.border.DEmptyBorder;
14
 import org.openzen.drawablegui.border.DPaddedBorder;
15
 import org.openzen.drawablegui.border.DPaddedBorder;
24
 import org.openzen.drawablegui.live.SimpleLiveObject;
25
 import org.openzen.drawablegui.live.SimpleLiveObject;
25
 import org.openzen.drawablegui.live.SimpleLiveString;
26
 import org.openzen.drawablegui.live.SimpleLiveString;
26
 import org.openzen.drawablegui.scroll.DScrollPane;
27
 import org.openzen.drawablegui.scroll.DScrollPane;
28
+import org.openzen.drawablegui.style.DDpDimension;
27
 import org.openzen.drawablegui.style.DRoundedRectangleShape;
29
 import org.openzen.drawablegui.style.DRoundedRectangleShape;
28
 import org.openzen.drawablegui.style.DShadow;
30
 import org.openzen.drawablegui.style.DShadow;
29
 import org.openzen.drawablegui.style.DStyleClass;
31
 import org.openzen.drawablegui.style.DStyleClass;
107
 				ExpandedArrow.INSTANCE,
109
 				ExpandedArrow.INSTANCE,
108
 				CollapsedArrow.INSTANCE,
110
 				CollapsedArrow.INSTANCE,
109
 				new RootTreeNode(this, host), false);
111
 				new RootTreeNode(this, host), false);
112
+		
113
+		DScalableSize treeSize = new DScalableSize(new DDpDimension(280), new DDpDimension(280));
110
 		DScrollPane treeScrollPane = new DScrollPane(
114
 		DScrollPane treeScrollPane = new DScrollPane(
111
 				DStyleClass.inline("projectView", new DStylesheetBuilder()
115
 				DStyleClass.inline("projectView", new DStylesheetBuilder()
112
 						.shape("shape", context -> new DRoundedRectangleShape(0, 0, context.dp(2), context.dp(2)))
116
 						.shape("shape", context -> new DRoundedRectangleShape(0, 0, context.dp(2), context.dp(2)))
114
 						.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
118
 						.shadow("shadow", context -> new DShadow(0xFF888888, 0, 0.5f * context.getScale(), 3 * context.getScale()))
115
 						.build()),
119
 						.build()),
116
 				projectTree,
120
 				projectTree,
117
-				new SimpleLiveObject<>(new DSizing(500, 500)));
121
+				new SimpleLiveObject<>(treeSize));
118
 		
122
 		
119
 		view = new DLinearLayout(
123
 		view = new DLinearLayout(
120
 				DStyleClass.inline(new DStylesheetBuilder()
124
 				DStyleClass.inline(new DStylesheetBuilder()

Loading…
Cancel
Save