Struct 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.w(), but.h(), false);
surface::ImageSurface::push_current(&sur);
draw::set_draw_color(enums::Color::White);
draw::draw_rectf(0, 0, but.w(), but.h());
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 128)
127fn prep_shape(w: i32, h: i32) -> image::RgbImage {
128    let surf = surface::ImageSurface::new(w, h, false);
129
130    surface::ImageSurface::push_current(&surf);
131
132    draw::set_draw_color(enums::Color::Black);
133    draw::draw_rectf(-1, -1, w + 2, h + 2);
134
135    draw::set_draw_color(enums::Color::White);
136    draw::draw_rounded_rectf(0, 0, w, h, 16);
137
138    let img = surf.image().unwrap();
139
140    surface::ImageSurface::pop_current();
141
142    img
143}
More examples
Hide additional examples
examples/paint.rs (line 25)
20    pub fn new(w: i32, h: i32) -> Self {
21        let mut frame = Frame::default().with_size(w, h).center_of_parent();
22        frame.set_color(Color::White);
23        frame.set_frame(FrameType::DownBox);
24
25        let surf = ImageSurface::new(frame.w(), frame.h(), false);
26        ImageSurface::push_current(&surf);
27        draw_rect_fill(0, 0, w, h, Color::White);
28        ImageSurface::pop_current();
29
30        let surf = Rc::from(RefCell::from(surf));
31
32        frame.draw({
33            let surf = surf.clone();
34            move |f| {
35                let surf = surf.borrow();
36                let mut img = surf.image().unwrap();
37                img.draw(f.x(), f.y(), f.w(), f.h());
38            }
39        });
40
41        frame.handle({
42            let mut x = 0;
43            let mut y = 0;
44            let surf = surf.clone();
45            move |f, ev| {
46                // println!("{}", ev);
47                // println!("coords {:?}", app::event_coords());
48                // println!("get mouse {:?}", app::get_mouse());
49                let surf = surf.borrow_mut();
50                match ev {
51                    Event::Push => {
52                        ImageSurface::push_current(&surf);
53                        set_draw_color(Color::Red);
54                        set_line_style(LineStyle::Solid, 3);
55                        let coords = app::event_coords();
56                        x = coords.0;
57                        y = coords.1;
58                        draw_point(x, y);
59                        ImageSurface::pop_current();
60                        f.redraw();
61                        true
62                    }
63                    Event::Drag => {
64                        ImageSurface::push_current(&surf);
65                        set_draw_color(Color::Red);
66                        set_line_style(LineStyle::Solid, 3);
67                        let coords = app::event_coords();
68                        draw_line(x, y, coords.0, coords.1);
69                        x = coords.0;
70                        y = coords.1;
71                        ImageSurface::pop_current();
72                        f.redraw();
73                        true
74                    }
75                    _ => false,
76                }
77            }
78        });
79        Self { frame, surf }
80    }
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 138)
127fn prep_shape(w: i32, h: i32) -> image::RgbImage {
128    let surf = surface::ImageSurface::new(w, h, false);
129
130    surface::ImageSurface::push_current(&surf);
131
132    draw::set_draw_color(enums::Color::Black);
133    draw::draw_rectf(-1, -1, w + 2, h + 2);
134
135    draw::set_draw_color(enums::Color::White);
136    draw::draw_rounded_rectf(0, 0, w, h, 16);
137
138    let img = surf.image().unwrap();
139
140    surface::ImageSurface::pop_current();
141
142    img
143}
More examples
Hide additional examples
examples/paint.rs (line 36)
20    pub fn new(w: i32, h: i32) -> Self {
21        let mut frame = Frame::default().with_size(w, h).center_of_parent();
22        frame.set_color(Color::White);
23        frame.set_frame(FrameType::DownBox);
24
25        let surf = ImageSurface::new(frame.w(), frame.h(), false);
26        ImageSurface::push_current(&surf);
27        draw_rect_fill(0, 0, w, h, Color::White);
28        ImageSurface::pop_current();
29
30        let surf = Rc::from(RefCell::from(surf));
31
32        frame.draw({
33            let surf = surf.clone();
34            move |f| {
35                let surf = surf.borrow();
36                let mut img = surf.image().unwrap();
37                img.draw(f.x(), f.y(), f.w(), f.h());
38            }
39        });
40
41        frame.handle({
42            let mut x = 0;
43            let mut y = 0;
44            let surf = surf.clone();
45            move |f, ev| {
46                // println!("{}", ev);
47                // println!("coords {:?}", app::event_coords());
48                // println!("get mouse {:?}", app::get_mouse());
49                let surf = surf.borrow_mut();
50                match ev {
51                    Event::Push => {
52                        ImageSurface::push_current(&surf);
53                        set_draw_color(Color::Red);
54                        set_line_style(LineStyle::Solid, 3);
55                        let coords = app::event_coords();
56                        x = coords.0;
57                        y = coords.1;
58                        draw_point(x, y);
59                        ImageSurface::pop_current();
60                        f.redraw();
61                        true
62                    }
63                    Event::Drag => {
64                        ImageSurface::push_current(&surf);
65                        set_draw_color(Color::Red);
66                        set_line_style(LineStyle::Solid, 3);
67                        let coords = app::event_coords();
68                        draw_line(x, y, coords.0, coords.1);
69                        x = coords.0;
70                        y = coords.1;
71                        ImageSurface::pop_current();
72                        f.redraw();
73                        true
74                    }
75                    _ => false,
76                }
77            }
78        });
79        Self { frame, surf }
80    }
Source

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

Available on crate feature use-images only.

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>,

Source§

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>,

Source§

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.