Display encoding on main screen
This commit is contained in:
parent
72b97ad7d3
commit
62289bc07e
|
@ -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<Encoding, Error> {
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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<slint::Image>) {
|
||||
pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image, encoding: Encoding, image_palette: Option<slint::Image>) {
|
||||
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 {"<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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Rgba8Pixel>,
|
||||
palette: Option<PaletteInfo>,
|
||||
|
|
|
@ -87,7 +87,7 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefC
|
|||
let encoding = file_tab.get_encoding()?;
|
||||
let (image, palette_image) = logic.borrow_mut().add_unadded_tim_as(&file_name, encoding)?;
|
||||
|
||||
main_tab.add_new_vram_file(&file_name, image, palette_image);
|
||||
main_tab.add_new_vram_file(&file_name, image, encoding, palette_image);
|
||||
file_tab.clear_load();
|
||||
main_window.invoke_change_to_main();
|
||||
Ok(())
|
||||
|
|
|
@ -5,6 +5,7 @@ struct VRAMImage {
|
|||
img: image,
|
||||
x: int,
|
||||
y: int,
|
||||
encoding_str: string,
|
||||
palette_count: int,
|
||||
is_palette: bool,
|
||||
}
|
||||
|
@ -78,10 +79,12 @@ export component MainTab inherits Rectangle {
|
|||
}
|
||||
|
||||
if event.kind == PointerEventKind.down {
|
||||
cur_sel_x.text = parent.img_x;
|
||||
cur_sel_y.text = parent.img_y;
|
||||
cur_sel_img.source = parent.img;
|
||||
cur_sel_img.visible = true;
|
||||
cur_sel_x.text = parent.img_x;
|
||||
cur_sel_y.text = parent.img_y;
|
||||
cur_sel_img.source = parent.img;
|
||||
encoding_text.encoding_str = vram-image.encoding_str;
|
||||
cur_sel_img.visible = true;
|
||||
|
||||
vram_files_list.current-item = i;
|
||||
}
|
||||
}
|
||||
|
@ -150,10 +153,11 @@ export component MainTab inherits Rectangle {
|
|||
model: root.vram_files;
|
||||
|
||||
current-item-changed(current-item) => {
|
||||
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 <string> encoding_str;
|
||||
text: "Encoding: " + encoding_str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue