topic/jb/tim_tool/risize_image #18
|
@ -1,27 +1,63 @@
|
|||
use crate::MainWindow;
|
||||
use super::{GUIElements, GUIElementsRef, MainWindowRef, display_error};
|
||||
use slint::Image;
|
||||
use slint::{Image, SharedString};
|
||||
use std::rc::Rc;
|
||||
use tool_helper::Error;
|
||||
|
||||
pub struct FileTab {
|
||||
main_window: MainWindowRef
|
||||
main_window: MainWindowRef,
|
||||
encoding_options: Rc<slint::VecModel<SharedString>>
|
||||
}
|
||||
|
||||
impl FileTab {
|
||||
fn update_encoding_options(&self, width: u32, height: u32, has_palette: bool) -> Result<(), Error> {
|
||||
self.encoding_options.clear();
|
||||
|
||||
if has_palette {
|
||||
let has_4bit = width%4 == 0;
|
||||
let has_8bit = width%2 == 0;
|
||||
|
||||
if !has_4bit && !has_8bit {
|
||||
return Err(Error::from_text(format!("Image width must be multiple of 2 and or 4 ({}/{})", width, height)));
|
||||
}
|
||||
|
||||
if has_4bit {
|
||||
self.encoding_options.push(SharedString::from(format!("4 bit ({}/{})", width/4, height)));
|
||||
}
|
||||
|
||||
if has_8bit {
|
||||
self.encoding_options.push(SharedString::from(format!("8 bit ({}/{})", width/2, height)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
else {
|
||||
self.encoding_options.push(SharedString::from(format!("16 bit ({}/{})", width, height)));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(main_window: MainWindowRef) -> FileTab {
|
||||
FileTab{main_window}
|
||||
let encoding_options = Rc::new(slint::VecModel::from(Vec::<SharedString>::new()));
|
||||
|
||||
main_window.borrow().set_file_tab_encoding_options(encoding_options.clone().into());
|
||||
FileTab{main_window, encoding_options}
|
||||
}
|
||||
|
||||
pub fn clear_load(&self) {
|
||||
let main_window = self.main_window.borrow();
|
||||
|
||||
self.encoding_options.clear();
|
||||
main_window.set_file_tab_browse_path("".into());
|
||||
main_window.set_file_tab_image_data(Image::default());
|
||||
main_window.set_file_tab_palette_data(Image::default());
|
||||
main_window.set_file_tab_image_name("".into());
|
||||
main_window.set_file_tab_enable(false);
|
||||
}
|
||||
|
||||
pub fn update_new_loaded_file(&self, file_name: Option<String>, image: Image, palette: Option<Image>) {
|
||||
pub fn update_new_loaded_file(&self, file_name: Option<String>, image: Image, palette: Option<Image>) -> Result<(), Error> {
|
||||
let has_palette = palette.is_some();
|
||||
|
||||
self.update_palette(palette);
|
||||
|
||||
let main_window = self.main_window.borrow();
|
||||
|
@ -37,7 +73,10 @@ impl FileTab {
|
|||
else {
|
||||
main_window.set_file_tab_image_name("".into());
|
||||
}
|
||||
|
||||
self.update_encoding_options(image_size.width, image_size.height, has_palette)?;
|
||||
main_window.set_file_tab_enable(true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_palette(&self, palette: Option<Image>) {
|
||||
|
|
|
@ -72,7 +72,7 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefC
|
|||
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_loaded_file(file_name, image, palette);
|
||||
return file_tab.update_new_loaded_file(file_name, image, palette);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -13,6 +13,7 @@ export component MainWindow inherits Window {
|
|||
callback move_vram_image <=> main_tab.move_vram_image;
|
||||
|
||||
// Convert Image values
|
||||
in-out property file_tab-encoding_options <=> file_tab.conv-encoding_options;
|
||||
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_width <=> file_tab.conv-image_width;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Button, TabWidget, LineEdit, GroupBox } from "std-widgets.slint";
|
||||
import { Button, TabWidget, LineEdit, GroupBox, ComboBox } from "std-widgets.slint";
|
||||
|
||||
export enum State {
|
||||
Project,
|
||||
|
@ -12,16 +12,17 @@ component ProjectWidget inherits Rectangle {
|
|||
}
|
||||
|
||||
component ConvertImageWidget inherits Rectangle {
|
||||
in-out property <string> image_path;
|
||||
in-out property <string> image_name;
|
||||
in-out property <image> image_data;
|
||||
in-out property <int> image-width;
|
||||
in-out property <int> image-height;
|
||||
in-out property <image> palette_data;
|
||||
in-out property <int> palette_width: 0;
|
||||
in-out property <int> palette_height: 0;
|
||||
in-out property <bool> enable_view: false;
|
||||
in-out property <bool> palette_visible: false;
|
||||
in-out property <[string]> encoding_options: [];
|
||||
in-out property <string> image_path;
|
||||
in-out property <string> image_name;
|
||||
in-out property <image> image_data;
|
||||
in-out property <int> image-width;
|
||||
in-out property <int> image-height;
|
||||
in-out property <image> palette_data;
|
||||
in-out property <int> palette_width: 0;
|
||||
in-out property <int> palette_height: 0;
|
||||
in-out property <bool> enable_view: false;
|
||||
in-out property <bool> palette_visible: false;
|
||||
|
||||
callback browse_clicked();
|
||||
callback add_clicked();
|
||||
|
@ -88,6 +89,13 @@ component ConvertImageWidget inherits Rectangle {
|
|||
text: "Height: " + root.image-height;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
ComboBox {
|
||||
model: root.encoding_options;
|
||||
enabled: root.enable_view;
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
// Fake padding because the padding setting for the HorizontalLayout would not work
|
||||
|
@ -188,16 +196,17 @@ component ConvertImageWidget inherits Rectangle {
|
|||
}
|
||||
|
||||
export component FileTab inherits Rectangle {
|
||||
in-out property <string> conv-image_path;
|
||||
in-out property <string> conv-image_name;
|
||||
in-out property <image> conv-image_data;
|
||||
in-out property <int> conv-image_width;
|
||||
in-out property <int> conv-image_height;
|
||||
in-out property <image> conv-palette_data;
|
||||
in-out property <int> conv-palette_width;
|
||||
in-out property <int> conv-palette_height;
|
||||
in-out property <bool> conv-palette_enable;
|
||||
in-out property <bool> conv-enable_view;
|
||||
in-out property <[string]> conv-encoding_options;
|
||||
in-out property <string> conv-image_path;
|
||||
in-out property <string> conv-image_name;
|
||||
in-out property <image> conv-image_data;
|
||||
in-out property <int> conv-image_width;
|
||||
in-out property <int> conv-image_height;
|
||||
in-out property <image> conv-palette_data;
|
||||
in-out property <int> conv-palette_width;
|
||||
in-out property <int> conv-palette_height;
|
||||
in-out property <bool> conv-palette_enable;
|
||||
in-out property <bool> conv-enable_view;
|
||||
|
||||
in-out property <State> state;
|
||||
callback conv-image_update_palette_size(int, int);
|
||||
|
@ -233,17 +242,19 @@ export component FileTab inherits Rectangle {
|
|||
alignment: start;
|
||||
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-width <=> root.conv-image_width;
|
||||
image-height <=> root.conv-image_height;
|
||||
palette_data <=> root.conv-palette_data;
|
||||
palette_width <=> root.conv-palette_width;
|
||||
palette_height <=> root.conv-palette_height;
|
||||
palette_visible <=> root.conv-palette_enable;
|
||||
image_name <=> root.conv-image_name;
|
||||
enable_view <=> root.conv-enable_view;
|
||||
encoding_options <=> root.conv-encoding_options;
|
||||
image_path <=> root.conv-image_path;
|
||||
image_data <=> root.conv-image_data;
|
||||
image-width <=> root.conv-image_width;
|
||||
image-height <=> root.conv-image_height;
|
||||
palette_data <=> root.conv-palette_data;
|
||||
palette_width <=> root.conv-palette_width;
|
||||
palette_height <=> root.conv-palette_height;
|
||||
palette_visible <=> root.conv-palette_enable;
|
||||
image_name <=> root.conv-image_name;
|
||||
enable_view <=> root.conv-enable_view;
|
||||
|
||||
update_palette_size(width, height) => {
|
||||
root.conv-image_update_palette_size(width, height);
|
||||
|
|
Loading…
Reference in New Issue