Support pre-view of palette

This commit is contained in:
Jaby 2025-03-03 21:31:02 +01:00
parent 618b642c3f
commit 1f8fc5100c
4 changed files with 37 additions and 11 deletions

View File

@ -21,10 +21,19 @@ impl FileTab {
main_window.set_file_tab_enable(false);
}
pub fn update_new_load(&self, file_name: Option<String>, image: Image) {
pub fn update_new_load(&self, file_name: Option<String>, image: Image, palette: Option<Image>) {
let main_window = self.main_window.borrow();
main_window.set_file_tab_image_data(image);
if let Some(palette) = palette {
main_window.set_file_tab_palette_data(palette);
main_window.set_file_tab_palette_visible(true);
}
else {
main_window.set_file_tab_palette_visible(false);
}
if let Some(file_name) = file_name {
main_window.set_file_tab_image_name(file_name.into());
}

View File

@ -58,13 +58,13 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefC
let file_tab = &gui_elements.file_tab;
let file_name = if let Some(name) = file.file_name() {Some(name.to_string_lossy().to_string())} else {None};
let (image, _palette_image) = logic.borrow_mut().set_unadded_tim(&file)?;
let (image, palette) = logic.borrow_mut().set_unadded_tim(&file)?;
let img_size = image.size();
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
return Err(Error::from_text(format!("Image size ({}; {}) is to big for VRAM ({}, {})", img_size.width, img_size.height, VRAM_WIDTH, VRAM_HEIGHT)));
}
file_tab.update_new_load(file_name, image);
file_tab.update_new_load(file_name, image, palette);
}
Ok(())

View File

@ -15,6 +15,8 @@ export component MainWindow inherits Window {
// Convert Image values
in-out property file_tab_browse_path <=> file_tab.conv_image_path;
in-out property file_tab_image_data <=> file_tab.conv_image_data;
in-out property file_tab_palette_data <=> file_tab.conv_palette_data;
in-out property file_tab_palette_visible <=> file_tab.conv_palette_enable;
in-out property file_tab_image_name <=> file_tab.conv_image_name;
in-out property file_tab_enable <=> file_tab.conv_image_enable;
callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked;

View File

@ -14,9 +14,10 @@ component ProjectWidget inherits Rectangle {
component ConvertImageWidget inherits Rectangle {
in-out property <string> image_path;
in-out property <image> image_data;
in-out property <image> image_palette_data;
in-out property <image> palette_data;
in-out property <string> image_name;
in-out property <bool> enable_button: false;
in-out property <bool> palette_visible: false;
callback browse_clicked();
callback add_clicked();
@ -80,10 +81,11 @@ component ConvertImageWidget inherits Rectangle {
background: #404040;
border-color: #808080;
border-width: 4px;
Image {
palette_image := Image {
width: 256px;
height: 256px;
source: root.image_palette_data;
source: root.palette_data;
visible: root.palette_visible;
image-fit: contain;
image-rendering: pixelated;
}
@ -114,11 +116,22 @@ component ConvertImageWidget inherits Rectangle {
}
}
}
public function set_palette_image(image: image) {
palette_image.source = image;
palette_image.visible = true;
}
public function clear_palette_image() {
palette_image.visible = false;
}
}
export component FileTab inherits Rectangle {
in-out property <string> conv_image_path;
in-out property <image> conv_image_data;
in-out property <image> conv_palette_data;
in-out property <bool> conv_palette_enable;
in-out property <string> conv_image_name;
in-out property <bool> conv_image_enable;
in-out property <State> state;
@ -155,11 +168,13 @@ export component FileTab inherits Rectangle {
if root.state == State.Project : ProjectWidget {
}
if root.state == State.ConvertImage : ConvertImageWidget {
image_path <=> root.conv_image_path;
image_data <=> root.conv_image_data;
image_name <=> root.conv_image_name;
enable_button <=> root.conv_image_enable;
image_path <=> root.conv_image_path;
image_data <=> root.conv_image_data;
palette_data <=> root.conv_palette_data;
palette_visible <=> root.conv_palette_enable;
image_name <=> root.conv_image_name;
enable_button <=> root.conv_image_enable;
browse_clicked => {
root.conv_image_browse_clicked();
}