pub struct ImageRoi<'a> { /* private fields */ }Implementations§
Source§impl<'a> ImageRoi<'a>
impl<'a> ImageRoi<'a>
Sourcepub fn draw<R: Renderer>(&self, renderer: &mut R, x: i32, y: i32)
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> 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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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