[banshee/grid: 4/4] [Grid] First import of the new grid code



commit d0b9d8aef83d7a968a552c6c0e644ebb08e2a50f
Author: Aaron Bockover <abockover novell com>
Date:   Sat Nov 21 17:30:39 2009 -0500

    [Grid] First import of the new grid code
    
    This first pass implements basic grid layout and rendering.
    No grid interaction has been implemented, and there is an
    off-by-one cell layout error, some minor layout math problems,
    etc.
    
    The foundation is there though. Enjoy.

 .../Banshee.Collection.Gui/AlbumListView.cs        |    3 +-
 .../Banshee.Collection.Gui/ColumnCellAlbum.cs      |   15 +++-
 .../Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs         |    2 +
 .../Hyena.Data.Gui/ListView/ListView_Header.cs     |    2 +-
 .../ListView/ListView_Interaction.cs               |    4 +-
 .../Hyena.Data.Gui/ListView/ListView_Rendering.cs  |   99 +++++++++++++++++++-
 .../Hyena.Data.Gui/ListView/ListView_Windowing.cs  |    4 +
 7 files changed, 118 insertions(+), 11 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
index be530e2..86b3ef4 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/AlbumListView.cs
@@ -42,7 +42,8 @@ namespace Banshee.Collection.Gui
     {
         public AlbumListView () : base ()
         {
-            ColumnCellAlbum renderer = new ColumnCellAlbum ();
+            LayoutStyle = DataViewLayoutStyle.Grid;
+            ColumnCellAlbum renderer = new ColumnCellAlbum () { LayoutStyle = LayoutStyle };
             column_controller.Add (new Column ("Album", renderer, 1.0));
             ColumnController = column_controller;
 
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs
index 8371884..35f790f 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/ColumnCellAlbum.cs
@@ -85,8 +85,11 @@ namespace Banshee.Collection.Gui
             AlbumInfo album = (AlbumInfo)BoundObject;
 
             bool is_default = false;
+            int actual_image_size = LayoutStyle == DataViewLayoutStyle.Grid
+                ? (int)Math.Max (Math.Min (cellWidth, cellHeight) - 10, 0)
+                : image_size;
             ImageSurface image = artwork_manager == null ? null
-                : artwork_manager.LookupScaleSurface (album.ArtworkId, image_size, true);
+                : artwork_manager.LookupScaleSurface (album.ArtworkId, actual_image_size, true);
 
             if (image == null) {
                 image = default_cover_image;
@@ -94,13 +97,19 @@ namespace Banshee.Collection.Gui
             }
 
             // int image_render_size = is_default ? image.Height : (int)cellHeight - 8;
-            int image_render_size = image_size;
-            int x = image_spacing;
+            int image_render_size = actual_image_size;
+            int x = LayoutStyle == DataViewLayoutStyle.Grid
+                ? ((int)cellWidth - image_render_size) / 2
+                : 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);
 
+            if (LayoutStyle == DataViewLayoutStyle.Grid) {
+                return;
+            }
+
             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;
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
index 65b3904..4817dd2 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
@@ -129,6 +129,8 @@ namespace Hyena.Data.Gui
             set { expand = value; }
         }
 
+        public DataViewLayoutStyle LayoutStyle { get; set; }
+
         public string Property {
             get { return property; }
             set {
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Header.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Header.cs
index f9aae51..fade711 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Header.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Header.cs
@@ -523,7 +523,7 @@ namespace Hyena.Data.Gui
         private int header_height = 0;
         private int HeaderHeight {
             get {
-                if (!header_visible) {
+                if (!header_visible || LayoutStyle != DataViewLayoutStyle.List) {
                     return 0;
                 }
 
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
index 02a05de..8706c33 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
@@ -804,7 +804,9 @@ namespace Hyena.Data.Gui
             }
 
             if (vadjustment != null && model != null) {
-                vadjustment.Upper = (RowHeight * (model.Count));
+                vadjustment.Upper = LayoutStyle == DataViewLayoutStyle.List
+                    ? RowHeight * model.Count
+                    : (RowHeight * model.Count) / GridColumnsInView;
                 vadjustment.StepIncrement = RowHeight;
                 if (vadjustment.Value + vadjustment.PageSize > vadjustment.Upper) {
                     vadjustment.Value = vadjustment.Upper - vadjustment.PageSize;
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
index 075e9a9..db1d53f 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
@@ -99,17 +99,22 @@ namespace Hyena.Data.Gui
             cell_context.Layout = pango_layout;
 
             Theme.DrawFrameBackground (cairo_context, Allocation, true);
-            if (header_visible && column_controller != null) {
+            if (header_visible && LayoutStyle != DataViewLayoutStyle.Grid && column_controller != null) {
                 PaintHeader (damage);
             }
 
-            if (HasFocus)
+            if (HasFocus) {
                 Theme.DrawFrameBorderFocused (cairo_context, Allocation);
-            else
+            } else {
                 Theme.DrawFrameBorder (cairo_context, Allocation);
+            }
 
             if (Model != null) {
-                PaintRows (damage);
+                if (LayoutStyle == DataViewLayoutStyle.List) {
+                    PaintList (damage);
+                } else {
+                    PaintGrid (damage);
+                }
             }
 
             PaintDraggingColumn (damage);
@@ -120,6 +125,8 @@ namespace Hyena.Data.Gui
             return true;
         }
 
+#region Header Rendering
+
         private void PaintHeader (Rectangle clip)
         {
             Rectangle rect = header_rendering_alloc;
@@ -201,7 +208,11 @@ namespace Hyena.Data.Gui
             }
         }
 
-        private void PaintRows (Rectangle clip)
+#endregion
+
+#region List Rendering
+
+        private void PaintList (Rectangle clip)
         {
             // TODO factor this out?
             // Render the sort effect to the GdkWindow.
@@ -422,6 +433,62 @@ namespace Hyena.Data.Gui
             cairo_context.Stroke ();
         }
 
+#endregion
+
+#region Grid Rendering
+
+        private void PaintGrid (Rectangle clip)
+        {
+            clip.Intersect (list_rendering_alloc);
+            cairo_context.Rectangle (clip.X, clip.Y, clip.Width, clip.Height);
+            cairo_context.Clip ();
+
+            cell_context.Clip = clip;
+            cell_context.TextAsForeground = false;
+
+            int rows_in_view = RowsInView;
+            int columns_in_view = GridColumnsInView;
+            int cell_height = RowHeight;
+            int cell_width = GridCellWidth + ((list_rendering_alloc.Width -
+                columns_in_view * GridCellWidth) / columns_in_view);
+            int vadjustment_value = VadjustmentValue;
+
+            int first_model_row = vadjustment_value / (row_height * columns_in_view);
+            int last_model_row = Math.Min (model.Count, first_model_row + rows_in_view * columns_in_view);
+            int offset = list_rendering_alloc.Y - vadjustment_value % row_height;
+
+            var grid_cell_alloc = new Rectangle () {
+                X = list_rendering_alloc.X,
+                Y = offset,
+                Width = GridCellWidth,
+                Height = GridCellHeight
+            };
+
+            Console.WriteLine ("FIRST = {0}, LAST = {1}", first_model_row, last_model_row);
+
+            for (int model_row_index = first_model_row, view_row_index = 0, view_column_index = 0;
+                model_row_index < last_model_row; model_row_index++) {
+
+                var item = model[model_row_index];
+                PaintCell (item, 0, model_row_index, grid_cell_alloc,
+                    IsRowOpaque (item), IsRowBold (item), StateType.Normal, false);
+
+                if (++view_column_index % columns_in_view == 0) {
+                    view_row_index++;
+                    view_column_index = 0;
+
+                    grid_cell_alloc.Y += cell_height;
+                    grid_cell_alloc.X = list_rendering_alloc.X;
+                } else {
+                    grid_cell_alloc.X += cell_width;
+                }
+            }
+
+            cairo_context.ResetClip ();
+        }
+
+#endregion
+
         private void InvalidateList ()
         {
             if (IsRealized) {
@@ -474,6 +541,10 @@ namespace Hyena.Data.Gui
         private int row_height = 32;
         public int RowHeight {
             get {
+                if (LayoutStyle == DataViewLayoutStyle.Grid) {
+                    return GridCellHeight;
+                }
+
                 if (RecomputeRowHeight) {
                     row_height = RowHeightProvider != null
                         ? RowHeightProvider (this)
@@ -488,5 +559,23 @@ namespace Hyena.Data.Gui
                 return row_height;
             }
         }
+
+        private DataViewLayoutStyle layout_style = DataViewLayoutStyle.List;
+        public DataViewLayoutStyle LayoutStyle {
+            get { return layout_style; }
+            set {
+                layout_style = value;
+                MoveResize (Allocation);
+                InvalidateList ();
+            }
+        }
+
+        public int GridCellWidth {
+            get { return 100; }
+        }
+
+        public int GridCellHeight {
+            get { return 100; }
+        }
     }
 }
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
index 99ca456..9b2cbfa 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
@@ -178,5 +178,9 @@ namespace Hyena.Data.Gui
         protected int RowsInView {
             get { return (int) Math.Ceiling ((list_rendering_alloc.Height + RowHeight) / (double) RowHeight); }
         }
+
+        protected int GridColumnsInView {
+            get { return Math.Max (list_rendering_alloc.Width / GridCellWidth, 1); }
+        }
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]