X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Frating-widget.vala;h=cafb73aa0b5c5edf8edcc760d570858736d2ae28;hb=d260a9c1ceb6458a73a32c1d00793be75cdb7975;hp=d432b485508fa3ff269e5ad09f35228e29a47a18;hpb=d9edb26f6cf6d89dd02c7eea7d6a2f6704b24264;p=cinaest diff --git a/src/rating-widget.vala b/src/rating-widget.vala index d432b48..cafb73a 100644 --- a/src/rating-widget.vala +++ b/src/rating-widget.vala @@ -19,11 +19,28 @@ using Gtk; public class RatingWidget : DrawingArea { - private int rating; + private int _rating; private bool button_pressed; private Gdk.Color active_color; private Gdk.Color disabled_color; + public int rating { + get { + return _rating; + } + set { + if (_rating == value) + return; + + _rating = value; + + unowned Gdk.Region region = this.window.get_clip_region (); + // redraw the cairo canvas completely by exposing it + this.window.invalidate_region (region, true); + this.window.process_updates (true); + } + } + public RatingWidget () { var style = Gtk.rc_get_style_by_paths (this.get_settings (), "GtkButton", null, typeof (Gtk.Button)); if (!style.lookup_color ("ActiveTextColor", out active_color)) @@ -101,26 +118,20 @@ public class RatingWidget : DrawingArea { } private void rate (double x) { - double r = 10 * x / this.allocation.width; - if (r <= 0) { - rating = 0; + int r; + + x = 10 * x / this.allocation.width; + if (x <= 0) { + r = 0; } else { - int star = (int) r; - rating = 10 * (star + 1); - r -= star; - if (r <= 0.333) - rating -= 5; - if (rating > 100) - rating = 100; + int star = (int) x; + r = 10 * (star + 1); + x -= star; + if (x <= 0.333) + r -= 5; + if (r > 100) + r = 100; } - - unowned Gdk.Region region = this.window.get_clip_region (); - // redraw the cairo canvas completely by exposing it - this.window.invalidate_region (region, true); - this.window.process_updates (true); - } - - public int get_rating () { - return rating; + rating = r; } }