core/component/mask
마스크 컴포넌트. (붙은 노드의 content_size 영역으로 자식 출력을 자른다)
- 실제 자르기는 NodeTree::draw_node 가 자식을 그리기 전후로 begin_clip / end_clip 을 부른다.
Mask component. (clips child drawing to the attached node's content_size area)
- The actual clipping is done by NodeTree::draw_node calling begin_clip / end_clip before and after drawing the children.
Maskstruct traits Default, Component
마스크 컴포넌트. (붙은 노드의 content_size 영역 밖으로 나가는 자식 노드 출력을 자른다)
- 노드 자신의 컴포넌트는 자르지 않는다. 컴포넌트를 다 그린 뒤 자식을 그리는 동안만 자른다.
- 둥근 크기를 주면 둥근 사각형으로 자른다. 배경 Paint 와 같은 둥근 크기를 주면 배경 모양 그대로 잘린다.
Mask component. (clips child node drawing that goes outside the attached node's content_size area)
- The node's own components are not clipped. Clipping applies only while drawing the children after all components are drawn.
- Giving a round size clips to a rounded rectangle. Giving the same round size as the background Paint clips exactly to the background shape.
use vanilla::{Mask, NodeTree, Paint, Vector2};
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let window_id = node_tree.create_child(root_id, "Window");
node_tree[window_id].set_content_size(Vector2::create(200.0, 200.0));
let paint = node_tree.add_component(window_id, Paint::create_with_color("#223344")).unwrap();
paint.set_round_size(24.0);
let mask = node_tree.add_component(window_id, Mask::new()).unwrap();
mask.set_round_size(24.0);
let child_id = node_tree.create_child(window_id, "Child");
node_tree[child_id].set_content_size(Vector2::create(160.0, 160.0));
node_tree[child_id].set_local_position(Vector2::create(120.0, 120.0));
node_tree.add_component(child_id, Paint::create_with_color("#ff6633"));
let mask = node_tree[window_id].get_component::<Mask>().unwrap();
assert_eq!(mask.get_round_size(), 24.0);생성.
Constructor.
반환ReturnsMask 둥근 크기가 0 인(곧은 사각형으로 자르는) 새 마스크.New mask with round size 0 (clipping to a sharp rectangle).
짝Counterpart: vanilla.js Mask.constructor
자르기 시작.
- 노드 content 좌표의 (0, 0, content_size 너비, 높이) 사각형을 Graphic 의 자르기 영역으로 건다. (스텐실이라 회전, 배율이 걸려도 정확히 잘린다)
- NodeTree 가 마스크 붙은 노드의 자식을 그리기 바로 전에 부른다. end_clip 과 짝으로 부르고, 그 사이에 그린 것만 잘린다.
Begins clipping.
- Sets the (0, 0, content_size width, height) rectangle in node content coordinates as the Graphic's clip area. (it is a stencil, so it clips exactly even with rotation and scale)
- Called by NodeTree right before drawing the children of a node with a mask. Called in pairs with end_clip, and only what is drawn in between is clipped.
- transform&NodeTransform
- 자를 영역을 정하는 노드 트랜스폼. (content_size 를 읽는다)Node transform that decides the clip area. (reads content_size)
- round_sizef64
- 귀퉁이 둥근 크기. (노드 좌표, 0 이면 곧은 사각형)Corner round size. (node coordinates, 0 is a sharp rectangle)
- graphic&mut Graphic
- 자르기 영역을 걸 그래픽.Graphic to set the clip area on.
짝Counterpart: vanilla.js Mask.beginClip
use vanilla::{Color, Graphic, Mask, NodeTransform, Rect};
fn draw_clipped(transform: &NodeTransform, graphic: &mut Graphic) {
Mask::begin_clip(transform, 8.0, graphic);
graphic.set_fill_color(Color::white());
graphic.draw_rect(Rect::create(-20.0, -20.0, 400.0, 400.0));
Mask::end_clip(graphic);
}자르기 끝.
- begin_clip 으로 건 자르기 영역을 푼다. (NodeTree 가 자식을 다 그린 뒤 부른다)
Ends clipping.
- Releases the clip area set with begin_clip. (called by NodeTree after drawing all children)
- graphic&mut Graphic
- begin_clip 에 넘긴 그래픽.The graphic passed to begin_clip.
짝Counterpart: vanilla.js Mask.endClip
라운드 크기 설정. (Paint 의 round_size 와 같은 값이면 배경과 정확히 맞는다)
Sets the round size. (the same value as Paint's round_size matches the background exactly)
- round_sizef64
- 자르는 사각형의 귀퉁이 둥근 크기. (노드 좌표, 0 이면 곧은 사각형, 처음 0)Corner round size of the clip rectangle. (node coordinates, 0 is a sharp rectangle, initially 0)
짝Counterpart: vanilla.js Mask.setRoundSize
라운드 크기 반환.
Returns the round size.
반환Returnsf64 자르는 사각형의 귀퉁이 둥근 크기. (노드 좌표)Corner round size of the clip rectangle. (node coordinates)
짝Counterpart: vanilla.js Mask.getRoundSize