ImageRoi

Struct ImageRoi 

Source
pub struct ImageRoi<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> ImageRoi<'a>

Source

pub fn draw<R: Renderer>(&self, renderer: &mut R, x: i32, y: i32)

Draw the ROI on a window

Examples found in repository?
examples/background.rs (lines 125-128)
73fn main() {
74    let mut args = env::args().skip(1);
75
76    let path = match args.next() {
77        Some(arg) => arg,
78        None => "/ui/background.png".to_string(),
79    };
80
81    let mode = BackgroundMode::from_str(&args.next().unwrap_or(String::new()));
82
83    match Image::from_path(&path) {
84        Ok(image) => {
85            let (display_width, display_height) = orbclient::get_display_size().expect("background: failed to get display size");
86
87            let mut window = Window::new_flags(
88                0, 0, display_width, display_height, &format!("{} - Background", path),
89                &[WindowFlag::Back, WindowFlag::Borderless, WindowFlag::Unclosable]
90            ).unwrap();
91
92            let mut scaled_image = image.clone();
93            let mut resize = Some((display_width, display_height));
94            loop {
95                if let Some((w, h)) = resize.take() {
96                    let (width, height) = find_scale(&image, mode, w, h);
97
98                    if width == scaled_image.width() && height == scaled_image.height() {
99                        // Do not resize scaled image
100                    } else if width == image.width() && height == image.height() {
101                        scaled_image = image.clone();
102                    } else {
103                        scaled_image = image.resize(width, height, orbimage::ResizeType::Lanczos3).unwrap();
104                    }
105
106                    let (crop_x, crop_w) = if width > w  {
107                        ((width - w)/2, w)
108                    } else {
109                        (0, width)
110                    };
111
112                    let (crop_y, crop_h) = if height > h {
113                        ((height - h)/2, h)
114                    } else {
115                        (0, height)
116                    };
117
118                    window.set(Color::rgb(0, 0, 0));
119
120                    let x = (w as i32 - crop_w as i32)/2;
121                    let y = (h as i32 - crop_h as i32)/2;
122                    scaled_image.roi(
123                        crop_x, crop_y,
124                        crop_w, crop_h,
125                    ).draw(
126                        &mut window,
127                        x, y
128                    );
129
130                    window.sync();
131                }
132
133                for event in window.events() {
134                    match event.to_option() {
135                        EventOption::Resize(resize_event) => {
136                            resize = Some((resize_event.width, resize_event.height));
137                        },
138                        EventOption::Screen(screen_event) => {
139                            window.set_size(screen_event.width, screen_event.height);
140                            resize = Some((screen_event.width, screen_event.height));
141                        },
142                        EventOption::Quit(_) => return,
143                        _ => ()
144                    }
145                }
146            }
147        },
148        Err(err) => {
149            println!("background: error loading {}: {}", path, err);
150        }
151    }
152}

Auto Trait Implementations§

§

impl<'a> Freeze for ImageRoi<'a>

§

impl<'a> !RefUnwindSafe for ImageRoi<'a>

§

impl<'a> !Send for ImageRoi<'a>

§

impl<'a> !Sync for ImageRoi<'a>

§

impl<'a> Unpin for ImageRoi<'a>

§

impl<'a> !UnwindSafe for ImageRoi<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
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.