mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix SizedIcon
This commit is contained in:
@@ -32,50 +32,40 @@ public class SizedIcon extends JBUI.JBAbstractIcon implements Icon, ScalableIcon
|
||||
private float myScale = 1f;
|
||||
|
||||
public SizedIcon(Icon delegate, int width, int height) {
|
||||
myDelegate = delegate;
|
||||
myScaledDelegate = myDelegate = delegate;
|
||||
myWidth = width;
|
||||
myHeight = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
int dx = scaleVal(myWidth) - delegate().getIconWidth();
|
||||
int dy = scaleVal(myHeight) - delegate().getIconHeight();
|
||||
int dx = scaleVal(myWidth) - myScaledDelegate.getIconWidth();
|
||||
int dy = scaleVal(myHeight) - myScaledDelegate.getIconHeight();
|
||||
if (dx > 0 || dy > 0) {
|
||||
delegate().paintIcon(c, g, x + dx/2, y + dy/2);
|
||||
myScaledDelegate.paintIcon(c, g, x + dx/2, y + dy/2);
|
||||
}
|
||||
else {
|
||||
delegate().paintIcon(c, g, x, y);
|
||||
myScaledDelegate.paintIcon(c, g, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public Icon delegate() {
|
||||
return myScaledDelegate != null ? myScaledDelegate : myDelegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scaleVal(int n) {
|
||||
return super.scaleVal(myScale == 1f ? n : (int) (n * myScale));
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
if (delegate() instanceof ScalableIcon) {
|
||||
return delegate().getIconWidth();
|
||||
}
|
||||
return scaleVal(myWidth);
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
if (delegate() instanceof ScalableIcon) {
|
||||
return delegate().getIconHeight();
|
||||
}
|
||||
return scaleVal(myHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon scale(float scaleFactor) {
|
||||
if (scaleFactor == 1f) {
|
||||
myScaledDelegate = null;
|
||||
myScaledDelegate = myDelegate;
|
||||
} else if (myDelegate instanceof ScalableIcon) {
|
||||
myScaledDelegate = ((ScalableIcon)myDelegate).scale(scaleFactor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user