click on a split card image in explorer to view at correct orientation (see #782).
parent
f45116a824
commit
1005b84c8f
|
@ -2,6 +2,7 @@ package magic.ui.widget.cards.canvas;
|
|||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
@ -24,9 +25,12 @@ import magic.ui.widget.TexturedPanel;
|
|||
public class CardImageOverlay extends TexturedPanel {
|
||||
|
||||
private BufferedImage cardImage = null;
|
||||
private boolean isSplitCard = false;
|
||||
|
||||
public CardImageOverlay(final MagicCardDefinition aCard) {
|
||||
|
||||
isSplitCard = aCard.isSplitCard();
|
||||
|
||||
getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "closeOverlay");
|
||||
getActionMap().put("closeOverlay", new AbstractAction() {
|
||||
@Override
|
||||
|
@ -62,10 +66,11 @@ public class CardImageOverlay extends TexturedPanel {
|
|||
}
|
||||
|
||||
private void drawCardImage(final MagicCardDefinition aCard) {
|
||||
final BufferedImage baseImage = MagicImages.getCardImage(aCard);
|
||||
final int baseWidth = baseImage.getWidth();
|
||||
final int baseHeight = baseImage.getHeight();
|
||||
final double scale = Math.min(
|
||||
isSplitCard = aCard.isSplitCard();
|
||||
BufferedImage baseImage = MagicImages.getCardImage(aCard);
|
||||
int baseWidth = baseImage.getWidth();
|
||||
int baseHeight = baseImage.getHeight();
|
||||
double scale = Math.min(
|
||||
Math.min(getWidth(), baseWidth) / (double) baseWidth,
|
||||
Math.min(getHeight(), baseHeight) / (double) baseHeight
|
||||
);
|
||||
|
@ -73,16 +78,28 @@ public class CardImageOverlay extends TexturedPanel {
|
|||
repaint();
|
||||
}
|
||||
|
||||
private void drawSplitCard(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.translate(this.getWidth() / 2, this.getHeight() / 2);
|
||||
g2d.rotate(Math.toRadians(90));
|
||||
g2d.translate(-cardImage.getWidth() / 2, -cardImage.getHeight() / 2);
|
||||
g2d.drawImage(cardImage, 0, 0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
if (cardImage != null) {
|
||||
g.drawImage(
|
||||
cardImage,
|
||||
(getWidth() - cardImage.getWidth()) / 2,
|
||||
(getHeight() - cardImage.getHeight()) / 2,
|
||||
this
|
||||
);
|
||||
if (isSplitCard) {
|
||||
drawSplitCard(g);
|
||||
} else {
|
||||
g.drawImage(
|
||||
cardImage,
|
||||
(getWidth() - cardImage.getWidth()) / 2,
|
||||
(getHeight() - cardImage.getHeight()) / 2,
|
||||
this
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import magic.ui.MagicImages;
|
|||
import magic.ui.dialog.prefs.ImageSizePresets;
|
||||
import magic.ui.helpers.ImageHelper;
|
||||
import magic.ui.utility.MagicStyle;
|
||||
import magic.ui.widget.cards.canvas.CardImageOverlay;
|
||||
import magic.ui.widget.cards.table.ICardSelectionListener;
|
||||
import magic.ui.widget.throbber.AbstractThrobber;
|
||||
import magic.ui.widget.throbber.ImageThrobber;
|
||||
|
@ -96,11 +97,13 @@ public class CardViewer extends JPanel implements ICardSelectionListener {
|
|||
public void mouseClicked(MouseEvent e) {
|
||||
if (thisCard.hasMultipleAspects()) {
|
||||
switchCardAspect();
|
||||
} else if (thisCard.isSplitCard()) {
|
||||
new CardImageOverlay(thisCard);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
defaultCursor = thisCard.hasMultipleAspects()
|
||||
defaultCursor = thisCard.hasMultipleAspects() || thisCard.isSplitCard()
|
||||
? Cursor.HAND_CURSOR
|
||||
: Cursor.DEFAULT_CURSOR;
|
||||
setCursor(Cursor.getPredefinedCursor(defaultCursor));
|
||||
|
|
Loading…
Reference in New Issue