[banshee/grid] Implemented interaction for grid mode
- From: Aaron Bockover <abock src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee/grid] Implemented interaction for grid mode
- Date: Fri, 4 Dec 2009 06:23:29 +0000 (UTC)
commit 35cdcb95fd4acb8e0021d8379f135bcc4b8db5a1
Author: Aaron Bockover <abockover novell com>
Date: Thu Dec 3 13:13:14 2009 +0800
Implemented interaction for grid mode
A few internal methods changed to support grid mode. These methods
also had their names/signatures changed:
GetYAtRow (index) => GetViewPointForModelRow (index)
Now returns a Cairo.PointD offering X,Y coords
GetRowAtY (y) => GetModelRowAt (x, y)
Accepts an X and Y view coordinate and returns a model row index
FocusRow => FocusModelRow
Name changed for clarity
The grid selection rendering is very simple and ugly right now,
but the grid is actually now functional!
There is an offet calculation problem when translation from the
X view coordinate to the view column index.
.../Hyena.Data.Gui/ListView/ListView_Accessible.cs | 4 +-
.../ListView/ListView_DragAndDrop.cs | 4 +-
.../ListView/ListView_Interaction.cs | 68 +++++++++++++-------
.../Hyena.Data.Gui/ListView/ListView_Rendering.cs | 21 ++++++-
4 files changed, 67 insertions(+), 30 deletions(-)
---
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Accessible.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Accessible.cs
index 1c8abc7..4727adb 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Accessible.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Accessible.cs
@@ -61,7 +61,7 @@ namespace Hyena.Data.Gui
int width = GetColumnWidth (column);
int height = RowHeight;
- int y = (int)GetYAtRow (row) - VadjustmentValue + ListAllocation.Y;
+ int y = (int)GetViewPointForModelRow (row).Y - VadjustmentValue + ListAllocation.Y;
int x = ListAllocation.X - HadjustmentValue;
for (int index=0;index<column;index++)
@@ -127,7 +127,7 @@ namespace Hyena.Data.Gui
CachedColumn cached_column = GetCachedColumnForColumn (column);
- row = GetRowAtY (y);
+ row = GetModelRowAt (x, y);
col = cached_column.Index;
}
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs
index 9b5cfb5..64d7a13 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs
@@ -197,13 +197,13 @@ namespace Hyena.Data.Gui
protected int GetDragRow (int y)
{
y = TranslateToListY (y);
- int row = GetRowAtY (y);
+ int row = GetModelRowAt (0, y);
if (row == -1) {
return -1;
}
- if (row != GetRowAtY (y + RowHeight / 2)) {
+ if (row != GetModelRowAt (0, y + RowHeight / 2)) {
row++;
}
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 1926f77..9ee9e7d 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
@@ -141,7 +141,7 @@ namespace Hyena.Data.Gui
}
// Scroll if needed
- double y_at_row = GetYAtRow (row_index);
+ double y_at_row = GetViewPointForModelRow (row_index).Y;
if (align_y) {
if (y_at_row < VadjustmentValue) {
ScrollTo (y_at_row);
@@ -359,10 +359,17 @@ namespace Hyena.Data.Gui
int page_offset = VadjustmentValue % RowHeight;
y = (y + page_offset) % RowHeight;
- icell_area.X = cached_column.X1 + Allocation.X;
- icell_area.Y = (int)GetYAtRow (row_index) + list_interaction_alloc.Y + Allocation.Y;
- icell_area.Width = cached_column.Width;
- icell_area.Height = RowHeight;
+ var view_point = GetViewPointForModelRow (row_index);
+ icell_area.Y = (int)view_point.Y + list_interaction_alloc.Y + Allocation.Y;
+ if (LayoutStyle == DataViewLayoutStyle.Grid) {
+ icell_area.X = (int)view_point.X + Allocation.X;
+ icell_area.Width = GridCellWidth;
+ icell_area.Height = GridCellHeight;
+ } else {
+ icell_area.X = cached_column.X1 + Allocation.X;
+ icell_area.Width = cached_column.Width;
+ icell_area.Height = RowHeight;
+ }
// Send the cell a synthesized input event
if (evnt_motion != null) {
@@ -387,7 +394,7 @@ namespace Hyena.Data.Gui
x -= list_interaction_alloc.X;
y -= list_interaction_alloc.Y;
- row_index = GetRowAtY (y);
+ row_index = GetModelRowAt (x, y);
if (row_index < 0 || row_index >= Model.Count) {
return false;
}
@@ -467,11 +474,12 @@ namespace Hyena.Data.Gui
return true;
}
+ int x = (int)evnt.X - list_interaction_alloc.X;
int y = (int)evnt.Y - list_interaction_alloc.Y;
GrabFocus ();
- int row_index = GetRowAtY (y);
+ int row_index = GetModelRowAt (x, y);
if (row_index < 0 || row_index >= Model.Count) {
Gtk.Drag.SourceUnset (this);
@@ -520,7 +528,7 @@ namespace Hyena.Data.Gui
}
}
- FocusRow (row_index);
+ FocusModelRow (row_index);
// Now that we've worked out the selections, open the context menu
if (evnt.Button == 3) {
@@ -586,11 +594,12 @@ namespace Hyena.Data.Gui
return true;
}
+ int x = (int)evnt.X - list_interaction_alloc.X;
int y = (int)evnt.Y - list_interaction_alloc.Y;
GrabFocus ();
- int row_index = GetRowAtY (y);
+ int row_index = GetModelRowAt (x, y);
if (row_index >= Model.Count) {
return true;
@@ -606,7 +615,7 @@ namespace Hyena.Data.Gui
if (Selection.Count > 1) {
Selection.Clear (false);
Selection.Select (row_index);
- FocusRow (row_index);
+ FocusModelRow (row_index);
InvalidateList ();
}
}
@@ -752,26 +761,37 @@ namespace Hyena.Data.Gui
return false;
}
- protected int GetRowAtY (int y)
+ protected int GetModelRowAt (int x, int y)
{
if (y < 0) {
return -1;
}
- int page_offset = VadjustmentValue % RowHeight;
- int first_row = VadjustmentValue / RowHeight;
- int row_offset = (y + page_offset) / RowHeight;
-
- return first_row + row_offset;
+ if (LayoutStyle == DataViewLayoutStyle.Grid) {
+ int v_page_offset = VadjustmentValue % GridCellHeight;
+ int h_page_offset = HadjustmentValue % GridCellWidth;
+ int first_row = VadjustmentValue / GridCellHeight;
+ int first_col = HadjustmentValue / GridCellWidth;
+ int row_offset = (y + v_page_offset) / GridCellHeight;
+ int col_offset = Math.Min ((x + h_page_offset) / GridCellWidth, GridColumnsInView);
+ int model_row = ((first_row + row_offset) * GridColumnsInView) + first_col + col_offset;
+ return model_row;
+ } else {
+ int v_page_offset = VadjustmentValue % RowHeight;
+ int first_row = VadjustmentValue / RowHeight;
+ int row_offset = (y + v_page_offset) / RowHeight;
+ return first_row + row_offset;
+ }
}
- protected double GetYAtRow (int row)
+ protected Cairo.PointD GetViewPointForModelRow (int row)
{
- double y = (double)RowHeight * row;
- return y;
+ return LayoutStyle == DataViewLayoutStyle.Grid
+ ? new Cairo.PointD (0, (double)RowHeight * row)
+ : new Cairo.PointD (0, (double)RowHeight * row);
}
- private void FocusRow (int index)
+ private void FocusModelRow (int index)
{
Selection.FocusedIndex = index;
}
@@ -847,17 +867,17 @@ namespace Hyena.Data.Gui
public void ScrollTo (int index)
{
- ScrollTo (GetYAtRow (index));
+ ScrollTo (GetViewPointForModelRow (index).Y);
}
public void CenterOn (int index)
{
- ScrollTo (index - RowsInView/2 + 1);
+ ScrollTo (index - RowsInView / 2 + 1);
}
public bool IsRowVisible (int index)
{
- double y = GetYAtRow (index);
+ double y = GetViewPointForModelRow (index).Y;
return vadjustment.Value <= y && y < vadjustment.Value + vadjustment.PageSize;
}
@@ -865,7 +885,7 @@ namespace Hyena.Data.Gui
{
if (Selection != null && Selection.Count > 0 && !Selection.AllSelected) {
bool selection_in_view = false;
- int first_row = GetRowAtY (0);
+ int first_row = GetModelRowAt (0, 0);
for (int i = 0; i < RowsInView; i++) {
if (Selection.Contains (first_row + i)) {
selection_in_view = true;
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 050f346..5bf5573 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
@@ -455,7 +455,7 @@ namespace Hyena.Data.Gui
int offset = list_rendering_alloc.Y - vadjustment_value % RowHeight;
int first_model_row = (int)Math.Floor (vadjustment_value / (double)RowHeight) * columns_in_view;
- int last_model_row = Math.Min (model.Count, first_model_row + rows_in_view * columns_in_view) - 1;
+ int last_model_row = Math.Min (model.Count, first_model_row + rows_in_view * columns_in_view);
var grid_cell_alloc = new Rectangle () {
X = list_rendering_alloc.X,
@@ -464,8 +464,25 @@ namespace Hyena.Data.Gui
Height = GridCellHeight
};
+ selected_rows.Clear ();
+
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++) {
+ model_row_index < last_model_row; model_row_index++) {
+
+ if (Selection != null && Selection.Contains (model_row_index)) {
+ selected_rows.Add (model_row_index);
+
+ var selection_color = Theme.Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected);
+ if (!HasFocus || HeaderFocused) {
+ selection_color = CairoExtensions.ColorShade (selection_color, 1.1);
+ }
+
+ Theme.DrawRowSelection (cairo_context,
+ grid_cell_alloc.X, grid_cell_alloc.Y,
+ grid_cell_alloc.Width, grid_cell_alloc.Height,
+ true, true, selection_color, CairoCorners.All);
+ }
+
var item = model[model_row_index];
PaintCell (item, 0, model_row_index, grid_cell_alloc,
IsRowOpaque (item), IsRowBold (item), StateType.Normal, false);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]