Skip to content

Commit

Permalink
Merge pull request #31 from Sanva/gtk3
Browse files Browse the repository at this point in the history
*icon view* thumbnail decorations, *edit mode* selection, background and edge case optimization.
  • Loading branch information
decriptor committed Jun 29, 2015
2 parents 3345613 + 925efee commit c84e813
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 206 deletions.
10 changes: 4 additions & 6 deletions src/Clients/MainApp/FSpot.Widgets/CollectionCellGridView.cs
Expand Up @@ -450,10 +450,9 @@ protected override void DrawCell (int cell_num, Rectangle cell_area, Cairo.Conte
thumbnail.Dispose ();
}

// GTK3: Render
// Render Decorations
if (DisplayRatings && region.X == draw.X && region.X != 0) {
// rating_renderer.Render (BinWindow, this, region, cell_expose_area, cell_state, photo);
rating_renderer.Render (cr, this, region, cell_expose_area, cell_state, photo);
}

// Render Captions
Expand All @@ -462,24 +461,23 @@ protected override void DrawCell (int cell_num, Rectangle cell_area, Cairo.Conte
caption_area.X = cell_area.X + CELL_BORDER_WIDTH;
caption_area.Width = cell_area.Width - 2 * CELL_BORDER_WIDTH;

// GTK3: Render
if (DisplayDates) {
caption_area.Height = date_renderer.GetHeight (this, ThumbnailWidth);
// date_renderer.Render (BinWindow, this, caption_area, cell_expose_area, cell_state, photo);
date_renderer.Render (cr, this, caption_area, cell_expose_area, cell_state, photo);

caption_area.Y += caption_area.Height;
}

if (DisplayFilenames) {
caption_area.Height = filename_renderer.GetHeight (this, ThumbnailWidth);
// filename_renderer.Render (BinWindow, this, caption_area, cell_expose_area, cell_state, photo);
filename_renderer.Render (cr, this, caption_area, cell_expose_area, cell_state, photo);

caption_area.Y += caption_area.Height;
}

if (DisplayTags) {
caption_area.Height = tag_renderer.GetHeight (this, ThumbnailWidth);
// tag_renderer.Render (BinWindow, this, caption_area, cell_expose_area, cell_state, photo);
tag_renderer.Render (cr, this, caption_area, cell_expose_area, cell_state, photo);

caption_area.Y += caption_area.Height;
}
Expand Down
13 changes: 6 additions & 7 deletions src/Clients/MainApp/FSpot.Widgets/ThumbnailCaptionRenderer.cs
Expand Up @@ -44,13 +44,12 @@ public abstract class ThumbnailCaptionRenderer

public abstract int GetHeight (Widget widget, int width);

// GTK3: Drawable
// public abstract void Render (Drawable window,
// Widget widget,
// Rectangle cell_area,
// Rectangle expose_area,
// StateType cell_state,
// IPhoto photo);
public abstract void Render (Cairo.Context cr,
Widget widget,
Rectangle cell_area,
Rectangle expose_area,
StateType cell_state,
IPhoto photo);

#endregion

Expand Down
78 changes: 38 additions & 40 deletions src/Clients/MainApp/FSpot.Widgets/ThumbnailDateCaptionRenderer.cs
Expand Up @@ -66,46 +66,44 @@ public override int GetHeight (Widget widget, int width)
return widget.Style.FontDescription.MeasureTextHeight (widget.PangoContext);
}

// GTK3: Drawable
// public override void Render (Drawable window,
// Widget widget,
// Rectangle cell_area,
// Rectangle expose_area,
// StateType cell_state,
// IPhoto photo)
// {
// string date_text = null;
//
// if (photo is IInvalidPhotoCheck && (photo as IInvalidPhotoCheck).IsInvalid)
// return;
//
// if (cell_area.Width > 200) {
// date_text = photo.Time.ToString ();
// } else {
// date_text = photo.Time.ToShortDateString ();
// }
//
// Pango.Layout layout = null;
// if ( ! cache.TryGetValue (date_text, out layout)) {
// layout = new Pango.Layout (widget.PangoContext);
// layout.SetText (date_text);
//
// cache.Add (date_text, layout);
// }
//
// Rectangle layout_bounds;
// layout.GetPixelSize (out layout_bounds.Width, out layout_bounds.Height);
//
// layout_bounds.Y = cell_area.Y;
// layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2;
//
// if (layout_bounds.IntersectsWith (expose_area)) {
// Style.PaintLayout (widget.Style, window, cell_state,
// true, expose_area, widget, "IconView",
// layout_bounds.X, layout_bounds.Y,
// layout);
// }
// }
public override void Render (Cairo.Context cr,
Widget widget,
Rectangle cell_area,
Rectangle expose_area,
StateType cell_state,
IPhoto photo)
{
string date_text = null;

if (photo is IInvalidPhotoCheck && (photo as IInvalidPhotoCheck).IsInvalid)
return;

if (cell_area.Width > 200) {
date_text = photo.Time.ToString ();
} else {
date_text = photo.Time.ToShortDateString ();
}

Pango.Layout layout = null;
if ( ! cache.TryGetValue (date_text, out layout)) {
layout = new Pango.Layout (widget.PangoContext);
layout.SetText (date_text);

cache.Add (date_text, layout);
}

Rectangle layout_bounds;
layout.GetPixelSize (out layout_bounds.Width, out layout_bounds.Height);

layout_bounds.Y = cell_area.Y;
layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2;

if (layout_bounds.IntersectsWith (expose_area)) {
widget.StyleContext.Save ();
widget.StyleContext.RenderLayout (cr, layout_bounds.X, layout_bounds.Y, layout);
widget.StyleContext.Restore ();
}
}

#endregion

Expand Down
13 changes: 6 additions & 7 deletions src/Clients/MainApp/FSpot.Widgets/ThumbnailDecorationRenderer.cs
Expand Up @@ -43,13 +43,12 @@ public abstract class ThumbnailDecorationRenderer

#region Drawing Methods

// GTK3: Drawable
// public abstract void Render (Drawable window,
// Widget widget,
// Rectangle cell_area,
// Rectangle expose_area,
// StateType cell_state,
// IPhoto photo);
public abstract void Render (Cairo.Context cr,
Widget widget,
Rectangle cell_area,
Rectangle expose_area,
StateType cell_state,
IPhoto photo);

#endregion

Expand Down
Expand Up @@ -57,24 +57,25 @@ public ThumbnailRatingDecorationRenderer ()

#region Drawing Methods

// GTK3: Drawable
// public override void Render (Drawable window,
// Widget widget,
// Rectangle cell_area,
// Rectangle expose_area,
// StateType cell_state,
// IPhoto photo)
// {
// if (photo.Rating > 0) {
// rating_renderer.Value = (int) photo.Rating;
//
// using (var rating_pixbuf = rating_renderer.RenderPixbuf ()) {
// rating_pixbuf.RenderToDrawable (window, widget.Style.WhiteGC,
// 0, 0, cell_area.X, cell_area.Y,
// -1, -1, RgbDither.None, 0, 0);
// }
// }
// }
public override void Render (Cairo.Context cr,
Widget widget,
Rectangle cell_area,
Rectangle expose_area,
StateType cell_state,
IPhoto photo)
{
if (photo.Rating > 0) {
rating_renderer.Value = (int) photo.Rating;

using (var rating_pixbuf = rating_renderer.RenderPixbuf ()) {
cr.Save ();
Gdk.CairoHelper.SetSourcePixbuf (cr, rating_pixbuf, cell_area.X, cell_area.Y);
cr.Rectangle (cell_area.X, cell_area.Y, rating_pixbuf.Width, rating_pixbuf.Height);
cr.Fill ();
cr.Restore ();
}
}
}

#endregion

Expand Down
124 changes: 61 additions & 63 deletions src/Clients/MainApp/FSpot.Widgets/ThumbnailTagsCaptionRenderer.cs
Expand Up @@ -70,69 +70,67 @@ public override int GetHeight (Widget widget, int width)
return tag_icon_size;
}

// GTK3: Drawable
// public override void Render (Drawable window,
// Widget widget,
// Rectangle cell_area,
// Rectangle expose_area,
// StateType cell_state,
// IPhoto photo)
// {
// Tag [] tags = photo.Tags;
// Rectangle tag_bounds;
//
// tag_bounds.X = cell_area.X + (cell_area.Width + tag_icon_hspacing - tags.Length * (tag_icon_size + tag_icon_hspacing)) / 2;
// tag_bounds.Y = cell_area.Y;// + cell_area.Height - cell_border_width - tag_icon_size + tag_icon_vspacing;
// tag_bounds.Width = tag_icon_size;
// tag_bounds.Height = tag_icon_size;
//
//
// foreach (Tag t in tags) {
//
// if (t == null)
// continue;
//
// Pixbuf icon = t.Icon;
//
// Tag tag_iter = t.Category;
// while (icon == null && tag_iter != App.Instance.Database.Tags.RootCategory && tag_iter != null) {
// icon = tag_iter.Icon;
// tag_iter = tag_iter.Category;
// }
//
// if (icon == null)
// continue;
//
// Rectangle region;
// if (tag_bounds.Intersect (expose_area, out region)) {
// Pixbuf scaled_icon;
// if (icon.Width == tag_bounds.Width) {
// scaled_icon = icon;
// } else {
// scaled_icon = icon.ScaleSimple (tag_bounds.Width,
// tag_bounds.Height,
// InterpType.Bilinear);
// }
//
// Cms.Profile screen_profile;
// if (FSpot.ColorManagement.Profiles.TryGetValue (Preferences.Get<string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
// FSpot.ColorManagement.ApplyProfile (scaled_icon, screen_profile);
//
// scaled_icon.RenderToDrawable (window, widget.Style.WhiteGC,
// region.X - tag_bounds.X,
// region.Y - tag_bounds.Y,
// region.X, region.Y,
// region.Width, region.Height,
// RgbDither.None, region.X, region.Y);
//
// if (scaled_icon != icon) {
// scaled_icon.Dispose ();
// }
// }
//
// tag_bounds.X += tag_bounds.Width + tag_icon_hspacing;
// }
// }
public override void Render (Cairo.Context cr,
Widget widget,
Rectangle cell_area,
Rectangle expose_area,
StateType cell_state,
IPhoto photo)
{
Tag [] tags = photo.Tags;
Rectangle tag_bounds;

tag_bounds.X = cell_area.X + (cell_area.Width + tag_icon_hspacing - tags.Length * (tag_icon_size + tag_icon_hspacing)) / 2;
tag_bounds.Y = cell_area.Y;
tag_bounds.Width = tag_icon_size;
tag_bounds.Height = tag_icon_size;


foreach (Tag t in tags) {

if (t == null)
continue;

Pixbuf icon = t.Icon;

Tag tag_iter = t.Category;
while (icon == null && tag_iter != App.Instance.Database.Tags.RootCategory && tag_iter != null) {
icon = tag_iter.Icon;
tag_iter = tag_iter.Category;
}

if (icon == null)
continue;

Rectangle region;
if (tag_bounds.Intersect (expose_area, out region)) {
Pixbuf scaled_icon;
if (icon.Width == tag_bounds.Width) {
scaled_icon = icon;
} else {
scaled_icon = icon.ScaleSimple (tag_bounds.Width,
tag_bounds.Height,
InterpType.Bilinear);
}

Cms.Profile screen_profile;
if (FSpot.ColorManagement.Profiles.TryGetValue (Preferences.Get<string> (Preferences.COLOR_MANAGEMENT_DISPLAY_PROFILE), out screen_profile))
FSpot.ColorManagement.ApplyProfile (scaled_icon, screen_profile);

cr.Save ();
Gdk.CairoHelper.SetSourcePixbuf (cr, scaled_icon, tag_bounds.X, tag_bounds.Y);
cr.Rectangle (tag_bounds.X, tag_bounds.Y, tag_bounds.Width, tag_bounds.Height);
cr.Fill ();
cr.Restore ();

if (scaled_icon != icon) {
scaled_icon.Dispose ();
}
}

tag_bounds.X += tag_bounds.Width + tag_icon_hspacing;
}
}

#endregion

Expand Down
50 changes: 24 additions & 26 deletions src/Clients/MainApp/FSpot.Widgets/ThumbnailTextCaptionRenderer.cs
Expand Up @@ -49,32 +49,30 @@ public override int GetHeight (Widget widget, int width)
return widget.Style.FontDescription.MeasureTextHeight (widget.PangoContext);
}

// GTK3: Drawable
// public override void Render (Drawable window,
// Widget widget,
// Rectangle cell_area,
// Rectangle expose_area,
// StateType cell_state,
// IPhoto photo)
// {
// string text = GetRenderText (photo);
//
// var layout = new Pango.Layout (widget.PangoContext);
// layout.SetText (text);
//
// Rectangle layout_bounds;
// layout.GetPixelSize (out layout_bounds.Width, out layout_bounds.Height);
//
// layout_bounds.Y = cell_area.Y;
// layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2;
//
// if (layout_bounds.IntersectsWith (expose_area)) {
// Style.PaintLayout (widget.Style, window, cell_state,
// true, expose_area, widget, "IconView",
// layout_bounds.X, layout_bounds.Y,
// layout);
// }
// }
public override void Render (Cairo.Context cr,
Widget widget,
Rectangle cell_area,
Rectangle expose_area,
StateType cell_state,
IPhoto photo)
{
string text = GetRenderText (photo);

var layout = new Pango.Layout (widget.PangoContext);
layout.SetText (text);

Rectangle layout_bounds;
layout.GetPixelSize (out layout_bounds.Width, out layout_bounds.Height);

layout_bounds.Y = cell_area.Y;
layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2;

if (layout_bounds.IntersectsWith (expose_area)) {
widget.StyleContext.Save ();
widget.StyleContext.RenderLayout (cr, layout_bounds.X, layout_bounds.Y, layout);
widget.StyleContext.Restore ();
}
}

protected abstract string GetRenderText (IPhoto photo);

Expand Down

0 comments on commit c84e813

Please sign in to comment.