Update name of VRAM images to reflect data
This commit is contained in:
parent
5ccf593963
commit
6a1b87cdb1
|
@ -1,28 +1,28 @@
|
||||||
mod callbacks;
|
mod callbacks;
|
||||||
|
|
||||||
use crate::{gui::{MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, VRAMImage};
|
use crate::{gui::{MutexTIMManager, VRAM_HEIGHT, VRAM_WIDTH}, VRAMImgData, VRAMInfo, VRAMData};
|
||||||
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::tim::types::Encoding;
|
||||||
|
|
||||||
struct VRAM {
|
struct VRAM {
|
||||||
count: usize,
|
count: usize,
|
||||||
file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
|
file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
|
||||||
image_list: Rc<slint::VecModel<VRAMImage>>
|
info: Rc<slint::VecModel<VRAMData>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VRAM {
|
impl VRAM {
|
||||||
pub fn push(&mut self, name: slint::StandardListViewItem, image: VRAMImage) {
|
pub fn push(&mut self, name: slint::StandardListViewItem, image: VRAMData) {
|
||||||
self.file_list.push(name);
|
self.file_list.push(name);
|
||||||
self.image_list.push(image);
|
self.info.push(image);
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, idx: usize) {
|
pub fn remove(&mut self, idx: usize) {
|
||||||
self.count -= 1;
|
self.count -= 1;
|
||||||
self.file_list.remove(idx);
|
self.file_list.remove(idx);
|
||||||
self.image_list.remove(idx);
|
self.info.remove(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pop(&mut self) {
|
pub fn pop(&mut self) {
|
||||||
|
@ -40,12 +40,12 @@ impl MainTab {
|
||||||
pub fn new(main_window: MainWindowRef, tim_manager: MutexTIMManager) -> SharedMainTab {
|
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: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_file_list = Rc::new(slint::VecModel::from(vram_file_list));
|
||||||
let vram_image_list = Rc::new(slint::VecModel::from(Vec::<VRAMImage>::new()));
|
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_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_data(info.clone().into());
|
||||||
|
|
||||||
let object = SharedMainTab::new(MainTab{vram: Arc::new(Mutex::new(VRAM{count: 0, file_list: vram_file_list, image_list: vram_image_list}))}.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());
|
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| {
|
main_window.borrow().on_move_vram_image(move |idx, dx, dy| {
|
||||||
|
@ -63,14 +63,18 @@ impl MainTab {
|
||||||
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, image: slint::Image, encoding: Encoding, palette_count: i32, is_palette: bool| {
|
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 encoding_str = if is_palette {"<Palette>"} else {encoding.to_str()};
|
||||||
let vram_image = VRAMImage{
|
let vram_image = VRAMData {
|
||||||
full_img: full_image,
|
images: VRAMImgData {
|
||||||
img: image,
|
full_image,
|
||||||
x: 0,
|
image
|
||||||
y: 0,
|
},
|
||||||
encoding_str: SharedString::from(encoding_str),
|
info: VRAMInfo {
|
||||||
palette_count,
|
x: 0,
|
||||||
is_palette,
|
y: 0,
|
||||||
|
encoding_str: SharedString::from(encoding_str),
|
||||||
|
palette_count,
|
||||||
|
is_palette,
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
vram_data.push(slint::StandardListViewItem::from(file_name.as_str()), vram_image);
|
vram_data.push(slint::StandardListViewItem::from(file_name.as_str()), vram_image);
|
||||||
|
@ -91,13 +95,13 @@ impl MainTab {
|
||||||
pub fn remove_vram_file(&mut self, idx: usize) -> Result<RangeInclusive<usize>, &'static str> {
|
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 mut vram_data = self.vram.lock().expect("VRAM already locked");
|
||||||
let extras = {
|
let extras = {
|
||||||
if let Some(element) = vram_data.image_list.iter().skip(idx).next() {
|
if let Some(element) = vram_data.info.iter().skip(idx).next() {
|
||||||
if element.is_palette {
|
if element.info.is_palette {
|
||||||
return Err("Can not remove palette. Delete image instead");
|
return Err("Can not remove palette. Delete image instead");
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
element.palette_count as usize
|
element.info.palette_count as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,28 +130,38 @@ impl MainTab {
|
||||||
|
|
||||||
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) {
|
||||||
let vram_data = self.vram.lock().expect("VRAM already locked");
|
let vram_data = self.vram.lock().expect("VRAM already locked");
|
||||||
if let Some(mut vram_info) = vram_data.image_list.row_data(idx) {
|
if let Some(mut vram_info) = vram_data.info.row_data(idx) {
|
||||||
vram_info.x += dx;
|
vram_info.info.x += dx;
|
||||||
vram_info.y += dy;
|
vram_info.info.y += dy;
|
||||||
|
|
||||||
if vram_info.x < 0 {
|
if vram_info.info.x < 0 {
|
||||||
vram_info.x = 0;
|
vram_info.info.x = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if vram_info.y < 0 {
|
if vram_info.info.y < 0 {
|
||||||
vram_info.y = 0;
|
vram_info.info.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (vram_img_width, vram_img_height) = (vram_info.img.size().width as i32, vram_info.img.size().height as i32);
|
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.x + vram_img_width) > VRAM_WIDTH as i32 {
|
if (vram_info.info.x + vram_img_width) > VRAM_WIDTH as i32 {
|
||||||
vram_info.x = VRAM_WIDTH as i32 - vram_img_width;
|
vram_info.info.x = VRAM_WIDTH as i32 - vram_img_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vram_info.y + vram_img_height) > VRAM_HEIGHT as i32 {
|
if (vram_info.info.y + vram_img_height) > VRAM_HEIGHT as i32 {
|
||||||
vram_info.y = VRAM_HEIGHT as i32 - vram_img_height;
|
vram_info.info.y = VRAM_HEIGHT as i32 - vram_img_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
vram_data.image_list.set_row_data(idx, vram_info);
|
vram_data.info.set_row_data(idx, vram_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*pub fn _clone_vram_images(&self) -> Vec<VRAMInfo> {
|
||||||
|
let vram_data = self.vram.lock().expect("VRAM already locked");
|
||||||
|
let mut images = Vec::new();
|
||||||
|
|
||||||
|
for image in vram_data.image_list.iter() {
|
||||||
|
images.push(image.clone());
|
||||||
|
}
|
||||||
|
images
|
||||||
|
}*/
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ export component MainWindow inherits Window {
|
||||||
// Main Tab values
|
// Main Tab values
|
||||||
in-out property main_tab_vram_bg <=> main_tab.vram_bg;
|
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_file_list <=> main_tab.vram_files;
|
||||||
in-out property main_tab_vram_images <=> main_tab.vram_images;
|
in-out property main_tab_vram_data <=> main_tab.vram_data;
|
||||||
callback main_tab_remove_file_clicked <=> main_tab.remove_file_clicked;
|
callback main_tab_remove_file_clicked <=> main_tab.remove_file_clicked;
|
||||||
callback move_vram_image <=> main_tab.move_vram_image;
|
callback move_vram_image <=> main_tab.move_vram_image;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import { VRAMArea } from "../vram-components.slint";
|
import { VRAMArea } from "../vram-components.slint";
|
||||||
import { Button, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView, Slider } from "std-widgets.slint";
|
import { Button, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView, Slider } from "std-widgets.slint";
|
||||||
|
|
||||||
struct VRAMImage {
|
struct VRAMImgData {
|
||||||
full_img: image,
|
full_image: image,
|
||||||
img: image,
|
image: image,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct VRAMInfo {
|
||||||
x: int,
|
x: int,
|
||||||
y: int,
|
y: int,
|
||||||
encoding_str: string,
|
encoding_str: string,
|
||||||
|
@ -11,11 +14,16 @@ struct VRAMImage {
|
||||||
is_palette: bool,
|
is_palette: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct VRAMData {
|
||||||
|
images: VRAMImgData,
|
||||||
|
info: VRAMInfo,
|
||||||
|
}
|
||||||
|
|
||||||
export component MainTab inherits Rectangle {
|
export component MainTab inherits Rectangle {
|
||||||
property <float> scale: 1.0;
|
property <float> scale: 1.0;
|
||||||
in-out property <image> vram_bg;
|
in-out property <image> vram_bg;
|
||||||
in-out property <[StandardListViewItem]> vram_files: [];
|
in-out property <[StandardListViewItem]> vram_files: [];
|
||||||
in-out property <[VRAMImage]> vram_images: [];
|
in-out property <[VRAMData]> vram_data: [];
|
||||||
|
|
||||||
callback add_file_clicked();
|
callback add_file_clicked();
|
||||||
callback remove_file_clicked(int);
|
callback remove_file_clicked(int);
|
||||||
|
@ -54,12 +62,12 @@ export component MainTab inherits Rectangle {
|
||||||
scale: scale;
|
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;
|
x: root.get_border_width()*1px;
|
||||||
y: root.get_border_width()*1px;
|
y: root.get_border_width()*1px;
|
||||||
img: vram_image.img;
|
img: vram_data.images.image;
|
||||||
img_x: vram_image.x;
|
img_x: vram_data.info.x;
|
||||||
img_y: vram_image.y;
|
img_y: vram_data.info.y;
|
||||||
scale: scale;
|
scale: scale;
|
||||||
|
|
||||||
TouchArea {
|
TouchArea {
|
||||||
|
@ -82,8 +90,8 @@ export component MainTab inherits Rectangle {
|
||||||
if event.kind == PointerEventKind.down {
|
if event.kind == PointerEventKind.down {
|
||||||
cur_sel_x.text = parent.img_x;
|
cur_sel_x.text = parent.img_x;
|
||||||
cur_sel_y.text = parent.img_y;
|
cur_sel_y.text = parent.img_y;
|
||||||
cur_sel_img.source = vram-image.full_img;
|
cur_sel_img.source = vram_data.images.full_image;
|
||||||
encoding_text.encoding_str = vram-image.encoding_str;
|
encoding_text.encoding_str = vram_data.info.encoding_str;
|
||||||
cur_sel_img.visible = true;
|
cur_sel_img.visible = true;
|
||||||
|
|
||||||
vram_files_list.current-item = i;
|
vram_files_list.current-item = i;
|
||||||
|
@ -154,10 +162,10 @@ export component MainTab inherits Rectangle {
|
||||||
model: root.vram_files;
|
model: root.vram_files;
|
||||||
|
|
||||||
current-item-changed(current-item) => {
|
current-item-changed(current-item) => {
|
||||||
cur_sel_x.text = root.vram_images[current-item].x;
|
cur_sel_x.text = root.vram_data[current-item].info.x;
|
||||||
cur_sel_y.text = root.vram_images[current-item].y;
|
cur_sel_y.text = root.vram_data[current-item].info.y;
|
||||||
cur_sel_img.source = root.vram_images[current-item].full_img;
|
cur_sel_img.source = root.vram_data[current-item].images.full_image;
|
||||||
encoding_text.encoding_str = root.vram_images[current-item].encoding_str;
|
encoding_text.encoding_str = root.vram_data[current-item].info.encoding_str;
|
||||||
cur_sel_img.visible = true;
|
cur_sel_img.visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,8 +218,8 @@ export component MainTab inherits Rectangle {
|
||||||
|
|
||||||
accepted(text) => {
|
accepted(text) => {
|
||||||
if(vram_files_list.current-item != -1) {
|
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);
|
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_images[vram_files_list.current-item].x;
|
self.text = vram_data[vram_files_list.current-item].info.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,8 +239,8 @@ export component MainTab inherits Rectangle {
|
||||||
|
|
||||||
accepted(text) => {
|
accepted(text) => {
|
||||||
if(vram_files_list.current-item != -1) {
|
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);
|
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_images[vram_files_list.current-item].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(vram_files_list.current-item != -1) {
|
||||||
if(event.text == Key.LeftArrow) {
|
if(event.text == Key.LeftArrow) {
|
||||||
root.move_vram_image(vram_files_list.current-item, -1, 0);
|
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) {
|
if(event.text == Key.RightArrow) {
|
||||||
root.move_vram_image(vram_files_list.current-item, 1, 0);
|
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) {
|
if(event.text == Key.UpArrow) {
|
||||||
root.move_vram_image(vram_files_list.current-item, 0, -1);
|
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) {
|
if(event.text == Key.DownArrow) {
|
||||||
root.move_vram_image(vram_files_list.current-item, 0, 1);
|
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
|
accept
|
||||||
|
|
Loading…
Reference in New Issue