Hyena.Gui.RatingRenderer.Render C# (CSharp) Method

Render() public method

public Render ( Context cr, Gdk area, Color color, bool showEmptyStars, bool isHovering, int hoverValue, double fillOpacity, double hoverFillOpacity, double strokeOpacity ) : void
cr Cairo.Context
area Gdk
color Color
showEmptyStars bool
isHovering bool
hoverValue int
fillOpacity double
hoverFillOpacity double
strokeOpacity double
return void
        public virtual void Render(Context cr, Gdk.Rectangle area, Color color, bool showEmptyStars, bool isHovering,
            int hoverValue, double fillOpacity, double hoverFillOpacity, double strokeOpacity)
        {
            if (Value == MinRating && !isHovering && !showEmptyStars) {
                return;
            }

            cr.Save ();

            Cairo.Color fill_color = color;
            fill_color.A = fillOpacity;
            Cairo.Color stroke_color = fill_color;
            stroke_color.A = strokeOpacity;
            Cairo.Color hover_fill_color = fill_color;
            hover_fill_color.A = hoverFillOpacity;

            double x, y;
            ComputePosition (area, out x, out y);

            cr.LineWidth = 1.0;
            cr.Translate (0.5, 0.5);

            for (int i = MinRating + 1, s = isHovering || showEmptyStars ? MaxRating : Value; i <= s; i++, x += Size) {
                bool fill = i <= Value && Value > MinRating;
                bool hover_fill = i <= hoverValue && hoverValue > MinRating;
                double scale = fill || hover_fill ? Size : Size - 2;
                double ofs = fill || hover_fill ? 0 : 1;

                for (int p = 0, n = star_plot.GetLength (0); p < n; p++) {
                    double px = x + ofs + star_plot[p, 0] * scale;
                    double py = y + ofs + star_plot[p, 1] * scale;
                    if (p == 0) {
                        cr.MoveTo (px, py);
                    } else {
                        cr.LineTo (px, py);
                    }
                }
                cr.ClosePath ();

                if (fill || hover_fill) {
                    if (!isHovering || hoverValue >= Value) {
                        cr.SetSourceColor (fill ? fill_color : hover_fill_color);
                    } else {
                        cr.SetSourceColor (hover_fill ? fill_color : hover_fill_color);
                    }
                    cr.Fill ();
                } else {
                    cr.SetSourceColor (stroke_color);
                    cr.Stroke ();
                }
            }
            cr.Restore ();
        }

Usage Example

Esempio n. 1
0
        private void RenderTrackRating (Cairo.Context cr, TrackInfo track)
        {
            RatingRenderer rating_renderer = new RatingRenderer ();
            rating_renderer.Value = track.Rating;

            int x = track_info_alloc.X + track_info_alloc.Width + 4 * rating_renderer.Xpad - rating_renderer.Width;
            int y = track_info_alloc.Y + track_info_alloc.Height;
            track_info_alloc.Height += rating_renderer.Height;

            Gdk.Rectangle area = new Gdk.Rectangle (x, y, rating_renderer.Width, rating_renderer.Height);
            rating_renderer.Render (cr, area, TextColor, false, false, rating_renderer.Value, 0.8, 0.8, 0.35);
        }