[f-spot/icon-view-cleanup: 22/24] Clean up drawing code in CellGridView
- From: Mike Gemünde <mgemuende src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [f-spot/icon-view-cleanup: 22/24] Clean up drawing code in CellGridView
- Date: Tue, 17 Aug 2010 19:21:54 +0000 (UTC)
commit cda297b2ea9c71c1831e0aafbb9e62d4179a9717
Author: Mike Gemünde <mike gemuende de>
Date: Mon Aug 16 19:32:55 2010 +0200
Clean up drawing code in CellGridView
I love this kind of removing code...
src/Clients/MainApp/FSpot.Widgets/CellGridView.cs | 58 ++++++++++-----------
1 files changed, 28 insertions(+), 30 deletions(-)
---
diff --git a/src/Clients/MainApp/FSpot.Widgets/CellGridView.cs b/src/Clients/MainApp/FSpot.Widgets/CellGridView.cs
index 5e327f0..8ed2cd8 100644
--- a/src/Clients/MainApp/FSpot.Widgets/CellGridView.cs
+++ b/src/Clients/MainApp/FSpot.Widgets/CellGridView.cs
@@ -11,6 +11,7 @@
*/
using System;
+using System.Collections.Generic;
using Gtk;
using Gdk;
@@ -255,6 +256,31 @@ namespace FSpot.Widgets
return bounds;
}
+ // TODO: move to utility class
+ protected int Limit (int lower_bound, int value, int upper_bound)
+ {
+ return Math.Max (lower_bound, Math.Min (value, upper_bound));
+ }
+
+ public IEnumerable<int> CellsInRect (Rectangle area)
+ {
+ int start_cell_column = Limit (0, (area.X - border_size) / cell_width, Allocation.Width);
+ int start_cell_row = Limit (0, (area.Y - border_size) / cell_height, Allocation.Height);
+
+ int end_cell_column = Limit (0, (area.X + area.Width - border_size) / cell_width, Allocation.Width);
+ int end_cell_row = Limit (0, (area.Y + area.Height - border_size) / cell_height, Allocation.Height);
+
+
+ for (int cell_row = start_cell_row; cell_row <= end_cell_row; cell_row ++) {
+
+ for (int cell_column = start_cell_column; cell_column <= end_cell_column; cell_column ++) {
+
+ yield return cell_column + cell_row * cells_per_row;
+
+ }
+ }
+ }
+
public void ScrollTo (int cell_num)
{
ScrollTo (cell_num, true);
@@ -421,36 +447,8 @@ namespace FSpot.Widgets
private void DrawAllCells (Gdk.Rectangle area)
{
- if (cell_width == 0 || cell_height == 0)
- return;
-
- int start_cell_column = Math.Max ((area.X - border_size) / cell_width, 0);
- int start_cell_row = Math.Max ((area.Y - border_size) / cell_height, 0);
- int start_cell_num = start_cell_column + start_cell_row * cells_per_row;
-
- int start_cell_x, cell_y;
- CellPosition (start_cell_num, out start_cell_x, out cell_y);
-
- int end_cell_column = Math.Max ((area.X + area.Width - border_size) / cell_width, 0);
- int end_cell_row = Math.Max ((area.Y + area.Height - border_size) / cell_height, 0);
-
- int num_rows = end_cell_row - start_cell_row + 1;
- int num_cols = Math.Min (end_cell_column - start_cell_column + 1, cells_per_row - start_cell_column);
-
- int i, cell_num;
-
- for (i = 0, cell_num = start_cell_num; i < num_rows && cell_num < cell_count; i ++) {
-
- int cell_x = start_cell_x;
-
- //Log.DebugFormat ("Drawing row {0}", start_cell_row + i);
- for (int j = 0; j < num_cols && cell_num + j < cell_count; j ++) {
- DrawCell (cell_num + j, area);
- cell_x += cell_width;
- }
-
- cell_y += cell_height;
- cell_num += cells_per_row;
+ foreach (var cell_num in CellsInRect (area)) {
+ DrawCell (cell_num, area);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]