mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Add middle (and left+right) click zoom support to Image View
This commit is contained in:
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package forge.gui.match.controllers;
|
package forge.gui.match.controllers;
|
||||||
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelEvent;
|
||||||
import java.awt.event.MouseWheelListener;
|
import java.awt.event.MouseWheelListener;
|
||||||
@@ -31,6 +30,7 @@ import forge.game.card.Card;
|
|||||||
import forge.gui.CardPicturePanel;
|
import forge.gui.CardPicturePanel;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
import forge.gui.match.views.VPicture;
|
import forge.gui.match.views.VPicture;
|
||||||
|
import forge.gui.toolbox.FMouseAdapter;
|
||||||
import forge.gui.toolbox.special.CardZoomer;
|
import forge.gui.toolbox.special.CardZoomer;
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
@@ -118,46 +118,23 @@ public enum CPicture implements ICDoc {
|
|||||||
* <li>Displays the alternate image for applicable cards on mouse click.
|
* <li>Displays the alternate image for applicable cards on mouse click.
|
||||||
*/
|
*/
|
||||||
private void setMouseButtonListener() {
|
private void setMouseButtonListener() {
|
||||||
this.picturePanel.addMouseListener(new MouseAdapter() {
|
this.picturePanel.addMouseListener(new FMouseAdapter() {
|
||||||
private final boolean[] buttonsDown = new boolean[4];
|
@Override
|
||||||
|
public void onLeftClick(MouseEvent e) {
|
||||||
|
flipCard();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(final MouseEvent e) {
|
public void onMiddleMouseDown(MouseEvent e) {
|
||||||
if (isCardDisplayed()) {
|
if (isCardDisplayed()) {
|
||||||
final int button = e.getButton();
|
CardZoomer.SINGLETON_INSTANCE.doMouseButtonZoom(currentCard, displayedState);
|
||||||
if (button < 1 || button > 3) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.buttonsDown[button] = true;
|
|
||||||
if (this.buttonsDown[2] || (this.buttonsDown[1] && this.buttonsDown[3])) {
|
|
||||||
zoomer.doMouseButtonZoom(currentCard, displayedState);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseReleased(final MouseEvent e) {
|
public void onMiddleMouseUp(MouseEvent e) {
|
||||||
if (isCardDisplayed()) {
|
if (isCardDisplayed()) {
|
||||||
final int button = e.getButton();
|
CardZoomer.SINGLETON_INSTANCE.closeZoomer();
|
||||||
if (button < 1 || button > 3) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!this.buttonsDown[button]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.buttonsDown[button] = false;
|
|
||||||
|
|
||||||
if (zoomer.isZoomerOpen()) {
|
|
||||||
if (!this.buttonsDown[1] && !this.buttonsDown[2] && !this.buttonsDown[3]) {
|
|
||||||
//don't stop zooming until all mouse buttons released
|
|
||||||
zoomer.closeZoomer();
|
|
||||||
}
|
|
||||||
return; //don't handle click event below if zoom was open
|
|
||||||
}
|
|
||||||
|
|
||||||
if (button == 1) {
|
|
||||||
flipCard();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -219,10 +196,10 @@ public enum CPicture implements ICDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCurrentCardFlippable() {
|
private boolean isCurrentCardFlippable() {
|
||||||
boolean isFlippableMorph =
|
if (currentCard == null) { return false; }
|
||||||
currentCard.isFaceDown() && isAuthorizedToViewFaceDownCard(currentCard);
|
|
||||||
return (currentCard != null) &
|
return currentCard.isDoubleFaced() || currentCard.isFlipCard() ||
|
||||||
(currentCard.isDoubleFaced() || currentCard.isFlipCard() || isFlippableMorph);
|
(currentCard.isFaceDown() && isAuthorizedToViewFaceDownCard(currentCard));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,14 +36,14 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
|
|
||||||
public void onMouseEnter(MouseEvent e) {}
|
public void onMouseEnter(MouseEvent e) {}
|
||||||
public void onMouseExit(MouseEvent e) {}
|
public void onMouseExit(MouseEvent e) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forge Mouse Adapter with infinite click tolerance (so long as mouse doesn't leave component)
|
* Forge Mouse Adapter with infinite click tolerance (so long as mouse doesn't leave component)
|
||||||
*/
|
*/
|
||||||
public FMouseAdapter() {
|
public FMouseAdapter() {
|
||||||
this(false);
|
this(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FMouseAdapter(boolean isCompDraggable0) {
|
public FMouseAdapter(boolean isCompDraggable0) {
|
||||||
isCompDraggable = isCompDraggable0;
|
isCompDraggable = isCompDraggable0;
|
||||||
}
|
}
|
||||||
@@ -52,25 +52,38 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
private boolean hovered;
|
private boolean hovered;
|
||||||
private Point mouseDownLoc;
|
private Point mouseDownLoc;
|
||||||
private Point firstClickLoc;
|
private Point firstClickLoc;
|
||||||
private int firstClickButton;
|
private int downButton, buttonsDown, firstClickButton;
|
||||||
private Component tempMotionListenerComp;
|
private Component tempMotionListenerComp;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void mousePressed(final MouseEvent e) {
|
public final void mousePressed(final MouseEvent e) {
|
||||||
switch (e.getButton()) {
|
final int button = e.getButton();
|
||||||
case 1:
|
if (button < 1 || button > 3) {
|
||||||
onLeftMouseDown(e);
|
return;
|
||||||
break;
|
}
|
||||||
case 2:
|
if (downButton == 0) {
|
||||||
onMiddleMouseDown(e);
|
downButton = button;
|
||||||
break;
|
switch (button) {
|
||||||
case 3:
|
case 1:
|
||||||
onRightMouseDown(e);
|
onLeftMouseDown(e);
|
||||||
break;
|
break;
|
||||||
|
case 2:
|
||||||
|
onMiddleMouseDown(e);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
onRightMouseDown(e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonsDown += button;
|
||||||
|
if (buttonsDown == 4 && downButton != 2) {
|
||||||
|
downButton = 2;
|
||||||
|
onMiddleMouseDown(e); //treat left and right together as equivalent of middle
|
||||||
}
|
}
|
||||||
|
|
||||||
mouseDownLoc = e.getLocationOnScreen();
|
mouseDownLoc = e.getLocationOnScreen();
|
||||||
|
|
||||||
//if component is draggable, ensure this adapter added as mouse motion listener to component while mouse down
|
//if component is draggable, ensure this adapter added as mouse motion listener to component while mouse down
|
||||||
if (isCompDraggable) {
|
if (isCompDraggable) {
|
||||||
tempMotionListenerComp = e.getComponent();
|
tempMotionListenerComp = e.getComponent();
|
||||||
@@ -90,7 +103,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
if (firstClickLoc != null) {
|
if (firstClickLoc != null) {
|
||||||
//if first mouse down resulted in click and second mouse down with same button in close proximity,
|
//if first mouse down resulted in click and second mouse down with same button in close proximity,
|
||||||
//handle double click event (don't wait until second mouse up to improve responsiveness)
|
//handle double click event (don't wait until second mouse up to improve responsiveness)
|
||||||
if (e.getClickCount() % 2 == 0 && e.getButton() == firstClickButton &&
|
if (e.getClickCount() % 2 == 0 && downButton == firstClickButton &&
|
||||||
e.getLocationOnScreen().distance(firstClickLoc) <= 3) {
|
e.getLocationOnScreen().distance(firstClickLoc) <= 3) {
|
||||||
switch (firstClickButton) {
|
switch (firstClickButton) {
|
||||||
case 1:
|
case 1:
|
||||||
@@ -108,7 +121,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
firstClickButton = 0;
|
firstClickButton = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void mouseDragged(MouseEvent e) {
|
public final void mouseDragged(MouseEvent e) {
|
||||||
//clear mouse down location if component begins being dragged
|
//clear mouse down location if component begins being dragged
|
||||||
@@ -117,7 +130,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
resetMouseDownLoc();
|
resetMouseDownLoc();
|
||||||
}
|
}
|
||||||
if (tempMotionListenerComp == null) { //don't raise drag event if only a temporary motion listener
|
if (tempMotionListenerComp == null) { //don't raise drag event if only a temporary motion listener
|
||||||
switch (e.getButton()) {
|
switch (downButton) {
|
||||||
case 1:
|
case 1:
|
||||||
onLeftMouseDragging(e);
|
onLeftMouseDragging(e);
|
||||||
break;
|
break;
|
||||||
@@ -130,19 +143,19 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void mouseEntered(MouseEvent e) {
|
public final void mouseEntered(MouseEvent e) {
|
||||||
hovered = true;
|
hovered = true;
|
||||||
onMouseEnter(e);
|
onMouseEnter(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void mouseExited(MouseEvent e) {
|
public final void mouseExited(MouseEvent e) {
|
||||||
hovered = false;
|
hovered = false;
|
||||||
onMouseExit(e);
|
onMouseExit(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetMouseDownLoc() {
|
private void resetMouseDownLoc() {
|
||||||
mouseDownLoc = null;
|
mouseDownLoc = null;
|
||||||
if (tempMotionListenerComp != null) {
|
if (tempMotionListenerComp != null) {
|
||||||
@@ -153,7 +166,17 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void mouseReleased(MouseEvent e) {
|
public final void mouseReleased(MouseEvent e) {
|
||||||
switch (e.getButton()) {
|
int button = e.getButton();
|
||||||
|
if (button < 1 || button > 3 || downButton == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
buttonsDown -= button;
|
||||||
|
if (buttonsDown > 0) { return; } //don't handle mouse up until all mouse buttons up
|
||||||
|
|
||||||
|
button = downButton;
|
||||||
|
downButton = 0;
|
||||||
|
|
||||||
|
switch (button) {
|
||||||
case 1:
|
case 1:
|
||||||
onLeftMouseUp(e);
|
onLeftMouseUp(e);
|
||||||
break;
|
break;
|
||||||
@@ -164,7 +187,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
onRightMouseUp(e);
|
onRightMouseUp(e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hovered) { //reset mouse down location and don't handle click if mouse up outside component
|
if (!hovered) { //reset mouse down location and don't handle click if mouse up outside component
|
||||||
resetMouseDownLoc();
|
resetMouseDownLoc();
|
||||||
}
|
}
|
||||||
@@ -173,13 +196,13 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
if (mouseDownLoc != null) {
|
if (mouseDownLoc != null) {
|
||||||
//if first click, cache button and mouse down location for determination of double click later
|
//if first click, cache button and mouse down location for determination of double click later
|
||||||
if (e.getClickCount() % 2 == 1) {
|
if (e.getClickCount() % 2 == 1) {
|
||||||
firstClickButton = e.getButton();
|
firstClickButton = button;
|
||||||
firstClickLoc = mouseDownLoc;
|
firstClickLoc = mouseDownLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
resetMouseDownLoc();
|
resetMouseDownLoc();
|
||||||
|
|
||||||
switch (e.getButton()) {
|
switch (button) {
|
||||||
case 1:
|
case 1:
|
||||||
onLeftClick(e);
|
onLeftClick(e);
|
||||||
break;
|
break;
|
||||||
@@ -192,7 +215,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isCompDraggable) { //handle drag drop if click not handled and component is draggable
|
else if (isCompDraggable) { //handle drag drop if click not handled and component is draggable
|
||||||
switch (e.getButton()) {
|
switch (button) {
|
||||||
case 1:
|
case 1:
|
||||||
onLeftMouseDragDrop(e);
|
onLeftMouseDragDrop(e);
|
||||||
break;
|
break;
|
||||||
@@ -205,7 +228,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void mouseClicked(MouseEvent e) {
|
public final void mouseClicked(MouseEvent e) {
|
||||||
//override mouseClicked as final to prevent it being used since it doesn't fire
|
//override mouseClicked as final to prevent it being used since it doesn't fire
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import javax.swing.JViewport;
|
|||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
|
|
||||||
import forge.ImageCache;
|
import forge.ImageCache;
|
||||||
|
import forge.game.card.Card;
|
||||||
import forge.gui.deckeditor.DeckProxy;
|
import forge.gui.deckeditor.DeckProxy;
|
||||||
import forge.gui.framework.ILocalRepaint;
|
import forge.gui.framework.ILocalRepaint;
|
||||||
import forge.gui.match.controllers.CDetail;
|
import forge.gui.match.controllers.CDetail;
|
||||||
@@ -37,6 +38,8 @@ import forge.gui.toolbox.FSkin.SkinFont;
|
|||||||
import forge.gui.toolbox.FSkin.SkinImage;
|
import forge.gui.toolbox.FSkin.SkinImage;
|
||||||
import forge.gui.toolbox.itemmanager.ItemManager;
|
import forge.gui.toolbox.itemmanager.ItemManager;
|
||||||
import forge.gui.toolbox.itemmanager.ItemManagerModel;
|
import forge.gui.toolbox.itemmanager.ItemManagerModel;
|
||||||
|
import forge.gui.toolbox.special.CardZoomer;
|
||||||
|
import forge.item.IPaperCard;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.view.arcane.CardPanel;
|
import forge.view.arcane.CardPanel;
|
||||||
|
|
||||||
@@ -88,11 +91,26 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLeftDoubleClick(MouseEvent e) {
|
public void onLeftDoubleClick(MouseEvent e) {
|
||||||
if (hoveredItem != null && hoveredItem.selected) {
|
ItemInfo item = getItemAtPoint(e.getPoint());
|
||||||
|
if (item != null && item.selected) {
|
||||||
itemManager.activateSelectedItems();
|
itemManager.activateSelectedItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMiddleMouseDown(MouseEvent e) {
|
||||||
|
ItemInfo item = getItemAtPoint(e.getPoint());
|
||||||
|
if (item != null && item.item instanceof IPaperCard) {
|
||||||
|
Card card = Card.getCardForUi((IPaperCard) item.item);
|
||||||
|
CardZoomer.SINGLETON_INSTANCE.doMouseButtonZoom(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMiddleMouseUp(MouseEvent e) {
|
||||||
|
CardZoomer.SINGLETON_INSTANCE.closeZoomer();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRightClick(MouseEvent e) {
|
public void onRightClick(MouseEvent e) {
|
||||||
selectItem(e);
|
selectItem(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user