Compare commits

..

No commits in common. "f72f92d4c2e61d195b801e0056691e0aeecb79c2" and "b0b8c43700c884b3e255fcaf22057541e0a6c2a0" have entirely different histories.

4 changed files with 55 additions and 159 deletions

View File

@ -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::{ImagePosition, Job, PaletteRect, Project}, 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 {
@ -79,16 +79,16 @@ pub(super) fn on_load_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
for job in new_project.jobs { for job in new_project.jobs {
let file_path = Job::create_file_path(job.file_path, open_location.as_str()); let file_path = Job::create_file_path(job.file_path, open_location.as_str());
let (_, _) = tim_manager.load_unadded_tim(&file_path)?; let (_, _) = tim_manager.load_unadded_tim(&file_path)?;
let (pal_x, pal_y, pal_width, pal_height) = if let Some(palette_rect) = job.palette_rect {palette_rect.into()} else {(0, 0, 0, 0)}; let (pal_width, pal_height) = job.palette_rect.size.into();
tim_manager.change_unadded_tim_palette_size(pal_width, pal_height)?; tim_manager.change_unadded_tim_palette_size(pal_width, pal_height)?;
let unadded_tim = UnaddedTIM{ let unadded_tim = UnaddedTIM{
file_name: &job.name, file_name: &job.name,
image_x: job.image_pos.x, image_x: job.image_pos.x,
image_y: job.image_pos.y, image_y: job.image_pos.y,
palette_x: pal_x, palette_x: job.palette_rect.pos.x,
palette_y: pal_y, palette_y: job.palette_rect.pos.y,
encoding: job.settings.encoding encoding: job.encoding
}; };
add_unadded_tim(main_tab, &mut tim_manager, unadded_tim)?; add_unadded_tim(main_tab, &mut tim_manager, unadded_tim)?;
} }
@ -126,7 +126,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
if let Some(mut cur_palette) = cur_palette { if let Some(mut cur_palette) = cur_palette {
cur_palette.pos = ImagePosition::new(vram.x as u16, vram.y as u16); cur_palette.pos = ImagePosition::new(vram.x as u16, vram.y as u16);
if let Some(cur_job) = &mut cur_job { if let Some(cur_job) = &mut cur_job {
cur_job.palette_rect = Some(cur_palette); cur_job.palette_rect = cur_palette;
} }
} }
None None
@ -149,7 +149,7 @@ 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), Encoding::from_str(vram.encoding_str.as_str())));
} }
prev_job prev_job
} }

View File

@ -94,8 +94,6 @@ 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,
trans_setting: 0,
palette_count, palette_count,
is_palette, is_palette,
} }

View File

@ -2,68 +2,6 @@ use super::tim::types::Encoding;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::PathBuf; use std::path::PathBuf;
#[derive(Serialize, Deserialize)]
pub struct FileSettings {
pub compress: bool,
pub transparency: Transparency,
pub encoding: Encoding,
}
impl FileSettings {
pub fn compatible(encoding: Encoding) -> FileSettings {
let mut new_type = FileSettings::default();
new_type.encoding = encoding;
new_type
}
}
impl std::default::Default for FileSettings {
fn default() -> Self {
Self{compress: Default::default(), transparency: Transparency::None, encoding: Encoding::FullColor}
}
}
#[derive(Serialize, Deserialize)]
pub struct Job {
pub name: String,
pub file_path: PathBuf,
pub image_pos: ImagePosition,
pub palette_rect: Option<PaletteRect>,
pub settings: FileSettings,
}
impl Job {
pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16), settings: FileSettings) -> Job {
Job{name, file_path, image_pos: ImagePosition{x: image_pos.0, y: image_pos.1}, palette_rect: None, settings}
}
pub fn create_file_path<T:?Sized + std::convert::AsRef<std::ffi::OsStr>>(file_path: PathBuf, location_path: &T) -> PathBuf {
if file_path.is_file() {
file_path
}
else {
let mut new_file_path = PathBuf::from(location_path);
new_file_path.pop();
new_file_path.push(file_path);
new_file_path
}
}
}
#[derive(Serialize, Deserialize)]
pub struct Project {
pub jobs: Vec<Job>
}
impl Project {
pub fn new(jobs: Vec<Job>) -> Project {
Project{jobs}
}
}
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct ImagePosition { pub struct ImagePosition {
pub x: u16, pub x: u16,
@ -118,12 +56,6 @@ impl PaletteRect {
} }
} }
impl From<PaletteRect> for (u16, u16, u16, u16) {
fn from(value: PaletteRect) -> Self {
(value.pos.x, value.pos.y, value.size.width, value.size.height)
}
}
impl std::default::Default for PaletteRect { impl std::default::Default for PaletteRect {
fn default() -> Self { fn default() -> Self {
PaletteRect{pos: ImagePosition::default(), size: ImageSize::default()} PaletteRect{pos: ImagePosition::default(), size: ImageSize::default()}
@ -131,9 +63,41 @@ impl std::default::Default for PaletteRect {
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub enum Transparency { pub struct Job {
None, pub name: String,
FirstColor, pub file_path: PathBuf,
PSXSemi, pub image_pos: ImagePosition,
Both, pub palette_rect: PaletteRect,
pub encoding: Encoding,
}
impl Job {
pub fn new(name: String, file_path: PathBuf, image_pos: (u16, u16), encoding: Encoding) -> Job {
Job{name, file_path, image_pos: ImagePosition{x: image_pos.0, y: image_pos.1}, palette_rect: PaletteRect::default(), encoding}
}
pub fn create_file_path<T:?Sized + std::convert::AsRef<std::ffi::OsStr>>(file_path: PathBuf, location_path: &T) -> PathBuf {
if file_path.is_file() {
file_path
}
else {
let mut new_file_path = PathBuf::from(location_path);
new_file_path.pop();
new_file_path.push(file_path);
new_file_path
}
}
}
#[derive(Serialize, Deserialize)]
pub struct Project {
pub jobs: Vec<Job>
}
impl Project {
pub fn new(jobs: Vec<Job>) -> Project {
Project{jobs}
}
} }

View File

@ -1,5 +1,5 @@
import { VRAMArea } from "../vram-components.slint"; import { VRAMArea } from "../vram-components.slint";
import { Button, CheckBox, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView, Slider } from "std-widgets.slint"; import { Button, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView, Slider } from "std-widgets.slint";
struct VRAMImgData { struct VRAMImgData {
full_image: image, full_image: image,
@ -10,8 +10,6 @@ struct VRAMInfo {
x: int, x: int,
y: int, y: int,
encoding_str: string, encoding_str: string,
use_compression: bool,
trans_setting: int,
palette_count: int, palette_count: int,
is_palette: bool, // < Can we combine the palette into this, instead of having it separate? is_palette: bool, // < Can we combine the palette into this, instead of having it separate?
} }
@ -98,14 +96,6 @@ export component MainTab inherits Rectangle {
encoding_text.encoding_str = vram_data.info.encoding_str; encoding_text.encoding_str = vram_data.info.encoding_str;
cur_sel_img.visible = true; cur_sel_img.visible = true;
if !vram-data.info.is_palette {
file_settings_box.set_active(i);
}
else {
file_settings_box.set_inactive();
}
vram_files_list.current-item = i; vram_files_list.current-item = i;
} }
} }
@ -181,14 +171,6 @@ export component MainTab inherits Rectangle {
cur_sel_img.source = root.vram_data[current-item].images.full_image; cur_sel_img.source = root.vram_data[current-item].images.full_image;
encoding_text.encoding_str = root.vram_data[current-item].info.encoding_str; encoding_text.encoding_str = root.vram_data[current-item].info.encoding_str;
cur_sel_img.visible = true; cur_sel_img.visible = true;
if !root.vram_data[current-item].info.is_palette {
file_settings_box.set_active(current-item);
}
else {
file_settings_box.set_inactive();
}
} }
item-pointer-event(item, event, position) => { item-pointer-event(item, event, position) => {
@ -297,54 +279,6 @@ export component MainTab inherits Rectangle {
} }
} }
} }
file_settings_box := GroupBox {
title: "File settings";
enabled: false;
VerticalLayout {
alignment: start;
lz4_check_box := CheckBox {
text: "Compress (lz4)";
enabled: file_settings_box.enabled;
toggled => {
if(vram_files_list.current-item != -1) {
root.vram_data[vram_files_list.current-item].info.use_compression = self.checked;
}
}
}
GroupBox {
title: "Transparency:";
enabled: file_settings_box.enabled;
VerticalLayout {
alignment: start;
trans_combo_box := ComboBox {
model: ["No transparency", "First color transparent", "PSX semi-transparency", "Both"];
enabled: file_settings_box.enabled;
selected(current-value) => {
if(vram_files_list.current-item != -1) {
root.vram_data[vram_files_list.current-item].info.trans_setting = self.current-index;
}
}
}
}
}
}
public function set_active(current-item: int) {
lz4_check_box.checked = root.vram_data[current-item].info.use_compression;
trans_combo_box.current-index = root.vram_data[current-item].info.trans_setting;
self.enabled = true;
}
public function set_inactive() {
lz4_check_box.checked = false;
trans_combo_box.current-index = 0;
self.enabled = false;
}
}
} }
} }
} }