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
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 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
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 }
}
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 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
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 }
}
sourcepub fn highres_image(&self) -> Option<SharedImage>
pub fn highres_image(&self) -> Option<SharedImage>
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 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