Struct fltk::surface::ImageSurface

source ·
pub struct ImageSurface { /* private fields */ }
Expand description

An image surface object. Example usage:

use fltk::{prelude::*, *};
let but = button::Button::new(0, 0, 80, 40, "Click");
let sur = surface::ImageSurface::new(but.width(), but.height(), false);
surface::ImageSurface::push_current(&sur);
draw::set_draw_color(enums::Color::White);
draw::draw_rectf(0, 0, but.width(), but.height());
sur.draw(&but, 0, 0);
let img = sur.image().unwrap();
surface::ImageSurface::pop_current();

Implementations§

source§

impl ImageSurface

source

pub fn new(w: i32, h: i32, high_res: bool) -> ImageSurface

Creates a new image surface

Examples found in repository?
examples/shapedwindow_taskbar.rs (line 118)
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn prep_shape(w: i32, h: i32) -> image::RgbImage {
    let surf = surface::ImageSurface::new(w, h, false);

    surface::ImageSurface::push_current(&surf);

    draw::set_draw_color(enums::Color::Black);
    draw::draw_rectf(-1, -1, w + 2, h + 2);

    draw::set_draw_color(enums::Color::White);
    draw::draw_rounded_rectf(0, 0, w, h, 16);

    let img = surf.image().unwrap();

    surface::ImageSurface::pop_current();

    img
}
More examples
Hide additional examples
examples/paint.rs (line 25)
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 }
    }
source

pub fn image(&self) -> Option<RgbImage>

Gets the image of an image surface as an rgb image

Examples found in repository?
examples/shapedwindow_taskbar.rs (line 128)
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
fn prep_shape(w: i32, h: i32) -> image::RgbImage {
    let surf = surface::ImageSurface::new(w, h, false);

    surface::ImageSurface::push_current(&surf);

    draw::set_draw_color(enums::Color::Black);
    draw::draw_rectf(-1, -1, w + 2, h + 2);

    draw::set_draw_color(enums::Color::White);
    draw::draw_rounded_rectf(0, 0, w, h, 16);

    let img = surf.image().unwrap();

    surface::ImageSurface::pop_current();

    img
}
More examples
Hide additional examples
examples/paint.rs (line 36)
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 }
    }
source

pub fn highres_image(&self) -> Option<SharedImage>

Gets the high resolution image of an image surface as a shared image

source

pub fn origin(&self) -> (i32, i32)

Gets the origin coordinates of an image surface

source

pub fn set_origin(&mut self, x: i32, y: i32)

Set the origin coordinates of an image surface

source

pub fn rescale(&mut self)

Rescale an image surface

source

pub fn draw<W: WidgetExt>(&self, widget: &W, delta_x: i32, delta_y: i32)

Draw a widget on the image surface

source

pub fn draw_decorated_window<W: WindowExt>( &self, win: &W, x_offset: i32, y_offset: i32 )

draw a decorated window

Trait Implementations§

source§

impl Drop for ImageSurface

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl SurfaceDevice for ImageSurface

source§

fn is_current(&self) -> bool

Checks whether this surface is the current surface
source§

fn surface() -> Self

Get the current surface
source§

fn push_current(new_current: &ImageSurface)

Push a surface as a current surface
source§

fn pop_current()

Pop the current surface

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.