Fix [#21516] UI artifacts in array modifier
[blender.git] / source / blender / editors / space_outliner / space_outliner.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32
33 #include "MEM_guardedalloc.h"
34
35 #include "BLI_blenlib.h"
36 #include "BLI_math.h"
37 #include "BLI_rand.h"
38
39 #include "BKE_colortools.h"
40 #include "BKE_context.h"
41 #include "BKE_screen.h"
42 #include "BKE_texture.h"
43 #include "BKE_utildefines.h"
44
45 #include "ED_screen.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 #include "BIF_gl.h"
51 #include "BIF_glutil.h"
52
53 #include "UI_resources.h"
54 #include "UI_view2d.h"
55
56
57 #include "outliner_intern.h"
58
59 static void outliner_main_area_init(wmWindowManager *wm, ARegion *ar)
60 {
61         wmKeyMap *keymap;
62         
63         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
64         
65         /* own keymap */
66         keymap= WM_keymap_find(wm->defaultconf, "Outliner", SPACE_OUTLINER, 0);
67         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
68 }
69
70 static void outliner_main_area_draw(const bContext *C, ARegion *ar)
71 {
72         View2D *v2d= &ar->v2d;
73         View2DScrollers *scrollers;
74         
75         /* clear */
76         UI_ThemeClearColor(TH_BACK);
77         glClear(GL_COLOR_BUFFER_BIT);
78         
79         draw_outliner(C);
80         
81         /* reset view matrix */
82         UI_view2d_view_restore(C);
83         
84         /* scrollers */
85         scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
86         UI_view2d_scrollers_draw(C, v2d, scrollers);
87         UI_view2d_scrollers_free(scrollers);
88 }
89
90
91 static void outliner_main_area_free(ARegion *ar)
92 {
93 }
94
95
96 static void outliner_main_area_listener(ARegion *ar, wmNotifier *wmn)
97 {
98         /* context changes */
99         switch(wmn->category) {
100                 case NC_SCENE:
101                         switch(wmn->data) {
102                                 case ND_OB_ACTIVE:
103                                 case ND_OB_SELECT:
104                                 case ND_MODE:
105                                 case ND_KEYINGSET:
106                                 case ND_FRAME:
107                                 case ND_RENDER_OPTIONS:
108                                 case ND_LAYER:
109                                         ED_region_tag_redraw(ar);
110                                         break;
111                         }
112                         break;
113                 case NC_OBJECT:
114                         switch(wmn->data) {
115                                 case ND_TRANSFORM:
116                                         /* transform doesn't change outliner data */
117                                         break;
118                                 case ND_BONE_ACTIVE:
119                                 case ND_BONE_SELECT:
120                                         ED_region_tag_redraw(ar);
121                                         break;
122                                 case ND_MODIFIER:
123                                         if(wmn->action == NA_RENAME)
124                                                 ED_region_tag_redraw(ar);
125                                         break;
126                         }
127                 case NC_GROUP:
128                         /* all actions now, todo: check outliner view mode? */
129                         ED_region_tag_redraw(ar);
130                         break;
131                 case NC_LAMP:
132                         /* For updating lamp icons, when changing lamp type */
133                         if(wmn->data == ND_LIGHTING_DRAW)
134                                 ED_region_tag_redraw(ar);
135                                 break;
136                 case NC_SPACE:
137                         if(wmn->data == ND_SPACE_OUTLINER)
138                                 ED_region_tag_redraw(ar);
139                                 break;
140                 case NC_ID:
141                         if(wmn->action == NA_RENAME)
142                                 ED_region_tag_redraw(ar);
143                         break;
144         }
145         
146 }
147
148
149 /* ************************ header outliner area region *********************** */
150
151 /* add handlers, stuff you only do once or on area/region changes */
152 static void outliner_header_area_init(wmWindowManager *wm, ARegion *ar)
153 {
154         ED_region_header_init(ar);
155 }
156
157 static void outliner_header_area_draw(const bContext *C, ARegion *ar)
158 {
159         ED_region_header(C, ar);
160 }
161
162 static void outliner_header_area_free(ARegion *ar)
163 {
164 }
165
166 static void outliner_header_area_listener(ARegion *ar, wmNotifier *wmn)
167 {
168         /* context changes */
169         switch(wmn->category) {
170                 case NC_SCENE:
171                         if(wmn->data == ND_KEYINGSET)
172                                 ED_region_tag_redraw(ar);
173                         break;
174                 case NC_SPACE:
175                         if(wmn->data == ND_SPACE_OUTLINER)
176                                 ED_region_tag_redraw(ar);
177                         break;
178         }
179 }
180
181 /* ******************** default callbacks for outliner space ***************** */
182
183 static SpaceLink *outliner_new(const bContext *C)
184 {
185         ARegion *ar;
186         SpaceOops *soutliner;
187
188         soutliner= MEM_callocN(sizeof(SpaceOops), "initoutliner");
189         soutliner->spacetype= SPACE_OUTLINER;
190         
191         /* header */
192         ar= MEM_callocN(sizeof(ARegion), "header for outliner");
193         
194         BLI_addtail(&soutliner->regionbase, ar);
195         ar->regiontype= RGN_TYPE_HEADER;
196         ar->alignment= RGN_ALIGN_BOTTOM;
197         
198         /* main area */
199         ar= MEM_callocN(sizeof(ARegion), "main area for outliner");
200         
201         BLI_addtail(&soutliner->regionbase, ar);
202         ar->regiontype= RGN_TYPE_WINDOW;
203         
204         ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O);
205         ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
206         ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
207         ar->v2d.keeptot= V2D_KEEPTOT_STRICT;
208         ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
209         
210         return (SpaceLink*)soutliner;
211 }
212
213 /* not spacelink itself */
214 static void outliner_free(SpaceLink *sl)
215 {
216         SpaceOops *soutliner= (SpaceOops*)sl;
217         
218         outliner_free_tree(&soutliner->tree);
219         if(soutliner->treestore) {
220                 if(soutliner->treestore->data) MEM_freeN(soutliner->treestore->data);
221                 MEM_freeN(soutliner->treestore);
222         }
223         
224 }
225
226 /* spacetype; init callback */
227 static void outliner_init(wmWindowManager *wm, ScrArea *sa)
228 {
229         
230 }
231
232 static SpaceLink *outliner_duplicate(SpaceLink *sl)
233 {
234         SpaceOops *soutliner= (SpaceOops *)sl;
235         SpaceOops *soutlinern= MEM_dupallocN(soutliner);
236
237         soutlinern->tree.first= soutlinern->tree.last= NULL;
238         soutlinern->treestore= NULL;
239         
240         return (SpaceLink *)soutlinern;
241 }
242
243 /* only called once, from space_api/spacetypes.c */
244 void ED_spacetype_outliner(void)
245 {
246         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
247         ARegionType *art;
248         
249         st->spaceid= SPACE_OUTLINER;
250         strncpy(st->name, "Outliner", BKE_ST_MAXNAME);
251         
252         st->new= outliner_new;
253         st->free= outliner_free;
254         st->init= outliner_init;
255         st->duplicate= outliner_duplicate;
256         st->operatortypes= outliner_operatortypes;
257         st->keymap= outliner_keymap;
258         
259         /* regions: main window */
260         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
261         art->regionid = RGN_TYPE_WINDOW;
262         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
263         
264         art->init= outliner_main_area_init;
265         art->draw= outliner_main_area_draw;
266         art->free= outliner_main_area_free;
267         art->listener= outliner_main_area_listener;
268         BLI_addhead(&st->regiontypes, art);
269         
270         /* regions: header */
271         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
272         art->regionid = RGN_TYPE_HEADER;
273         art->prefsizey= HEADERY;
274         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
275         
276         art->init= outliner_header_area_init;
277         art->draw= outliner_header_area_draw;
278         art->free= outliner_header_area_free;
279         art->listener= outliner_header_area_listener;
280         BLI_addhead(&st->regiontypes, art);
281         
282         BKE_spacetype_register(st);
283 }
284