Get moving tiles sorted
This commit is contained in:
parent
a9fd194672
commit
2993fa661a
|
@ -2,29 +2,67 @@
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use slint::Model;
|
use slint::Model;
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, path::Path, rc::Rc};
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
struct GUIElements {
|
struct GUIElements {
|
||||||
tab_vram_file_list: Rc<slint::VecModel<slint::StandardListViewItem>>
|
vram_file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
|
||||||
|
vram_image_list: Rc<slint::VecModel<VRAMImage>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GUIElements {
|
impl GUIElements {
|
||||||
pub fn new(main_window: &MainWindow) -> GUIElements {
|
pub fn new(main_window: &MainWindow) -> GUIElements {
|
||||||
let tab_vram_file_list:Vec<slint::StandardListViewItem> = main_window.get_main_tab_vram_file_list().iter().collect();
|
let vram_file_list:Vec<slint::StandardListViewItem> = main_window.get_main_tab_vram_file_list().iter().collect();
|
||||||
let tab_vram_file_list = Rc::new(slint::VecModel::from(tab_vram_file_list));
|
let vram_file_list = Rc::new(slint::VecModel::from(vram_file_list));
|
||||||
|
|
||||||
main_window.set_main_tab_vram_file_list(tab_vram_file_list.clone().into());
|
let vram_image_list = Rc::new(slint::VecModel::from(Vec::<VRAMImage>::new()));
|
||||||
GUIElements{tab_vram_file_list}
|
|
||||||
|
main_window.set_main_tab_vram_file_list(vram_file_list.clone().into());
|
||||||
|
main_window.set_main_tab_vram_images(vram_image_list.clone().into());
|
||||||
|
GUIElements{vram_file_list, vram_image_list}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_new_vram_file(&mut self, file: &str) {
|
pub fn add_new_vram_file(&mut self, file: &str) {
|
||||||
self.tab_vram_file_list.push(slint::StandardListViewItem::from(file));
|
let vram_image = VRAMImage{
|
||||||
|
img: slint::Image::load_from_path(Path::new("/home/jaby/Desktop/PSX_Dev/jabyengine/examples/PoolBox/assets/IMG_6921.png")).unwrap(),
|
||||||
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
};
|
||||||
|
|
||||||
|
self.vram_file_list.push(slint::StandardListViewItem::from(file));
|
||||||
|
self.vram_image_list.push(vram_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_vram_file(&mut self, idx: usize) {
|
pub fn remove_vram_file(&mut self, idx: usize) {
|
||||||
self.tab_vram_file_list.remove(idx);
|
self.vram_file_list.remove(idx);
|
||||||
|
self.vram_image_list.remove(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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) > 1024 {
|
||||||
|
vram_info.x = 1024 - vram_img_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vram_info.y + vram_img_width) > 512 {
|
||||||
|
vram_info.y = 512 - vram_img_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.vram_image_list.set_row_data(idx, vram_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,5 +80,10 @@ fn main() -> Result<(), slint::PlatformError> {
|
||||||
gui_elements_cloned.borrow_mut().remove_vram_file(idx as usize);
|
gui_elements_cloned.borrow_mut().remove_vram_file(idx as usize);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
let gui_elements_cloned = gui_elements.clone();
|
||||||
|
main_window.on_move_vram_image(move |idx: i32, dx: i32, dy: i32| {
|
||||||
|
gui_elements_cloned.borrow_mut().move_vram_image(idx as usize, dx, dy);
|
||||||
|
});
|
||||||
|
|
||||||
main_window.run()
|
main_window.run()
|
||||||
}
|
}
|
|
@ -5,9 +5,11 @@ import { TabWidget } from "std-widgets.slint";
|
||||||
|
|
||||||
export component MainWindow inherits Window {
|
export component MainWindow inherits Window {
|
||||||
in-out property main_tab_vram_file_list <=> tab.vram_files;
|
in-out property main_tab_vram_file_list <=> tab.vram_files;
|
||||||
|
in-out property main_tab_vram_images <=> tab.vram_images;
|
||||||
|
|
||||||
callback main_tab_add_file_clicked <=> tab.add_file_clicked;
|
callback main_tab_add_file_clicked <=> tab.add_file_clicked;
|
||||||
callback main_tab_remove_file_clicked <=> tab.remove_file_clicked;
|
callback main_tab_remove_file_clicked <=> tab.remove_file_clicked;
|
||||||
|
callback move_vram_image <=> tab.move_vram_image;
|
||||||
|
|
||||||
title: "TIM Tool 0.1.0";
|
title: "TIM Tool 0.1.0";
|
||||||
width: tab_widget.width;
|
width: tab_widget.width;
|
||||||
|
|
|
@ -2,9 +2,9 @@ import { VRAMArea } from "../vram-components.slint";
|
||||||
import { Button, ComboBox, GroupBox, StandardListView } from "std-widgets.slint";
|
import { Button, ComboBox, GroupBox, StandardListView } from "std-widgets.slint";
|
||||||
|
|
||||||
struct VRAMImage {
|
struct VRAMImage {
|
||||||
img: image,
|
img: image,
|
||||||
x: int,
|
x: int,
|
||||||
y: int,
|
y: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
export component MainTab inherits Rectangle {
|
export component MainTab inherits Rectangle {
|
||||||
|
@ -13,6 +13,7 @@ export component MainTab inherits Rectangle {
|
||||||
|
|
||||||
callback add_file_clicked();
|
callback add_file_clicked();
|
||||||
callback remove_file_clicked(int);
|
callback remove_file_clicked(int);
|
||||||
|
callback move_vram_image(int, int, int);
|
||||||
|
|
||||||
width: group.width + group.x*2;
|
width: group.width + group.x*2;
|
||||||
height: group.height + group.y*2 + 32px;
|
height: group.height + group.y*2 + 32px;
|
||||||
|
@ -40,9 +41,43 @@ 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 {
|
||||||
|
x: (parent.img_x + self.lines_crossed_x())*1px;
|
||||||
|
y: (parent.img_y + self.lines_crossed_y())*1px;
|
||||||
|
width: (parent.img.width + self.lines_crossed_width())*1px;
|
||||||
|
height: (parent.img.height + self.lines_crossed_height())*1px;
|
||||||
|
mouse-cursor: grab;
|
||||||
|
moved => {
|
||||||
|
self.mouse-cursor = MouseCursor.grabbing;
|
||||||
|
root.move_vram_image(i, (self.mouse-x - self.pressed-x)/1px, (self.mouse-y - self.pressed-y)/1px);
|
||||||
|
|
||||||
|
}
|
||||||
|
pointer-event(event) => {
|
||||||
|
if event.kind == PointerEventKind.up {
|
||||||
|
self.mouse-cursor = MouseCursor.grab;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thanks to Cody the white tiger
|
||||||
|
function lines_crossed_x() -> int {
|
||||||
|
return parent.img_x/64;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lines_crossed_y() -> int {
|
||||||
|
return parent.img_y/256;
|
||||||
|
}
|
||||||
|
|
||||||
|
function lines_crossed_width() -> int {
|
||||||
|
return ((parent.img_x + parent.img.width)/64) - self.lines_crossed_x();
|
||||||
|
}
|
||||||
|
|
||||||
|
function lines_crossed_height() -> int {
|
||||||
|
return ((parent.img_y + parent.img.height)/256) - self.lines_crossed_y();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
|
|
Loading…
Reference in New Issue