-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathdraw_image_crop.rs
45 lines (37 loc) · 973 Bytes
/
draw_image_crop.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use notan::draw::*;
use notan::prelude::*;
#[derive(AppState)]
struct State {
img: Texture,
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(init)
.add_config(DrawConfig)
.draw(draw)
.build()
}
fn init(gfx: &mut Graphics) -> State {
let texture = gfx
.create_texture()
.from_image(include_bytes!("assets/rust-logo-512x512.png"))
.build()
.unwrap();
State { img: texture }
}
fn draw(gfx: &mut Graphics, state: &mut State) {
let (ww, hh) = state.img.size();
let mut draw = gfx.create_draw();
draw.clear(Color::WHITE);
// Right side of the logo
draw.image(&state.img)
.position(100.0, 50.0)
.size(ww * 0.5, hh)
.crop((ww * 0.5, 0.0), (ww * 0.5, hh));
// Left side of the logo
draw.image(&state.img)
.position(450.0, 50.0)
.size(ww * 0.5, hh)
.crop((0.0, 0.0), (ww * 0.5, hh));
gfx.render(&draw);
}