Function fltk::draw::draw_point

source ·
pub fn draw_point(x: i32, y: i32)
Expand description

Draws a point

Examples found in repository?
examples/paint.rs (line 58)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    pub fn new(w: i32, h: i32) -> Self {
        let mut frame = Frame::default().with_size(w, h).center_of_parent();
        frame.set_color(Color::White);
        frame.set_frame(FrameType::DownBox);

        let surf = ImageSurface::new(frame.width(), frame.height(), false);
        ImageSurface::push_current(&surf);
        draw_rect_fill(0, 0, w, h, Color::White);
        ImageSurface::pop_current();

        let surf = Rc::from(RefCell::from(surf));

        frame.draw({
            let surf = surf.clone();
            move |f| {
                let surf = surf.borrow();
                let mut img = surf.image().unwrap();
                img.draw(f.x(), f.y(), f.w(), f.h());
            }
        });

        frame.handle({
            let mut x = 0;
            let mut y = 0;
            let surf = surf.clone();
            move |f, ev| {
                // println!("{}", ev);
                // println!("coords {:?}", app::event_coords());
                // println!("get mouse {:?}", app::get_mouse());
                let surf = surf.borrow_mut();
                match ev {
                    Event::Push => {
                        ImageSurface::push_current(&surf);
                        set_draw_color(Color::Red);
                        set_line_style(LineStyle::Solid, 3);
                        let coords = app::event_coords();
                        x = coords.0;
                        y = coords.1;
                        draw_point(x, y);
                        ImageSurface::pop_current();
                        f.redraw();
                        true
                    }
                    Event::Drag => {
                        ImageSurface::push_current(&surf);
                        set_draw_color(Color::Red);
                        set_line_style(LineStyle::Solid, 3);
                        let coords = app::event_coords();
                        draw_line(x, y, coords.0, coords.1);
                        x = coords.0;
                        y = coords.1;
                        ImageSurface::pop_current();
                        f.redraw();
                        true
                    }
                    _ => false,
                }
            }
        });
        Self { frame, surf }
    }