Refine search
* Fetches angle relative to screen centre point * where 3 O'Clock is 0 and 12 O'Clock is 270 degrees * * @param screenPoint * @return angle in degress from 0-360. */ public double getAngle(Point screenPoint) { double dx = screenPoint.getX() - mCentreX; // Minus to correct for coord re-mapping double dy = -(screenPoint.getY() - mCentreY); double inRads = Math.atan2(dy,dx); // We need to map to coord system when 0 degree is at 3 O'clock, 270 at 12 O'clock if (inRads < 0) inRads = Math.abs(inRads); else inRads = 2*Math.PI - inRads; return Math.toDegrees(inRads); }
Point p1 = new Point(currentWp.getX() - maxSquaresAway, currentWp.getY() - maxSquaresAway); Rectangle r1 = new Rectangle((int) p1.getX(), (int) p1.getY(), 2 * maxSquaresAway + 1, 2 * maxSquaresAway + 1); Point p2 = new Point(currentWp.getX() - minSquaresAway, currentWp.getY() - minSquaresAway); Rectangle r2 = new Rectangle((int) p2.getX(), (int) p2.getY(), 2 * minSquaresAway + 1, 2 * minSquaresAway + 1);
startingLocations.put("LeftRook", new Point(1, 1)); startingLocations.put("LeftKnight", new Point(1, 2)); startingLocations.put("LeftCamel", new Point(1, 3)); System.out.println("The LeftCamel's start is at [ " + camelLoc.getX() + ", " + camelLoc.getY() + " ]"); System.out.println("Try 2 - Map updated! The LeftCamel's start is now at [ " + newCamelLoc.getX() + ", " + newCamelLoc.getY() + " ]"); }
@Override public void mousePressed(MouseEvent e, TransferData data) { data.component.requestFocusInWindow(); // for some reason sometime mouseRelease happens before numerous Mouse_Dragged events // that results in not finished dragging clearDragging(this.prevCardPanel); isDragging = false; startedDragging = false; prevCardPanel = null; cardPanels.clear(); Point mouse = new Point(e.getX(), e.getY()); SwingUtilities.convertPointToScreen(mouse, data.component); initialMousePos = new Point((int) mouse.getX(), (int) mouse.getY()); initialCardPos = data.component.getLocation(); // Closes popup & enlarged view if a card/Permanent is selected hideTooltipPopup(); }
void zoom(double f, Point p) { double ex = modelBounds.getWidth() * f; double ey = modelBounds.getHeight() * f; modelBounds.expandBy(ex / 2, ey / 2); if (p != null) { // Note: Graphics Y coordinates increase down the screen, hence the opposite signs. double tx = ex * -((p.getX() / this.width) - 0.5); double ty = ey * +((p.getY() / this.height) - 0.5); modelBounds.translate(tx, ty); } // update the display drawLevel = DRAW_PARTIAL; }
private Point dragLocation = new Point(); public void mouseDragged(MouseEvent e) { if (drag) { if (dragLocation.getX()> getWidth()-10 && dragLocation.getY()>getHeight()-10) { System.err.println("in"); setSize((int)(getWidth()+(e.getPoint().getX()-dragLocation.getX())), (int)(getHeight()+(e.getPoint().getY()-dragLocation.getY()))); dragLocation = e.getPoint();
double xDistance = distance(xCentre, p.getX()); double yDistance = distance(pixelCentre.getY(), p.getY()); double lonDistanceInDegrees = (xDistance * minutesPerPixel) / 60; double mp = (yDistance * minutesPerPixel); lat = findLat(mp, 0.0, 85.0); lon = (p.getX() < xCentre ? centre.getLongitude() - lonDistanceInDegrees : centre.getLongitude() + lonDistanceInDegrees); if (p.getY() > pixelCentre.getY()) { lat = -1 * lat;
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); } } } }
private static void saveWindowPosition(Frame frame) { if (!isWindowPositioningEnabled()) { return; } Point point; try { point = frame.getLocationOnScreen(); } catch (Exception e) { e.printStackTrace(); try { point = frame.getLocation(); } catch (Exception e2) { e2.printStackTrace(); return; } } int x = (int)point.getX(); int y = (int)point.getY(); int w = frame.getWidth(); int h = frame.getHeight(); Utils.setConfigInteger("window.x", x); Utils.setConfigInteger("window.y", y); Utils.setConfigInteger("window.w", w); Utils.setConfigInteger("window.h", h); LOGGER.debug("Saved window position (x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ")"); }
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); } } } } }
public void setVisible(boolean visible) { if (visible) { int x = (int) getOwner().getLocation().getX() + (getOwner().getWidth() / 2) - (getWidth() / 2); int y = (int) getOwner().getLocation().getY() + (getOwner().getHeight() / 2) - (getHeight() / 2); setLocation(adjustX(x), adjustY(y)); } super.setVisible(visible); }
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(); } ); } });