use notan::draw::*;
use notan::math::Vec2;
use notan::prelude::*;
#[derive(Default, AppState)]
struct State {
rot: f32,
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(State::default)
.add_config(DrawConfig)
.draw(draw)
.build()
}
fn draw(app: &mut App, gfx: &mut Graphics, state: &mut State) {
let mut draw = gfx.create_draw();
draw.clear(Color::BLACK);
{
let size = (400.0, 300.0);
let mut rect = draw.rect((0.0, 0.0), size);
rect.rotate_from((size.0 * 0.5, size.1 * 0.5), state.rot)
.translate(200.0, 150.0);
let local = rect.screen_to_local_position(app.mouse.x, app.mouse.y);
let color = rect_color(local, size);
rect.color(color);
}
state.rot += app.timer.delta_f32();
gfx.render(&draw);
}
fn rect_color(local: Vec2, size: (f32, f32)) -> Color {
let (width, height) = size;
let in_bounds = local.x >= 0.0 && local.x <= width && local.y >= 0.0 && local.y <= height;
if in_bounds {
Color::RED
} else {
Color::WHITE
}
}