View2D: More bugfixes
authorJoshua Leung <aligorith@gmail.com>
Thu, 18 Dec 2008 09:20:29 +0000 (09:20 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 18 Dec 2008 09:20:29 +0000 (09:20 +0000)
* Added flags to View2D to specify whether the view should have pixel offsets applied (this is able to be specified per axis, just in case the need arises). Currently, this is only used for headers, where the UI elements were not as smooth + round as they could be

* Fixed IPO/Action/NLA so that new instance will show channel lists by default and with scrollers

* Fixed Outliner zoom-in/out on changing windowsize. I didn't notice this on my previous custom .B.blend file, but the problem was apparent in the default setup.

source/blender/blenloader/intern/readfile.c
source/blender/editors/interface/view2d.c
source/blender/editors/space_action/space_action.c
source/blender/editors/space_nla/space_nla.c
source/blender/editors/space_outliner/space_outliner.c
source/blender/makesdna/DNA_view2d_types.h

index 3fcf0beeb263b592f3e0a68c4b3909b539855ba6..559d6b212494a65da01a63bd5e1fc27d226738aa 100644 (file)
@@ -5079,19 +5079,21 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                BLI_addtail(lb, ar);
                                ar->regiontype= RGN_TYPE_CHANNELS;
                                ar->alignment= RGN_ALIGN_LEFT; 
-                               
+                               ar->v2d.scroll= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
                                break;
                        case SPACE_ACTION:
                                ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                                BLI_addtail(lb, ar);
                                ar->regiontype= RGN_TYPE_CHANNELS;
                                ar->alignment= RGN_ALIGN_LEFT;
+                               ar->v2d.scroll= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
                                break;
                        case SPACE_NLA:
                                ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
                                BLI_addtail(lb, ar);
                                ar->regiontype= RGN_TYPE_CHANNELS;
                                ar->alignment= RGN_ALIGN_LEFT;
+                               ar->v2d.scroll= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
                                break;
                }
        }
@@ -5117,7 +5119,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
                                ar->v2d.keepzoom |= (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPASPECT);
                                ar->v2d.keeptot = V2D_KEEPTOT_STRICT;
-                               ar->v2d.flag |= V2D_IS_INITIALISED;
+                               //ar->v2d.flag |= V2D_IS_INITIALISED;
                        }
                                break;
                        case SPACE_TIME:
@@ -5131,7 +5133,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
                                ar->v2d.tot.ymin= ar->v2d.cur.ymin= -10.0;
                                ar->v2d.min[1]= ar->v2d.max[1]= 20.0;
-                               ar->v2d.flag |= V2D_IS_INITIALISED;
+                               //ar->v2d.flag |= V2D_IS_INITIALISED;
                        }
                                break;
                        case SPACE_IPO:
@@ -5141,7 +5143,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                
                                ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
                                ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_VERTICAL);
-                               ar->v2d.flag |= V2D_IS_INITIALISED;
+                               //ar->v2d.flag |= V2D_IS_INITIALISED;
                                break;
                        }
                        case SPACE_SOUND:
@@ -5151,7 +5153,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                
                                ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
                                ar->v2d.scroll |= (V2D_SCROLL_LEFT);
-                               ar->v2d.flag |= V2D_IS_INITIALISED;
+                               //ar->v2d.flag |= V2D_IS_INITIALISED;
                                break;
                        }
                        case SPACE_NLA:
@@ -5161,7 +5163,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                
                                ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
                                ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
-                               ar->v2d.flag |= V2D_IS_INITIALISED;
+                               //ar->v2d.flag |= V2D_IS_INITIALISED;
                                break;
                        }
                        case SPACE_ACTION:
@@ -5171,7 +5173,7 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
                                
                                ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
                                ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
-                               ar->v2d.flag |= V2D_IS_INITIALISED;
+                               //ar->v2d.flag |= V2D_IS_INITIALISED;
                                break;
                        }
                        case SPACE_SEQ:
index 3213e1201355223a30a443dfff20cb7cddd076dd..e0e60f67fcbf0871ac7925e6fe9f61d3680678e4 100644 (file)
@@ -64,7 +64,6 @@
  *     - this function should only be called from region init() callbacks, where it is expected that
  *       this is called before UI_view2d_size_update(), as this one checks that the rects are properly initialised. 
  */
-// eView2D_CommonViewTypes <--- only check handle these types...
 void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
 {
        short tot_changed= 0;
@@ -127,8 +126,8 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
                                /* zoom + aspect ratio are locked */
                                v2d->keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
                                v2d->minzoom= v2d->maxzoom= 1.0f;
-                               v2d->min[0]= v2d->max[0]= winx;
-                               v2d->min[1]= v2d->max[1]= winy;
+                               v2d->min[0]= v2d->max[0]= winx-1;
+                               v2d->min[1]= v2d->max[1]= winy-1;
                                
                                /* tot rect has strictly regulated placement, and must only occur in +/+ quadrant */
                                v2d->align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y);
@@ -140,6 +139,9 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
                                
                                /* absolutely no scrollers allowed */
                                v2d->scroll= 0;
+                               
+                               /* pixel offsets need to be applied for smooth UI controls */
+                               v2d->flag |= (V2D_PIXELOFS_X|V2D_PIXELOFS_Y);
                        }
                                break;
                        
@@ -335,8 +337,15 @@ void UI_view2d_curRect_validate(View2D *v2d)
                        }
                }
                else {
-                       /* landscape window: correct for y */
-                       height = width * winRatio;
+                       if ((v2d->keeptot == V2D_KEEPTOT_STRICT) && (winy != v2d->oldwiny)) {
+                               /* special exception for Outliner (and later channel-lists):
+                                *      - Currently, no actions need to be taken here...
+                                */
+                       }
+                       else {
+                               /* landscape window: correct for y */
+                               height = width * winRatio;
+                       }
                }
                
                /* store region size for next time */
@@ -625,28 +634,30 @@ static void view2d_map_cur_using_mask(View2D *v2d, rctf *curmasked)
        }
 }
 
-/* Set view matrices to use 'cur' rect as viewing frame for View2D drawing 
-*      - this assumes viewport/scissor been set for the region, taking scrollbars into account
-*/
-
+/* Set view matrices to use 'cur' rect as viewing frame for View2D drawing */
 void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
 {
        wmWindow *window= CTX_wm_window(C);
        rctf curmasked;
+       float xofs, yofs;
        
-       /* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied
-        * as they were causing some unwanted offsets when drawing 
+       /* pixel offsets (-0.375f) are needed to get 1:1 correspondance with pixels for smooth UI drawing
+        * but only applied where requsted
         */
+       xofs= (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f;
+       yofs= (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f;
+       
+       /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */
        view2d_map_cur_using_mask(v2d, &curmasked);
-       wmOrtho2(window, curmasked.xmin, curmasked.xmax, curmasked.ymin, curmasked.ymax);
+       
+       /* set matrix on all appropriate axes */
+       wmOrtho2(window, curmasked.xmin-xofs, curmasked.xmax-xofs, curmasked.ymin-yofs, curmasked.ymax-yofs);
        
        /* XXX is this necessary? */
        wmLoadIdentity(window);
 }
 
 /* Set view matrices to only use one axis of 'cur' only
- *     - this assumes viewport/scissor been set for the region, taking scrollbars into account
- *
  *     - xaxis         = if non-zero, only use cur x-axis, otherwise use cur-yaxis (mostly this will be used for x)
  */
 void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
@@ -654,15 +665,22 @@ void UI_view2d_view_orthoSpecial(const bContext *C, View2D *v2d, short xaxis)
        wmWindow *window= CTX_wm_window(C);
        ARegion *ar= CTX_wm_region(C);
        rctf curmasked;
+       float xofs, yofs;
        
-       /* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied
-        * as they were causing some unwanted offsets when drawing 
+       /* pixel offsets (-0.375f) are needed to get 1:1 correspondance with pixels for smooth UI drawing
+        * but only applied where requsted
         */
+       xofs= (v2d->flag & V2D_PIXELOFS_X) ? 0.375f : 0.0f;
+       yofs= (v2d->flag & V2D_PIXELOFS_Y) ? 0.375f : 0.0f;
+       
+       /* apply mask-based adjustments to cur rect (due to scrollers), to eliminate scaling artifacts */
        view2d_map_cur_using_mask(v2d, &curmasked);
+       
+       /* only set matrix with 'cur' coordinates on relevant axes */
        if (xaxis)
-               wmOrtho2(window, curmasked.xmin, curmasked.xmax, 0, ar->winy);
+               wmOrtho2(window, curmasked.xmin-xofs, curmasked.xmax-xofs, -yofs, ar->winy-yofs);
        else
-               wmOrtho2(window, 0, ar->winx, curmasked.ymin, curmasked.ymax);
+               wmOrtho2(window, -xofs, ar->winx-xofs, curmasked.ymin-yofs, curmasked.ymax-yofs);
                
        /* XXX is this necessary? */
        wmLoadIdentity(window);
@@ -779,8 +797,6 @@ View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, sh
                        grid->powerx-= 2;
                        if (grid->powerx < -2) grid->powerx= -2;
                }
-               
-               grid->startx= v2d->cur.xmin;
        }
        
        /* calculate y-axis grid scale (only if both args are valid) */
@@ -795,8 +811,6 @@ View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, sh
                        if (grid->dy < 1.0f) grid->dy= 1.0f;
                        if (grid->powery < 1) grid->powery= 1;
                }
-               
-               grid->starty= v2d->cur.ymin;
        }
        
        /* calculate start position */
@@ -804,10 +818,15 @@ View2DGrid *UI_view2d_grid_calc(const bContext *C, View2D *v2d, short xunits, sh
                grid->startx= seconddiv*(v2d->cur.xmin/seconddiv - fmod(v2d->cur.xmin/seconddiv, grid->dx/seconddiv));
                if (v2d->cur.xmin < 0.0f) grid->startx-= grid->dx;
        }
+       else
+               grid->startx= v2d->cur.xmin;
+               
        if (ELEM(V2D_ARG_DUMMY, yunits, yclamp) == 0) {
                grid->starty= (v2d->cur.ymin - fmod(v2d->cur.ymin, grid->dy));
                if (v2d->cur.ymin < 0.0f) grid->starty-= grid->dy;
        }
+       else
+               grid->starty= v2d->cur.ymin;
        
        return grid;
 }
index 35b5d5926376b3de04a46596f1de80b7ff252d79..4b29167e844856621c13b13ae9aa36bed2870903 100644 (file)
@@ -80,41 +80,44 @@ static SpaceLink *action_new(void)
        ar->regiontype= RGN_TYPE_HEADER;
        ar->alignment= RGN_ALIGN_BOTTOM;
        
+       /* channel list region */
+       ar= MEM_callocN(sizeof(ARegion), "channel area for action");
+       BLI_addtail(&saction->regionbase, ar);
+       ar->regiontype= RGN_TYPE_CHANNELS;
+       ar->alignment= RGN_ALIGN_LEFT;
+       
+               /* only need to set scroll settings, as this will use 'listview' v2d configuration */
+       ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
+       ar->v2d.flag = V2D_VIEWSYNC_Y;
+       
        /* main area */
        ar= MEM_callocN(sizeof(ARegion), "main area for action");
        
        BLI_addtail(&saction->regionbase, ar);
        ar->regiontype= RGN_TYPE_WINDOW;
        
-       ar->v2d.tot.xmin= 1.0f;
-       ar->v2d.tot.ymin= -1000.0f;
-       ar->v2d.tot.xmax= 1000.0f;
+       ar->v2d.tot.xmin= -5.0f;
+       ar->v2d.tot.ymin= -2000.0f;
+       ar->v2d.tot.xmax= 1000.0f; // xxx - use end frame instead?
        ar->v2d.tot.ymax= 0.0f;
        
-       ar->v2d.cur.xmin= -5.0f;
-       ar->v2d.cur.ymin= -75.0f;
-       ar->v2d.cur.xmax= 65.0f;
-       ar->v2d.cur.ymax= 5.0f;
+       ar->v2d.cur.xmin= -2.0f;
+       ar->v2d.cur.ymin= -200.0f;
+       ar->v2d.cur.xmax= 100.0f;
+       ar->v2d.cur.ymax= 0.0f;
        
        ar->v2d.min[0]= 0.0f;
        ar->v2d.min[1]= 0.0f;
        
        ar->v2d.max[0]= MAXFRAMEF;
-       ar->v2d.max[1]= 1000.0f;
+       ar->v2d.max[1]= 2000.0f;
        
        ar->v2d.minzoom= 0.01f;
        ar->v2d.maxzoom= 50;
-       ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
+       ar->v2d.scroll = (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
        ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
        ar->v2d.keepzoom= V2D_LOCKZOOM_Y;
-       ar->v2d.align= V2D_ALIGN_NO_POS_X;
-       
-       /* channel list region XXX */
-       ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
-       BLI_addtail(&saction->regionbase, ar);
-       ar->regiontype= RGN_TYPE_CHANNELS;
-       ar->alignment= RGN_ALIGN_LEFT;
-                               
+       ar->v2d.align= V2D_ALIGN_NO_POS_Y;
        
        return (SpaceLink *)saction;
 }
@@ -159,9 +162,12 @@ static void action_main_area_init(wmWindowManager *wm, ARegion *ar)
 static void action_main_area_draw(const bContext *C, ARegion *ar)
 {
        /* draw entirely, view changes should be handled here */
-       // SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
+       SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
        View2D *v2d= &ar->v2d;
+       View2DGrid *grid;
+       View2DScrollers *scrollers;
        float col[3];
+       int unit;
        
        /* clear and setup matrix */
        UI_GetThemeColor3fv(TH_BACK, col);
@@ -170,13 +176,22 @@ static void action_main_area_draw(const bContext *C, ARegion *ar)
        
        UI_view2d_view_ortho(C, v2d);
                
-       /* data... */
+       /* time grid */
+       unit= (saction->flag & SACTION_DRAWTIME)? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
+       grid= UI_view2d_grid_calc(C, v2d, unit, V2D_GRID_NOCLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
+       UI_view2d_grid_draw(C, v2d, grid, V2D_GRIDLINES_ALL);
+       UI_view2d_grid_free(grid);
        
+       /* data? */
+               
        
        /* reset view matrix */
        UI_view2d_view_restore(C);
        
-       /* scrollers? */
+       /* scrollers */
+       scrollers= UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_NOCLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+       UI_view2d_scrollers_draw(C, v2d, scrollers);
+       UI_view2d_scrollers_free(scrollers);
 }
 
 void action_operatortypes(void)
@@ -189,6 +204,46 @@ void action_keymap(struct wmWindowManager *wm)
        
 }
 
+/* add handlers, stuff you only do once or on area/region changes */
+static void action_channel_area_init(wmWindowManager *wm, ARegion *ar)
+{
+       ListBase *keymap;
+       
+       UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
+       
+       /* own keymap */
+       keymap= WM_keymap_listbase(wm, "Action", SPACE_ACTION, 0);      /* XXX weak? */
+       WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
+}
+
+static void action_channel_area_draw(const bContext *C, ARegion *ar)
+{
+       /* draw entirely, view changes should be handled here */
+       //SpaceAction *saction= C->area->spacedata.first;
+       View2D *v2d= &ar->v2d;
+       View2DScrollers *scrollers;
+       float col[3];
+       
+       /* clear and setup matrix */
+       UI_GetThemeColor3fv(TH_BACK, col);
+       glClearColor(col[0], col[1], col[2], 0.0);
+       glClear(GL_COLOR_BUFFER_BIT);
+       
+       UI_view2d_view_ortho(C, v2d);
+       
+       /* data... */
+       
+       
+       /* reset view matrix */
+       UI_view2d_view_restore(C);
+       
+       /* scrollers */
+       scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+       UI_view2d_scrollers_draw(C, v2d, scrollers);
+       UI_view2d_scrollers_free(scrollers);
+}
+
+
 /* add handlers, stuff you only do once or on area/region changes */
 static void action_header_area_init(wmWindowManager *wm, ARegion *ar)
 {
@@ -261,11 +316,11 @@ void ED_spacetype_action(void)
        /* regions: channels */
        art= MEM_callocN(sizeof(ARegionType), "spacetype action region");
        art->regionid = RGN_TYPE_CHANNELS;
-       art->minsizex = 200;
+       art->minsizex= 200;
        art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
        
-       //art->init= action_channel_area_init;
-       //art->draw= action_channel_area_draw;
+       art->init= action_channel_area_init;
+       art->draw= action_channel_area_draw;
        
        BLI_addhead(&st->regiontypes, art);
        
index 6bb4252724153439d8aef5b2ac26006b9f99a979..58f7b92e8721620ec65a3fc302b42e379cf8c177 100644 (file)
@@ -78,6 +78,14 @@ static SpaceLink *nla_new(void)
        ar->regiontype= RGN_TYPE_HEADER;
        ar->alignment= RGN_ALIGN_BOTTOM;
        
+       /* channel list region XXX */
+       ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
+       BLI_addtail(&snla->regionbase, ar);
+       ar->regiontype= RGN_TYPE_CHANNELS;
+       ar->alignment= RGN_ALIGN_LEFT;
+       
+       ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
+       
        /* main area */
        ar= MEM_callocN(sizeof(ARegion), "main area for nla");
        
@@ -106,13 +114,6 @@ static SpaceLink *nla_new(void)
        ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
        ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
        ar->v2d.keepzoom= V2D_LOCKZOOM_Y;
-       
-       
-       /* channel list region XXX */
-       ar= MEM_callocN(sizeof(ARegion), "area region from do_versions");
-       BLI_addtail(&snla->regionbase, ar);
-       ar->regiontype= RGN_TYPE_CHANNELS;
-       ar->alignment= RGN_ALIGN_LEFT;
                
        
        return (SpaceLink *)snla;
index 4fa10adcd9132ff7235437623554f9f56469577f..ba694754e13543f82c02c4c15124a4ffcfe74bca 100644 (file)
@@ -555,7 +555,8 @@ static SpaceLink *outliner_new(void)
        ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O);
        ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
        ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
-       ar->v2d.keeptot= 2;     /* XXX make define */
+       ar->v2d.keeptot= V2D_KEEPTOT_STRICT;
+       ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
        
        return (SpaceLink*)soutliner;
 }
index ff96e9092e5a26171062c798f5ab21383ab67605..20b14b178ac895596ca7fac03dabb9ef27684f4c 100644 (file)
@@ -92,6 +92,10 @@ typedef struct View2D {
 #define V2D_VIEWSYNC_X         (1<<0)
        /* within region view2d vertical locking */
 #define V2D_VIEWSYNC_Y         (1<<1)
+       /* apply pixel offsets on x-axis */
+#define V2D_PIXELOFS_X         (1<<2)
+       /* apply pixel offsets on y-axis */
+#define V2D_PIXELOFS_Y         (1<<3)
        /* view settings need to be set still... */
 #define V2D_IS_INITIALISED             (1<<10)