Skip to content

Commit 6a3667c

Browse files
committed
Added option to attach a PopTable to the position of the mouse.
1 parent c1bb3a4 commit 6a3667c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### 1.4.0
22
* Added ColorPicker widget.
33
* Added option to disable centering when layout is called in ResizeWidget.
4+
* Added option to attach a PopTable to the position of the mouse.
45
* Added ability to supress key listeners in PopTable.
56
* Added methods to set/get the stage background for PopTable.
67
* Added method to get the parent group that PopTable belongs to.

stripe/src/com/ray3k/stripe/PopTable.java

+27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ray3k.stripe;
22

3+
import com.badlogic.gdx.Gdx;
34
import com.badlogic.gdx.graphics.g2d.Batch;
45
import com.badlogic.gdx.math.MathUtils;
56
import com.badlogic.gdx.math.Vector2;
@@ -45,6 +46,8 @@ public class PopTable extends Table {
4546
private float highlightAlpha = 1f;
4647
private boolean draggable;
4748
private boolean suppressKeyInputListeners;
49+
private boolean attachToMouse;
50+
private int attachToMouseAlignment;
4851

4952
public PopTable() {
5053
this(new PopTableStyle());
@@ -528,6 +531,19 @@ public void setDraggable(boolean draggable) {
528531
this.draggable = draggable;
529532
}
530533

534+
public boolean isAttachToMouse() {
535+
return attachToMouse;
536+
}
537+
538+
public void setAttachToMouse(boolean attachToMouse) {
539+
setAttachToMouse(attachToMouse, Align.bottomLeft);
540+
}
541+
542+
public void setAttachToMouse(boolean attachToMouse, int alignment) {
543+
this.attachToMouse = attachToMouse;
544+
attachToMouseAlignment = alignment;
545+
}
546+
531547
public PopTableStyle getStyle() {
532548
return style;
533549
}
@@ -574,6 +590,17 @@ public void setFillParent(boolean fillParent) {
574590
this.fillParent = fillParent;
575591
}
576592

593+
private static final Vector2 mousePosition = new Vector2();
594+
@Override
595+
public void act(float delta) {
596+
super.act(delta);
597+
if (attachToMouse) {
598+
mousePosition.set(Gdx.input.getX(), Gdx.input.getY());
599+
group.screenToLocalCoordinates(mousePosition);
600+
setPosition(mousePosition.x, mousePosition.y, attachToMouseAlignment);
601+
}
602+
}
603+
577604
@Override
578605
public void draw(Batch batch, float parentAlpha) {
579606
if (highlightActor != null) {

0 commit comments

Comments
 (0)