Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2008 Blender Foundation. 00019 * All rights reserved. 00020 * 00021 * 00022 * Contributor(s): Blender Foundation 00023 * 00024 * ***** END GPL LICENSE BLOCK ***** 00025 */ 00026 00032 #include <string.h> 00033 #include <stdio.h> 00034 00035 #include "MEM_guardedalloc.h" 00036 00037 #include "BLI_blenlib.h" 00038 #include "BLI_math.h" 00039 #include "BLI_rand.h" 00040 #include "BLI_utildefines.h" 00041 00042 #include "BKE_context.h" 00043 #include "BKE_screen.h" 00044 00045 #include "ED_space_api.h" 00046 #include "ED_screen.h" 00047 00048 #include "WM_api.h" 00049 #include "WM_types.h" 00050 00051 #include "BIF_gl.h" 00052 00053 #include "UI_resources.h" 00054 #include "UI_view2d.h" 00055 00056 00057 #include "outliner_intern.h" 00058 00059 static void outliner_main_area_init(wmWindowManager *wm, ARegion *ar) 00060 { 00061 wmKeyMap *keymap; 00062 00063 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy); 00064 00065 /* own keymap */ 00066 keymap= WM_keymap_find(wm->defaultconf, "Outliner", SPACE_OUTLINER, 0); 00067 /* don't pass on view2d mask, it's always set with scrollbar space, hide fails */ 00068 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, NULL, &ar->winrct); 00069 } 00070 00071 static void outliner_main_area_draw(const bContext *C, ARegion *ar) 00072 { 00073 View2D *v2d= &ar->v2d; 00074 View2DScrollers *scrollers; 00075 00076 /* clear */ 00077 UI_ThemeClearColor(TH_BACK); 00078 glClear(GL_COLOR_BUFFER_BIT); 00079 00080 draw_outliner(C); 00081 00082 /* reset view matrix */ 00083 UI_view2d_view_restore(C); 00084 00085 /* scrollers */ 00086 scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY); 00087 UI_view2d_scrollers_draw(C, v2d, scrollers); 00088 UI_view2d_scrollers_free(scrollers); 00089 } 00090 00091 00092 static void outliner_main_area_free(ARegion *UNUSED(ar)) 00093 { 00094 00095 } 00096 00097 static void outliner_main_area_listener(ARegion *ar, wmNotifier *wmn) 00098 { 00099 /* context changes */ 00100 switch(wmn->category) { 00101 case NC_SCENE: 00102 switch(wmn->data) { 00103 case ND_OB_ACTIVE: 00104 case ND_OB_SELECT: 00105 case ND_OB_VISIBLE: 00106 case ND_OB_RENDER: 00107 case ND_MODE: 00108 case ND_KEYINGSET: 00109 case ND_FRAME: 00110 case ND_RENDER_OPTIONS: 00111 case ND_LAYER: 00112 case ND_WORLD: 00113 ED_region_tag_redraw(ar); 00114 break; 00115 } 00116 break; 00117 case NC_OBJECT: 00118 switch(wmn->data) { 00119 case ND_TRANSFORM: 00120 /* transform doesn't change outliner data */ 00121 break; 00122 case ND_BONE_ACTIVE: 00123 case ND_BONE_SELECT: 00124 case ND_DRAW: 00125 case ND_PARENT: 00126 case ND_OB_SHADING: 00127 ED_region_tag_redraw(ar); 00128 break; 00129 case ND_CONSTRAINT: 00130 switch(wmn->action) { 00131 case NA_ADDED: 00132 case NA_REMOVED: 00133 case NA_RENAME: 00134 ED_region_tag_redraw(ar); 00135 break; 00136 } 00137 break; 00138 case ND_MODIFIER: 00139 /* all modifier actions now */ 00140 ED_region_tag_redraw(ar); 00141 break; 00142 } 00143 break; 00144 case NC_GROUP: 00145 /* all actions now, todo: check outliner view mode? */ 00146 ED_region_tag_redraw(ar); 00147 break; 00148 case NC_LAMP: 00149 /* For updating lamp icons, when changing lamp type */ 00150 if(wmn->data == ND_LIGHTING_DRAW) 00151 ED_region_tag_redraw(ar); 00152 break; 00153 case NC_SPACE: 00154 if(wmn->data == ND_SPACE_OUTLINER) 00155 ED_region_tag_redraw(ar); 00156 break; 00157 case NC_ID: 00158 if(wmn->action == NA_RENAME) 00159 ED_region_tag_redraw(ar); 00160 break; 00161 case NC_MATERIAL: 00162 switch(wmn->data) { 00163 case ND_SHADING: 00164 case ND_SHADING_DRAW: 00165 ED_region_tag_redraw(ar); 00166 break; 00167 } 00168 break; 00169 case NC_TEXTURE: 00170 ED_region_tag_redraw(ar); 00171 break; 00172 case NC_GEOM: 00173 switch(wmn->data) { 00174 case ND_DATA: 00175 /* needed for vertex groups only, no special notifier atm so use NC_GEOM|ND_DATA */ 00176 ED_region_tag_redraw(ar); 00177 break; 00178 } 00179 break; 00180 case NC_ANIMATION: 00181 switch(wmn->data) { 00182 case ND_NLA_ACTCHANGE: 00183 ED_region_tag_redraw(ar); 00184 break; 00185 case ND_ANIMCHAN: 00186 if(wmn->action==NA_SELECTED) 00187 ED_region_tag_redraw(ar); 00188 break; 00189 } 00190 break; 00191 } 00192 00193 } 00194 00195 00196 /* ************************ header outliner area region *********************** */ 00197 00198 /* add handlers, stuff you only do once or on area/region changes */ 00199 static void outliner_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar) 00200 { 00201 ED_region_header_init(ar); 00202 } 00203 00204 static void outliner_header_area_draw(const bContext *C, ARegion *ar) 00205 { 00206 ED_region_header(C, ar); 00207 } 00208 00209 static void outliner_header_area_free(ARegion *UNUSED(ar)) 00210 { 00211 } 00212 00213 static void outliner_header_area_listener(ARegion *ar, wmNotifier *wmn) 00214 { 00215 /* context changes */ 00216 switch(wmn->category) { 00217 case NC_SCENE: 00218 if(wmn->data == ND_KEYINGSET) 00219 ED_region_tag_redraw(ar); 00220 break; 00221 case NC_SPACE: 00222 if(wmn->data == ND_SPACE_OUTLINER) 00223 ED_region_tag_redraw(ar); 00224 break; 00225 } 00226 } 00227 00228 /* ******************** default callbacks for outliner space ***************** */ 00229 00230 static SpaceLink *outliner_new(const bContext *UNUSED(C)) 00231 { 00232 ARegion *ar; 00233 SpaceOops *soutliner; 00234 00235 soutliner= MEM_callocN(sizeof(SpaceOops), "initoutliner"); 00236 soutliner->spacetype= SPACE_OUTLINER; 00237 00238 /* header */ 00239 ar= MEM_callocN(sizeof(ARegion), "header for outliner"); 00240 00241 BLI_addtail(&soutliner->regionbase, ar); 00242 ar->regiontype= RGN_TYPE_HEADER; 00243 ar->alignment= RGN_ALIGN_BOTTOM; 00244 00245 /* main area */ 00246 ar= MEM_callocN(sizeof(ARegion), "main area for outliner"); 00247 00248 BLI_addtail(&soutliner->regionbase, ar); 00249 ar->regiontype= RGN_TYPE_WINDOW; 00250 00251 ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O); 00252 ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y); 00253 ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT); 00254 ar->v2d.keeptot= V2D_KEEPTOT_STRICT; 00255 ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f; 00256 00257 return (SpaceLink*)soutliner; 00258 } 00259 00260 /* not spacelink itself */ 00261 static void outliner_free(SpaceLink *sl) 00262 { 00263 SpaceOops *soutliner= (SpaceOops*)sl; 00264 00265 outliner_free_tree(&soutliner->tree); 00266 if(soutliner->treestore) { 00267 if(soutliner->treestore->data) MEM_freeN(soutliner->treestore->data); 00268 MEM_freeN(soutliner->treestore); 00269 } 00270 00271 } 00272 00273 /* spacetype; init callback */ 00274 static void outliner_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa)) 00275 { 00276 00277 } 00278 00279 static SpaceLink *outliner_duplicate(SpaceLink *sl) 00280 { 00281 SpaceOops *soutliner= (SpaceOops *)sl; 00282 SpaceOops *soutlinern= MEM_dupallocN(soutliner); 00283 00284 soutlinern->tree.first= soutlinern->tree.last= NULL; 00285 soutlinern->treestore= NULL; 00286 00287 return (SpaceLink *)soutlinern; 00288 } 00289 00290 /* only called once, from space_api/spacetypes.c */ 00291 void ED_spacetype_outliner(void) 00292 { 00293 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time"); 00294 ARegionType *art; 00295 00296 st->spaceid= SPACE_OUTLINER; 00297 strncpy(st->name, "Outliner", BKE_ST_MAXNAME); 00298 00299 st->new= outliner_new; 00300 st->free= outliner_free; 00301 st->init= outliner_init; 00302 st->duplicate= outliner_duplicate; 00303 st->operatortypes= outliner_operatortypes; 00304 st->keymap= outliner_keymap; 00305 00306 /* regions: main window */ 00307 art= MEM_callocN(sizeof(ARegionType), "spacetype time region"); 00308 art->regionid = RGN_TYPE_WINDOW; 00309 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D; 00310 00311 art->init= outliner_main_area_init; 00312 art->draw= outliner_main_area_draw; 00313 art->free= outliner_main_area_free; 00314 art->listener= outliner_main_area_listener; 00315 BLI_addhead(&st->regiontypes, art); 00316 00317 /* regions: header */ 00318 art= MEM_callocN(sizeof(ARegionType), "spacetype time region"); 00319 art->regionid = RGN_TYPE_HEADER; 00320 art->prefsizey= HEADERY; 00321 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER; 00322 00323 art->init= outliner_header_area_init; 00324 art->draw= outliner_header_area_draw; 00325 art->free= outliner_header_area_free; 00326 art->listener= outliner_header_area_listener; 00327 BLI_addhead(&st->regiontypes, art); 00328 00329 BKE_spacetype_register(st); 00330 } 00331