View2D - Initial commit of Pan-View Operator
[blender.git] / source / blender / editors / space_outliner / space_outliner.c
index e272864d163cdce665de6e89c1b3e13f432a5ea8..8903f26cf3e268de428003dd90f4f24addd12c2a 100644 (file)
@@ -107,17 +107,19 @@ void UI_table_free(uiTable *table)
 void UI_table_draw(wmWindow *window, ARegion *region, uiTable *table)
 {
        uiBlock *block;
 void UI_table_draw(wmWindow *window, ARegion *region, uiTable *table)
 {
        uiBlock *block;
+       View2D *v2d;
        rcti *rct, cellrct;
        int y, row, col;
        rcti *rct, cellrct;
        int y, row, col;
-
+       
+       v2d= &region->v2d;
        rct= &table->rct;
        rct= &table->rct;
-
+       
        block= uiBeginBlock(window, region, "table outliner", UI_EMBOSST, UI_HELV);
        block= uiBeginBlock(window, region, "table outliner", UI_EMBOSST, UI_HELV);
-
+       
        for(y=rct->ymax, row=0; y>rct->ymin; y-=ROW_HEIGHT, row++) {
                if(row%2 == 0) {
                        UI_ThemeColorShade(TH_BACK, 6);
        for(y=rct->ymax, row=0; y>rct->ymin; y-=ROW_HEIGHT, row++) {
                if(row%2 == 0) {
                        UI_ThemeColorShade(TH_BACK, 6);
-                       glRecti(rct->xmin, y-ROW_HEIGHT, rct->xmax, y);
+                       glRecti(v2d->cur.xmin, y-ROW_HEIGHT, v2d->cur.xmax, y);
                }
 
                if(row >= table->rows)
                }
 
                if(row >= table->rows)
@@ -153,7 +155,6 @@ typedef struct CellRNA {
        int lastrow, index;
 
        CollectionPropertyIterator iter;
        int lastrow, index;
 
        CollectionPropertyIterator iter;
-       PropertyRNA *iterprop;
 } CellRNA;
 
 static void rna_back_cb(void *arg_buts, void *arg_unused)
 } CellRNA;
 
 static void rna_back_cb(void *arg_buts, void *arg_unused)
@@ -192,12 +193,12 @@ static void rna_label(CellRNA *cell, rcti *rct, uiBlock *block)
        int arraylength;
 
        prop= cell->prop;
        int arraylength;
 
        prop= cell->prop;
-       type= RNA_property_type(prop, &cell->ptr);
-       subtype= RNA_property_subtype(prop, &cell->ptr);
-       arraylength= RNA_property_array_length(prop, &cell->ptr);
+       type= RNA_property_type(&cell->ptr, prop);
+       subtype= RNA_property_subtype(&cell->ptr, prop);
+       arraylength= RNA_property_array_length(&cell->ptr, prop);
 
        if(cell->index == -1) {
 
        if(cell->index == -1) {
-               uiDefBut(block, LABEL, 0, (char*)RNA_property_ui_name(prop, &cell->ptr), rct->xmin, rct->ymin, rct->xmax-rct->xmin, rct->ymax-rct->ymin, 0, 0, 0, 0, 0, (char*)RNA_property_ui_description(prop, &cell->ptr));
+               uiDefBut(block, LABEL, 0, (char*)RNA_property_ui_name(&cell->ptr, prop), rct->xmin, rct->ymin, rct->xmax-rct->xmin, rct->ymax-rct->ymin, 0, 0, 0, 0, 0, (char*)RNA_property_ui_description(&cell->ptr, prop));
        }
        else if (type != PROP_COLLECTION) {
                if(arraylength == 4 && subtype == PROP_ROTATION)
        }
        else if (type != PROP_COLLECTION) {
                if(arraylength == 4 && subtype == PROP_ROTATION)
@@ -220,13 +221,13 @@ static void rna_collection_but(CellRNA *cell, rcti *rct, uiBlock *block)
        PropertyRNA *nameprop;
        char name[256]= "", *nameptr= name;
 
        PropertyRNA *nameprop;
        char name[256]= "", *nameptr= name;
 
-       RNA_property_collection_lookup_int(cell->prop, &cell->ptr, cell->index, &lookup);
+       RNA_property_collection_lookup_int(&cell->ptr, cell->prop, cell->index, &lookup);
 
        if(lookup.data) {
                nameprop= RNA_struct_name_property(&lookup);
 
                if(nameprop)
 
        if(lookup.data) {
                nameprop= RNA_struct_name_property(&lookup);
 
                if(nameprop)
-                       nameptr= RNA_property_string_get_alloc(nameprop, &lookup, name, sizeof(name));
+                       nameptr= RNA_property_string_get_alloc(&lookup, nameprop, name, sizeof(name));
                else
                        sprintf(nameptr, "%d", cell->index+1);
        }
                else
                        sprintf(nameptr, "%d", cell->index+1);
        }
@@ -248,8 +249,8 @@ static void rna_but(CellRNA *cell, rcti *rct, uiBlock *block)
        int arraylength, index;
 
        prop= cell->prop;
        int arraylength, index;
 
        prop= cell->prop;
-       type= RNA_property_type(prop, &cell->ptr);
-       arraylength= RNA_property_array_length(prop, &cell->ptr);
+       type= RNA_property_type(&cell->ptr, prop);
+       arraylength= RNA_property_array_length(&cell->ptr, prop);
 
        if(type == PROP_COLLECTION) {
                /* item in a collection */
 
        if(type == PROP_COLLECTION) {
                /* item in a collection */
@@ -297,17 +298,17 @@ static void rna_table_cell_func(void *userdata, int row, int col, rcti *rct, uiB
                if(cell->prop) {
                        cell->index++;
 
                if(cell->prop) {
                        cell->index++;
 
-                       type= RNA_property_type(cell->prop, &cell->ptr);
+                       type= RNA_property_type(&cell->ptr, cell->prop);
                        if(type == PROP_COLLECTION)
                        if(type == PROP_COLLECTION)
-                               length= RNA_property_collection_length(cell->prop, &cell->ptr);
+                               length= RNA_property_collection_length(&cell->ptr, cell->prop);
                        else
                        else
-                               length= RNA_property_array_length(cell->prop, &cell->ptr);
+                               length= RNA_property_array_length(&cell->ptr, cell->prop);
 
                        /* verify if we need to go to the next property */
                        if(type == PROP_COLLECTION && cell->index < length);
                        else if(length && cell->index < length);
                        else {
 
                        /* verify if we need to go to the next property */
                        if(type == PROP_COLLECTION && cell->index < length);
                        else if(length && cell->index < length);
                        else {
-                               RNA_property_collection_next(cell->iterprop, &cell->iter);
+                               RNA_property_collection_next(&cell->iter);
                                cell->prop= cell->iter.ptr.data;
                                cell->index= -1;
                        }
                                cell->prop= cell->iter.ptr.data;
                                cell->index= -1;
                        }
@@ -333,29 +334,26 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
        uiTable *table;
        rcti rct;
        CellRNA cell;
        uiTable *table;
        rcti rct;
        CellRNA cell;
-       PropertyRNA *prop;
+       PropertyRNA *prop, *iterprop;
        PointerRNA newptr;
        float col[3];
        PointerRNA newptr;
        float col[3];
-       int rows, cols, width, height;
+       int rows, cols, awidth, aheight, width, height;
        SpaceOops *soutliner= C->area->spacedata.first;
        SpaceOops *soutliner= C->area->spacedata.first;
+       View2D *v2d= &ar->v2d;
 
        /* clear */
        UI_GetThemeColor3fv(TH_BACK, col);
        glClearColor(col[0], col[1], col[2], 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
 
 
        /* clear */
        UI_GetThemeColor3fv(TH_BACK, col);
        glClearColor(col[0], col[1], col[2], 0.0);
        glClear(GL_COLOR_BUFFER_BIT);
 
-       width= ar->winrct.xmax - ar->winrct.xmin;
-       height= ar->winrct.ymax - ar->winrct.ymin;
+       // XXX width should be depend on max length of items (like height)...
+       awidth= width= ar->winrct.xmax - ar->winrct.xmin;
+       aheight= height= ar->winrct.ymax - ar->winrct.ymin;
        
        /* create table */
        
        /* create table */
-       rct.xmin= 0;
-       rct.ymin= 0;
-       rct.xmax= width;
-       rct.ymax= height;
-
        cell.space= soutliner;
        cell.lastrow= -1;
        cell.space= soutliner;
        cell.lastrow= -1;
-       RNA_pointer_main_get(G.main, &cell.ptr);
+       RNA_main_pointer_create(G.main, &cell.ptr);
        cell.prop= NULL;
 
        /* solve RNA path or reset if fails */
        cell.prop= NULL;
 
        /* solve RNA path or reset if fails */
@@ -378,25 +376,43 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
        rows= 1;
        cols= 2;
 
        rows= 1;
        cols= 2;
 
-       cell.iterprop= RNA_struct_iterator_property(&cell.ptr);
-       RNA_property_collection_begin(cell.iterprop, &cell.iter, &cell.ptr);
+       iterprop= RNA_struct_iterator_property(&cell.ptr);
+       RNA_property_collection_begin(&cell.ptr, iterprop, &cell.iter);
 
 
-       for(; cell.iter.valid; RNA_property_collection_next(cell.iterprop, &cell.iter)) {
+       for(; cell.iter.valid; RNA_property_collection_next(&cell.iter)) {
                prop= cell.iter.ptr.data;
 
                prop= cell.iter.ptr.data;
 
-               rows += 1 + RNA_property_array_length(prop, &cell.ptr);
-               if(RNA_property_type(prop, &cell.ptr) == PROP_COLLECTION)
-                       rows += RNA_property_collection_length(prop, &cell.ptr);
+               rows += 1 + RNA_property_array_length(&cell.ptr, prop);
+               if(RNA_property_type(&cell.ptr, prop) == PROP_COLLECTION)
+                       rows += RNA_property_collection_length(&cell.ptr, prop);
        }
 
        }
 
-       RNA_property_collection_end(cell.iterprop, &cell.iter);
+       RNA_property_collection_end(&cell.iter);
 
 
+       if ((rows*ROW_HEIGHT) > height)
+               height= rows * ROW_HEIGHT;
+       
+       /* need to validate view2d after updating size of tot */
+       v2d->tot.xmin= 0;
+       v2d->tot.xmax= width;
+       v2d->tot.ymax= 0;
+       v2d->tot.ymin= -height;
+       UI_view2d_enforce_status(v2d, awidth, aheight);
+       
+       rct.xmin= 0;
+       rct.ymin= -height;
+       rct.xmax= width;
+       rct.ymax= 0;
+       
+       /* set matrix for 2d-view controls */
+       UI_view2d_ortho(C, v2d);
+       
        /* create and draw table */
        table= UI_table_create(rows, 2, &rct, rna_table_cell_func, &cell);
 
        /* create and draw table */
        table= UI_table_create(rows, 2, &rct, rna_table_cell_func, &cell);
 
-       RNA_property_collection_begin(cell.iterprop, &cell.iter, &cell.ptr);
+       RNA_property_collection_begin(&cell.ptr, iterprop, &cell.iter);
        UI_table_draw(C->window, ar, table);
        UI_table_draw(C->window, ar, table);
-       RNA_property_collection_end(cell.iterprop, &cell.iter);
+       RNA_property_collection_end(&cell.iter);
 
        UI_table_free(table);
 }
 
        UI_table_free(table);
 }
@@ -483,6 +499,7 @@ static void outliner_init(wmWindowManager *wm, ScrArea *sa)
                        ar->type= &mainart;
 
                        WM_event_add_keymap_handler(&ar->handlers, &wm->uikeymap);
                        ar->type= &mainart;
 
                        WM_event_add_keymap_handler(&ar->handlers, &wm->uikeymap);
+                       WM_event_add_keymap_handler(&ar->handlers, &wm->view2dkeymap);
                }
                else if(ar->regiontype == RGN_TYPE_HEADER) {
                        static ARegionType headerart={NULL, NULL, NULL, NULL, NULL};
                }
                else if(ar->regiontype == RGN_TYPE_HEADER) {
                        static ARegionType headerart={NULL, NULL, NULL, NULL, NULL};
@@ -493,6 +510,7 @@ static void outliner_init(wmWindowManager *wm, ScrArea *sa)
                        ar->type= &headerart;
 
                        WM_event_add_keymap_handler(&ar->handlers, &wm->uikeymap);
                        ar->type= &headerart;
 
                        WM_event_add_keymap_handler(&ar->handlers, &wm->uikeymap);
+                       WM_event_add_keymap_handler(&ar->handlers, &wm->view2dkeymap);
                }
                else {
                        static ARegionType headerart={NULL, NULL, NULL, NULL, NULL};
                }
                else {
                        static ARegionType headerart={NULL, NULL, NULL, NULL, NULL};