Example #1
0
        public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
        {
            if (data_handler == null) {
                return;
            }

            if (!has_sort) {
                base.Render (context, state, cellWidth, cellHeight);
                return;
            }

            Gdk.Rectangle arrow_alloc = new Gdk.Rectangle ();
            arrow_alloc.Width = (int)(cellHeight / 3.0);
            arrow_alloc.Height = (int)((double)arrow_alloc.Width / 1.6);
            arrow_alloc.X = (int)cellWidth - arrow_alloc.Width - Spacing;
            arrow_alloc.Y = ((int)cellHeight - arrow_alloc.Height) / 2;

            double textWidth = arrow_alloc.X - Spacing;
            if (textWidth > 0) {
                base.Render (context, state, textWidth, cellHeight);
            }

            SortType sort_type = ((ISortableColumn)data_handler ()).SortType;
            if (sort_type != SortType.None) {
                context.Theme.DrawArrow (context.Context, arrow_alloc, sort_type);
            }
        }
Example #2
0
        public override void Render(CellContext context, StateType state, double cellWidth, double cellHeight)
        {
            if (BoundObject == null) {
                return;
            }

            if (!(BoundObject is TrackInfo)) {
                throw new InvalidCastException ("CubanoTitleCell can only bind to TrackInfo objects");
            }

            TrackInfo track = (TrackInfo)BoundObject;

            context.Layout.Width = (int)((cellWidth - 8) * Pango.Scale.PangoScale);
            context.Layout.Ellipsize = Pango.EllipsizeMode.End;
            //context.Layout.FontDescription = context.Widget.PangoContext.FontDescription.Copy ();
            context.Layout.FontDescription.Weight = font_weight;
            context.Layout.SetMarkup (String.Format ("<big>{0}</big>  {1}",
                track.TrackNumber,
                GLib.Markup.EscapeText (track.DisplayTrackTitle)));

            int text_width;
            int text_height;
            context.Layout.GetPixelSize (out text_width, out text_height);

            context.Context.MoveTo (4, ((int)cellHeight - text_height) / 2);
            Cairo.Color color = context.Theme.Colors.GetWidgetColor (
                context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, state);
            color.A = (!context.Sensitive) ? 0.3 : 1.0;
            context.Context.Color = color;

            PangoCairoHelper.ShowLayout (context.Context, context.Layout);
        }
Example #3
0
        public override void Render(CellContext context, StateFlags state, double cellWidth, double cellHeight)
        {
            if (BoundObject == null) {
                return;
            }

            if (!(BoundObject is TrackInfo)) {
                throw new InvalidCastException ("ColumnCellAlbum can only bind to AlbumInfo objects");
            }

            TrackInfo track = (TrackInfo)BoundObject;

            context.Layout.Width = (int)((cellWidth - 8) * Pango.Scale.PangoScale);
            context.Layout.Ellipsize = Pango.EllipsizeMode.End;
            context.Layout.FontDescription.Weight = font_weight;
            context.Layout.SetMarkup (String.Format ("<b>{0}</b>\n<small><i>{1}</i></small>",
                GLib.Markup.EscapeText (track.DisplayTrackTitle),
                GLib.Markup.EscapeText (track.DisplayArtistName)));

            int text_width;
            int text_height;
            context.Layout.GetPixelSize (out text_width, out text_height);

            context.Context.MoveTo (4, ((int)cellHeight - text_height) / 2);
            context.Widget.StyleContext.Save ();
            context.Widget.StyleContext.AddClass ("entry");
            Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor (context.Widget.StyleContext.GetColor (StateFlags.Selected));
            context.Widget.StyleContext.Restore ();
            color.A = (!context.Opaque) ? 0.3 : 1.0;
            context.Context.SetSourceColor (color);

            PangoCairoHelper.ShowLayout (context.Context, context.Layout);
        }
        public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
        {
            PodcastTrackInfo podcast = PodcastTrackInfo.From (BoundTrack);
            if (podcast != null) {
                if (podcast.Activity == PodcastItemActivity.DownloadPending) {
                    context.Opaque = false;
                }
            }

            base.Render (context, state, cellWidth, cellHeight);
        }
        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            ContactTrackInfo ci = ContactTrackInfo.From (BoundTrack);
            if (ci != null) {
                if (ci.IsDownloadPending) {
                    context.Opaque = false;
                }
            }

            base.Render (context, cellWidth, cellHeight);
        }
Example #6
0
        public override void Render (CellContext context, double cellWidth, double cellHeight)
        {
            int cell_width = (int)cellWidth - 2 * Xpad;
            int cell_height = (int)cellHeight - 2 * Ypad;
            int x = context.Area.X + xpad + ((cell_width - Size) / 2);
            int y = context.Area.Y + ypad + ((cell_height - Size) / 2);

            if (context.State == StateType.Normal && last_hover_bound == BoundObjectParent) {
                context.State = StateType.Prelight;
            }

            Style.PaintCheck (context.Widget.Style, context.Drawable, context.State,
                Value ? ShadowType.In : ShadowType.Out,
                context.Clip, context.Widget, "cellcheck", x, y, Size, Size);
        }
        public void Render (CellContext context, Rect allocation, IPhoto photo)
        {
            string caption = GetCaptionString (photo);

            var text_color = context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, context.State);

            var layout = context.Layout;
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.Alignment = Pango.Alignment.Center;
            layout.Width = (int)(allocation.Width * Pango.Scale.PangoScale);

            layout.SetText (caption);

            context.Context.Color = text_color;
            context.Context.MoveTo (allocation.X, allocation.Y);
            PangoCairoHelper.ShowLayout (context.Context, layout);
        }
        public override void Render(CellContext context, Gtk.StateType state, double cellWidth, double cellHeight)
        {
            Base.SafeUri uri = BoundObject as Base.SafeUri;
            if (uri == null || !uri.IsLocalPath)
                return;

            var mood_service = ServiceStack.ServiceManager.Get<MoodbarService> ();
            var moodbar = mood_service.GetMoodbarQuick (uri.LocalPath);
            if (moodbar == null)
                return;

            Cairo.Context cr = context.Context;
            cr.Rectangle (0, 1, cellWidth, cellHeight-2);
            cr.Clip ();
            moodbar.Render (cr, 0, 0, ((int)cellWidth), ((int)cellHeight));
            cr.ResetClip ();
        }
Example #9
0
        public override void Render (CellContext context, double cellWidth, double cellHeight)
        {
            Gdk.Rectangle area = new Gdk.Rectangle (0, 0, (int)cellWidth, (int)cellHeight);

            // FIXME: Compute font height and set to renderer.Size

            renderer.Value = Value;
            bool is_hovering = hover_bound == BoundObjectParent && hover_bound != null;
            renderer.Render (context.Context, area, context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, context.State),
                is_hovering, is_hovering, hover_value, 0.8, 0.45, 0.35);

            // FIXME: Something is hosed in the view when computing cell dimensions
            // The cell width request is always smaller than the actual cell, so
            // this value is preserved once we compute it from rendering so the
            // input stuff can do its necessary calculations
            actual_area_hack = area;
        }
        public override void Render (CellContext context, Gtk.StateType state, double cellWidth, double cellHeight)
        {
            base.Render (context, state, cellWidth, cellHeight);

            if (measure) {
                solution_value_widths.Clear ();
                var sb = new StringBuilder ();
                int x = 0, w, h;
                foreach (var str in SolutionOptions) {
                    sb.Append (str);
                    context.Layout.SetMarkup (sb.ToString ());
                    context.Layout.GetPixelSize (out w, out h);
                    x += w;
                    solution_value_widths.Add (x);
                    sb.Append (solution_joiner);
                }
            }
        }
        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            // check state and parameters:
            if (BoundObject == null) {
                return;
            }
            var artistInfo = BoundObject as ArtistInfo;
            if (artistInfo == null) {
                throw new InvalidCastException ("FanArtArtistColumnCell can only bind ArtistInfo objects");
            }

            var musicBrainzID = GetArtistsMbid (artistInfo);
            bool image = false;

            // get artist image:
            if (musicBrainzID != null && FanArtMusicBrainz.HasImage (musicBrainzID)) {
                string imagePath = FanArtArtistImageSpec.GetPath (
                     FanArtArtistImageSpec.CreateArtistImageFileName (musicBrainzID));

                var fas = ServiceManager.Get<FanArtService> ();
                if (!Banshee.IO.File.Exists (new Hyena.SafeUri (imagePath))) {
                    if (!fas.IsThereActiveJob ()) {
                        ServiceManager.DbConnection.Execute (
                            "INSERT OR REPLACE INTO ArtistImageDownloads (MusicBrainzID, Downloaded, LastAttempt) VALUES (?, ?, ?)",
                            musicBrainzID, 0, DateTime.MinValue);

                        var artistName = FanArtMusicBrainz.ArtistNameByMBID (musicBrainzID);
                        ServiceManager.DbConnection.Execute (
                            "INSERT OR REPLACE INTO ArtistMusicBrainz (ArtistName, MusicBrainzId, LastAttempt) VALUES (?, ?, ?)",
                            artistName, musicBrainzID, DateTime.MinValue);

                        fas.FetchArtistImages (true);
                    }
                } else {
                    image = RenderArtistImage (imagePath, context);
                }
            }

            if (!image) {
                RenderArtistText (artistInfo.DisplayName, cellWidth, context);
            }
        }
 public string GetTooltipMarkup(CellContext cellContext, double columnWidth)
 {
     var our_attributes = AttributesForBoundObject.Select (i => attributes_uc[i]);
     return our_attributes.Count () > 0
         ? String.Format ("Creative Commons {0}", String.Join ("-", our_attributes.ToArray ()))
         : null;
 }
Example #13
0
 public void UpdateText(CellContext context, double cellWidth)
 {
     string text = last_text = GetText (BoundObject);
     UpdateText (context.Layout, cellWidth, text);
 }
Example #14
0
 public string GetTooltipMarkup(CellContext cellContext, double columnWidth)
 {
     UpdateText (cellContext, columnWidth);
     return IsEllipsized ? GLib.Markup.EscapeText (Text) : null;
 }
Example #15
0
 public virtual void Render(CellContext context, double cellWidth, double cellHeight)
 {
 }
Example #16
0
        public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
        {
            if (BoundObject == null) {
                return;
            }

            if (!(BoundObject is AlbumInfo)) {
                throw new InvalidCastException ("ColumnCellAlbum can only bind to AlbumInfo objects");
            }

            AlbumInfo album = (AlbumInfo)BoundObject;

            bool is_default = false;
            ImageSurface image = artwork_manager == null ? null
                : artwork_manager.LookupScaleSurface (album.ArtworkId, image_size, true);

            if (image == null) {
                image = default_cover_image;
                is_default = true;
            }

            // int image_render_size = is_default ? image.Height : (int)cellHeight - 8;
            int image_render_size = image_size;
            int x = image_spacing;
            int y = ((int)cellHeight - image_render_size) / 2;

            ArtworkRenderer.RenderThumbnail (context.Context, image, false, x, y,
                image_render_size, image_render_size, !is_default, context.Theme.Context.Radius);

            int fl_width = 0, fl_height = 0, sl_width = 0, sl_height = 0;
            Cairo.Color text_color = context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state);
            text_color.A = 0.75;

            Pango.Layout layout = context.Layout;
            layout.Width = (int)((cellWidth - cellHeight - x - 10) * Pango.Scale.PangoScale);
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.FontDescription.Weight = Pango.Weight.Bold;

            // Compute the layout sizes for both lines for centering on the cell
            int old_size = layout.FontDescription.Size;

            layout.SetText (album.DisplayTitle);
            layout.GetPixelSize (out fl_width, out fl_height);

            if (!String.IsNullOrEmpty (album.ArtistName)) {
                layout.FontDescription.Weight = Pango.Weight.Normal;
                layout.FontDescription.Size = (int)(old_size * Pango.Scale.Small);
                layout.FontDescription.Style = Pango.Style.Italic;
                layout.SetText (album.ArtistName);
                layout.GetPixelSize (out sl_width, out sl_height);
            }

            // Calculate the layout positioning
            x = ((int)cellHeight - x) + 10;
            y = (int)((cellHeight - (fl_height + sl_height)) / 2);

            // Render the second line first since we have that state already
            if (!String.IsNullOrEmpty (album.ArtistName)) {
                context.Context.MoveTo (x, y + fl_height);
                context.Context.Color = text_color;
                PangoCairoHelper.ShowLayout (context.Context, layout);
            }

            // Render the first line, resetting the state
            layout.SetText (album.DisplayTitle);
            layout.FontDescription.Weight = Pango.Weight.Bold;
            layout.FontDescription.Size = old_size;
            layout.FontDescription.Style = Pango.Style.Normal;

            layout.SetText (album.DisplayTitle);

            context.Context.MoveTo (x, y);
            text_color.A = 1;
            context.Context.Color = text_color;
            PangoCairoHelper.ShowLayout (context.Context, layout);
        }
Example #17
0
 public abstract void Render (CellContext context);
        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            if (!artwork_initialized) {
                artwork_manager = ServiceManager.Get<ArtworkManager> ();

                if (!artwork_manager.IsCachedSize (image_size)) {
                    artwork_manager.AddCachedSize (image_size);
                }
                if (artwork_manager != null) {
                    artwork_manager.ChangeCacheSize (ImageSize, GetAllAlbumsCount () + 3);
                }

                artwork_initialized = true;
            }

            bool is_queryalble_source = ServiceManager.SourceManager.ActiveSource is PrimarySource;
            is_queryalble_source = is_queryalble_source || ServiceManager.SourceManager.ActiveSource is PlaylistSource;
            is_queryalble_source = is_queryalble_source || ServiceManager.SourceManager.ActiveSource is SmartPlaylistSource;

            if (BoundObject == null) {
                return;
            }

            if (!(BoundObject is ArtistInfo)) {
                throw new InvalidCastException ("ColumnCellArtist can only bind to ArtistInfo objects");
            }
            var artist = (ArtistInfo)BoundObject;

            DatabaseArtistInfo db_artist = DatabaseArtistInfo.FindOrCreate (artist.Name, artist.NameSort);

            AlbumInfo[] albums = GetAlbums (db_artist.DbId);
            int album_count = albums.Length;

            string pattern = Catalog.GetString ("All Artists ({0})")
                .Replace ("(", "\\(")
                .Replace (")", "\\)")
                .Replace ("{0}", "[0-9]+");

            if (!String.IsNullOrEmpty (artist.Name) && System.Text.RegularExpressions.Regex.IsMatch (artist.Name, pattern)) {
                album_count = GetAllAlbumsCount ();
            }

            ImageSurface image = null;
            var images = new List<ImageSurface> ();

            int non_empty = 0;
            for (int i = 0; i < albums.Length && non_empty < 3; i++) {
                if (artwork_manager != null) {
                    ImageSurface sur = artwork_manager.LookupScaleSurface (albums [i].ArtworkId, image_size, true);
                    images.Add (sur);
                    if (sur != null) {
                        non_empty++;
                    }
                }
            }

            //bringing non-empty images to the front
            images.Sort (delegate (ImageSurface a, ImageSurface b) {
                if (a == null && b != null) return -1;
                if (a != null && b == null) return 1;
                return 0;
            });

            if (images.Count > 3) {
                images.RemoveRange (3, images.Count - 3);
            }

            bool is_default = false;
            if (images.Count == 0) {
                image = default_cover_image;
                is_default = true;
            } else {
                image = images[images.Count - 1];
            }

            int image_render_size = image_size;
            int x = image_spacing;
            int y = image_spacing;

            if (use_small_images) {
                x = image_spacing / 2;
                y = image_spacing / 2;
            }

            const int y_image_spacing = 1;
            int x_offset = (use_small_images ? album_spacing_small : album_spacing_normal);
            if (images.Count > 1)
                x_offset *= 2;
            int y_offset = (images.Count > 1) ? y_image_spacing * 2 : y_image_spacing;

            for (int i = 0; i < images.Count - 1; i++) {
                int move_x = x + ((i) * (use_small_images ? album_spacing_small : album_spacing_normal));
                int move_y = y + ((i) * y_image_spacing);
                ArtworkRenderer.RenderThumbnail (context.Context, images[i], false, move_x, move_y,
                    image_render_size, image_render_size, !is_default, context.Theme.Context.Radius, true, new Color (1.0, 1.0, 1.0, 1.0));
            }

            if (images.Count > 0) {
                ArtworkRenderer.RenderThumbnail (context.Context, image, false, x + x_offset, y + y_offset,
                    image_render_size, image_render_size, !is_default, context.Theme.Context.Radius, true, new Color (1.0, 1.0, 1.0, 1.0));
            } else {
                ArtworkRenderer.RenderThumbnail (context.Context, image, false, x + x_offset, y + y_offset,
                    image_render_size, image_render_size, !is_default, context.Theme.Context.Radius);
            }

            int fl_width = 0, fl_height = 0, sl_width = 0, sl_height = 0;
            context.Widget.StyleContext.Save ();
            context.Widget.StyleContext.AddClass ("entry");
            Color text_color = CairoExtensions.GdkRGBAToCairoColor (context.Widget.StyleContext.GetColor (context.State));
            context.Widget.StyleContext.Restore ();
            text_color.A = 0.75;

            Pango.Layout layout = context.Layout;
            layout.Width = (int)((cellWidth - cellHeight - x - 10) * Pango.Scale.PangoScale);
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.FontDescription.Weight = Pango.Weight.Bold;

            // Compute the layout sizes for both lines for centering on the cell
            int old_size = layout.FontDescription.Size;

            layout.SetText (artist.DisplayName);
            layout.GetPixelSize (out fl_width, out fl_height);

            layout.FontDescription.Weight = Pango.Weight.Normal;
            layout.FontDescription.Size = (int)(old_size * Pango.Scale.Small);
            layout.FontDescription.Style = Pango.Style.Italic;

            string album_string_singular = Catalog.GetString ("Album");
            string album_string_plural = Catalog.GetString ("Albums");

            layout.SetText (album_count + " " + ((album_count == 1) ? album_string_singular : album_string_plural));
            layout.GetPixelSize (out sl_width, out sl_height);

            // Calculate the layout positioning
            x = ((int)cellHeight - x) + (use_small_images ? album_spacing_small : album_spacing_normal) + 8;
            y = use_small_images ? (int)((cellHeight - (fl_height)) / 2) : (int)((cellHeight - (fl_height + sl_height)) / 2);

            // Render the second line first since we have that state already
            if (album_count > 0 && is_queryalble_source) {
                if (use_small_images) {
                    context.Context.MoveTo (cellWidth - sl_width - image_spacing, y + image_spacing / 2);
                } else {
                    context.Context.MoveTo (x, y + fl_height);
                }
                context.Context.SetSourceColor (text_color);
                if (!use_small_images || fl_width + x + sl_width <= cellWidth) {
                    Pango.CairoHelper.ShowLayout (context.Context, layout);
                }
            }

            // Render the first line, resetting the state
            layout.SetText (artist.DisplayName);
            layout.FontDescription.Weight = Pango.Weight.Bold;
            layout.FontDescription.Size = old_size;
            layout.FontDescription.Style = Pango.Style.Normal;

            layout.SetText (artist.DisplayName);

            context.Context.MoveTo (x, y);
            text_color.A = 1;
            context.Context.SetSourceColor (text_color);
            Pango.CairoHelper.ShowLayout (context.Context, layout);
        }
Example #19
0
 public abstract void Render(CellContext context);
Example #20
0
        public void UpdateText(CellContext context, double cellWidth)
        {
            string text = last_text = GetText(BoundObject);

            UpdateText(context.Layout, cellWidth, text);
        }
 protected virtual void RenderImageSurface (CellContext context, Rect allocation, ImageSurface imageSurface)
 {
     ArtworkRenderer.RenderThumbnail (context.Context,
         imageSurface, false,
         allocation.X, allocation.Y, allocation.Width, allocation.Height,
         true, context.Theme.Context.Radius,
         imageSurface == null, new Color (0.8, 0.8, 0.8));
 }
Example #22
0
 public virtual void Render(CellContext context, double cellWidth, double cellHeight)
 {
     Render(context, context.State, cellWidth, cellHeight);
 }
Example #23
0
 protected override void ClippedRender(CellContext context)
 {
     Render(context, ContentAllocation.Width, ContentAllocation.Height);
 }
Example #24
0
 public virtual void Render(CellContext context, Gtk.StateType state, double cellWidth, double cellHeight)
 {
 }
Example #25
0
 public abstract void Render(CellContext context, StateType state, double cellWidth, double cellHeight);
Example #26
0
        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            int cell_width = (int)cellWidth - 2 * Xpad;
            int cell_height = (int)cellHeight - 2 * Ypad;
            int x = Xpad + ((cell_width - Size) / 2);
            int y = Ypad + ((cell_height - Size) / 2);

            if (context.State == StateFlags.Normal && last_hover_bound == BoundObjectParent) {
                context.State = StateFlags.Prelight;
            }
            context.Widget.StyleContext.Save ();
            context.Widget.StyleContext.AddClass ("check");
            context.Widget.StyleContext.State = (Value ? StateFlags.Active : StateFlags.Normal);
            context.Widget.StyleContext.RenderCheck (context.Context, x, y, Size, Size);
            context.Widget.StyleContext.Restore ();
        }
Example #27
0
 public virtual void Render (CellContext context, Gtk.StateType state, double cellWidth, double cellHeight)
 {
 }
Example #28
0
        public override void Render (CellContext context)
        {
            if (inner_allocation.IsEmpty || ! valid)
                return;

            context.Context.Translate (inner_allocation.X, inner_allocation.Y);

            var photo = BoundPhoto;
            var view_layout = ParentLayout as PhotoGridViewLayout;

            if (photo != last_photo) {
                last_photo = photo;

                Reload (photo);
            }

            view_layout.CaptionRender.Render (context, caption_allocation, photo);

            ThreadAssist.BlockingProxyToMain (() => {
                RenderThumbnail (photo, context);
                ReloadIfSuboptimalSize (photo);
            });
        }
Example #29
0
        //int? height;
        //public override Size Measure (Size available)
        //{
            //int min, max;
            //GetWidthRange (ParentLayout.View.PangoLayout, out min, out max);
            //
            /*if (height == null) {
                using (var layout = new Pango.Layout (ParentLayout.View.PangoContext)) {
                    if (layout.FontDescription == null) {
                        layout.FontDescription = new Pango.FontDescription ();
                    }
                    UpdateText (layout, 100, "Woo Mar");
                    height = TextHeight;
                }
            }*/

            //return FixedSize ?? new Size (0, (double)height + Padding.Y);
        //}

        public override void Render (CellContext context, double cellWidth, double cellHeight)
        {
            UpdateText (context, cellWidth);
            if (String.IsNullOrEmpty (last_text)) {
                return;
            }

            //context.Context.Rectangle (0, 0, cellWidth, cellHeight);
            //context.Context.Clip ();
            context.Context.MoveTo (Padding.Left, ((int)cellHeight - text_height) / 2);
            Cairo.Color color = context.Theme.Colors.GetWidgetColor (
                context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, context.State);
            color.A = Alpha ?? (context.Opaque ? 1.0 : 0.5);
	    context.Context.SetSourceColor (color);

            PangoCairoHelper.ShowLayout (context.Context, context.Layout);
            //context.Context.ResetClip ();
        }
Example #30
0
        void RenderThumbnail (IPhoto photo, CellContext context)
        {
            ImageSurface image_surface = null;
            if (!(ParentLayout as PhotoGridViewLayout).SurfaceCache.TryGetValue (photo, out image_surface))
                return;

            // Scale needed to fill the grid slot.
            double scalex = image_surface == null ? 1 : image_surface.Width / thumbnail_allocation.Width;
            double scaley = image_surface == null ? 1 : image_surface.Height / thumbnail_allocation.Height;

            // Upscale if the photo is larger than the allocation.
            bool upscale = photo.Width > thumbnail_allocation.Width || photo.Height > thumbnail_allocation.Height;
            if (!upscale) {
                scalex = Math.Max (1.0, scalex);
                scaley = Math.Max (1.0, scaley);
            }

            double scale = 1 / Math.Max (scalex, scaley);

            RenderThumbnail (context.Context,
                             image_surface,
                             false,
                             0.0,
                             0.0,
                             thumbnail_allocation.Width,
                             thumbnail_allocation.Height,
                             context.Theme.Context.Radius,
                             false,
                             new Color (0.8, 0.0, 0.0),
                             CairoCorners.All, scale);
        }
Example #31
0
        //int? height;
        //public override Size Measure (Size available)
        //{
        //int min, max;
        //GetWidthRange (ParentLayout.View.PangoLayout, out min, out max);
        //
        /*if (height == null) {
                using (var layout = new Pango.Layout (ParentLayout.View.PangoContext)) {
                    if (layout.FontDescription == null) {
                        layout.FontDescription = new Pango.FontDescription ();
                    }
                    UpdateText (layout, 100, "Woo Mar");
                    height = TextHeight;
                }
            }*/
        //return FixedSize ?? new Size (0, (double)height + Padding.Y);
        //}
        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            UpdateText (context, cellWidth);
            if (String.IsNullOrEmpty (last_text)) {
                return;
            }

            //context.Context.Rectangle (0, 0, cellWidth, cellHeight);
            //context.Context.Clip ();
            context.Context.MoveTo (Padding.Left, ((int)cellHeight - text_height) / 2);
            var color = CairoExtensions.GdkRGBAToCairoColor (context.Theme.Widget.StyleContext.GetColor (context.State));
            color.A = Alpha ?? (context.Opaque ? 1.0 : 0.5);
            context.Context.Color = color;

            PangoCairoHelper.ShowLayout (context.Context, context.Layout);
            //context.Context.ResetClip ();
        }
        public override void Render (CellContext context, StateType state, double cellWidth, double cellHeight)
        {
            if (BoundObject == null) {
                return;
            }

            if (!(BoundObject is Feed)) {
                throw new InvalidCastException("ColumnCellPodcast can only bind to Feed objects");
            }

            Feed feed = (Feed)BoundObject;

            bool is_default = false;
            ImageSurface image = artwork_manager == null ? null
                : artwork_manager.LookupScaleSurface (PodcastService.ArtworkIdFor (feed), image_size, true);

            if (image == null) {
                image = default_cover_image;
                is_default = true;
            }

            // int image_render_size = is_default ? image.Height : (int)cellHeight - 8;
            int image_render_size = image_size;
            int x = image_spacing;
            int y = ((int)cellHeight - image_render_size) / 2;

            ArtworkRenderer.RenderThumbnail (context.Context, image, false, x, y,
                image_render_size, image_render_size, !is_default, context.Theme.Context.Radius);

            int fl_width = 0, fl_height = 0, sl_width = 0, sl_height = 0;
            Cairo.Color text_color = context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state);
            text_color.A = 0.75;

            Pango.Layout layout = context.Layout;
            layout.Width = (int)((cellWidth - cellHeight - x - 10) * Pango.Scale.PangoScale);
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.FontDescription.Weight = Pango.Weight.Bold;

            // Compute the layout sizes for both lines for centering on the cell
            int old_size = layout.FontDescription.Size;

            layout.SetText (feed.Title ?? String.Empty);
            layout.GetPixelSize (out fl_width, out fl_height);

            if (feed.DbId > 0) {
                layout.FontDescription.Weight = Pango.Weight.Normal;
                layout.FontDescription.Size = (int)(old_size * Pango.Scale.Small);
                layout.FontDescription.Style = Pango.Style.Italic;

                if (feed.LastDownloadTime == DateTime.MinValue) {
                    layout.SetText (Catalog.GetString ("Never updated"));
                } else if (feed.LastDownloadTime.Date == DateTime.Now.Date) {
                    layout.SetText (String.Format (Catalog.GetString ("Updated at {0}"), feed.LastDownloadTime.ToShortTimeString ()));
                } else {
                    layout.SetText (String.Format (Catalog.GetString ("Updated {0}"), Hyena.Query.RelativeTimeSpanQueryValue.RelativeToNow (feed.LastDownloadTime).ToUserQuery ()));
                }
                layout.GetPixelSize (out sl_width, out sl_height);
            }

            // Calculate the layout positioning
            x = ((int)cellHeight - x) + 10;
            y = (int)((cellHeight - (fl_height + sl_height)) / 2);

            // Render the second line first since we have that state already
            if (feed.DbId > 0) {
                context.Context.MoveTo (x, y + fl_height);
                context.Context.Color = text_color;
                PangoCairoHelper.ShowLayout (context.Context, layout);
            }

            // Render the first line, resetting the state
            layout.SetText (feed.Title ?? String.Empty);
            layout.FontDescription.Weight = Pango.Weight.Bold;
            layout.FontDescription.Size = old_size;
            layout.FontDescription.Style = Pango.Style.Normal;

            layout.SetText (feed.Title ?? String.Empty);

            context.Context.MoveTo (x, y);
            text_color.A = 1;
            context.Context.Color = text_color;
            PangoCairoHelper.ShowLayout (context.Context, layout);
        }
Example #33
0
        protected override void ClippedRender(CellContext context)
        {
            var artwork_id = BoundObject as string;
            var image_surface = artwork_id != null && artwork_manager != null
                ? artwork_manager.LookupScaleSurface (artwork_id, (int)ImageSize, true)
                : null;

            ArtworkRenderer.RenderThumbnail (context.Context,
                image_surface, false,
                0, 0, ImageSize, ImageSize,
                true, context.Theme.Context.Radius,
                image_surface == null, new Color (0.8, 0.8, 0.8)
            );
        }
 public string GetTooltipMarkup(CellContext cellContext, double columnWidth)
 {
     return GetTextAlternative (BoundObject);
 }
        public override void Render(CellContext context, StateFlags state, double cellWidth, double cellHeight)
        {
            context.Context.Translate (0, 0.5);
            int draw_x = 0;

            foreach (int i in AttributesForBoundObject) {
                Gdk.Pixbuf render_pixbuf = pixbufs[i];

                if (render_pixbuf != null) {
                    Cairo.Rectangle pixbuf_area = new Cairo.Rectangle (draw_x,
                        (cellHeight - render_pixbuf.Height) / 2, render_pixbuf.Width, render_pixbuf.Height);

                    if (!context.Opaque) {
                        context.Context.Save ();
                    }

                    Gdk.CairoHelper.SetSourcePixbuf (context.Context, render_pixbuf, pixbuf_area.X, pixbuf_area.Y);
                    context.Context.Rectangle (pixbuf_area);

                    if (!context.Opaque) {
                        context.Context.Clip ();
                        context.Context.PaintWithAlpha (0.5);
                        context.Context.Restore ();
                    } else {
                        context.Context.Fill ();
                    }
                }

                draw_x += ICON_SIZE;
            }
        }
        public override void Render(CellContext context, StateFlags state, double cellWidth, double cellHeight)
        {
            TrackInfo track = BoundTrack;
            if (track == null) {
                return;
            }

            int icon_index = GetIconIndex (track);
            TooltipMarkup = icon_index == -1 ? null : StatusNames[icon_index];

            if (icon_index < 0 || pixbufs == null || pixbufs[icon_index] == null) {
                return;
            }

            context.Context.Translate (0, 0.5);

            Gdk.Pixbuf render_pixbuf = pixbufs[icon_index];

            Cairo.Rectangle pixbuf_area = new Cairo.Rectangle ((cellWidth - render_pixbuf.Width) / 2,
                (cellHeight - render_pixbuf.Height) / 2, render_pixbuf.Width, render_pixbuf.Height);

            if (!context.Opaque) {
                context.Context.Save ();
            }

            Gdk.CairoHelper.SetSourcePixbuf (context.Context, render_pixbuf, pixbuf_area.X, pixbuf_area.Y);
            context.Context.Rectangle (pixbuf_area);

            if (!context.Opaque) {
                context.Context.Clip ();
                context.Context.PaintWithAlpha (0.5);
                context.Context.Restore ();
            } else {
                context.Context.Fill ();
            }
        }
Example #37
0
 public string GetTooltipMarkup(CellContext cellContext, double columnWidth)
 {
     UpdateText(cellContext, columnWidth);
     return(IsEllipsized ? GLib.Markup.EscapeText(Text) : null);
 }
        public override void Render (CellContext context)
        {
            if (inner_allocation.IsEmpty) {
                return;
            }

            // Need to call this again here to make sure we have the latest artwork
            var album = BoundObject as AlbumInfo;
            if (album != null) {
                image_surface = artwork_manager != null
                    ? artwork_manager.LookupScaleSurface (album.ArtworkId, (int)ImageSize, true)
                    : null;
            }

            context.Context.Translate (inner_allocation.X, inner_allocation.Y);

            RenderImageSurface (context, image_allocation, image_surface);

            // Render the overlay
            if (IsGridLayout && prelight_opacity > 0) {
                var cr = context.Context;
                var x = image_allocation.Width / 2.0;
                var y = image_allocation.Height / 2.0;
                var grad = new RadialGradient (x, y, 0, x, y, x);
                grad.AddColorStop (0, new Color (0, 0, 0, 0.1 * prelight_opacity));
                grad.AddColorStop (1, new Color (0, 0, 0, 0.35 * prelight_opacity));
                cr.Pattern = grad;
                CairoExtensions.RoundedRectangle (cr, image_allocation.X, image_allocation.Y,
                    image_allocation.Width, image_allocation.Height, context.Theme.Context.Radius);
                cr.Fill ();
                grad.Destroy ();

                /*cr.Save ();
                cr.LineWidth = 2;
                cr.Antialias = Cairo.Antialias.Default;

                // math prep for rendering multiple controls...
                double max_controls = 3;
                double spacing = 4;
                double radius = (width - ((max_controls + 1) * spacing)) / max_controls / 2;

                // render first control
                cr.Arc (width / 2, height - radius - 2 * spacing, radius, 0, 2 * Math.PI);

                cr.Color = new Color (0, 0, 0, 0.4);
                cr.FillPreserve ();
                cr.Color = new Color (1, 1, 1, 0.8);
                cr.Stroke ();

                cr.Restore ();*/
            }

            if (lines == null || lines.Length < 2) {
                return;
            }

            var text_color = context.Theme.Colors.GetWidgetColor (GtkColorClass.Text, context.State);

            var layout = context.Layout;
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.Width = (int)(first_line_allocation.Width * Pango.Scale.PangoScale);

            int normal_size = layout.FontDescription.Size;
            int small_size = (int)(normal_size * Pango.Scale.Small);

            if (!String.IsNullOrEmpty (lines[0])) {
                layout.FontDescription.Size = small_size;
                layout.SetText (lines[0]);

                context.Context.Color = text_color;
                context.Context.MoveTo (first_line_allocation.X, first_line_allocation.Y);
                PangoCairoHelper.ShowLayout (context.Context, layout);
            }

            if (!String.IsNullOrEmpty (lines[1])) {
                layout.FontDescription.Weight = Pango.Weight.Normal;
                layout.FontDescription.Size = small_size;
                layout.SetText (lines[1]);

                text_color.A = 0.60;
                context.Context.Color = text_color;
                context.Context.MoveTo (second_line_allocation.X, second_line_allocation.Y);
                PangoCairoHelper.ShowLayout (context.Context, layout);
            }

            layout.FontDescription.Size = normal_size;
        }