use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.
the class SpriteImagePanel method drawStack.
@Override
public void drawStack(Graphics g) {
Rectangle r = convertRectToViewRect(_graphicBounds);
g.clipRect(r.x, r.y, r.width, r.height);
super.drawStack(g);
g.setClip(null);
}
use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.
the class GraphicPanel method addGraphic.
public void addGraphic(GraphicObject aGraphic) {
if (aGraphic.getAnchor() == GraphicObject.Anchor.CENTRE) {
Rectangle r = aGraphic.getRect();
r.x -= r.width / 2;
r.y -= r.height / 2;
aGraphic.saveRect();
}
// add to top
_drawStack.add(0, aGraphic);
aGraphic.setBounds(_graphicBounds);
repaint();
_lastAddedGraphic = aGraphic;
for (int i = 0; i < _changeListeners.size(); ++i) {
_changeListeners.get(i).graphicAdded(this, aGraphic);
}
}
use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.
the class GridGraphicPanel method dropGraphic.
@Override
protected void dropGraphic(GraphicObject aGraphic, boolean aUndoable) {
Rectangle bounds = this.getGraphicsBounds();
if (bounds == null) {
bounds = new Rectangle(0, 0, this.getSize().width, this.getSize().height);
}
Dimension padding = this.padding;
if (padding == null)
padding = new Dimension(0, 0);
Rectangle r = aGraphic.getRect();
if (this.tileSize != null) {
Dimension total = new Dimension(tileSize.width + padding.width, tileSize.height + padding.height);
Point currentCentre = new Point(r.x + r.width / 2, r.y + r.height / 2);
Point closestPoint = new Point((currentCentre.x - (Math.abs(currentCentre.x) % total.width)) + (total.width / 2), (currentCentre.y - (Math.abs(currentCentre.y) % total.height)) + (total.height / 2));
aGraphic.setRect(new Rectangle(closestPoint.x - r.width / 2, closestPoint.y - r.height / 2, r.width, r.height));
}
super.dropGraphic(aGraphic, aUndoable);
}
use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.
the class GraphicPanel method mouseDragged.
public void mouseDragged(MouseEvent evt) {
if (_lastClickPoint == null)
return;
Point p = evt.getPoint();
Point dist = new Point(p.x - _lastClickPoint.x, p.y - _lastClickPoint.y);
switch(_mouseButtonPressed) {
case DRAG_BUTTON:
case DRAG_BUTTON_2:
{
moveContent(dist, _lastOrigin);
}
break;
case SELECT_BUTTON:
{
if (System.getProperty("os.name").startsWith("Mac OS X") && (evt.getModifiers() & ActionEvent.META_MASK) != 0) {
moveContent(dist, _lastOrigin);
break;
}
if (!_bAllowsEditing)
break;
if (_resizingGraphic != null && _resizeDirection != Compass.NONE) {
Point resizeDist = MathUtil.dividePoint(dist, _zoom);
_resizingGraphic.resizeFromSavedPoint(resizeDist, _resizeDirection);
} else if (_multiSelectRect != null) {
int topX = Math.min(p.x, _lastClickPoint.x);
int topY = Math.min(p.y, _lastClickPoint.y);
int bottomX = Math.max(p.x, _lastClickPoint.x);
int bottomY = Math.max(p.y, _lastClickPoint.y);
_multiSelectRect = new Rectangle(topX, topY, bottomX - topX, bottomY - topY);
} else {
for (int i = 0; i < _drawStack.size(); ++i) {
GraphicObject graphic = _drawStack.get(i);
if (graphic.isSelected()) {
graphic.moveFromSavedPoint(MathUtil.dividePoint(dist, _zoom));
}
}
}
}
break;
}
repaint();
}
use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.
the class GraphicPanel method topGraphicAtPosition.
protected GraphicObject topGraphicAtPosition(Point aPoint) {
for (int i = 0; i < _drawStack.size(); ++i) {
GraphicObject graphic = _drawStack.get(i);
Rectangle r = convertRectToViewRect(graphic.getRect());
if (MathUtil.pointRectCollide(aPoint, r)) {
return graphic;
}
}
return null;
}
Aggregations