mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +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;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
@@ -31,6 +30,7 @@ import forge.game.card.Card;
|
||||
import forge.gui.CardPicturePanel;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.gui.match.views.VPicture;
|
||||
import forge.gui.toolbox.FMouseAdapter;
|
||||
import forge.gui.toolbox.special.CardZoomer;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
@@ -118,46 +118,23 @@ public enum CPicture implements ICDoc {
|
||||
* <li>Displays the alternate image for applicable cards on mouse click.
|
||||
*/
|
||||
private void setMouseButtonListener() {
|
||||
this.picturePanel.addMouseListener(new MouseAdapter() {
|
||||
private final boolean[] buttonsDown = new boolean[4];
|
||||
this.picturePanel.addMouseListener(new FMouseAdapter() {
|
||||
@Override
|
||||
public void onLeftClick(MouseEvent e) {
|
||||
flipCard();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
public void onMiddleMouseDown(MouseEvent e) {
|
||||
if (isCardDisplayed()) {
|
||||
final int button = e.getButton();
|
||||
if (button < 1 || button > 3) {
|
||||
return;
|
||||
}
|
||||
this.buttonsDown[button] = true;
|
||||
if (this.buttonsDown[2] || (this.buttonsDown[1] && this.buttonsDown[3])) {
|
||||
zoomer.doMouseButtonZoom(currentCard, displayedState);
|
||||
}
|
||||
CardZoomer.SINGLETON_INSTANCE.doMouseButtonZoom(currentCard, displayedState);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(final MouseEvent e) {
|
||||
public void onMiddleMouseUp(MouseEvent e) {
|
||||
if (isCardDisplayed()) {
|
||||
final int button = e.getButton();
|
||||
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();
|
||||
}
|
||||
CardZoomer.SINGLETON_INSTANCE.closeZoomer();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -219,10 +196,10 @@ public enum CPicture implements ICDoc {
|
||||
}
|
||||
|
||||
private boolean isCurrentCardFlippable() {
|
||||
boolean isFlippableMorph =
|
||||
currentCard.isFaceDown() && isAuthorizedToViewFaceDownCard(currentCard);
|
||||
return (currentCard != null) &
|
||||
(currentCard.isDoubleFaced() || currentCard.isFlipCard() || isFlippableMorph);
|
||||
if (currentCard == null) { return false; }
|
||||
|
||||
return currentCard.isDoubleFaced() || currentCard.isFlipCard() ||
|
||||
(currentCard.isFaceDown() && isAuthorizedToViewFaceDownCard(currentCard));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,14 +36,14 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
|
||||
public void onMouseEnter(MouseEvent e) {}
|
||||
public void onMouseExit(MouseEvent e) {}
|
||||
|
||||
|
||||
/**
|
||||
* Forge Mouse Adapter with infinite click tolerance (so long as mouse doesn't leave component)
|
||||
*/
|
||||
public FMouseAdapter() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
|
||||
public FMouseAdapter(boolean isCompDraggable0) {
|
||||
isCompDraggable = isCompDraggable0;
|
||||
}
|
||||
@@ -52,25 +52,38 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
private boolean hovered;
|
||||
private Point mouseDownLoc;
|
||||
private Point firstClickLoc;
|
||||
private int firstClickButton;
|
||||
private int downButton, buttonsDown, firstClickButton;
|
||||
private Component tempMotionListenerComp;
|
||||
|
||||
@Override
|
||||
public final void mousePressed(final MouseEvent e) {
|
||||
switch (e.getButton()) {
|
||||
case 1:
|
||||
onLeftMouseDown(e);
|
||||
break;
|
||||
case 2:
|
||||
onMiddleMouseDown(e);
|
||||
break;
|
||||
case 3:
|
||||
onRightMouseDown(e);
|
||||
break;
|
||||
final int button = e.getButton();
|
||||
if (button < 1 || button > 3) {
|
||||
return;
|
||||
}
|
||||
if (downButton == 0) {
|
||||
downButton = button;
|
||||
switch (button) {
|
||||
case 1:
|
||||
onLeftMouseDown(e);
|
||||
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();
|
||||
|
||||
|
||||
//if component is draggable, ensure this adapter added as mouse motion listener to component while mouse down
|
||||
if (isCompDraggable) {
|
||||
tempMotionListenerComp = e.getComponent();
|
||||
@@ -90,7 +103,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
if (firstClickLoc != null) {
|
||||
//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)
|
||||
if (e.getClickCount() % 2 == 0 && e.getButton() == firstClickButton &&
|
||||
if (e.getClickCount() % 2 == 0 && downButton == firstClickButton &&
|
||||
e.getLocationOnScreen().distance(firstClickLoc) <= 3) {
|
||||
switch (firstClickButton) {
|
||||
case 1:
|
||||
@@ -108,7 +121,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
firstClickButton = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void mouseDragged(MouseEvent e) {
|
||||
//clear mouse down location if component begins being dragged
|
||||
@@ -117,7 +130,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
resetMouseDownLoc();
|
||||
}
|
||||
if (tempMotionListenerComp == null) { //don't raise drag event if only a temporary motion listener
|
||||
switch (e.getButton()) {
|
||||
switch (downButton) {
|
||||
case 1:
|
||||
onLeftMouseDragging(e);
|
||||
break;
|
||||
@@ -130,19 +143,19 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void mouseEntered(MouseEvent e) {
|
||||
hovered = true;
|
||||
onMouseEnter(e);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void mouseExited(MouseEvent e) {
|
||||
hovered = false;
|
||||
onMouseExit(e);
|
||||
}
|
||||
|
||||
|
||||
private void resetMouseDownLoc() {
|
||||
mouseDownLoc = null;
|
||||
if (tempMotionListenerComp != null) {
|
||||
@@ -153,7 +166,17 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
|
||||
@Override
|
||||
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:
|
||||
onLeftMouseUp(e);
|
||||
break;
|
||||
@@ -164,7 +187,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
onRightMouseUp(e);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!hovered) { //reset mouse down location and don't handle click if mouse up outside component
|
||||
resetMouseDownLoc();
|
||||
}
|
||||
@@ -173,13 +196,13 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
if (mouseDownLoc != null) {
|
||||
//if first click, cache button and mouse down location for determination of double click later
|
||||
if (e.getClickCount() % 2 == 1) {
|
||||
firstClickButton = e.getButton();
|
||||
firstClickButton = button;
|
||||
firstClickLoc = mouseDownLoc;
|
||||
}
|
||||
|
||||
resetMouseDownLoc();
|
||||
|
||||
switch (e.getButton()) {
|
||||
switch (button) {
|
||||
case 1:
|
||||
onLeftClick(e);
|
||||
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
|
||||
switch (e.getButton()) {
|
||||
switch (button) {
|
||||
case 1:
|
||||
onLeftMouseDragDrop(e);
|
||||
break;
|
||||
@@ -205,7 +228,7 @@ public abstract class FMouseAdapter extends MouseAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void mouseClicked(MouseEvent e) {
|
||||
//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 forge.ImageCache;
|
||||
import forge.game.card.Card;
|
||||
import forge.gui.deckeditor.DeckProxy;
|
||||
import forge.gui.framework.ILocalRepaint;
|
||||
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.itemmanager.ItemManager;
|
||||
import forge.gui.toolbox.itemmanager.ItemManagerModel;
|
||||
import forge.gui.toolbox.special.CardZoomer;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.view.arcane.CardPanel;
|
||||
|
||||
@@ -88,11 +91,26 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
@Override
|
||||
public void onLeftDoubleClick(MouseEvent e) {
|
||||
if (hoveredItem != null && hoveredItem.selected) {
|
||||
ItemInfo item = getItemAtPoint(e.getPoint());
|
||||
if (item != null && item.selected) {
|
||||
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
|
||||
public void onRightClick(MouseEvent e) {
|
||||
selectItem(e);
|
||||
|
||||
Reference in New Issue
Block a user