changeset 4225:f6625617716b

- use ceil() to round non-integer pixel lengths up to the next integer value; this is needed to deal with non-integer scale factors, and should be probably applied to other scalable ui-widgets
author Giacomo Lozito <james@develia.org>
date Mon, 28 Jan 2008 02:50:54 +0100
parents 9b8d6438e00f
children 708b5473f8d6 704607c1f858
files src/audacious/ui_skinned_button.c src/audacious/ui_skinned_horizontal_slider.c
diffstat 2 files changed, 20 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/ui_skinned_button.c	Mon Jan 28 03:04:00 2008 +0200
+++ b/src/audacious/ui_skinned_button.c	Mon Jan 28 02:50:54 2008 +0100
@@ -20,6 +20,7 @@
 
 #include "ui_skinned_button.h"
 #include "util.h"
+#include <math.h>
 
 #define UI_SKINNED_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ui_skinned_button_get_type(), UiSkinnedButtonPrivate))
 typedef struct _UiSkinnedButtonPrivate UiSkinnedButtonPrivate;
@@ -263,24 +264,24 @@
     UiSkinnedButton *button = UI_SKINNED_BUTTON (widget);
     UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE (button);
     widget->allocation = *allocation;
-    widget->allocation.x *= (priv->scaled ? cfg.scale_factor : 1);
-    widget->allocation.y *= (priv->scaled ? cfg.scale_factor : 1);
+    widget->allocation.x = ceil(widget->allocation.x*(priv->scaled ? cfg.scale_factor : 1));
+    widget->allocation.y = ceil(widget->allocation.y*(priv->scaled ? cfg.scale_factor : 1));
 
     if (GTK_WIDGET_REALIZED (widget))
     {
         if ( button->event_window != NULL )
-            gdk_window_move_resize(button->event_window, allocation->x*(priv->scaled ? cfg.scale_factor : 1), allocation->y*(priv->scaled ? cfg.scale_factor : 1), allocation->width, allocation->height);
+            gdk_window_move_resize(button->event_window, ceil(allocation->x*(priv->scaled ? cfg.scale_factor : 1)), ceil(allocation->y*(priv->scaled ? cfg.scale_factor : 1)), allocation->width, allocation->height);
         else
-            gdk_window_move_resize(widget->window, allocation->x*(priv->scaled ? cfg.scale_factor : 1), allocation->y*(priv->scaled ? cfg.scale_factor : 1), allocation->width, allocation->height);
+            gdk_window_move_resize(widget->window, ceil(allocation->x*(priv->scaled ? cfg.scale_factor : 1)), ceil(allocation->y*(priv->scaled ? cfg.scale_factor : 1)), allocation->width, allocation->height);
     }
 
-    if (button->x + priv->move_x == widget->allocation.x/(priv->scaled ? cfg.scale_factor : 1))
+    if (button->x + priv->move_x == ceil(widget->allocation.x/(priv->scaled ? cfg.scale_factor : 1)))
         priv->move_x = 0;
-    if (button->y + priv->move_y == widget->allocation.y/(priv->scaled ? cfg.scale_factor : 1))
+    if (button->y + priv->move_y == ceil(widget->allocation.y/(priv->scaled ? cfg.scale_factor : 1)))
         priv->move_y = 0;
 
-    button->x = widget->allocation.x/(priv->scaled ? cfg.scale_factor : 1);
-    button->y = widget->allocation.y/(priv->scaled ? cfg.scale_factor : 1);
+    button->x = ceil(widget->allocation.x/(priv->scaled ? cfg.scale_factor : 1));
+    button->y = ceil(widget->allocation.y/(priv->scaled ? cfg.scale_factor : 1));
 }
 
 static gboolean ui_skinned_button_expose(GtkWidget *widget, GdkEventExpose *event) {
--- a/src/audacious/ui_skinned_horizontal_slider.c	Mon Jan 28 03:04:00 2008 +0200
+++ b/src/audacious/ui_skinned_horizontal_slider.c	Mon Jan 28 02:50:54 2008 +0100
@@ -27,6 +27,7 @@
 #include "ui_skinned_horizontal_slider.h"
 #include "main.h"
 #include "util.h"
+#include <math.h>
 
 #define UI_SKINNED_HORIZONTAL_SLIDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ui_skinned_horizontal_slider_get_type(), UiSkinnedHorizontalSliderPrivate))
 typedef struct _UiSkinnedHorizontalSliderPrivate UiSkinnedHorizontalSliderPrivate;
@@ -215,19 +216,19 @@
     UiSkinnedHorizontalSliderPrivate *priv = UI_SKINNED_HORIZONTAL_SLIDER_GET_PRIVATE(horizontal_slider);
 
     widget->allocation = *allocation;
-    widget->allocation.x *= (priv->scaled ? cfg.scale_factor : 1);
-    widget->allocation.y *= (priv->scaled ? cfg.scale_factor : 1);
+    widget->allocation.x = ceil(widget->allocation.x*(priv->scaled ? cfg.scale_factor : 1));
+    widget->allocation.y = ceil(widget->allocation.y*(priv->scaled ? cfg.scale_factor : 1));
 
     if (priv->knob_height == priv->height)
-        priv->knob_height = allocation->height/(priv->scaled ? cfg.scale_factor : 1);
-    priv->width = allocation->width/(priv->scaled ? cfg.scale_factor : 1);
-    priv->height = allocation->height/(priv->scaled ? cfg.scale_factor : 1);
+        priv->knob_height = ceil(allocation->height/(priv->scaled ? cfg.scale_factor : 1));
+    priv->width = ceil(allocation->width/(priv->scaled ? cfg.scale_factor : 1));
+    priv->height = ceil(allocation->height/(priv->scaled ? cfg.scale_factor : 1));
 
     if (GTK_WIDGET_REALIZED (widget))
         gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height);
 
-    horizontal_slider->x = widget->allocation.x/(priv->scaled ? cfg.scale_factor : 1);
-    horizontal_slider->y = widget->allocation.y/(priv->scaled ? cfg.scale_factor : 1);
+    horizontal_slider->x = ceil(widget->allocation.x/(priv->scaled ? cfg.scale_factor : 1));
+    horizontal_slider->y = ceil(widget->allocation.y/(priv->scaled ? cfg.scale_factor : 1));
 }
 
 static gboolean ui_skinned_horizontal_slider_expose(GtkWidget *widget, GdkEventExpose *event) {
@@ -356,7 +357,9 @@
 
     priv->scaled = !priv->scaled;
 
-    gtk_widget_set_size_request(widget, priv->width*(priv->scaled ? cfg.scale_factor : 1), priv->height*(priv->scaled ? cfg.scale_factor : 1));
+    gtk_widget_set_size_request(widget,
+        priv->width*(priv->scaled ? cfg.scale_factor : 1),
+        priv->height*(priv->scaled ? cfg.scale_factor : 1));
 
     gtk_widget_queue_draw(GTK_WIDGET(horizontal_slider));
 }