mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Make scroll arrow buttons semi-transparent and more like FLabels
This commit is contained in:
@@ -318,14 +318,12 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
|||||||
private final FMouseAdapter madEvents = new FMouseAdapter() {
|
private final FMouseAdapter madEvents = new FMouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void onMouseEnter(MouseEvent e) {
|
public void onMouseEnter(MouseEvent e) {
|
||||||
hovered = true;
|
setHovered(true);
|
||||||
repaintSelf();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMouseExit(MouseEvent e) {
|
public void onMouseExit(MouseEvent e) {
|
||||||
hovered = false;
|
setHovered(false);
|
||||||
repaintSelf();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -333,14 +331,12 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
|||||||
if (reactOnMouseDown) {
|
if (reactOnMouseDown) {
|
||||||
_doMouseAction(); //for best responsiveness, do action before repainting for pressed state
|
_doMouseAction(); //for best responsiveness, do action before repainting for pressed state
|
||||||
}
|
}
|
||||||
pressed = true;
|
setPressed(true);
|
||||||
repaintSelf();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLeftMouseUp(MouseEvent e) {
|
public void onLeftMouseUp(MouseEvent e) {
|
||||||
pressed = false;
|
setPressed(false);
|
||||||
repaintSelf();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -376,6 +372,16 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
|||||||
else { this.addMouseListener(madEvents); }
|
else { this.addMouseListener(madEvents); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setHovered(boolean hovered0) {
|
||||||
|
this.hovered = hovered0;
|
||||||
|
repaintSelf();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setPressed(boolean pressed0) {
|
||||||
|
this.pressed = pressed0;
|
||||||
|
repaintSelf();
|
||||||
|
}
|
||||||
|
|
||||||
/** @param b0   boolean */
|
/** @param b0   boolean */
|
||||||
// Must be public.
|
// Must be public.
|
||||||
public void setSelected(final boolean b0) {
|
public void setSelected(final boolean b0) {
|
||||||
@@ -540,13 +546,26 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
|||||||
else if (selectable) {
|
else if (selectable) {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
paintDown(g2d, w, h);
|
paintDown(g2d, w, h);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
paintBorder(g2d, w, h);
|
paintBorder(g2d, w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paintContent(g2d, w, h, paintPressedState);
|
||||||
|
|
||||||
|
if (hoverable) {
|
||||||
|
g2d.setComposite(oldComp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasFocus() && isEnabled()) {
|
||||||
|
paintFocus(g2d, w, h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void paintContent(final Graphics2D g, int w, int h, final boolean paintPressedState) {
|
||||||
if (paintPressedState) { //while pressed, translate graphics so icon and text appear shifted down and to the right
|
if (paintPressedState) { //while pressed, translate graphics so icon and text appear shifted down and to the right
|
||||||
g2d.translate(1, 1);
|
g.translate(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Icon in background
|
// Icon in background
|
||||||
@@ -560,21 +579,13 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
|||||||
|
|
||||||
int y = (int) (((h - sh) / 2) + iconInsets.getY());
|
int y = (int) (((h - sh) / 2) + iconInsets.getY());
|
||||||
|
|
||||||
g2d.drawImage(img, x, y, sw + x, sh + y, 0, 0, iw, ih, null);
|
g.drawImage(img, x, y, sw + x, sh + y, 0, 0, iw, ih, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
|
|
||||||
if (paintPressedState) { //reset translation after icon and text painted
|
if (paintPressedState) { //reset translation after icon and text painted
|
||||||
g2d.translate(-1, -1);
|
g.translate(-1, -1);
|
||||||
}
|
|
||||||
|
|
||||||
if (hoverable) {
|
|
||||||
g2d.setComposite(oldComp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasFocus() && isEnabled()) {
|
|
||||||
paintFocus(g2d, w, h);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package forge.gui.toolbox;
|
package forge.gui.toolbox;
|
||||||
|
|
||||||
import java.awt.AlphaComposite;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Composite;
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -28,17 +25,13 @@ import java.awt.LayoutManager;
|
|||||||
import java.awt.PopupMenu;
|
import java.awt.PopupMenu;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollBar;
|
import javax.swing.JScrollBar;
|
||||||
import javax.swing.ScrollPaneConstants;
|
import javax.swing.ScrollPaneConstants;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
|
|
||||||
import forge.gui.framework.ILocalRepaint;
|
|
||||||
import forge.gui.toolbox.FSkin.SkinColor;
|
import forge.gui.toolbox.FSkin.SkinColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,6 +40,7 @@ import forge.gui.toolbox.FSkin.SkinColor;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FScrollPanel extends FScrollPane {
|
public class FScrollPanel extends FScrollPane {
|
||||||
|
private static final SkinColor arrowColor = FSkin.getColor(FSkin.Colors.CLR_TEXT);
|
||||||
private final boolean useArrowButtons;
|
private final boolean useArrowButtons;
|
||||||
private final ArrowButton[] arrowButtons = new ArrowButton[4];
|
private final ArrowButton[] arrowButtons = new ArrowButton[4];
|
||||||
private JPanel innerPanel;
|
private JPanel innerPanel;
|
||||||
@@ -212,61 +206,34 @@ public class FScrollPanel extends FScrollPane {
|
|||||||
FAbsolutePositioner.SINGLETON_INSTANCE.show(arrowButton, this, x, y);
|
FAbsolutePositioner.SINGLETON_INSTANCE.show(arrowButton, this, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract class ArrowButton extends JLabel implements ILocalRepaint {
|
private abstract class ArrowButton extends FLabel {
|
||||||
private final SkinColor clrFore = FSkin.getColor(FSkin.Colors.CLR_TEXT);
|
|
||||||
private final SkinColor clrBack = FSkin.getColor(FSkin.Colors.CLR_INACTIVE);
|
|
||||||
private final SkinColor d50 = clrBack.stepColor(-50);
|
|
||||||
private final SkinColor d10 = clrBack.stepColor(-10);
|
|
||||||
private final SkinColor l10 = clrBack.stepColor(10);
|
|
||||||
private final SkinColor l20 = clrBack.stepColor(20);
|
|
||||||
private final AlphaComposite alphaDefault = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f);
|
|
||||||
private final AlphaComposite alphaHovered = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.9f);
|
|
||||||
protected final int arrowSize = 6;
|
protected final int arrowSize = 6;
|
||||||
private final JScrollBar scrollBar;
|
private final JScrollBar scrollBar;
|
||||||
private final int incrementDirection;
|
private final int incrementDirection;
|
||||||
private boolean hovered;
|
|
||||||
|
|
||||||
protected ArrowButton(final JScrollBar scrollBar0, final int incrementDirection0) {
|
protected ArrowButton(final JScrollBar scrollBar0, final int incrementDirection0) {
|
||||||
super("");
|
super(new FLabel.ButtonBuilder());
|
||||||
scrollBar = scrollBar0;
|
scrollBar = scrollBar0;
|
||||||
incrementDirection = incrementDirection0;
|
incrementDirection = incrementDirection0;
|
||||||
timer.setInitialDelay(500); //wait half a second after mouse down before starting timer
|
timer.setInitialDelay(500); //wait half a second after mouse down before starting timer
|
||||||
addMouseListener(madEvents);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void repaintSelf() {
|
protected void setPressed(boolean pressed0) {
|
||||||
final Dimension d = getSize();
|
super.setPressed(pressed0);
|
||||||
repaint(0, 0, d.width, d.height);
|
if (pressed0) {
|
||||||
|
scrollBar.setValue(scrollBar.getValue() + scrollBar.getUnitIncrement() * incrementDirection);
|
||||||
|
timer.start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timer.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(final Graphics g) {
|
protected void paintContent(final Graphics2D g, int w, int h, final boolean paintPressedState) {
|
||||||
Graphics2D g2d = (Graphics2D)g;
|
FSkin.setGraphicsColor(g, arrowColor);
|
||||||
|
|
||||||
int w = getWidth();
|
|
||||||
int h = getHeight();
|
|
||||||
|
|
||||||
g.setColor(Color.white); //draw white background before composite so not semi-transparent
|
|
||||||
g.fillRect(0, 0, w, h);
|
|
||||||
|
|
||||||
Composite oldComp = g2d.getComposite();
|
|
||||||
g2d.setComposite(hovered ? alphaHovered : alphaDefault);
|
|
||||||
|
|
||||||
FSkin.setGraphicsGradientPaint(g2d, 0, h, d10, 0, 0, l20);
|
|
||||||
g.fillRect(0, 0, w, h);
|
|
||||||
|
|
||||||
FSkin.setGraphicsColor(g, d50);
|
|
||||||
g.drawRect(0, 0, w - 1, h - 1);
|
|
||||||
FSkin.setGraphicsColor(g, l10);
|
|
||||||
g.drawRect(1, 1, w - 3, h - 3);
|
|
||||||
|
|
||||||
FSkin.setGraphicsColor(g, clrFore);
|
|
||||||
drawArrow(g);
|
drawArrow(g);
|
||||||
|
|
||||||
super.paintComponent(g);
|
|
||||||
|
|
||||||
g2d.setComposite(oldComp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void drawArrow(final Graphics g);
|
protected abstract void drawArrow(final Graphics g);
|
||||||
@@ -282,39 +249,6 @@ public class FScrollPanel extends FScrollPane {
|
|||||||
scrollBar.setValue(scrollBar.getValue() + scrollBar.getUnitIncrement() * incrementDirection);
|
scrollBar.setValue(scrollBar.getValue() + scrollBar.getUnitIncrement() * incrementDirection);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
private final MouseAdapter madEvents = new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mousePressed(final MouseEvent e) {
|
|
||||||
scrollBar.setValue(scrollBar.getValue() + scrollBar.getUnitIncrement() * incrementDirection);
|
|
||||||
timer.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseReleased(final MouseEvent e) {
|
|
||||||
timer.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseEntered(MouseEvent e) {
|
|
||||||
hovered = true;
|
|
||||||
repaintSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseExited(MouseEvent e) {
|
|
||||||
hovered = false;
|
|
||||||
repaintSelf();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseMoved(MouseEvent e) {
|
|
||||||
if (!hovered) {
|
|
||||||
hovered = true;
|
|
||||||
repaintSelf();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LeftArrowButton extends ArrowButton {
|
private class LeftArrowButton extends ArrowButton {
|
||||||
@@ -327,8 +261,7 @@ public class FScrollPanel extends FScrollPane {
|
|||||||
int x = (getWidth() - arrowSize) / 2;
|
int x = (getWidth() - arrowSize) / 2;
|
||||||
int y2 = getHeight() / 2;
|
int y2 = getHeight() / 2;
|
||||||
int y1 = y2 - 1;
|
int y1 = y2 - 1;
|
||||||
for (int i = 0; i < arrowSize; i++)
|
for (int i = 0; i < arrowSize; i++) {
|
||||||
{
|
|
||||||
g.drawLine(x, y1, x, y2);
|
g.drawLine(x, y1, x, y2);
|
||||||
x++;
|
x++;
|
||||||
y1--;
|
y1--;
|
||||||
@@ -347,8 +280,7 @@ public class FScrollPanel extends FScrollPane {
|
|||||||
int x = (getWidth() + arrowSize) / 2;
|
int x = (getWidth() + arrowSize) / 2;
|
||||||
int y2 = getHeight() / 2;
|
int y2 = getHeight() / 2;
|
||||||
int y1 = y2 - 1;
|
int y1 = y2 - 1;
|
||||||
for (int i = 0; i < arrowSize; i++)
|
for (int i = 0; i < arrowSize; i++) {
|
||||||
{
|
|
||||||
g.drawLine(x, y1, x, y2);
|
g.drawLine(x, y1, x, y2);
|
||||||
x--;
|
x--;
|
||||||
y1--;
|
y1--;
|
||||||
@@ -367,8 +299,7 @@ public class FScrollPanel extends FScrollPane {
|
|||||||
int x2 = getWidth() / 2;
|
int x2 = getWidth() / 2;
|
||||||
int x1 = x2 - 1;
|
int x1 = x2 - 1;
|
||||||
int y = (getHeight() - arrowSize) / 2;
|
int y = (getHeight() - arrowSize) / 2;
|
||||||
for (int i = 0; i < arrowSize; i++)
|
for (int i = 0; i < arrowSize; i++) {
|
||||||
{
|
|
||||||
g.drawLine(x1, y, x2, y);
|
g.drawLine(x1, y, x2, y);
|
||||||
x1--;
|
x1--;
|
||||||
x2++;
|
x2++;
|
||||||
@@ -387,8 +318,7 @@ public class FScrollPanel extends FScrollPane {
|
|||||||
int x2 = getWidth() / 2;
|
int x2 = getWidth() / 2;
|
||||||
int x1 = x2 - 1;
|
int x1 = x2 - 1;
|
||||||
int y = (getHeight() + arrowSize) / 2;
|
int y = (getHeight() + arrowSize) / 2;
|
||||||
for (int i = 0; i < arrowSize; i++)
|
for (int i = 0; i < arrowSize; i++) {
|
||||||
{
|
|
||||||
g.drawLine(x1, y, x2, y);
|
g.drawLine(x1, y, x2, y);
|
||||||
x1--;
|
x1--;
|
||||||
x2++;
|
x2++;
|
||||||
|
|||||||
Reference in New Issue
Block a user