diff --git a/application/src/main/java/net/emustudio/application/gui/dialogs/EditorPanel.java b/application/src/main/java/net/emustudio/application/gui/dialogs/EditorPanel.java index 4ba7c313c..25e46ff03 100644 --- a/application/src/main/java/net/emustudio/application/gui/dialogs/EditorPanel.java +++ b/application/src/main/java/net/emustudio/application/gui/dialogs/EditorPanel.java @@ -18,7 +18,6 @@ */ package net.emustudio.application.gui.dialogs; -import net.emustudio.application.Constants; import net.emustudio.application.gui.actions.CompileAction; import net.emustudio.application.gui.actions.editor.*; import net.emustudio.application.gui.editor.Editor; diff --git a/plugins/device/zxspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/gui/DisplayWindow.java b/plugins/device/zxspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/gui/DisplayWindow.java index 7426ab332..aef8d64b4 100644 --- a/plugins/device/zxspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/gui/DisplayWindow.java +++ b/plugins/device/zxspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/gui/DisplayWindow.java @@ -21,6 +21,7 @@ import net.emustudio.plugins.device.zxspectrum.ula.ULA; import javax.swing.*; +import javax.swing.border.BevelBorder; import java.awt.*; import java.awt.event.WindowEvent; @@ -34,10 +35,11 @@ public class DisplayWindow extends JDialog { private final static int BOUND_Y = (int) (DisplayCanvas.ZOOM * SCREEN_IMAGE_HEIGHT + 2 * MARGIN); private final DisplayCanvas canvas; + private final KeyboardCanvas keyboardCanvas = new KeyboardCanvas(70); + private final JPanel statusBar = new JPanel(); public DisplayWindow(JFrame parent, ULA ula) { super(parent); - KeyboardCanvas keyboardCanvas = new KeyboardCanvas(70); this.canvas = new DisplayCanvas(ula, keyboardCanvas); initComponents(); @@ -70,16 +72,32 @@ private void initComponents() { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); canvas.setBounds(MARGIN, MARGIN, BOUND_X, BOUND_Y); + statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.X_AXIS)); + statusBar.setBorder(new BevelBorder(BevelBorder.LOWERED)); + + JLabel labelOpacity = new JLabel("Keyboard opacity:"); + labelOpacity.setHorizontalAlignment(SwingConstants.LEFT); + statusBar.add(labelOpacity); + + JSlider sliderOpacity = new JSlider(); + sliderOpacity.setMinimum(0); + sliderOpacity.setMaximum(100); + sliderOpacity.setValue(keyboardCanvas.getAlpha()); + sliderOpacity.addChangeListener(e -> keyboardCanvas.setAlpha(sliderOpacity.getValue())); + statusBar.add(sliderOpacity); + GroupLayout layout = new GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) - .addComponent(canvas)); + .addComponent(canvas) + .addComponent(statusBar, GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE)); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(canvas, GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE) - .addContainerGap())); + .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) + .addComponent(statusBar, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE))); pack(); } diff --git a/plugins/device/zxspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/gui/KeyboardCanvas.java b/plugins/device/zxspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/gui/KeyboardCanvas.java index 28c670d32..27085d2b2 100644 --- a/plugins/device/zxspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/gui/KeyboardCanvas.java +++ b/plugins/device/zxspectrum-ula/src/main/java/net/emustudio/plugins/device/zxspectrum/ula/gui/KeyboardCanvas.java @@ -25,7 +25,7 @@ public class KeyboardCanvas extends JComponent implements KeyboardDispatcher.OnK private final static double sHalf = s / 2.0; // space between buttons private final static int arc = 15; // arc radius private final static int margin = 10; - private final static int rshiftw = 3 * bw - 3 * s - margin + (int)sHalf; // right shift width + private final static int rshiftw = 3 * bw - 3 * s - margin + (int) sHalf; // right shift width public final static int KEYBOARD_WIDTH = 13 * (bw + s) + bsw + 10 + 10; public final static int KEYBOARD_HEIGHT = 5 * (bh + s) + 2 * margin - s; @@ -104,12 +104,14 @@ public class KeyboardCanvas extends JComponent implements KeyboardDispatcher.OnK private final Color usableButtonColor; private final Color outlineColor; private final Color brightColor; + private int alpha; private boolean symShift = false; private boolean shift = false; public KeyboardCanvas(int alpha) { setDoubleBuffered(true); + this.alpha = alpha; this.usableButtonColor = new Color( Color.LIGHT_GRAY.getRed(), Color.LIGHT_GRAY.getGreen(), @@ -131,6 +133,14 @@ public boolean onKeyEvent(KeyEvent e) { return true; } + public int getAlpha() { + return alpha; + } + + public void setAlpha(int alpha) { + this.alpha = alpha; + } + public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; // we must set RenderingHints before any drawing @@ -142,7 +152,7 @@ public void paint(Graphics g) { g2d.setFont(new Font("SansSerif", Font.PLAIN, 11)); g2d.setStroke(outlineStroke); - g2d.setColor(brightColor); + g2d.setColor(adjustAlpha(brightColor)); g2d.translate(X_SHIFT_L, 0); for (int i = 0; i < KEY_MAP.length; i++) { @@ -161,7 +171,7 @@ public void paint(Graphics g) { int sw = g2d.getFontMetrics().stringWidth(text); g2d.translate(KEY_MAP[i][0] - sw / 2.0, KEY_MAP[i][1]); - g2d.setColor(outlineColor); + g2d.setColor(adjustAlpha(outlineColor)); g2d.fill(textShape); g2d.translate(sw / 2.0, 0); } @@ -169,18 +179,20 @@ public void paint(Graphics g) { private void drawKeyboard(Graphics2D g) { BasicStroke stroke = new BasicStroke(2.0f); + Color adjUsableButtonColor = adjustAlpha(usableButtonColor); + Color adjOutlineColor = adjustAlpha(outlineColor); // keyboard shape g.setStroke(stroke); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); g.drawRoundRect(X_SHIFT, -STROKE_WIDTH, KEYBOARD_WIDTH, KEYBOARD_HEIGHT, arc, arc); // top row for (int i = 0; i < 13; i++) { if (i >= 1 && i <= 10) { - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L + i * (bw + s), Y_SHIFT_T, bw, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); } g.drawRoundRect(X_SHIFT_L + i * (bw + s), Y_SHIFT_T, bw, bh, arc, arc); } @@ -193,9 +205,9 @@ private void drawKeyboard(Graphics2D g) { g.drawRoundRect(X_SHIFT_L, y1, tabw, bh, arc, arc); for (int i = 0; i < 12; i++) { if (i < 10) { - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L + i * (bw + s) + tabw + s, y1, bw, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); } g.drawRoundRect(X_SHIFT_L + i * (bw + s) + tabw + s, y1, bw, bh, arc, arc); } @@ -209,9 +221,9 @@ private void drawKeyboard(Graphics2D g) { 6 ); - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillPolygon(enterPolygon); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); g.drawPolygon(enterPolygon); // caps lock @@ -219,9 +231,9 @@ private void drawKeyboard(Graphics2D g) { g.drawRoundRect(X_SHIFT_L, y2, bsw, bh, arc, arc); for (int i = 0; i < 12; i++) { if (i < 9) { - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L + i * (bw + s) + bsw + s, y2, bw, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); } g.drawRoundRect(X_SHIFT_L + i * (bw + s) + bsw + s, y2, bw, bh, arc, arc); } @@ -229,43 +241,50 @@ private void drawKeyboard(Graphics2D g) { // l shift int y3 = Y_SHIFT_T + (bh + s) * 3; - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L, y3, lshiftw, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); g.drawRoundRect(X_SHIFT_L, y3, lshiftw, bh, arc, arc); for (int i = 0; i < 11; i++) { if (i >= 1 && i < 8) { - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L + i * (bw + s) + lshiftw + s, y3, bw, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); } g.drawRoundRect(X_SHIFT_L + i * (bw + s) + lshiftw + s, y3, bw, bh, arc, arc); } - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L + 11 * (bw + s) + lshiftw + s, y3, rshiftw, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); g.drawRoundRect(X_SHIFT_L + 11 * (bw + s) + lshiftw + s, y3, rshiftw, bh, arc, arc); // l ctrl int y4 = Y_SHIFT_T + (bh + s) * 4; - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L, y4, tabw, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); g.drawRoundRect(X_SHIFT_L, y4, tabw, bh, arc, arc); g.drawRoundRect(X_SHIFT_L + tabw + s, y4, bw, bh, arc, arc); g.drawRoundRect(X_SHIFT_L + tabw + bw + 2 * s, y4, tabw, bh, arc, arc); - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L + 2 * (tabw + s) + bw + 2 * s, y4, brakew, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); g.drawRoundRect(X_SHIFT_L + 2 * (tabw + s) + bw + 2 * s, y4, brakew, bh, arc, arc); g.drawRoundRect(X_SHIFT_L + 2 * (tabw + s) + bw + 4 * s + brakew, y4, tabw, bh, arc, arc); - g.setColor(usableButtonColor); + g.setColor(adjUsableButtonColor); g.fillRoundRect(X_SHIFT_L + 3 * (tabw + s) + bw + 4 * s + brakew, y4, bw, bh, arc, arc); - g.setColor(outlineColor); + g.setColor(adjOutlineColor); g.drawRoundRect(X_SHIFT_L + 3 * (tabw + s) + bw + 4 * s + brakew, y4, bw, bh, arc, arc); // RCTRL g.drawRoundRect(X_SHIFT_L + 3 * (tabw + s) + 2 * bw + 5 * s + brakew, y4, bw, bh, arc, arc); g.drawRoundRect(X_SHIFT_L + 3 * (tabw + s) + 3 * bw + 6 * s + brakew, y4, tabw, bh, arc, arc); } + + private Color adjustAlpha(Color color) { + int r = color.getRed(); + int g = color.getGreen(); + int b = color.getBlue(); + return new Color(r, g, b, this.alpha); + } }