Compare commits
3 Commits
3f0023e7c5
...
f68ef48296
Author | SHA1 | Date |
---|---|---|
|
f68ef48296 | |
|
10dab4c2b3 | |
|
61562a1588 |
|
@ -4,11 +4,14 @@ use super::{GUIElementsRef, MainWindowRef};
|
||||||
use slint::Model;
|
use slint::Model;
|
||||||
use std::{rc::Rc, sync::{Arc, Mutex}};
|
use std::{rc::Rc, sync::{Arc, Mutex}};
|
||||||
|
|
||||||
|
struct VRAM {
|
||||||
|
pub file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
|
||||||
|
pub image_list: Rc<slint::VecModel<VRAMImage>>
|
||||||
|
}
|
||||||
|
|
||||||
pub struct MainTab {
|
pub struct MainTab {
|
||||||
main_window: MainWindowRef,
|
main_window: MainWindowRef,
|
||||||
mtx: Arc<Mutex<i32>>,
|
vram: Arc<Mutex<VRAM>>,
|
||||||
vram_file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
|
|
||||||
vram_image_list: Rc<slint::VecModel<VRAMImage>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MainTab {
|
impl MainTab {
|
||||||
|
@ -20,43 +23,63 @@ impl MainTab {
|
||||||
main_window.borrow().set_main_tab_vram_file_list(vram_file_list.clone().into());
|
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());
|
main_window.borrow().set_main_tab_vram_images(vram_image_list.clone().into());
|
||||||
|
|
||||||
MainTab{main_window, mtx: Arc::new(Mutex::new(0)), vram_file_list, vram_image_list}
|
MainTab{main_window, vram: Arc::new(Mutex::new(VRAM{file_list: vram_file_list, image_list: vram_image_list}))}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image, image_palette: Option<slint::Image>) {
|
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_data = self.vram.lock().expect("VRAM already locked");
|
||||||
|
let add_new_image = |file_name: &String, image: slint::Image, palette_count: i32, is_palette: bool| {
|
||||||
let vram_image = VRAMImage{
|
let vram_image = VRAMImage{
|
||||||
img: image,
|
img: image,
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
palette_count: 0,
|
palette_count,
|
||||||
is_palette: false,
|
is_palette,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str()));
|
vram_data.file_list.push(slint::StandardListViewItem::from(file_name.as_str()));
|
||||||
self.vram_image_list.push(vram_image);
|
vram_data.image_list.push(vram_image);
|
||||||
};
|
};
|
||||||
|
|
||||||
let _lock = self.mtx.lock().unwrap();
|
add_new_image(file_name, image, if image_palette.is_some() {1} else {0}, false);
|
||||||
add_new_image(file_name, image);
|
if let Some(image_palette) = image_palette {
|
||||||
|
let file_name = file_name.clone() + " (Palette)";
|
||||||
|
add_new_image(&file_name, image_palette, 0, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_vram_file(&mut self, idx: usize) -> bool {
|
pub fn remove_vram_file(&mut self, idx: usize) -> bool {
|
||||||
let _lock = self.mtx.lock().unwrap();
|
let vram_data = self.vram.lock().expect("VRAM already locked");
|
||||||
|
let remove_image = |idx: usize| {
|
||||||
|
vram_data.file_list.remove(idx);
|
||||||
|
vram_data.image_list.remove(idx);
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(element) = self.vram_image_list.iter().skip(idx).next() {
|
let extras = {
|
||||||
if element.is_palette {
|
if let Some(element) = vram_data.image_list.iter().skip(idx).next() {
|
||||||
return false;
|
if element.is_palette {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
element.palette_count as usize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.vram_file_list.remove(idx);
|
else {
|
||||||
self.vram_image_list.remove(idx);
|
0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for _ in idx..=idx+extras {
|
||||||
|
remove_image(idx);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_vram_image(&mut self, idx: usize, dx: i32, dy: i32) {
|
pub fn move_vram_image(&mut self, idx: usize, dx: i32, dy: i32) {
|
||||||
if let Some(mut vram_info) = self.vram_image_list.row_data(idx) {
|
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.x += dx;
|
||||||
vram_info.y += dy;
|
vram_info.y += dy;
|
||||||
|
|
||||||
|
@ -77,7 +100,7 @@ impl MainTab {
|
||||||
vram_info.y = VRAM_HEIGHT as i32 - vram_img_height;
|
vram_info.y = VRAM_HEIGHT as i32 - vram_img_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.vram_image_list.set_row_data(idx, vram_info);
|
vram_data.image_list.set_row_data(idx, vram_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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_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 file_name = if let Some(name) = file.file_name() {Some(name.to_string_lossy().to_string())} else {None};
|
||||||
|
|
||||||
let (image, palette_image) = logic.borrow_mut().set_unadded_tim(&file)?;
|
let (image, _palette_image) = logic.borrow_mut().set_unadded_tim(&file)?;
|
||||||
|
|
||||||
let img_size = image.size();
|
let img_size = image.size();
|
||||||
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
|
if img_size.width > VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 {
|
||||||
|
|
|
@ -44,9 +44,9 @@ export component MainTab inherits Rectangle {
|
||||||
for vram_image[i] in root.vram_images: VRAMArea {
|
for vram_image[i] in root.vram_images: VRAMArea {
|
||||||
x: root.get_border_width()*1px;
|
x: root.get_border_width()*1px;
|
||||||
y: root.get_border_width()*1px;
|
y: root.get_border_width()*1px;
|
||||||
img: vram-image.img;
|
img: vram_image.img;
|
||||||
img_x: vram-image.x;
|
img_x: vram_image.x;
|
||||||
img_y: vram-image.y;
|
img_y: vram_image.y;
|
||||||
TouchArea {
|
TouchArea {
|
||||||
x: (parent.img_x + self.lines_crossed_x())*1px;
|
x: (parent.img_x + self.lines_crossed_x())*1px;
|
||||||
y: (parent.img_y + self.lines_crossed_y())*1px;
|
y: (parent.img_y + self.lines_crossed_y())*1px;
|
||||||
|
@ -65,9 +65,11 @@ export component MainTab inherits Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
if event.kind == PointerEventKind.down {
|
if event.kind == PointerEventKind.down {
|
||||||
cur_sel_x.display_value = parent.img_x;
|
cur_sel_x.display_value = parent.img_x;
|
||||||
cur_sel_y.display_value = parent.img_y;
|
cur_sel_y.display_value = parent.img_y;
|
||||||
cur_sel_img.source = parent.img;
|
cur_sel_img.source = parent.img;
|
||||||
|
cur_sel_img.visible = true;
|
||||||
|
vram_files_list.current-item = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +103,13 @@ export component MainTab inherits Rectangle {
|
||||||
width: background_image.width/2;
|
width: background_image.width/2;
|
||||||
height: 128px;
|
height: 128px;
|
||||||
model: root.vram_files;
|
model: root.vram_files;
|
||||||
|
|
||||||
|
current-item-changed(current-item) => {
|
||||||
|
cur_sel_x.display_value = root.vram_images[current-item].x;
|
||||||
|
cur_sel_y.display_value = root.vram_images[current-item].y;
|
||||||
|
cur_sel_img.source = root.vram_images[current-item].img;
|
||||||
|
cur_sel_img.visible = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
|
@ -113,6 +122,9 @@ export component MainTab inherits Rectangle {
|
||||||
clicked => {
|
clicked => {
|
||||||
root.remove_file_clicked(vram_files_list.current_item);
|
root.remove_file_clicked(vram_files_list.current_item);
|
||||||
vram_files_list.current-item = -1;
|
vram_files_list.current-item = -1;
|
||||||
|
cur_sel_x.display_value = 0;
|
||||||
|
cur_sel_y.display_value = 0;
|
||||||
|
cur_sel_img.visible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue