List of usage examples for com.badlogic.gdx.math Rectangle contains
public boolean contains(float x, float y)
From source file:com.game.libgdx.roguelikeengine.PopupInfoText.java
License:Open Source License
protected boolean mouseOverWord(Rectangle rect, BitmapFont font) { int mouseX = Gdx.input.getX(); int mouseY = Gdx.graphics.getHeight() + ((int) font.getLineHeight()) - Gdx.input.getY(); rect.x += x;// w ww .j a va 2s . c om rect.y += y; boolean result = rect.contains(mouseX, mouseY); rect.x -= x; rect.y -= y; return result; }
From source file:com.game.libgdx.roguelikeengine.PopupInfoText.java
License:Open Source License
protected boolean xyOverWord(Rectangle rect, int x, int y) { return rect.contains(x, y); }
From source file:com.gamejolt.mikykr5.ceidecpong.ecs.systems.CollisionDetectionSystem.java
License:Open Source License
private boolean collidesLeft(Rectangle a, Rectangle b) { float leftBottomCornerY, leftTopCornerY, leftCenterY; leftBottomCornerY = a.y;//w w w .j a v a2s.c om leftTopCornerY = a.y + a.height; leftCenterY = a.y + (a.height / 2); return b.contains(a.x, leftBottomCornerY) || b.contains(a.x, leftTopCornerY) || b.contains(a.x, leftCenterY); }
From source file:com.gamejolt.mikykr5.ceidecpong.ecs.systems.CollisionDetectionSystem.java
License:Open Source License
private boolean collidesRight(Rectangle a, Rectangle b) { float x, rightBottomCornerY, rightTopCornerY, rightCenterY; x = a.x + a.width;//from w w w . j a v a2 s .c o m rightBottomCornerY = a.y; rightTopCornerY = a.y + a.height; rightCenterY = a.y + (a.height / 2); return b.contains(x, rightBottomCornerY) || b.contains(x, rightTopCornerY) || b.contains(x, rightCenterY); }
From source file:com.kotcrab.vis.editor.module.physicseditor.input.EditionInputProcessor.java
License:Apache License
private List<Vector2> getPointsInSelection() { RigidBodyModel model = screen.getSelectedModel(); List<Vector2> points = new ArrayList<Vector2>(); Vector2 p1 = screen.mouseSelectionP1; Vector2 p2 = screen.mouseSelectionP2; if (p1 != null && p2 != null) { Rectangle rect = new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); for (Vector2 p : getAllPoints()) { if (p == model.getOrigin()) continue; if (rect.contains(p.x, p.y)) points.add(p);/*w ww.j a v a 2s .c om*/ } } return Collections.unmodifiableList(points); }
From source file:com.kotcrab.vis.editor.module.scene.entitymanipulator.tool.BaseSelectionTool.java
License:Apache License
/** * Returns entity with smallest surface area that contains point x,y. * <p>//from w w w. ja v a 2s . c om * When selecting entities, and few of them are overlapping, selecting entity with smallest * area gives better results than just selecting first one. */ protected EntityProxy findEntityWithSmallestSurfaceArea(float x, float y) { EntityProxy matchingEntity = null; float lastSurfaceArea = Float.MAX_VALUE; for (EntityProxy entity : entityProxyCache.getCache().values()) { Rectangle entityBoundingRectangle = entity.getBoundingRectangle(); if (entityBoundingRectangle.contains(x, y)) { float currentSurfaceArea = entityBoundingRectangle.width * entityBoundingRectangle.height; if (currentSurfaceArea < lastSurfaceArea) { if (scene.getLayerById(entity.getLayerID()).locked) continue; matchingEntity = entity; lastSurfaceArea = currentSurfaceArea; } } } return matchingEntity; }
From source file:com.kotcrab.vis.editor.module.scene.EntityManipulatorModule.java
License:Apache License
/** * Returns entity with smallest surface area that contains point x,y. * <p>//w ww . j a v a 2 s. co m * When selecting entities, and few of them are overlapping, selecting entity with smallest * area gives better results than just selecting first one. */ private EditorObject findEntityWithSmallestSurfaceArea(float x, float y) { EditorObject matchingEntity = null; float lastSurfaceArea = Float.MAX_VALUE; for (EditorObject entity : entities) { Rectangle entityBoundingRectangle = entity.getBoundingRectangle(); if (entityBoundingRectangle.contains(x, y)) { float currentSurfaceArea = entityBoundingRectangle.width * entityBoundingRectangle.height; if (currentSurfaceArea < lastSurfaceArea) { matchingEntity = entity; lastSurfaceArea = currentSurfaceArea; } } } return matchingEntity; }
From source file:com.kotcrab.vis.ui.widget.MultiSplitPane.java
License:Apache License
private void initialize() { addListener(new SplitPaneCursorManager(this, vertical) { @Override/* w ww . j a v a 2 s .c o m*/ protected boolean handleBoundsContains(float x, float y) { return getHandleContaining(x, y) != null; } @Override protected boolean contains(float x, float y) { for (Rectangle bound : widgetBounds) { if (bound.contains(x, y)) return true; } return getHandleContaining(x, y) != null; } }); addListener(new InputListener() { int draggingPointer = -1; @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (isTouchable() == false) return false; if (draggingPointer != -1) return false; if (pointer == 0 && button != 0) return false; Rectangle containingHandle = getHandleContaining(x, y); if (containingHandle != null) { handleOverIndex = handleBounds.indexOf(containingHandle, true); FocusManager.resetFocus(getStage()); draggingPointer = pointer; lastPoint.set(x, y); handlePosition.set(containingHandle.x, containingHandle.y); return true; } return false; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { if (pointer == draggingPointer) draggingPointer = -1; handleOver = getHandleContaining(x, y); } @Override public boolean mouseMoved(InputEvent event, float x, float y) { handleOver = getHandleContaining(x, y); return false; } @Override public void touchDragged(InputEvent event, float x, float y, int pointer) { if (pointer != draggingPointer) return; Drawable handle = style.handle; if (!vertical) { float delta = x - lastPoint.x; float availWidth = getWidth() - handle.getMinWidth(); float dragX = handlePosition.x + delta; handlePosition.x = dragX; dragX = Math.max(0, dragX); dragX = Math.min(availWidth, dragX); float targetSplit = dragX / availWidth; setSplit(handleOverIndex, targetSplit); lastPoint.set(x, y); } else { float delta = y - lastPoint.y; float availHeight = getHeight() - handle.getMinHeight(); float dragY = handlePosition.y + delta; handlePosition.y = dragY; dragY = Math.max(0, dragY); dragY = Math.min(availHeight, dragY); float targetSplit = 1 - (dragY / availHeight); setSplit(handleOverIndex, targetSplit); lastPoint.set(x, y); } invalidate(); } }); }
From source file:com.kotcrab.vis.ui.widget.MultiSplitPane.java
License:Apache License
private Rectangle getHandleContaining(float x, float y) { for (Rectangle rect : handleBounds) { if (rect.contains(x, y)) { return rect; }//w ww . java 2 s . c o m } return null; }
From source file:com.mygdx.game.shamballa.java
@Override public boolean touchDown(int i, int i1, int i2, int i3) { stage.clear();//w w w .ja va 2s . c o m Vector2 v2 = new Vector2(); Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); cam.unproject(touchPos); v2.x = touchPos.x; v2.y = touchPos.y; paths.add(v2); for (Rectangle r : overworld.townrec) { if (r.contains(touchPos.x, touchPos.y)) { loca.x = r.x; loca.y = r.y; System.out.print("loca " + loca.x); System.out.print("loca " + loca.y); overworld.rec.x = r.x; overworld.rec.y = r.y; overworld.owpathfinding.setup(loca, overworld.p, overworld.totalWay); overworld.totalWay = overworld.owpathfinding.current.size(); overworld.p.isMoving = true; movetime = time; // moveplayer(); } } return false; }