use of mage.cards.MageCardLocation in project mage by magefree.
the class CardPanelRenderModeImage method paintCard.
@Override
protected void paintCard(Graphics2D g2d) {
float alpha = getAlpha();
if (alpha != 1.0f) {
AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, alpha);
g2d.setComposite(composite);
}
// draw background (selected/chooseable/playable)
MageCardLocation cardLocation = getCardLocation();
g2d.drawImage(IMAGE_CACHE.getOrThrow(new Key(getInsets(), cardLocation.getCardWidth(), cardLocation.getCardHeight(), cardLocation.getCardWidth(), cardLocation.getCardHeight(), 0, 0, hasImage, isSelected(), isChoosable(), getGameCard().isPlayable(), getGameCard().isCanAttack(), getGameCard().isCanBlock())), 0, 0, cardLocation.getCardWidth(), cardLocation.getCardHeight(), null);
g2d.dispose();
}
use of mage.cards.MageCardLocation in project mage by magefree.
the class MageLayer method contains.
@Override
public boolean contains(int x, int y) {
// TODO: is it work with multi layer?
// Mouse coords checking to find a child component under the mouse (example: show card hint on mouse over or button click)
// Swing uses relative coords here (0,0 is component's top left corner)
// WARNING, when you fail a parent coord check then all childs goes to ignore (example: top layer miss check,
// then no card panel get it and no card hints on mouse over)
MageCardLocation needLocation = this.getCardLocation();
// TODO: added contains support for icons hint
// implement idea: use custom "contains" methods for all components structure: from top layer to icon label
// another implement idea: save last AffineTransforms from paint method, translate it to current component and check coords (most accurate method)
// extra size for icons (workaround to fix tooltips over icons)
Rectangle iconsOffset = new Rectangle(0, 0);
if (this.iconsPanels.stream().anyMatch(Component::isVisible)) {
CardIconsPanel samplePanel = this.iconsPanels.stream().findFirst().get();
iconsOffset.x = -samplePanel.getHalfSize();
iconsOffset.y = -samplePanel.getHalfSize();
iconsOffset.height = samplePanel.getHalfSize();
iconsOffset.width = samplePanel.getHalfSize();
}
Rectangle normalRect = new Rectangle(needLocation.getCardRelativeX() + iconsOffset.x, needLocation.getCardRelativeY() + iconsOffset.y, needLocation.getCardWidth() + iconsOffset.width, needLocation.getCardHeight() + iconsOffset.height);
Rectangle animatedRect = animateCoords(this, normalRect);
// debug draw just for color info, real draw will be transformed/animated with card, so you can look at draw rect
if (DebugUtil.GUI_CARD_DRAW_MOUSE_CONTAINS_BOUNDS) {
this.mainLayerDebug.setBounds(animatedRect.x, animatedRect.y, animatedRect.width, animatedRect.height);
if (animatedRect.contains(x, y)) {
this.mainLayerDebug.setBorder(BorderFactory.createLineBorder(Color.green));
} else {
this.mainLayerDebug.setBorder(BorderFactory.createLineBorder(Color.MAGENTA));
}
}
return animatedRect.contains(x, y);
}
use of mage.cards.MageCardLocation in project mage by magefree.
the class MageLayer method setCardBounds.
@Override
public void setCardBounds(int x, int y, int width, int height) {
// if (this.getTopPanelRef() == this && this.getOriginal().getName().equals("Kathari Remnant")) { // for debug only
if (this.getTopPanelRef() == this) {
// TODO: is it support multi layer drawing?
// scale inner card and create space for additional drawing like icons
MageCardSpace innerSpace = getAdditionalSpaces(width, height);
// extra space for animation and other drawing
// WTF, I'm tired with render calcs, so make BIG draw spaces for any needs
MageCardSpace outerSpace = new MageCardSpace(width * 2, width * 2, height * 2, height * 2);
// MageCardSpace outerSpace = new MageCardSpace(50, 30, 150, 20);
this.lastOuterSpace = outerSpace;
// construct new spaces (outer + inner)
MageCardSpace fullSpace = MageCardSpace.combine(innerSpace, outerSpace).withDebugColor(innerSpace.getDebugColor());
this.setEmptySpaces(fullSpace);
// noinspection deprecation - it's ok to use inner setBounds here
this.setBounds(x - outerSpace.getLeft(), y - outerSpace.getTop(), width + outerSpace.getWidth(), height + outerSpace.getHeight());
mainPanel.setCardBounds(x + innerSpace.getLeft(), y + innerSpace.getTop(), width - innerSpace.getWidth(), height - innerSpace.getHeight());
} else {
this.setEmptySpaces(0, 0, 0, 0);
// noinspection deprecation - it's ok to use inner setBounds here
this.setBounds(x, y, width, height);
mainPanel.setCardBounds(x, y, width, height);
}
MageCardLocation location = this.getCardLocation();
// panel sizes
this.mainLayerCard.setBounds(0, 0, location.getComponentWidth(), location.getComponentHeight());
this.mainLayerIcons.setBounds(0, 0, location.getComponentWidth(), location.getComponentHeight());
// icons sizes
Rectangle cardSize = new Rectangle(location.getCardRelativeX(), location.getCardRelativeY(), location.getCardWidth(), location.getCardHeight());
iconsPanels.forEach(panel -> {
panel.updateSizes(cardSize);
});
}
Aggregations