Skip to content

Commit 3a80b38

Browse files
committed
fix(cover): turntable fitting (#34)
fix: #33 Hoping that my maths are not wrong. Basically, I lazily appended the texture at a lower scale for turntable mode, which led to bad fittings on rectangular ratios. It now properly calculates the new values, at an as optimized branch as I could get it to. Maybe we can do it a bit more optimized since the cover is static and we can skip re-calculations on snapshotting. Reviewed-on: https://codeberg.org/GeopJr/Turntable/pulls/34
1 parent 689a783 commit 3a80b38

File tree

1 file changed

+59
-20
lines changed

1 file changed

+59
-20
lines changed

src/Widgets/Cover.vala

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -525,22 +525,47 @@ public class Turntable.Widgets.Cover : Gtk.Widget {
525525
float ratio = cover == null ? 1f : (float) cover.get_intrinsic_aspect_ratio ();
526526
float w = 0;
527527
float h = 0;
528+
float t_w = 0;
529+
float t_h = 0;
528530

529-
if (ratio > 1) {
531+
if (ratio == 1) {
532+
w = width;
533+
h = height;
534+
if (this.turntable) {
535+
t_w = this.record_center_inner.size.width;
536+
t_h = this.record_center_inner.size.height;
537+
}
538+
} else if (ratio > 1) {
530539
if (fit_cover) {
531540
w = height * ratio;
532541
h = height;
542+
if (this.turntable) {
543+
t_w = this.record_center_inner.size.height * ratio;
544+
t_h = this.record_center_inner.size.height;
545+
}
533546
} else {
534547
w = width;
535548
h = width / ratio;
549+
if (this.turntable) {
550+
t_w = this.record_center_inner.size.width;
551+
t_h = this.record_center_inner.size.width / ratio;
552+
}
536553
}
537554
} else {
538555
if (fit_cover) {
539556
w = width;
540557
h = width / ratio;
558+
if (this.turntable) {
559+
t_w = this.record_center_inner.size.width;
560+
t_h = this.record_center_inner.size.width / ratio;
561+
}
541562
} else {
542563
w = height * ratio;
543564
h = height;
565+
if (this.turntable) {
566+
t_w = this.record_center_inner.size.height * ratio;
567+
t_h = this.record_center_inner.size.height;
568+
}
544569
}
545570
}
546571

@@ -727,34 +752,48 @@ public class Turntable.Widgets.Cover : Gtk.Widget {
727752
float texture_w = w;
728753
float texture_h = h;
729754
if (this.turntable) {
730-
if (this.fit_cover) {
731-
texture_w = width * 0.65f;
732-
texture_h = height * 0.65f;
733-
} else {
734-
texture_w = texture_w * 0.65f;
735-
texture_h = texture_h * 0.65f;
736-
}
755+
texture_w = t_w;
756+
texture_h = t_h;
737757

738-
snapshot.translate (Graphene.Point () {
739-
x = (width - Math.ceilf (texture_w)) / 2f,
740-
y = Math.floorf ((height - texture_h)) / 2f
741-
});
758+
var center_point = Graphene.Point () {
759+
x = width / 2 - this.record_center_inner.size.width / 2,
760+
y = height / 2 - this.record_center_inner.size.height / 2
761+
};
742762

743763
snapshot.push_rounded_clip (
744764
Gsk.RoundedRect ().init_from_rect (
745765
Graphene.Rect () {
746-
origin = Graphene.Point () {
747-
x = 0,
748-
y = 0
749-
},
750-
size = Graphene.Size () {
751-
width = texture_w,
752-
height = texture_h
753-
}
766+
origin = center_point,
767+
size = this.record_center_inner.size
754768
},
755769
9999f
756770
)
757771
);
772+
773+
if (ratio == 1) {
774+
snapshot.translate (center_point);
775+
} else if (this.fit_cover) {
776+
float new_x = 0;
777+
float new_y = 0;
778+
779+
if (ratio < 1) {
780+
new_x = width / 2 - this.record_center_inner.size.width / 2;
781+
new_y = height / 2 - texture_h / 2;
782+
} else {
783+
new_y = height / 2 - this.record_center_inner.size.height / 2;
784+
new_x = width / 2 - texture_w / 2;
785+
}
786+
787+
snapshot.translate (Graphene.Point () {
788+
x = new_x,
789+
y = new_y
790+
});
791+
} else {
792+
snapshot.translate (Graphene.Point () {
793+
x = width / 2 - texture_w / 2,
794+
y = height / 2 - texture_h / 2
795+
});
796+
}
758797
} else if (this.style == Style.SHADOW) {
759798
snapshot.translate (Graphene.Point () {
760799
x = 0,

0 commit comments

Comments
 (0)