From 6c47174cddde33f6315c5f32f753163b0c26a559 Mon Sep 17 00:00:00 2001 From: Starryi Date: Fri, 23 Jul 2021 18:52:18 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-55719=20=E3=80=90=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E5=88=86=E7=A6=BB=E3=80=91=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=A4=8D=E7=94=A8-=E6=8A=A5=E8=A1=A8=E5=9D=97=E5=9C=A8?= =?UTF-8?q?=E7=94=BB=E5=B8=83=E5=86=85=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20REPORT-55737=20=E3=80=90=E7=BB=84=E4=BB=B6=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E5=88=86=E7=A6=BB=E3=80=91=E7=BB=84=E4=BB=B6=E5=A4=8D=E7=94=A8?= =?UTF-8?q?-=E4=B8=BB=E4=BD=93=E8=83=8C=E6=99=AF=E9=81=AE=E6=8C=A1?= =?UTF-8?q?=E8=BE=B9=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 设计器端无法预览边框点九图的效果 2. 由XTitleLayout绘制的边框图片,会被BodyWidget负责绘制的背景遮挡 【改动思路】 1. 实现点九图的绘制和设计器端画布上的预览 2. 点九图的绘制需要对原始图片进行切割,分别缩放绘制, 耗时较长,因此考虑在点九图分割位置变化时 进行子图的创建,从而提高性能 2. 背景由XWTitleLayout负责绘制,但需要向下偏移标题栏的高度,以满足兼容性要求 --- .../creator/XBorderStyleWidgetCreator.java | 88 ++++++++++++++++--- 1 file changed, 77 insertions(+), 11 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java index 645f38706..158712658 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XBorderStyleWidgetCreator.java @@ -35,6 +35,9 @@ import java.awt.geom.RoundRectangle2D; public class XBorderStyleWidgetCreator extends XWidgetCreator{ protected static final Dimension BORDER_PREFERRED_SIZE = new Dimension(250, 150); protected Background background4Painting; // 设计器预览界面中绘制组件背景图 + protected double backgroundOpacity4Painting; // 设计器预览界面中绘制组件背景图 + protected Background borderImage4Painting; // 设计器预览界面中绘制边框图片 + protected double borderImageOpacity4Painting; public XBorderStyleWidgetCreator(Widget widget, Dimension initSize) { super(widget, initSize); @@ -54,6 +57,30 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ this.repaint(); } + public double getBackgroundOpacity4Painting() { + return backgroundOpacity4Painting; + } + + public void setBackgroundOpacity4Painting(double backgroundOpacity4Painting) { + this.backgroundOpacity4Painting = backgroundOpacity4Painting; + } + + public Background getBorderImage4Painting() { + return borderImage4Painting; + } + + public void setBorderImage4Painting(Background borderImage4Painting) { + this.borderImage4Painting = borderImage4Painting; + } + + public double getBorderImageOpacity4Painting() { + return borderImageOpacity4Painting; + } + + public void setBorderImageOpacity4Painting(double borderImageOpacity4Painting) { + this.borderImageOpacity4Painting = borderImageOpacity4Painting; + } + /** * 返回容器对应的widget * @return 同上 @@ -102,8 +129,11 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ } this.setBorder(border); + this.setBorderImage4Painting(style != null ? style.getBorderImage() : null); + this.setBorderImageOpacity4Painting(style != null ? style.getBorderImageOpacity() : 0.0); this.setBackground4Painting(style != null ? style.getBackground() : null); + this.setBackgroundOpacity4Painting(style != null ? style.getAlpha() : 0.0); } private void clearTitleWidget() { @@ -194,14 +224,27 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ titleCreator.setBorder(new BottomLineBorder(color, thickness)); } - // 主体背景的生效范围暂时保持原样,不作用于包含标题区域的整体范围内 -// if (bodyXCreator instanceof XBorderStyleWidgetCreator) { -// XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator; -// Background background4Painting = styledBodyXCreator.getBackground4Painting(); -// -// styledBodyXCreator.setBackground4Painting(null); // body不绘制背景 -// titleParent.setBackground4Painting(background4Painting); // 容器绘制完整背景 -// } + if (bodyXCreator instanceof XBorderStyleWidgetCreator) { + XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator; + Background borderImage4Painting = styledBodyXCreator.getBorderImage4Painting(); + double opacity = styledBodyXCreator.getBorderImageOpacity4Painting(); + + styledBodyXCreator.setBorderImage4Painting(null); // body不绘制图片边框 + styledBodyXCreator.setBorderImageOpacity4Painting(0.0); + titleParent.setBorderImage4Painting(borderImage4Painting); // 容器绘制完整图片边框 + titleParent.setBorderImageOpacity4Painting(opacity); + } + + if (bodyXCreator instanceof XBorderStyleWidgetCreator) { + XBorderStyleWidgetCreator styledBodyXCreator = (XBorderStyleWidgetCreator) bodyXCreator; + Background background4Painting = styledBodyXCreator.getBackground4Painting(); + double opacity = styledBodyXCreator.getBackgroundOpacity4Painting(); + + styledBodyXCreator.setBackground4Painting(null); // body不绘制背景 + styledBodyXCreator.setBackgroundOpacity4Painting(0.0); + titleParent.setBackground4Painting(background4Painting); // 容器绘制完整背景 + titleParent.setBackgroundOpacity4Painting(opacity); + } } } } @@ -226,10 +269,32 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ public void paintBackground(Graphics2D g2d) { Background background4Painting = getBackground4Painting(); if (background4Painting != null) { - BorderPacker style = toData().getBorderStyle(); Composite oldComposite = g2d.getComposite(); - g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, style.getAlpha())); - background4Painting.paint(g2d, new Rectangle2D.Double(0, 0, getWidth(), getHeight())); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) backgroundOpacity4Painting)); + + Shape shape = new Rectangle2D.Double(0, 0, getWidth(), getHeight()); + if (this instanceof XWTitleLayout) { + // 兼容性考虑,组件样式背景不作用在标题范围内,只作用在控件整体,但同时不能遮挡作用于整体的边框图片 + // 所以考虑样式背景与边框图片都由XWTitleLayout绘制,但样式背景要向下偏移标题栏的高度 + XWTitleLayout titleParent = (XWTitleLayout) this; + if (getComponentCount() > 1) { + XCreator titleCreator = titleParent.getTitleCreator(); + int titleHeight = titleCreator != null ? titleCreator.getHeight() : 0; + shape = new Rectangle2D.Double(0, titleHeight, getWidth(), getHeight() - titleHeight); + } + } + background4Painting.paint(g2d, shape); + + g2d.setComposite(oldComposite); + } + } + + public void paintBorderImage(Graphics2D g2d) { + Background borderImage4Painting = getBorderImage4Painting(); + if (borderImage4Painting != null) { + Composite oldComposite = g2d.getComposite(); + g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, (float) borderImageOpacity4Painting)); + borderImage4Painting.paint(g2d, new Rectangle2D.Double(0, 0, getWidth(), getHeight())); g2d.setComposite(oldComposite); } } @@ -243,6 +308,7 @@ public class XBorderStyleWidgetCreator extends XWidgetCreator{ public void paint(Graphics g) { this.clipByRoundedBorder((Graphics2D) g); this.paintBackground((Graphics2D) g); + this.paintBorderImage((Graphics2D) g); this.paintForeground((Graphics2D) g); }