📄 shadowpainter.java
字号:
}
private void drawTopLeftTabShadow(Graphics g, int x, int y, int height, Rectangle componentsBounds,
int totalWidth, boolean flip, boolean isLast) {
boolean connected = x + shadowSize > componentsBounds.x;
if (!connected || y + shadowSize + shadowBlendSize <= componentsBounds.y) {
drawLeftCornerShadow(g, y, Math.min(x, componentsBounds.x), !flip, isLast ? tabBackgroundColor : null);
drawEdgeShadow(g,
y,
connected ? componentsBounds.y : y + height,
Math.min(x, componentsBounds.x),
false,
!flip,
isLast ? tabBackgroundColor : null);
}
int endX = componentsBounds.x + componentsBounds.width;
if (endX < totalWidth) {
drawLeftCornerShadow(g, componentsBounds.y, endX, !flip, tabBackgroundColor);
drawEdgeShadow(g,
componentsBounds.y,
componentsBounds.y + componentsBounds.height,
endX,
false,
!flip,
tabBackgroundColor);
}
}
private void drawBottomRightTabShadow(Graphics g,
int x,
int y,
int width,
int tabX,
int tabWidth,
int tabHeight,
int componentsX,
int componentsWidth,
int componentsHeight,
boolean flip,
boolean isLast) {
Shape oldClipRect = g.getClip();
{
Rectangle clipRect = createRectangle(x, y, Math.min(tabX, componentsX) - x, 1000000, flip);
g.clipRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
}
drawLeftCornerShadow(g, x, y, flip, null);
drawEdgeShadow(g, x, tabX, y, false, flip, null);
boolean connected = tabX < componentsX && tabX + tabWidth >= componentsX;
g.setClip(oldClipRect);
if (!connected) {
Rectangle clipRect = createRectangle(x, y, componentsX - x, 1000000, flip);
g.clipRect(clipRect.x, clipRect.y, clipRect.width, clipRect.height);
}
if (tabX < componentsX) {
int endX = connected && tabHeight == componentsHeight ? componentsX + componentsWidth :
Math.min(componentsX, tabX + tabWidth);
if (tabX + shadowSize < endX)
drawLeftCornerShadow(g, tabX, y + tabHeight, flip, panelBackgroundColor);
drawEdgeShadow(g, tabX, endX, y + tabHeight, false, flip, panelBackgroundColor);
if (endX < x + width && (!connected || componentsHeight < tabHeight)) {
drawRightCornerShadow(g, endX, y + tabHeight, flip, panelBackgroundColor);
drawEdgeShadow(g,
y + (connected ? componentsHeight : 0),
y + tabHeight,
endX,
true,
!flip,
isLast ? tabBackgroundColor : null);
}
}
if (!connected) {
drawEdgeShadow(g, tabX + tabWidth, componentsX, y, true, flip, isLast ? tabBackgroundColor : null);
g.setClip(oldClipRect);
}
if (componentsHeight > 0 && (!connected || tabHeight != componentsHeight)) {
if (!connected || componentsHeight > tabHeight) {
drawLeftCornerShadow(g, componentsX, y + componentsHeight, flip, panelBackgroundColor);
drawEdgeShadow(g,
componentsX,
componentsX + componentsWidth,
y + componentsHeight,
false,
flip,
panelBackgroundColor);
}
else
drawEdgeShadow(g,
componentsX,
componentsX + componentsWidth,
y + componentsHeight,
true,
flip,
panelBackgroundColor);
}
if (componentsX + componentsWidth < x + width) {
drawRightCornerShadow(g, componentsX + componentsWidth, y + componentsHeight, flip, panelBackgroundColor);
drawEdgeShadow(g, y, y + componentsHeight, componentsX + componentsWidth, true, !flip, panelBackgroundColor);
drawEdgeShadow(g, componentsX + componentsWidth, x + width, y, true, flip, panelBackgroundColor);
}
}
private void drawBottomRightEdgeShadow(Graphics g, int x, int y, int width, boolean flip, Color backgroundColor) {
drawLeftCornerShadow(g, x, y, flip, backgroundColor);
drawEdgeShadow(g, x, x + width, y, false, flip, backgroundColor);
}
private void drawLeftCornerShadow(Graphics g, int x, int y, boolean upper, Color backgroundColor) {
for (int i = 0; i < shadowBlendSize; i++) {
g.setColor(getShadowBlendColor(i, backgroundColor));
int x1 = x + shadowSize + shadowBlendSize - 1 - i;
int y1 = y + shadowSize - shadowBlendSize;
if (y1 > y)
drawLine(g, x1, y, x1, y1 - 1, upper);
drawLine(g, x1, y1, x + shadowSize + shadowBlendSize - 1, y + shadowSize - shadowBlendSize + i, upper);
}
}
private void drawRightCornerShadow(Graphics g, int x, int y, boolean flip, Color backgroundColor) {
g.setColor(getShadowColor(backgroundColor));
for (int i = 0; i < shadowSize - shadowBlendSize; i++) {
drawLine(g, x + i, y, x + i, y + shadowSize - shadowBlendSize, flip);
}
for (int i = 0; i < shadowBlendSize; i++) {
g.setColor(getShadowBlendColor(i, backgroundColor));
int d = shadowSize - shadowBlendSize + i;
drawLine(g, x + d, y, x + d, y + shadowSize - shadowBlendSize, flip);
drawLine(g, x, y + d, x + shadowSize - shadowBlendSize, y + d, flip);
drawLine(g, x + d, y + shadowSize - shadowBlendSize, x + shadowSize - shadowBlendSize, y + d, flip);
}
}
private void drawEdgeShadow(Graphics g, int startX, int endX, int y, boolean cornerStart, boolean vertical,
Color backgroundColor) {
if (startX + (cornerStart ? 0 : shadowSize + shadowBlendSize) >= endX)
return;
g.setColor(getShadowColor(backgroundColor));
for (int i = 0; i < shadowSize - shadowBlendSize; i++) {
drawLine(g,
startX + (cornerStart ? i + (vertical ? 1 : 0) : shadowSize + shadowBlendSize),
y + i,
endX - 1,
y + i,
vertical);
}
for (int i = 0; i < shadowBlendSize; i++) {
g.setColor(getShadowBlendColor(i, backgroundColor));
int d = shadowSize - shadowBlendSize + i;
drawLine(g,
startX + (cornerStart ? d + (vertical ? 1 : 0) : shadowSize + shadowBlendSize),
y + d,
endX - 1,
y + d,
vertical);
}
}
/* private void drawShadowLine(Graphics g, int startX, int endX, int y, boolean vertical, Color backgroundColor) {
if (startX >= endX)
return;
g.setColor(getShadowColor(backgroundColor));
for (int i = 0; i < shadowSize - shadowBlendSize; i++) {
drawLine(g, startX, y + i, endX - 1, y + i, vertical);
}
for (int i = 0; i < shadowBlendSize; i++) {
g.setColor(getShadowBlendColor(i, backgroundColor));
int d = shadowSize - shadowBlendSize + i;
drawLine(g, startX, y + d, endX - 1, y + d, vertical);
}
}
*/
private static void drawLine(Graphics g, int x1, int y1, int x2, int y2, boolean flip) {
if (flip)
GraphicsUtil.drawOptimizedLine(g, y1, x1, y2, x2);
else
GraphicsUtil.drawOptimizedLine(g, x1, y1, x2, y2);
}
private Color getShadowBlendColor(int offset, Color backgroundColor) {
return backgroundColor == null ?
new Color(shadowColor.getRed(),
shadowColor.getGreen(),
shadowColor.getBlue(),
(int) (255F * shadowStrength * (shadowBlendSize - offset) / (shadowBlendSize + 1))) :
ColorUtil.blend(backgroundColor,
shadowColor,
shadowStrength * (shadowBlendSize - offset) / (shadowBlendSize + 1));
}
private Color getShadowColor(Color backgroundColor) {
return backgroundColor == null ?
new Color(shadowColor.getRed(),
shadowColor.getGreen(),
shadowColor.getBlue(),
(int) (255F * shadowStrength)) :
ColorUtil.blend(backgroundColor,
shadowColor,
shadowStrength);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -