|
1 | 1 | package com.ray3k.stripe;
|
2 | 2 |
|
| 3 | +import com.badlogic.gdx.Gdx; |
3 | 4 | import com.badlogic.gdx.graphics.g2d.Batch;
|
4 | 5 | import com.badlogic.gdx.math.MathUtils;
|
5 | 6 | import com.badlogic.gdx.math.Vector2;
|
@@ -45,6 +46,8 @@ public class PopTable extends Table {
|
45 | 46 | private float highlightAlpha = 1f;
|
46 | 47 | private boolean draggable;
|
47 | 48 | private boolean suppressKeyInputListeners;
|
| 49 | + private boolean attachToMouse; |
| 50 | + private int attachToMouseAlignment; |
48 | 51 |
|
49 | 52 | public PopTable() {
|
50 | 53 | this(new PopTableStyle());
|
@@ -528,6 +531,19 @@ public void setDraggable(boolean draggable) {
|
528 | 531 | this.draggable = draggable;
|
529 | 532 | }
|
530 | 533 |
|
| 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 | + |
531 | 547 | public PopTableStyle getStyle() {
|
532 | 548 | return style;
|
533 | 549 | }
|
@@ -574,6 +590,17 @@ public void setFillParent(boolean fillParent) {
|
574 | 590 | this.fillParent = fillParent;
|
575 | 591 | }
|
576 | 592 |
|
| 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 | + |
577 | 604 | @Override
|
578 | 605 | public void draw(Batch batch, float parentAlpha) {
|
579 | 606 | if (highlightActor != null) {
|
|
0 commit comments