Prepare for palette
This commit is contained in:
parent
6ddca9e79f
commit
2af28b72c8
|
@ -2,10 +2,11 @@ use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH}, MainWindow, VRAMImage};
|
|||
use super::{GUIElementsRef, MainWindowRef};
|
||||
|
||||
use slint::Model;
|
||||
use std::rc::Rc;
|
||||
use std::{rc::Rc, sync::{Arc, Mutex}};
|
||||
|
||||
pub struct MainTab {
|
||||
main_window: MainWindowRef,
|
||||
mtx: Arc<Mutex<i32>>,
|
||||
vram_file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
|
||||
vram_image_list: Rc<slint::VecModel<VRAMImage>>,
|
||||
}
|
||||
|
@ -19,22 +20,30 @@ 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_file_list, vram_image_list}
|
||||
MainTab{main_window, mtx: Arc::new(Mutex::new(0)), vram_file_list, vram_image_list}
|
||||
}
|
||||
|
||||
pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image) {
|
||||
let vram_image = VRAMImage{
|
||||
img: image,
|
||||
x: 0,
|
||||
y: 0,
|
||||
is_palette: false,
|
||||
pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image, image_palette: Option<slint::Image>) {
|
||||
let add_new_image = |file_name: &String, image: slint::Image| {
|
||||
let vram_image = VRAMImage{
|
||||
img: image,
|
||||
x: 0,
|
||||
y: 0,
|
||||
palette_count: 0,
|
||||
is_palette: false,
|
||||
};
|
||||
|
||||
self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str()));
|
||||
self.vram_image_list.push(vram_image);
|
||||
};
|
||||
|
||||
self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str()));
|
||||
self.vram_image_list.push(vram_image);
|
||||
let _lock = self.mtx.lock().unwrap();
|
||||
add_new_image(file_name, image);
|
||||
}
|
||||
|
||||
pub fn remove_vram_file(&mut self, idx: usize) -> bool {
|
||||
let _lock = self.mtx.lock().unwrap();
|
||||
|
||||
if let Some(element) = self.vram_image_list.iter().skip(idx).next() {
|
||||
if element.is_palette {
|
||||
return false;
|
||||
|
|
|
@ -14,7 +14,7 @@ impl Logic {
|
|||
Logic{unadded_tim: None}
|
||||
}
|
||||
|
||||
pub fn set_unadded_tim(&mut self, path: &PathBuf) -> Result<Image, Error> {
|
||||
pub fn set_unadded_tim(&mut self, path: &PathBuf) -> Result<(Image, Option<Image>), Error> {
|
||||
let tim_info = TIMInfo::from_image(path)?;
|
||||
let image = tim_info.get_slint_images();
|
||||
|
||||
|
@ -22,7 +22,7 @@ impl Logic {
|
|||
Ok(image)
|
||||
}
|
||||
|
||||
pub fn add_unadded_tim_as(&mut self, _name: &String) -> Result<Image, Error> {
|
||||
pub fn add_unadded_tim_as(&mut self, _name: &String) -> Result<(Image, Option<Image>), Error> {
|
||||
if let Some(unadded_tim) = &self.unadded_tim {
|
||||
let image = unadded_tim.get_slint_images();
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ impl TIMInfo {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_slint_images(&self) -> slint::Image {
|
||||
slint::Image::from_rgba8_premultiplied(self.image_data.clone())
|
||||
pub fn get_slint_images(&self) -> (slint::Image, Option<slint::Image>) {
|
||||
(slint::Image::from_rgba8_premultiplied(self.image_data.clone()), None)
|
||||
}
|
||||
}
|
|
@ -58,7 +58,7 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefC
|
|||
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 = logic.borrow_mut().set_unadded_tim(&file)?;
|
||||
let (image, palette_image) = logic.borrow_mut().set_unadded_tim(&file)?;
|
||||
|
||||
let img_size = image.size();
|
||||
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
|
||||
|
@ -75,9 +75,10 @@ fn setup_file_tab(gui_elements_ref: Rc<RefCell<GUIElements>>, logic_ref: Rc<RefC
|
|||
let main_tab = &mut gui_elements.main_tab;
|
||||
let file_tab = &gui_elements.file_tab;
|
||||
|
||||
let file_name = file_tab.get_file_name();
|
||||
main_tab.add_new_vram_file(&file_name, logic.borrow_mut().add_unadded_tim_as(&file_name)?);
|
||||
let file_name = file_tab.get_file_name();
|
||||
let (image, palette_image) = logic.borrow_mut().add_unadded_tim_as(&file_name)?;
|
||||
|
||||
main_tab.add_new_vram_file(&file_name, image, palette_image);
|
||||
file_tab.clear_load();
|
||||
main_window.invoke_change_to_main();
|
||||
Ok(())
|
||||
|
|
|
@ -2,10 +2,11 @@ import { VRAMArea } from "../vram-components.slint";
|
|||
import { Button, ComboBox, GroupBox, StandardListView } from "std-widgets.slint";
|
||||
|
||||
struct VRAMImage {
|
||||
img: image,
|
||||
x: int,
|
||||
y: int,
|
||||
is_palette: bool,
|
||||
img: image,
|
||||
x: int,
|
||||
y: int,
|
||||
palette_count: int,
|
||||
is_palette: bool,
|
||||
}
|
||||
|
||||
export component MainTab inherits Rectangle {
|
||||
|
|
Loading…
Reference in New Issue