Simple scale concept
This commit is contained in:
parent
ebf640520e
commit
a797bff7a1
|
@ -1,5 +1,5 @@
|
||||||
import { VRAMArea } from "../vram-components.slint";
|
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 {
|
struct VRAMImage {
|
||||||
img: image,
|
img: image,
|
||||||
|
@ -10,6 +10,7 @@ struct VRAMImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
export component MainTab inherits Rectangle {
|
export component MainTab inherits Rectangle {
|
||||||
|
property <int> test_scale: 2;
|
||||||
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 <[VRAMImage]> vram_images: [];
|
||||||
|
@ -27,67 +28,79 @@ export component MainTab inherits Rectangle {
|
||||||
y: 4px;
|
y: 4px;
|
||||||
|
|
||||||
VerticalLayout {
|
VerticalLayout {
|
||||||
background_rect := Rectangle {
|
ScrollView {
|
||||||
width: background_image.width + root.get_border_width()*2px;
|
width: rect.width/root.test_scale;
|
||||||
height: background_image.height + root.get_border_width()*2px;
|
height: rect.height/root.test_scale;
|
||||||
border-width: root.get_border_width()*1px;
|
viewport-x: 0;
|
||||||
border-color: #404040;
|
viewport-y: 0;
|
||||||
background: #A0A0A0;
|
viewport-width: rect.width;
|
||||||
background_image := VRAMArea {
|
viewport-height: rect.height;
|
||||||
x: root.get_border_width()*1px;
|
|
||||||
y: root.get_border_width()*1px;
|
|
||||||
img: vram_bg;
|
|
||||||
img_x: 0;
|
|
||||||
img_y: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for vram_image[i] in root.vram_images: VRAMArea {
|
rect := Rectangle {
|
||||||
x: root.get_border_width()*1px;
|
width: background_image.width + root.get_border_width()*2px;
|
||||||
y: root.get_border_width()*1px;
|
height: background_image.height + root.get_border_width()*2px;
|
||||||
img: vram_image.img;
|
border-width: root.get_border_width()*1px;
|
||||||
img_x: vram_image.x;
|
border-color: #404040;
|
||||||
img_y: vram_image.y;
|
background: #A0A0A0;
|
||||||
TouchArea {
|
background_image := VRAMArea {
|
||||||
x: (parent.img_x + self.lines_crossed_x())*1px;
|
x: root.get_border_width()*1px;
|
||||||
y: (parent.img_y + self.lines_crossed_y())*1px;
|
y: root.get_border_width()*1px;
|
||||||
width: (parent.img.width + self.lines_crossed_width())*1px;
|
img: vram_bg;
|
||||||
height: (parent.img.height + self.lines_crossed_height())*1px;
|
img_x: 0;
|
||||||
mouse-cursor: grab;
|
img_y: 0;
|
||||||
moved => {
|
scale: test_scale;
|
||||||
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;
|
for vram_image[i] in root.vram_images: VRAMArea {
|
||||||
cur_sel_y.text = parent.img_y;
|
x: root.get_border_width()*1px;
|
||||||
}
|
y: root.get_border_width()*1px;
|
||||||
pointer-event(event) => {
|
img: vram_image.img;
|
||||||
if event.kind == PointerEventKind.up {
|
img_x: vram_image.x;
|
||||||
self.mouse-cursor = MouseCursor.grab;
|
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;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if event.kind == PointerEventKind.down {
|
// Thanks to Cody the white tiger
|
||||||
cur_sel_x.text = parent.img_x;
|
function lines_crossed_x() -> int {
|
||||||
cur_sel_y.text = parent.img_y;
|
return parent.img_x/64;
|
||||||
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_y() -> int {
|
||||||
function lines_crossed_x() -> int {
|
return parent.img_y/256;
|
||||||
return parent.img_x/64;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function lines_crossed_y() -> int {
|
function lines_crossed_width() -> int {
|
||||||
return parent.img_y/256;
|
return ((parent.img_x + parent.img.width)/64) - self.lines_crossed_x();
|
||||||
}
|
}
|
||||||
|
|
||||||
function lines_crossed_width() -> int {
|
function lines_crossed_height() -> int {
|
||||||
return ((parent.img_x + parent.img.width)/64) - self.lines_crossed_x();
|
return ((parent.img_y + parent.img.height)/256) - self.lines_crossed_y();
|
||||||
}
|
}
|
||||||
|
|
||||||
function lines_crossed_height() -> int {
|
|
||||||
return ((parent.img_y + parent.img.height)/256) - self.lines_crossed_y();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,17 @@ component VRAMSegment inherits Rectangle {
|
||||||
in property <image> img;
|
in property <image> img;
|
||||||
in property <int> clip_x;
|
in property <int> clip_x;
|
||||||
in property <int> clip_y;
|
in property <int> clip_y;
|
||||||
|
in property <int> scale: 1;
|
||||||
|
|
||||||
width: 64px;
|
width: 64px*scale;
|
||||||
height: 256px;
|
height: 256px*scale;
|
||||||
clip: true;
|
clip: true;
|
||||||
Image {
|
Image {
|
||||||
source: img;
|
source: img;
|
||||||
x: -root.clip_x*1px;
|
x: -root.clip_x*1px*scale;
|
||||||
y: -root.clip_y*1px;
|
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 <image> img;
|
in property <image> img;
|
||||||
in property <int> img_x;
|
in property <int> img_x;
|
||||||
in property <int> img_y;
|
in property <int> img_y;
|
||||||
|
in property <int> scale: 1;
|
||||||
|
|
||||||
width: (64*16+15)*1px;
|
width: ((64*16+15)*1px)*scale;
|
||||||
height: (256*2+1)*1px;
|
height: ((256*2+1)*1px)*scale;
|
||||||
|
|
||||||
for idx in 32 : VRAMSegment {
|
for idx in 32 : VRAMSegment {
|
||||||
x: root.get_x(idx)*(64px + 1px);
|
x: (root.get_x(idx)*(64px + 1px))*scale;
|
||||||
y: root.get_y(idx)*(256px + 1px);
|
y: (root.get_y(idx)*(256px + 1px))*scale;
|
||||||
|
|
||||||
img: img;
|
img: img;
|
||||||
clip_x: (root.get_x(idx)*64) - root.img_x;
|
clip_x: (root.get_x(idx)*64) - root.img_x;
|
||||||
clip_y: (root.get_y(idx)*256) - root.img_y;
|
clip_y: (root.get_y(idx)*256) - root.img_y;
|
||||||
|
scale: root.scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_x(idx: int) -> int {
|
function get_x(idx: int) -> int {
|
||||||
|
|
Loading…
Reference in New Issue