Skip to content

Commit c6f4870

Browse files
committed
Implemented Card Stack Rendering
1 parent 2180a78 commit c6f4870

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/de/littlerolf/sav/gui/SAVHistoryComponent.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package de.littlerolf.sav.gui;
22

33
import java.awt.Graphics;
4+
import java.awt.Graphics2D;
5+
import java.awt.RenderingHints;
46
import java.awt.image.BufferedImage;
57
import java.io.IOException;
68
import java.util.ArrayList;
@@ -51,7 +53,7 @@ public class SAVHistoryComponent extends JComponent {
5153

5254
public SAVHistoryComponent() {
5355
HistoryItem i = new HistoryItem();
54-
i.values = new int[] { 4, 50, 42, 3 };
56+
i.values = new int[] { 4, 10, 5, 20, 50, 10, 3, 48 };
5557
getHistoryItems().add(i);
5658
}
5759

@@ -68,8 +70,13 @@ public void reset() {
6870
}
6971

7072
@Override
71-
protected void paintComponent(Graphics g) {
72-
super.paintComponent(g);
73+
protected void paintComponent(Graphics g1) {
74+
super.paintComponent(g1);
75+
Graphics2D g = (Graphics2D) g1;
76+
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
77+
RenderingHints.VALUE_ANTIALIAS_ON);
78+
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
79+
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
7380

7481
HistoryItem currentItem = getHistoryItems().get(currentIndex);
7582
if (currentItem == null)
@@ -78,15 +85,17 @@ protected void paintComponent(Graphics g) {
7885
int valueAmount = currentItem.values.length;
7986
int width = getWidth();
8087
int height = getHeight();
81-
int x = 0;
88+
int i = 0;
89+
int diff = width / 2 / valueAmount;
8290
for (int value : currentItem.values) {
8391
if (value > cardImages.length || value < 0)
8492
continue;
93+
8594
BufferedImage cardImage = cardImages[value];
86-
g.drawImage(cardImage,
87-
x + width / 2 - (valueAmount * cardImage.getWidth()) / 2,
88-
height / 2 - cardImage.getHeight() / 2, null);
89-
x += cardImage.getWidth();
95+
g.drawImage(cardImage, width / 4 - cardImage.getWidth() / 4 + i
96+
* diff, height / 2 - cardImage.getHeight() / 2 / 2,
97+
cardImage.getWidth() / 2, cardImage.getHeight() / 2, null);
98+
i++;
9099
}
91100
}
92101

0 commit comments

Comments
 (0)