Creation of TIM Tool #15
|
@ -1,5 +1,6 @@
|
||||||
use crate::MainWindow;
|
use crate::MainWindow;
|
||||||
use super::{GUIElementsRef, MainWindowRef, main_tab::MainTab};
|
use super::{GUIElements, GUIElementsRef, MainWindowRef};
|
||||||
|
use slint::Image;
|
||||||
|
|
||||||
pub struct FileTab {
|
pub struct FileTab {
|
||||||
main_window: MainWindowRef
|
main_window: MainWindowRef
|
||||||
|
@ -10,12 +11,23 @@ impl FileTab {
|
||||||
FileTab{main_window}
|
FileTab{main_window}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_browse_file(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&MainWindow, &mut MainTab) + 'static) {
|
pub fn update_new_load(&self, file_name: Option<String>, image: Image) {
|
||||||
|
self.main_window.borrow().set_file_tab_image_data(image);
|
||||||
|
if let Some(file_name) = file_name {
|
||||||
|
self.main_window.borrow().set_file_tab_image_name(file_name.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
self.main_window.borrow().set_file_tab_image_name("".into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn on_browse_file(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow) + 'static) {
|
||||||
let main_window_cloned = self.main_window.clone();
|
let main_window_cloned = self.main_window.clone();
|
||||||
let gui_cloned = gui_elements.clone();
|
let gui_cloned = gui_elements.clone();
|
||||||
|
|
||||||
self.main_window.borrow().on_file_tab_browse_convert_image(move || {
|
self.main_window.borrow().on_file_tab_browse_convert_image(move || {
|
||||||
function(&main_window_cloned.borrow(), &mut gui_cloned.borrow_mut().main_tab);
|
function(&mut gui_cloned.borrow_mut(), &main_window_cloned.borrow());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,8 +2,7 @@ use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMImage};
|
||||||
use super::{GUIElementsRef, MainWindowRef};
|
use super::{GUIElementsRef, MainWindowRef};
|
||||||
|
|
||||||
use slint::Model;
|
use slint::Model;
|
||||||
use std::{ffi::OsStr, path::PathBuf, rc::Rc};
|
use std::rc::Rc;
|
||||||
use tool_helper::Error;
|
|
||||||
|
|
||||||
pub struct MainTab {
|
pub struct MainTab {
|
||||||
main_window: MainWindowRef,
|
main_window: MainWindowRef,
|
||||||
|
@ -23,22 +22,15 @@ impl MainTab {
|
||||||
MainTab{main_window, vram_file_list, vram_image_list}
|
MainTab{main_window, vram_file_list, vram_image_list}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_new_vram_file(&mut self, file: PathBuf) -> Result<(), Error> {
|
pub fn _add_new_vram_file(&mut self, file_name: String, image: slint::Image) {
|
||||||
let vram_image = VRAMImage{
|
let vram_image = VRAMImage{
|
||||||
img: slint::Image::load_from_path(&file).or_else(|_| {Err(Error::from_str("Failed loading image"))})?,
|
img: image,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
let img_size = vram_image.img.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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
let file_name = file.file_name().get_or_insert(OsStr::new("<No file name>")).to_string_lossy().to_string();
|
|
||||||
self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str()));
|
self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str()));
|
||||||
self.vram_image_list.push(vram_image);
|
self.vram_image_list.push(vram_image);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_vram_file(&mut self, idx: usize) {
|
pub fn remove_vram_file(&mut self, idx: usize) {
|
||||||
|
|
|
@ -1,3 +1 @@
|
||||||
pub fn hello_world() {
|
pub mod tim_tool;
|
||||||
println!("Hello Planschi");
|
|
||||||
}
|
|
|
@ -2,10 +2,11 @@
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
mod gui;
|
mod gui;
|
||||||
use gui::GUIElements;
|
use gui::{GUIElements, VRAM_WIDTH, VRAM_HEIGHT};
|
||||||
use rfd::{FileDialog, MessageDialog};
|
use rfd::{FileDialog, MessageDialog};
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
use slint::SharedString;
|
use slint::SharedString;
|
||||||
|
use tim_tool::tim_tool::load_image;
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
|
@ -37,7 +38,11 @@ fn setup_main_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
||||||
fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
||||||
let gui_elements = gui_elements_ref.borrow();
|
let gui_elements = gui_elements_ref.borrow();
|
||||||
|
|
||||||
gui_elements.file_tab.on_browse_file(gui_elements_ref.clone(), move |main_window, main_tab| {
|
gui_elements.file_tab.on_browse_file(gui_elements_ref.clone(), move |gui_elements, main_window| {
|
||||||
|
fn show_error_message(text: String) {
|
||||||
|
MessageDialog::new().set_title("Loading Image failed").set_level(rfd::MessageLevel::Error).set_description(text).show();
|
||||||
|
}
|
||||||
|
|
||||||
let file = FileDialog::new()
|
let file = FileDialog::new()
|
||||||
.add_filter("Images (.png; .bmp; .jpeg)", &["png", "bmp", "jpeg"])
|
.add_filter("Images (.png; .bmp; .jpeg)", &["png", "bmp", "jpeg"])
|
||||||
.set_title("Select image file")
|
.set_title("Select image file")
|
||||||
|
@ -48,10 +53,25 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
||||||
main_window.set_file_tab_browse_path(SharedString::from(file_path));
|
main_window.set_file_tab_browse_path(SharedString::from(file_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Result::Err(error) = main_tab.add_new_vram_file(file) {
|
let file_name = if let Some(name) = file.file_name() {Some(name.to_string_lossy().to_string())} else {None};
|
||||||
MessageDialog::new().set_title("Loading Image failed").set_level(rfd::MessageLevel::Error).set_description(error.to_string()).show();
|
let (image, _info) = match load_image(file) {
|
||||||
|
Ok((image, info)) => (image, info),
|
||||||
|
Err(error) => {
|
||||||
|
show_error_message(error.to_string());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
main_window.invoke_change_to_main();
|
};
|
||||||
|
|
||||||
|
let img_size = image.size();
|
||||||
|
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
|
||||||
|
show_error_message(format!("Image size ({}; {}) is to big for VRAM ({}, {})", img_size.width, img_size.height, VRAM_WIDTH, VRAM_HEIGHT));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let file_tab = &mut gui_elements.file_tab;
|
||||||
|
file_tab.update_new_load(file_name, image);
|
||||||
|
|
||||||
|
//main_window.invoke_change_to_main();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use tool_helper::Error;
|
||||||
|
|
||||||
|
pub struct TIMImage {}
|
||||||
|
|
||||||
|
pub fn load_image(path: PathBuf) -> Result<(slint::Image, TIMImage), Error> {
|
||||||
|
Ok((slint::Image::load_from_path(&path).or_else(|_| {Err(Error::from_str("Failed loading image"))})?, TIMImage{}))
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ 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_image_name <=> file_tab.conv_image_name;
|
||||||
callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked;
|
callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked;
|
||||||
|
|
||||||
title: "TIM Tool 0.1.0";
|
title: "TIM Tool 0.1.0";
|
||||||
|
|
|
@ -14,6 +14,7 @@ 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 <string> image_name;
|
||||||
|
|
||||||
callback browse_clicked();
|
callback browse_clicked();
|
||||||
|
|
||||||
|
@ -65,16 +66,20 @@ component ConvertImageWidget inherits Rectangle {
|
||||||
}
|
}
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
alignment: start;
|
alignment: start;
|
||||||
|
padding: 4px;
|
||||||
VerticalLayout {
|
VerticalLayout {
|
||||||
alignment: center;
|
alignment: center;
|
||||||
Text {
|
Text {
|
||||||
text: "Name: ";
|
text: "Name: ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LineEdit {}
|
LineEdit {
|
||||||
|
text: root.image_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
alignment: start;
|
alignment: start;
|
||||||
|
padding: 4px;
|
||||||
Button {
|
Button {
|
||||||
text: "Add Image";
|
text: "Add Image";
|
||||||
enabled: false;
|
enabled: false;
|
||||||
|
@ -88,6 +93,7 @@ component ConvertImageWidget inherits Rectangle {
|
||||||
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 <string> conv_image_name;
|
||||||
in-out property <State> state;
|
in-out property <State> state;
|
||||||
callback conv_image_browse_clicked;
|
callback conv_image_browse_clicked;
|
||||||
|
|
||||||
|
@ -123,6 +129,7 @@ export component FileTab inherits Rectangle {
|
||||||
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;
|
||||||
browse_clicked => {
|
browse_clicked => {
|
||||||
root.conv_image_browse_clicked();
|
root.conv_image_browse_clicked();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue