use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class SvgCreator method createLine.
public static Element createLine(Document doc, Line line) {
Element elt = doc.createElement("line");
Location v1 = line.getEnd0();
Location v2 = line.getEnd1();
elt.setAttribute("x1", "" + v1.getX());
elt.setAttribute("y1", "" + v1.getY());
elt.setAttribute("x2", "" + v2.getX());
elt.setAttribute("y2", "" + v2.getY());
populateStroke(elt, line);
return elt;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class AbstractCanvasObject method overlaps.
public boolean overlaps(CanvasObject other) {
Bounds a = this.getBounds();
Bounds b = other.getBounds();
Bounds c = a.intersect(b);
Random rand = new Random();
if (c.getWidth() == 0 || c.getHeight() == 0) {
return false;
} else if (other instanceof AbstractCanvasObject) {
AbstractCanvasObject that = (AbstractCanvasObject) other;
for (int i = 0; i < OVERLAP_TRIES; i++) {
if (i % 2 == 0) {
Location loc = this.getRandomPoint(c, rand);
if (loc != null && that.contains(loc, false))
return true;
} else {
Location loc = that.getRandomPoint(c, rand);
if (loc != null && this.contains(loc, false))
return true;
}
}
return false;
} else {
for (int i = 0; i < OVERLAP_TRIES; i++) {
Location loc = this.getRandomPoint(c, rand);
if (loc != null && other.contains(loc, false))
return true;
}
return false;
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Curve method getHandleArray.
private Handle[] getHandleArray(HandleGesture gesture) {
if (gesture == null) {
return new Handle[] { new Handle(this, p0), new Handle(this, p1), new Handle(this, p2) };
} else {
Handle g = gesture.getHandle();
int gx = g.getX() + gesture.getDeltaX();
int gy = g.getY() + gesture.getDeltaY();
Handle[] ret = { new Handle(this, p0), new Handle(this, p1), new Handle(this, p2) };
if (g.isAt(p0)) {
if (gesture.isShiftDown()) {
Location p = LineUtil.snapTo8Cardinals(p2, gx, gy);
ret[0] = new Handle(this, p);
} else {
ret[0] = new Handle(this, gx, gy);
}
} else if (g.isAt(p2)) {
if (gesture.isShiftDown()) {
Location p = LineUtil.snapTo8Cardinals(p0, gx, gy);
ret[2] = new Handle(this, p);
} else {
ret[2] = new Handle(this, gx, gy);
}
} else if (g.isAt(p1)) {
if (gesture.isShiftDown()) {
double x0 = p0.getX();
double y0 = p0.getY();
double x1 = p2.getX();
double y1 = p2.getY();
double midx = (x0 + x1) / 2;
double midy = (y0 + y1) / 2;
double dx = x1 - x0;
double dy = y1 - y0;
double[] p = LineUtil.nearestPointInfinite(gx, gy, midx, midy, midx - dy, midy + dx);
gx = (int) Math.round(p[0]);
gy = (int) Math.round(p[1]);
}
if (gesture.isAltDown()) {
double[] e0 = { p0.getX(), p0.getY() };
double[] e1 = { p2.getX(), p2.getY() };
double[] mid = { gx, gy };
double[] ct = CurveUtil.interpolate(e0, e1, mid);
gx = (int) Math.round(ct[0]);
gy = (int) Math.round(ct[1]);
}
ret[1] = new Handle(this, gx, gy);
}
return ret;
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class InstanceTextField method getTextCaret.
public Caret getTextCaret(ComponentUserEvent event) {
canvas = event.getCanvas();
Graphics g = canvas.getGraphics();
// and if it is empty, just return a caret at its beginning
if (field == null)
createField(comp.getAttributeSet(), "");
String text = field.getText();
if (text == null || text.equals(""))
return field.getCaret(g, 0);
Bounds bds = field.getBounds(g);
if (bds.getWidth() < 4 || bds.getHeight() < 4) {
Location loc = comp.getLocation();
bds = bds.add(Bounds.create(loc).expand(2));
}
int x = event.getX();
int y = event.getY();
if (bds.contains(x, y))
return field.getCaret(g, x, y);
else
return null;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class InstanceComponent method contains.
public boolean contains(Location pt) {
Location translated = pt.translate(-loc.getX(), -loc.getY());
InstanceFactory factory = instance.getFactory();
return factory.contains(translated, instance.getAttributeSet());
}
Aggregations