[hyena/gtk3] ListView: Fix rendering for gtk3
- From: Bertrand Lorentz <blorentz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hyena/gtk3] ListView: Fix rendering for gtk3
- Date: Sun, 24 Jul 2011 15:46:17 +0000 (UTC)
commit 207057dc48a176b6ead0506ba0db9809d671393f
Author: Olivier Dufour <olivier duff gmail com>
Date: Sat Jul 23 12:25:30 2011 +0200
ListView: Fix rendering for gtk3
Signed-off-by: Bertrand Lorentz <bertrand lorentz gmail com>
.../Hyena.Data.Gui/ListView/ListView_Rendering.cs | 183 +++++++++-----------
1 files changed, 85 insertions(+), 98 deletions(-)
---
diff --git a/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs b/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
index 5bcb3a6..a9225f9 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
@@ -42,7 +42,6 @@ namespace Hyena.Data.Gui
public partial class ListView<T> : ListViewBase
{
- private Cairo.Context cairo_context;
private CellContext cell_context;
private Pango.Layout pango_layout;
@@ -118,24 +117,14 @@ namespace Hyena.Data.Gui
}
}
- protected override bool OnDamageEvent (Gdk.EventExpose evnt)
+ protected override bool OnDrawn (Cairo.Context cr)
{
if (DoNotRenderNullModel && Model == null) {
return true;
}
- var damage = new Rectangle ();
- for (int i = 0; i < evnt.Region.NumRectangles; i++) {
- var rect_int = evnt.Region.GetRectangle (i);
- var rect =
- new Rectangle (rect_int.X, rect_int.Y, rect_int.Width, rect_int.Height);
- damage = damage.Union (rect);
- }
-
- cairo_context = Gdk.CairoHelper.Create (evnt.Window);
-
cell_context.Layout = PangoLayout;
- cell_context.Context = cairo_context;
+ cell_context.Context = cr;
// FIXME: legacy list foo
if (ViewLayout == null) {
@@ -144,14 +133,14 @@ namespace Hyena.Data.Gui
// treview style
StyleContext.AddClass ("view");
- StyleContext.RenderBackground (cairo_context, Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
+ StyleContext.RenderBackground (cr, Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
// FIXME: ViewLayout will never be null in the future but we'll need
// to deterministically render a header somehow...
if (header_visible && ViewLayout == null && column_controller != null) {
StyleContext.AddRegion ("column-header", RegionFlags.First);
//TODO check flags
- PaintHeader (damage);
+ PaintHeader (cr);
StyleContext.RemoveRegion ("column-header");
}
@@ -160,32 +149,30 @@ namespace Hyena.Data.Gui
// FIXME: ViewLayout will never be null in
// the future, PaintList will go away
if (ViewLayout == null) {
- PaintList (damage);
+ PaintList (cr, Allocation);
} else {
- PaintView ((Rect)damage);
+ PaintView (cr, (Rect)Allocation);
}
}
- StyleContext.RenderFrame (cairo_context, Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
-
- PaintDraggingColumn (damage);
+ StyleContext.RenderFrame (cr, Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
- CairoExtensions.DisposeContext (cairo_context);
+ PaintDraggingColumn (cr);
return true;
}
#region Header Rendering
- private void PaintHeader (Rectangle clip)
+ private void PaintHeader (Cairo.Context cr)
{
- Rectangle rect = header_rendering_alloc;
- rect.Height += Theme.BorderWidth;
- clip.Intersect (rect);
- cairo_context.Rectangle (clip.X, clip.Y, clip.Width, clip.Height);
- cairo_context.Clip ();
+ Rectangle clip = header_rendering_alloc;
+ clip.Height += Theme.BorderWidth;
+ clip.Intersect (Allocation);
+ cr.Rectangle (clip.X, clip.Y, clip.Width, clip.Height);
+ cr.Clip ();
- Theme.DrawHeaderBackground (cairo_context, header_rendering_alloc);
+ Theme.DrawHeaderBackground (cr, header_rendering_alloc);
Rectangle cell_area = new Rectangle ();
cell_area.Y = header_rendering_alloc.Y;
@@ -204,32 +191,32 @@ namespace Hyena.Data.Gui
cell_area.X = column_cache[ci].X1 + Theme.TotalBorderWidth + header_rendering_alloc.X - HadjustmentValue;
cell_area.Width = column_cache[ci].Width;
- PaintHeaderCell (cell_area, ci, false, ref have_drawn_separator);
+ PaintHeaderCell (cr, cell_area, ci, false, ref have_drawn_separator);
}
if (pressed_column_is_dragging && pressed_column_index >= 0) {
cell_area.X = pressed_column_x_drag + Allocation.X - HadjustmentValue;
cell_area.Width = column_cache[pressed_column_index].Width;
- PaintHeaderCell (cell_area, pressed_column_index, true, ref have_drawn_separator);
+ PaintHeaderCell (cr, cell_area, pressed_column_index, true, ref have_drawn_separator);
}
- cairo_context.ResetClip ();
+ cr.ResetClip ();
}
- private void PaintHeaderCell (Rectangle area, int ci, bool dragging, ref bool have_drawn_separator)
+ private void PaintHeaderCell (Cairo.Context cr, Rectangle area, int ci, bool dragging, ref bool have_drawn_separator)
{
if (ci < 0 || column_cache.Length <= ci)
return;
if (ci == ActiveColumn && HasFocus && HeaderFocused) {
- Theme.DrawColumnHeaderFocus (cairo_context, area);
+ Theme.DrawColumnHeaderFocus (cr, area);
}
if (dragging) {
Cairo.Color dark_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Normal));
dark_color = CairoExtensions.ColorShade (dark_color, 0.7);
- Theme.DrawColumnHighlight (cairo_context, area, dark_color);
+ Theme.DrawColumnHighlight (cr, area, dark_color);
StyleContext.Save ();
StyleContext.AddClass ("entry");
@@ -239,29 +226,29 @@ namespace Hyena.Data.Gui
Cairo.Color stroke_color = CairoExtensions.ColorShade (base_color, 0.0);
stroke_color.A = 0.3;
- cairo_context.Color = stroke_color;
- cairo_context.MoveTo (area.X + 0.5, area.Y + 1.0);
- cairo_context.LineTo (area.X + 0.5, area.Bottom);
- cairo_context.MoveTo (area.Right - 0.5, area.Y + 1.0);
- cairo_context.LineTo (area.Right - 0.5, area.Bottom);
- cairo_context.Stroke ();
+ cr.Color = stroke_color;
+ cr.MoveTo (area.X + 0.5, area.Y + 1.0);
+ cr.LineTo (area.X + 0.5, area.Bottom);
+ cr.MoveTo (area.Right - 0.5, area.Y + 1.0);
+ cr.LineTo (area.Right - 0.5, area.Bottom);
+ cr.Stroke ();
}
ColumnCell cell = column_cache[ci].Column.HeaderCell;
if (cell != null) {
- cairo_context.Save ();
- cairo_context.Translate (area.X, area.Y);
+ cr.Save ();
+ cr.Translate (area.X, area.Y);
cell_context.Area = area;
cell_context.State = StateFlags.Normal;
cell.Render (cell_context, area.Width, area.Height);
- cairo_context.Restore ();
+ cr.Restore ();
}
if (!dragging && ci < column_cache.Length - 1 && (have_drawn_separator ||
column_cache[ci].MaxWidth != column_cache[ci].MinWidth)) {
have_drawn_separator = true;
- Theme.DrawHeaderSeparator (cairo_context, area, area.Right);
+ Theme.DrawHeaderSeparator (cr, area, area.Right);
}
}
@@ -269,7 +256,7 @@ namespace Hyena.Data.Gui
#region List Rendering
- private void PaintList (Rectangle clip)
+ private void PaintList (Cairo.Context cr, Rectangle clip)
{
if (ChildSize.Height <= 0) {
return;
@@ -280,7 +267,7 @@ namespace Hyena.Data.Gui
if (sort_column_index != -1 && (!pressed_column_is_dragging || pressed_column_index != sort_column_index)) {
CachedColumn col = column_cache[sort_column_index];
StyleContext.AddRegion ("column", RegionFlags.Sorted);
- StyleContext.RenderBackground (cairo_context,
+ StyleContext.RenderBackground (cr,
list_rendering_alloc.X + col.X1 - HadjustmentValue,
header_rendering_alloc.Bottom + Theme.BorderWidth,
col.Width, list_rendering_alloc.Height + Theme.InnerBorderWidth * 2);
@@ -288,8 +275,8 @@ namespace Hyena.Data.Gui
}
clip.Intersect (list_rendering_alloc);
- cairo_context.Rectangle (clip.X, clip.Y, clip.Width, clip.Height);
- cairo_context.Clip ();
+ cr.Rectangle (clip.X, clip.Y, clip.Width, clip.Height);
+ cr.Clip ();
cell_context.Clip = clip;
cell_context.TextAsForeground = false;
@@ -326,12 +313,12 @@ namespace Hyena.Data.Gui
} else {
if (rules_hint && ri % 2 != 0) {
StyleContext.AddRegion ("row", RegionFlags.Odd);
- StyleContext.RenderBackground (cairo_context, single_list_alloc.X, single_list_alloc.Y,
+ StyleContext.RenderBackground (cr, single_list_alloc.X, single_list_alloc.Y,
single_list_alloc.Width, single_list_alloc.Height);
StyleContext.RemoveRegion ("row");
}
- PaintReorderLine (ri, single_list_alloc);
+ PaintReorderLine (cr, ri, single_list_alloc);
if (Selection != null && Selection.FocusedIndex == ri && !Selection.Contains (ri) && HasFocus) {
CairoCorners corners = CairoCorners.All;
@@ -345,7 +332,7 @@ namespace Hyena.Data.Gui
}
if (HasFocus && !HeaderFocused) // Cursor out of selection.
- Theme.DrawRowCursor (cairo_context, single_list_alloc.X, single_list_alloc.Y,
+ Theme.DrawRowCursor (cr, single_list_alloc.X, single_list_alloc.Y,
single_list_alloc.Width, single_list_alloc.Height,
CairoExtensions.ColorShade (CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Selected)), 0.85));
}
@@ -356,22 +343,22 @@ namespace Hyena.Data.Gui
if (!HasFocus || HeaderFocused)
selection_color = CairoExtensions.ColorShade (selection_color, 1.1);
- Theme.DrawRowSelection (cairo_context, list_rendering_alloc.X, selection_y, list_rendering_alloc.Width, selection_height,
+ Theme.DrawRowSelection (cr, list_rendering_alloc.X, selection_y, list_rendering_alloc.Width, selection_height,
true, true, selection_color, CairoCorners.All);
selection_height = 0;
}
- PaintRow (ri, single_list_alloc, StateFlags.Normal);
+ PaintRow (cr, ri, single_list_alloc, StateFlags.Normal);
}
single_list_alloc.Y += single_list_alloc.Height;
}
// In case the user is dragging to the end of the list
- PaintReorderLine (last_row, single_list_alloc);
+ PaintReorderLine (cr, last_row, single_list_alloc);
if (selection_height > 0) {
- Theme.DrawRowSelection (cairo_context, list_rendering_alloc.X, selection_y,
+ Theme.DrawRowSelection (cr, list_rendering_alloc.X, selection_y,
list_rendering_alloc.Width, selection_height);
}
@@ -384,38 +371,38 @@ namespace Hyena.Data.Gui
Cairo.Color text_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetColor (StateFlags.Selected));
StyleContext.Restore ();
- Theme.DrawRowCursor (cairo_context, selected_focus_alloc.X, selected_focus_alloc.Y,
+ Theme.DrawRowCursor (cr, selected_focus_alloc.X, selected_focus_alloc.Y,
selected_focus_alloc.Width, selected_focus_alloc.Height, text_color);
}
foreach (int ri in selected_rows) {
single_list_alloc.Y = offset + ((ri - first_row) * single_list_alloc.Height);
- PaintRow (ri, single_list_alloc, StateFlags.Selected);
+ PaintRow (cr, ri, single_list_alloc, StateFlags.Selected);
}
- cairo_context.ResetClip ();
+ cr.ResetClip ();
}
- private void PaintReorderLine (int row_index, Rectangle single_list_alloc)
+ private void PaintReorderLine (Cairo.Context cr, int row_index, Rectangle single_list_alloc)
{
if (row_index == drag_reorder_row_index && IsReorderable) {
- cairo_context.Save ();
- cairo_context.LineWidth = 1.0;
- cairo_context.Antialias = Cairo.Antialias.None;
- cairo_context.MoveTo (single_list_alloc.Left, single_list_alloc.Top);
- cairo_context.LineTo (single_list_alloc.Right, single_list_alloc.Top);
+ cr.Save ();
+ cr.LineWidth = 1.0;
+ cr.Antialias = Cairo.Antialias.None;
+ cr.MoveTo (single_list_alloc.Left, single_list_alloc.Top);
+ cr.LineTo (single_list_alloc.Right, single_list_alloc.Top);
StyleContext.Save ();
StyleContext.AddClass ("entry");
- cairo_context.Color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetColor (StateFlags.Normal));
+ cr.Color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetColor (StateFlags.Normal));
StyleContext.Restore ();
- cairo_context.Stroke ();
- cairo_context.Restore ();
+ cr.Stroke ();
+ cr.Restore ();
}
}
- private void PaintRow (int row_index, Rectangle area, StateFlags state)
+ private void PaintRow (Cairo.Context cr, int row_index, Rectangle area, StateFlags state)
{
if (column_cache == null) {
return;
@@ -440,18 +427,18 @@ namespace Hyena.Data.Gui
cell_area.Width = column_cache[ci].Width;
cell_area.X = column_cache[ci].X1 + area.X;
- PaintCell (item, ci, row_index, cell_area, opaque, bold, state, false);
+ PaintCell (cr, item, ci, row_index, cell_area, opaque, bold, state, false);
}
if (pressed_column_is_dragging && pressed_column_index >= 0) {
cell_area.Width = column_cache[pressed_column_index].Width;
cell_area.X = pressed_column_x_drag + list_rendering_alloc.X -
list_interaction_alloc.X - HadjustmentValue;
- PaintCell (item, pressed_column_index, row_index, cell_area, opaque, bold, state, true);
+ PaintCell (cr, item, pressed_column_index, row_index, cell_area, opaque, bold, state, true);
}
}
- private void PaintCell (object item, int column_index, int row_index, Rectangle area, bool opaque, bool bold,
+ private void PaintCell (Cairo.Context cr, object item, int column_index, int row_index, Rectangle area, bool opaque, bool bold,
StateFlags state, bool dragging)
{
ColumnCell cell = column_cache[column_index].Column.GetCell (0);
@@ -469,23 +456,23 @@ namespace Hyena.Data.Gui
Cairo.Color fill_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Normal));
StyleContext.Restore ();
fill_color.A = 0.5;
- cairo_context.Color = fill_color;
- cairo_context.Rectangle (area.X, area.Y, area.Width, area.Height);
- cairo_context.Fill ();
+ cr.Color = fill_color;
+ cr.Rectangle (area.X, area.Y, area.Width, area.Height);
+ cr.Fill ();
}
- cairo_context.Save ();
- cairo_context.Translate (area.X, area.Y);
+ cr.Save ();
+ cr.Translate (area.X, area.Y);
cell_context.Area = area;
cell_context.Opaque = opaque;
cell_context.State = dragging ? StateFlags.Normal : state;
cell.Render (cell_context, area.Width, area.Height);
- cairo_context.Restore ();
+ cr.Restore ();
AccessibleCellRedrawn (column_index, row_index);
}
- private void PaintDraggingColumn (Rectangle clip)
+ private void PaintDraggingColumn (Cairo.Context cr)
{
if (!pressed_column_is_dragging || pressed_column_index < 0) {
return;
@@ -504,30 +491,30 @@ namespace Hyena.Data.Gui
stroke_color.A = 0.3;
StyleContext.Restore ();
- cairo_context.Rectangle (x, header_rendering_alloc.Bottom + 1, column.Width - 2,
+ cr.Rectangle (x, header_rendering_alloc.Bottom + 1, column.Width - 2,
list_rendering_alloc.Bottom - header_rendering_alloc.Bottom - 1);
- cairo_context.Color = fill_color;
- cairo_context.Fill ();
+ cr.Color = fill_color;
+ cr.Fill ();
- cairo_context.MoveTo (x - 0.5, header_rendering_alloc.Bottom + 0.5);
- cairo_context.LineTo (x - 0.5, list_rendering_alloc.Bottom + 0.5);
- cairo_context.LineTo (x + column.Width - 1.5, list_rendering_alloc.Bottom + 0.5);
- cairo_context.LineTo (x + column.Width - 1.5, header_rendering_alloc.Bottom + 0.5);
+ cr.MoveTo (x - 0.5, header_rendering_alloc.Bottom + 0.5);
+ cr.LineTo (x - 0.5, list_rendering_alloc.Bottom + 0.5);
+ cr.LineTo (x + column.Width - 1.5, list_rendering_alloc.Bottom + 0.5);
+ cr.LineTo (x + column.Width - 1.5, header_rendering_alloc.Bottom + 0.5);
- cairo_context.Color = stroke_color;
- cairo_context.LineWidth = 1.0;
- cairo_context.Stroke ();
+ cr.Color = stroke_color;
+ cr.LineWidth = 1.0;
+ cr.Stroke ();
}
#endregion
#region View Layout Rendering
- private void PaintView (Rect clip)
+ private void PaintView (Cairo.Context cr, Rect clip)
{
clip.Intersect ((Rect)list_rendering_alloc);
- cairo_context.Rectangle ((Cairo.Rectangle)clip);
- cairo_context.Clip ();
+ cr.Rectangle ((Cairo.Rectangle)clip);
+ cr.Clip ();
cell_context.Clip = (Gdk.Rectangle)clip;
cell_context.TextAsForeground = false;
@@ -550,7 +537,7 @@ namespace Hyena.Data.Gui
selection_color = CairoExtensions.ColorShade (selection_color, 1.1);
}
- Theme.DrawRowSelection (cairo_context,
+ Theme.DrawRowSelection (cr,
(int)child_allocation.X, (int)child_allocation.Y,
(int)child_allocation.Width, (int)child_allocation.Height,
true, true, selection_color, CairoCorners.All);
@@ -560,15 +547,15 @@ namespace Hyena.Data.Gui
cell_context.State = StateFlags.Normal;
}
- //cairo_context.Save ();
- //cairo_context.Translate (child_allocation.X, child_allocation.Y);
- //cairo_context.Rectangle (0, 0, child_allocation.Width, child_allocation.Height);
- //cairo_context.Clip ();
+ //cr.Save ();
+ //cr.Translate (child_allocation.X, child_allocation.Y);
+ //cr.Rectangle (0, 0, child_allocation.Width, child_allocation.Height);
+ //cr.Clip ();
layout_child.Render (cell_context);
- //cairo_context.Restore ();
+ //cr.Restore ();
}
- cairo_context.ResetClip ();
+ cr.ResetClip ();
}
#endregion
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]