Revision: 18194
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18194
Author:   aligorith
Date:     2008-12-31 11:44:00 +0100 (Wed, 31 Dec 2008)

Log Message:
-----------
View2D: 

Added methods for easier checking of visiblity/position of items arranged in 
some regular table format (i.e. columns and/or rows).

Last commit from me for 2008!

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
    branches/blender2.5/blender/source/blender/editors/interface/view2d.c

Modified: branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h      
2008-12-31 06:23:30 UTC (rev 18193)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h      
2008-12-31 10:44:00 UTC (rev 18194)
@@ -159,6 +159,10 @@
 void UI_view2d_scrollers_draw(const struct bContext *C, struct View2D *v2d, 
View2DScrollers *scrollers);
 void UI_view2d_scrollers_free(View2DScrollers *scrollers);
 
+/* list view tools */
+void UI_view2d_listview_get_cell(struct View2D *v2d, short columnwidth, short 
rowheight, float startx, float starty, float viewx, float viewy, int *column, 
int *row);
+void UI_view2d_listview_visible_cells(struct View2D *v2d, short columnwidth, 
short rowheight, float startx, float starty, int *column_min, int *column_max, 
int *row_min, int *row_max);
+
 /* coordinate conversion */
 void UI_view2d_region_to_view(struct View2D *v2d, int x, int y, float *viewx, 
float *viewy);
 void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, short 
*regionx, short *regiony);

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c       
2008-12-31 06:23:30 UTC (rev 18193)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c       
2008-12-31 10:44:00 UTC (rev 18194)
@@ -1086,7 +1086,7 @@
 }
 
 /* *********************************************************************** */
-/* Scrollbars */
+/* Scrollers */
 
 /* View2DScrollers is typedef'd in UI_view2d.h 
  * WARNING: the start of this struct must not change, as view2d_ops.c uses 
this too. 
@@ -1562,6 +1562,114 @@
 }
 
 /* *********************************************************************** */
+/* List View Utilities */
+
+/* Get the 'cell' (row, column) that the given 2D-view coordinates (i.e. in 
'tot' rect space) lie in.
+ *     - columnwidth, rowheight        = size of each 'cell'
+ *     - startx, starty                        = coordinates (in 'tot' rect 
space) that the list starts from
+ *                                                       This should be (0,0) 
for most views. However, for those where the starting row was offsetted
+ *                                                       (like for Animation 
Editor channel lists, to make the first entry more visible), these will be 
+ *                                                       the min-coordinates 
of the first item.
+ *     - viewx, viewy                  = 2D-coordinates (in 2D-view / 'tot' 
rect space) to get the cell for
+ *     - column, row                           = the 'coordinates' of the 
relevant 'cell'
+ */
+void UI_view2d_listview_get_cell(View2D *v2d, short columnwidth, short 
rowheight, float startx, float starty, 
+                                               float viewx, float viewy, int 
*column, int *row)
+{
+       const int x= (int)(floor(viewx + 0.5f) - startx); 
+       const int y= (int)(floor(viewy + 0.5f) - starty);
+       
+       /* sizes must not be negative */
+       if ( (v2d == NULL) || ((columnwidth <= 0) && (rowheight <= 0)) ) {
+               if (column) *column= 0;
+               if (row) *row= 0;
+               
+               return;
+       }
+       
+       /* get column */
+       if ((column) && (columnwidth > 0)) {
+               /* which way to get column depends on the alignment of the 
'tot' rect 
+                *      - we favour positive-x here, as that's the recommended 
configuration for listviews
+                */
+               if ((v2d->align & V2D_ALIGN_NO_NEG_X) && !(v2d->align & 
V2D_ALIGN_NO_POS_X)) {
+                       /* contents are in positive-x half */
+                       if (x > 0)
+                               *column= x % columnwidth;
+                       else
+                               *column= 0;
+               }
+               else if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & 
V2D_ALIGN_NO_NEG_X)) {
+                       /* contents are in negative-x half */
+                       if (x < 0)
+                               *column= (-x) % columnwidth;
+                       else
+                               *column= 0;
+               }
+               else {
+                       /* contents are centered around x==0 */
+                       // temp case for now...
+                       *column= 0;
+               }
+       }
+       else if (column) {
+               /* we want the column, but column width is undefined */
+               *column= 0;
+       }
+       
+       /* get row */
+       if ((row) && (rowheight > 0)) {
+               /* which way to get column depends on the alignment of the 
'tot' rect 
+                *      - we favour negative-y here, as that's the recommended 
configuration for listviews
+                */
+               if ((v2d->align & V2D_ALIGN_NO_POS_Y) && !(v2d->align & 
V2D_ALIGN_NO_NEG_Y)) {
+                       /* contents are in negative-y half */
+                       if (y < 0)
+                               *row= (-y) % rowheight;
+                       else
+                               *row= 0;
+               }
+               else if ((v2d->align & V2D_ALIGN_NO_NEG_Y) && !(v2d->align & 
V2D_ALIGN_NO_POS_Y)) {
+                       /* contents are in positive-y half */
+                       if (y > 0)
+                               *row= y % rowheight;
+                       else
+                               *row= 0;
+               }
+               else {
+                       /* contents are centered around y==0 */
+                       // temp case for now...
+                       *row= 0;
+                       
+               }
+       }
+       else if (row) {
+               /* we want the row, but row height is undefined */
+               *row= 0;
+       }
+}
+
+/* Get the 'extreme' (min/max) column and row indices which are visible within 
the 'cur' rect 
+ *     - columnwidth, rowheight        = size of each 'cell'
+ *     - startx, starty                        = coordinates that the list 
starts from, which should be (0,0) for most views
+ *     - column/row_min/max            = the starting and ending column/row 
indices
+ */
+void UI_view2d_listview_visible_cells(View2D *v2d, short columnwidth, short 
rowheight, float startx, float starty, 
+                                               int *column_min, int 
*column_max, int *row_min, int *row_max)
+{
+       /* using 'cur' rect coordinates, call the cell-getting function to get 
the cells for this */
+       if (v2d) {
+               /* min */
+               UI_view2d_listview_get_cell(v2d, columnwidth, rowheight, 
startx, starty, 
+                                       v2d->cur.xmin, v2d->cur.ymin, 
column_min, row_min);
+                                       
+               /* max*/
+               UI_view2d_listview_get_cell(v2d, columnwidth, rowheight, 
startx, starty, 
+                                       v2d->cur.xmax, v2d->cur.ymax, 
column_max, row_max);
+       }
+}
+
+/* *********************************************************************** */
 /* Coordinate Conversions */
 
 /* Convert from screen/region space to 2d-View space 


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to