Compare commits
11 Commits
2d0c63f871
...
b394330405
Author | SHA1 | Date |
---|---|---|
|
b394330405 | |
|
602fb3a5c2 | |
|
6a1b87cdb1 | |
|
5ccf593963 | |
|
2b6fb4c090 | |
|
aaeeaf97c5 | |
|
a4fe26f112 | |
|
c114745a8e | |
|
e3a85fc2d9 | |
|
eb29237f24 | |
|
ab5c7efce8 |
|
@ -0,0 +1,112 @@
|
|||
use std::fmt::format;
|
||||
|
||||
use crate::{gui::{main_tab::MainTab, MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMInfo};
|
||||
use super::FileTab;
|
||||
use rfd::FileDialog;
|
||||
use slint::SharedString;
|
||||
use tim_tool::logic::{project::{Job, Project}, tim::{self, 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(tim_manager: MutexTIMManager) -> impl FnMut(&mut FileTab, &MainTab, &MainWindow) -> Result<(), Error> + 'static {
|
||||
move |_file_tab, main_tab, _main_window| {
|
||||
let tim_info = tim_manager.lock().expect("VRAM already locked").clone_added_tims();
|
||||
let vram_info = main_tab.clone_vram_info();
|
||||
|
||||
if tim_info.len() != vram_info.len() {
|
||||
return Err(Error::from_str("TIM and VRAM info not in sync! Please close program"));
|
||||
}
|
||||
|
||||
let mut cur_job = None;
|
||||
let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, vram)| {
|
||||
if vram.is_palette {
|
||||
// Add palette to cur_job
|
||||
None
|
||||
}
|
||||
|
||||
else {
|
||||
// We are done with the old job
|
||||
let prev_job = std::mem::replace(&mut cur_job, None);
|
||||
|
||||
cur_job = Some(Job::new("Planschi".to_owned(), std::path::PathBuf::from("value")));
|
||||
prev_job
|
||||
}
|
||||
}).collect());
|
||||
if let Some(cur_job) = cur_job {
|
||||
project.push(cur_job);
|
||||
}
|
||||
|
||||
Err(Error::from_text(format!("Adding {} jobs", project.len())))
|
||||
}
|
||||
}
|
||||
|
||||
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_tab, cloned_main_window, mut function) = (object.clone(), main_tab.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 cloned_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_tab, cloned_main_window, mut function) = (object.clone(), main_tab.clone(), main_window.clone(), callbacks::on_save_project_clicked(tim_manager.clone()));
|
||||
main_window.borrow().on_project_widget_save_project_clicked (move || {
|
||||
if let Err(error) = function(&mut cloned_object.borrow_mut(), &cloned_main_tab.borrow(), &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()))?))
|
||||
}
|
||||
}
|
|
@ -1,156 +0,0 @@
|
|||
use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMImage};
|
||||
use super::{GUIElementsRef, MainWindowRef};
|
||||
|
||||
use slint::{Model, SharedString};
|
||||
use tim_tool::logic::tim::types::Encoding;
|
||||
use std::{ops::RangeInclusive, rc::Rc, sync::{Arc, Mutex}};
|
||||
|
||||
struct VRAM {
|
||||
count: usize,
|
||||
file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
|
||||
image_list: Rc<slint::VecModel<VRAMImage>>
|
||||
}
|
||||
|
||||
impl VRAM {
|
||||
pub fn push(&mut self, name: slint::StandardListViewItem, image: VRAMImage) {
|
||||
self.file_list.push(name);
|
||||
self.image_list.push(image);
|
||||
self.count += 1;
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, idx: usize) {
|
||||
self.count -= 1;
|
||||
self.file_list.remove(idx);
|
||||
self.image_list.remove(idx);
|
||||
}
|
||||
|
||||
pub fn pop(&mut self) {
|
||||
self.remove(self.count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MainTab {
|
||||
main_window: MainWindowRef,
|
||||
vram: Arc<Mutex<VRAM>>,
|
||||
}
|
||||
|
||||
impl MainTab {
|
||||
pub fn new(main_window: MainWindowRef) -> MainTab {
|
||||
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()));
|
||||
|
||||
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}))}
|
||||
}
|
||||
|
||||
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 {
|
||||
let mut vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
let mut add_new_image = |file_name: &String, full_image: slint::Image, image: slint::Image, encoding: Encoding, palette_count: i32, is_palette: bool| {
|
||||
let encoding_str = if is_palette {"<Palette>"} else {encoding.to_str()};
|
||||
let vram_image = VRAMImage{
|
||||
full_img: full_image,
|
||||
img: image,
|
||||
x: 0,
|
||||
y: 0,
|
||||
encoding_str: SharedString::from(encoding_str),
|
||||
palette_count,
|
||||
is_palette,
|
||||
};
|
||||
|
||||
vram_data.push(slint::StandardListViewItem::from(file_name.as_str()), vram_image);
|
||||
};
|
||||
|
||||
let mut images_added = 1;
|
||||
add_new_image(file_name, full_image, image, encoding, if image_palette.is_some() {1} else {0}, false);
|
||||
if let Some(image_palette) = image_palette {
|
||||
let file_name = " => ".to_owned() + file_name.as_str() + " (Palette)";
|
||||
|
||||
images_added += 1;
|
||||
add_new_image(&file_name, image_palette.clone(), image_palette, encoding, 0, true);
|
||||
}
|
||||
|
||||
images_added
|
||||
}
|
||||
|
||||
pub fn remove_vram_file(&mut self, idx: usize) -> Result<RangeInclusive<usize>, &'static str> {
|
||||
let mut vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
let extras = {
|
||||
if let Some(element) = vram_data.image_list.iter().skip(idx).next() {
|
||||
if element.is_palette {
|
||||
return Err("Can not remove palette. Delete image instead");
|
||||
}
|
||||
|
||||
else {
|
||||
element.palette_count as usize
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
let range = idx..=idx+extras;
|
||||
let mut remove_image = |idx: usize| {
|
||||
vram_data.remove(idx);
|
||||
};
|
||||
|
||||
for _ in range.clone() {
|
||||
remove_image(idx);
|
||||
}
|
||||
return Ok(range);
|
||||
}
|
||||
|
||||
pub fn pop_vram_files(&mut self, count: usize) {
|
||||
let mut vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
for _ in 0..count {
|
||||
vram_data.pop();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_vram_image(&mut self, idx: usize, dx: i32, dy: i32) {
|
||||
let vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
if let Some(mut vram_info) = vram_data.image_list.row_data(idx) {
|
||||
vram_info.x += dx;
|
||||
vram_info.y += dy;
|
||||
|
||||
if vram_info.x < 0 {
|
||||
vram_info.x = 0;
|
||||
}
|
||||
|
||||
if vram_info.y < 0 {
|
||||
vram_info.y = 0;
|
||||
}
|
||||
|
||||
let (vram_img_width, vram_img_height) = (vram_info.img.size().width as i32, vram_info.img.size().height as i32);
|
||||
if (vram_info.x + vram_img_width) > VRAM_WIDTH as i32 {
|
||||
vram_info.x = VRAM_WIDTH as i32 - vram_img_width;
|
||||
}
|
||||
|
||||
if (vram_info.y + vram_img_height) > VRAM_HEIGHT as i32 {
|
||||
vram_info.y = VRAM_HEIGHT as i32 - vram_img_height;
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,167 @@
|
|||
mod callbacks;
|
||||
|
||||
use crate::{gui::{MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, VRAMImgData, VRAMInfo, VRAMData};
|
||||
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;
|
||||
|
||||
struct VRAM {
|
||||
count: usize,
|
||||
file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
|
||||
info: Rc<slint::VecModel<VRAMData>>
|
||||
}
|
||||
|
||||
impl VRAM {
|
||||
pub fn push(&mut self, name: slint::StandardListViewItem, image: VRAMData) {
|
||||
self.file_list.push(name);
|
||||
self.info.push(image);
|
||||
self.count += 1;
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, idx: usize) {
|
||||
self.count -= 1;
|
||||
self.file_list.remove(idx);
|
||||
self.info.remove(idx);
|
||||
}
|
||||
|
||||
pub fn pop(&mut self) {
|
||||
self.remove(self.count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MainTab {
|
||||
vram: Arc<Mutex<VRAM>>,
|
||||
}
|
||||
|
||||
pub type SharedMainTab = Rc<RefCell<MainTab>>;
|
||||
|
||||
impl 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 info = Rc::new(slint::VecModel::from(Vec::<VRAMData>::new()));
|
||||
|
||||
main_window.borrow().set_main_tab_vram_file_list(vram_file_list.clone().into());
|
||||
main_window.borrow().set_main_tab_vram_data(info.clone().into());
|
||||
|
||||
let object = SharedMainTab::new(MainTab{vram: Arc::new(Mutex::new(VRAM{count: 0, file_list: vram_file_list, info}))}.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 {
|
||||
let mut vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
let mut add_new_image = |file_name: &String, full_image: slint::Image, image: slint::Image, encoding: Encoding, palette_count: i32, is_palette: bool| {
|
||||
let encoding_str = if is_palette {"<Palette>"} else {encoding.to_str()};
|
||||
let vram_image = VRAMData {
|
||||
images: VRAMImgData {
|
||||
full_image,
|
||||
image
|
||||
},
|
||||
info: VRAMInfo {
|
||||
x: 0,
|
||||
y: 0,
|
||||
encoding_str: SharedString::from(encoding_str),
|
||||
palette_count,
|
||||
is_palette,
|
||||
}
|
||||
};
|
||||
|
||||
vram_data.push(slint::StandardListViewItem::from(file_name.as_str()), vram_image);
|
||||
};
|
||||
|
||||
let mut images_added = 1;
|
||||
add_new_image(file_name, full_image, image, encoding, if image_palette.is_some() {1} else {0}, false);
|
||||
if let Some(image_palette) = image_palette {
|
||||
let file_name = " => ".to_owned() + file_name.as_str() + " (Palette)";
|
||||
|
||||
images_added += 1;
|
||||
add_new_image(&file_name, image_palette.clone(), image_palette, encoding, 0, true);
|
||||
}
|
||||
|
||||
images_added
|
||||
}
|
||||
|
||||
pub fn remove_vram_file(&mut self, idx: usize) -> Result<RangeInclusive<usize>, &'static str> {
|
||||
let mut vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
let extras = {
|
||||
if let Some(element) = vram_data.info.iter().skip(idx).next() {
|
||||
if element.info.is_palette {
|
||||
return Err("Can not remove palette. Delete image instead");
|
||||
}
|
||||
|
||||
else {
|
||||
element.info.palette_count as usize
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
let range = idx..=idx+extras;
|
||||
let mut remove_image = |idx: usize| {
|
||||
vram_data.remove(idx);
|
||||
};
|
||||
|
||||
for _ in range.clone() {
|
||||
remove_image(idx);
|
||||
}
|
||||
return Ok(range);
|
||||
}
|
||||
|
||||
pub fn pop_vram_files(&mut self, count: usize) {
|
||||
let mut vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
for _ in 0..count {
|
||||
vram_data.pop();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_vram_image(&mut self, idx: usize, dx: i32, dy: i32) {
|
||||
let vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
if let Some(mut vram_info) = vram_data.info.row_data(idx) {
|
||||
vram_info.info.x += dx;
|
||||
vram_info.info.y += dy;
|
||||
|
||||
if vram_info.info.x < 0 {
|
||||
vram_info.info.x = 0;
|
||||
}
|
||||
|
||||
if vram_info.info.y < 0 {
|
||||
vram_info.info.y = 0;
|
||||
}
|
||||
|
||||
let (vram_img_width, vram_img_height) = (vram_info.images.image.size().width as i32, vram_info.images.image.size().height as i32);
|
||||
if (vram_info.info.x + vram_img_width) > VRAM_WIDTH as i32 {
|
||||
vram_info.info.x = VRAM_WIDTH as i32 - vram_img_width;
|
||||
}
|
||||
|
||||
if (vram_info.info.y + vram_img_height) > VRAM_HEIGHT as i32 {
|
||||
vram_info.info.y = VRAM_HEIGHT as i32 - vram_img_height;
|
||||
}
|
||||
|
||||
vram_data.info.set_row_data(idx, vram_info);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_vram_info(&self) -> Vec<VRAMInfo> {
|
||||
let vram_data = self.vram.lock().expect("VRAM already locked");
|
||||
let mut infos = Vec::new();
|
||||
|
||||
for vram_data in vram_data.info.iter() {
|
||||
infos.push(vram_data.info.clone());
|
||||
}
|
||||
infos
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
pub mod project;
|
||||
pub mod tim;
|
||||
pub mod tim_mgr;
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
pub struct Job {
|
||||
name: String,
|
||||
file_path: PathBuf,
|
||||
}
|
||||
|
||||
impl Job {
|
||||
pub fn new(name: String, file_path: PathBuf) -> Job {
|
||||
Job{name, file_path}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Project {
|
||||
jobs: Vec<Job>
|
||||
}
|
||||
|
||||
impl Project {
|
||||
pub fn new(jobs: Vec<Job>) -> Project {
|
||||
Project{jobs}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, job: Job) {
|
||||
self.jobs.push(job);
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.jobs.len()
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ use slint::{Rgba8Pixel, SharedPixelBuffer};
|
|||
use tool_helper::Error;
|
||||
use types::Encoding;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TIMInfo {
|
||||
_path: PathBuf,
|
||||
image_data: SharedPixelBuffer<Rgba8Pixel>,
|
||||
|
@ -119,6 +120,7 @@ impl TIMInfo {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct PaletteInfo {
|
||||
data: Vec<Rgba8Pixel>,
|
||||
width: u32,
|
||||
|
|
|
@ -69,4 +69,8 @@ impl TIMManager {
|
|||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clone_added_tims(&self) -> Vec<Option<TIMInfo>> {
|
||||
self.added_tims.clone()
|
||||
}
|
||||
}
|
|
@ -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_data <=> main_tab.vram_data;
|
||||
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 {
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import { VRAMArea } from "../vram-components.slint";
|
||||
import { Button, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView, Slider } from "std-widgets.slint";
|
||||
|
||||
struct VRAMImage {
|
||||
full_img: image,
|
||||
img: image,
|
||||
struct VRAMImgData {
|
||||
full_image: image,
|
||||
image: image,
|
||||
}
|
||||
|
||||
struct VRAMInfo {
|
||||
x: int,
|
||||
y: int,
|
||||
encoding_str: string,
|
||||
|
@ -11,11 +14,16 @@ struct VRAMImage {
|
|||
is_palette: bool,
|
||||
}
|
||||
|
||||
struct VRAMData {
|
||||
images: VRAMImgData,
|
||||
info: VRAMInfo,
|
||||
}
|
||||
|
||||
export component MainTab inherits Rectangle {
|
||||
property <float> scale: 1.0;
|
||||
property <float> scale: 1.0;
|
||||
in-out property <image> vram_bg;
|
||||
in-out property <[StandardListViewItem]> vram_files: [];
|
||||
in-out property <[VRAMImage]> vram_images: [];
|
||||
in-out property <[StandardListViewItem]> vram_files: [];
|
||||
in-out property <[VRAMData]> vram_data: [];
|
||||
|
||||
callback add_file_clicked();
|
||||
callback remove_file_clicked(int);
|
||||
|
@ -54,12 +62,12 @@ export component MainTab inherits Rectangle {
|
|||
scale: scale;
|
||||
}
|
||||
|
||||
for vram_image[i] in root.vram_images: VRAMArea {
|
||||
for vram_data[i] in root.vram_data: VRAMArea {
|
||||
x: root.get_border_width()*1px;
|
||||
y: root.get_border_width()*1px;
|
||||
img: vram_image.img;
|
||||
img_x: vram_image.x;
|
||||
img_y: vram_image.y;
|
||||
img: vram_data.images.image;
|
||||
img_x: vram_data.info.x;
|
||||
img_y: vram_data.info.y;
|
||||
scale: scale;
|
||||
|
||||
TouchArea {
|
||||
|
@ -82,8 +90,8 @@ export component MainTab inherits Rectangle {
|
|||
if event.kind == PointerEventKind.down {
|
||||
cur_sel_x.text = parent.img_x;
|
||||
cur_sel_y.text = parent.img_y;
|
||||
cur_sel_img.source = vram-image.full_img;
|
||||
encoding_text.encoding_str = vram-image.encoding_str;
|
||||
cur_sel_img.source = vram_data.images.full_image;
|
||||
encoding_text.encoding_str = vram_data.info.encoding_str;
|
||||
cur_sel_img.visible = true;
|
||||
|
||||
vram_files_list.current-item = i;
|
||||
|
@ -154,10 +162,10 @@ export component MainTab inherits Rectangle {
|
|||
model: root.vram_files;
|
||||
|
||||
current-item-changed(current-item) => {
|
||||
cur_sel_x.text = root.vram_images[current-item].x;
|
||||
cur_sel_y.text = root.vram_images[current-item].y;
|
||||
cur_sel_img.source = root.vram_images[current-item].full_img;
|
||||
encoding_text.encoding_str = root.vram_images[current-item].encoding_str;
|
||||
cur_sel_x.text = root.vram_data[current-item].info.x;
|
||||
cur_sel_y.text = root.vram_data[current-item].info.y;
|
||||
cur_sel_img.source = root.vram_data[current-item].images.full_image;
|
||||
encoding_text.encoding_str = root.vram_data[current-item].info.encoding_str;
|
||||
cur_sel_img.visible = true;
|
||||
}
|
||||
}
|
||||
|
@ -210,8 +218,8 @@ export component MainTab inherits Rectangle {
|
|||
|
||||
accepted(text) => {
|
||||
if(vram_files_list.current-item != -1) {
|
||||
root.move_vram_image(vram_files_list.current-item, text.to-float() - vram_images[vram_files_list.current-item].x, 0);
|
||||
self.text = vram_images[vram_files_list.current-item].x;
|
||||
root.move_vram_image(vram_files_list.current-item, text.to-float() - vram_data[vram_files_list.current-item].info.x, 0);
|
||||
self.text = vram_data[vram_files_list.current-item].info.x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,8 +239,8 @@ export component MainTab inherits Rectangle {
|
|||
|
||||
accepted(text) => {
|
||||
if(vram_files_list.current-item != -1) {
|
||||
root.move_vram_image(vram_files_list.current-item, 0, text.to-float() - vram_images[vram_files_list.current-item].y);
|
||||
self.text = vram_images[vram_files_list.current-item].y;
|
||||
root.move_vram_image(vram_files_list.current-item, 0, text.to-float() - vram_data[vram_files_list.current-item].info.y);
|
||||
self.text = vram_data[vram_files_list.current-item].info.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,22 +260,22 @@ export component MainTab inherits Rectangle {
|
|||
if(vram_files_list.current-item != -1) {
|
||||
if(event.text == Key.LeftArrow) {
|
||||
root.move_vram_image(vram_files_list.current-item, -1, 0);
|
||||
cur_sel_x.text = vram_images[vram_files_list.current-item].x;
|
||||
cur_sel_x.text = vram_data[vram_files_list.current-item].info.x;
|
||||
}
|
||||
|
||||
if(event.text == Key.RightArrow) {
|
||||
root.move_vram_image(vram_files_list.current-item, 1, 0);
|
||||
cur_sel_x.text = vram_images[vram_files_list.current-item].x;
|
||||
cur_sel_x.text = vram_data[vram_files_list.current-item].info.x;
|
||||
}
|
||||
|
||||
if(event.text == Key.UpArrow) {
|
||||
root.move_vram_image(vram_files_list.current-item, 0, -1);
|
||||
cur_sel_y.text = vram_images[vram_files_list.current-item].y;
|
||||
cur_sel_y.text = vram_data[vram_files_list.current-item].info.y;
|
||||
}
|
||||
|
||||
if(event.text == Key.DownArrow) {
|
||||
root.move_vram_image(vram_files_list.current-item, 0, 1);
|
||||
cur_sel_y.text = vram_images[vram_files_list.current-item].y;
|
||||
cur_sel_y.text = vram_data[vram_files_list.current-item].info.y;
|
||||
}
|
||||
}
|
||||
accept
|
||||
|
|
Loading…
Reference in New Issue