Support File Settings #26
|
@ -4,7 +4,7 @@ use crate::{gui::{self, main_tab::{MainTab, NewVRAMImageInfo}, MutexTIMManager,
|
||||||
use super::FileTab;
|
use super::FileTab;
|
||||||
use rfd::FileDialog;
|
use rfd::FileDialog;
|
||||||
use slint::SharedString;
|
use slint::SharedString;
|
||||||
use tim_tool::logic::{project::{FileSettings, ImagePosition, Job, PaletteRect, Project}, tim::types::Encoding, TIMManager};
|
use tim_tool::logic::{project::{FileSettings, ImagePosition, Job, PaletteRect, Project, Transparency}, tim::types::Encoding, TIMManager};
|
||||||
use tool_helper::Error;
|
use tool_helper::Error;
|
||||||
|
|
||||||
pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
pub(super) fn on_browse_file(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||||
|
@ -46,7 +46,7 @@ pub(super) fn on_add_image(tim_manager: MutexTIMManager) -> impl FnMut(&mut File
|
||||||
let file_name = file_tab.get_file_name();
|
let file_name = file_tab.get_file_name();
|
||||||
let encoding = file_tab.get_encoding()?;
|
let encoding = file_tab.get_encoding()?;
|
||||||
|
|
||||||
add_unadded_tim(main_tab, &mut tim_manager.lock().expect("VRAM already locked"), UnaddedTIM::new(&file_name, encoding))?;
|
add_unadded_tim(main_tab, &mut tim_manager.lock().expect("VRAM already locked"), UnaddedTIM::new(&file_name, encoding), FileSettings::from_encoding(encoding))?;
|
||||||
|
|
||||||
file_tab.clear_load();
|
file_tab.clear_load();
|
||||||
main_window.invoke_change_to_main();
|
main_window.invoke_change_to_main();
|
||||||
|
@ -90,7 +90,7 @@ pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
||||||
palette_y: pal_y,
|
palette_y: pal_y,
|
||||||
encoding: job.settings.encoding
|
encoding: job.settings.encoding
|
||||||
};
|
};
|
||||||
add_unadded_tim(main_tab, &mut tim_manager, unadded_tim)?;
|
add_unadded_tim(main_tab, &mut tim_manager, unadded_tim, job.settings)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
main_window.invoke_change_to_main();
|
main_window.invoke_change_to_main();
|
||||||
|
@ -149,7 +149,11 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {tim.get_path()};
|
} else {tim.get_path()};
|
||||||
cur_job = Some(Job::new(name, file_path, (vram.x as u16, vram.y as u16), FileSettings::compatible(Encoding::from_str(vram.encoding_str.as_str()))));
|
cur_job = Some(Job::new(name, file_path, (vram.x as u16, vram.y as u16), FileSettings::new(
|
||||||
|
vram.use_compression,
|
||||||
|
Transparency::from(vram.trans_setting),
|
||||||
|
Encoding::from_str(vram.encoding_str.as_str())
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
prev_job
|
prev_job
|
||||||
}
|
}
|
||||||
|
@ -220,11 +224,11 @@ impl<'a> UnaddedTIM<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_unadded_tim(main_tab: &mut MainTab, tim_manager: &mut TIMManager, unadded_tim: UnaddedTIM) -> Result<(), Error> {
|
fn add_unadded_tim(main_tab: &mut MainTab, tim_manager: &mut TIMManager, unadded_tim: UnaddedTIM, settings: FileSettings) -> Result<(), Error> {
|
||||||
let (image, palette_image) = tim_manager.get_converted_unadded_tim_image(unadded_tim.encoding)?;
|
let (image, palette_image) = tim_manager.get_converted_unadded_tim_image(unadded_tim.encoding)?;
|
||||||
let (full_image, _) = tim_manager.get_converted_unadded_tim_image(Encoding::FullColor)?;
|
let (full_image, _) = tim_manager.get_converted_unadded_tim_image(Encoding::FullColor)?;
|
||||||
let image = NewVRAMImageInfo::new(image, unadded_tim.image_x, unadded_tim.image_y, unadded_tim.encoding);
|
let image = NewVRAMImageInfo::new(image, unadded_tim.image_x, unadded_tim.image_y, settings);
|
||||||
let palette_image = if let Some(palette_image) = palette_image { Some(NewVRAMImageInfo::new(palette_image, unadded_tim.palette_x, unadded_tim.palette_y, Encoding::FullColor)) } else { None };
|
let palette_image = if let Some(palette_image) = palette_image { Some(NewVRAMImageInfo::new(palette_image, unadded_tim.palette_x, unadded_tim.palette_y, FileSettings::from_encoding(Encoding::FullColor))) } else { None };
|
||||||
|
|
||||||
let images_created = main_tab.add_new_vram_file(unadded_tim.file_name, full_image, image, palette_image);
|
let images_created = main_tab.add_new_vram_file(unadded_tim.file_name, full_image, image, palette_image);
|
||||||
if let Err(error) = tim_manager.add_unadded_tim(images_created) {
|
if let Err(error) = tim_manager.add_unadded_tim(images_created) {
|
||||||
|
|
|
@ -4,18 +4,18 @@ use crate::{gui::{MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, VRAMImgData, VRAMIn
|
||||||
use super::MainWindowRef;
|
use super::MainWindowRef;
|
||||||
use slint::{Model, SharedString};
|
use slint::{Model, SharedString};
|
||||||
use std::{cell::RefCell, ops::RangeInclusive, rc::Rc, sync::{Arc, Mutex}};
|
use std::{cell::RefCell, ops::RangeInclusive, rc::Rc, sync::{Arc, Mutex}};
|
||||||
use tim_tool::logic::tim::types::Encoding;
|
use tim_tool::logic::project::FileSettings;
|
||||||
|
|
||||||
pub struct NewVRAMImageInfo {
|
pub struct NewVRAMImageInfo {
|
||||||
pub image: slint::Image,
|
pub image: slint::Image,
|
||||||
pub x: u16,
|
pub x: u16,
|
||||||
pub y: u16,
|
pub y: u16,
|
||||||
pub encoding: Encoding,
|
pub settings: FileSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NewVRAMImageInfo {
|
impl NewVRAMImageInfo {
|
||||||
pub fn new(image: slint::Image, x: u16, y: u16, encoding: Encoding) -> NewVRAMImageInfo {
|
pub fn new(image: slint::Image, x: u16, y: u16, settings: FileSettings) -> NewVRAMImageInfo {
|
||||||
NewVRAMImageInfo{image, x, y, encoding}
|
NewVRAMImageInfo{image, x, y, settings}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ impl MainTab {
|
||||||
pub fn add_new_vram_file(&mut self, file_name: &String, full_image: slint::Image, texture: NewVRAMImageInfo, image_palette: Option<NewVRAMImageInfo>) -> usize {
|
pub fn add_new_vram_file(&mut self, file_name: &String, full_image: slint::Image, texture: NewVRAMImageInfo, image_palette: Option<NewVRAMImageInfo>) -> usize {
|
||||||
let mut vram_data = self.vram.lock().expect("VRAM already locked");
|
let mut vram_data = self.vram.lock().expect("VRAM already locked");
|
||||||
let mut add_new_image = |file_name: &String, full_image: slint::Image, vram_image: NewVRAMImageInfo, palette_count: i32, is_palette: bool| {
|
let mut add_new_image = |file_name: &String, full_image: slint::Image, vram_image: NewVRAMImageInfo, palette_count: i32, is_palette: bool| {
|
||||||
let encoding_str = if is_palette {"<Palette>"} else {vram_image.encoding.to_str()};
|
let encoding_str = if is_palette {"<Palette>"} else {vram_image.settings.encoding.to_str()};
|
||||||
let vram_image = VRAMData {
|
let vram_image = VRAMData {
|
||||||
images: VRAMImgData {
|
images: VRAMImgData {
|
||||||
full_image,
|
full_image,
|
||||||
|
@ -94,8 +94,8 @@ impl MainTab {
|
||||||
x: vram_image.x as i32,
|
x: vram_image.x as i32,
|
||||||
y: vram_image.y as i32,
|
y: vram_image.y as i32,
|
||||||
encoding_str: SharedString::from(encoding_str),
|
encoding_str: SharedString::from(encoding_str),
|
||||||
use_compression: false,
|
use_compression: vram_image.settings.compress,
|
||||||
trans_setting: 0,
|
trans_setting: vram_image.settings.transparency.as_idx(),
|
||||||
palette_count,
|
palette_count,
|
||||||
is_palette,
|
is_palette,
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,11 @@ pub struct FileSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileSettings {
|
impl FileSettings {
|
||||||
pub fn compatible(encoding: Encoding) -> FileSettings {
|
pub fn new(compress: bool, transparency: Transparency, encoding: Encoding) -> FileSettings {
|
||||||
|
FileSettings{compress, transparency, encoding}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_encoding(encoding: Encoding) -> FileSettings {
|
||||||
let mut new_type = FileSettings::default();
|
let mut new_type = FileSettings::default();
|
||||||
|
|
||||||
new_type.encoding = encoding;
|
new_type.encoding = encoding;
|
||||||
|
@ -136,4 +140,25 @@ pub enum Transparency {
|
||||||
FirstColor,
|
FirstColor,
|
||||||
PSXSemi,
|
PSXSemi,
|
||||||
Both,
|
Both,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Transparency {
|
||||||
|
pub fn from(selection: i32) -> Transparency {
|
||||||
|
match selection {
|
||||||
|
0 => Transparency::None,
|
||||||
|
1 => Transparency::FirstColor,
|
||||||
|
2 => Transparency::PSXSemi,
|
||||||
|
3 => Transparency::Both,
|
||||||
|
_ => Transparency::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_idx(&self) -> i32 {
|
||||||
|
match self {
|
||||||
|
Transparency::None => 0,
|
||||||
|
Transparency::FirstColor => 1,
|
||||||
|
Transparency::PSXSemi => 2,
|
||||||
|
Transparency::Both => 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue