From 4285813e01e1f575f8070a11546fe54dfa9a758e Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 31 Mar 2011 20:13:57 +0200 Subject: UI: Only free errors if they exist --- src/user_interface.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/user_interface.c b/src/user_interface.c index 4b956eb..4359108 100644 --- a/src/user_interface.c +++ b/src/user_interface.c @@ -324,8 +324,10 @@ load_controls (UserInterface * ui) ui->control_bg = clutter_texture_new_from_file (vid_panel_png, &error); if (!ui->control_bg && error) g_debug ("Clutter error: %s\n", error->message); - g_error_free (error); - error = NULL; + if (error) { + g_error_free (error); + error = NULL; + } g_free (vid_panel_png); clutter_container_add_actor (CLUTTER_CONTAINER (ui->control_box), @@ -341,8 +343,10 @@ load_controls (UserInterface * ui) ui->control_play_toggle = clutter_texture_new_from_file (ui->pause_png, &error); if (!ui->control_play_toggle && error) g_debug ("Clutter error: %s\n", error->message); - g_error_free (error); - error = NULL; + if (error) { + g_error_free (error); + error = NULL; + } clutter_box_layout_pack (CLUTTER_BOX_LAYOUT (main_box_layout), ui->control_play_toggle, FALSE, /* expand */ -- cgit v1.2.3 From f8df7228e7dafffa020a4d93bf30f86221e8dd6c Mon Sep 17 00:00:00 2001 From: Robert Swain Date: Thu, 31 Mar 2011 22:37:03 +0200 Subject: UI: Fix AR scaling calculations and size_change/event callbacks --- src/user_interface.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/user_interface.c b/src/user_interface.c index 4359108..660195c 100644 --- a/src/user_interface.c +++ b/src/user_interface.c @@ -31,7 +31,7 @@ static void center_controls (UserInterface * ui); static gboolean controls_timeout_cb (gpointer data); static gboolean event_cb (ClutterStage * stage, ClutterEvent * event, - gpointer data); + UserInterface * ui); static void load_controls (UserInterface * ui); static gboolean penalty_box (gpointer data); static gchar * position_ns_to_str (gint64 nanoseconds); @@ -39,7 +39,7 @@ static void progress_timing (UserInterface * ui); static gboolean progress_update_text (gpointer data); static gboolean progress_update_seekbar (gpointer data); gboolean rotate_video (UserInterface * ui); -static void size_change (ClutterStage * stage, gpointer data); +static void size_change (ClutterStage * stage, UserInterface * ui); static void show_controls (UserInterface * ui, gboolean vis); static void toggle_fullscreen (UserInterface * ui); static void toggle_playing (UserInterface * ui); @@ -83,9 +83,8 @@ controls_timeout_cb (gpointer data) } static gboolean -event_cb (ClutterStage * stage, ClutterEvent * event, gpointer data) +event_cb (ClutterStage * stage, ClutterEvent * event, UserInterface * ui) { - UserInterface *ui = (UserInterface *) data; gboolean handled = FALSE; switch (event->type) { @@ -528,14 +527,12 @@ gboolean rotate_video (UserInterface * ui) } static void -size_change (ClutterStage * stage, gpointer data) +size_change (ClutterStage * stage, UserInterface * ui) { - UserInterface *ui = (UserInterface *) data; - gfloat stage_width, stage_height; gfloat new_width, new_height; gfloat media_width, media_height; - gfloat aratio; + gfloat stage_ar, media_ar; media_width = clutter_actor_get_width (ui->texture); media_height = clutter_actor_get_height (ui->texture); @@ -545,20 +542,25 @@ size_change (ClutterStage * stage, gpointer data) ui->stage_width = stage_width; ui->stage_height = stage_height; - if (!ui->rotated) { - new_width = stage_width; - new_height = stage_height; + stage_ar = stage_width / stage_height; + + /* if we're rotated, the media_width and media_height are swapped */ + if (ui->rotated) { + media_ar = media_height / media_width; } else { - new_width = stage_height; - new_height = stage_width; + media_ar = media_width / media_height; } - if (media_height <= media_width) { - aratio = media_height / media_width; - new_height = new_width * aratio; + /* calculate new width and height + * note: when we're done, new_width/new_height should equal media_ar */ + if (media_ar > stage_ar) { + /* media has wider aspect than stage so use new width as stage width and + * scale down height */ + new_width = stage_width; + new_height = stage_width / media_ar; } else { - aratio = media_width / media_height; - new_width = new_height * aratio; + new_height = stage_height; + new_width = stage_height * media_ar; } clutter_actor_set_size (CLUTTER_ACTOR (ui->texture), new_width, new_height); -- cgit v1.2.3