mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +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() {
|
||||
@Override
|
||||
public void onMouseEnter(MouseEvent e) {
|
||||
hovered = true;
|
||||
repaintSelf();
|
||||
setHovered(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseExit(MouseEvent e) {
|
||||
hovered = false;
|
||||
repaintSelf();
|
||||
setHovered(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -333,14 +331,12 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
||||
if (reactOnMouseDown) {
|
||||
_doMouseAction(); //for best responsiveness, do action before repainting for pressed state
|
||||
}
|
||||
pressed = true;
|
||||
repaintSelf();
|
||||
setPressed(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLeftMouseUp(MouseEvent e) {
|
||||
pressed = false;
|
||||
repaintSelf();
|
||||
setPressed(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -376,6 +372,16 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
||||
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 */
|
||||
// Must be public.
|
||||
public void setSelected(final boolean b0) {
|
||||
@@ -540,13 +546,26 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
||||
else if (selectable) {
|
||||
if (selected) {
|
||||
paintDown(g2d, w, h);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
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
|
||||
g2d.translate(1, 1);
|
||||
g.translate(1, 1);
|
||||
}
|
||||
|
||||
// Icon in background
|
||||
@@ -560,21 +579,13 @@ public class FLabel extends SkinnedLabel implements ILocalRepaint {
|
||||
|
||||
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);
|
||||
|
||||
if (paintPressedState) { //reset translation after icon and text painted
|
||||
g2d.translate(-1, -1);
|
||||
}
|
||||
|
||||
if (hoverable) {
|
||||
g2d.setComposite(oldComp);
|
||||
}
|
||||
|
||||
if (hasFocus() && isEnabled()) {
|
||||
paintFocus(g2d, w, h);
|
||||
g.translate(-1, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,7 @@
|
||||
*/
|
||||
package forge.gui.toolbox;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
@@ -28,17 +25,13 @@ import java.awt.LayoutManager;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.event.ActionEvent;
|
||||
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.JScrollBar;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import forge.gui.framework.ILocalRepaint;
|
||||
import forge.gui.toolbox.FSkin.SkinColor;
|
||||
|
||||
/**
|
||||
@@ -47,6 +40,7 @@ import forge.gui.toolbox.FSkin.SkinColor;
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class FScrollPanel extends FScrollPane {
|
||||
private static final SkinColor arrowColor = FSkin.getColor(FSkin.Colors.CLR_TEXT);
|
||||
private final boolean useArrowButtons;
|
||||
private final ArrowButton[] arrowButtons = new ArrowButton[4];
|
||||
private JPanel innerPanel;
|
||||
@@ -212,61 +206,34 @@ public class FScrollPanel extends FScrollPane {
|
||||
FAbsolutePositioner.SINGLETON_INSTANCE.show(arrowButton, this, x, y);
|
||||
}
|
||||
|
||||
private abstract class ArrowButton extends JLabel implements ILocalRepaint {
|
||||
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);
|
||||
private abstract class ArrowButton extends FLabel {
|
||||
protected final int arrowSize = 6;
|
||||
private final JScrollBar scrollBar;
|
||||
private final int incrementDirection;
|
||||
private boolean hovered;
|
||||
|
||||
protected ArrowButton(final JScrollBar scrollBar0, final int incrementDirection0) {
|
||||
super("");
|
||||
super(new FLabel.ButtonBuilder());
|
||||
scrollBar = scrollBar0;
|
||||
incrementDirection = incrementDirection0;
|
||||
timer.setInitialDelay(500); //wait half a second after mouse down before starting timer
|
||||
addMouseListener(madEvents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void repaintSelf() {
|
||||
final Dimension d = getSize();
|
||||
repaint(0, 0, d.width, d.height);
|
||||
protected void setPressed(boolean pressed0) {
|
||||
super.setPressed(pressed0);
|
||||
if (pressed0) {
|
||||
scrollBar.setValue(scrollBar.getValue() + scrollBar.getUnitIncrement() * incrementDirection);
|
||||
timer.start();
|
||||
}
|
||||
else {
|
||||
timer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintComponent(final Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D)g;
|
||||
|
||||
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);
|
||||
protected void paintContent(final Graphics2D g, int w, int h, final boolean paintPressedState) {
|
||||
FSkin.setGraphicsColor(g, arrowColor);
|
||||
drawArrow(g);
|
||||
|
||||
super.paintComponent(g);
|
||||
|
||||
g2d.setComposite(oldComp);
|
||||
}
|
||||
|
||||
protected abstract void drawArrow(final Graphics g);
|
||||
@@ -282,39 +249,6 @@ public class FScrollPanel extends FScrollPane {
|
||||
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 {
|
||||
@@ -327,8 +261,7 @@ public class FScrollPanel extends FScrollPane {
|
||||
int x = (getWidth() - arrowSize) / 2;
|
||||
int y2 = getHeight() / 2;
|
||||
int y1 = y2 - 1;
|
||||
for (int i = 0; i < arrowSize; i++)
|
||||
{
|
||||
for (int i = 0; i < arrowSize; i++) {
|
||||
g.drawLine(x, y1, x, y2);
|
||||
x++;
|
||||
y1--;
|
||||
@@ -347,8 +280,7 @@ public class FScrollPanel extends FScrollPane {
|
||||
int x = (getWidth() + arrowSize) / 2;
|
||||
int y2 = getHeight() / 2;
|
||||
int y1 = y2 - 1;
|
||||
for (int i = 0; i < arrowSize; i++)
|
||||
{
|
||||
for (int i = 0; i < arrowSize; i++) {
|
||||
g.drawLine(x, y1, x, y2);
|
||||
x--;
|
||||
y1--;
|
||||
@@ -367,8 +299,7 @@ public class FScrollPanel extends FScrollPane {
|
||||
int x2 = getWidth() / 2;
|
||||
int x1 = x2 - 1;
|
||||
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);
|
||||
x1--;
|
||||
x2++;
|
||||
@@ -387,8 +318,7 @@ public class FScrollPanel extends FScrollPane {
|
||||
int x2 = getWidth() / 2;
|
||||
int x1 = x2 - 1;
|
||||
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);
|
||||
x1--;
|
||||
x2++;
|
||||
|
||||
Reference in New Issue
Block a user