diff --git a/src/Tools/tim_tool/src/gui/file_tab.rs b/src/Tools/tim_tool/src/gui/file_tab.rs index 9c7635f9..d076e654 100644 --- a/src/Tools/tim_tool/src/gui/file_tab.rs +++ b/src/Tools/tim_tool/src/gui/file_tab.rs @@ -11,15 +11,11 @@ pub struct FileTab { } impl FileTab { - const FOUR_BIT_NAME:&str = "4 bit"; - const EIGHT_BIT_NAME:&str = "8 bit"; - const FULL_COLOR_NAME:&str = "Full color"; - fn update_encoding_options(&self, width: u32, height: u32, has_palette: bool) -> Result<&str, Error> { self.encoding_options.clear(); if has_palette { - let mut selected_str = Self::EIGHT_BIT_NAME; + let mut selected_str = Encoding::EightBit.to_str(); let has_4bit = width%4 == 0; let has_8bit = width%2 == 0; @@ -28,19 +24,19 @@ impl FileTab { } if has_4bit { - self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::FOUR_BIT_NAME, width/4, height))); - selected_str = Self::FOUR_BIT_NAME; + self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Encoding::FourBit.to_str(), width/4, height))); + selected_str = Encoding::FourBit.to_str(); } if has_8bit { - self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::EIGHT_BIT_NAME, width/2, height))); + self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Encoding::EightBit.to_str(), width/2, height))); } Ok(selected_str) } else { - self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Self::FULL_COLOR_NAME, width, height))); - Ok(Self::FULL_COLOR_NAME) + self.encoding_options.push(SharedString::from(format!("{} ({}/{})", Encoding::FullColor.to_str(), width, height))); + Ok(Encoding::FullColor.to_str()) } } @@ -116,15 +112,15 @@ impl FileTab { pub fn get_encoding(&self) -> Result { let selected_encoding = self.main_window.borrow().get_file_tab_selected_encoding(); - if selected_encoding.starts_with(Self::FOUR_BIT_NAME) { + if selected_encoding.starts_with(Encoding::FourBit.to_str()) { Ok(Encoding::FourBit) } - else if selected_encoding.starts_with(Self::EIGHT_BIT_NAME) { + else if selected_encoding.starts_with(Encoding::EightBit.to_str()) { Ok(Encoding::EightBit) } - else if selected_encoding.starts_with(Self::FULL_COLOR_NAME) { + else if selected_encoding.starts_with(Encoding::FullColor.to_str()) { Ok(Encoding::FullColor) } diff --git a/src/Tools/tim_tool/src/gui/main_tab.rs b/src/Tools/tim_tool/src/gui/main_tab.rs index 84db3017..4e2b5c32 100644 --- a/src/Tools/tim_tool/src/gui/main_tab.rs +++ b/src/Tools/tim_tool/src/gui/main_tab.rs @@ -1,7 +1,8 @@ use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMImage}; use super::{GUIElementsRef, MainWindowRef}; -use slint::Model; +use slint::{Model, SharedString}; +use tim_tool::logic::tim::Encoding; use std::{rc::Rc, sync::{Arc, Mutex}}; struct VRAM { @@ -26,13 +27,15 @@ impl MainTab { MainTab{main_window, vram: Arc::new(Mutex::new(VRAM{file_list: vram_file_list, image_list: vram_image_list}))} } - pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image, image_palette: Option) { + pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image, encoding: Encoding, image_palette: Option) { let vram_data = self.vram.lock().expect("VRAM already locked"); - let add_new_image = |file_name: &String, image: slint::Image, palette_count: i32, is_palette: bool| { - let vram_image = VRAMImage{ + let add_new_image = |file_name: &String, image: slint::Image, encoding: Encoding, palette_count: i32, is_palette: bool| { + let encoding_str = if is_palette {""} else {encoding.to_str()}; + let vram_image = VRAMImage{ img: image, x: 0, y: 0, + encoding_str: SharedString::from(encoding_str), palette_count, is_palette, }; @@ -41,10 +44,10 @@ impl MainTab { vram_data.image_list.push(vram_image); }; - add_new_image(file_name, image, if image_palette.is_some() {1} else {0}, false); + add_new_image(file_name, image, encoding, if image_palette.is_some() {1} else {0}, false); if let Some(image_palette) = image_palette { let file_name = " => ".to_owned() + file_name.as_str() + " (Palette)"; - add_new_image(&file_name, image_palette, 0, true); + add_new_image(&file_name, image_palette, encoding, 0, true); } } diff --git a/src/Tools/tim_tool/src/logic/tim.rs b/src/Tools/tim_tool/src/logic/tim.rs index 7cdf8d3b..6f176afc 100644 --- a/src/Tools/tim_tool/src/logic/tim.rs +++ b/src/Tools/tim_tool/src/logic/tim.rs @@ -2,12 +2,27 @@ use std::{fs::File, path::PathBuf}; use slint::{Rgba8Pixel, SharedPixelBuffer}; use tool_helper::Error; +#[derive(Clone, Copy)] pub enum Encoding { FourBit, EightBit, FullColor, } +impl Encoding { + const FOUR_BIT_NAME:&str = "4 bit"; + const EIGHT_BIT_NAME:&str = "8 bit"; + const FULL_COLOR_NAME:&str = "Full color"; + + pub const fn to_str(&self) -> &str { + match self { + Encoding::FourBit => Self::FOUR_BIT_NAME, + Encoding::EightBit => Self::EIGHT_BIT_NAME, + Encoding::FullColor => Self::FULL_COLOR_NAME, + } + } +} + pub struct TIMInfo { image_data: SharedPixelBuffer, palette: Option, diff --git a/src/Tools/tim_tool/src/main.rs b/src/Tools/tim_tool/src/main.rs index da21920a..496e4767 100644 --- a/src/Tools/tim_tool/src/main.rs +++ b/src/Tools/tim_tool/src/main.rs @@ -87,7 +87,7 @@ fn setup_file_tab(gui_elements_ref: Rc>, logic_ref: Rc { - cur_sel_x.text = root.vram_images[current-item].x; - cur_sel_y.text = root.vram_images[current-item].y; - cur_sel_img.source = root.vram_images[current-item].img; - cur_sel_img.visible = true; + cur_sel_x.text = root.vram_images[current-item].x; + cur_sel_y.text = root.vram_images[current-item].y; + cur_sel_img.source = root.vram_images[current-item].img; + encoding_text.encoding_str = root.vram_images[current-item].encoding_str; + cur_sel_img.visible = true; } } HorizontalLayout { @@ -232,9 +236,9 @@ export component MainTab inherits Rectangle { } } } - ComboBox { - model: ["4-bit", "16-bit", "24-bit"]; - current-value: "4-bit"; + encoding_text := Text { + in-out property encoding_str; + text: "Encoding: " + encoding_str; } } }