Skip to content

Commit

Permalink
fixed background splines not properly being rendered on unfullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarhead committed Dec 27, 2022
1 parent b15dc90 commit ac3e1da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/main/java/jarhead/DrawPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public class DrawPanel extends JPanel {
Polygon poly = new Polygon(xPoly, yPoly, xPoly.length);

public void update(){
renderBackgroundSplines();
resetPath();
preRenderedSplines = null;
// renderBackgroundSplines();
repaint();
}

Expand All @@ -44,7 +46,7 @@ public Dimension getPreferredSize() {
int width = main.getWidth()-(main.infoPanel.getWidth() + in.left + in.right + main.exportPanel.getWidth());
int height = (main.getHeight()-(main.buttonPanel.getHeight()+in.top + in.bottom));
int min = Math.min(width, height);
main.scale = min/144;
main.scale = min/144.0;
return new Dimension(min, min);
}

Expand Down Expand Up @@ -110,7 +112,11 @@ private void renderSplines(Graphics g, Path path, Color color) {
private void renderRobotPath(Graphics2D g, Path path, Color color, float transparency) {
//TODO: make this faster :(
if(this.getWidth() != this.getHeight()) System.out.println("w != h");
BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
BufferedImage image;
if(this.getWidth() > 0)
image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
else
image = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setColor(color);
double rX = main.robotLength*main.scale;
Expand Down Expand Up @@ -165,10 +171,6 @@ private void renderPoints(Graphics g, Path path, Color c1, int ovalscale){
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(new ImageIcon(Main.class.getResource("/field-2022-kai-dark.png")).getImage(), 0, 0,this.getWidth(), this.getHeight(), null);
if(preRenderedSplines == null) renderBackgroundSplines();
g.drawImage(preRenderedSplines, 0,0,null);

main.scale = ((double)this.getWidth()-this.getInsets().left - this.getInsets().right)/144.0;
if(oldScale != main.scale)
main.getManagers().forEach(nodeManager -> {
Expand All @@ -178,6 +180,11 @@ public void paintComponent(Graphics g) {
});

oldScale = main.scale;
g.drawImage(new ImageIcon(Main.class.getResource("/field-2022-kai-dark.png")).getImage(), 0, 0,this.getWidth(), this.getHeight(), null);
if(preRenderedSplines == null || preRenderedSplines.getWidth() != this.getWidth()) renderBackgroundSplines();
g.drawImage(preRenderedSplines, 0,0,null);


if(getCurrentManager().size() > 0) {

Node node = getCurrentManager().get(0);
Expand Down Expand Up @@ -220,8 +227,8 @@ public void paintComponent(Graphics g) {
public void renderBackgroundSplines(){
if(this.getWidth() > 0)
preRenderedSplines = new BufferedImage((this.getWidth()), this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);

else preRenderedSplines = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);

Graphics g = preRenderedSplines.getGraphics();
for (NodeManager manager : managers){
if(!manager.equals(getCurrentManager())){
Expand Down Expand Up @@ -263,6 +270,7 @@ public void renderBackgroundSplines(){
}
}
}
g.dispose();
}

private void renderArrows(Graphics g, NodeManager nodeM, int ovalscale, Color color1, Color color2, Color color3) {
Expand Down Expand Up @@ -475,6 +483,8 @@ private void keyInput(KeyEvent e){
main.undo();
}

// if(e.getKeyCode() == KeyEvent.VK_J) preRenderedSplines = null;

if(e.getKeyCode() == KeyEvent.VK_DELETE || e.getKeyCode() == KeyEvent.VK_BACK_SPACE){
if(main.currentN >= 0){
Node n = getCurrentManager().get(main.currentN);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/jarhead/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void redo(){
Node node = getCurrentManager().redo.last();
Node u;
Node temp;
//TODO: fix undo and redo
switch (node.state){
case 1: //redo delete
temp = getCurrentManager().get(node.index);
Expand Down

0 comments on commit ac3e1da

Please sign in to comment.