core/component/softshade
부드러운 그늘. (vanilla.js core/component/softshade.js 의 SoftShade, SoftShadeShape)
- 글 뒤를 어둡게 눌러 밝은 바탕 위에서도 읽히게 할 때 쓴다. 모양을 작은 그림 한 장에 구워 노드의 내용 크기로 늘려 그린다.
- 부드러운 그라데이션이라 낮은 해상도로 구워 늘려도 자국이 보이지 않는다. (구운 한 픽셀이 굽기 단위만큼을 덮고, 가로세로 상한이 있다)
- 노드 크기, 모양, 색, 짙기, 양옆 흐림이 바뀌면 다시 굽는다. 같은 모양을 구운 것이 있으면 나눠 쓴다. (sharedbakecache.rs) 노드의 불투명도는 한 장째로 먹는다.
- 원본 getBakeCanvas 는 구운 캔버스 대신 구운 Image 를 돌려주는 get_bake_image 다.
Soft shade. (SoftShade and SoftShadeShape in vanilla.js core/component/softshade.js)
- Used to darken the area behind text so it stays readable even on a bright background. Bakes the shape into one small image and draws it stretched to the node's content size.
- It is a soft gradient, so baking at low resolution and stretching leaves no visible artifacts. (one baked pixel covers one bake unit, and there is a width and height limit)
- Rebakes when the node size, shape, color, density or side fade changes. If a bake of the same look already exists, it is shared. (sharedbakecache.rs) The node's opacity applies to it as one sheet.
- The original getBakeCanvas is get_bake_image, which returns the baked Image instead of the baked canvas.
SoftShadestruct traits Default, Component
부드러운 그늘 컴포넌트. (모양을 작은 그림 한 장에 구워 노드 content_size 로 늘려 그린다)
- 처음은 Band 모양, 검정, 가장 짙은 곳의 불투명도 0.5, 양옆 흐림 0, 굽기 단위 4, 가로세로 상한 256.
- 글 뒤를 어둡게 눌러 밝은 바탕 위에서도 읽히게 할 때 쓴다. 노드의 불투명도는 구운 한 장째로 먹는다.
Soft shade component. (bakes the shape into one small image and draws it stretched to the node's content_size)
- Initially Band shape, black, opacity 0.5 at the densest point, side fade 0, bake unit 4, width and height limit 256.
- Used to darken the area behind text so it stays readable even on a bright background. The node's opacity applies to the baked sheet as one.
use vanilla::{Color, NodeTree, SoftShade, SoftShadeShape, Vector2};
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let shade_id = node_tree.create_child(root_id, "Shade");
node_tree[shade_id].set_content_size(Vector2::create(400.0, 80.0));
let soft_shade = node_tree.add_component(shade_id, SoftShade::new()).unwrap();
soft_shade.set_shade(SoftShadeShape::Band, Color::black(), 0.6, 60.0);
let soft_shade = node_tree[shade_id].get_component::<SoftShade>().unwrap();
assert_eq!(soft_shade.get_shape(), SoftShadeShape::Band);
assert_eq!(soft_shade.get_fade_width(), 60.0);
assert!(soft_shade.get_bake_image().is_none());생성.
Constructor.
반환ReturnsSoftShade Band 모양, 검정, 불투명도 0.5, 양옆 흐림 0, 굽기 단위 4, 가로세로 상한 256 인 새 컴포넌트.New component with Band shape, black, opacity 0.5, side fade 0, bake unit 4, width and height limit 256.
짝Counterpart: vanilla.js SoftShade.constructor
출력.
- 구울 크기는 content_size 를 굽기 단위로 나눠 올림한 값이고 2 ~ 가로세로 상한으로 맞춘다. 양옆 흐림 비율은 fade_width / 너비 (0.5 까지).
- 크기, 모양, 색, 불투명도, 양옆 흐림이 지난번과 다르면 다시 굽는다. (같은 모양을 구운 것이 있으면 나눠 쓴다)
- 너비나 높이가 0 이하이거나 불투명도가 0 이하면 그리지 않는다.
Draw.
- The bake size is content_size divided by the bake unit and rounded up, fitted to 2 ~ the width and height limit. The side fade ratio is fade_width / width (up to 0.5).
- Rebakes if the size, shape, color, opacity or side fade differs from last time. (if a bake of the same look already exists, it is shared)
- Does not draw if the width or height is 0 or less, or the opacity is 0 or less.
- transform&NodeTransform
- 그늘을 그릴 노드 트랜스폼. (content_size 를 읽는다)Node transform to draw the shade on. (reads content_size)
- graphic&mut Graphic
- 그릴 그래픽. (노드 트랜스폼이 걸린 상태)Graphic to draw to. (with the node transform applied)
굽기. (픽셀마다 알파를 셈한다, 텍스처 캐시가 그림마다 한 번 올리므로 구울 때마다 새 그림)
- 모든 픽셀의 색은 그늘 색(알파는 쓰지 않는다)이고, 알파는 255 x 불투명도 x 세로 짙기 x 가로 짙기다.
- Band: 세로는 가운데 줄이 1 이고 위아래 끝으로 부드럽게 0, 가로는 양끝에서 fade_ratio 안쪽까지 부드럽게 0 에서 1. Bottom: 세로는 위 끝 0 에서 아래 끝 1 로 곧게, 가로는 1.
Bake. (computes alpha per pixel, a new image on every bake because the texture cache uploads each image once)
- Every pixel's color is the shade color (its alpha is not used), and the alpha is 255 x opacity x vertical density x horizontal density.
- Band: vertically 1 at the middle row, smoothly to 0 at the top and bottom ends, horizontally smoothly from 0 to 1 from both ends inward to fade_ratio. Bottom: vertically linear from 0 at the top end to 1 at the bottom end, horizontally 1.
- bake_widthu32
- 구울 그림의 너비. (픽셀)Width of the image to bake. (pixels)
- bake_heightu32
- 구울 그림의 높이. (픽셀)Height of the image to bake. (pixels)
- fade_ratiof64
- Band 의 양옆이 엷어지는 너비를 그림 너비에 대한 비율로. (0 ~ 0.5, 0 이면 양옆을 흐리지 않는다, Bottom 은 쓰지 않는다)Width over which the sides of a Band fade, as a ratio of the image width. (0 ~ 0.5, 0 does not fade the sides, not used by Bottom)
반환ReturnsRc<Image> 구운 새 그림. (bake_width x bake_height)The new baked image. (bake_width x bake_height)
짝Counterpart: vanilla.js SoftShade.bakeShade
use vanilla::{Color, SoftShade, SoftShadeShape};
let mut soft_shade = SoftShade::new();
soft_shade.set_shade(SoftShadeShape::Bottom, Color::black(), 1.0, 0.0);
let image = soft_shade.bake_shade(1, 2, 0.0);
assert_eq!(image.get_width(), 1);
assert_eq!(image.get_height(), 2);
let pixels = image.get_pixels();
assert_eq!(pixels[3], 64);
assert_eq!(pixels[7], 191);pub fn set_shade(&mut self, shape: SoftShadeShape, color: impl Into<Color>, opacity: f64, fade_width: f64)#그늘 설정. (모양, 색, 가장 짙은 곳의 불투명도, 띠의 양옆이 엷어지는 너비)
Sets the shade. (shape, color, opacity at the darkest point, width over which the band's sides fade)
- shapeSoftShadeShape
- 그늘 모양. (처음 Band)Shade shape. (initially Band)
- colorimpl Into<Color>
- 그늘 색. (Color 또는 "#rrggbb" 같은 문자열, 알파는 쓰지 않는다, 처음 검정)Shade color. (a Color or a string such as "#rrggbb", alpha is not used, initially black)
- opacityf64
- 가장 짙은 곳의 불투명도. (0 ~ 1, 0 이하면 그리지 않는다, 처음 0.5)Opacity at the densest point. (0 ~ 1, does not draw if 0 or less, initially 0.5)
- fade_widthf64
- Band 의 양옆이 엷어지는 너비. (노드 좌표, 노드 너비의 반까지만 먹는다, 처음 0)Width over which the sides of a Band fade. (node coordinates, applies only up to half the node width, initially 0)
짝Counterpart: vanilla.js SoftShade.setShade
굽기 해상도 설정. (구운 한 픽셀이 덮는 단위, 가로세로 상한)
Sets the bake resolution. (unit covered by one baked pixel, width/height cap)
- bake_unitf64
- 구운 한 픽셀이 덮는 노드 좌표 크기. (1 보다 작으면 1, 처음 4)Node coordinate size covered by one baked pixel. (1 if less than 1, initially 4)
- bake_maximum_sizeu32
- 구운 그림의 가로세로 상한. (픽셀, 2 보다 작으면 2, 처음 256)Width and height limit of the baked image. (pixels, 2 if less than 2, initially 256)
짝Counterpart: vanilla.js SoftShade.setBakeResolution
use vanilla::SoftShade;
let mut soft_shade = SoftShade::new();
soft_shade.set_bake_resolution(8.0, 128);
assert_eq!(soft_shade.get_bake_unit(), 8.0);
assert_eq!(soft_shade.get_bake_maximum_size(), 128);
soft_shade.set_bake_resolution(0.5, 1);
assert_eq!(soft_shade.get_bake_unit(), 1.0);
assert_eq!(soft_shade.get_bake_maximum_size(), 2);모양 반환.
Returns the shape.
반환ReturnsSoftShadeShape 그늘 모양.Shade shape.
짝Counterpart: vanilla.js SoftShade.getShape
가장 짙은 곳의 불투명도 반환.
Returns the opacity at the darkest point.
반환Returnsf64 가장 짙은 곳의 불투명도. (0 ~ 1)Opacity at the densest point. (0 ~ 1)
짝Counterpart: vanilla.js SoftShade.getOpacity
띠의 양옆이 엷어지는 너비 반환.
Returns the width over which the band's sides fade.
반환Returnsf64 띠의 양옆이 엷어지는 너비. (노드 좌표)Width over which the sides of the band fade. (node coordinates)
짝Counterpart: vanilla.js SoftShade.getFadeWidth
구운 한 픽셀이 덮는 단위 반환.
Returns the unit covered by one baked pixel.
반환Returnsf64 구운 한 픽셀이 덮는 노드 좌표 크기. (1 이상)Node coordinate size covered by one baked pixel. (1 or more)
짝Counterpart: vanilla.js SoftShade.getBakeUnit
구운 그림의 가로세로 상한 반환.
Returns the width and height limit of the baked image.
반환Returnsu32 구운 그림의 가로세로 상한. (픽셀, 2 이상)Width and height limit of the baked image. (pixels, 2 or more)
짝Counterpart: vanilla.js SoftShade.getBakeMaximumSize
구운 그림 반환. (아직 굽지 않았으면 None, 원본 getBakeCanvas)
Returns the baked image. (None if not baked yet, the original getBakeCanvas)
반환ReturnsOption<&Rc<Image>> 마지막으로 구운 그림. 아직 한 번도 그리지 않았으면 None.The last baked image. None if it has never been drawn.
SoftShadeShapeenum traits Clone, Copy, PartialEq, Eq, Debug
부드러운 그늘의 모양.
Shape of the soft shade.
| 이름Name | 설명Description |
|---|---|
Band | 가운데 가로줄이 가장 짙고 위아래 끝으로 차츰 엷어지는 띠. (양옆은 fade_width 안쪽까지 차츰)A band densest at the middle row that gradually fades toward the top and bottom ends. (the sides fade gradually inward to fade_width) |
Bottom | 아래 끝이 가장 짙고 위 끝에서 0 인 세로 그라데이션.Vertical gradient darkest at the bottom edge and 0 at the top edge. |