From 61562a1588c2e2db531cf4207f76200101abeece Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 17 Feb 2025 10:00:04 +0100 Subject: [PATCH 01/17] Improve mutex usage --- src/Tools/tim_tool/src/gui/main_tab.rs | 32 ++++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/main_tab.rs b/src/Tools/tim_tool/src/gui/main_tab.rs index 3647dfe3..13bacb9e 100644 --- a/src/Tools/tim_tool/src/gui/main_tab.rs +++ b/src/Tools/tim_tool/src/gui/main_tab.rs @@ -4,11 +4,14 @@ use super::{GUIElementsRef, MainWindowRef}; use slint::Model; use std::{rc::Rc, sync::{Arc, Mutex}}; +struct VRAM { + pub file_list: Rc>, + pub image_list: Rc> +} + pub struct MainTab { main_window: MainWindowRef, - mtx: Arc>, - vram_file_list: Rc>, - vram_image_list: Rc>, + vram: Arc>, } impl MainTab { @@ -20,10 +23,11 @@ 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, 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) { + let vram_data = self.vram.lock().expect("VRAM already locked"); let add_new_image = |file_name: &String, image: slint::Image| { let vram_image = VRAMImage{ img: image, @@ -33,30 +37,28 @@ impl MainTab { is_palette: false, }; - self.vram_file_list.push(slint::StandardListViewItem::from(file_name.as_str())); - self.vram_image_list.push(vram_image); + vram_data.file_list.push(slint::StandardListViewItem::from(file_name.as_str())); + vram_data.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() { + let vram_data = self.vram.lock().expect("VRAM already locked"); + if let Some(element) = vram_data.image_list.iter().skip(idx).next() { if element.is_palette { return false; } } - self.vram_file_list.remove(idx); - self.vram_image_list.remove(idx); + vram_data.file_list.remove(idx); + vram_data.image_list.remove(idx); return true; } 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.y += dy; @@ -77,7 +79,7 @@ impl MainTab { 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); } } -- 2.30.2 From 10dab4c2b34ed4748db50f4f6bc80e53d43f2767 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 17 Feb 2025 10:29:40 +0100 Subject: [PATCH 02/17] Handle palette in GUI --- src/Tools/tim_tool/src/gui/main_tab.rs | 43 +++++++++++++++++++------- src/Tools/tim_tool/src/main.rs | 2 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/main_tab.rs b/src/Tools/tim_tool/src/gui/main_tab.rs index 13bacb9e..7ede86cf 100644 --- a/src/Tools/tim_tool/src/gui/main_tab.rs +++ b/src/Tools/tim_tool/src/gui/main_tab.rs @@ -28,31 +28,52 @@ impl MainTab { pub fn add_new_vram_file(&mut self, file_name: &String, image: slint::Image, image_palette: Option) { let vram_data = self.vram.lock().expect("VRAM already locked"); - let add_new_image = |file_name: &String, image: slint::Image| { + let add_new_image = |file_name: &String, image: slint::Image, palette_count: i32, is_palette: bool| { let vram_image = VRAMImage{ img: image, x: 0, y: 0, - palette_count: 0, - is_palette: false, + palette_count, + is_palette, }; vram_data.file_list.push(slint::StandardListViewItem::from(file_name.as_str())); vram_data.image_list.push(vram_image); }; - add_new_image(file_name, image); + + add_new_image(file_name, image, if image_palette.is_some() {1} else {0}, false); + 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 { let vram_data = self.vram.lock().expect("VRAM already locked"); - if let Some(element) = vram_data.image_list.iter().skip(idx).next() { - if element.is_palette { - return false; - } - } + let remove_image = |idx: usize| { + vram_data.file_list.remove(idx); + vram_data.image_list.remove(idx); + }; - vram_data.file_list.remove(idx); - vram_data.image_list.remove(idx); + let extras = { + if let Some(element) = vram_data.image_list.iter().skip(idx).next() { + if element.is_palette { + return false; + } + + else { + element.palette_count as usize + } + } + + else { + 0 + } + }; + + for _ in idx..=idx+extras { + remove_image(idx); + } return true; } diff --git a/src/Tools/tim_tool/src/main.rs b/src/Tools/tim_tool/src/main.rs index 3506d5a5..aa2d1a58 100644 --- a/src/Tools/tim_tool/src/main.rs +++ b/src/Tools/tim_tool/src/main.rs @@ -58,7 +58,7 @@ fn setup_file_tab(gui_elements_ref: Rc>, logic_ref: Rc VRAM_WIDTH as u32 || img_size.height > VRAM_HEIGHT as u32 { -- 2.30.2 From f68ef482967bf9879562db09fb183c6bab779c31 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 17 Feb 2025 10:55:20 +0100 Subject: [PATCH 03/17] GUI improvements --- src/Tools/tim_tool/ui/tab/main-tab.slint | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index dc3b1a0f..2f0e6c66 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -44,9 +44,9 @@ export component MainTab inherits Rectangle { for vram_image[i] in root.vram_images: VRAMArea { x: root.get_border_width()*1px; y: root.get_border_width()*1px; - img: vram-image.img; - img_x: vram-image.x; - img_y: vram-image.y; + img: vram_image.img; + img_x: vram_image.x; + img_y: vram_image.y; TouchArea { x: (parent.img_x + self.lines_crossed_x())*1px; y: (parent.img_y + self.lines_crossed_y())*1px; @@ -65,9 +65,11 @@ export component MainTab inherits Rectangle { } 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; + cur_sel_x.display_value = parent.img_x; + cur_sel_y.display_value = parent.img_y; + 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; height: 128px; 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 { padding: 4px; @@ -113,6 +122,9 @@ export component MainTab inherits Rectangle { clicked => { root.remove_file_clicked(vram_files_list.current_item); vram_files_list.current-item = -1; + cur_sel_x.display_value = 0; + cur_sel_y.display_value = 0; + cur_sel_img.visible = false; } } } -- 2.30.2 From fb1ecf17c5c7406f884a60b3b21462f0c068b529 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 17 Feb 2025 11:29:47 +0100 Subject: [PATCH 04/17] Load palette --- src/Tools/tim_tool/src/logic/tim.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Tools/tim_tool/src/logic/tim.rs b/src/Tools/tim_tool/src/logic/tim.rs index 025eed4e..571953a7 100644 --- a/src/Tools/tim_tool/src/logic/tim.rs +++ b/src/Tools/tim_tool/src/logic/tim.rs @@ -71,6 +71,22 @@ impl TIMInfo { } pub fn get_slint_images(&self) -> (slint::Image, Option) { - (slint::Image::from_rgba8_premultiplied(self.image_data.clone()), None) + (slint::Image::from_rgba8_premultiplied(self.image_data.clone()), if let Some(palette) = &self.palette { + let width = if palette.len() <= 16 {16} else {256}; + Some(Self::get_palette_image(palette, width, 1)) + } else { + None + }) + } + + fn get_palette_image(palette: &Vec, width: u32, height: u32) -> slint::Image { + let mut image_data = SharedPixelBuffer::new(width, height); + let dst_pixels = image_data.make_mut_slice(); + + for (idx, byte) in dst_pixels.iter_mut().enumerate() { + *byte = if idx < palette.len() {palette[idx]} else {Rgba8Pixel::new(0, 0, 0, 0xFF)}; + } + + slint::Image::from_rgba8_premultiplied(image_data.clone()) } } \ No newline at end of file -- 2.30.2 From b4c6cb70b6ad51a5dfefcfa4fe3643f680869d84 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 17 Feb 2025 16:53:35 +0100 Subject: [PATCH 05/17] Make image pos editable --- src/Tools/tim_tool/src/gui/main_tab.rs | 2 +- src/Tools/tim_tool/ui/tab/main-tab.slint | 68 ++++++++++++++++++------ 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/main_tab.rs b/src/Tools/tim_tool/src/gui/main_tab.rs index 7ede86cf..84db3017 100644 --- a/src/Tools/tim_tool/src/gui/main_tab.rs +++ b/src/Tools/tim_tool/src/gui/main_tab.rs @@ -43,7 +43,7 @@ impl MainTab { add_new_image(file_name, image, if image_palette.is_some() {1} else {0}, false); if let Some(image_palette) = image_palette { - let file_name = file_name.clone() + " (Palette)"; + let file_name = " => ".to_owned() + file_name.as_str() + " (Palette)"; add_new_image(&file_name, image_palette, 0, true); } } diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index 2f0e6c66..e3fe5b26 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -1,5 +1,5 @@ import { VRAMArea } from "../vram-components.slint"; -import { Button, ComboBox, GroupBox, StandardListView } from "std-widgets.slint"; +import { Button, ComboBox, GroupBox, StandardListView, LineEdit } from "std-widgets.slint"; struct VRAMImage { img: image, @@ -56,8 +56,8 @@ 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; + cur_sel_x.text = parent.img_x; + cur_sel_y.text = parent.img_y; } pointer-event(event) => { if event.kind == PointerEventKind.up { @@ -65,8 +65,8 @@ export component MainTab inherits Rectangle { } if event.kind == PointerEventKind.down { - cur_sel_x.display_value = parent.img_x; - cur_sel_y.display_value = parent.img_y; + cur_sel_x.text = parent.img_x; + cur_sel_y.text = parent.img_y; cur_sel_img.source = parent.img; cur_sel_img.visible = true; vram_files_list.current-item = i; @@ -105,10 +105,10 @@ export component MainTab inherits Rectangle { 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; + cur_sel_x.text = root.vram_images[current-item].x; + cur_sel_y.text = root.vram_images[current-item].y; + cur_sel_img.source = root.vram_images[current-item].img; + cur_sel_img.visible = true; } } HorizontalLayout { @@ -122,8 +122,8 @@ export component MainTab inherits Rectangle { clicked => { root.remove_file_clicked(vram_files_list.current_item); vram_files_list.current-item = -1; - cur_sel_x.display_value = 0; - cur_sel_y.display_value = 0; + cur_sel_x.text = 0; + cur_sel_y.text = 0; cur_sel_img.visible = false; } } @@ -144,13 +144,47 @@ export component MainTab inherits Rectangle { image-fit: contain; } } - cur_sel_x := Text { - in-out property display_value; - text: "X: " + display_value; + HorizontalLayout { + alignment: start; + VerticalLayout { + alignment: center; + Text { + text: "X: "; + } + } + cur_sel_x := LineEdit { + input-type: number; + text: 0; + width: 64pt; + + accepted(text) => { + 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); + self.text = vram_images[vram_files_list.current-item].x; + } + } + } } - cur_sel_y :=Text { - in-out property display_value; - text: "Y: " + display_value; + HorizontalLayout { + alignment: start; + VerticalLayout { + alignment: center; + Text { + text: "Y: "; + } + } + cur_sel_y := LineEdit { + input-type: number; + text: 0; + width: 64pt; + + accepted(text) => { + 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); + self.text = vram_images[vram_files_list.current-item].y; + } + } + } } ComboBox { model: ["4-bit", "16-bit", "24-bit"]; -- 2.30.2 From ebf640520e012c3d050434e3ddb9d4c9b45db6e5 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 17 Feb 2025 17:05:24 +0100 Subject: [PATCH 06/17] Support movement by key --- src/Tools/tim_tool/ui/tab/main-tab.slint | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index e3fe5b26..6d7e8c2a 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -196,6 +196,33 @@ export component MainTab inherits Rectangle { } } + FocusScope { + key-pressed(event) => { + if(vram_files_list.current-item != -1) { + if(event.text == Key.LeftArrow) { + root.move_vram_image(vram_files_list.current-item, -1, 0); + cur_sel_x.text = vram_images[vram_files_list.current-item].x; + } + + if(event.text == Key.RightArrow) { + root.move_vram_image(vram_files_list.current-item, 1, 0); + cur_sel_x.text = vram_images[vram_files_list.current-item].x; + } + + if(event.text == Key.UpArrow) { + root.move_vram_image(vram_files_list.current-item, 0, -1); + cur_sel_y.text = vram_images[vram_files_list.current-item].y; + } + + if(event.text == Key.DownArrow) { + root.move_vram_image(vram_files_list.current-item, 0, 1); + cur_sel_y.text = vram_images[vram_files_list.current-item].y; + } + } + accept + } + } + function get_border_width() -> int { return 4; } -- 2.30.2 From a797bff7a1770f3f910493576f071b0215ac76c2 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 17 Feb 2025 17:46:59 +0100 Subject: [PATCH 07/17] Simple scale concept --- src/Tools/tim_tool/ui/tab/main-tab.slint | 131 +++++++++++--------- src/Tools/tim_tool/ui/vram-components.slint | 21 ++-- 2 files changed, 85 insertions(+), 67 deletions(-) diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index 6d7e8c2a..4da26360 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -1,5 +1,5 @@ import { VRAMArea } from "../vram-components.slint"; -import { Button, ComboBox, GroupBox, StandardListView, LineEdit } from "std-widgets.slint"; +import { Button, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView } from "std-widgets.slint"; struct VRAMImage { img: image, @@ -10,6 +10,7 @@ struct VRAMImage { } export component MainTab inherits Rectangle { + property test_scale: 2; in-out property vram_bg; in-out property <[StandardListViewItem]> vram_files: []; in-out property <[VRAMImage]> vram_images: []; @@ -27,67 +28,79 @@ export component MainTab inherits Rectangle { y: 4px; VerticalLayout { - background_rect := Rectangle { - width: background_image.width + root.get_border_width()*2px; - height: background_image.height + root.get_border_width()*2px; - border-width: root.get_border_width()*1px; - border-color: #404040; - background: #A0A0A0; - background_image := VRAMArea { - x: root.get_border_width()*1px; - y: root.get_border_width()*1px; - img: vram_bg; - img_x: 0; - img_y: 0; - } + ScrollView { + width: rect.width/root.test_scale; + height: rect.height/root.test_scale; + viewport-x: 0; + viewport-y: 0; + viewport-width: rect.width; + viewport-height: rect.height; - for vram_image[i] in root.vram_images: VRAMArea { - x: root.get_border_width()*1px; - y: root.get_border_width()*1px; - img: vram_image.img; - img_x: vram_image.x; - 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); - cur_sel_x.text = parent.img_x; - cur_sel_y.text = parent.img_y; - } - pointer-event(event) => { - if event.kind == PointerEventKind.up { - self.mouse-cursor = MouseCursor.grab; + rect := Rectangle { + width: background_image.width + root.get_border_width()*2px; + height: background_image.height + root.get_border_width()*2px; + border-width: root.get_border_width()*1px; + border-color: #404040; + background: #A0A0A0; + background_image := VRAMArea { + x: root.get_border_width()*1px; + y: root.get_border_width()*1px; + img: vram_bg; + img_x: 0; + img_y: 0; + scale: test_scale; + } + + for vram_image[i] in root.vram_images: VRAMArea { + x: root.get_border_width()*1px; + y: root.get_border_width()*1px; + img: vram_image.img; + img_x: vram_image.x; + img_y: vram_image.y; + scale: test_scale; + + 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); + cur_sel_x.text = parent.img_x; + cur_sel_y.text = parent.img_y; } - - if event.kind == PointerEventKind.down { - cur_sel_x.text = parent.img_x; - cur_sel_y.text = parent.img_y; - cur_sel_img.source = parent.img; - cur_sel_img.visible = true; - vram_files_list.current-item = i; + pointer-event(event) => { + if event.kind == PointerEventKind.up { + self.mouse-cursor = MouseCursor.grab; + } + + if event.kind == PointerEventKind.down { + cur_sel_x.text = parent.img_x; + cur_sel_y.text = parent.img_y; + cur_sel_img.source = parent.img; + cur_sel_img.visible = true; + vram_files_list.current-item = i; + } + } + + // 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(); } - } - - // 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(); } } } diff --git a/src/Tools/tim_tool/ui/vram-components.slint b/src/Tools/tim_tool/ui/vram-components.slint index b7b869df..b39e35f9 100644 --- a/src/Tools/tim_tool/ui/vram-components.slint +++ b/src/Tools/tim_tool/ui/vram-components.slint @@ -3,14 +3,17 @@ component VRAMSegment inherits Rectangle { in property img; in property clip_x; in property clip_y; + in property scale: 1; - width: 64px; - height: 256px; + width: 64px*scale; + height: 256px*scale; clip: true; Image { source: img; - x: -root.clip_x*1px; - y: -root.clip_y*1px; + x: -root.clip_x*1px*scale; + y: -root.clip_y*1px*scale; + width: img.width*1px*scale; + height: img.height*1px*scale; } } @@ -18,17 +21,19 @@ export component VRAMArea inherits Rectangle { in property img; in property img_x; in property img_y; + in property scale: 1; - width: (64*16+15)*1px; - height: (256*2+1)*1px; + width: ((64*16+15)*1px)*scale; + height: ((256*2+1)*1px)*scale; for idx in 32 : VRAMSegment { - x: root.get_x(idx)*(64px + 1px); - y: root.get_y(idx)*(256px + 1px); + x: (root.get_x(idx)*(64px + 1px))*scale; + y: (root.get_y(idx)*(256px + 1px))*scale; img: img; clip_x: (root.get_x(idx)*64) - root.img_x; clip_y: (root.get_y(idx)*256) - root.img_y; + scale: root.scale; } function get_x(idx: int) -> int { -- 2.30.2 From e25cc7ba38afec68384e94d6bb664cb8bb67a405 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 23 Feb 2025 07:38:11 +0100 Subject: [PATCH 08/17] Make test scale work? --- src/Tools/tim_tool/ui/tab/main-tab.slint | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index 4da26360..a206a1f1 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -60,14 +60,14 @@ export component MainTab inherits Rectangle { scale: test_scale; 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; + x: ((parent.img_x + self.lines_crossed_x())*1px)*test_scale; + y: ((parent.img_y + self.lines_crossed_y())*1px)*test_scale; + width: ((parent.img.width + self.lines_crossed_width())*1px)*test_scale; + height: ((parent.img.height + self.lines_crossed_height())*1px)*test_scale; 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); + root.move_vram_image(i, ((self.mouse-x - self.pressed-x)/test_scale)/1px, ((self.mouse-y - self.pressed-y)/test_scale)/1px); cur_sel_x.text = parent.img_x; cur_sel_y.text = parent.img_y; } -- 2.30.2 From 39dace6f6bfb11c9d11cf798e12875be7ab1dd4b Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 2 Mar 2025 00:09:11 +0100 Subject: [PATCH 09/17] Fix layout scaling issue --- src/Tools/tim_tool/ui/tab/main-tab.slint | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index a206a1f1..d252e3ac 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -10,7 +10,7 @@ struct VRAMImage { } export component MainTab inherits Rectangle { - property test_scale: 2; + property test_scale: 4; in-out property vram_bg; in-out property <[StandardListViewItem]> vram_files: []; in-out property <[VRAMImage]> vram_images: []; @@ -24,11 +24,12 @@ export component MainTab inherits Rectangle { group := GroupBox { title: "VRAM Layout"; - x: 4px; - y: 4px; + x: 4px; + y: 4px; + width: main_view.width + 2*main_view.x; VerticalLayout { - ScrollView { + main_view := ScrollView { width: rect.width/root.test_scale; height: rect.height/root.test_scale; viewport-x: 0; @@ -107,13 +108,14 @@ export component MainTab inherits Rectangle { } HorizontalLayout { padding: 4px; + GroupBox { title: "Added files"; VerticalLayout { alignment: start; padding: 4px; vram_files_list := StandardListView { - width: background_image.width/2; + width: background_image.width/root.test_scale/2; height: 128px; model: root.vram_files; -- 2.30.2 From a62728db7ba8e054facfdddbd327136398828c4b Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 2 Mar 2025 00:45:23 +0100 Subject: [PATCH 10/17] Crappy scale slider implementation --- src/Tools/tim_tool/ui/tab/main-tab.slint | 25 +++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index d252e3ac..00c139b1 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -1,5 +1,5 @@ import { VRAMArea } from "../vram-components.slint"; -import { Button, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView } from "std-widgets.slint"; +import { Button, ComboBox, GroupBox, StandardListView, LineEdit, ScrollView, Slider } from "std-widgets.slint"; struct VRAMImage { img: image, @@ -10,7 +10,7 @@ struct VRAMImage { } export component MainTab inherits Rectangle { - property test_scale: 4; + property test_scale: 1; in-out property vram_bg; in-out property <[StandardListViewItem]> vram_files: []; in-out property <[VRAMImage]> vram_images: []; @@ -108,7 +108,26 @@ export component MainTab inherits Rectangle { } HorizontalLayout { padding: 4px; - + VerticalLayout { + alignment: center; + padding: 4px; + Text { + text: "Scale: " + slider.value; + } + } + slider := Slider { + minimum: 100.0; + maximum: 400.0; + step: 1.0; + value: 100.0; + + changed(value) => { + root.test_scale = value/100.0; + } + } + } + HorizontalLayout { + padding: 4px; GroupBox { title: "Added files"; VerticalLayout { -- 2.30.2 From 57f22a6d6c51df1526e6d841638aa8f6c3275cef Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 3 Mar 2025 20:28:46 +0100 Subject: [PATCH 11/17] Addd scale slider --- src/Tools/tim_tool/ui/tab/main-tab.slint | 41 +++++++++++++-------- src/Tools/tim_tool/ui/vram-components.slint | 15 ++++---- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index 00c139b1..3501f47e 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -10,7 +10,7 @@ struct VRAMImage { } export component MainTab inherits Rectangle { - property test_scale: 1; + property scale: 1.0; in-out property vram_bg; in-out property <[StandardListViewItem]> vram_files: []; in-out property <[VRAMImage]> vram_images: []; @@ -30,8 +30,8 @@ export component MainTab inherits Rectangle { VerticalLayout { main_view := ScrollView { - width: rect.width/root.test_scale; - height: rect.height/root.test_scale; + width: rect.width/root.scale; + height: rect.height/root.scale; viewport-x: 0; viewport-y: 0; viewport-width: rect.width; @@ -49,7 +49,7 @@ export component MainTab inherits Rectangle { img: vram_bg; img_x: 0; img_y: 0; - scale: test_scale; + scale: scale; } for vram_image[i] in root.vram_images: VRAMArea { @@ -58,17 +58,17 @@ export component MainTab inherits Rectangle { img: vram_image.img; img_x: vram_image.x; img_y: vram_image.y; - scale: test_scale; + scale: scale; TouchArea { - x: ((parent.img_x + self.lines_crossed_x())*1px)*test_scale; - y: ((parent.img_y + self.lines_crossed_y())*1px)*test_scale; - width: ((parent.img.width + self.lines_crossed_width())*1px)*test_scale; - height: ((parent.img.height + self.lines_crossed_height())*1px)*test_scale; + x: ((parent.img_x + self.lines_crossed_x())*1px)*scale; + y: ((parent.img_y + self.lines_crossed_y())*1px)*scale; + width: ((parent.img.width + self.lines_crossed_width())*1px)*scale; + height: ((parent.img.height + self.lines_crossed_height())*1px)*scale; mouse-cursor: grab; moved => { self.mouse-cursor = MouseCursor.grabbing; - root.move_vram_image(i, ((self.mouse-x - self.pressed-x)/test_scale)/1px, ((self.mouse-y - self.pressed-y)/test_scale)/1px); + root.move_vram_image(i, ((self.mouse-x - self.pressed-x)/scale)/1px, ((self.mouse-y - self.pressed-y)/scale)/1px); cur_sel_x.text = parent.img_x; cur_sel_y.text = parent.img_y; } @@ -105,14 +105,24 @@ export component MainTab inherits Rectangle { } } } + + function update_viewport() { + if abs(self.viewport-x) + self.width > self.viewport-width { + self.viewport-x = 0; + } + + if abs(self.viewport-y) + self.height > self.viewport-height { + self.viewport-y = 0; + } + } } HorizontalLayout { padding: 4px; VerticalLayout { - alignment: center; - padding: 4px; + alignment: center; + padding-right: 4px; Text { - text: "Scale: " + slider.value; + text: "Scale: " + round(slider.value) + "%"; } } slider := Slider { @@ -122,7 +132,8 @@ export component MainTab inherits Rectangle { value: 100.0; changed(value) => { - root.test_scale = value/100.0; + root.scale = round(value)/100.0; + main_view.update_viewport(); } } } @@ -134,7 +145,7 @@ export component MainTab inherits Rectangle { alignment: start; padding: 4px; vram_files_list := StandardListView { - width: background_image.width/root.test_scale/2; + width: background_image.width/root.scale/2; height: 128px; model: root.vram_files; diff --git a/src/Tools/tim_tool/ui/vram-components.slint b/src/Tools/tim_tool/ui/vram-components.slint index b39e35f9..65e21fd6 100644 --- a/src/Tools/tim_tool/ui/vram-components.slint +++ b/src/Tools/tim_tool/ui/vram-components.slint @@ -3,17 +3,18 @@ component VRAMSegment inherits Rectangle { in property img; in property clip_x; in property clip_y; - in property scale: 1; + in property scale: 1.0; width: 64px*scale; height: 256px*scale; clip: true; Image { - source: img; - x: -root.clip_x*1px*scale; - y: -root.clip_y*1px*scale; - width: img.width*1px*scale; - height: img.height*1px*scale; + source: img; + x: -root.clip_x*1px*scale; + y: -root.clip_y*1px*scale; + width: img.width*1px*scale; + height: img.height*1px*scale; + image-rendering: pixelated; } } @@ -21,7 +22,7 @@ export component VRAMArea inherits Rectangle { in property img; in property img_x; in property img_y; - in property scale: 1; + in property scale: 1.0; width: ((64*16+15)*1px)*scale; height: ((256*2+1)*1px)*scale; -- 2.30.2 From 70cf70c4b50d6b4f6c243dd2a701cdfc4a5768df Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 3 Mar 2025 20:34:15 +0100 Subject: [PATCH 12/17] Pixelate scale of selection window --- src/Tools/tim_tool/ui/tab/main-tab.slint | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Tools/tim_tool/ui/tab/main-tab.slint b/src/Tools/tim_tool/ui/tab/main-tab.slint index 3501f47e..aa2b4202 100644 --- a/src/Tools/tim_tool/ui/tab/main-tab.slint +++ b/src/Tools/tim_tool/ui/tab/main-tab.slint @@ -184,9 +184,10 @@ export component MainTab inherits Rectangle { height: 128px; background: #A0A0A0; cur_sel_img := Image { - width: 128px; - height: 128px; - image-fit: contain; + width: 128px; + height: 128px; + image-fit: contain; + image-rendering: pixelated; } } HorizontalLayout { -- 2.30.2 From 618b642c3f06141b1331b780bb2abd94c248af4f Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 3 Mar 2025 20:46:30 +0100 Subject: [PATCH 13/17] Prepare for palette display --- src/Tools/tim_tool/ui/tab/file-tab.slint | 39 +++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Tools/tim_tool/ui/tab/file-tab.slint b/src/Tools/tim_tool/ui/tab/file-tab.slint index 58a39df2..91a57665 100644 --- a/src/Tools/tim_tool/ui/tab/file-tab.slint +++ b/src/Tools/tim_tool/ui/tab/file-tab.slint @@ -14,6 +14,7 @@ component ProjectWidget inherits Rectangle { component ConvertImageWidget inherits Rectangle { in-out property image_path; in-out property image_data; + in-out property image_palette_data; in-out property image_name; in-out property enable_button: false; @@ -48,21 +49,43 @@ component ConvertImageWidget inherits Rectangle { } GroupBox { - title: "Loaded image"; + title: "Loaded image and palette"; VerticalLayout { alignment: start; padding: 4px; HorizontalLayout { alignment: center; Rectangle { - width: 256px; - height: 256px; - background: #000000; + width: 256px + 2*4px; // < Because of border + height: 256px + 2*4px; // < Because of border + background: #404040; + border-color: #808080; + border-width: 4px; Image { - width: 256px; - height: 256px; - source: root.image_data; - image-fit: contain; + width: 256px; + height: 256px; + source: root.image_data; + image-fit: contain; + image-rendering: pixelated; + } + } + Rectangle { + // Fake padding because the padding setting for the HorizontalLayout would not work + width: 4px; + height: 1px; + } + Rectangle { + width: 256px + 2*4px; // < Because of border + height: 256px + 2*4px; // < Because of border + background: #404040; + border-color: #808080; + border-width: 4px; + Image { + width: 256px; + height: 256px; + source: root.image_palette_data; + image-fit: contain; + image-rendering: pixelated; } } } -- 2.30.2 From 1f8fc5100c6908e19e40c25d5bdb353addfc50bc Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 3 Mar 2025 21:31:02 +0100 Subject: [PATCH 14/17] Support pre-view of palette --- src/Tools/tim_tool/src/gui/file_tab.rs | 11 ++++++++- src/Tools/tim_tool/src/main.rs | 4 +-- src/Tools/tim_tool/ui/app-window.slint | 2 ++ src/Tools/tim_tool/ui/tab/file-tab.slint | 31 ++++++++++++++++++------ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/file_tab.rs b/src/Tools/tim_tool/src/gui/file_tab.rs index 02b1c9c3..d8ee67fb 100644 --- a/src/Tools/tim_tool/src/gui/file_tab.rs +++ b/src/Tools/tim_tool/src/gui/file_tab.rs @@ -21,10 +21,19 @@ impl FileTab { main_window.set_file_tab_enable(false); } - pub fn update_new_load(&self, file_name: Option, image: Image) { + pub fn update_new_load(&self, file_name: Option, image: Image, palette: Option) { let main_window = self.main_window.borrow(); main_window.set_file_tab_image_data(image); + if let Some(palette) = palette { + main_window.set_file_tab_palette_data(palette); + main_window.set_file_tab_palette_visible(true); + } + + else { + main_window.set_file_tab_palette_visible(false); + } + if let Some(file_name) = file_name { main_window.set_file_tab_image_name(file_name.into()); } diff --git a/src/Tools/tim_tool/src/main.rs b/src/Tools/tim_tool/src/main.rs index aa2d1a58..ac432830 100644 --- a/src/Tools/tim_tool/src/main.rs +++ b/src/Tools/tim_tool/src/main.rs @@ -58,13 +58,13 @@ fn setup_file_tab(gui_elements_ref: Rc>, logic_ref: Rc 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))); } - file_tab.update_new_load(file_name, image); + file_tab.update_new_load(file_name, image, palette); } Ok(()) diff --git a/src/Tools/tim_tool/ui/app-window.slint b/src/Tools/tim_tool/ui/app-window.slint index a556f9dc..93f1149c 100644 --- a/src/Tools/tim_tool/ui/app-window.slint +++ b/src/Tools/tim_tool/ui/app-window.slint @@ -15,6 +15,8 @@ export component MainWindow inherits Window { // Convert Image values in-out property file_tab_browse_path <=> file_tab.conv_image_path; in-out property file_tab_image_data <=> file_tab.conv_image_data; + in-out property file_tab_palette_data <=> file_tab.conv_palette_data; + in-out property file_tab_palette_visible <=> file_tab.conv_palette_enable; in-out property file_tab_image_name <=> file_tab.conv_image_name; in-out property file_tab_enable <=> file_tab.conv_image_enable; callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked; diff --git a/src/Tools/tim_tool/ui/tab/file-tab.slint b/src/Tools/tim_tool/ui/tab/file-tab.slint index 91a57665..d3685932 100644 --- a/src/Tools/tim_tool/ui/tab/file-tab.slint +++ b/src/Tools/tim_tool/ui/tab/file-tab.slint @@ -14,9 +14,10 @@ component ProjectWidget inherits Rectangle { component ConvertImageWidget inherits Rectangle { in-out property image_path; in-out property image_data; - in-out property image_palette_data; + in-out property palette_data; in-out property image_name; in-out property enable_button: false; + in-out property palette_visible: false; callback browse_clicked(); callback add_clicked(); @@ -80,10 +81,11 @@ component ConvertImageWidget inherits Rectangle { background: #404040; border-color: #808080; border-width: 4px; - Image { + palette_image := Image { width: 256px; height: 256px; - source: root.image_palette_data; + source: root.palette_data; + visible: root.palette_visible; image-fit: contain; image-rendering: pixelated; } @@ -114,11 +116,22 @@ component ConvertImageWidget inherits Rectangle { } } } + + public function set_palette_image(image: image) { + palette_image.source = image; + palette_image.visible = true; + } + + public function clear_palette_image() { + palette_image.visible = false; + } } export component FileTab inherits Rectangle { in-out property conv_image_path; in-out property conv_image_data; + in-out property conv_palette_data; + in-out property conv_palette_enable; in-out property conv_image_name; in-out property conv_image_enable; in-out property state; @@ -155,11 +168,13 @@ export component FileTab inherits Rectangle { if root.state == State.Project : ProjectWidget { } if root.state == State.ConvertImage : ConvertImageWidget { - image_path <=> root.conv_image_path; - image_data <=> root.conv_image_data; - image_name <=> root.conv_image_name; - enable_button <=> root.conv_image_enable; - + image_path <=> root.conv_image_path; + image_data <=> root.conv_image_data; + palette_data <=> root.conv_palette_data; + palette_visible <=> root.conv_palette_enable; + image_name <=> root.conv_image_name; + enable_button <=> root.conv_image_enable; + browse_clicked => { root.conv_image_browse_clicked(); } -- 2.30.2 From e948887faa17dac46a7c719c992bea109c9a5d52 Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 4 Mar 2025 20:40:50 +0100 Subject: [PATCH 15/17] Add GUI for palette width/height --- src/Tools/tim_tool/ui/app-window.slint | 2 +- src/Tools/tim_tool/ui/tab/file-tab.slint | 63 +++++++++++++++++------- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/Tools/tim_tool/ui/app-window.slint b/src/Tools/tim_tool/ui/app-window.slint index 93f1149c..56c6b093 100644 --- a/src/Tools/tim_tool/ui/app-window.slint +++ b/src/Tools/tim_tool/ui/app-window.slint @@ -18,7 +18,7 @@ export component MainWindow inherits Window { in-out property file_tab_palette_data <=> file_tab.conv_palette_data; in-out property file_tab_palette_visible <=> file_tab.conv_palette_enable; in-out property file_tab_image_name <=> file_tab.conv_image_name; - in-out property file_tab_enable <=> file_tab.conv_image_enable; + in-out property file_tab_enable <=> file_tab.conv_enable_view; callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked; callback file_tab_add_convert_image <=> file_tab.conv_image_add_clicked; diff --git a/src/Tools/tim_tool/ui/tab/file-tab.slint b/src/Tools/tim_tool/ui/tab/file-tab.slint index d3685932..536a98a6 100644 --- a/src/Tools/tim_tool/ui/tab/file-tab.slint +++ b/src/Tools/tim_tool/ui/tab/file-tab.slint @@ -16,7 +16,7 @@ component ConvertImageWidget inherits Rectangle { in-out property image_data; in-out property palette_data; in-out property image_name; - in-out property enable_button: false; + in-out property enable_view: false; in-out property palette_visible: false; callback browse_clicked(); @@ -75,19 +75,48 @@ component ConvertImageWidget inherits Rectangle { width: 4px; height: 1px; } - Rectangle { - width: 256px + 2*4px; // < Because of border - height: 256px + 2*4px; // < Because of border - background: #404040; - border-color: #808080; - border-width: 4px; - palette_image := Image { - width: 256px; - height: 256px; - source: root.palette_data; - visible: root.palette_visible; - image-fit: contain; - image-rendering: pixelated; + VerticalLayout { + Rectangle { + width: 256px + 2*4px; // < Because of border + height: 256px + 2*4px; // < Because of border + background: #404040; + border-color: #808080; + border-width: 4px; + palette_image := Image { + width: 256px; + height: 256px; + source: root.palette_data; + visible: root.palette_visible; + image-fit: contain; + image-rendering: pixelated; + } + } + HorizontalLayout { + alignment: start; + VerticalLayout { + VerticalLayout { + alignment: center; + Text { + text: "Width: "; + } + } + VerticalLayout { + alignment: center; + Text { + text: "Height: "; + } + } + } + VerticalLayout { + LineEdit { + width: 40pt; + enabled: root.enable_view; + } + LineEdit { + width: 40pt; + enabled: root.enable_view; + } + } } } } @@ -109,7 +138,7 @@ component ConvertImageWidget inherits Rectangle { padding: 4px; Button { text: "Add Image"; - enabled: root.enable_button; + enabled: root.enable_view; clicked => {root.add_clicked();} } } @@ -133,7 +162,7 @@ export component FileTab inherits Rectangle { in-out property conv_palette_data; in-out property conv_palette_enable; in-out property conv_image_name; - in-out property conv_image_enable; + in-out property conv_enable_view; in-out property state; callback conv_image_browse_clicked; callback conv_image_add_clicked; @@ -173,7 +202,7 @@ export component FileTab inherits Rectangle { palette_data <=> root.conv_palette_data; palette_visible <=> root.conv_palette_enable; image_name <=> root.conv_image_name; - enable_button <=> root.conv_image_enable; + enable_view <=> root.conv_enable_view; browse_clicked => { root.conv_image_browse_clicked(); -- 2.30.2 From 3cdfe4a677c56d8e086d052acbb57f7bba2ce3f2 Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 4 Mar 2025 20:53:35 +0100 Subject: [PATCH 16/17] Update palette size info --- src/Tools/tim_tool/src/gui/file_tab.rs | 6 ++++++ src/Tools/tim_tool/ui/app-window.slint | 2 ++ src/Tools/tim_tool/ui/tab/file-tab.slint | 24 +++++++++++++++++------- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/file_tab.rs b/src/Tools/tim_tool/src/gui/file_tab.rs index d8ee67fb..c613b026 100644 --- a/src/Tools/tim_tool/src/gui/file_tab.rs +++ b/src/Tools/tim_tool/src/gui/file_tab.rs @@ -26,11 +26,17 @@ impl FileTab { main_window.set_file_tab_image_data(image); if let Some(palette) = palette { + let size = palette.size(); + main_window.set_file_tab_palette_data(palette); + main_window.set_file_tab_palette_width(size.width as i32); + main_window.set_file_tab_palette_height(size.height as i32); main_window.set_file_tab_palette_visible(true); } else { + main_window.set_file_tab_palette_width(0); + main_window.set_file_tab_palette_height(0); main_window.set_file_tab_palette_visible(false); } diff --git a/src/Tools/tim_tool/ui/app-window.slint b/src/Tools/tim_tool/ui/app-window.slint index 56c6b093..5ecd471b 100644 --- a/src/Tools/tim_tool/ui/app-window.slint +++ b/src/Tools/tim_tool/ui/app-window.slint @@ -16,6 +16,8 @@ export component MainWindow inherits Window { in-out property file_tab_browse_path <=> file_tab.conv_image_path; in-out property file_tab_image_data <=> file_tab.conv_image_data; in-out property file_tab_palette_data <=> file_tab.conv_palette_data; + in-out property file_tab_palette_width <=> file_tab.conv_palette_width; + in-out property file_tab_palette_height <=> file_tab.conv_palette_height; in-out property file_tab_palette_visible <=> file_tab.conv_palette_enable; in-out property file_tab_image_name <=> file_tab.conv_image_name; in-out property file_tab_enable <=> file_tab.conv_enable_view; diff --git a/src/Tools/tim_tool/ui/tab/file-tab.slint b/src/Tools/tim_tool/ui/tab/file-tab.slint index 536a98a6..a031c25d 100644 --- a/src/Tools/tim_tool/ui/tab/file-tab.slint +++ b/src/Tools/tim_tool/ui/tab/file-tab.slint @@ -13,10 +13,12 @@ component ProjectWidget inherits Rectangle { component ConvertImageWidget inherits Rectangle { in-out property image_path; + in-out property image_name; in-out property image_data; in-out property palette_data; - in-out property image_name; - in-out property enable_view: false; + in-out property palette_width: 0; + in-out property palette_height: 0; + in-out property enable_view: false; in-out property palette_visible: false; callback browse_clicked(); @@ -109,12 +111,14 @@ component ConvertImageWidget inherits Rectangle { } VerticalLayout { LineEdit { - width: 40pt; - enabled: root.enable_view; + width: 40pt; + enabled: root.palette_visible; + text: root.palette_width; } LineEdit { - width: 40pt; - enabled: root.enable_view; + width: 40pt; + enabled: root.palette_visible; + text: root.palette_height; } } } @@ -158,11 +162,15 @@ component ConvertImageWidget inherits Rectangle { export component FileTab inherits Rectangle { in-out property conv_image_path; + in-out property conv_image_name; in-out property conv_image_data; in-out property conv_palette_data; + in-out property conv_palette_width; + in-out property conv_palette_height; in-out property conv_palette_enable; - in-out property conv_image_name; in-out property conv_enable_view; + + in-out property state; callback conv_image_browse_clicked; callback conv_image_add_clicked; @@ -200,6 +208,8 @@ export component FileTab inherits Rectangle { image_path <=> root.conv_image_path; image_data <=> root.conv_image_data; palette_data <=> root.conv_palette_data; + palette_width <=> root.conv_palette_width; + palette_height <=> root.conv_palette_height; palette_visible <=> root.conv_palette_enable; image_name <=> root.conv_image_name; enable_view <=> root.conv_enable_view; -- 2.30.2 From 4d62d79cbdd31e114593550a0af7679b28183e6f Mon Sep 17 00:00:00 2001 From: Jaby Date: Tue, 4 Mar 2025 21:38:08 +0100 Subject: [PATCH 17/17] Support changing palette size --- src/Tools/tim_tool/src/gui/file_tab.rs | 37 ++++++++---- src/Tools/tim_tool/src/logic/mod.rs | 10 ++++ src/Tools/tim_tool/src/logic/tim.rs | 42 +++++++++++--- src/Tools/tim_tool/src/main.rs | 10 +++- src/Tools/tim_tool/ui/app-window.slint | 21 +++---- src/Tools/tim_tool/ui/tab/file-tab.slint | 73 +++++++++++++++--------- 6 files changed, 137 insertions(+), 56 deletions(-) diff --git a/src/Tools/tim_tool/src/gui/file_tab.rs b/src/Tools/tim_tool/src/gui/file_tab.rs index c613b026..4bf68e6f 100644 --- a/src/Tools/tim_tool/src/gui/file_tab.rs +++ b/src/Tools/tim_tool/src/gui/file_tab.rs @@ -21,10 +21,25 @@ impl FileTab { main_window.set_file_tab_enable(false); } - pub fn update_new_load(&self, file_name: Option, image: Image, palette: Option) { + pub fn update_new_loaded_file(&self, file_name: Option, image: Image, palette: Option) { + self.update_palette(palette); + let main_window = self.main_window.borrow(); main_window.set_file_tab_image_data(image); + if let Some(file_name) = file_name { + main_window.set_file_tab_image_name(file_name.into()); + } + + else { + main_window.set_file_tab_image_name("".into()); + } + main_window.set_file_tab_enable(true); + } + + pub fn update_palette(&self, palette: Option) { + let main_window = self.main_window.borrow(); + if let Some(palette) = palette { let size = palette.size(); @@ -39,15 +54,6 @@ impl FileTab { main_window.set_file_tab_palette_height(0); main_window.set_file_tab_palette_visible(false); } - - if let Some(file_name) = file_name { - main_window.set_file_tab_image_name(file_name.into()); - } - - else { - main_window.set_file_tab_image_name("".into()); - } - main_window.set_file_tab_enable(true); } pub fn get_file_name(&self) -> String { @@ -65,6 +71,17 @@ impl FileTab { }); } + pub fn on_update_palette_size(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow, u32, u32) -> Result<(), Error> + 'static) { + let main_window_cloned = self.main_window.clone(); + let gui_cloned = gui_elements.clone(); + + self.main_window.borrow().on_file_tab_update_palette_size(move |width, height| { + if let Err(error) = function(&mut gui_cloned.borrow_mut(), &main_window_cloned.borrow(), width as u32, height as u32) { + display_error("Loadind file failed", &error.to_string()); + } + }); + } + pub fn on_add_image(&self, gui_elements: GUIElementsRef, mut function: impl FnMut(&mut GUIElements, &MainWindow) -> Result<(), Error> + 'static) { let main_window_cloned = self.main_window.clone(); let gui_cloned = gui_elements.clone(); diff --git a/src/Tools/tim_tool/src/logic/mod.rs b/src/Tools/tim_tool/src/logic/mod.rs index c938513f..fd5fc7b3 100644 --- a/src/Tools/tim_tool/src/logic/mod.rs +++ b/src/Tools/tim_tool/src/logic/mod.rs @@ -34,4 +34,14 @@ impl Logic { Err(Error::from_str("No data found for loaded image")) } } + + pub fn change_unadded_tim_palette_size(&mut self, width: u32, height: u32) -> Result, Error> { + if let Some(unadded_tim) = &mut self.unadded_tim { + unadded_tim.change_palette_size(width, height) + } + + else { + Ok(None) + } + } } \ No newline at end of file diff --git a/src/Tools/tim_tool/src/logic/tim.rs b/src/Tools/tim_tool/src/logic/tim.rs index 571953a7..15a1f6b0 100644 --- a/src/Tools/tim_tool/src/logic/tim.rs +++ b/src/Tools/tim_tool/src/logic/tim.rs @@ -4,7 +4,7 @@ use tool_helper::Error; pub struct TIMInfo { image_data: SharedPixelBuffer, - palette: Option>, + palette: Option, } impl TIMInfo { @@ -48,7 +48,7 @@ impl TIMInfo { _ => {return Err(Error::from_str("Only 4 and 8bit color depth are supported for indexed color images"));} } } - Ok(TIMInfo{image_data, palette: Some(palette_colors)}) + Ok(TIMInfo{image_data, palette: Some(PaletteInfo::new(palette_colors))}) } else { @@ -70,21 +70,49 @@ impl TIMInfo { } } + pub fn change_palette_size(&mut self, width: u32, height: u32) -> Result, Error> { + if let Some(palette) = &mut self.palette { + if width == 0 || height == 0 { + return Err(Error::from_text(format!("{}px x {}px is not a valid size for palette", width, height))); + } + + palette.width = width; + palette.height = height; + Ok(Some(palette.get_image())) + } + + else { + Ok(None) + } + } + pub fn get_slint_images(&self) -> (slint::Image, Option) { (slint::Image::from_rgba8_premultiplied(self.image_data.clone()), if let Some(palette) = &self.palette { - let width = if palette.len() <= 16 {16} else {256}; - Some(Self::get_palette_image(palette, width, 1)) + Some(palette.get_image()) } else { None }) } +} - fn get_palette_image(palette: &Vec, width: u32, height: u32) -> slint::Image { - let mut image_data = SharedPixelBuffer::new(width, height); +struct PaletteInfo { + data: Vec, + width: u32, + height: u32, +} + +impl PaletteInfo { + pub fn new(data: Vec) -> PaletteInfo { + let width = if data.len() <= 16 {16} else {256}; + PaletteInfo{data, width, height: 1} + } + + pub fn get_image(&self) -> slint::Image { + let mut image_data = SharedPixelBuffer::new(self.width, self.height); let dst_pixels = image_data.make_mut_slice(); for (idx, byte) in dst_pixels.iter_mut().enumerate() { - *byte = if idx < palette.len() {palette[idx]} else {Rgba8Pixel::new(0, 0, 0, 0xFF)}; + *byte = if idx < self.data.len() {self.data[idx]} else {Rgba8Pixel::new(0, 0, 0, 0xFF)}; } slint::Image::from_rgba8_premultiplied(image_data.clone()) diff --git a/src/Tools/tim_tool/src/main.rs b/src/Tools/tim_tool/src/main.rs index ac432830..d351734e 100644 --- a/src/Tools/tim_tool/src/main.rs +++ b/src/Tools/tim_tool/src/main.rs @@ -43,6 +43,14 @@ fn setup_main_tab(gui_elements_ref: Rc>) { fn setup_file_tab(gui_elements_ref: Rc>, logic_ref: Rc>) { let gui_elements = gui_elements_ref.borrow(); + let logic = logic_ref.clone(); + gui_elements.file_tab.on_update_palette_size(gui_elements_ref.clone(), move |gui_elements, _main_window, width, height| -> Result<(), Error> { + let file_tab = &gui_elements.file_tab; + + file_tab.update_palette(logic.borrow_mut().change_unadded_tim_palette_size(width, height)?); + Ok(()) + }); + let logic = logic_ref.clone(); gui_elements.file_tab.on_browse_file(gui_elements_ref.clone(), move |gui_elements, main_window| -> Result<(), Error> { let file = FileDialog::new() @@ -64,7 +72,7 @@ fn setup_file_tab(gui_elements_ref: Rc>, logic_ref: Rc 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))); } - file_tab.update_new_load(file_name, image, palette); + file_tab.update_new_loaded_file(file_name, image, palette); } Ok(()) diff --git a/src/Tools/tim_tool/ui/app-window.slint b/src/Tools/tim_tool/ui/app-window.slint index 5ecd471b..4e00ab32 100644 --- a/src/Tools/tim_tool/ui/app-window.slint +++ b/src/Tools/tim_tool/ui/app-window.slint @@ -13,16 +13,17 @@ export component MainWindow inherits Window { callback move_vram_image <=> main_tab.move_vram_image; // Convert Image values - in-out property file_tab_browse_path <=> file_tab.conv_image_path; - in-out property file_tab_image_data <=> file_tab.conv_image_data; - in-out property file_tab_palette_data <=> file_tab.conv_palette_data; - in-out property file_tab_palette_width <=> file_tab.conv_palette_width; - in-out property file_tab_palette_height <=> file_tab.conv_palette_height; - in-out property file_tab_palette_visible <=> file_tab.conv_palette_enable; - in-out property file_tab_image_name <=> file_tab.conv_image_name; - in-out property file_tab_enable <=> file_tab.conv_enable_view; - callback file_tab_browse_convert_image <=> file_tab.conv_image_browse_clicked; - callback file_tab_add_convert_image <=> file_tab.conv_image_add_clicked; + in-out property file_tab-browse_path <=> file_tab.conv-image_path; + in-out property file_tab-image_data <=> file_tab.conv-image_data; + in-out property file_tab-palette_data <=> file_tab.conv-palette_data; + in-out property file_tab-palette_width <=> file_tab.conv-palette_width; + in-out property file_tab-palette_height <=> file_tab.conv-palette_height; + in-out property file_tab-palette_visible <=> file_tab.conv-palette_enable; + in-out property file_tab-image_name <=> file_tab.conv-image_name; + in-out property file_tab-enable <=> file_tab.conv-enable_view; + callback file_tab-update_palette_size <=> file_tab.conv-image_update_palette_size; + callback file_tab-browse_convert_image <=> file_tab.conv-image_browse_clicked; + callback file_tab-add_convert_image <=> file_tab.conv-image_add_clicked; title: "TIM Tool 0.1.0"; width: tab_widget.width; diff --git a/src/Tools/tim_tool/ui/tab/file-tab.slint b/src/Tools/tim_tool/ui/tab/file-tab.slint index a031c25d..958b7070 100644 --- a/src/Tools/tim_tool/ui/tab/file-tab.slint +++ b/src/Tools/tim_tool/ui/tab/file-tab.slint @@ -23,6 +23,7 @@ component ConvertImageWidget inherits Rectangle { callback browse_clicked(); callback add_clicked(); + callback update_palette_size(int, int); background: #D0D0D0; @@ -110,15 +111,25 @@ component ConvertImageWidget inherits Rectangle { } } VerticalLayout { - LineEdit { - width: 40pt; - enabled: root.palette_visible; - text: root.palette_width; + palette_width_edit := LineEdit { + width: 40pt; + input-type: number; + enabled: root.palette_visible; + text: root.palette_width; + + accepted(text) => { + update_palette_size(palette_width_edit.text.to-float(), palette_height_edit.text.to-float()); + } } - LineEdit { - width: 40pt; - enabled: root.palette_visible; - text: root.palette_height; + palette_height_edit := LineEdit { + width: 40pt; + input-type: number; + enabled: root.palette_visible; + text: root.palette_height; + + accepted(text) => { + update_palette_size(palette_width_edit.text.to-float(), palette_height_edit.text.to-float()); + } } } } @@ -161,19 +172,21 @@ component ConvertImageWidget inherits Rectangle { } export component FileTab inherits Rectangle { - in-out property conv_image_path; - in-out property conv_image_name; - in-out property conv_image_data; - in-out property conv_palette_data; - in-out property conv_palette_width; - in-out property conv_palette_height; - in-out property conv_palette_enable; - in-out property conv_enable_view; + // TODO: Names are messed up here! + in-out property conv-image_path; + in-out property conv-image_name; + in-out property conv-image_data; + in-out property conv-palette_data; + in-out property conv-palette_width; + in-out property conv-palette_height; + in-out property conv-palette_enable; + in-out property conv-enable_view; in-out property state; - callback conv_image_browse_clicked; - callback conv_image_add_clicked; + callback conv-image_update_palette_size(int, int); + callback conv-image_browse_clicked; + callback conv-image_add_clicked; x: 0px; y: 0px; @@ -205,21 +218,25 @@ export component FileTab inherits Rectangle { if root.state == State.Project : ProjectWidget { } if root.state == State.ConvertImage : ConvertImageWidget { - image_path <=> root.conv_image_path; - image_data <=> root.conv_image_data; - palette_data <=> root.conv_palette_data; - palette_width <=> root.conv_palette_width; - palette_height <=> root.conv_palette_height; - palette_visible <=> root.conv_palette_enable; - image_name <=> root.conv_image_name; - enable_view <=> root.conv_enable_view; + image_path <=> root.conv-image_path; + image_data <=> root.conv-image_data; + palette_data <=> root.conv-palette_data; + palette_width <=> root.conv-palette_width; + palette_height <=> root.conv-palette_height; + palette_visible <=> root.conv-palette_enable; + image_name <=> root.conv-image_name; + enable_view <=> root.conv-enable_view; + update_palette_size(width, height) => { + root.conv-image_update_palette_size(width, height); + } + browse_clicked => { - root.conv_image_browse_clicked(); + root.conv-image_browse_clicked(); } add_clicked => { - root.conv_image_add_clicked(); + root.conv-image_add_clicked(); } } } -- 2.30.2