Просмотр исходного кода

Added tooltips to the toolbars.

Stan Hebben 6 лет назад
Родитель
Сommit
fc5265a83c

+ 25
- 45
DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltip.java Просмотреть файл

@@ -5,10 +5,8 @@
5 5
  */
6 6
 package org.openzen.drawablegui;
7 7
 
8
-import org.openzen.drawablegui.listeners.ListenerHandle;
9 8
 import org.openzen.drawablegui.live.LiveString;
10 9
 import org.openzen.drawablegui.style.DStyleClass;
11
-import org.openzen.drawablegui.style.DStylePath;
12 10
 
13 11
 /**
14 12
  *
@@ -17,31 +15,22 @@ import org.openzen.drawablegui.style.DStylePath;
17 15
 public class DSimpleTooltip {
18 16
 	private final DStyleClass styleClass;
19 17
 	private final LiveString tooltip;
20
-	private final ListenerHandle<LiveString.Listener> tooltipListener;
21 18
 	
22 19
 	private DUIContext context;
23
-	private DIRectangle bounds;
24
-	private DFontMetrics fontMetrics;
25
-	private DTooltipStyle style;
26
-	private boolean visible = false;
20
+	private DSimpleTooltipStyle style;
27 21
 	private DTimerHandle timerHandle = null;
28 22
 	
23
+	private int enterMouseX;
24
+	private int enterMouseY;
25
+	private DUIWindow window;
26
+	
29 27
 	public DSimpleTooltip(DStyleClass styleClass, LiveString tooltip) {
30 28
 		this.styleClass = styleClass;
31 29
 		this.tooltip = tooltip;
32
-		tooltipListener = tooltip.addListener(this::onTooltipChanged);
33 30
 	}
34 31
 	
35
-	private void onTooltipChanged(String oldValue, String newValue) {
36
-		if (context == null || bounds == null)
37
-			return;
38
-		
39
-		bounds = new DIRectangle(
40
-				bounds.x,
41
-				bounds.y,
42
-				style.border.getPaddingLeft() + fontMetrics.getWidth(tooltip.getValue()) + style.border.getPaddingRight(),
43
-				style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingBottom());
44
-		context.repaint(bounds);
32
+	public void setContext(DUIContext context) {
33
+		this.context = context;
45 34
 	}
46 35
 	
47 36
 	public void onTargetMouseEnter(DMouseEvent e) {
@@ -49,11 +38,13 @@ public class DSimpleTooltip {
49 38
 			timerHandle.close();
50 39
 		
51 40
 		timerHandle = context.setTimer(1000, this::show);
52
-		bounds = new DIRectangle(
53
-				e.x,
54
-				e.y,
55
-				style.border.getPaddingLeft() + fontMetrics.getWidth(tooltip.getValue()) + style.border.getPaddingRight(),
56
-				style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingBottom());
41
+		enterMouseX = e.x;
42
+		enterMouseY = e.y;
43
+	}
44
+	
45
+	public void onTargetMouseMove(DMouseEvent e) {
46
+		enterMouseX = e.x;
47
+		enterMouseY = e.y;
57 48
 	}
58 49
 	
59 50
 	public void onTargetMouseExit(DMouseEvent e) {
@@ -67,8 +58,9 @@ public class DSimpleTooltip {
67 58
 	
68 59
 	private void show() {
69 60
 		System.out.println("Show tooltip");
70
-		visible = true;
71
-		context.repaint(bounds);
61
+		
62
+		DSimpleTooltipComponent view = new DSimpleTooltipComponent(styleClass, tooltip);
63
+		window = context.openView(enterMouseX, enterMouseY + context.dp(8), DAnchor.TOP_LEFT, view);
72 64
 		
73 65
 		if (timerHandle != null) {
74 66
 			timerHandle.close();
@@ -78,29 +70,17 @@ public class DSimpleTooltip {
78 70
 	
79 71
 	private void hide() {
80 72
 		System.out.println("Hide tooltip");
81
-		visible = false;
82
-		context.repaint(bounds);
83
-	}
84
-	
85
-	public void setContext(DStylePath parent, DUIContext context) {
86
-		this.context = context;
87 73
 		
88
-		DStylePath path = parent.getChild("tooltip", styleClass);
89
-		style = new DTooltipStyle(context.getStylesheets().get(context, path));
90
-		fontMetrics = context.getFontMetrics(style.font);
91
-	}
92
-	
93
-	public void paint(DCanvas canvas) {
94
-		if (!visible)
95
-			return;
96
-		
97
-		System.out.println("Actually paint tooltip");
98
-		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
99
-		style.border.paint(canvas, bounds);
100
-		canvas.drawText(style.font, style.textColor, bounds.x + style.border.getPaddingLeft(), bounds.y + style.border.getPaddingTop(), tooltip.getValue());
74
+		if (window != null) {
75
+			window.close();
76
+			window = null;
77
+		}
101 78
 	}
102 79
 	
103 80
 	public void close() {
104
-		tooltipListener.close();
81
+		if (window != null) {
82
+			window.close();
83
+			window = null;
84
+		}
105 85
 	}
106 86
 }

+ 102
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltipComponent.java Просмотреть файл

@@ -0,0 +1,102 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.listeners.ListenerHandle;
9
+import org.openzen.drawablegui.live.LiveObject;
10
+import org.openzen.drawablegui.live.LiveString;
11
+import org.openzen.drawablegui.live.MutableLiveObject;
12
+import org.openzen.drawablegui.style.DStyleClass;
13
+import org.openzen.drawablegui.style.DStylePath;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class DSimpleTooltipComponent implements DComponent {
20
+	private final DStyleClass styleClass;
21
+	private final LiveString tooltip;
22
+	private final MutableLiveObject<DSizing> sizing = DSizing.create();
23
+	private final ListenerHandle<LiveString.Listener> tooltipListener;
24
+	
25
+	private DUIContext context;
26
+	private DIRectangle bounds;
27
+	private DFontMetrics fontMetrics;
28
+	private DSimpleTooltipStyle style;
29
+	
30
+	public DSimpleTooltipComponent(DStyleClass styleClass, LiveString tooltip) {
31
+		this.styleClass = styleClass;
32
+		this.tooltip = tooltip;
33
+		tooltipListener = tooltip.addListener(this::onTooltipChanged);
34
+	}
35
+	
36
+	private void onTooltipChanged(String oldValue, String newValue) {
37
+		if (context == null || bounds == null)
38
+			return;
39
+		
40
+		calculateSize();
41
+		bounds = new DIRectangle(
42
+				bounds.x,
43
+				bounds.y,
44
+				style.border.getPaddingLeft() + fontMetrics.getWidth(tooltip.getValue()) + style.border.getPaddingRight(),
45
+				style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingBottom());
46
+		context.repaint(bounds);
47
+	}
48
+	
49
+	@Override
50
+	public void setBounds(DIRectangle bounds) {
51
+		this.bounds = bounds;
52
+	}
53
+	
54
+	@Override
55
+	public DIRectangle getBounds() {
56
+		return bounds;
57
+	}
58
+	
59
+	@Override
60
+	public int getBaselineY() {
61
+		return style.border.getPaddingTop() + fontMetrics.getAscent();
62
+	}
63
+	
64
+	@Override
65
+	public LiveObject<DSizing> getSizing() {
66
+		return sizing;
67
+	}
68
+	
69
+	@Override
70
+	public void setContext(DStylePath parent, DUIContext context) {
71
+		this.context = context;
72
+		
73
+		DStylePath path = parent.getChild("tooltip", styleClass);
74
+		style = new DSimpleTooltipStyle(context.getStylesheets().get(context, path));
75
+		fontMetrics = context.getFontMetrics(style.font);
76
+		calculateSize();
77
+	}
78
+	
79
+	@Override
80
+	public void paint(DCanvas canvas) {
81
+		System.out.println("Actually paint tooltip");
82
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
83
+		style.border.paint(canvas, bounds);
84
+		canvas.drawText(
85
+				style.font,
86
+				style.textColor,
87
+				bounds.x + style.border.getPaddingLeft(),
88
+				bounds.y + style.border.getPaddingTop() + fontMetrics.getAscent(),
89
+				tooltip.getValue());
90
+	}
91
+	
92
+	@Override
93
+	public void close() {
94
+		tooltipListener.close();
95
+	}
96
+	
97
+	private void calculateSize() {
98
+		sizing.setValue(new DSizing(
99
+				style.border.getPaddingLeft() + fontMetrics.getWidth(tooltip.getValue()) + style.border.getPaddingRight(),
100
+				style.border.getPaddingTop() + fontMetrics.getAscent() + fontMetrics.getDescent() + style.border.getPaddingBottom()));
101
+	}
102
+}

DrawableGui/src/main/java/org/openzen/drawablegui/DTooltipStyle.java → DrawableGui/src/main/java/org/openzen/drawablegui/DSimpleTooltipStyle.java Просмотреть файл

@@ -15,15 +15,15 @@ import org.openzen.drawablegui.style.DStyleDefinition;
15 15
  *
16 16
  * @author Hoofdgebruiker
17 17
  */
18
-public class DTooltipStyle {
18
+public class DSimpleTooltipStyle {
19 19
 	public final DBorder border;
20 20
 	public final DFont font;
21 21
 	public final int backgroundColor;
22 22
 	public final int textColor;
23 23
 	
24
-	public DTooltipStyle(DStyleDefinition style) {
24
+	public DSimpleTooltipStyle(DStyleDefinition style) {
25 25
 		border = style.getBorder("border", context -> new DCompositeBorder(
26
-				new DLineBorder(0xFF, 1),
26
+				new DLineBorder(0xFF000000, 1),
27 27
 				new DPaddedBorder(context.dp(4), context.dp(4), context.dp(4), context.dp(4))));
28 28
 		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, context.sp(12)));
29 29
 		backgroundColor = style.getColor("backgroundColor", 0xFFFFFFE1);

+ 0
- 26
DrawableGui/src/main/java/org/openzen/drawablegui/DTooltip.java Просмотреть файл

@@ -1,26 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.drawablegui;
7
-
8
-import org.openzen.drawablegui.style.DStylePath;
9
-
10
-/**
11
- *
12
- * @author Hoofdgebruiker
13
- */
14
-public interface DTooltip {
15
-	void setContext(DUIContext context, DStylePath parent);
16
-	
17
-	int getWidth();
18
-	
19
-	int getHeight();
20
-	
21
-	void setBounds(DIRectangle bounds);
22
-	
23
-	DIRectangle getBounds();
24
-	
25
-	void paint(DCanvas canvas);
26
-}

+ 0
- 14
DrawableGui/src/main/java/org/openzen/drawablegui/DTooltipHandle.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.drawablegui;
7
-
8
-/**
9
- *
10
- * @author Hoofdgebruiker
11
- */
12
-public interface DTooltipHandle {
13
-	void close();
14
-}

+ 0
- 2
DrawableGui/src/main/java/org/openzen/drawablegui/DUIContext.java Просмотреть файл

@@ -40,8 +40,6 @@ public interface DUIContext {
40 40
 	
41 41
 	DUIWindow openView(int x, int y, DAnchor anchor, DComponent root);
42 42
 	
43
-	DTooltipHandle openTooltip(int x, int y, DTooltip tooltip);
44
-	
45 43
 	default int dp(float dp) {
46 44
 		return (int)(dp * getScale());
47 45
 	}

+ 0
- 7
DrawableGui/src/main/java/org/openzen/drawablegui/scroll/DScrollPane.java Просмотреть файл

@@ -15,8 +15,6 @@ import org.openzen.drawablegui.DFontMetrics;
15 15
 import org.openzen.drawablegui.DIRectangle;
16 16
 import org.openzen.drawablegui.DMouseEvent;
17 17
 import org.openzen.drawablegui.DTimerHandle;
18
-import org.openzen.drawablegui.DTooltip;
19
-import org.openzen.drawablegui.DTooltipHandle;
20 18
 import org.openzen.drawablegui.listeners.ListenerHandle;
21 19
 import org.openzen.drawablegui.live.LiveInt;
22 20
 import org.openzen.drawablegui.live.LiveObject;
@@ -333,11 +331,6 @@ public class DScrollPane implements DComponent {
333 331
 		public DUIWindow openView(int x, int y, DAnchor anchor, DComponent root) {
334 332
 			return context.openView(toGlobalX(x), toGlobalY(y), anchor, root);
335 333
 		}
336
-		
337
-		@Override
338
-		public DTooltipHandle openTooltip(int x, int y, DTooltip tooltip) {
339
-			return context.openTooltip(toGlobalX(x), toGlobalY(y), tooltip);
340
-		}
341 334
 	}
342 335
 	
343 336
 	private class ScrollListener implements LiveInt.Listener {

+ 12
- 11
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingGraphicsContext.java Просмотреть файл

@@ -8,6 +8,7 @@ package org.openzen.drawablegui.swing;
8 8
 import java.awt.Dimension;
9 9
 import java.awt.Font;
10 10
 import java.awt.Graphics;
11
+import java.awt.Point;
11 12
 import java.awt.geom.GeneralPath;
12 13
 import java.util.WeakHashMap;
13 14
 import javax.swing.JFrame;
@@ -21,8 +22,6 @@ import org.openzen.drawablegui.DFont;
21 22
 import org.openzen.drawablegui.DFontMetrics;
22 23
 import org.openzen.drawablegui.DPathTracer;
23 24
 import org.openzen.drawablegui.DTimerHandle;
24
-import org.openzen.drawablegui.DTooltip;
25
-import org.openzen.drawablegui.DTooltipHandle;
26 25
 import org.openzen.drawablegui.DUIContext;
27 26
 import org.openzen.drawablegui.DUIWindow;
28 27
 import org.openzen.drawablegui.style.DStylePathRoot;
@@ -171,29 +170,31 @@ public class SwingGraphicsContext implements DUIContext {
171 170
 
172 171
 	@Override
173 172
 	public DUIWindow openView(int x, int y, DAnchor anchor, DComponent root) {
174
-		SwingDialog window = new SwingDialog((SwingWindow)this.window, "", root, false);
173
+		SwingWindow swingWindow = (SwingWindow)this.window;
174
+		SwingInlineWindow window = new SwingInlineWindow(swingWindow, "", root);
175 175
 		SwingGraphicsContext windowContext = new SwingGraphicsContext(stylesheets, scale, textScale, window.swingComponent);
176 176
 		windowContext.setWindow(window);
177 177
 		windowContext.graphics = this.graphics; // help a little...
178 178
 		
179 179
 		root.setContext(DStylePathRoot.INSTANCE, windowContext);
180 180
 		DSizing dimension = root.getSizing().getValue();
181
-		int tx = (int)(x - anchor.alignX * dimension.preferredWidth);
182
-		int ty = (int)(y - anchor.alignY * dimension.preferredHeight);
183 181
 		
184
-		window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
182
+		Point rootLocation = swingWindow.swingComponent.getLocationOnScreen();
183
+		
184
+		int tx = (int)(x + rootLocation.x - anchor.alignX * dimension.preferredWidth);
185
+		int ty = (int)(y + rootLocation.y - anchor.alignY * dimension.preferredHeight);
186
+		System.out.println("Position: " + tx + ", " + ty);
187
+		
185 188
 		window.swingComponent.setPreferredSize(new Dimension(dimension.preferredWidth, dimension.preferredHeight));
186 189
 		window.setLocation(tx, ty);
187 190
 		window.pack();
188 191
 		window.setVisible(true);
192
+		window.swingComponent.repaint();
193
+		
194
+		System.out.println("Window size: " + window.getWidth() + " x " + window.getHeight());
189 195
 		return window;
190 196
 	}
191 197
 	
192
-	@Override
193
-	public DTooltipHandle openTooltip(int x, int y, DTooltip tooltip) {
194
-		return null; // TODO
195
-	}
196
-	
197 198
 	private class PathTracer implements DPathTracer {
198 199
 		private final GeneralPath path;
199 200
 		

+ 136
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingInlineWindow.java Просмотреть файл

@@ -0,0 +1,136 @@
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.event.WindowEvent;
10
+import java.awt.event.WindowListener;
11
+import java.awt.event.WindowStateListener;
12
+import javax.swing.JWindow;
13
+import org.openzen.drawablegui.DComponent;
14
+import org.openzen.drawablegui.DIRectangle;
15
+import org.openzen.drawablegui.DUIContext;
16
+import org.openzen.drawablegui.DUIWindow;
17
+import org.openzen.drawablegui.live.ImmutableLiveObject;
18
+import org.openzen.drawablegui.live.LiveBool;
19
+import org.openzen.drawablegui.live.LiveObject;
20
+import org.openzen.drawablegui.live.SimpleLiveBool;
21
+
22
+/**
23
+ *
24
+ * @author Hoofdgebruiker
25
+ */
26
+public final class SwingInlineWindow extends JWindow implements WindowListener, WindowStateListener, DUIWindow {
27
+	public final SwingRoot swingComponent;
28
+	private final LiveObject<State> state = new ImmutableLiveObject<>(State.NORMAL);
29
+	private final SimpleLiveBool active = new SimpleLiveBool(true);
30
+	
31
+	public SwingInlineWindow(SwingWindow owner, String title, DComponent root) {
32
+		super(owner);
33
+		
34
+		addWindowListener(this);
35
+		addWindowStateListener(this);
36
+		
37
+		getContentPane().add(swingComponent = new SwingRoot(root), BorderLayout.CENTER);
38
+		swingComponent.setWindow(this);
39
+		swingComponent.requestFocusInWindow();
40
+	}
41
+	
42
+	@Override
43
+	public DUIContext getContext() {
44
+		return swingComponent.context;
45
+	}
46
+
47
+	@Override
48
+	public DIRectangle getWindowBounds() {
49
+		return new DIRectangle(getX(), getY(), getWidth(), getHeight());
50
+	}
51
+
52
+	@Override
53
+	public boolean hasTitleBar() {
54
+		return false;
55
+	}
56
+
57
+	@Override
58
+	public void close() {
59
+		dispose();
60
+	}
61
+
62
+	@Override
63
+	public void maximize() {
64
+		// cannot maximize
65
+	}
66
+
67
+	@Override
68
+	public void restore() {
69
+		// cannot restore
70
+	}
71
+
72
+	@Override
73
+	public void minimize() {
74
+		// cannot minimize
75
+	}
76
+
77
+	@Override
78
+	public LiveObject<State> getWindowState() {
79
+		return state;
80
+	}
81
+	
82
+	@Override
83
+	public LiveBool getActive() {
84
+		return active;
85
+	}
86
+	
87
+	@Override
88
+	public void focus(DComponent component) {
89
+		swingComponent.focus(component);
90
+	}
91
+	
92
+	@Override
93
+	public DUIWindow openModal(String title, DComponent component) {
94
+		throw new IllegalArgumentException("Cannot open a modal from an inline window!");
95
+	}
96
+
97
+	@Override
98
+	public void windowOpened(WindowEvent e) {
99
+		
100
+	}
101
+
102
+	@Override
103
+	public void windowClosing(WindowEvent e) {
104
+		
105
+	}
106
+
107
+	@Override
108
+	public void windowClosed(WindowEvent e) {
109
+		
110
+	}
111
+
112
+	@Override
113
+	public void windowIconified(WindowEvent e) {
114
+		
115
+	}
116
+
117
+	@Override
118
+	public void windowDeiconified(WindowEvent e) {
119
+		
120
+	}
121
+
122
+	@Override
123
+	public void windowActivated(WindowEvent e) {
124
+		active.setValue(true);
125
+	}
126
+
127
+	@Override
128
+	public void windowDeactivated(WindowEvent e) {
129
+		active.setValue(false);
130
+	}
131
+
132
+	@Override
133
+	public void windowStateChanged(WindowEvent e) {
134
+		
135
+	}
136
+}

+ 1
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingRoot.java Просмотреть файл

@@ -77,6 +77,7 @@ public final class SwingRoot extends Component implements ComponentListener, Mou
77 77
 			firstPaint = false;
78 78
 			component.setContext(DStylePathRoot.INSTANCE, context);
79 79
 			component.setBounds(new DIRectangle(0, 0, getWidth(), getHeight()));
80
+			System.out.println("Painting with size " + getWidth() + " x " + getHeight());
80 81
 		}
81 82
 		
82 83
 		Rectangle clipBounds = g.getClipBounds();

+ 0
- 32
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingTooltipWindow.java Просмотреть файл

@@ -1,32 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.drawablegui.swing;
7
-
8
-import javax.swing.JWindow;
9
-import org.openzen.drawablegui.DComponent;
10
-import org.openzen.drawablegui.DTooltipHandle;
11
-import org.openzen.drawablegui.style.DStylePathRoot;
12
-
13
-/**
14
- *
15
- * @author Hoofdgebruiker
16
- */
17
-public class SwingTooltipWindow extends JWindow implements DTooltipHandle {
18
-	private final SwingGraphicsContext context;
19
-	
20
-	public SwingTooltipWindow(SwingGraphicsContext parent, DComponent rootComponent) {
21
-		SwingRoot root = new SwingRoot(rootComponent);
22
-		context = new SwingGraphicsContext(parent.getStylesheets(), parent.getScale(), parent.getTextScale(), root);
23
-		rootComponent.setContext(DStylePathRoot.INSTANCE, context);
24
-		rootPane.add(root);
25
-		pack();
26
-	}
27
-	
28
-	@Override
29
-	public void close() {
30
-		dispose();
31
-	}
32
-}

+ 1
- 1
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java Просмотреть файл

@@ -28,7 +28,7 @@ import org.openzen.drawablegui.style.DStyleClass;
28 28
  * @author Hoofdgebruiker
29 29
  */
30 30
 public final class SwingWindow extends JFrame implements WindowListener, WindowStateListener, DUIWindow {
31
-	private final SwingRoot swingComponent;
31
+	public final SwingRoot swingComponent;
32 32
 	private final boolean noTitleBar;
33 33
 	private final SimpleLiveObject<State> state = new SimpleLiveObject<>(State.NORMAL);
34 34
 	private final SimpleLiveBool active = new SimpleLiveBool(true);

+ 6
- 5
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java Просмотреть файл

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui;
7 7
 
8
+import org.openzen.drawablegui.live.ImmutableLiveString;
8 9
 import org.openzen.drawablegui.live.LiveBool;
9 10
 import org.openzen.drawablegui.live.LivePredicateBool;
10 11
 import org.openzen.drawablegui.live.MutableLiveObject;
@@ -66,24 +67,24 @@ public class IDEWindow {
66 67
 	
67 68
 	private void init() {
68 69
 		projectToolbar = new IDEAspectToolbar(0, ShadedProjectIcon.PURPLE, "Project", "Project management");
69
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.BLUE, AddBoxIcon.GRAY, addContentDisabled, e -> {
70
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.BLUE, AddBoxIcon.GRAY, addContentDisabled, new ImmutableLiveString("Create package"), e -> {
70 71
 			CreatePackageDialog dialog = new CreatePackageDialog(this, contextModule.getValue(), contextPackage.getValue());
71 72
 			dialog.open(e.window);
72 73
 		}));
73
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.ORANGE, AddBoxIcon.GRAY, addContentDisabled, e -> {
74
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.ORANGE, AddBoxIcon.GRAY, addContentDisabled, new ImmutableLiveString("Create source file"), e -> {
74 75
 			CreateSourceFileDialog dialog = new CreateSourceFileDialog(this, contextModule.getValue(), contextPackage.getValue());
75 76
 			dialog.open(e.window);
76 77
 		}));
77
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, SettingsIcon.PURPLE, e -> {
78
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, SettingsIcon.PURPLE, new ImmutableLiveString("Project settings"), e -> {
78 79
 			
79 80
 		}));
80
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, BuildIcon.BLUE, e -> {
81
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, BuildIcon.BLUE, new ImmutableLiveString("Build"), e -> {
81 82
 			for (IDETarget target : host.getTargets()) {
82 83
 				if (target.canBuild())
83 84
 					target.build();
84 85
 			}
85 86
 		}));
86
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, PlayIcon.GREEN, e -> {
87
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, PlayIcon.GREEN, new ImmutableLiveString("Run"), e -> {
87 88
 			for (IDETarget target : host.getTargets()) {
88 89
 				if (target.canRun())
89 90
 					target.run();

+ 16
- 3
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/IconButtonControl.java Просмотреть файл

@@ -15,10 +15,12 @@ import org.openzen.drawablegui.DPath;
15 15
 import org.openzen.drawablegui.DTransform2D;
16 16
 import org.openzen.drawablegui.DUIContext;
17 17
 import org.openzen.drawablegui.DIRectangle;
18
+import org.openzen.drawablegui.DSimpleTooltip;
18 19
 import org.openzen.drawablegui.listeners.ListenerHandle;
19 20
 import org.openzen.drawablegui.live.ImmutableLiveBool;
20 21
 import org.openzen.drawablegui.live.LiveBool;
21 22
 import org.openzen.drawablegui.live.LiveObject;
23
+import org.openzen.drawablegui.live.LiveString;
22 24
 import org.openzen.drawablegui.live.MutableLiveObject;
23 25
 import org.openzen.drawablegui.style.DStyleClass;
24 26
 import org.openzen.drawablegui.style.DStylePath;
@@ -34,6 +36,7 @@ public class IconButtonControl implements DComponent {
34 36
 	private final Consumer<DMouseEvent> onClick;
35 37
 	private final LiveBool disabled;
36 38
 	private final ListenerHandle<LiveBool.Listener> disabledListener;
39
+	private final DSimpleTooltip tooltip;
37 40
 	
38 41
 	private DUIContext context;
39 42
 	private IconButtonControlStyle style;
@@ -43,22 +46,25 @@ public class IconButtonControl implements DComponent {
43 46
 	private boolean press;
44 47
 	private DPath shape;
45 48
 	
46
-	public IconButtonControl(DStyleClass styleClass, DDrawable icon, DDrawable iconDisabled, LiveBool disabled, Consumer<DMouseEvent> onClick) {
49
+	public IconButtonControl(DStyleClass styleClass, DDrawable icon, DDrawable iconDisabled, LiveBool disabled, LiveString tooltip, Consumer<DMouseEvent> onClick) {
47 50
 		this.styleClass = styleClass;
48 51
 		this.icon = icon;
49 52
 		this.iconDisabled = iconDisabled;
50 53
 		this.onClick = onClick;
51 54
 		this.disabled = disabled;
55
+		this.tooltip = new DSimpleTooltip(DStyleClass.EMPTY, tooltip);
52 56
 		disabledListener = disabled.addListener((oldValue, newValue) -> repaint());
53 57
 	}
54 58
 	
55
-	public IconButtonControl(DStyleClass styleClass, DDrawable icon, Consumer<DMouseEvent> onClick) {
56
-		this(styleClass, icon, icon, ImmutableLiveBool.FALSE, onClick);
59
+	public IconButtonControl(DStyleClass styleClass, DDrawable icon, LiveString tooltip, Consumer<DMouseEvent> onClick) {
60
+		this(styleClass, icon, icon, ImmutableLiveBool.FALSE, tooltip, onClick);
57 61
 	}
58 62
 
59 63
 	@Override
60 64
 	public void setContext(DStylePath parent, DUIContext context) {
61 65
 		this.context = context;
66
+		tooltip.setContext(context);
67
+		
62 68
 		DStylePath path = parent.getChild("iconbutton", styleClass);
63 69
 		style = new IconButtonControlStyle(context.getStylesheets().get(context, path));
64 70
 		
@@ -132,6 +138,7 @@ public class IconButtonControl implements DComponent {
132 138
 	public void onMouseEnter(DMouseEvent e) {
133 139
 		hover = true;
134 140
 		repaint();
141
+		tooltip.onTargetMouseEnter(e);
135 142
 	}
136 143
 	
137 144
 	@Override
@@ -139,6 +146,12 @@ public class IconButtonControl implements DComponent {
139 146
 		hover = false;
140 147
 		press = false;
141 148
 		repaint();
149
+		tooltip.onTargetMouseExit(e);
150
+	}
151
+	
152
+	@Override
153
+	public void onMouseMove(DMouseEvent e) {
154
+		tooltip.onTargetMouseMove(e);
142 155
 	}
143 156
 	
144 157
 	@Override

+ 7
- 3
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/aspectbar/AspectBarSelectorButton.java Просмотреть файл

@@ -42,7 +42,7 @@ public class AspectBarSelectorButton implements DComponent {
42 42
 	private DPath shape;
43 43
 	private boolean hovering;
44 44
 	private boolean pressing;
45
-	private DSimpleTooltip tooltip;
45
+	private final DSimpleTooltip tooltip;
46 46
 	
47 47
 	private final ListenerHandle<LiveBool.Listener> activeListener;
48 48
 	
@@ -69,7 +69,7 @@ public class AspectBarSelectorButton implements DComponent {
69 69
 				style.height,
70 70
 				style.roundingRadius);
71 71
 		
72
-		tooltip.setContext(parent, context);
72
+		tooltip.setContext(context);
73 73
 	}
74 74
 
75 75
 	@Override
@@ -119,7 +119,6 @@ public class AspectBarSelectorButton implements DComponent {
119 119
 				bounds.x + (style.width - icon.getNominalWidth() * context.getScale()) / 2,
120 120
 				bounds.y + (style.height - icon.getNominalHeight() * context.getScale()) / 2,
121 121
 				context.getScale()));
122
-		tooltip.paint(canvas);
123 122
 	}
124 123
 	
125 124
 	@Override
@@ -129,6 +128,11 @@ public class AspectBarSelectorButton implements DComponent {
129 128
 		repaint();
130 129
 	}
131 130
 	
131
+	@Override
132
+	public void onMouseMove(DMouseEvent e) {
133
+		tooltip.onTargetMouseMove(e);
134
+	}
135
+	
132 136
 	@Override
133 137
 	public void onMouseExit(DMouseEvent e) {
134 138
 		hovering = false;

+ 2
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java Просмотреть файл

@@ -19,7 +19,6 @@ import org.openzen.drawablegui.DTimerHandle;
19 19
 import org.openzen.drawablegui.DTransform2D;
20 20
 import org.openzen.drawablegui.listeners.ListenerHandle;
21 21
 import org.openzen.drawablegui.live.LiveObject;
22
-import org.openzen.drawablegui.live.SimpleLiveObject;
23 22
 import org.openzen.zenscript.ide.host.IDESourceFile;
24 23
 import org.openzen.zenscript.ide.ui.IDEAspectToolbar;
25 24
 import org.openzen.zenscript.ide.ui.IDEWindow;
@@ -29,6 +28,7 @@ import org.openzen.zenscript.lexer.ZSToken;
29 28
 import org.openzen.zenscript.lexer.ZSTokenParser;
30 29
 import org.openzen.zenscript.lexer.ZSTokenType;
31 30
 import org.openzen.drawablegui.DUIContext;
31
+import org.openzen.drawablegui.live.ImmutableLiveString;
32 32
 import org.openzen.drawablegui.live.MutableLiveObject;
33 33
 import org.openzen.drawablegui.live.SimpleLiveBool;
34 34
 import org.openzen.drawablegui.style.DStyleClass;
@@ -83,7 +83,7 @@ public class SourceEditor implements DComponent {
83 83
 		tokens = new TokenModel(sourceFile.getName(), tab.length());
84 84
 		tokenListener = tokens.addListener(new TokenListener());
85 85
 		
86
-		editToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, ShadedSaveIcon.PURPLE, SaveIcon.GREY, unchanged, e -> save()));
86
+		editToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, ShadedSaveIcon.PURPLE, SaveIcon.GREY, unchanged, new ImmutableLiveString("Save file"), e -> save()));
87 87
 		
88 88
 		try {
89 89
 			TokenParser<ZSToken, ZSTokenType> parser = ZSTokenParser.createRaw(

Загрузка…
Отмена
Сохранить