Created
August 19, 2013 09:10
-
-
Save Munken/6267149 to your computer and use it in GitHub Desktop.
Proof of concept button in endlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package qgame.animator; | |
import qgame.frame.style.StyleSheet; | |
import qgame.plotpanel.LayerUI; | |
import qgame.util.ImageUtils; | |
import javax.swing.*; | |
import javax.swing.border.LineBorder; | |
import java.awt.*; | |
import java.awt.event.MouseEvent; | |
import static qgame.frame.style.StyleSheet.STYLE_SHEET; | |
public class AnimatorLayer extends LayerUI<JComponent> { | |
private StyleSheet stylesheet; | |
private Image labelRendering; | |
private boolean isVisible; | |
private JLabel skip; | |
private Image[] buttons; | |
public AnimatorLayer() { | |
this.stylesheet = STYLE_SHEET; | |
skip = new JLabel("Skip"); | |
skip.setBorder(new LineBorder(Color.BLACK,2)); | |
skip.setFont(stylesheet.getEndLayerFont()); | |
skip.setSize(skip.getPreferredSize()); | |
skip.setOpaque(false); | |
skip.setForeground(stylesheet.getEndLayerFontColor()); | |
} | |
public boolean containsSkip(MouseEvent e) { | |
return skip.contains(e.getPoint()); | |
} | |
public void showBeforeAnimation() { | |
showMessageAndSetVisible("If you want to see the animation, click"); | |
} | |
public void showAfterAnimation() { | |
showMessageAndSetVisible("The animation is done! Now it is your turn! Click to try it yourself!"); | |
JButton test = STYLE_SHEET.createTextButton("Test"); | |
test.setSize(test.getPreferredSize()); | |
buttons = new Image[] {ImageUtils.createComponentImage(test)}; | |
} | |
private void showMessageAndSetVisible(String mes) { | |
mes = mes.replaceAll("\n", "<br>"); | |
mes = "<html><center>" + mes + "</center></html>"; | |
JLabel label = new JLabel(mes); | |
label.setFont(stylesheet.getEndLayerFont()); | |
label.setSize(label.getPreferredSize()); | |
label.setOpaque(false); | |
label.setForeground(stylesheet.getEndLayerFontColor()); | |
labelRendering = ImageUtils.createComponentImage(label); | |
setVisible(true); | |
} | |
public void setVisible(boolean isVisible) { | |
this.isVisible = isVisible; | |
} | |
public boolean isVisible() { | |
return isVisible; | |
} | |
@Override | |
public void paint(Graphics g, JComponent c) { | |
super.paint(g, c); | |
if (!isVisible) return; | |
Graphics2D g2 = (Graphics2D) g.create(); | |
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | |
// draw faded background | |
int w = c.getWidth(); | |
int h = c.getHeight(); | |
g2.setComposite(AlphaComposite.getInstance( | |
AlphaComposite.SRC_OVER, .55f)); | |
g2.setPaint(Color.black); | |
g2.fillRect(0, 0, w, h); | |
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); | |
int x = (w - labelRendering.getWidth(null)) / 2; | |
int y = (h - labelRendering.getHeight(null)) / 2; | |
g2.drawImage(labelRendering, x, y, null); | |
skip.setLocation(20, 20); | |
skip.paint(g); | |
paintButtons(g2); | |
g2.dispose(); | |
} | |
private void paintButtons(Graphics2D g) { | |
if (buttons == null) return; | |
g.translate(100, 100); | |
for (Image button : buttons) { | |
g.drawImage(button, 0,0, null); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment