Compare commits

..

6 Commits

Author SHA1 Message Date
Jaby 13c051715e Support bundeling applications; Set icon for TIM Tool 2025-02-12 22:22:40 +01:00
Jaby 9146bf94a5 Restructure code a bit 2025-02-12 21:47:38 +01:00
Jaby 3054fab315 Retrieve file conversion path 2025-02-10 22:16:25 +01:00
Jaby 7f831bc09b Support loading image 2025-02-09 19:31:42 +01:00
Jaby 3009b11675 Support preview image 2025-02-09 17:17:39 +01:00
Jaby 3e0fb8396d Support proper background and coordinates now 2025-02-09 17:00:24 +01:00
10 changed files with 319 additions and 93 deletions

View File

@ -6,4 +6,4 @@ RUST_VERSION=1.84.0
echo "<<< Install Rust $RUST_VERSION >>>"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain=$RUST_VERSION -y
. "$HOME/.cargo/env"
cargo install cargo-edit --locked
cargo install cargo-edit cargo-bundle --locked

View File

@ -50,7 +50,7 @@
{
"id": "cargo cmd",
"type":"pickString",
"options": ["build", "check", "upgrade", "clean", "run", "tree"],
"options": ["build", "check", "run", "upgrade", "clean", "bundle"],
"default": "build",
"description": "cargo command to run"
}

View File

@ -7,7 +7,21 @@ edition = "2021"
panic = "abort"
[dependencies]
rfd = "0.15.2"
slint = "1.9.2"
tiny-skia = "0.11.4"
tool_helper = {path = "../tool_helper"}
[build-dependencies]
slint-build = "1.9.2"
[package.metadata.bundle]
name = "TIMTOOL"
identifier = "zone.jabyengine.timtool"
icon = ["ui/assets/TimTool64x64.png"]
copyright = "Copyright (c) 2025 Jaby MIT License"
category = "Developer Tool"
short_description = "TIM Tool for JabyEngine"
long_description = """
A new interpetation of the TIM Tool from Sony, for use with PSYQ and the JabyEngine
"""

View File

@ -0,0 +1,78 @@
use crate::{gui::{VRAM_HEIGHT, VRAM_WIDTH, create_vram_bg}, MainWindow, VRAMImage};
use slint::Model;
use std::{cell::RefCell, ffi::OsStr, path::PathBuf, rc::Rc};
use tool_helper::Error;
pub struct GUIElements {
pub main_window: Rc<RefCell<MainWindow>>,
vram_file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
vram_image_list: Rc<slint::VecModel<VRAMImage>>,
}
impl GUIElements {
pub fn new(main_window: Rc<RefCell<MainWindow>>) -> GUIElements {
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());
GUIElements{main_window, vram_file_list, vram_image_list}
}
pub fn add_new_vram_file(&mut self, file: PathBuf) -> Result<(), Error> {
let vram_image = VRAMImage{
img: slint::Image::load_from_path(&file).or_else(|_| {Err(Error::from_str("Failed loading image"))})?,
x: 0,
y: 0
};
let img_size = vram_image.img.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)));
}
let file_name = file.file_name().get_or_insert(OsStr::new("<No file name>")).to_string_lossy().to_string();
self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str()));
self.vram_image_list.push(vram_image);
Ok(())
}
pub fn remove_vram_file(&mut self, idx: usize) {
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) > 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;
}
self.vram_image_list.set_row_data(idx, vram_info);
}
}
pub 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()))?))
}
}

View File

@ -0,0 +1,35 @@
mod gui_elements;
use slint::{Rgba8Pixel, SharedPixelBuffer};
use tiny_skia::{Rect, Transform};
pub use gui_elements::GUIElements;
pub const VRAM_WIDTH:usize = 1024;
pub const VRAM_HEIGHT:usize = 512;
pub fn create_vram_bg(rect_width: u32, rect_height: u32) -> Option<SharedPixelBuffer<Rgba8Pixel>> {
let mut pixel_buffer = SharedPixelBuffer::<Rgba8Pixel>::new(VRAM_WIDTH as u32, VRAM_HEIGHT as u32);
let width = pixel_buffer.width();
let height = pixel_buffer.height();
if let Some(mut pixmap) = tiny_skia::PixmapMut::from_bytes(pixel_buffer.make_mut_bytes(), width, height) {
let vram_color = tiny_skia::Color::from_rgba8(0x0, 0x80, 0x80, 0xFF);
let display_buffer_color = tiny_skia::Color::from_rgba8(0x0, 0x80, 0x0, 0xFF);
let draw_area_color = tiny_skia::Color::from_rgba8(0x80, 0x80, 0x0, 0xFF);
let mut paint = tiny_skia::Paint::default();
pixmap.fill(vram_color);
paint.set_color(display_buffer_color);
pixmap.fill_rect(Rect::from_xywh(0.0, 0.0, rect_width as f32, rect_height as f32).unwrap(), &paint, Transform::identity(), None);
paint.set_color(draw_area_color);
pixmap.fill_rect(Rect::from_xywh(0.0, rect_height as f32, rect_width as f32, rect_height as f32).unwrap(), &paint, Transform::identity(), None);
Some(pixel_buffer)
}
else {
None
}
}

View File

@ -1,88 +1,66 @@
// Prevent console window in addition to Slint window in Windows release builds when, e.g., starting the app via file manager. Ignored on other platforms.
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use slint::Model;
use std::{cell::RefCell, path::Path, rc::Rc};
mod gui;
use gui::GUIElements;
use rfd::{FileDialog, MessageDialog};
use std::{cell::RefCell, rc::Rc};
use slint::SharedString;
slint::include_modules!();
struct GUIElements {
vram_file_list: Rc<slint::VecModel<slint::StandardListViewItem>>,
vram_image_list: Rc<slint::VecModel<VRAMImage>>
}
impl GUIElements {
pub fn new(main_window: &MainWindow) -> GUIElements {
let vram_file_list:Vec<slint::StandardListViewItem> = main_window.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.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) {
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) {
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);
}
}
}
fn main() -> Result<(), slint::PlatformError> {
let main_window = MainWindow::new()?;
let gui_elements = Rc::new(RefCell::new(GUIElements::new(&main_window)));
let main_window = Rc::new(RefCell::new(MainWindow::new()?));
let gui_elements = Rc::new(RefCell::new(GUIElements::new(main_window.clone())));
let main_window = main_window.borrow();
main_window.set_main_tab_vram_bg(GUIElements::create_bg()?);
let gui_elements_cloned = gui_elements.clone();
main_window.on_main_tab_add_file_clicked(move || {
gui_elements_cloned.borrow_mut().add_new_vram_file("Planschi");
});
let gui_elements_cloned = gui_elements.clone();
main_window.on_main_tab_remove_file_clicked(move |idx: i32| {
if idx >= 0 {
gui_elements_cloned.borrow_mut().remove_vram_file(idx as usize);
let mut gui_elements = gui_elements_cloned.borrow_mut();
let file = FileDialog::new()
.add_filter("Images", &["png", "bmp", "jpeg"])
.add_filter("All", &[""])
.set_title("Add TIM image")
.pick_file();
if let Some(file) = file {
if let Result::Err(error) = gui_elements.add_new_vram_file(file) {
MessageDialog::new().set_title("Loading Image failed").set_level(rfd::MessageLevel::Error).set_description(error.to_string()).show();
}
}
});
let gui_elements_cloned = gui_elements.clone();
main_window.on_main_tab_remove_file_clicked(move |idx: i32| {
let mut gui_elements = gui_elements_cloned.borrow_mut();
if idx >= 0 {
gui_elements.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);
let mut gui_elements = gui_elements_cloned.borrow_mut();
gui_elements.move_vram_image(idx as usize, dx, dy);
});
let gui_elements_cloned = gui_elements.clone();
main_window.on_file_tab_browse_convert_image(move || {
let gui_elements = gui_elements_cloned.borrow_mut();
let file = FileDialog::new()
.add_filter("Images", &["png", "bmp", "jpeg"])
.add_filter("All", &[""])
.set_title("Select image file")
.pick_file();
if let Some(file) = file {
let main_window = gui_elements.main_window.borrow();
if let Some(file_path) = file.to_str() {
main_window.set_file_tab_browse_path(SharedString::from(file_path));
}
}
});
main_window.run()

View File

@ -4,12 +4,18 @@ import { MainTab } from "./tab/main-tab.slint";
import { TabWidget } from "std-widgets.slint";
export component MainWindow inherits Window {
in-out property main_tab_vram_file_list <=> tab.vram_files;
in-out property main_tab_vram_images <=> tab.vram_images;
// 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;
callback main_tab_add_file_clicked <=> tab.add_file_clicked;
callback main_tab_remove_file_clicked <=> tab.remove_file_clicked;
callback move_vram_image <=> tab.move_vram_image;
callback main_tab_add_file_clicked <=> main_tab.add_file_clicked;
callback main_tab_remove_file_clicked <=> main_tab.remove_file_clicked;
callback move_vram_image <=> main_tab.move_vram_image;
// Convert Image values
in-out property file_tab_browse_path <=> file_tab.conv_image_path;
callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked;
title: "TIM Tool 0.1.0";
width: tab_widget.width;
@ -18,20 +24,20 @@ export component MainWindow inherits Window {
tab_widget := TabWidget {
x: 0px;
y: 0px;
width: tab.width;
height: tab.height;
width: main_tab.width;
height: main_tab.height;
current-index: 1;
Tab {
title: "File";
FileTab {
file_tab := FileTab {
x: 0px;
y: 0px;
}
}
Tab {
title: "VRAM Layout";
tab := MainTab {
main_tab := MainTab {
x: 0px;
y: 0px;
}

BIN
src/Tools/tim_tool/ui/assets/TimTool64x64.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -1,3 +1,94 @@
export component FileTab inherits Rectangle {
import { Button, TabWidget, LineEdit, GroupBox } from "std-widgets.slint";
enum State {
ConvertImage,
Test
}
component ConvertImageWidget inherits Rectangle {
in-out property <string> path;
callback browse_clicked();
background: #D0D0D0;
width: 100%;
height: 100%;
GroupBox {
title: "Convert image to TIM";
x: 4px;
y: 4px;
VerticalLayout {
alignment: start;
Text {
text: "Select image file to convert to TIM";
}
LineEdit {
width: 200%;
text: path;
}
HorizontalLayout {
alignment: start;
padding: 4px;
Button {
text: "Browse";
clicked => {browse_clicked();}
}
Button {
text: "Convert";
}
}
}
}
}
component TestWidget inherits Rectangle {
Text {
text: "!!Planschbecken!!";
}
}
export component FileTab inherits Rectangle {
in-out property <string> conv_image_path;
callback conv_image_browse_clicked;
property <State> state: ConvertImage;
x: 0px;
y: 0px;
HorizontalLayout {
padding: 4px;
VerticalLayout {
padding: 4px;
width: 20%;
alignment: start;
Button {
text: "Convert image file";
clicked => {
root.state = State.ConvertImage;
}
}
Button {
text: "Testing";
clicked => {
root.state = State.Test;
}
}
}
VerticalLayout {
padding: 4px;
alignment: start;
if root.state == State.ConvertImage : ConvertImageWidget {
path <=> root.conv_image_path;
browse_clicked => {
root.conv_image_browse_clicked();
}
}
if root.state == State.Test : TestWidget {
}
}
}
}

View File

@ -8,6 +8,7 @@ struct VRAMImage {
}
export component MainTab inherits Rectangle {
in-out property <image> vram_bg;
in-out property <[StandardListViewItem]> vram_files: [];
in-out property <[VRAMImage]> vram_images: [];
@ -33,7 +34,7 @@ export component MainTab inherits Rectangle {
background_image := VRAMArea {
x: root.get_border_width()*1px;
y: root.get_border_width()*1px;
img: @image-url("../../../../../examples/PoolBox/assets/AllTheJaby.png");
img: vram_bg;
img_x: 0;
img_y: 0;
}
@ -53,12 +54,19 @@ export component MainTab inherits Rectangle {
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);
cur_sel_x.display_value = parent.img_x;
cur_sel_y.display_value = parent.img_y;
}
pointer-event(event) => {
if event.kind == PointerEventKind.up {
self.mouse-cursor = MouseCursor.grab;
}
if event.kind == PointerEventKind.down {
cur_sel_x.display_value = parent.img_x;
cur_sel_y.display_value = parent.img_y;
cur_sel_img.source = parent.img;
}
}
// Thanks to Cody the white tiger
@ -83,7 +91,7 @@ export component MainTab inherits Rectangle {
HorizontalLayout {
padding: 4px;
GroupBox {
title: "Added Files";
title: "Added TIMs";
VerticalLayout {
alignment: start;
padding: 4px;
@ -95,11 +103,11 @@ export component MainTab inherits Rectangle {
HorizontalLayout {
padding: 4px;
Button {
text: "Add File";
text: "Add TIM";
clicked => {root.add_file_clicked();}
}
Button {
text: "Remove File";
text: "Remove TIM";
clicked => {
root.remove_file_clicked(vram_files_list.current_item);
vram_files_list.current-item = -1;
@ -116,6 +124,19 @@ export component MainTab inherits Rectangle {
width: 128px;
height: 128px;
background: #A0A0A0;
cur_sel_img := Image {
width: 128px;
height: 128px;
image-fit: contain;
}
}
cur_sel_x := Text {
in-out property <int> display_value;
text: "X: " + display_value;
}
cur_sel_y :=Text {
in-out property <int> display_value;
text: "Y: " + display_value;
}
ComboBox {
model: ["4-bit", "16-bit", "24-bit"];