mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
FPanel "fixed", that is, round corners for solid colors, square for images.
This commit is contained in:
@@ -107,6 +107,7 @@ public final class Main {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
|
System.out.println("Running finalizer");
|
||||||
// NOT WORKING
|
// NOT WORKING
|
||||||
// this should call close in model,
|
// this should call close in model,
|
||||||
// should probably be attached to frame close method
|
// should probably be attached to frame close method
|
||||||
|
|||||||
@@ -21,12 +21,9 @@ import java.awt.Color;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.geom.Area;
|
|
||||||
import java.awt.geom.RoundRectangle2D;
|
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
@@ -65,8 +62,6 @@ public class FPanel extends JPanel {
|
|||||||
private int pnlW, pnlH, imgW, imgH, scaledW, scaledH, textureW, textureH, tempX, tempY;
|
private int pnlW, pnlH, imgW, imgH, scaledW, scaledH, textureW, textureH, tempX, tempY;
|
||||||
// Image aspect ratio (width / height)
|
// Image aspect ratio (width / height)
|
||||||
private double iar;
|
private double iar;
|
||||||
// Clip rounded corner shape
|
|
||||||
private Area clip;
|
|
||||||
|
|
||||||
/** Core panel used in UI. See class javadoc for more details. */
|
/** Core panel used in UI. See class javadoc for more details. */
|
||||||
public FPanel() {
|
public FPanel() {
|
||||||
@@ -190,24 +185,15 @@ public class FPanel extends JPanel {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(final Graphics graphics0) {
|
public void paintComponent(final Graphics graphics0) {
|
||||||
//super.paintComponent(graphics0);
|
super.paintComponent(graphics0);
|
||||||
|
|
||||||
pnlW = this.getWidth();
|
pnlW = this.getWidth();
|
||||||
pnlH = this.getHeight();
|
pnlH = this.getHeight();
|
||||||
final Graphics2D g2d = (Graphics2D) graphics0.create();
|
final Graphics2D g2d = (Graphics2D) graphics0.create();
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
if (this.backgroundTexture == null) {
|
|
||||||
drawBackgroundColor(g2d);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
drawBackgroundTexture(g2d);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.paintComponent(g2d);
|
|
||||||
|
|
||||||
// Draw background as required
|
// Draw background as required
|
||||||
/* if (foregroundStretch && foregroundImage != null) {
|
if (foregroundStretch && foregroundImage != null) {
|
||||||
drawForegroundStretched(g2d);
|
drawForegroundStretched(g2d);
|
||||||
}
|
}
|
||||||
else if (this.backgroundTexture == null) {
|
else if (this.backgroundTexture == null) {
|
||||||
@@ -227,8 +213,7 @@ public class FPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear memory
|
// Clear memory
|
||||||
if (clip != null) { clip.reset(); }
|
g2d.dispose();
|
||||||
g2d.dispose();*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//========== Special draw methods
|
//========== Special draw methods
|
||||||
@@ -243,10 +228,6 @@ public class FPanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void drawBackgroundTexture(final Graphics2D g2d0) {
|
private void drawBackgroundTexture(final Graphics2D g2d0) {
|
||||||
Rectangle oldClipBounds = g2d0.getClipBounds();
|
|
||||||
//clip = new Area(new RoundRectangle2D.Float(0, 0, pnlW, pnlH, cornerDiameter, cornerDiameter));
|
|
||||||
//g2d0.setClip(clip);
|
|
||||||
|
|
||||||
this.tempX = 0;
|
this.tempX = 0;
|
||||||
this.tempY = 0;
|
this.tempY = 0;
|
||||||
|
|
||||||
@@ -259,14 +240,9 @@ public class FPanel extends JPanel {
|
|||||||
this.tempY = 0;
|
this.tempY = 0;
|
||||||
}
|
}
|
||||||
this.tempX = 0;
|
this.tempX = 0;
|
||||||
g2d0.setClip(oldClipBounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawForegroundScaled(final Graphics2D g2d0) {
|
private void drawForegroundScaled(final Graphics2D g2d0) {
|
||||||
Rectangle oldClipBounds = g2d0.getClipBounds();
|
|
||||||
clip = new Area(new RoundRectangle2D.Float(0, 0, pnlW, pnlH, cornerDiameter, cornerDiameter));
|
|
||||||
g2d0.setClip(clip);
|
|
||||||
|
|
||||||
// Scaling 1: First dimension larger than panel
|
// Scaling 1: First dimension larger than panel
|
||||||
if (imgW >= pnlW) { // Image is wider than panel? Shrink to width.
|
if (imgW >= pnlW) { // Image is wider than panel? Shrink to width.
|
||||||
scaledW = pnlW;
|
scaledW = pnlW;
|
||||||
@@ -295,15 +271,10 @@ public class FPanel extends JPanel {
|
|||||||
tempX = (int) ((pnlW - scaledW) / 2);
|
tempX = (int) ((pnlW - scaledW) / 2);
|
||||||
tempY = (int) ((pnlH - scaledH) / 2);
|
tempY = (int) ((pnlH - scaledH) / 2);
|
||||||
g2d0.drawImage(foregroundImage, tempX, tempY, scaledW + tempX, scaledH + tempY, 0, 0, imgW, imgH, null);
|
g2d0.drawImage(foregroundImage, tempX, tempY, scaledW + tempX, scaledH + tempY, 0, 0, imgW, imgH, null);
|
||||||
g2d0.setClip(oldClipBounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawForegroundStretched(final Graphics2D g2d0) {
|
private void drawForegroundStretched(final Graphics2D g2d0) {
|
||||||
Rectangle oldClipBounds = g2d0.getClipBounds();
|
|
||||||
clip = new Area(new RoundRectangle2D.Float(0, 0, pnlW, pnlH, cornerDiameter, cornerDiameter));
|
|
||||||
g2d0.setClip(clip);
|
|
||||||
g2d0.drawImage(foregroundImage, 0, 0, pnlW, pnlH, 0, 0, imgW, imgH, null);
|
g2d0.drawImage(foregroundImage, 0, 0, pnlW, pnlH, 0, 0, imgW, imgH, null);
|
||||||
g2d0.setClip(oldClipBounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawBorder(final Graphics2D g2d0) {
|
private void drawBorder(final Graphics2D g2d0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user