diff --git a/src/file_manager/main.rs b/src/file_manager/main.rs index 21030cb65839b1c3e73d9f041c7bdb92c3241891..b12506e538c1104a3b62c7c556a102b64b508f44 100644 --- a/src/file_manager/main.rs +++ b/src/file_manager/main.rs @@ -5,9 +5,8 @@ extern crate orbclient; extern crate orbimage; extern crate orbfont; -use std::{cmp, env}; +use std::{cmp, env, fs}; use std::collections::BTreeMap; -use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; use std::string::{String, ToString}; @@ -17,6 +16,8 @@ use orbclient::{event, Color, EventOption, MouseEvent, Renderer, Window}; use orbimage::Image; use orbfont::Font; +const ICON_SIZE: i32 = 32; + #[cfg(target_os = "redox")] static UI_PATH: &'static str = "/ui/icons"; @@ -239,10 +240,14 @@ pub struct FileManager { fn load_icon(path: &Path) -> Image { match Image::from_path(path) { - Ok(icon) => icon, + Ok(icon) => if icon.width() == ICON_SIZE as u32 && icon.height() == ICON_SIZE as u32 { + icon + } else { + icon.resize(ICON_SIZE as u32, ICON_SIZE as u32, orbimage::ResizeType::Lanczos3).unwrap() + }, Err(err) => { println!("Failed to load icon {}: {}", path.display(), err); - Image::from_color(48, 48, Color::rgba(0, 0, 0, 0)) + Image::from_color(ICON_SIZE as u32, ICON_SIZE as u32, Color::rgba(0, 0, 0, 0)) } } } @@ -295,10 +300,8 @@ impl FileManager { } fn draw_header_row(&mut self) { - let row = 0; - for column in self.columns.iter() { - let text_y = 48 * row as i32 + 8; + let text_y = 8; self.font.render(column.name, 16.0).draw(&mut self.window, column.x, text_y, Color::rgb(0, 0, 0)); if column.sort_predicate == self.sort_predicate { @@ -314,11 +317,11 @@ impl FileManager { fn draw_file_list(&mut self) { for (i, file) in self.files.iter().enumerate() { - let y = 48 * (i + 1) as i32; // Plus 1 because the header row is 0 + let y = ICON_SIZE * i as i32 + 32; // Plus 32 because the header row is 32 pixels let text_color = if i as isize == self.selected { let width = self.window.width(); - self.window.rect(0, y, width, 48, Color::rgb(0x52, 0x94, 0xE2)); + self.window.rect(0, y, width, ICON_SIZE as u32, Color::rgb(0x52, 0x94, 0xE2)); Color::rgb(255, 255, 255) } else { Color::rgb(0, 0, 0) @@ -430,7 +433,7 @@ impl FileManager { self.sort_files(); - self.columns[0].x = 56; + self.columns[0].x = ICON_SIZE + 8; self.columns[1].x = self.columns[0].x + self.columns[0].width; self.columns[2].x = self.columns[1].x + self.columns[1].width; @@ -440,7 +443,7 @@ impl FileManager { let x = self.window.x(); let y = self.window.y(); let w = (self.columns[2].x + self.columns[2].width) as u32; - let h = ((self.files.len() + 1) * 48) as u32; // +1 for the header row + let h = (self.files.len() * ICON_SIZE as usize) as u32 + 32; // +32 for the header row self.window = Window::new(x, y, w, h, &path).unwrap(); @@ -549,8 +552,8 @@ impl FileManager { redraw = false; for (row, _) in self.files.iter().enumerate() { - if mouse_event.y >= 48 * (row as i32 + 1) && // +1 for the header row - mouse_event.y < 48 * (row as i32 + 2) { + if mouse_event.y >= ICON_SIZE * (row as i32 + 1) && // +1 for the header row + mouse_event.y < ICON_SIZE * (row as i32 + 2) { if row as isize != self.selected { self.selected = row as isize; redraw = true; @@ -559,7 +562,7 @@ impl FileManager { } if ! mouse_event.left_button && self.last_mouse_event.left_button { - if mouse_event.y < 48 { // Header row clicked + if mouse_event.y < ICON_SIZE { // Header row clicked if mouse_event.x < self.columns[1].x as i32 { if self.sort_predicate != SortPredicate::Name { self.sort_predicate = SortPredicate::Name; diff --git a/src/launcher/main.rs b/src/launcher/main.rs index 8c4390d7272a6899460c4ceb7e4aa75a01211303..8140cc8cd85765786d48ee19ef58b5f3687617dc 100644 --- a/src/launcher/main.rs +++ b/src/launcher/main.rs @@ -5,6 +5,8 @@ extern crate orbclient; extern crate orbimage; extern crate orbfont; +pub const ICON_SIZE: i32 = 40; + #[cfg(target_os = "redox")] static UI_PATH: &'static str = "/ui"; @@ -31,6 +33,15 @@ fn wait(status: &mut usize) -> usize { syscall::waitpid(0, status, syscall::WNOHANG).unwrap() } +fn load_icon(path: &str) -> Image { + let icon = Image::from_path(path).unwrap_or(Image::default()); + if icon.width() == ICON_SIZE as u32 && icon.height() == ICON_SIZE as u32 { + icon + } else { + icon.resize(ICON_SIZE as u32, ICON_SIZE as u32, orbimage::ResizeType::Lanczos3).unwrap() + } +} + use std::env; use std::os::unix::process::ExitStatusExt; use std::path::Path; @@ -133,18 +144,18 @@ fn draw_chooser(window: &mut Window, font: &Font, packages: &Vec<Package>, selec let mut y = 0; for (i, package) in packages.iter().enumerate() { if i as i32 == selected { - window.rect(0, y, w, 48, BAR_HIGHLIGHT_COLOR); + window.rect(0, y, w, ICON_SIZE as u32, BAR_HIGHLIGHT_COLOR); } package.icon.draw(window, 0, y); - let mut c_x = 56; + let mut c_x = ICON_SIZE + 8; for c in package.name.chars() { font.render(&c.to_string(), 16.0).draw(window, c_x as i32, y + 8, if i as i32 == selected { TEXT_HIGHLIGHT_COLOR } else { TEXT_COLOR }); c_x += 8; } - y += 48; + y += ICON_SIZE; } window.sync(); @@ -155,12 +166,12 @@ fn bar_main() { let packages = get_packages(); - let start = Image::from_path(format!("{}/icons/places/start-here.png", UI_PATH)).unwrap_or(Image::default()); + let start = load_icon(&format!("{}/icons/places/start-here.png", UI_PATH)); - let shutdown = Image::from_path(format!("{}/icons/actions/system-log-out.png", UI_PATH)).unwrap_or(Image::default()); + let shutdown = load_icon(&format!("{}/icons/actions/system-log-out.png", UI_PATH)); let (width, height) = orbclient::get_display_size().expect("launcher: failed to get display size"); - let mut window = Window::new(0, height as i32 - 48, width, 48, "").expect("launcher: failed to open window"); + let mut window = Window::new(0, height as i32 - ICON_SIZE, width, ICON_SIZE as u32, "").expect("launcher: failed to open window"); let mut selected = -1; let mut last_left_button = false; @@ -215,8 +226,8 @@ fn bar_main() { let mut i = 0; if i == selected { - let start_h = packages.len() as u32 * 48; - let mut start_window = Window::new(0, height as i32 - 48 - start_h as i32, 320, start_h, "").unwrap(); + let start_h = packages.len() as u32 * ICON_SIZE as u32; + let mut start_window = Window::new(0, height as i32 - ICON_SIZE - start_h as i32, 320, start_h, "").unwrap(); let font = Font::find(None, None, None).unwrap(); let mut selected = -1; @@ -231,10 +242,10 @@ fn bar_main() { let mut y = 0; for (i, _package) in packages.iter().enumerate() { - if mouse_event.y >= y && mouse_event.y < y + 48 { + if mouse_event.y >= y && mouse_event.y < y + ICON_SIZE { now_selected = i as i32; } - y += 48; + y += ICON_SIZE; } if now_selected != selected { @@ -245,14 +256,14 @@ fn bar_main() { if ! mouse_event.left_button && last_left_button { let mut y = 0; for package in packages.iter() { - if mouse_event.y >= y && mouse_event.y < y + 48 { + if mouse_event.y >= y && mouse_event.y < y + ICON_SIZE { match Command::new(&package.binary).spawn() { Ok(child) => children.push(child), Err(err) => println!("launcher: failed to launch {}: {}", package.binary, err) } break 'start_choosing; } - y += 48; + y += ICON_SIZE; } } @@ -336,7 +347,7 @@ fn chooser_main(paths: env::Args) { }); if packages.len() > 1 { - let mut window = Window::new(-1, -1, 320, packages.len() as u32 * 48, path).expect("launcher: failed to open window"); + let mut window = Window::new(-1, -1, 320, packages.len() as u32 * ICON_SIZE as u32, path).expect("launcher: failed to open window"); let font = Font::find(None, None, None).expect("launcher: failed to open font"); let mut selected = -1; @@ -351,10 +362,10 @@ fn chooser_main(paths: env::Args) { let mut y = 0; for (i, _package) in packages.iter().enumerate() { - if mouse_event.y >= y && mouse_event.y < y + 48 { + if mouse_event.y >= y && mouse_event.y < y + ICON_SIZE { now_selected = i as i32; } - y += 48; + y += ICON_SIZE; } if now_selected != selected { @@ -365,13 +376,13 @@ fn chooser_main(paths: env::Args) { if ! mouse_event.left_button && last_left_button { let mut y = 0; for package in packages.iter() { - if mouse_event.y >= y && mouse_event.y < y + 48 { + if mouse_event.y >= y && mouse_event.y < y + ICON_SIZE { if let Err(err) = Command::new(&package.binary).arg(path).spawn() { println!("launcher: failed to launch {}: {}", package.binary, err); } break 'choosing; } - y += 48; + y += ICON_SIZE; } } diff --git a/src/launcher/package.rs b/src/launcher/package.rs index 59b389fdc4bdcd2f78a2dc030a75e0c3c6bed8dc..a4ee5d36e610f84e3585acbf056fe0d51254e765 100644 --- a/src/launcher/package.rs +++ b/src/launcher/package.rs @@ -3,6 +3,8 @@ use std::io::Read; use orbimage::Image; +use super::load_icon; + /// A package (_REDOX content serialized) pub struct Package { /// The URL @@ -56,7 +58,7 @@ impl Package { } else if line.starts_with("binary=") { package.binary = line[7..].to_string(); } else if line.starts_with("icon=") { - package.icon = Image::from_path(&line[5..]).unwrap_or(Image::default()); + package.icon = load_icon(&line[5..]); } else if line.starts_with("accept=") { package.accepts.push(line[7..].to_string()); } else if line.starts_with("author=") {