Compare commits
No commits in common. "6fa574c921ee195b66a17455c0cebd5a6c94d582" and "b35967d6dc97da861d65884be3f40f3b101b3070" have entirely different histories.
6fa574c921
...
b35967d6dc
|
@ -1,6 +1,5 @@
|
|||
use crate::MainWindow;
|
||||
use super::{GUIElements, GUIElementsRef, MainWindowRef};
|
||||
use slint::Image;
|
||||
use super::MainWindowRef;
|
||||
|
||||
pub struct FileTab {
|
||||
main_window: MainWindowRef
|
||||
|
@ -11,48 +10,10 @@ impl FileTab {
|
|||
FileTab{main_window}
|
||||
}
|
||||
|
||||
pub fn clear_load(&self) {
|
||||
let main_window = self.main_window.borrow();
|
||||
|
||||
main_window.set_file_tab_browse_path("".into());
|
||||
main_window.set_file_tab_image_data(Image::default());
|
||||
main_window.set_file_tab_image_name("".into());
|
||||
main_window.set_file_tab_enable(false);
|
||||
}
|
||||
|
||||
pub fn update_new_load(&self, file_name: Option<String>, image: Image) {
|
||||
let main_window = self.main_window.borrow();
|
||||
|
||||
main_window.set_file_tab_image_data(image);
|
||||
if let Some(file_name) = file_name {
|
||||
main_window.set_file_tab_image_name(file_name.into());
|
||||
}
|
||||
|
||||
else {
|
||||
main_window.set_file_tab_image_name("".into());
|
||||
}
|
||||
main_window.set_file_tab_enable(true);
|
||||
}
|
||||
|
||||
pub fn get_file_name(&self) -> String {
|
||||
self.main_window.borrow().get_file_tab_image_name().to_string()
|
||||
}
|
||||
|
||||
pub fn on_browse_file(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow) + 'static) {
|
||||
pub fn on_browse_file(&self, mut function: impl FnMut(&MainWindow) + 'static) {
|
||||
let main_window_cloned = self.main_window.clone();
|
||||
let gui_cloned = gui_elements.clone();
|
||||
|
||||
self.main_window.borrow().on_file_tab_browse_convert_image(move || {
|
||||
function(&mut gui_cloned.borrow_mut(), &main_window_cloned.borrow());
|
||||
});
|
||||
}
|
||||
|
||||
pub fn on_add_image(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow) + 'static) {
|
||||
let main_window_cloned = self.main_window.clone();
|
||||
let gui_cloned = gui_elements.clone();
|
||||
|
||||
self.main_window.borrow().on_file_tab_add_convert_image(move || {
|
||||
function(&mut gui_cloned.borrow_mut(), &main_window_cloned.borrow());
|
||||
function(&main_window_cloned.borrow());
|
||||
});
|
||||
}
|
||||
}
|
|
@ -2,7 +2,8 @@ use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMImage};
|
|||
use super::{GUIElementsRef, MainWindowRef};
|
||||
|
||||
use slint::Model;
|
||||
use std::rc::Rc;
|
||||
use std::{ffi::OsStr, path::PathBuf, rc::Rc};
|
||||
use tool_helper::Error;
|
||||
|
||||
pub struct MainTab {
|
||||
main_window: MainWindowRef,
|
||||
|
@ -22,15 +23,22 @@ impl MainTab {
|
|||
MainTab{main_window, vram_file_list, vram_image_list}
|
||||
}
|
||||
|
||||
pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image) {
|
||||
pub fn add_new_vram_file(&mut self, file: PathBuf) -> Result<(), Error> {
|
||||
let vram_image = VRAMImage{
|
||||
img: image,
|
||||
img: slint::Image::load_from_path(&file).or_else(|_| {Err(Error::from_str("Failed loading image"))})?,
|
||||
x: 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_image_list.push(vram_image);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_vram_file(&mut self, idx: usize) {
|
||||
|
@ -79,4 +87,12 @@ impl MainTab {
|
|||
function(&mut gui_cloned.borrow_mut().main_tab, &main_window_cloned.borrow(), idx);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn on_add_file(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut MainTab, &MainWindow) + 'static) {
|
||||
let main_window_cloned = self.main_window.clone();
|
||||
let gui_cloned = gui_elements.clone();
|
||||
self.main_window.borrow().on_main_tab_add_file_clicked(move || {
|
||||
function(&mut gui_cloned.borrow_mut().main_tab, &main_window_cloned.borrow());
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1 +1,3 @@
|
|||
pub mod logic;
|
||||
pub fn hello_world() {
|
||||
println!("Hello Planschi");
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
pub mod tim;
|
||||
use slint::Image;
|
||||
use tim::TIMInfo;
|
||||
|
||||
pub struct Logic {
|
||||
unadded_tim: UnaddedTIM,
|
||||
}
|
||||
|
||||
impl Logic {
|
||||
pub fn new() -> Logic {
|
||||
Logic{unadded_tim: UnaddedTIM::empty()}
|
||||
}
|
||||
|
||||
pub fn set_unadded_tim(&mut self, info: TIMInfo, image: Image) {
|
||||
self.unadded_tim = UnaddedTIM::new(info, image);
|
||||
}
|
||||
|
||||
pub fn add_unadded_tim_as(&mut self, _name: &String) -> Image {
|
||||
let _info = self.unadded_tim.take_info();
|
||||
self.unadded_tim.take_image()
|
||||
}
|
||||
}
|
||||
|
||||
struct UnaddedTIM {
|
||||
info: TIMInfo,
|
||||
image: Image,
|
||||
}
|
||||
|
||||
impl UnaddedTIM {
|
||||
pub fn new(info: TIMInfo, image: Image) -> UnaddedTIM {
|
||||
UnaddedTIM{info, image}
|
||||
}
|
||||
|
||||
pub fn take_info(&mut self) -> TIMInfo {
|
||||
std::mem::take(&mut self.info)
|
||||
}
|
||||
|
||||
pub fn take_image(&mut self) -> Image {
|
||||
std::mem::take(&mut self.image)
|
||||
}
|
||||
|
||||
fn empty() -> UnaddedTIM {
|
||||
UnaddedTIM{info: TIMInfo{}, image: Image::default()}
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
use std::path::PathBuf;
|
||||
use tool_helper::Error;
|
||||
|
||||
pub struct TIMInfo {}
|
||||
|
||||
impl std::default::Default for TIMInfo {
|
||||
fn default() -> Self {
|
||||
TIMInfo{}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_image(path: PathBuf) -> Result<(slint::Image, TIMInfo), Error> {
|
||||
Ok((slint::Image::load_from_path(&path).or_else(|_| {Err(Error::from_str("Failed loading image"))})?, TIMInfo{}))
|
||||
}
|
|
@ -2,22 +2,19 @@
|
|||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod gui;
|
||||
use gui::{GUIElements, VRAM_WIDTH, VRAM_HEIGHT};
|
||||
use gui::GUIElements;
|
||||
use rfd::{FileDialog, MessageDialog};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use slint::SharedString;
|
||||
use tim_tool::logic::{tim::load_image, Logic};
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
|
||||
fn main() -> Result<(), slint::PlatformError> {
|
||||
let logic_ref = Rc::new(RefCell::new(Logic::new()));
|
||||
let main_window_ref = Rc::new(RefCell::new(MainWindow::new()?));
|
||||
let gui_elements_ref = Rc::new(RefCell::new(GUIElements::new(main_window_ref.clone())?));
|
||||
|
||||
setup_main_tab(gui_elements_ref.clone());
|
||||
setup_file_tab(gui_elements_ref.clone(), logic_ref);
|
||||
setup_file_tab(gui_elements_ref.clone());
|
||||
|
||||
let main_window = main_window_ref.borrow();
|
||||
main_window.run()
|
||||
|
@ -35,19 +32,29 @@ fn setup_main_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
|||
main_tab.remove_vram_file(idx as usize);
|
||||
}
|
||||
});
|
||||
|
||||
gui_elements.main_tab.on_add_file(gui_elements_ref.clone(), move |main_tab, _main_window| {
|
||||
let file = FileDialog::new()
|
||||
.add_filter("Images", &["png", "bmp", "jpeg"])
|
||||
.add_filter("All", &[""])
|
||||
.set_title("Add TIM image")
|
||||
.pick_file();
|
||||
|
||||
if let Some(file) = file {
|
||||
if let Result::Err(error) = main_tab.add_new_vram_file(file) {
|
||||
MessageDialog::new().set_title("Loading Image failed").set_level(rfd::MessageLevel::Error).set_description(error.to_string()).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefCell<Logic>>) {
|
||||
fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>) {
|
||||
let gui_elements = gui_elements_ref.borrow();
|
||||
|
||||
let logic = logic_ref.clone();
|
||||
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()
|
||||
.add_filter("Images (.png; .bmp; .jpeg)", &["png", "bmp", "jpeg"])
|
||||
gui_elements.file_tab.on_browse_file(move |main_window| {
|
||||
let file = FileDialog::new()
|
||||
.add_filter("Images", &["png", "bmp", "jpeg"])
|
||||
.add_filter("All", &[""])
|
||||
.set_title("Select image file")
|
||||
.pick_file();
|
||||
|
||||
|
@ -55,40 +62,6 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefC
|
|||
if let Some(file_path) = file.to_str() {
|
||||
main_window.set_file_tab_browse_path(SharedString::from(file_path));
|
||||
}
|
||||
|
||||
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, info) = match load_image(file) {
|
||||
Ok((image, info)) => (image, info),
|
||||
Err(error) => {
|
||||
file_tab.clear_load();
|
||||
show_error_message(error.to_string());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let img_size = image.size();
|
||||
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
|
||||
file_tab.clear_load();
|
||||
show_error_message(format!("Image size ({}; {}) is to big for VRAM ({}, {})", img_size.width, img_size.height, VRAM_WIDTH, VRAM_HEIGHT));
|
||||
return;
|
||||
}
|
||||
|
||||
logic.borrow_mut().set_unadded_tim(info, image.clone());
|
||||
file_tab.update_new_load(file_name, image);
|
||||
}
|
||||
});
|
||||
|
||||
let logic = logic_ref.clone();
|
||||
gui_elements.file_tab.on_add_image(gui_elements_ref.clone(), move |gui_elements, main_window| {
|
||||
let main_tab = &mut gui_elements.main_tab;
|
||||
let file_tab = &gui_elements.file_tab;
|
||||
|
||||
let file_name = file_tab.get_file_name();
|
||||
main_tab.add_new_vram_file(&file_name, logic.borrow_mut().add_unadded_tim_as(&file_name));
|
||||
|
||||
file_tab.clear_load();
|
||||
main_window.invoke_change_to_main();
|
||||
});
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import { AboutTab } from "./tab/about-tab.slint";
|
||||
import { FileTab, State } from "./tab/file-tab.slint";
|
||||
import { FileTab } from "./tab/file-tab.slint";
|
||||
import { MainTab } from "./tab/main-tab.slint";
|
||||
import { TabWidget } from "std-widgets.slint";
|
||||
|
||||
|
@ -9,16 +9,13 @@ export component MainWindow inherits Window {
|
|||
in-out property main_tab_vram_file_list <=> main_tab.vram_files;
|
||||
in-out property main_tab_vram_images <=> main_tab.vram_images;
|
||||
|
||||
callback main_tab_add_file_clicked <=> main_tab.add_file_clicked;
|
||||
callback main_tab_remove_file_clicked <=> main_tab.remove_file_clicked;
|
||||
callback move_vram_image <=> main_tab.move_vram_image;
|
||||
|
||||
// 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_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;
|
||||
callback file_tab_add_convert_image <=> file_tab.conv_image_add_clicked;
|
||||
|
||||
title: "TIM Tool 0.1.0";
|
||||
width: tab_widget.width;
|
||||
|
@ -43,7 +40,6 @@ export component MainWindow inherits Window {
|
|||
main_tab := MainTab {
|
||||
x: 0px;
|
||||
y: 0px;
|
||||
add_file_clicked => {root.change_to_load_file()}
|
||||
}
|
||||
}
|
||||
Tab {
|
||||
|
@ -51,13 +47,4 @@ export component MainWindow inherits Window {
|
|||
AboutTab {}
|
||||
}
|
||||
}
|
||||
|
||||
public function change_to_load_file() {
|
||||
file_tab.state = State.ConvertImage;
|
||||
tab_widget.current-index = 0;
|
||||
}
|
||||
|
||||
public function change_to_main() {
|
||||
tab_widget.current-index = 1;
|
||||
}
|
||||
}
|
|
@ -1,107 +1,59 @@
|
|||
import { Button, TabWidget, LineEdit, GroupBox } from "std-widgets.slint";
|
||||
|
||||
export enum State {
|
||||
Project,
|
||||
enum State {
|
||||
ConvertImage,
|
||||
Test
|
||||
}
|
||||
|
||||
component ProjectWidget inherits Rectangle {
|
||||
component ConvertImageWidget inherits Rectangle {
|
||||
in-out property <string> path;
|
||||
|
||||
callback browse_clicked();
|
||||
|
||||
background: #D0D0D0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
GroupBox {
|
||||
title: "Convert image to TIM";
|
||||
x: 4px;
|
||||
y: 4px;
|
||||
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
Text {
|
||||
text: "Select image file to convert to TIM";
|
||||
}
|
||||
LineEdit {
|
||||
width: 200%;
|
||||
text: path;
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
Button {
|
||||
text: "Browse";
|
||||
clicked => {browse_clicked();}
|
||||
}
|
||||
Button {
|
||||
text: "Convert";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component TestWidget inherits Rectangle {
|
||||
Text {
|
||||
text: "!!Planschbecken!!";
|
||||
}
|
||||
}
|
||||
|
||||
component ConvertImageWidget inherits Rectangle {
|
||||
in-out property <string> image_path;
|
||||
in-out property <image> image_data;
|
||||
in-out property <string> image_name;
|
||||
in-out property <bool> enable_button: false;
|
||||
|
||||
callback browse_clicked();
|
||||
callback add_clicked();
|
||||
|
||||
background: #D0D0D0;
|
||||
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
GroupBox {
|
||||
title: "Add image file";
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
Text {
|
||||
text: "Select image file to convert to be used with TIM Tool";
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
LineEdit {
|
||||
width: 300pt;
|
||||
text: image_path;
|
||||
}
|
||||
Button {
|
||||
text: "Browse";
|
||||
clicked => {browse_clicked();}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GroupBox {
|
||||
title: "Loaded image";
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
Rectangle {
|
||||
width: 256px;
|
||||
height: 256px;
|
||||
background: #000000;
|
||||
Image {
|
||||
width: 256px;
|
||||
height: 256px;
|
||||
source: root.image_data;
|
||||
image-fit: contain;
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Text {
|
||||
text: "Name: ";
|
||||
}
|
||||
}
|
||||
LineEdit {
|
||||
text: root.image_name;
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
Button {
|
||||
text: "Add Image";
|
||||
enabled: root.enable_button;
|
||||
clicked => {root.add_clicked();}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component FileTab inherits Rectangle {
|
||||
in-out property <string> conv_image_path;
|
||||
in-out property <image> conv_image_data;
|
||||
in-out property <string> conv_image_name;
|
||||
in-out property <bool> conv_image_enable;
|
||||
in-out property <State> state;
|
||||
callback conv_image_browse_clicked;
|
||||
callback conv_image_add_clicked;
|
||||
|
||||
property <State> state: ConvertImage;
|
||||
x: 0px;
|
||||
y: 0px;
|
||||
|
||||
|
@ -113,15 +65,15 @@ export component FileTab inherits Rectangle {
|
|||
alignment: start;
|
||||
|
||||
Button {
|
||||
text: "Projects";
|
||||
text: "Convert image file";
|
||||
clicked => {
|
||||
root.state = State.Project;
|
||||
root.state = State.ConvertImage;
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: "Add Image";
|
||||
text: "Testing";
|
||||
clicked => {
|
||||
root.state = State.ConvertImage;
|
||||
root.state = State.Test;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,21 +81,13 @@ export component FileTab inherits Rectangle {
|
|||
VerticalLayout {
|
||||
padding: 4px;
|
||||
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_name <=> root.conv_image_name;
|
||||
enable_button <=> root.conv_image_enable;
|
||||
|
||||
path <=> root.conv_image_path;
|
||||
browse_clicked => {
|
||||
root.conv_image_browse_clicked();
|
||||
}
|
||||
|
||||
add_clicked => {
|
||||
root.conv_image_add_clicked();
|
||||
}
|
||||
}
|
||||
if root.state == State.Test : TestWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ export component MainTab inherits Rectangle {
|
|||
HorizontalLayout {
|
||||
padding: 4px;
|
||||
GroupBox {
|
||||
title: "Added files";
|
||||
title: "Added TIMs";
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
|
@ -103,11 +103,11 @@ export component MainTab inherits Rectangle {
|
|||
HorizontalLayout {
|
||||
padding: 4px;
|
||||
Button {
|
||||
text: "Add file";
|
||||
text: "Add TIM";
|
||||
clicked => {root.add_file_clicked();}
|
||||
}
|
||||
Button {
|
||||
text: "Remove file";
|
||||
text: "Remove TIM";
|
||||
clicked => {
|
||||
root.remove_file_clicked(vram_files_list.current_item);
|
||||
vram_files_list.current-item = -1;
|
||||
|
|
Loading…
Reference in New Issue