mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Lock input while refreshing images
This commit is contained in:
@@ -26,6 +26,7 @@ import javax.swing.JComponent;
|
|||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JViewport;
|
import javax.swing.JViewport;
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import forge.ImageCache;
|
import forge.ImageCache;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -72,6 +73,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
private ColumnDef pileBy = null;
|
private ColumnDef pileBy = null;
|
||||||
private GroupDef groupBy = null;
|
private GroupDef groupBy = null;
|
||||||
private boolean lockHoveredItem = false;
|
private boolean lockHoveredItem = false;
|
||||||
|
private boolean lockInput = false;
|
||||||
private Point hoverPoint;
|
private Point hoverPoint;
|
||||||
private Point hoverScrollPos;
|
private Point hoverScrollPos;
|
||||||
private ItemInfo hoveredItem;
|
private ItemInfo hoveredItem;
|
||||||
@@ -225,6 +227,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
display.addMouseListener(new FMouseAdapter() {
|
display.addMouseListener(new FMouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void onLeftMouseDown(MouseEvent e) {
|
public void onLeftMouseDown(MouseEvent e) {
|
||||||
|
if (lockInput) { return; }
|
||||||
|
|
||||||
if (!selectItem(e)) {
|
if (!selectItem(e)) {
|
||||||
//if didn't click on item, see if clicked on group header
|
//if didn't click on item, see if clicked on group header
|
||||||
if (groupBy != null) {
|
if (groupBy != null) {
|
||||||
@@ -246,6 +250,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLeftDoubleClick(MouseEvent e) {
|
public void onLeftDoubleClick(MouseEvent e) {
|
||||||
|
if (lockInput) { return; }
|
||||||
|
|
||||||
ItemInfo item = getItemAtPoint(e.getPoint());
|
ItemInfo item = getItemAtPoint(e.getPoint());
|
||||||
if (item != null && item.selected) {
|
if (item != null && item.selected) {
|
||||||
itemManager.activateSelectedItems();
|
itemManager.activateSelectedItems();
|
||||||
@@ -254,6 +260,8 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMiddleMouseDown(MouseEvent e) {
|
public void onMiddleMouseDown(MouseEvent e) {
|
||||||
|
if (lockInput) { return; }
|
||||||
|
|
||||||
ItemInfo item = getItemAtPoint(e.getPoint());
|
ItemInfo item = getItemAtPoint(e.getPoint());
|
||||||
if (item != null && item.item instanceof IPaperCard) {
|
if (item != null && item.item instanceof IPaperCard) {
|
||||||
setLockHoveredItem(true); //lock hoveredItem while zoomer open
|
setLockHoveredItem(true); //lock hoveredItem while zoomer open
|
||||||
@@ -264,12 +272,16 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMiddleMouseUp(MouseEvent e) {
|
public void onMiddleMouseUp(MouseEvent e) {
|
||||||
|
if (lockInput) { return; }
|
||||||
|
|
||||||
CardZoomer.SINGLETON_INSTANCE.closeZoomer();
|
CardZoomer.SINGLETON_INSTANCE.closeZoomer();
|
||||||
setLockHoveredItem(false);
|
setLockHoveredItem(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRightClick(MouseEvent e) {
|
public void onRightClick(MouseEvent e) {
|
||||||
|
if (lockInput) { return; }
|
||||||
|
|
||||||
if (selectItem(e)) {
|
if (selectItem(e)) {
|
||||||
setLockHoveredItem(true); //lock hoveredItem while context menu open
|
setLockHoveredItem(true); //lock hoveredItem while context menu open
|
||||||
itemManager.showContextMenu(e, new Runnable() {
|
itemManager.showContextMenu(e, new Runnable() {
|
||||||
@@ -524,6 +536,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateLayout(boolean forRefresh) {
|
private void updateLayout(boolean forRefresh) {
|
||||||
|
lockInput = true; //lock input until next repaint finishes
|
||||||
focalItem = null; //clear cached focalItem when layout changes
|
focalItem = null; //clear cached focalItem when layout changes
|
||||||
|
|
||||||
int x, groupY, pileY, pileHeight, maxPileHeight;
|
int x, groupY, pileY, pileHeight, maxPileHeight;
|
||||||
@@ -1043,6 +1056,15 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
drawItemImage(g2d, skippedItem);
|
drawItemImage(g2d, skippedItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lockInput) { //unlock input after repaint finishes if needed
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
lockInput = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawItemImage(Graphics2D g, ItemInfo itemInfo) {
|
private void drawItemImage(Graphics2D g, ItemInfo itemInfo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user