From 57f22a6d6c51df1526e6d841638aa8f6c3275cef Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 3 Mar 2025 20:28:46 +0100 Subject: [PATCH] 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;