Browse code

add onMouseHover event

bob authored on 26/07/2014 at 10:14:24
Showing 3 changed files
... ...
@@ -215,13 +215,14 @@ public class NuitToolkit extends Toolkit<Widget, Table> {
215 215
         }
216 216
 
217 217
         controls.pollPointer(root.getWidth(), root.getHeight(), pointer);
218
+        root.onMouseHover(pointer.getX(), pointer.getY(), pointer.isDown());
218 219
         if (pointer.getX() != oldPointerX || pointer.getY() != oldPointerY) {
219 220
             root.onMouseMove(pointer.getX(), pointer.getY());
220 221
         }
221 222
         oldPointerX = pointer.getX();
222 223
         oldPointerY = pointer.getY();
223 224
         boolean isMouseButtonDown = pointer.isDown();
224
-        if (isMouseButtonDown && Boolean.FALSE == oldIsMouseButtonDown) {
225
+        if (isMouseButtonDown && Boolean.FALSE.equals(oldIsMouseButtonDown)) {
225 226
             root.onMouseClick(pointer.getX(), pointer.getY());
226 227
         }
227 228
         oldIsMouseButtonDown = isMouseButtonDown;
... ...
@@ -308,5 +309,4 @@ public class NuitToolkit extends Toolkit<Widget, Table> {
308 308
         }
309 309
         return pressAnyKeyAction;
310 310
     }
311
-
312 311
 }
... ...
@@ -28,6 +28,7 @@ import java.util.List;
28 28
 
29 29
 /**
30 30
  * Stack layout widget container: only the top widget is show.
31
+ *
31 32
  * @author devnewton
32 33
  */
33 34
 public class Stack extends Widget {
... ...
@@ -91,6 +92,14 @@ public class Stack extends Widget {
91 91
     }
92 92
 
93 93
     @Override
94
+    public void onMouseHover(float mouseX, float mouseY, boolean mouseButtonDown) {
95
+        Widget child = getFocusedChild();
96
+        if (null != child) {
97
+            child.onMouseHover(mouseX, mouseY, mouseButtonDown);
98
+        }
99
+    }
100
+
101
+    @Override
94 102
     public void onMouseMove(float mouseX, float mouseY) {
95 103
         Widget child = getFocusedChild();
96 104
         if (null != child) {
... ...
@@ -412,6 +412,14 @@ public abstract class Widget {
412 412
         }
413 413
     }
414 414
 
415
+    public void onMouseHover(float mouseX, float mouseY, boolean mouseButtonDown) {
416
+        for (Widget child : children) {
417
+            if (mouseX >= child.getX() && mouseX <= (child.getX() + child.getWidth()) && mouseY >= child.getY() && mouseY <= (child.getY() + child.getHeight())) {
418
+                child.onMouseHover(mouseX, mouseY, mouseButtonDown);
419
+            }
420
+        }
421
+    }
422
+
415 423
     public void onMouseMove(float mouseX, float mouseY) {
416 424
         for (Widget child : children) {
417 425
             if (mouseX >= child.getX() && mouseX <= (child.getX() + child.getWidth()) && mouseY >= child.getY() && mouseY <= (child.getY() + child.getHeight())) {