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;
}
use of java.awt.Rectangle in project darkFunction-Editor by darkFunction.
the class GraphicPanel method drawCheckerBoardBuffer.
protected void drawCheckerBoardBuffer(final Graphics g, final Rectangle aRect) {
if (_checkerBoard == null)
_checkerBoard = this.makeCheckerBoardBuffer(new Rectangle(0, 0, 256, 256));
g.clipRect(aRect.x, aRect.y, aRect.width, aRect.height);
for (int x = aRect.x; x < aRect.x + aRect.width; ++x) {
for (int y = aRect.y; y < aRect.y + aRect.height; ++y) {
g.drawImage(_checkerBoard, x, y, null);
y += _checkerBoard.getHeight() - 1;
}
x += _checkerBoard.getWidth() - 1;
}
g.setClip(0, 0, this.getWidth(), this.getHeight());
}
Aggregations