Revision: 17637
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17637
Author:   aligorith
Date:     2008-11-30 07:15:33 +0100 (Sun, 30 Nov 2008)

Log Message:
-----------
View2D - Initial commit of Pan-View Operator

* Moved View2D data from space-data to ARegion (aka regions). This has been 
done because drawing occurs in regions not areas anymore. The View2D struct is 
currently stored in the ARegion struct (not as pointer), given that most of the 
regions in use will be 2D anyway (only the 3d-view's "window" region is the 
exception).
Added version patch code for outliner and timeline only for now. Headers are 
also likely to need this.

* Added separate keymap for View2D operators. All regions that use View2D will 
need this added. This includes headers too. 

* Pan view operator (ED_View2D_OT_view_pan), currently works for Outliner and 
Timeline. Use MMB-drag as before. 
- It currently doesn't exposed any parameters for redo (via RNA-ID-Props), but 
only uses some customdata. Suggestions on what these parameters could be are 
welcomed. 
- I've yet to implement the necessary axis-locking features for this panning 
(which is required in Timeline for example to prevent vertical panning, which 
moves the markers out of view).
 

Modified Paths:
--------------
    branches/blender2.5/blender/SConstruct
    
branches/blender2.5/blender/projectfiles_vc9/blender/editors/ED_editors.vcproj
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
    branches/blender2.5/blender/source/blender/editors/interface/view2d.c
    branches/blender2.5/blender/source/blender/editors/screen/screen_ops.c
    branches/blender2.5/blender/source/blender/editors/screen/spacetypes.c
    
branches/blender2.5/blender/source/blender/editors/space_outliner/space_outliner.c
    branches/blender2.5/blender/source/blender/editors/space_time/space_time.c
    branches/blender2.5/blender/source/blender/editors/space_time/time_ops.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_screen_types.h
    branches/blender2.5/blender/source/blender/makesdna/DNA_view2d_types.h
    
branches/blender2.5/blender/source/blender/makesdna/DNA_windowmanager_types.h

Added Paths:
-----------
    branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c

Modified: branches/blender2.5/blender/SConstruct
===================================================================
--- branches/blender2.5/blender/SConstruct      2008-11-30 05:07:57 UTC (rev 
17636)
+++ branches/blender2.5/blender/SConstruct      2008-11-30 06:15:33 UTC (rev 
17637)
@@ -115,8 +115,8 @@
                env.Tool('mstoolkit', ['tools'])
        else:
                env = BlenderEnvironment(tools=[toolset], ENV = os.environ)
-               if env:
-                       btools.SetupSpawn(env)
+               #if env:
+               #       btools.SetupSpawn(env)
 else:
        env = BlenderEnvironment(ENV = os.environ)
 

Modified: 
branches/blender2.5/blender/projectfiles_vc9/blender/editors/ED_editors.vcproj
===================================================================
--- 
branches/blender2.5/blender/projectfiles_vc9/blender/editors/ED_editors.vcproj  
    2008-11-30 05:07:57 UTC (rev 17636)
+++ 
branches/blender2.5/blender/projectfiles_vc9/blender/editors/ED_editors.vcproj  
    2008-11-30 06:15:33 UTC (rev 17637)
@@ -306,6 +306,10 @@
                                
RelativePath="..\..\..\source\blender\editors\interface\view2d.c"
                                >
                        </File>
+                       <File
+                               
RelativePath="..\..\..\source\blender\editors\interface\view2d_ops.c"
+                               >
+                       </File>
                </Filter>
                <Filter
                        Name="space_view3d"

Modified: 
branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c     
2008-11-30 05:07:57 UTC (rev 17636)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c     
2008-11-30 06:15:33 UTC (rev 17637)
@@ -3787,6 +3787,7 @@
        wm->operators.first= wm->operators.last= NULL;
        wm->windowkeymap.first= wm->windowkeymap.last= NULL;
        wm->screenkeymap.first= wm->screenkeymap.last= NULL;
+       wm->view2dkeymap.first= wm->view2dkeymap.last= NULL;
        wm->uikeymap.first= wm->uikeymap.last= NULL;
        wm->timekeymap.first= wm->timekeymap.last= NULL;
        
@@ -5061,12 +5062,24 @@
                                ar->alignment= RGN_ALIGN_BOTTOM;
                        else
                                ar->alignment= RGN_ALIGN_TOP;
+                       // TODO: add conversion stuff for header scrolling to 
v2d of header region
                }
                
                ar= MEM_callocN(sizeof(ARegion), "area region from 
do_versions");
                BLI_addtail(&sa->regionbase, ar);
                ar->winrct= sa->totrct;
                ar->regiontype= RGN_TYPE_WINDOW;
+               
+               /* if active spacetype has view2d data, copy that over to main 
region */
+               switch(sa->spacetype) {
+                       case SPACE_OOPS:
+                               memcpy(&ar->v2d, &((SpaceOops 
*)sa->spacedata.first)->v2d, sizeof(View2D));
+                               break;
+                       case SPACE_TIME:
+                               memcpy(&ar->v2d, &((SpaceTime 
*)sa->spacedata.first)->v2d, sizeof(View2D));
+                               break;
+                       //case SPACE_XXX: // FIXME... add other ones
+               }
        }
 }
 

Modified: branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h      
2008-11-30 05:07:57 UTC (rev 17636)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h      
2008-11-30 06:15:33 UTC (rev 17637)
@@ -35,6 +35,10 @@
 /* ------------------------------------------ */
 /* Settings:                                                           */
 
+/* generic value to use when coordinate lies out of view when converting */
+#define V2D_IS_CLIPPED 12000
+
+/* ---  Grids --- */
 /* grid-units (for drawing time) */
 #define V2D_UNIT_SECONDS       0
 #define V2D_UNIT_FRAMES                1
@@ -43,20 +47,18 @@
 #define V2D_GRID_CLAMP         0
 #define V2D_GRID_NOCLAMP       1
 
-/* generic value to use when coordinate lies out of view when converting */
-#define V2D_IS_CLIPPED 12000
-
 /* flags for grid-lines to draw */
 #define V2D_HORIZONTAL_LINES   (1<<0)
 #define V2D_VERTICAL_LINES             (1<<1)
 #define V2D_HORIZONTAL_AXIS            (1<<2)
 #define V2D_VERTICAL_AXIS              (1<<3)
 
+/* --- Scrollers --- */
+
 /* ------------------------------------------ */
 /* Macros:                                                             */
 
-/* test if mouse in scrollbar */
-// XXX do we want more elegant method?
+/* test if mouse in a scrollbar */
 #define IN_2D_VERT_SCROLL(v2d, co) (BLI_in_rcti(&v2d->vert, co[0], co[1]))
 #define IN_2D_HORIZ_SCROLL(v2d, co) (BLI_in_rcti(&v2d->hor, co[0], co[1]))
 
@@ -65,9 +67,13 @@
 
 struct View2D;
 struct View2DGrid;
+struct View2DScrollbar;
+
+struct wmWindowManager;
 struct bContext;
 
 typedef struct View2DGrid View2DGrid;
+typedef struct View2DScrollers View2DScrollers;
 
 /* ----------------------------------------- */
 /* Prototypes:                                             */
@@ -75,6 +81,7 @@
 /* setup */
 void UI_view2d_ortho(const struct bContext *C, struct View2D *v2d);
 void UI_view2d_update_size(struct View2D *v2d, int winx, int winy);
+void UI_view2d_enforce_status(struct View2D *v2d, int winx, int winy);
 
 /* grid drawing */
 View2DGrid *UI_view2d_calc_grid(const struct bContext *C, struct View2D *v2d, 
short unit, short type, int winx, int winy);
@@ -83,6 +90,8 @@
 
 /* scrollbar drawing */
 
+void UI_view2d_draw_scrollers(const struct bContext *C, struct View2D *v2d, 
View2dScrollers *scrollers, int flag);
+void UI_view2d_free_scrollbars(View2DScrollers *scrollers);
 
 /* coordinate conversion */
 void UI_view2d_region_to_view(struct View2D *v2d, short x, short y, float 
*viewx, float *viewy);
@@ -90,8 +99,12 @@
 void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, short 
*regionx, short *region_y);
 
 /* utilities */
-void UI_view2d_getscale(View2D *v2d, float *x, float *y);
+void UI_view2d_getscale(struct View2D *v2d, float *x, float *y);
 
 
+/* operators */
+void ui_view2d_operatortypes(void);
+void UI_view2d_keymap(struct wmWindowManager *wm);
+
 #endif /* UI_VIEW2D_H */
 

Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c       
2008-11-30 05:07:57 UTC (rev 17636)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c       
2008-11-30 06:15:33 UTC (rev 17637)
@@ -35,6 +35,7 @@
 #include "DNA_view2d_types.h"
 
 #include "BKE_global.h"
+#include "BKE_utildefines.h"
 
 #include "WM_api.h"
 
@@ -47,6 +48,7 @@
 /* Setup and Refresh Code */
 
 /* Set view matrices to ortho for View2D drawing */
+// XXX in past, this was not always the case!
 void UI_view2d_ortho(const bContext *C, View2D *v2d)
 {
        wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, 
v2d->cur.ymax);
@@ -61,9 +63,10 @@
        v2d->mask.xmax= winx;
        v2d->mask.ymax= winy;
        
-       /* scrollbars shrink mask area, but should be based off regionsize */
-       // XXX scrollbars should become limited to one bottom lower edges of 
region like everyone else does!
-       if(v2d->scroll) {
+       /* scrollbars shrink mask area, but should be based off regionsize 
+        *      - they can only be on one edge of the region they define
+        */
+       if (v2d->scroll) {
                /* vertical scrollbar */
                if (v2d->scroll & L_SCROLL) {
                        /* on left-hand edge of region */
@@ -71,7 +74,7 @@
                        v2d->vert.xmax= SCROLLB;
                        v2d->mask.xmin= SCROLLB;
                }
-               else if(v2d->scroll & R_SCROLL) {
+               else if (v2d->scroll & R_SCROLL) {
                        /* on right-hand edge of region */
                        v2d->vert= v2d->mask;
                        v2d->vert.xmin= v2d->vert.xmax-SCROLLB;
@@ -85,7 +88,7 @@
                        v2d->hor.ymax= SCROLLH;
                        v2d->mask.ymin= SCROLLH;
                }
-               else if(v2d->scroll & T_SCROLL) {
+               else if (v2d->scroll & T_SCROLL) {
                        /* on upper edge of region */
                        v2d->hor= v2d->mask;
                        v2d->hor.ymin= v2d->hor.ymax-SCROLLH;
@@ -94,6 +97,238 @@
        }
 }
 
+/* Ensure View2D rects remain in a viable configuration 
+ *     - cur is not allowed to be: larger than max, smaller than min, or 
outside of tot
+ */
+// XXX pre2.5 -> this used to be called  test_view2d()
+// XXX FIXME - still need to go through this and figure out what it all parts 
of it do
+void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
+{
+       /* cur is not allowed to be larger than max, smaller than min, or 
outside of tot */
+       rctf *cur, *tot;
+       float dx, dy, temp, fac, zoom;
+       
+       /* correct winx for scrollbars */
+       if (v2d->scroll & L_SCROLL) winx-= SCROLLB;
+       if (v2d->scroll & B_SCROLL) winy-= SCROLLH;
+       if (v2d->scroll & B_SCROLLO) winy-= SCROLLH; /* B_SCROLL and B_SCROLLO 
are basically same thing */
+       
+       /* header completely closed window */
+       if (winy <= 0) return;
+       
+       /* get pointers */
+       cur= &v2d->cur;
+       tot= &v2d->tot;
+       
+       /* dx, dy are width and height of v2d->cur, respectively */
+       dx= cur->xmax - cur->xmin;
+       dy= cur->ymax - cur->ymin;
+       
+       /* keepzoom - restore old zoom */
+       if (v2d->keepzoom) {    
+               /* keepzoom on x or y axis - reset size of current-viewable 
area to size of region (i.e. no zooming happened) */
+               if (v2d->keepzoom & V2D_LOCKZOOM_Y)
+                       cur->ymax= cur->ymin + ((float)winy);
+               if (v2d->keepzoom & V2D_LOCKZOOM_X)
+                       cur->xmax= cur->xmin + ((float)winx);
+               
+               /* calculate zoom-factor for x */
+               zoom= ((float)winx)/dx;
+               
+               /* if zoom factor is excessive, normalise it and calculate new 
width */
+               if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
+                       if (zoom < v2d->minzoom) fac= zoom / v2d->minzoom;
+                       else fac= zoom / v2d->maxzoom;
+                       
+                       dx *= fac;
+                       temp= 0.5f * (cur->xmax + cur->xmin);
+                       
+                       cur->xmin= temp - (0.5f * dx);
+                       cur->xmax= temp + (0.5f * dx);
+               }
+               
+               /* calculate zoom-factor for y */
+               zoom= ((float)winy)/dy;
+               
+               /* if zoom factor is excessive, normalise it and calculate new 
width */
+               if ((zoom < v2d->minzoom) || (zoom > v2d->maxzoom)) {
+                       if (zoom < v2d->minzoom) fac= zoom / v2d->minzoom;
+                       else fac= zoom / v2d->maxzoom;
+                       
+                       dy *= fac;
+                       temp= 0.5f * (cur->ymax + cur->ymin);
+                       
+                       cur->ymin= temp - (0.5f * dy);
+                       cur->ymax= temp + (0.5f * dy);
+               }
+       }
+       else {
+               /* if extents of cur are below or above what's acceptable, 
interpolate extent to lie halfway */
+               if (dx < v2d->min[0]) {
+                       dx= v2d->min[0];
+                       temp= 0.5f * (cur->xmax + cur->xmin);
+                       
+                       cur->xmin= temp - (0.5f * dx);
+                       cur->xmax= temp + (0.5f * dx);
+               }
+               else if (dx > v2d->max[0]) {
+                       dx= v2d->max[0];
+                       temp= 0.5f * (cur->xmax + cur->xmin);
+                       
+                       cur->xmin= temp - (0.5f * dx);
+                       cur->xmax= temp + (0.5f * dx);
+               }
+               
+               if (dy < v2d->min[1]) {
+                       dy= v2d->min[1];
+                       temp= 0.5f * (cur->ymax + cur->ymin);
+                       
+                       cur->ymin= temp - (0.5f * dy);
+                       cur->ymax= temp + (0.5f * dy);
+               }
+               else if (dy > v2d->max[1]) {
+                       dy= v2d->max[1];
+                       temp= 0.5f * (cur->ymax + cur->ymin);
+                       cur->ymin= temp-0.5*dy;
+                       cur->ymax= temp+0.5*dy;
+               }
+       }
+       
+       /* keep aspect - maintain aspect ratio */
+       if (v2d->keepaspect) {
+               short do_x=0, do_y=0;
+               

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to