下面列出了java.awt.Shape#contains ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void renderObjectOverlay(Graphics2D graphics, Shape area, Color color, Point mousePosition)
{
if (area == null)
{
return;
}
graphics.setColor(color);
graphics.setStroke(new BasicStroke(2));
graphics.draw(area);
graphics.setColor(setColorAlpha(color, 50));
graphics.fill(area);
if (area.contains(mousePosition.getX(), mousePosition.getY()))
{
graphics.setColor(setColorAlpha(color, 60));
graphics.fill(area);
}
}
private void renderRift(Graphics2D graphics, DecorativeObject object)
{
AbyssRifts rift = AbyssRifts.getRift(object.getId());
if (rift == null || !plugin.getRifts().contains(rift))
{
return;
}
Point mousePosition = client.getMouseCanvasPosition();
Shape objectClickbox = object.getClickbox();
if (objectClickbox != null)
{
if (objectClickbox.contains(mousePosition.getX(), mousePosition.getY()))
{
graphics.setColor(Color.MAGENTA.darker());
}
else
{
graphics.setColor(Color.MAGENTA);
}
graphics.draw(objectClickbox);
graphics.setColor(new Color(255, 0, 255, 20));
graphics.fill(objectClickbox);
}
}
@Override
public Interactive findInteractive(DrawingPanel panel, int xpix, int ypix) {
if (!isEnabled() || !(panel instanceof TrackerPanel)) return null;
if ("".equals(getText().trim())) return null; //$NON-NLS-1$
if (bounds==null) return null;
TrackerPanel trackerPanel = (TrackerPanel)panel;
if (!PencilDrawer.isDrawing(trackerPanel)) return null;
double mag = trackerPanel.getMagnification();
transform.setToTranslation(panel.xToPix(x-bounds.getWidth()/2), panel.yToPix(y-bounds.getHeight()));
transform.scale(mag, mag);
Shape s = transform.createTransformedShape(bounds);
if (s.contains(xpix, ypix)) {
return this;
}
return null;
}
private static GeneralPath findShapeToFitRectangle(Shape originalShape,
int w, int h) {
GeneralPath newShape = new GeneralPath();
Rectangle2D rect = new Rectangle2D.Float();
ShapeBounds.getBounds(originalShape, rect);
if (originalShape.contains(rect.getX() + rect.getWidth() / 2,
rect.getY() + rect.getHeight() / 2) == false)
throw new IllegalArgumentException(
"This custom shape is not allowed. The center of this shape must be inside the shape.");
double scale = Math.min((w) / rect.getWidth(), (h) / rect.getHeight());
AffineTransform transform = new AffineTransform();
while (true) {
newShape.reset();
newShape.append(originalShape, true);
transform.setToScale(scale, scale);
newShape.transform(transform);
ShapeBounds.getBounds(newShape, rect);
if (newShape.contains(rect.getX() + rect.getWidth() / 2 - w / 2,
rect.getY() + rect.getHeight() / 2 - h / 2, w, h)) {
return newShape;
}
scale += .01;
}
}
public static void renderHoverableArea(Graphics2D graphics, Shape area, net.runelite.api.Point mousePosition, Color fillColor, Color borderColor, Color borderHoverColor)
{
if (area != null)
{
if (area.contains(mousePosition.getX(), mousePosition.getY()))
{
graphics.setColor(borderHoverColor);
}
else
{
graphics.setColor(borderColor);
}
graphics.draw(area);
graphics.setColor(fillColor);
graphics.fill(area);
}
}
private void renderObject(GameObject object, Graphics2D graphics, Color color)
{
LocalPoint localLocation = client.getLocalPlayer().getLocalLocation();
Point mousePosition = client.getMouseCanvasPosition();
LocalPoint location = object.getLocalLocation();
if (localLocation.distanceTo(location) <= MAX_DISTANCE)
{
Shape objectClickbox = object.getClickbox();
if (objectClickbox != null)
{
if (objectClickbox.contains(mousePosition.getX(), mousePosition.getY()))
{
graphics.setColor(color.darker());
}
else
{
graphics.setColor(color);
}
graphics.draw(objectClickbox);
graphics.setColor(new Color(0xFF, 0, 0, 20));
graphics.fill(objectClickbox);
}
}
}
private void renderRift(Graphics2D graphics, DecorativeObject object)
{
AbyssRifts rift = AbyssRifts.getRift(object.getId());
if (rift == null || !plugin.getRifts().contains(rift))
{
return;
}
Point mousePosition = client.getMouseCanvasPosition();
Shape objectClickbox = object.getClickbox();
if (objectClickbox != null)
{
if (objectClickbox.contains(mousePosition.getX(), mousePosition.getY()))
{
graphics.setColor(Color.MAGENTA.darker());
}
else
{
graphics.setColor(Color.MAGENTA);
}
graphics.draw(objectClickbox);
graphics.setColor(new Color(255, 0, 255, 20));
graphics.fill(objectClickbox);
}
}
/**
* Returns the first connected {@link OutputPort} for which the specified point lies inside the
* connector shape.
*
* @param p
* the point in question
* @param unit
* the process for which to check
* @return an output port for which the point lies inside the connector or {@code null}
*/
OutputPort getPortForConnectorNear(final Point p, final ExecutionUnit unit) {
List<OutputPort> candidates = new LinkedList<>();
candidates.addAll(unit.getInnerSources().getAllPorts());
for (Operator op : unit.getOperators()) {
candidates.addAll(op.getOutputPorts().getAllPorts());
}
for (OutputPort port : candidates) {
if (port.isConnected()) {
Shape connector = ProcessDrawUtils.createConnector(port, port.getDestination(), model);
if (connector == null) {
return null;
}
Shape thick = CONNECTION_HOVER_DETECTION_STROKE.createStrokedShape(connector);
if (thick.contains(p)) {
return port;
}
}
}
return null;
}
protected boolean isInSatelliteLensArea(MouseEvent e) {
// must be inside of the 'lens' ...
VisualizationViewer<V, E> satelliteViewer = getSatelliteGraphViewer(e);
VisualizationViewer<V, E> viewMaster =
((SatelliteVisualizationViewer<V, E>) satelliteViewer).getMaster();
Shape lensInSatelliteViewSpace =
getSatelliteLensInSatelliteViewSpace(satelliteViewer, viewMaster);
return lensInSatelliteViewSpace.contains(e.getPoint());
}
private List<RenderedObject> getObjectsAtPoint(int x, int y) {
List<RenderedObject> result = new ArrayList<RenderedObject>();
for (RenderedObject next : renderedObjects) {
Shape shape = next.getShape();
if (shape != null && shape.contains(x, y)) {
result.add(next);
}
}
Collections.reverse(result);
return result;
}
private List<ShapeInfo> getShapesAtPoint(Point p) {
List<ShapeInfo> result = new ArrayList<ShapeInfo>();
for (Map.Entry<Shape, ShapeInfo> next : drawnShapes.entrySet()) {
Shape shape = next.getKey();
if (shape.contains(p)) {
result.add(next.getValue());
}
}
return result;
}
public Object[] getObjectsAtPoint(Point p) {
Collection result = new ArrayList();
// System.out.println("Getting objects at point "+p);
for (Iterator it = objects.iterator();it.hasNext();) {
Object next = it.next();
Shape s = (Shape)shapes.get(next);
// System.out.println("Next object: "+next+", shape: "+s);
if (s!=null && s.contains(p.x,p.y)) {
result.add(next);
// System.out.println("Added");
}
}
return result.toArray();
}
/**
* Function to test if the given 2D rectangle is contained in any of the given shapes in the
* collection.
*/
private static boolean containedIn(final Rectangle2D r, final Collection<Polygon> shapes) {
for (final Shape item : shapes) {
if (item.contains(r)) {
return true;
}
}
return false;
}
/**
* Checks if a new placement for an entity is valid.
*
* @param zone the zone where the entity should be placed
* @param entity the entity to place
* @param allowedArea if specified, restrict placement within this area
* @param oldX the x coordinate from where the entity was displaced
* @param oldY the y coordinate from where the entity was displaced
* @param newX the x coordinate of the new placement
* @param newY the y coordinate of the new placement
* @param checkPath if true, check that there is a path from <code>(newX, newY)</code>
* to <code>(oldX, oldY)</code>
*
* @return true if placing is possible, false otherwise
*/
private static boolean isValidPlacement(final StendhalRPZone zone, final Entity entity,
final Shape allowedArea, final int oldX, final int oldY,
final int newX, final int newY, final boolean checkPath) {
// allow admins in ghostmode to teleport to collision tiles
if (entity instanceof Player) {
if (((Player) entity).isGhost()) {
return true;
}
}
if (!zone.collides(entity, newX, newY)) {
// Check the possibleArea now. This is a performance
// optimization because the pathfinding is very expensive.
if ((allowedArea != null) && (!allowedArea.contains(newX, newY))) {
return false;
}
if (!checkPath) {
return true;
}
// We verify that there is a walkable path between the original
// spot and the new destination. This is to prevent players to
// enter not allowed places by logging in on top of other players.
// Or monsters to spawn on the other side of a wall.
final List<Node> path = Path.searchPath(entity, zone,
oldX, oldY, new Rectangle(newX, newY, 1, 1),
400 /* maxDestination * maxDestination */, false);
if (!path.isEmpty()) {
// We found a place!
return true;
}
}
return false;
}
/**
* Check if teleporting to a location is allowed.
*
* @param x x coordinate
* @param y y coordinate
* @return <code>true</code> if teleporting to the point is allowed, <code>false</code> otherwise
*/
public boolean isInAllowed(int x, int y) {
for (Shape r : arrivingBarriers) {
if (r.contains(x, y)) {
return false;
}
}
return true;
}
public boolean hasSelectedDrawnShape(Point2D p) {
for (int i = 0; i < hep.getNumShapes(); i++) {
Shape s = hep.getHoles().getShape(i, hep.previewArea);
if (s.contains(p)) {
return true;
}
}
return false;
}
boolean reflect(Discrete p, boolean scatter) {
float dt = model.getTimeStep();
float predictedX = p.getRx() + p.getVx() * dt;
float predictedY = p.getRy() + p.getVy() * dt;
if (p instanceof Particle) {
float dt2 = 0.5f * dt * dt;
predictedX += ((Particle) p).ax * dt2;
predictedY += ((Particle) p).ay * dt2;
}
Shape shape = getShape();
boolean predictedToBeInShape = true; // optimization flag: if the predicted position is not within this part, skip the costly reflection calculation
if (p instanceof Photon)
predictedToBeInShape = shape.contains(predictedX, predictedY);
if (shape instanceof Rectangle2D.Float) {
if (predictedToBeInShape)
return reflect((Rectangle2D.Float) shape, p, predictedX, predictedY, scatter);
} else if (shape instanceof Polygon2D) {
if (predictedToBeInShape)
return reflect((Polygon2D) shape, p, predictedX, predictedY, scatter);
} else if (shape instanceof Blob2D) {
if (predictedToBeInShape)
return reflect((Blob2D) shape, p, predictedX, predictedY, scatter);
} else if (shape instanceof Ellipse2D.Float) {
if (predictedToBeInShape)
return reflect((Ellipse2D.Float) shape, p, predictedX, predictedY, scatter);
} else if (shape instanceof Annulus) {
if (predictedToBeInShape)
return reflect((Annulus) shape, p, predictedX, predictedY, scatter);
} else if (shape instanceof EllipticalAnnulus) {
if (predictedToBeInShape)
return reflect((EllipticalAnnulus) shape, p, predictedX, predictedY, scatter);
}
return false;
}
public boolean selectDrawnShape(Point2D p) {
endPolygon();
for (int i = 0; i < hep.getNumShapes(); i++) {
Shape s = hep.getHoles().getShape(i, hep.previewArea);
if (s.contains(p) && hep.currentShape != i) {
hep.setCurrentShape(i);
setShapeData(hep.getHoles().getShapeData(i), 0, 0, 1, 1);
return true;
}
}
hep.setCurrentShape(hep.getHoles().getNumCells() + 1);
clean();
return false;
}
private boolean contains(Shape shape, float x, float y, boolean tolerateRoundOffError) {
if (tolerateRoundOffError)
return shape.contains(x, y);
float tol = 0.001f;
return shape.contains(x, y) || shape.contains(x - deltaX * tol, y) || shape.contains(x + deltaX * tol, y) || shape.contains(x, y - deltaY * tol) || shape.contains(x, y + deltaY * tol);
}
public Shape getOutline(int frame, int time, RenderContext renderContext, Matrix transformation, boolean stroked) {
Frame fr = getFrame(frame);
Area area = new Area();
Stack<Clip> clips = new Stack<>();
for (int d = maxDepth; d >= 0; d--) {
Clip currentClip = null;
for (int i = clips.size() - 1; i >= 0; i--) {
Clip cl = clips.get(i);
if (cl.depth <= d) {
clips.remove(i);
}
}
if (!clips.isEmpty()) {
currentClip = clips.peek();
}
DepthState layer = fr.layers.get(d);
if (layer == null) {
continue;
}
if (!layer.isVisible) {
continue;
}
CharacterTag character = swf.getCharacter(layer.characterId);
if (character instanceof DrawableTag) {
DrawableTag drawable = (DrawableTag) character;
Matrix m = transformation.concatenate(new Matrix(layer.matrix));
int drawableFrameCount = drawable.getNumFrames();
if (drawableFrameCount == 0) {
drawableFrameCount = 1;
}
int dframe = time % drawableFrameCount;
if (character instanceof ButtonTag) {
dframe = ButtonTag.FRAME_UP;
if (renderContext.cursorPosition != null) {
ButtonTag buttonTag = (ButtonTag) character;
Shape buttonShape = buttonTag.getOutline(ButtonTag.FRAME_HITTEST, time, layer.ratio, renderContext, m, stroked);
if (buttonShape.contains(renderContext.cursorPosition)) {
if (renderContext.mouseButton > 0) {
dframe = ButtonTag.FRAME_DOWN;
} else {
dframe = ButtonTag.FRAME_OVER;
}
}
}
}
Shape cshape = ((DrawableTag) character).getOutline(dframe, time, layer.ratio, renderContext, m, stroked);
Area addArea = new Area(cshape);
if (currentClip != null) {
Area a = new Area(new Rectangle(displayRect.Xmin, displayRect.Ymin, displayRect.getWidth(), displayRect.getHeight()));
a.subtract(new Area(currentClip.shape));
addArea.subtract(a);
}
if (layer.clipDepth > -1) {
Clip clip = new Clip(addArea, layer.clipDepth);
clips.push(clip);
} else {
area.add(addArea);
}
}
}
return area;
}