Compare commits

...

3 Commits

Author SHA1 Message Date
Jaby 1f8fc5100c Support pre-view of palette 2025-03-03 21:31:02 +01:00
Jaby 618b642c3f Prepare for palette display 2025-03-03 20:46:30 +01:00
Jaby 70cf70c4b5 Pixelate scale of selection window 2025-03-03 20:34:15 +01:00
5 changed files with 69 additions and 19 deletions

View File

@ -21,10 +21,19 @@ impl FileTab {
main_window.set_file_tab_enable(false); 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(); let main_window = self.main_window.borrow();
main_window.set_file_tab_image_data(image); 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 { if let Some(file_name) = file_name {
main_window.set_file_tab_image_name(file_name.into()); 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_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 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(); let img_size = image.size();
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 { 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))); 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(()) Ok(())

View File

@ -15,6 +15,8 @@ export component MainWindow inherits Window {
// Convert Image values // Convert Image values
in-out property file_tab_browse_path <=> file_tab.conv_image_path; 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_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_image_name <=> file_tab.conv_image_name;
in-out property file_tab_enable <=> file_tab.conv_image_enable; in-out property file_tab_enable <=> file_tab.conv_image_enable;
callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked; callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked;

View File

@ -14,8 +14,10 @@ component ProjectWidget inherits Rectangle {
component ConvertImageWidget inherits Rectangle { component ConvertImageWidget inherits Rectangle {
in-out property <string> image_path; in-out property <string> image_path;
in-out property <image> image_data; in-out property <image> image_data;
in-out property <image> palette_data;
in-out property <string> image_name; in-out property <string> image_name;
in-out property <bool> enable_button: false; in-out property <bool> enable_button: false;
in-out property <bool> palette_visible: false;
callback browse_clicked(); callback browse_clicked();
callback add_clicked(); callback add_clicked();
@ -48,21 +50,44 @@ component ConvertImageWidget inherits Rectangle {
} }
GroupBox { GroupBox {
title: "Loaded image"; title: "Loaded image and palette";
VerticalLayout { VerticalLayout {
alignment: start; alignment: start;
padding: 4px; padding: 4px;
HorizontalLayout { HorizontalLayout {
alignment: center; alignment: center;
Rectangle { Rectangle {
width: 256px; width: 256px + 2*4px; // < Because of border
height: 256px; height: 256px + 2*4px; // < Because of border
background: #000000; background: #404040;
border-color: #808080;
border-width: 4px;
Image { Image {
width: 256px; width: 256px;
height: 256px; height: 256px;
source: root.image_data; source: root.image_data;
image-fit: contain; image-fit: contain;
image-rendering: pixelated;
}
}
Rectangle {
// Fake padding because the padding setting for the HorizontalLayout would not work
width: 4px;
height: 1px;
}
Rectangle {
width: 256px + 2*4px; // < Because of border
height: 256px + 2*4px; // < Because of border
background: #404040;
border-color: #808080;
border-width: 4px;
palette_image := Image {
width: 256px;
height: 256px;
source: root.palette_data;
visible: root.palette_visible;
image-fit: contain;
image-rendering: pixelated;
} }
} }
} }
@ -91,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 { export component FileTab inherits Rectangle {
in-out property <string> conv_image_path; in-out property <string> conv_image_path;
in-out property <image> conv_image_data; 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 <string> conv_image_name;
in-out property <bool> conv_image_enable; in-out property <bool> conv_image_enable;
in-out property <State> state; in-out property <State> state;
@ -132,10 +168,12 @@ export component FileTab inherits Rectangle {
if root.state == State.Project : ProjectWidget { if root.state == State.Project : ProjectWidget {
} }
if root.state == State.ConvertImage : ConvertImageWidget { if root.state == State.ConvertImage : ConvertImageWidget {
image_path <=> root.conv_image_path; image_path <=> root.conv_image_path;
image_data <=> root.conv_image_data; image_data <=> root.conv_image_data;
image_name <=> root.conv_image_name; palette_data <=> root.conv_palette_data;
enable_button <=> root.conv_image_enable; palette_visible <=> root.conv_palette_enable;
image_name <=> root.conv_image_name;
enable_button <=> root.conv_image_enable;
browse_clicked => { browse_clicked => {
root.conv_image_browse_clicked(); root.conv_image_browse_clicked();

View File

@ -184,9 +184,10 @@ export component MainTab inherits Rectangle {
height: 128px; height: 128px;
background: #A0A0A0; background: #A0A0A0;
cur_sel_img := Image { cur_sel_img := Image {
width: 128px; width: 128px;
height: 128px; height: 128px;
image-fit: contain; image-fit: contain;
image-rendering: pixelated;
} }
} }
HorizontalLayout { HorizontalLayout {