mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
draw line
This commit is contained in:
parent
667768e100
commit
fef9302793
1 changed files with 35 additions and 20 deletions
|
|
@ -77,10 +77,9 @@ public class RenderEngine extends JPanel {
|
||||||
* Remove a {@code Renderer} from the engine because it won't be needed anymore.
|
* Remove a {@code Renderer} from the engine because it won't be needed anymore.
|
||||||
* <p>If the object should only temporarily be invisible, change its {@code isVisible} field</p>
|
* <p>If the object should only temporarily be invisible, change its {@code isVisible} field</p>
|
||||||
* @param d
|
* @param d
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public boolean removeRenderer(Renderer d){
|
public void removeRenderer(Renderer d){
|
||||||
return layerManager.removeRenderer(d);
|
layerManager.removeRenderer(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -136,16 +135,16 @@ public class RenderEngine extends JPanel {
|
||||||
public void fillRect(Vector2D position, Vector2D size, Color color, double rotation){
|
public void fillRect(Vector2D position, Vector2D size, Color color, double rotation){
|
||||||
drawSetup(position, size, color, rotation);
|
drawSetup(position, size, color, rotation);
|
||||||
g2d.fillRect(
|
g2d.fillRect(
|
||||||
(int) sdc.abs.x, (int) sdc.abs.y,
|
(int) sdc.pos.x, (int) sdc.pos.y,
|
||||||
(int) sdc.sizeAbs.x, (int) sdc.sizeAbs.y);
|
(int) sdc.size.x, (int) sdc.size.y);
|
||||||
drawTearDown();
|
drawTearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillRoundRect(Vector2D position, Vector2D size, Vector2D arcFactors, Color color, double rotation){
|
public void fillRoundRect(Vector2D position, Vector2D size, Vector2D arcFactors, Color color, double rotation){
|
||||||
drawSetup(position, size, color, rotation);
|
drawSetup(position, size, color, rotation);
|
||||||
g2d.fillRoundRect(
|
g2d.fillRoundRect(
|
||||||
(int) sdc.abs.x, (int) sdc.abs.y,
|
(int) sdc.pos.x, (int) sdc.pos.y,
|
||||||
(int) sdc.sizeAbs.x, (int) sdc.sizeAbs.y,
|
(int) sdc.size.x, (int) sdc.size.y,
|
||||||
(int) (master.getW() / arcFactors.x), (int) (master.getH() / arcFactors.y));
|
(int) (master.getW() / arcFactors.x), (int) (master.getH() / arcFactors.y));
|
||||||
drawTearDown();
|
drawTearDown();
|
||||||
}
|
}
|
||||||
|
|
@ -153,20 +152,33 @@ public class RenderEngine extends JPanel {
|
||||||
public void fillOval(Vector2D position, Vector2D size, Color color, double rotation){
|
public void fillOval(Vector2D position, Vector2D size, Color color, double rotation){
|
||||||
drawSetup(position, size, color, rotation);
|
drawSetup(position, size, color, rotation);
|
||||||
g2d.fillOval(
|
g2d.fillOval(
|
||||||
(int) sdc.abs.x, (int) sdc.abs.y,
|
(int) sdc.pos.x, (int) sdc.pos.y,
|
||||||
(int) sdc.sizeAbs.x, (int) sdc.sizeAbs.y);
|
(int) sdc.size.x, (int) sdc.size.y);
|
||||||
drawTearDown();
|
drawTearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawRect(Vector2D position, Vector2D size, Color color, int rotation) {
|
public void drawRect(Vector2D position, Vector2D size, Color color, int rotation) {
|
||||||
drawSetup(position, size, color, rotation);
|
drawSetup(position, size, color, rotation);
|
||||||
g2d.drawRect(
|
g2d.drawRect(
|
||||||
(int) sdc.abs.x, (int) sdc.abs.y,
|
(int) sdc.pos.x, (int) sdc.pos.y,
|
||||||
(int) sdc.sizeAbs.x, (int) sdc.sizeAbs.y
|
(int) sdc.size.x, (int) sdc.size.y
|
||||||
);
|
);
|
||||||
drawTearDown();
|
drawTearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void drawLine(Vector2D position1, Vector2D position2, Vector2D size, Color color, int rotation){
|
||||||
|
drawSetup(position1, size, color, rotation);
|
||||||
|
g2d.setStroke(new BasicStroke((int) sdc.size.x, BasicStroke.CAP_BUTT,
|
||||||
|
BasicStroke.JOIN_BEVEL));
|
||||||
|
|
||||||
|
Vector2D absPos2 = Coordinates.getWorldCoordinates(shiftPoint(position2));
|
||||||
|
g2d.drawLine((int)sdc.pos.x, (int)sdc.pos.y, (int)absPos2.x, (int)absPos2.y);
|
||||||
|
drawTearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before every J2D draw method
|
||||||
|
*/
|
||||||
private void drawSetup(Vector2D position, Vector2D size, Color color, double rotation, Object ... args){
|
private void drawSetup(Vector2D position, Vector2D size, Color color, double rotation, Object ... args){
|
||||||
Vector2D abs = Coordinates.getWorldCoordinates(shiftPoint(position));
|
Vector2D abs = Coordinates.getWorldCoordinates(shiftPoint(position));
|
||||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(scaleSize(size));
|
Vector2D sizeAbs = Coordinates.getWorldCoordinates(scaleSize(size));
|
||||||
|
|
@ -175,11 +187,14 @@ public class RenderEngine extends JPanel {
|
||||||
sdc = new ShapeDrawContainer(abs, sizeAbs, centerAbs, color, rotation, args);
|
sdc = new ShapeDrawContainer(abs, sizeAbs, centerAbs, color, rotation, args);
|
||||||
|
|
||||||
g2d.setPaint(sdc.color);
|
g2d.setPaint(sdc.color);
|
||||||
g2d.rotate(sdc.rotation, sdc.centerAbs.x, sdc.centerAbs.y);
|
g2d.rotate(sdc.rotation, sdc.center.x, sdc.center.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after every J2D draw method
|
||||||
|
*/
|
||||||
private void drawTearDown(){
|
private void drawTearDown(){
|
||||||
g2d.rotate(-sdc.rotation, sdc.centerAbs.x, sdc.centerAbs.y);
|
g2d.rotate(-sdc.rotation, sdc.center.x, sdc.center.y);
|
||||||
sdc = null; //to avoid any drawing errors, might be changed at some point
|
sdc = null; //to avoid any drawing errors, might be changed at some point
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,17 +203,17 @@ public class RenderEngine extends JPanel {
|
||||||
* Holds all information about a shape to be drawn
|
* Holds all information about a shape to be drawn
|
||||||
*/
|
*/
|
||||||
private class ShapeDrawContainer {
|
private class ShapeDrawContainer {
|
||||||
public Vector2D abs;
|
public Vector2D pos;
|
||||||
public Vector2D sizeAbs;
|
public Vector2D size;
|
||||||
public Vector2D centerAbs;
|
public Vector2D center;
|
||||||
public Color color;
|
public Color color;
|
||||||
public double rotation;
|
public double rotation;
|
||||||
public Object[] args;
|
public Object[] args;
|
||||||
|
|
||||||
public ShapeDrawContainer(Vector2D abs, Vector2D sizeAbs, Vector2D centerAbs, Color color, double rotation, Object ... args) {
|
public ShapeDrawContainer(Vector2D pos, Vector2D size, Vector2D center, Color color, double rotation, Object ... args) {
|
||||||
this.abs = abs;
|
this.pos = pos;
|
||||||
this.sizeAbs = sizeAbs;
|
this.size = size;
|
||||||
this.centerAbs = centerAbs;
|
this.center = center;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue