/** * Returns a point where the given popup menu should be shown. The * point is calculated by adjusting the X and Y coordinates from the * given mouse event so that the popup menu will not be clipped by * the screen boundaries. * * @param popup the popup menu * @param event the mouse event * @return the point where the popup menu should be shown */ public static Point getPopupMenuShowPoint(JPopupMenu popup, MouseEvent event) { Component source = (Component) event.getSource(); Point topLeftSource = source.getLocationOnScreen(); Point ptRet = getPopupMenuShowPoint(popup, topLeftSource.x + event.getX(), topLeftSource.y + event.getY()); ptRet.translate(-topLeftSource.x, -topLeftSource.y); return ptRet; }
Point cp = e.getPoint(); Point vp = vport.getViewPosition(); vp.translate(pp.x-cp.x, pp.y-cp.y); image.scrollRectToVisible(new Rectangle(vp, vport.getSize())); pp.setLocation(cp);
@Override public MouseEvent mouseDragged(MouseEvent mouseEvent) { if (!inOverlayDraggingMode) { return mouseEvent; } final Point mousePoint = mouseEvent.getPoint(); mousePosition.setLocation(mousePoint); final Rectangle canvasRect = new Rectangle(client.getRealDimensions()); if (!canvasRect.contains(mousePoint)) { return mouseEvent; } if (movedOverlay != null) { final Dimension realDimension = client.getRealDimensions(); mousePoint.translate(-overlayOffset.x, -overlayOffset.y); mousePoint.x = Ints.constrainToRange(mousePoint.x, 0, realDimension.width - movedOverlay.getBounds().width); mousePoint.y = Ints.constrainToRange(mousePoint.y, 0, realDimension.height - movedOverlay.getBounds().height); movedOverlay.setPreferredPosition(null); movedOverlay.setPreferredLocation(mousePoint); mouseEvent.consume(); } return mouseEvent; }
Point convertToRegionLocation(Point point_in_global_coordinate) { Point ret = new Point(point_in_global_coordinate); ret.translate(-_region.x, -_region.y); return ret; }
public static void drawArrowsForPairedCards(TransferData data, Point parentPoint) { if (data.card.getPairedCard() != null) { Point me = new Point(data.locationOnScreen); me.translate(-parentPoint.x, -parentPoint.y); UUID uuid = data.card.getPairedCard(); for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid); if (permanent != null) { Point target = permanent.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.green, ArrowBuilder.Type.PAIRED); } } } }
public static void drawArrowsForSource(TransferData data, Point parentPoint) { if (data.card.isAbility()) { Point me = new Point(data.locationOnScreen); me.translate(-parentPoint.x, -parentPoint.y); UUID uuid = data.card.getParentId(); for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid); if (permanent != null) { Point source = permanent.getLocationOnScreen(); source.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(data.gameId, (int) source.getX() + 40, (int) source.getY() + 10, (int) me.getX() + 35, (int) me.getY() + 20, Color.blue, ArrowBuilder.Type.SOURCE); } } } }
public static void drawArrowsForBandedCards(TransferData data, Point parentPoint) { if (data.card.getBandedCards() != null && !data.card.getBandedCards().isEmpty()) { Point me = new Point(data.locationOnScreen); me.translate(-parentPoint.x, -parentPoint.y); for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) { for (UUID uuid : data.card.getBandedCards()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid); if (permanent != null) { Point target = permanent.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 55, (int) me.getY() + 25, (int) target.getX() + 60, (int) target.getY() + 35, Color.yellow, ArrowBuilder.Type.BANDED); } } } } }
/** {@inheritDoc} */ @Override public void moveImage(int dx, int dy) { drawingLock.lock(); try { if (isShowing() && !getVisibleRect().isEmpty()) { imageOrigin.translate(dx, dy); baseImageMoved.set(true); repaint(); onImageMoved(); } } finally { drawingLock.unlock(); } }
public void showPopup(final Component popupContainer, final Component infoPane) throws InterruptedException { final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE); SwingUtilities.invokeLater(() -> { if (!popupTextWindowOpen || enlargedWindowState != EnlargedWindowState.CLOSED) { return; } if (data.locationOnScreen == null) { data.locationOnScreen = data.component.getLocationOnScreen(); } Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40); location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, infoPane, parentComponent); location.translate(-parentPoint.x, -parentPoint.y); popupContainer.setLocation(location); popupContainer.setVisible(true); c.repaint(); } ); } });
private void drawDefender(CombatGroupView group, MagePermanent attackerCard, UUID gameId) { UUID defenderId = group.getDefenderId(); if (defenderId != null) { parentPoint = getParentPoint(attackerCard); PlayAreaPanel p = MageFrame.getGame(gameId).getPlayers().get(defenderId); if (p != null) { Point target = p.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); Point attackerPoint = attackerCard.getLocationOnScreen(); attackerPoint.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() - 20, Color.red, ArrowBuilder.Type.COMBAT); } else { for (PlayAreaPanel pa : MageFrame.getGame(gameId).getPlayers().values()) { MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(defenderId); if (permanent != null) { Point target = permanent.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); Point attackerPoint = attackerCard.getLocationOnScreen(); attackerPoint.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(gameId, (int) attackerPoint.getX() + 45, (int) attackerPoint.getY() + 25, (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.COMBAT); } } } } }
public static void drawArrowsForEnchantPlayers(TransferData data, Point parentPoint) { if (data.gameId != null && MageFrame.getGame(data.gameId) != null) { for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).getPlayers().values()) { PlayerPanelExt playAreaPanel = pa.getPlayerPanel(); if (playAreaPanel != null && playAreaPanel.getPlayer() != null && playAreaPanel.getPlayer().hasAttachments()) { Point me = new Point(data.locationOnScreen); me.translate(-parentPoint.x, -parentPoint.y); for (UUID attachmentId : playAreaPanel.getPlayer().getAttachments()) { if (attachmentId.equals(data.card.getId())) { Point player = pa.getLocationOnScreen(); player.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(data.gameId,(int) me.getX() + 35, (int) me.getY(), (int) player.getX() + 40, (int) player.getY() - 40, Color.magenta, ArrowBuilder.Type.ENCHANT_PLAYERS); } } } } } }
me.translate(-parentPoint.x, -parentPoint.y); for (UUID uuid : targets) { if (p != null) { Point target = p.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() - 40, Color.red, ArrowBuilder.Type.TARGET); continue; if (permanent != null) { Point target = permanent.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.TARGET); continue; if (p != null) { Point target = p.getLocationOnScreen(); target.translate(-parentPoint.x, -parentPoint.y); int yOffset = p.isSmallMode() ? (PlayAreaPanel.PANEL_HEIGHT - PlayAreaPanel.PANEL_HEIGHT_SMALL) : 0; ArrowBuilder.getBuilder().addArrow(data.gameId, (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 15, (int) target.getY() + 145 - yOffset, Color.red, ArrowBuilder.Type.TARGET);
private void drawBlockers(CombatGroupView group, MagePermanent attackerCard, UUID gameId) { for (CardView blocker : group.getBlockers().values()) { for (PlayAreaPanel pa : MageFrame.getGame(gameId).getPlayers().values()) { MagePermanent blockerCard = pa.getBattlefieldPanel().getPermanents().get(blocker.getId()); if (blockerCard != null) { parentPoint = getParentPoint(blockerCard); Point blockerPoint = blockerCard.getLocationOnScreen(); blockerPoint.translate(-parentPoint.x, -parentPoint.y); Point attackerPoint = attackerCard.getLocationOnScreen(); attackerPoint.translate(-parentPoint.x, -parentPoint.y); double yRateA = (attackerCard.getSize().height / SettingsManager.instance.getCardSize().height); double xRateA = (attackerCard.getSize().width / SettingsManager.instance.getCardSize().width); double yRateB = (blockerCard.getSize().height / SettingsManager.instance.getCardSize().height); double xRateB = (blockerCard.getSize().width / SettingsManager.instance.getCardSize().width); ArrowBuilder.getBuilder().addArrow(gameId, (int) blockerPoint.getX() + (int) (55 * xRateB), (int) blockerPoint.getY() + (int) (25 * xRateB), (int) attackerPoint.getX() + (int) (70 * xRateA), (int) attackerPoint.getY() + (int) (25 * yRateA), Color.blue, ArrowBuilder.Type.COMBAT); globalBlockersCount++; } } } }
@Override public void dragMouseMoved(DragSourceDragEvent dsde) { Point pt = dsde.getLocation(); pt.translate(5, 5); // offset window.setLocation(pt);
if (regExPos!=null) { if (regExPos.x!=regExPos.y) { regExPos.translate(start, start); range = new DocumentRange(regExPos.x, regExPos.y);
Point location = new Point((int) transferData.locationOnScreen.getX() + transferData.popupOffsetX - 40, (int) transferData.locationOnScreen.getY() + transferData.popupOffsetY - 40); location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent); location.translate(-parentPoint.x, -parentPoint.y); popupContainer.setLocation(location); popupContainer.setVisible(true);
penPosition.translate(dh, 0); context.moveTo(penPosition); text = PICTUtil.readPascalString(pStream); penPosition.translate(0, dv); context.moveTo(penPosition); text = PICTUtil.readPascalString(pStream); penPosition.translate(x, y); context.moveTo(penPosition); text = PICTUtil.readPascalString(pStream);