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
impl ImageSurface
Sourcepub fn new(w: i32, h: i32, high_res: bool) -> ImageSurface
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
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 }
Sourcepub fn image(&self) -> Option<RgbImage>
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
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 }
Sourcepub fn highres_image(&self) -> Option<SharedImage>
Available on crate feature use-images
only.
pub fn highres_image(&self) -> Option<SharedImage>
use-images
only.Gets the high resolution image of an image surface as a shared image
Sourcepub fn set_origin(&mut self, x: i32, y: i32)
pub fn set_origin(&mut self, x: i32, y: i32)
Set the origin coordinates of an image surface
Trait Implementations§
Source§impl Drop for ImageSurface
impl Drop for ImageSurface
Source§impl SurfaceDevice for ImageSurface
impl SurfaceDevice for ImageSurface
Source§fn is_current(&self) -> bool
fn is_current(&self) -> bool
Checks whether this surface is the current surface
Source§fn push_current(new_current: &ImageSurface)
fn push_current(new_current: &ImageSurface)
Push a surface as a current surface
Source§fn pop_current()
fn pop_current()
Pop the current surface
Auto Trait Implementations§
impl Freeze for ImageSurface
impl RefUnwindSafe for ImageSurface
impl !Send for ImageSurface
impl !Sync for ImageSurface
impl Unpin for ImageSurface
impl UnwindSafe for ImageSurface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more