Merge pull request 'topic/bg/project-gui' (#21) from topic/bg/project-gui into main
Reviewed-on: #21 Reviewed-by: cody <william@werl.me>
This commit is contained in:
commit
5ccf593963
|
@ -0,0 +1,84 @@
|
|||
use crate::{gui::{main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow};
|
||||
use super::FileTab;
|
||||
use rfd::FileDialog;
|
||||
use slint::SharedString;
|
||||
use tim_tool::logic::tim::types::Encoding;
|
||||
use tool_helper::Error;
|
||||
|
||||
pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
return move |file_tab, main_window| -> Result<(), Error> {
|
||||
let file = FileDialog::new()
|
||||
.add_filter("PNG image (.png)", &["png"])
|
||||
.set_title("PNG image file")
|
||||
.pick_file();
|
||||
|
||||
if let Some(file) = file {
|
||||
if let Some(file_path) = file.to_str() {
|
||||
main_window.set_file_tab_browse_path(SharedString::from(file_path));
|
||||
}
|
||||
|
||||
let file_name = if let Some(name) = file.file_name() {Some(name.to_string_lossy().to_string())} else {None};
|
||||
|
||||
let (image, palette) = tim_manager.lock().expect("VRAM already locked").load_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)));
|
||||
}
|
||||
return file_tab.update_new_loaded_file(file_name, image, palette);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
|
||||
pub(super) fn on_update_palette_size(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow, u32, u32) -> Result<(), Error> + 'static {
|
||||
return move |file_tab, _main_window, width, height| -> Result<(), Error> {
|
||||
file_tab.update_palette(tim_manager.lock().expect("VRAM already locked").change_unadded_tim_palette_size(width, height)?);
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
|
||||
pub(super) fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &mut MainTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
return move |file_tab, main_tab, main_window| {
|
||||
let file_name = file_tab.get_file_name();
|
||||
let encoding = file_tab.get_encoding()?;
|
||||
let mut tim_mgr = tim_manager.lock().expect("VRAM already locked");
|
||||
let (image, palette_image) = tim_mgr.get_converted_unadded_tim_image(encoding)?;
|
||||
let (full_image, _) = tim_mgr.get_converted_unadded_tim_image(Encoding::FullColor)?;
|
||||
|
||||
let images_created = main_tab.add_new_vram_file(&file_name, full_image, image, encoding, palette_image);
|
||||
if let Err(error) = tim_mgr.add_unadded_tim(images_created) {
|
||||
main_tab.pop_vram_files(images_created);
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
file_tab.clear_load();
|
||||
main_window.invoke_change_to_main();
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
|
||||
pub(super) fn on_load_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_load_project_clicked"))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_save_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_save_project_clicked"))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_browse_open_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_browse_open_project_clicked"))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn on_browse_save_project_clicked() -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, _main_window| {
|
||||
Err(Error::not_implemented("on_browse_save_project_clicked"))
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
use crate::MainWindow;
|
||||
use super::{GUIElements, GUIElementsRef, MainWindowRef, display_error};
|
||||
mod callbacks;
|
||||
|
||||
use crate::gui::MutexTIMManager;
|
||||
use super::{main_tab::SharedMainTab, MainWindowRef, display_error};
|
||||
use slint::{Image, SharedString};
|
||||
use std::rc::Rc;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use tim_tool::logic::tim::types::Encoding;
|
||||
use tool_helper::Error;
|
||||
|
||||
|
@ -10,6 +12,8 @@ pub struct FileTab {
|
|||
encoding_options: Rc<slint::VecModel<SharedString>>
|
||||
}
|
||||
|
||||
pub type SharedFileTab = Rc<RefCell<FileTab>>;
|
||||
|
||||
impl FileTab {
|
||||
fn update_encoding_options(&self, width: u32, height: u32, has_palette: bool) -> Result<&str, Error> {
|
||||
self.encoding_options.clear();
|
||||
|
@ -40,11 +44,64 @@ impl FileTab {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new(main_window: MainWindowRef) -> FileTab {
|
||||
pub fn new(main_window: MainWindowRef, main_tab: SharedMainTab, tim_manager: MutexTIMManager) -> SharedFileTab {
|
||||
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}
|
||||
|
||||
let object = Rc::new(RefCell::new(FileTab{main_window: main_window.clone(), encoding_options}));
|
||||
|
||||
// Image conv functions
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_browse_file(tim_manager.clone()));
|
||||
main_window.borrow().on_file_tab_browse_convert_image(move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Loading file failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_update_palette_size(tim_manager.clone()));
|
||||
main_window.borrow().on_file_tab_update_palette_size(move |width, height| {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow(), width as u32, height as u32) {
|
||||
display_error("Updating palette failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_add_image(tim_manager.clone()));
|
||||
main_window.borrow().on_file_tab_add_convert_image(move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &mut main_tab.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Adding file failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
// Project functions
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_load_project_clicked());
|
||||
main_window.borrow().on_project_widget_load_project_clicked(move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Loading project failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_save_project_clicked());
|
||||
main_window.borrow().on_project_widget_save_project_clicked (move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Saving project failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_browse_open_project_clicked());
|
||||
main_window.borrow().on_project_widget_browse_open_project_clicked (move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Browsing project failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_browse_save_project_clicked());
|
||||
main_window.borrow().on_project_widget_browse_save_project_clicked(move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow()) {
|
||||
display_error("Browsing save location failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
|
||||
object
|
||||
}
|
||||
|
||||
pub fn clear_load(&self) {
|
||||
|
@ -128,35 +185,4 @@ impl FileTab {
|
|||
Err(Error::from_str("Failed to obtain encoding"))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_browse_file(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow) -> Result<(), Error> + '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 || {
|
||||
if let Err(error) = function(&mut gui_cloned.borrow_mut(), &main_window_cloned.borrow()) {
|
||||
display_error("Loadind file failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn on_update_palette_size(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow, u32, u32) -> Result<(), Error> + 'static) {
|
||||
let main_window_cloned = self.main_window.clone();
|
||||
|
||||
self.main_window.borrow().on_file_tab_update_palette_size(move |width, height| {
|
||||
if let Err(error) = function(&mut gui_elements.borrow_mut(), &main_window_cloned.borrow(), width as u32, height as u32) {
|
||||
display_error("Loadind file failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn on_add_image(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow) -> Result<(), Error> + 'static) {
|
||||
let main_window_cloned = self.main_window.clone();
|
||||
|
||||
self.main_window.borrow().on_file_tab_add_convert_image(move || {
|
||||
if let Err(error) = function(&mut gui_elements.borrow_mut(), &main_window_cloned.borrow()) {
|
||||
display_error("Adding file failed", &error.to_string());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
use super::create_vram_bg;
|
||||
|
||||
use super::MainWindowRef;
|
||||
use super::{file_tab::FileTab, main_tab::MainTab};
|
||||
|
||||
pub struct GUIElements {
|
||||
pub file_tab: FileTab,
|
||||
pub main_tab: MainTab,
|
||||
}
|
||||
|
||||
impl GUIElements {
|
||||
pub fn new(main_window: MainWindowRef) -> Result<GUIElements, slint::PlatformError> {
|
||||
main_window.borrow().set_main_tab_vram_bg(GUIElements::create_bg()?);
|
||||
Ok(GUIElements{file_tab: FileTab::new(main_window.clone()), main_tab: MainTab::new(main_window.clone())})
|
||||
}
|
||||
|
||||
fn create_bg() -> Result<slint::Image, slint::PlatformError> {
|
||||
Ok(slint::Image::from_rgba8_premultiplied(create_vram_bg(320, 256).ok_or(slint::PlatformError::Other("Failed creating VRAM background image".to_string()))?))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
use crate::{gui::MutexTIMManager, MainWindow, display_information};
|
||||
use super::MainTab;
|
||||
|
||||
pub fn on_move_vram_image() -> impl FnMut(&mut MainTab, &MainWindow, i32, i32, i32) + 'static {
|
||||
return move |main_tab, _main_window, idx, dx, dy| {
|
||||
main_tab.move_vram_image(idx as usize, dx, dy);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_remove_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut MainTab, &MainWindow, i32) + 'static {
|
||||
return move |main_tab, _main_window, idx| {
|
||||
if idx >= 0 {
|
||||
match main_tab.remove_vram_file(idx as usize) {
|
||||
Ok(range) => tim_manager.lock().expect("VRAM already locked").remove_added_tim(range),
|
||||
Err(error) => display_information("Removing VRAM file", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMImage};
|
||||
use super::{GUIElementsRef, MainWindowRef};
|
||||
mod callbacks;
|
||||
|
||||
use crate::{gui::{MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, VRAMImage};
|
||||
use super::MainWindowRef;
|
||||
use slint::{Model, SharedString};
|
||||
use std::{cell::RefCell, ops::RangeInclusive, rc::Rc, sync::{Arc, Mutex}};
|
||||
use tim_tool::logic::tim::types::Encoding;
|
||||
use std::{ops::RangeInclusive, rc::Rc, sync::{Arc, Mutex}};
|
||||
|
||||
struct VRAM {
|
||||
count: usize,
|
||||
|
@ -30,12 +31,13 @@ impl VRAM {
|
|||
}
|
||||
|
||||
pub struct MainTab {
|
||||
main_window: MainWindowRef,
|
||||
vram: Arc<Mutex<VRAM>>,
|
||||
vram: Arc<Mutex<VRAM>>,
|
||||
}
|
||||
|
||||
pub type SharedMainTab = Rc<RefCell<MainTab>>;
|
||||
|
||||
impl MainTab {
|
||||
pub fn new(main_window: MainWindowRef) -> MainTab {
|
||||
pub fn new(main_window: MainWindowRef, tim_manager: MutexTIMManager) -> SharedMainTab {
|
||||
let vram_file_list:Vec<slint::StandardListViewItem> = main_window.borrow().get_main_tab_vram_file_list().iter().collect();
|
||||
let vram_file_list = Rc::new(slint::VecModel::from(vram_file_list));
|
||||
let vram_image_list = Rc::new(slint::VecModel::from(Vec::<VRAMImage>::new()));
|
||||
|
@ -43,7 +45,18 @@ impl MainTab {
|
|||
main_window.borrow().set_main_tab_vram_file_list(vram_file_list.clone().into());
|
||||
main_window.borrow().set_main_tab_vram_images(vram_image_list.clone().into());
|
||||
|
||||
MainTab{main_window, vram: Arc::new(Mutex::new(VRAM{count: 0, file_list: vram_file_list, image_list: vram_image_list}))}
|
||||
let object = SharedMainTab::new(MainTab{vram: Arc::new(Mutex::new(VRAM{count: 0, file_list: vram_file_list, image_list: vram_image_list}))}.into());
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_move_vram_image());
|
||||
main_window.borrow().on_move_vram_image(move |idx, dx, dy| {
|
||||
function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow(), idx, dx, dy);
|
||||
});
|
||||
|
||||
let (cloned_object, cloned_main_window, mut function) = (object.clone(), main_window.clone(), callbacks::on_remove_file(tim_manager));
|
||||
main_window.borrow().on_main_tab_remove_file_clicked(move |idx| {
|
||||
function(&mut cloned_object.borrow_mut(), &cloned_main_window.borrow(), idx);
|
||||
});
|
||||
object
|
||||
}
|
||||
|
||||
pub fn add_new_vram_file(&mut self, file_name: &String, full_image: slint::Image, image: slint::Image, encoding: Encoding, image_palette: Option<slint::Image>) -> usize {
|
||||
|
@ -137,20 +150,4 @@ impl MainTab {
|
|||
vram_data.image_list.set_row_data(idx, vram_info);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn on_move_vram_image(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut MainTab, &MainWindow, i32, i32, i32) + 'static) {
|
||||
let main_window_cloned = self.main_window.clone();
|
||||
|
||||
self.main_window.borrow().on_move_vram_image(move |idx, dx, dy| {
|
||||
function(&mut gui_elements.borrow_mut().main_tab, &main_window_cloned.borrow(), idx, dx, dy);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn on_remove_file(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut MainTab, &MainWindow, i32) + 'static) {
|
||||
let main_window_cloned = self.main_window.clone();
|
||||
|
||||
self.main_window.borrow().on_main_tab_remove_file_clicked(move |idx| {
|
||||
function(&mut gui_elements.borrow_mut().main_tab, &main_window_cloned.borrow(), idx);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,20 +1,42 @@
|
|||
mod file_tab;
|
||||
mod gui_elements;
|
||||
mod main_tab;
|
||||
|
||||
use crate::MainWindow;
|
||||
use file_tab::{FileTab, SharedFileTab};
|
||||
use main_tab::{MainTab, SharedMainTab};
|
||||
use rfd::MessageDialog;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use std::{cell::RefCell, rc::Rc, sync::Mutex};
|
||||
use slint::{Rgba8Pixel, SharedPixelBuffer};
|
||||
use tim_tool::logic::TIMManager;
|
||||
use tiny_skia::{Rect, Transform};
|
||||
|
||||
pub use gui_elements::GUIElements;
|
||||
type MainWindowRef = Rc<RefCell<MainWindow>>;
|
||||
|
||||
pub type MutexTIMManager = Rc<Mutex<TIMManager>>;
|
||||
|
||||
pub const VRAM_WIDTH:usize = 1024;
|
||||
pub const VRAM_HEIGHT:usize = 512;
|
||||
|
||||
type MainWindowRef = Rc<RefCell<MainWindow>>;
|
||||
type GUIElementsRef = Rc<RefCell<GUIElements>>;
|
||||
pub struct GUIElements {
|
||||
_file_tab: SharedFileTab,
|
||||
_main_tab: SharedMainTab,
|
||||
}
|
||||
|
||||
impl GUIElements {
|
||||
pub fn new(main_window: MainWindowRef, tim_manager: MutexTIMManager) -> Result<GUIElements, slint::PlatformError> {
|
||||
main_window.borrow().set_main_tab_vram_bg(GUIElements::create_bg()?);
|
||||
|
||||
let _main_tab = MainTab::new(main_window.clone(), tim_manager.clone());
|
||||
let _file_tab = FileTab::new(main_window.clone(), _main_tab.clone(), tim_manager);
|
||||
|
||||
Ok(GUIElements{_file_tab, _main_tab})
|
||||
}
|
||||
|
||||
fn create_bg() -> Result<slint::Image, slint::PlatformError> {
|
||||
Ok(slint::Image::from_rgba8_premultiplied(create_vram_bg(320, 256).ok_or(slint::PlatformError::Other("Failed creating VRAM background image".to_string()))?))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn display_information(title: impl Into<String>, text: impl Into<String>) {
|
||||
MessageDialog::new().set_title(title).set_level(rfd::MessageLevel::Info).set_description(text).show();
|
||||
|
|
|
@ -2,34 +2,32 @@
|
|||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod gui;
|
||||
use gui::{GUIElements, VRAM_WIDTH, VRAM_HEIGHT, display_information};
|
||||
use rfd::FileDialog;
|
||||
use gui::{GUIElements, display_information};
|
||||
use std::{cell::RefCell, rc::Rc, sync::Mutex};
|
||||
use slint::SharedString;
|
||||
use tim_tool::logic::{tim::types::Encoding, TIMManager};
|
||||
use tool_helper::Error;
|
||||
use tim_tool::logic::TIMManager;
|
||||
|
||||
slint::include_modules!();
|
||||
|
||||
struct Application {
|
||||
main_window: Rc<RefCell<MainWindow>>,
|
||||
gui_elements: Rc<RefCell<GUIElements>>,
|
||||
tim_manager: Rc<Mutex<TIMManager>>,
|
||||
_gui_elements: Rc<RefCell<GUIElements>>,
|
||||
_tim_manager: Rc<Mutex<TIMManager>>,
|
||||
}
|
||||
|
||||
impl Application {
|
||||
fn new() -> Result<Application, slint::PlatformError> {
|
||||
let main_window = Rc::new(RefCell::new(MainWindow::new()?));
|
||||
let _tim_manager = Rc::new(Mutex::new(TIMManager::new()));
|
||||
|
||||
Ok(Application{
|
||||
main_window: main_window.clone(),
|
||||
gui_elements: Rc::new(RefCell::new(GUIElements::new(main_window.clone())?)),
|
||||
tim_manager: Rc::new(Mutex::new(TIMManager::new()))
|
||||
_gui_elements: Rc::new(RefCell::new(GUIElements::new(main_window.clone(), _tim_manager.clone())?)),
|
||||
_tim_manager,
|
||||
})
|
||||
}
|
||||
|
||||
fn setup(&self) {
|
||||
self.setup_main_tab();
|
||||
self.setup_file_tab();
|
||||
self.setup_about_tab();
|
||||
}
|
||||
|
||||
|
@ -38,81 +36,6 @@ impl Application {
|
|||
main_window.run()
|
||||
}
|
||||
|
||||
fn setup_main_tab(&self) {
|
||||
self.gui_elements.borrow().main_tab.on_move_vram_image(self.gui_elements.clone(), move |main_tab, _main_window, idx, dx, dy| {
|
||||
main_tab.move_vram_image(idx as usize, dx, dy);
|
||||
});
|
||||
|
||||
let tim_manager = self.tim_manager.clone();
|
||||
self.gui_elements.borrow().main_tab.on_remove_file(self.gui_elements.clone(), move |main_tab, _main_window, idx| {
|
||||
if idx >= 0 {
|
||||
match main_tab.remove_vram_file(idx as usize) {
|
||||
Ok(range) => tim_manager.lock().expect("VRAM already locked").remove_added_tim(range),
|
||||
Err(error) => display_information("Removing VRAM file", error)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn setup_file_tab(&self) {
|
||||
let tim_manager = self.tim_manager.clone();
|
||||
self.gui_elements.borrow().file_tab.on_update_palette_size(self.gui_elements.clone(), move |gui_elements, _main_window, width, height| -> Result<(), Error> {
|
||||
let file_tab = &gui_elements.file_tab;
|
||||
|
||||
file_tab.update_palette(tim_manager.lock().expect("VRAM already locked").change_unadded_tim_palette_size(width, height)?);
|
||||
Ok(())
|
||||
});
|
||||
|
||||
let tim_manager = self.tim_manager.clone();
|
||||
self.gui_elements.borrow().file_tab.on_browse_file(self.gui_elements.clone(), move |gui_elements, main_window| -> Result<(), Error> {
|
||||
let file = FileDialog::new()
|
||||
.add_filter("PNG image (.png)", &["png"])
|
||||
.set_title("PNG image file")
|
||||
.pick_file();
|
||||
|
||||
if let Some(file) = file {
|
||||
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, palette) = tim_manager.lock().expect("VRAM already locked").load_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)));
|
||||
}
|
||||
return file_tab.update_new_loaded_file(file_name, image, palette);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
});
|
||||
|
||||
let tim_manager = self.tim_manager.clone();
|
||||
self.gui_elements.borrow().file_tab.on_add_image(self.gui_elements.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();
|
||||
let encoding = file_tab.get_encoding()?;
|
||||
let mut tim_mgr = tim_manager.lock().expect("VRAM already locked");
|
||||
let (image, palette_image) = tim_mgr.get_converted_unadded_tim_image(encoding)?;
|
||||
let (full_image, _) = tim_mgr.get_converted_unadded_tim_image(Encoding::FullColor)?;
|
||||
|
||||
let images_created = main_tab.add_new_vram_file(&file_name, full_image, image, encoding, palette_image);
|
||||
if let Err(error) = tim_mgr.add_unadded_tim(images_created) {
|
||||
main_tab.pop_vram_files(images_created);
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
file_tab.clear_load();
|
||||
main_window.invoke_change_to_main();
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
fn setup_about_tab(&self) {
|
||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
|
|
|
@ -5,12 +5,19 @@ import { TabWidget } from "std-widgets.slint";
|
|||
|
||||
export component MainWindow inherits Window {
|
||||
// Main Tab values
|
||||
in-out property main_tab_vram_bg <=> main_tab.vram_bg;
|
||||
in-out property main_tab_vram_file_list <=> main_tab.vram_files;
|
||||
in-out property main_tab_vram_images <=> main_tab.vram_images;
|
||||
in-out property main_tab_vram_bg <=> main_tab.vram_bg;
|
||||
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_remove_file_clicked <=> main_tab.remove_file_clicked;
|
||||
callback move_vram_image <=> main_tab.move_vram_image;
|
||||
|
||||
callback main_tab_remove_file_clicked <=> main_tab.remove_file_clicked;
|
||||
callback move_vram_image <=> main_tab.move_vram_image;
|
||||
// Project widget values
|
||||
in-out property project_widget-open_project_path <=> file_tab.project_widget-open_project_path;
|
||||
in-out property project_widget-save_project_path <=> file_tab.project_widget-save_project_path;
|
||||
callback project_widget-load_project_clicked <=> file_tab.project_widget-load_project_clicked;
|
||||
callback project_widget-save_project_clicked <=> file_tab.project_widget-save_project_clicked;
|
||||
callback project_widget-browse_open_project_clicked <=> file_tab.project_widget-browse_open_project_clicked;
|
||||
callback project_widget-browse_save_project_clicked <=> file_tab.project_widget-browse_save_project_clicked;
|
||||
|
||||
// Convert Image values
|
||||
in-out property file_tab-encoding_options <=> file_tab.conv-encoding_options;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Button, TabWidget, LineEdit, GroupBox, ComboBox } from "std-widgets.slint";
|
||||
import { Button, TabWidget, LineEdit, GroupBox, ComboBox, CheckBox } from "std-widgets.slint";
|
||||
|
||||
export enum State {
|
||||
Project,
|
||||
|
@ -6,11 +6,85 @@ export enum State {
|
|||
}
|
||||
|
||||
component ProjectWidget inherits Rectangle {
|
||||
Text {
|
||||
text: "Projects not supported yet";
|
||||
color: #FF0000;
|
||||
font-size: 30pt;
|
||||
font-weight: 800;
|
||||
in-out property <string> open_project_path;
|
||||
in-out property <string> save_project_path;
|
||||
|
||||
callback load_project_clicked();
|
||||
callback save_project_clicked();
|
||||
callback browse_open_project_clicked();
|
||||
callback browse_save_project_clicked();
|
||||
|
||||
background: #D0D0D0;
|
||||
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
GroupBox {
|
||||
title: "Open Project";
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
Text {
|
||||
text: "Select a project to open. Any existing changes will be dropped";
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
LineEdit {
|
||||
width: 300pt;
|
||||
text: root.open_project_path;
|
||||
}
|
||||
Button {
|
||||
text: "Browse";
|
||||
clicked => {
|
||||
root.browse_open_project_clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
Button {
|
||||
text: "Load";
|
||||
clicked => {
|
||||
root.load_project_clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GroupBox {
|
||||
title: "Save Project";
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
padding: 4px;
|
||||
Text {
|
||||
text: "Save the current project";
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
LineEdit {
|
||||
width: 300pt;
|
||||
text: root.save_project_path;
|
||||
}
|
||||
Button {
|
||||
text: "Browse";
|
||||
clicked => {
|
||||
root.browse_save_project_clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
CheckBox {
|
||||
text: "Use relative path for files";
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
Button {
|
||||
text: "Save";
|
||||
clicked => {
|
||||
root.save_project_clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,6 +278,16 @@ component ConvertImageWidget inherits Rectangle {
|
|||
}
|
||||
|
||||
export component FileTab inherits Rectangle {
|
||||
in-out property <State> state;
|
||||
// For project widget
|
||||
in-out property <string> project_widget-open_project_path;
|
||||
in-out property <string> project_widget-save_project_path;
|
||||
callback project_widget-load_project_clicked();
|
||||
callback project_widget-save_project_clicked();
|
||||
callback project_widget-browse_open_project_clicked();
|
||||
callback project_widget-browse_save_project_clicked();
|
||||
|
||||
// For image conversion widget
|
||||
in-out property <[string]> conv-encoding_options;
|
||||
in-out property <string> conv-image_path;
|
||||
in-out property <string> conv-image_name;
|
||||
|
@ -216,11 +300,9 @@ export component FileTab inherits Rectangle {
|
|||
in-out property <string> conv-selected_encoding;
|
||||
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);
|
||||
callback conv-image_browse_clicked;
|
||||
callback conv-image_add_clicked;
|
||||
callback conv-image_update_palette_size(int, int);
|
||||
callback conv-image_browse_clicked;
|
||||
callback conv-image_add_clicked;
|
||||
|
||||
x: 0px;
|
||||
y: 0px;
|
||||
|
@ -250,6 +332,24 @@ export component FileTab inherits Rectangle {
|
|||
padding: 4px;
|
||||
alignment: start;
|
||||
if root.state == State.Project : ProjectWidget {
|
||||
open_project_path <=> root.project_widget-open_project_path;
|
||||
save_project_path <=> root.project_widget-save_project_path;
|
||||
|
||||
load_project_clicked() => {
|
||||
root.project_widget-load_project_clicked();
|
||||
}
|
||||
|
||||
save_project_clicked() => {
|
||||
root.project_widget-save_project_clicked();
|
||||
}
|
||||
|
||||
browse_open_project_clicked() => {
|
||||
root.project_widget-browse_open_project_clicked();
|
||||
}
|
||||
|
||||
browse_save_project_clicked() => {
|
||||
root.project_widget-browse_save_project_clicked();
|
||||
}
|
||||
}
|
||||
|
||||
if root.state == State.ConvertImage : ConvertImageWidget {
|
||||
|
|
Loading…
Reference in New Issue