Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions src/widgets/MediaButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ private class MediaButton : Gtk.Widget {
return;
}

width = this.get_allocated_width ();
height = this.get_allocated_height ();
double scale_x = (double)width / this._media.width;
double scale_y = (double)height / this._media.height;
width = int.min (this._media.width, this.get_allocated_width ());
scale = this.get_allocated_width () / (double) this._media.width;

scale = double.min (double.min (scale_x, scale_y), 1.0);

width = (int)(this._media.width * scale);
height = (int)(this._media.height * scale);
if (scale > 1) {
height = int.min (this._media.height, (int) Math.floor ((this.get_allocated_width () / 4.0) * 3));
scale = 1;
} else {
height = (int) Math.floor (double.min (this._media.height * scale, (this._media.width * scale / 4.0) * 3));
}
}

public override bool draw (Cairo.Context ct) {
Expand All @@ -128,7 +128,8 @@ private class MediaButton : Gtk.Widget {
int draw_x = (widget_width / 2) - (draw_width / 2);

ct.scale (scale, scale);
ct.set_source_surface (media.surface, draw_x / scale, 0);
double draw_y = -(((media.height * scale) - draw_height) / 2);
ct.set_source_surface (media.surface, draw_x / scale, draw_y / scale);
ct.fill ();
ct.restore ();

Expand Down Expand Up @@ -189,7 +190,7 @@ private class MediaButton : Gtk.Widget {
out int natural) {
int media_width;
int media_height;

if (this._media == null || this._media.width == -1 || this._media.height == -1) {
media_width = MIN_WIDTH;
media_height = MAX_HEIGHT;
Expand All @@ -198,9 +199,17 @@ private class MediaButton : Gtk.Widget {
media_height = this._media.height;
}

double width_ratio = (double)width / (double) media_width;
int height = int.min (media_height, (int)(media_height * width_ratio));
natural = minimum = height;
double scale = width / (double) media_width;

int height = 0;

if (scale > 1) {
height = int.min (media_height, (int) Math.floor ((width / 4.0) * 3));
} else {
height = (int) Math.floor (double.min (media_height * scale, (media_width * scale / 4.0) * 3));
}

minimum = natural = height;
}

public override void get_preferred_width_for_height (int height,
Expand All @@ -217,19 +226,19 @@ private class MediaButton : Gtk.Widget {
media_height = this._media.height;
}

double height_ratio = (double)height / (double)media_height;
int width = int.min (media_width, (int)(media_width * height_ratio));
int max_width = (int) Math.floor ((height / 3.0) * 4);
int width = int.min (media_width, max_width);
minimum = int.min (media_width, MIN_WIDTH);
natural = width;
}

public override void get_preferred_height (out int minimum,
out int natural) {
int media_height;
if (this._media == null || this._media.width == -1) {
if (this._media == null || this._media.height == -1) {
media_height = 1;
} else {
media_height = this._media.width;
media_height = this._media.height;
}

minimum = int.min (media_height, MIN_HEIGHT);
Expand Down