Fix examples using `Mesh2D`

This commit is contained in:
Héctor Ramón Jiménez 2020-02-12 09:12:15 +01:00
parent 96b36d0f9e
commit 1beeaf9db5
2 changed files with 84 additions and 91 deletions

View File

@ -102,7 +102,7 @@ mod bezier {
// Draw rectangle border with lyon. // Draw rectangle border with lyon.
basic_shapes::stroke_rectangle( basic_shapes::stroke_rectangle(
&lyon::math::Rect::new( &lyon::math::Rect::new(
lyon::math::Point::new(bounds.x + 0.5, bounds.y + 0.5), lyon::math::Point::new(0.5, 0.5),
lyon::math::Size::new( lyon::math::Size::new(
bounds.width - 1.0, bounds.width - 1.0,
bounds.height - 1.0, bounds.height - 1.0,
@ -121,48 +121,35 @@ mod bezier {
for curve in self.curves { for curve in self.curves {
path_builder.move_to(lyon::math::Point::new( path_builder.move_to(lyon::math::Point::new(
curve.from.x + bounds.x, curve.from.x,
curve.from.y + bounds.y, curve.from.y,
)); ));
path_builder.quadratic_bezier_to( path_builder.quadratic_bezier_to(
lyon::math::Point::new( lyon::math::Point::new(curve.control.x, curve.control.y),
curve.control.x + bounds.x, lyon::math::Point::new(curve.to.x, curve.to.y),
curve.control.y + bounds.y,
),
lyon::math::Point::new(
curve.to.x + bounds.x,
curve.to.y + bounds.y,
),
); );
} }
match self.state.pending { match self.state.pending {
None => {} None => {}
Some(Pending::One { from }) => { Some(Pending::One { from }) => {
path_builder.move_to(lyon::math::Point::new( path_builder
from.x + bounds.x, .move_to(lyon::math::Point::new(from.x, from.y));
from.y + bounds.y,
));
path_builder.line_to(lyon::math::Point::new( path_builder.line_to(lyon::math::Point::new(
cursor_position.x, cursor_position.x - bounds.x,
cursor_position.y, cursor_position.y - bounds.y,
)); ));
} }
Some(Pending::Two { from, to }) => { Some(Pending::Two { from, to }) => {
path_builder.move_to(lyon::math::Point::new( path_builder
from.x + bounds.x, .move_to(lyon::math::Point::new(from.x, from.y));
from.y + bounds.y,
));
path_builder.quadratic_bezier_to( path_builder.quadratic_bezier_to(
lyon::math::Point::new( lyon::math::Point::new(
cursor_position.x, cursor_position.x - bounds.x,
cursor_position.y, cursor_position.y - bounds.y,
),
lyon::math::Point::new(
to.x + bounds.x,
to.y + bounds.y,
), ),
lyon::math::Point::new(to.x, to.y),
); );
} }
} }
@ -186,10 +173,13 @@ mod bezier {
) )
.unwrap(); .unwrap();
let mesh = Primitive::Mesh2D(Arc::new(Mesh2D { let mesh = Primitive::Mesh2D {
origin: Point::new(bounds.x, bounds.y),
buffers: Arc::new(Mesh2D {
vertices: buffer.vertices, vertices: buffer.vertices,
indices: buffer.indices, indices: buffer.indices,
})); }),
};
( (
Primitive::Clip { Primitive::Clip {

View File

@ -69,23 +69,25 @@ mod rainbow {
let posn_center = { let posn_center = {
if b.contains(cursor_position) { if b.contains(cursor_position) {
[cursor_position.x, cursor_position.y] [cursor_position.x - b.x, cursor_position.y - b.y]
} else { } else {
[b.x + (b.width / 2.0), b.y + (b.height / 2.0)] [b.width / 2.0, b.height / 2.0]
} }
}; };
let posn_tl = [b.x, b.y]; let posn_tl = [0.0, 0.0];
let posn_t = [b.x + (b.width / 2.0), b.y]; let posn_t = [b.width / 2.0, 0.0];
let posn_tr = [b.x + b.width, b.y]; let posn_tr = [b.width, 0.0];
let posn_r = [b.x + b.width, b.y + (b.height / 2.0)]; let posn_r = [b.width, b.height / 2.0];
let posn_br = [b.x + b.width, b.y + b.height]; let posn_br = [b.width, b.height];
let posn_b = [b.x + (b.width / 2.0), b.y + b.height]; let posn_b = [(b.width / 2.0), b.height];
let posn_bl = [b.x, b.y + b.height]; let posn_bl = [0.0, b.height];
let posn_l = [b.x, b.y + (b.height / 2.0)]; let posn_l = [0.0, b.height / 2.0];
( (
Primitive::Mesh2D(std::sync::Arc::new(Mesh2D { Primitive::Mesh2D {
origin: Point::new(b.x, b.y),
buffers: std::sync::Arc::new(Mesh2D {
vertices: vec![ vertices: vec![
Vertex2D { Vertex2D {
position: posn_center, position: posn_center,
@ -134,7 +136,8 @@ mod rainbow {
0, 7, 8, // BL 0, 7, 8, // BL
0, 8, 1, // L 0, 8, 1, // L
], ],
})), }),
},
MouseCursor::OutOfBounds, MouseCursor::OutOfBounds,
) )
} }