|
1 | 1 | import type { |
2 | 2 | IGraphicAttribute, |
3 | 3 | IContext2d, |
4 | | - IImage, |
5 | 4 | IThemeAttribute, |
6 | 5 | IImageRenderContribution, |
7 | 6 | IDrawContext, |
8 | | - IBackgroundConfig, |
9 | | - IGraphic, |
10 | 7 | IMarkAttribute |
11 | 8 | } from '../../../../interface'; |
12 | | -import { getTheme } from '../../../../graphic/theme'; |
13 | | -import { |
14 | | - defaultBaseBackgroundRenderContribution, |
15 | | - DefaultBaseBackgroundRenderContribution |
16 | | -} from './base-contribution-render'; |
| 9 | +import { defaultBaseBackgroundRenderContribution } from './base-contribution-render'; |
17 | 10 | import { BaseRenderContributionTime } from '../../../../common/enums'; |
18 | | -import { isNumber, isObject } from '@visactor/vutils'; |
19 | | -import { parsePadding } from '../../../../common/utils'; |
20 | | -import { createRectPath } from '../../../../common/shape/rect'; |
21 | 11 | import { DefaultRectRenderContribution } from './rect-contribution-render'; |
22 | 12 |
|
23 | | -// export class DefaultImageBackgroundRenderContribution |
24 | | -// extends DefaultBaseBackgroundRenderContribution |
25 | | -// implements IImageRenderContribution |
26 | | -// { |
27 | | -// time: BaseRenderContributionTime = BaseRenderContributionTime.beforeFillStroke; |
28 | | - |
29 | | -// drawShape( |
30 | | -// graphic: IImage, |
31 | | -// context: IContext2d, |
32 | | -// x: number, |
33 | | -// y: number, |
34 | | -// doFill: boolean, |
35 | | -// doStroke: boolean, |
36 | | -// fVisible: boolean, |
37 | | -// sVisible: boolean, |
38 | | -// graphicAttribute: Required<IGraphicAttribute>, |
39 | | -// drawContext: IDrawContext, |
40 | | -// fillCb?: (ctx: IContext2d, markAttribute: Partial<IGraphicAttribute>, themeAttribute: IThemeAttribute) => boolean, |
41 | | -// strokeCb?: (ctx: IContext2d, markAttribute: Partial<IGraphicAttribute>, themeAttribute: IThemeAttribute) => boolean |
42 | | -// ) { |
43 | | -// const { |
44 | | -// background, |
45 | | -// backgroundMode = graphicAttribute.backgroundMode, |
46 | | -// backgroundFit = graphicAttribute.backgroundFit, |
47 | | -// width, |
48 | | -// height |
49 | | -// } = graphic.attribute; |
50 | | -// if (!background) { |
51 | | -// return; |
52 | | -// } |
53 | | - |
54 | | -// if (!graphic.backgroundImg) { |
55 | | -// if (isObject(background)) { |
56 | | -// const { |
57 | | -// stroke, |
58 | | -// fill, |
59 | | -// lineWidth = 1, |
60 | | -// cornerRadius = 0, |
61 | | -// expandX = 0, |
62 | | -// expandY = 0 |
63 | | -// } = background as IBackgroundConfig; |
64 | | - |
65 | | -// if (!stroke && !fill) { |
66 | | -// return; |
67 | | -// } |
68 | | - |
69 | | -// context.beginPath(); |
70 | | -// const { x, y, width, height } = getActualPosition(graphic); |
71 | | -// if (cornerRadius) { |
72 | | -// createRectPath(context, x - expandX, y - expandY, width + expandX * 2, height + expandY * 2, cornerRadius); |
73 | | -// } else { |
74 | | -// context.rect(x - expandX, y - expandY, width + expandX * 2, height + expandY * 2); |
75 | | -// } |
76 | | - |
77 | | -// context.globalAlpha = 1; |
78 | | -// if (fill) { |
79 | | -// context.fillStyle = fill as string; |
80 | | -// context.fill(); |
81 | | -// } |
82 | | - |
83 | | -// if (stroke && lineWidth > 0) { |
84 | | -// context.lineWidth = lineWidth; |
85 | | -// context.strokeStyle = stroke as string; |
86 | | -// context.stroke(); |
87 | | -// } |
88 | | -// } else { |
89 | | -// context.beginPath(); |
90 | | -// // const b = graphic.AABBBounds; |
91 | | -// // image的背景不包括Bounds了 |
92 | | -// context.rect(x, y, width || 0, height || 0); |
93 | | -// context.fillStyle = background as string; |
94 | | -// context.globalAlpha = 1; |
95 | | -// context.fill(); |
96 | | -// } |
97 | | -// } else { |
98 | | -// const res = graphic.resources.get(background as any); |
99 | | -// if (res.state !== 'success' || !res.data) { |
100 | | -// return; |
101 | | -// } |
102 | | -// context.save(); |
103 | | -// if (graphic.parent && !graphic.transMatrix.onlyTranslate()) { |
104 | | -// const groupAttribute = getTheme(graphic.parent).group; |
105 | | -// const { scrollX = groupAttribute.scrollX, scrollY = groupAttribute.scrollY } = graphic.parent.attribute; |
106 | | -// context.setTransformFromMatrix(graphic.parent.globalTransMatrix, true); |
107 | | -// context.translate(scrollX, scrollY); |
108 | | -// } |
109 | | -// // context.clip(); |
110 | | -// const b = graphic.AABBBounds; |
111 | | -// this.doDrawImage(context, res.data, b, backgroundMode, backgroundFit); |
112 | | -// context.restore(); |
113 | | -// if (!graphic.transMatrix.onlyTranslate()) { |
114 | | -// context.setTransformForCurrent(); |
115 | | -// } |
116 | | -// } |
117 | | -// } |
118 | | -// } |
119 | | - |
120 | | -// function getActualPosition(graphic: IGraphic) { |
121 | | -// const boundsPadding = parsePadding(graphic.attribute.boundsPadding); |
122 | | -// const bounds = graphic.AABBBounds; |
123 | | -// let x = bounds.x1; |
124 | | -// let y = bounds.y1; |
125 | | -// let width = bounds.width(); |
126 | | -// let height = bounds.height(); |
127 | | - |
128 | | -// if (isNumber(boundsPadding)) { |
129 | | -// x += boundsPadding; |
130 | | -// y += boundsPadding; |
131 | | -// width -= boundsPadding * 2; |
132 | | -// height -= boundsPadding * 2; |
133 | | -// } else { |
134 | | -// x += boundsPadding[3]; |
135 | | -// y += boundsPadding[0]; |
136 | | -// width -= boundsPadding[1] + boundsPadding[3]; |
137 | | -// height -= boundsPadding[0] + boundsPadding[2]; |
138 | | -// } |
139 | | - |
140 | | -// return { |
141 | | -// x, |
142 | | -// y, |
143 | | -// width, |
144 | | -// height |
145 | | -// }; |
146 | | -// } |
147 | | - |
148 | 13 | export class DefaultImageRenderContribution extends DefaultRectRenderContribution implements IImageRenderContribution { |
149 | 14 | time: BaseRenderContributionTime = BaseRenderContributionTime.afterFillStroke; |
150 | 15 | useStyle: boolean = true; |
|
0 commit comments