Merged revision(s) 57768-57827 from trunk/blender into soc-2013-dingto
[blender.git] / source / blender / editors / space_view3d / space_view3d.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_view3d/space_view3d.c
28  *  \ingroup spview3d
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_material_types.h"
36 #include "DNA_object_types.h"
37 #include "DNA_scene_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42 #include "BLI_math.h"
43 #include "BLI_utildefines.h"
44
45 #include "BKE_context.h"
46 #include "BKE_icons.h"
47 #include "BKE_object.h"
48 #include "BKE_screen.h"
49
50 #include "ED_render.h"
51 #include "ED_space_api.h"
52 #include "ED_screen.h"
53 #include "ED_object.h"
54
55 #include "GPU_extensions.h"
56 #include "GPU_material.h"
57
58 #include "BIF_gl.h"
59
60 #include "WM_api.h"
61 #include "WM_types.h"
62
63 #include "RE_engine.h"
64
65 #include "RNA_access.h"
66
67 #include "UI_resources.h"
68
69 #include "view3d_intern.h"  /* own include */
70
71 /* ******************** manage regions ********************* */
72
73 ARegion *view3d_has_buttons_region(ScrArea *sa)
74 {
75         ARegion *ar, *arnew;
76
77         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
78         if (ar) return ar;
79         
80         /* add subdiv level; after header */
81         ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
82
83         /* is error! */
84         if (ar == NULL) return NULL;
85         
86         arnew = MEM_callocN(sizeof(ARegion), "buttons for view3d");
87         
88         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
89         arnew->regiontype = RGN_TYPE_UI;
90         arnew->alignment = RGN_ALIGN_RIGHT;
91         
92         arnew->flag = RGN_FLAG_HIDDEN;
93         
94         return arnew;
95 }
96
97 ARegion *view3d_has_tools_region(ScrArea *sa)
98 {
99         ARegion *ar, *artool = NULL, *arprops = NULL, *arhead;
100         
101         for (ar = sa->regionbase.first; ar; ar = ar->next) {
102                 if (ar->regiontype == RGN_TYPE_TOOLS)
103                         artool = ar;
104                 if (ar->regiontype == RGN_TYPE_TOOL_PROPS)
105                         arprops = ar;
106         }
107         
108         /* tool region hide/unhide also hides props */
109         if (arprops && artool) return artool;
110         
111         if (artool == NULL) {
112                 /* add subdiv level; after header */
113                 for (arhead = sa->regionbase.first; arhead; arhead = arhead->next)
114                         if (arhead->regiontype == RGN_TYPE_HEADER)
115                                 break;
116                 
117                 /* is error! */
118                 if (arhead == NULL) return NULL;
119                 
120                 artool = MEM_callocN(sizeof(ARegion), "tools for view3d");
121                 
122                 BLI_insertlinkafter(&sa->regionbase, arhead, artool);
123                 artool->regiontype = RGN_TYPE_TOOLS;
124                 artool->alignment = RGN_ALIGN_LEFT;
125                 artool->flag = RGN_FLAG_HIDDEN;
126         }
127
128         if (arprops == NULL) {
129                 /* add extra subdivided region for tool properties */
130                 arprops = MEM_callocN(sizeof(ARegion), "tool props for view3d");
131                 
132                 BLI_insertlinkafter(&sa->regionbase, artool, arprops);
133                 arprops->regiontype = RGN_TYPE_TOOL_PROPS;
134                 arprops->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
135         }
136         
137         return artool;
138 }
139
140 /* ****************************************************** */
141
142 /* function to always find a regionview3d context inside 3D window */
143 RegionView3D *ED_view3d_context_rv3d(bContext *C)
144 {
145         RegionView3D *rv3d = CTX_wm_region_view3d(C);
146         
147         if (rv3d == NULL) {
148                 ScrArea *sa = CTX_wm_area(C);
149                 if (sa && sa->spacetype == SPACE_VIEW3D) {
150                         ARegion *ar = BKE_area_find_region_active_win(sa);
151                         if (ar) {
152                                 rv3d = ar->regiondata;
153                         }
154                 }
155         }
156         return rv3d;
157 }
158
159 /* ideally would return an rv3d but in some cases the region is needed too
160  * so return that, the caller can then access the ar->regiondata */
161 bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_ar)
162 {
163         ScrArea *sa = CTX_wm_area(C);
164
165         *r_v3d = NULL;
166         *r_ar = NULL;
167
168         if (sa && sa->spacetype == SPACE_VIEW3D) {
169                 ARegion *ar = CTX_wm_region(C);
170                 View3D *v3d = (View3D *)sa->spacedata.first;
171
172                 if (ar) {
173                         RegionView3D *rv3d = ar->regiondata;
174                         if (rv3d && rv3d->viewlock == 0) {
175                                 *r_v3d = v3d;
176                                 *r_ar = ar;
177                                 return true;
178                         }
179                         else {
180                                 ARegion *ar_unlock_user = NULL;
181                                 ARegion *ar_unlock = NULL;
182                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
183                                         /* find the first unlocked rv3d */
184                                         if (ar->regiondata && ar->regiontype == RGN_TYPE_WINDOW) {
185                                                 rv3d = ar->regiondata;
186                                                 if (rv3d->viewlock == 0) {
187                                                         ar_unlock = ar;
188                                                         if (rv3d->persp == RV3D_PERSP || rv3d->persp == RV3D_CAMOB) {
189                                                                 ar_unlock_user = ar;
190                                                                 break;
191                                                         }
192                                                 }
193                                         }
194                                 }
195
196                                 /* camera/perspective view get priority when the active region is locked */
197                                 if (ar_unlock_user) {
198                                         *r_v3d = v3d;
199                                         *r_ar = ar_unlock_user;
200                                         return true;
201                                 }
202
203                                 if (ar_unlock) {
204                                         *r_v3d = v3d;
205                                         *r_ar = ar_unlock;
206                                         return true;
207                                 }
208                         }
209                 }
210         }
211
212         return false;
213 }
214
215 /* Most of the time this isn't needed since you could assume the view matrix was
216  * set while drawing, however when functions like mesh_foreachScreenVert are
217  * called by selection tools, we can't be sure this object was the last.
218  *
219  * for example, transparent objects are drawn after editmode and will cause
220  * the rv3d mat's to change and break selection.
221  *
222  * 'ED_view3d_init_mats_rv3d' should be called before
223  * view3d_project_short_clip and view3d_project_short_noclip in cases where
224  * these functions are not used during draw_object
225  */
226 void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d)
227 {
228         /* local viewmat and persmat, to calculate projections */
229         mul_m4_m4m4(rv3d->viewmatob, rv3d->viewmat, ob->obmat);
230         mul_m4_m4m4(rv3d->persmatob, rv3d->persmat, ob->obmat);
231
232         /* initializes object space clipping, speeds up clip tests */
233         ED_view3d_clipping_local(rv3d, ob->obmat);
234 }
235
236 void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d)
237 {
238         ED_view3d_init_mats_rv3d(ob, rv3d);
239
240         /* we have to multiply instead of loading viewmatob to make
241          * it work with duplis using displists, otherwise it will
242          * override the dupli-matrix */
243         glMultMatrixf(ob->obmat);
244 }
245
246 #ifdef DEBUG
247 /* ensure we correctly initialize */
248 void ED_view3d_clear_mats_rv3d(struct RegionView3D *rv3d)
249 {
250         zero_m4(rv3d->viewmatob);
251         zero_m4(rv3d->persmatob);
252 }
253
254 void ED_view3d_check_mats_rv3d(struct RegionView3D *rv3d)
255 {
256         BLI_ASSERT_ZERO_M4(rv3d->viewmatob);
257         BLI_ASSERT_ZERO_M4(rv3d->persmatob);
258 }
259 #endif
260
261 /* ******************** default callbacks for view3d space ***************** */
262
263 static SpaceLink *view3d_new(const bContext *C)
264 {
265         Scene *scene = CTX_data_scene(C);
266         ARegion *ar;
267         View3D *v3d;
268         RegionView3D *rv3d;
269         
270         v3d = MEM_callocN(sizeof(View3D), "initview3d");
271         v3d->spacetype = SPACE_VIEW3D;
272         v3d->blockscale = 0.7f;
273         v3d->lay = v3d->layact = 1;
274         if (scene) {
275                 v3d->lay = v3d->layact = scene->lay;
276                 v3d->camera = scene->camera;
277         }
278         v3d->scenelock = TRUE;
279         v3d->grid = 1.0f;
280         v3d->gridlines = 16;
281         v3d->gridsubdiv = 10;
282         v3d->drawtype = OB_SOLID;
283
284         v3d->gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR;
285         
286         v3d->flag = V3D_SELECT_OUTLINE;
287         v3d->flag2 = V3D_SHOW_RECONSTRUCTION | V3D_SHOW_GPENCIL;
288         
289         v3d->lens = 35.0f;
290         v3d->near = 0.01f;
291         v3d->far = 1000.0f;
292
293         v3d->twflag |= U.tw_flag & V3D_USE_MANIPULATOR;
294         v3d->twtype = V3D_MANIP_TRANSLATE;
295         v3d->around = V3D_CENTROID;
296         
297         v3d->bundle_size = 0.2f;
298         v3d->bundle_drawtype = OB_PLAINAXES;
299         
300         /* header */
301         ar = MEM_callocN(sizeof(ARegion), "header for view3d");
302         
303         BLI_addtail(&v3d->regionbase, ar);
304         ar->regiontype = RGN_TYPE_HEADER;
305         ar->alignment = RGN_ALIGN_BOTTOM;
306         
307         /* tool shelf */
308         ar = MEM_callocN(sizeof(ARegion), "toolshelf for view3d");
309         
310         BLI_addtail(&v3d->regionbase, ar);
311         ar->regiontype = RGN_TYPE_TOOLS;
312         ar->alignment = RGN_ALIGN_LEFT;
313         ar->flag = RGN_FLAG_HIDDEN;
314         
315         /* tool properties */
316         ar = MEM_callocN(sizeof(ARegion), "tool properties for view3d");
317         
318         BLI_addtail(&v3d->regionbase, ar);
319         ar->regiontype = RGN_TYPE_TOOL_PROPS;
320         ar->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
321         ar->flag = RGN_FLAG_HIDDEN;
322         
323         /* buttons/list view */
324         ar = MEM_callocN(sizeof(ARegion), "buttons for view3d");
325         
326         BLI_addtail(&v3d->regionbase, ar);
327         ar->regiontype = RGN_TYPE_UI;
328         ar->alignment = RGN_ALIGN_RIGHT;
329         ar->flag = RGN_FLAG_HIDDEN;
330         
331         /* main area */
332         ar = MEM_callocN(sizeof(ARegion), "main area for view3d");
333         
334         BLI_addtail(&v3d->regionbase, ar);
335         ar->regiontype = RGN_TYPE_WINDOW;
336         
337         ar->regiondata = MEM_callocN(sizeof(RegionView3D), "region view3d");
338         rv3d = ar->regiondata;
339         rv3d->viewquat[0] = 1.0f;
340         rv3d->persp = RV3D_PERSP;
341         rv3d->view = RV3D_VIEW_PERSPORTHO;
342         rv3d->dist = 10.0;
343         
344         return (SpaceLink *)v3d;
345 }
346
347 /* not spacelink itself */
348 static void view3d_free(SpaceLink *sl)
349 {
350         View3D *vd = (View3D *) sl;
351
352         BLI_freelistN(&vd->bgpicbase);
353
354         if (vd->localvd) MEM_freeN(vd->localvd);
355         
356         if (vd->properties_storage) MEM_freeN(vd->properties_storage);
357         
358         /* matcap material, its preview rect gets freed via icons */
359         if (vd->defmaterial) {
360                 if (vd->defmaterial->gpumaterial.first)
361                         GPU_material_free(vd->defmaterial);
362                 BKE_previewimg_free(&vd->defmaterial->preview);
363                 MEM_freeN(vd->defmaterial);
364         }
365 }
366
367
368 /* spacetype; init callback */
369 static void view3d_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
370 {
371
372 }
373
374 static SpaceLink *view3d_duplicate(SpaceLink *sl)
375 {
376         View3D *v3do = (View3D *)sl;
377         View3D *v3dn = MEM_dupallocN(sl);
378         
379         /* clear or remove stuff from old */
380         
381 // XXX  BIF_view3d_previewrender_free(v3do);
382         
383         if (v3dn->localvd) {
384                 v3dn->localvd = NULL;
385                 v3dn->properties_storage = NULL;
386                 v3dn->lay = v3do->localvd->lay & 0xFFFFFF;
387         }
388
389         if (v3dn->drawtype == OB_RENDER)
390                 v3dn->drawtype = OB_SOLID;
391         
392         /* copy or clear inside new stuff */
393
394         v3dn->defmaterial = NULL;
395         
396         BLI_duplicatelist(&v3dn->bgpicbase, &v3do->bgpicbase);
397
398         v3dn->properties_storage = NULL;
399         
400         return (SpaceLink *)v3dn;
401 }
402
403 /* add handlers, stuff you only do once or on area/region changes */
404 static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
405 {
406         ListBase *lb;
407         wmKeyMap *keymap;
408
409         /* object ops. */
410         
411         /* important to be before Pose keymap since they can both be enabled at once */
412         keymap = WM_keymap_find(wm->defaultconf, "Face Mask", 0, 0);
413         WM_event_add_keymap_handler(&ar->handlers, keymap);
414         
415         
416         keymap = WM_keymap_find(wm->defaultconf, "Weight Paint Vertex Selection", 0, 0);
417         WM_event_add_keymap_handler(&ar->handlers, keymap);
418
419         /* pose is not modal, operator poll checks for this */
420         keymap = WM_keymap_find(wm->defaultconf, "Pose", 0, 0);
421         WM_event_add_keymap_handler(&ar->handlers, keymap);
422         
423         keymap = WM_keymap_find(wm->defaultconf, "Object Mode", 0, 0);
424         WM_event_add_keymap_handler(&ar->handlers, keymap);
425
426         keymap = WM_keymap_find(wm->defaultconf, "Image Paint", 0, 0);
427         WM_event_add_keymap_handler(&ar->handlers, keymap);
428
429         keymap = WM_keymap_find(wm->defaultconf, "Vertex Paint", 0, 0);
430         WM_event_add_keymap_handler(&ar->handlers, keymap);
431
432         keymap = WM_keymap_find(wm->defaultconf, "Weight Paint", 0, 0);
433         WM_event_add_keymap_handler(&ar->handlers, keymap);
434
435         keymap = WM_keymap_find(wm->defaultconf, "Sculpt", 0, 0);
436         WM_event_add_keymap_handler(&ar->handlers, keymap);
437         
438         keymap = WM_keymap_find(wm->defaultconf, "Mesh", 0, 0);
439         WM_event_add_keymap_handler(&ar->handlers, keymap);
440         
441         keymap = WM_keymap_find(wm->defaultconf, "Curve", 0, 0);
442         WM_event_add_keymap_handler(&ar->handlers, keymap);
443         
444         keymap = WM_keymap_find(wm->defaultconf, "Armature", 0, 0);
445         WM_event_add_keymap_handler(&ar->handlers, keymap);
446
447         keymap = WM_keymap_find(wm->defaultconf, "Pose", 0, 0);
448         WM_event_add_keymap_handler(&ar->handlers, keymap);
449
450         keymap = WM_keymap_find(wm->defaultconf, "Metaball", 0, 0);
451         WM_event_add_keymap_handler(&ar->handlers, keymap);
452         
453         keymap = WM_keymap_find(wm->defaultconf, "Lattice", 0, 0);
454         WM_event_add_keymap_handler(&ar->handlers, keymap);
455
456         /* armature sketching needs to take over mouse */
457         keymap = WM_keymap_find(wm->defaultconf, "Armature Sketch", 0, 0);
458         WM_event_add_keymap_handler(&ar->handlers, keymap);
459
460         keymap = WM_keymap_find(wm->defaultconf, "Particle", 0, 0);
461         WM_event_add_keymap_handler(&ar->handlers, keymap);
462
463         /* editfont keymap swallows all... */
464         keymap = WM_keymap_find(wm->defaultconf, "Font", 0, 0);
465         WM_event_add_keymap_handler(&ar->handlers, keymap);
466
467         keymap = WM_keymap_find(wm->defaultconf, "Object Non-modal", 0, 0);
468         WM_event_add_keymap_handler(&ar->handlers, keymap);
469
470         keymap = WM_keymap_find(wm->defaultconf, "Frames", 0, 0);
471         WM_event_add_keymap_handler(&ar->handlers, keymap);
472
473         /* own keymap, last so modes can override it */
474         keymap = WM_keymap_find(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
475         WM_event_add_keymap_handler(&ar->handlers, keymap);
476
477         keymap = WM_keymap_find(wm->defaultconf, "3D View", SPACE_VIEW3D, 0);
478         WM_event_add_keymap_handler(&ar->handlers, keymap);
479         
480         /* add drop boxes */
481         lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
482         
483         WM_event_add_dropbox_handler(&ar->handlers, lb);
484         
485 }
486
487 static void view3d_main_area_exit(wmWindowManager *UNUSED(wm), ARegion *ar)
488 {
489         RegionView3D *rv3d = ar->regiondata;
490
491         if (rv3d->render_engine) {
492                 RE_engine_free(rv3d->render_engine);
493                 rv3d->render_engine = NULL;
494         }
495
496         if (rv3d->gpuoffscreen) {
497                 GPU_offscreen_free(rv3d->gpuoffscreen);
498                 rv3d->gpuoffscreen = NULL;
499         }
500 }
501
502 static int view3d_ob_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
503 {
504         if (drag->type == WM_DRAG_ID) {
505                 ID *id = (ID *)drag->poin;
506                 if (GS(id->name) == ID_OB)
507                         return 1;
508         }
509         return 0;
510 }
511
512 static int view3d_group_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
513 {
514         if (drag->type == WM_DRAG_ID) {
515                 ID *id = (ID *)drag->poin;
516                 if (GS(id->name) == ID_GR)
517                         return 1;
518         }
519         return 0;
520 }
521
522 static int view3d_mat_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
523 {
524         if (drag->type == WM_DRAG_ID) {
525                 ID *id = (ID *)drag->poin;
526                 if (GS(id->name) == ID_MA)
527                         return 1;
528         }
529         return 0;
530 }
531
532 static int view3d_ima_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
533 {
534         if (drag->type == WM_DRAG_ID) {
535                 ID *id = (ID *)drag->poin;
536                 if (GS(id->name) == ID_IM)
537                         return 1;
538         }
539         else if (drag->type == WM_DRAG_PATH) {
540                 if (ELEM(drag->icon, 0, ICON_FILE_IMAGE))   /* rule might not work? */
541                         return 1;
542         }
543         return 0;
544 }
545
546 static int view3d_ima_bg_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
547 {
548         if (event->ctrl)
549                 return false;
550
551         if (!ED_view3d_give_base_under_cursor(C, event->mval)) {
552                 return view3d_ima_drop_poll(C, drag, event);
553         }
554         return 0;
555 }
556
557 static int view3d_ima_empty_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
558 {
559         Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
560
561         /* either holding and ctrl and no object, or dropping to empty */
562         if ((event->ctrl && !base) || (base && base->object->type == OB_EMPTY))
563                 return view3d_ima_drop_poll(C, drag, event);
564
565         return 0;
566 }
567
568 static int view3d_ima_mesh_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
569 {
570         Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
571
572         if (base && base->object->type == OB_MESH)
573                 return view3d_ima_drop_poll(C, drag, event);
574         return 0;
575 }
576
577 static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop)
578 {
579         ID *id = (ID *)drag->poin;
580
581         RNA_string_set(drop->ptr, "name", id->name + 2);
582 }
583
584 static void view3d_group_drop_copy(wmDrag *drag, wmDropBox *drop)
585 {
586         ID *id = (ID *)drag->poin;
587         
588         drop->opcontext = WM_OP_EXEC_DEFAULT;
589         RNA_string_set(drop->ptr, "name", id->name + 2);
590 }
591
592 static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop)
593 {
594         ID *id = (ID *)drag->poin;
595         
596         RNA_string_set(drop->ptr, "name", id->name + 2);
597 }
598
599 static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop)
600 {
601         ID *id = (ID *)drag->poin;
602         
603         if (id)
604                 RNA_string_set(drop->ptr, "name", id->name + 2);
605         if (drag->path[0])
606                 RNA_string_set(drop->ptr, "filepath", drag->path);
607 }
608
609
610 /* region dropbox definition */
611 static void view3d_dropboxes(void)
612 {
613         ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
614         
615         WM_dropbox_add(lb, "OBJECT_OT_add_named", view3d_ob_drop_poll, view3d_ob_drop_copy);
616         WM_dropbox_add(lb, "OBJECT_OT_drop_named_material", view3d_mat_drop_poll, view3d_id_drop_copy);
617         WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_mesh_drop_poll, view3d_id_path_drop_copy);
618         WM_dropbox_add(lb, "OBJECT_OT_drop_named_image", view3d_ima_empty_drop_poll, view3d_id_path_drop_copy);
619         WM_dropbox_add(lb, "VIEW3D_OT_background_image_add", view3d_ima_bg_drop_poll, view3d_id_path_drop_copy);
620         WM_dropbox_add(lb, "OBJECT_OT_group_instance_add", view3d_group_drop_poll, view3d_group_drop_copy);
621 }
622
623
624
625 /* type callback, not region itself */
626 static void view3d_main_area_free(ARegion *ar)
627 {
628         RegionView3D *rv3d = ar->regiondata;
629         
630         if (rv3d) {
631                 if (rv3d->localvd) MEM_freeN(rv3d->localvd);
632                 if (rv3d->clipbb) MEM_freeN(rv3d->clipbb);
633
634                 if (rv3d->ri) {
635                         // XXX          BIF_view3d_previewrender_free(rv3d);
636                 }
637
638                 if (rv3d->render_engine)
639                         RE_engine_free(rv3d->render_engine);
640                 
641                 if (rv3d->depths) {
642                         if (rv3d->depths->depths) MEM_freeN(rv3d->depths->depths);
643                         MEM_freeN(rv3d->depths);
644                 }
645                 if (rv3d->sms) {
646                         MEM_freeN(rv3d->sms);
647                 }
648                 if (rv3d->gpuoffscreen) {
649                         GPU_offscreen_free(rv3d->gpuoffscreen);
650                 }
651
652                 MEM_freeN(rv3d);
653                 ar->regiondata = NULL;
654         }
655 }
656
657 /* copy regiondata */
658 static void *view3d_main_area_duplicate(void *poin)
659 {
660         if (poin) {
661                 RegionView3D *rv3d = poin, *new;
662         
663                 new = MEM_dupallocN(rv3d);
664                 if (rv3d->localvd)
665                         new->localvd = MEM_dupallocN(rv3d->localvd);
666                 if (rv3d->clipbb)
667                         new->clipbb = MEM_dupallocN(rv3d->clipbb);
668                 
669                 new->depths = NULL;
670                 new->gpuoffscreen = NULL;
671                 new->ri = NULL;
672                 new->render_engine = NULL;
673                 new->gpd = NULL;
674                 new->sms = NULL;
675                 new->smooth_timer = NULL;
676                 
677                 return new;
678         }
679         return NULL;
680 }
681
682 static void view3d_recalc_used_layers(ARegion *ar, wmNotifier *wmn, Scene *scene)
683 {
684         wmWindow *win = wmn->wm->winactive;
685         ScrArea *sa;
686         unsigned int lay_used = 0;
687         Base *base;
688
689         if (!win) return;
690
691         base = scene->base.first;
692         while (base) {
693                 lay_used |= base->lay & ((1 << 20) - 1); /* ignore localview */
694
695                 if (lay_used == (1 << 20) - 1)
696                         break;
697
698                 base = base->next;
699         }
700
701         for (sa = win->screen->areabase.first; sa; sa = sa->next) {
702                 if (sa->spacetype == SPACE_VIEW3D) {
703                         if (BLI_findindex(&sa->regionbase, ar) != -1) {
704                                 View3D *v3d = sa->spacedata.first;
705                                 v3d->lay_used = lay_used;
706                                 break;
707                         }
708                 }
709         }
710 }
711
712 static void view3d_main_area_listener(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *wmn)
713 {
714         Scene *scene = sc->scene;
715         View3D *v3d = sa->spacedata.first;
716         
717         /* context changes */
718         switch (wmn->category) {
719                 case NC_ANIMATION:
720                         switch (wmn->data) {
721                                 case ND_KEYFRAME_PROP:
722                                 case ND_NLA_ACTCHANGE:
723                                         ED_region_tag_redraw(ar);
724                                         break;
725                                 case ND_NLA:
726                                 case ND_KEYFRAME:
727                                         if (wmn->action == NA_EDITED)
728                                                 ED_region_tag_redraw(ar);
729                                         break;
730                                 case ND_ANIMCHAN:
731                                         if (wmn->action == NA_SELECTED)
732                                                 ED_region_tag_redraw(ar);
733                                         break;
734                         }
735                         break;
736                 case NC_SCENE:
737                         switch (wmn->data) {
738                                 case ND_LAYER_CONTENT:
739                                         if (wmn->reference)
740                                                 view3d_recalc_used_layers(ar, wmn, wmn->reference);
741                                         ED_region_tag_redraw(ar);
742                                         break;
743                                 case ND_FRAME:
744                                 case ND_TRANSFORM:
745                                 case ND_OB_ACTIVE:
746                                 case ND_OB_SELECT:
747                                 case ND_OB_VISIBLE:
748                                 case ND_LAYER:
749                                 case ND_RENDER_OPTIONS:
750                                 case ND_MODE:
751                                         ED_region_tag_redraw(ar);
752                                         break;
753                                 case ND_WORLD:
754                                         /* handled by space_view3d_listener() for v3d access */
755                                         break;
756                         }
757                         if (wmn->action == NA_EDITED)
758                                 ED_region_tag_redraw(ar);
759                         break;
760                 case NC_OBJECT:
761                         switch (wmn->data) {
762                                 case ND_BONE_ACTIVE:
763                                 case ND_BONE_SELECT:
764                                 case ND_TRANSFORM:
765                                 case ND_POSE:
766                                 case ND_DRAW:
767                                 case ND_MODIFIER:
768                                 case ND_CONSTRAINT:
769                                 case ND_KEYS:
770                                 case ND_PARTICLE:
771                                         ED_region_tag_redraw(ar);
772                                         break;
773                         }
774                         switch (wmn->action) {
775                                 case NA_ADDED:
776                                         ED_region_tag_redraw(ar);
777                                         break;
778                         }
779                         break;
780                 case NC_GEOM:
781                         switch (wmn->data) {
782                                 case ND_DATA:
783                                 case ND_VERTEX_GROUP:
784                                 case ND_SELECT:
785                                         ED_region_tag_redraw(ar);
786                                         break;
787                         }
788                         switch (wmn->action) {
789                                 case NA_EDITED:
790                                         ED_region_tag_redraw(ar);
791                                         break;
792                         }
793                         break;
794                 case NC_GROUP:
795                         /* all group ops for now */
796                         ED_region_tag_redraw(ar);
797                         break;
798                 case NC_BRUSH:
799                         if (wmn->action == NA_EDITED)
800                                 ED_region_tag_redraw_overlay(ar);
801                         break;
802                 case NC_MATERIAL:
803                         switch (wmn->data) {
804                                 case ND_SHADING:
805                                 case ND_NODES:
806                                         if ((v3d->drawtype == OB_MATERIAL) ||
807                                             (v3d->drawtype == OB_TEXTURE && scene->gm.matmode == GAME_MAT_GLSL))
808                                         {
809                                                 ED_region_tag_redraw(ar);
810                                         }
811                                         break;
812                                 case ND_SHADING_DRAW:
813                                 case ND_SHADING_LINKS:
814                                         ED_region_tag_redraw(ar);
815                                         break;
816                         }
817                         break;
818                 case NC_WORLD:
819                         switch (wmn->data) {
820                                 case ND_WORLD_DRAW:
821                                         /* handled by space_view3d_listener() for v3d access */
822                                         break;
823                                 case ND_WORLD_STARS:
824                                 {
825                                         RegionView3D *rv3d = ar->regiondata;
826                                         if (rv3d->persp == RV3D_CAMOB) {
827                                                 ED_region_tag_redraw(ar);
828                                         }
829                                 }
830                         }
831                         break;
832                 case NC_LAMP:
833                         switch (wmn->data) {
834                                 case ND_LIGHTING:
835                                         if ((v3d->drawtype == OB_MATERIAL) ||
836                                             (v3d->drawtype == OB_TEXTURE && (scene->gm.matmode == GAME_MAT_GLSL)))
837                                         {
838                                                 ED_region_tag_redraw(ar);
839                                         }
840                                         break;
841                                 case ND_LIGHTING_DRAW:
842                                         ED_region_tag_redraw(ar);
843                                         break;
844                         }
845                         break;
846                 case NC_IMAGE:
847                         /* this could be more fine grained checks if we had
848                          * more context than just the region */
849                         ED_region_tag_redraw(ar);
850                         break;
851                 case NC_TEXTURE:
852                         /* same as above */
853                         ED_region_tag_redraw(ar);
854                         break;
855                 case NC_MOVIECLIP:
856                         if (wmn->data == ND_DISPLAY)
857                                 ED_region_tag_redraw(ar);
858                         break;
859                 case NC_SPACE:
860                         if (wmn->data == ND_SPACE_VIEW3D) {
861                                 if (wmn->subtype == NS_VIEW3D_GPU) {
862                                         RegionView3D *rv3d = ar->regiondata;
863                                         rv3d->rflag |= RV3D_GPULIGHT_UPDATE;
864                                 }
865                                 ED_region_tag_redraw(ar);
866                         }
867                         break;
868                 case NC_ID:
869                         if (wmn->action == NA_RENAME)
870                                 ED_region_tag_redraw(ar);
871                         break;
872                 case NC_SCREEN:
873                         switch (wmn->data) {
874                                 case ND_ANIMPLAY:
875                                 case ND_SKETCH:
876                                         ED_region_tag_redraw(ar);
877                                         break;
878                                 case ND_SCREENBROWSE:
879                                 case ND_SCREENDELETE:
880                                 case ND_SCREENSET:
881                                         /* screen was changed, need to update used layers due to NC_SCENE|ND_LAYER_CONTENT */
882                                         /* updates used layers only for View3D in active screen */
883                                         if (wmn->reference) {
884                                                 bScreen *sc = wmn->reference;
885                                                 view3d_recalc_used_layers(ar, wmn, sc->scene);
886                                         }
887                                         ED_region_tag_redraw(ar);
888                                         break;
889                         }
890
891                         break;
892                 case NC_GPENCIL:
893                         if (wmn->action == NA_EDITED)
894                                 ED_region_tag_redraw(ar);
895                         break;
896         }
897 }
898
899 /* concept is to retrieve cursor type context-less */
900 static void view3d_main_area_cursor(wmWindow *win, ScrArea *UNUSED(sa), ARegion *UNUSED(ar))
901 {
902         Scene *scene = win->screen->scene;
903
904         if (scene->obedit) {
905                 WM_cursor_set(win, CURSOR_EDIT);
906         }
907         else {
908                 WM_cursor_set(win, CURSOR_STD);
909         }
910 }
911
912 /* add handlers, stuff you only do once or on area/region changes */
913 static void view3d_header_area_init(wmWindowManager *wm, ARegion *ar)
914 {
915         wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
916         
917         WM_event_add_keymap_handler(&ar->handlers, keymap);
918
919         ED_region_header_init(ar);
920 }
921
922 static void view3d_header_area_draw(const bContext *C, ARegion *ar)
923 {
924         ED_region_header(C, ar);
925 }
926
927 static void view3d_header_area_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
928 {
929         /* context changes */
930         switch (wmn->category) {
931                 case NC_SCENE:
932                         switch (wmn->data) {
933                                 case ND_FRAME:
934                                 case ND_OB_ACTIVE:
935                                 case ND_OB_SELECT:
936                                 case ND_OB_VISIBLE:
937                                 case ND_MODE:
938                                 case ND_LAYER:
939                                 case ND_TOOLSETTINGS:
940                                 case ND_LAYER_CONTENT:
941                                         ED_region_tag_redraw(ar);
942                                         break;
943                         }
944                         break;
945                 case NC_SPACE:
946                         if (wmn->data == ND_SPACE_VIEW3D)
947                                 ED_region_tag_redraw(ar);
948                         break;
949         }
950 }
951
952 /* add handlers, stuff you only do once or on area/region changes */
953 static void view3d_buttons_area_init(wmWindowManager *wm, ARegion *ar)
954 {
955         wmKeyMap *keymap;
956
957         ED_region_panels_init(wm, ar);
958         
959         keymap = WM_keymap_find(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
960         WM_event_add_keymap_handler(&ar->handlers, keymap);
961 }
962
963 static void view3d_buttons_area_draw(const bContext *C, ARegion *ar)
964 {
965         ED_region_panels(C, ar, 1, NULL, -1);
966 }
967
968 static void view3d_buttons_area_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
969 {
970         /* context changes */
971         switch (wmn->category) {
972                 case NC_ANIMATION:
973                         switch (wmn->data) {
974                                 case ND_KEYFRAME_PROP:
975                                 case ND_NLA_ACTCHANGE:
976                                         ED_region_tag_redraw(ar);
977                                         break;
978                                 case ND_NLA:
979                                 case ND_KEYFRAME:
980                                         if (wmn->action == NA_EDITED)
981                                                 ED_region_tag_redraw(ar);
982                                         break;
983                         }
984                         break;
985                 case NC_SCENE:
986                         switch (wmn->data) {
987                                 case ND_FRAME:
988                                 case ND_OB_ACTIVE:
989                                 case ND_OB_SELECT:
990                                 case ND_OB_VISIBLE:
991                                 case ND_MODE:
992                                 case ND_LAYER:
993                                 case ND_LAYER_CONTENT:
994                                 case ND_TOOLSETTINGS:
995                                         ED_region_tag_redraw(ar);
996                                         break;
997                         }
998                         switch (wmn->action) {
999                                 case NA_EDITED:
1000                                         ED_region_tag_redraw(ar);
1001                                         break;
1002                         }
1003                         break;
1004                 case NC_OBJECT:
1005                         switch (wmn->data) {
1006                                 case ND_BONE_ACTIVE:
1007                                 case ND_BONE_SELECT:
1008                                 case ND_TRANSFORM:
1009                                 case ND_POSE:
1010                                 case ND_DRAW:
1011                                 case ND_KEYS:
1012                                 case ND_MODIFIER:
1013                                         ED_region_tag_redraw(ar);
1014                                         break;
1015                         }
1016                         break;
1017                 case NC_GEOM:
1018                         switch (wmn->data) {
1019                                 case ND_DATA:
1020                                 case ND_VERTEX_GROUP:
1021                                 case ND_SELECT:
1022                                         ED_region_tag_redraw(ar);
1023                                         break;
1024                         }
1025                         if (wmn->action == NA_EDITED)
1026                                 ED_region_tag_redraw(ar);
1027                         break;
1028                 case NC_TEXTURE:
1029                 case NC_MATERIAL:
1030                         /* for brush textures */
1031                         ED_region_tag_redraw(ar);
1032                         break;
1033                 case NC_BRUSH:
1034                         if (wmn->action == NA_EDITED)
1035                                 ED_region_tag_redraw(ar);
1036                         break;
1037                 case NC_SPACE:
1038                         if (wmn->data == ND_SPACE_VIEW3D)
1039                                 ED_region_tag_redraw(ar);
1040                         break;
1041                 case NC_ID:
1042                         if (wmn->action == NA_RENAME)
1043                                 ED_region_tag_redraw(ar);
1044                         break;
1045                 case NC_GPENCIL:
1046                         if (wmn->data == ND_DATA || wmn->action == NA_EDITED)
1047                                 ED_region_tag_redraw(ar);
1048                         break;
1049         }
1050 }
1051
1052 /* add handlers, stuff you only do once or on area/region changes */
1053 static void view3d_tools_area_init(wmWindowManager *wm, ARegion *ar)
1054 {
1055         wmKeyMap *keymap;
1056         
1057         ED_region_panels_init(wm, ar);
1058
1059         keymap = WM_keymap_find(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
1060         WM_event_add_keymap_handler(&ar->handlers, keymap);
1061 }
1062
1063 static void view3d_tools_area_draw(const bContext *C, ARegion *ar)
1064 {
1065         ED_region_panels(C, ar, 1, CTX_data_mode_string(C), -1);
1066 }
1067
1068 static void view3d_props_area_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
1069 {
1070         /* context changes */
1071         switch (wmn->category) {
1072                 case NC_WM:
1073                         if (wmn->data == ND_HISTORY)
1074                                 ED_region_tag_redraw(ar);
1075                         break;
1076                 case NC_SCENE:
1077                         if (wmn->data == ND_MODE)
1078                                 ED_region_tag_redraw(ar);
1079                         break;
1080                 case NC_SPACE:
1081                         if (wmn->data == ND_SPACE_VIEW3D)
1082                                 ED_region_tag_redraw(ar);
1083                         break;
1084         }
1085 }
1086
1087 /*area (not region) level listener*/
1088 static void space_view3d_listener(bScreen *UNUSED(sc), ScrArea *sa, struct wmNotifier *wmn)
1089 {
1090         View3D *v3d = sa->spacedata.first;
1091
1092         /* context changes */
1093         switch (wmn->category) {
1094                 case NC_SCENE:
1095                         switch (wmn->data) {
1096                                 case ND_WORLD:
1097                                         if (v3d->flag2 & V3D_RENDER_OVERRIDE)
1098                                                 ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
1099                                         break;
1100                         }
1101                         break;
1102                 case NC_WORLD:
1103                         switch (wmn->data) {
1104                                 case ND_WORLD_DRAW:
1105                                         if (v3d->flag2 & V3D_RENDER_OVERRIDE)
1106                                                 ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
1107                                         break;
1108                         }
1109                         break;
1110                 case NC_MATERIAL:
1111                         switch (wmn->data) {
1112                                 case ND_NODES:
1113                                         if (v3d->drawtype == OB_TEXTURE)
1114                                                 ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
1115                                         break;
1116                         }
1117                         break;
1118         }
1119
1120         /* removed since BKE_image_user_frame_calc is now called in view3d_draw_bgpic because screen_ops doesnt call the notifier. */
1121 #if 0
1122         if (wmn->category == NC_SCENE && wmn->data == ND_FRAME) {
1123                 View3D *v3d = area->spacedata.first;
1124                 BGpic *bgpic = v3d->bgpicbase.first;
1125
1126                 for (; bgpic; bgpic = bgpic->next) {
1127                         if (bgpic->ima) {
1128                                 Scene *scene = wmn->reference;
1129                                 BKE_image_user_frame_calc(&bgpic->iuser, scene->r.cfra, 0);
1130                         }
1131                 }
1132         }
1133 #endif
1134 }
1135
1136 const char *view3d_context_dir[] = {
1137         "selected_objects", "selected_bases", "selected_editable_objects",
1138         "selected_editable_bases", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
1139         "active_base", "active_object", NULL
1140 };
1141
1142 static int view3d_context(const bContext *C, const char *member, bContextDataResult *result)
1143 {
1144         View3D *v3d = CTX_wm_view3d(C);
1145         Scene *scene = CTX_data_scene(C);
1146         Base *base;
1147         /* fallback to the scene layer, allows duplicate and other object operators to run outside the 3d view */
1148         unsigned int lay = v3d ? v3d->lay : scene->lay;
1149
1150         if (CTX_data_dir(member)) {
1151                 CTX_data_dir_set(result, view3d_context_dir);
1152         }
1153         else if (CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
1154                 int selected_objects = CTX_data_equals(member, "selected_objects");
1155
1156                 for (base = scene->base.first; base; base = base->next) {
1157                         if ((base->flag & SELECT) && (base->lay & lay)) {
1158                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
1159                                         if (selected_objects)
1160                                                 CTX_data_id_list_add(result, &base->object->id);
1161                                         else
1162                                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
1163                                 }
1164                         }
1165                 }
1166                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
1167                 return 1;
1168         }
1169         else if (CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
1170                 int selected_editable_objects = CTX_data_equals(member, "selected_editable_objects");
1171
1172                 for (base = scene->base.first; base; base = base->next) {
1173                         if ((base->flag & SELECT) && (base->lay & lay)) {
1174                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
1175                                         if (0 == BKE_object_is_libdata(base->object)) {
1176                                                 if (selected_editable_objects)
1177                                                         CTX_data_id_list_add(result, &base->object->id);
1178                                                 else
1179                                                         CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
1180                                         }
1181                                 }
1182                         }
1183                 }
1184                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
1185                 return 1;
1186         }
1187         else if (CTX_data_equals(member, "visible_objects") || CTX_data_equals(member, "visible_bases")) {
1188                 int visible_objects = CTX_data_equals(member, "visible_objects");
1189
1190                 for (base = scene->base.first; base; base = base->next) {
1191                         if (base->lay & lay) {
1192                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
1193                                         if (visible_objects)
1194                                                 CTX_data_id_list_add(result, &base->object->id);
1195                                         else
1196                                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
1197                                 }
1198                         }
1199                 }
1200                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
1201                 return 1;
1202         }
1203         else if (CTX_data_equals(member, "selectable_objects") || CTX_data_equals(member, "selectable_bases")) {
1204                 int selectable_objects = CTX_data_equals(member, "selectable_objects");
1205
1206                 for (base = scene->base.first; base; base = base->next) {
1207                         if (base->lay & lay) {
1208                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) {
1209                                         if (selectable_objects)
1210                                                 CTX_data_id_list_add(result, &base->object->id);
1211                                         else
1212                                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
1213                                 }
1214                         }
1215                 }
1216                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
1217                 return 1;
1218         }
1219         else if (CTX_data_equals(member, "active_base")) {
1220                 if (scene->basact && (scene->basact->lay & lay)) {
1221                         Object *ob = scene->basact->object;
1222                         /* if hidden but in edit mode, we still display, can happen with animation */
1223                         if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT))
1224                                 CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, scene->basact);
1225                 }
1226                 
1227                 return 1;
1228         }
1229         else if (CTX_data_equals(member, "active_object")) {
1230                 if (scene->basact && (scene->basact->lay & lay)) {
1231                         Object *ob = scene->basact->object;
1232                         if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT))
1233                                 CTX_data_id_pointer_set(result, &scene->basact->object->id);
1234                 }
1235                 
1236                 return 1;
1237         }
1238         else {
1239                 return 0; /* not found */
1240         }
1241
1242         return -1; /* found but not available */
1243 }
1244
1245
1246 /* only called once, from space/spacetypes.c */
1247 void ED_spacetype_view3d(void)
1248 {
1249         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype view3d");
1250         ARegionType *art;
1251         
1252         st->spaceid = SPACE_VIEW3D;
1253         strncpy(st->name, "View3D", BKE_ST_MAXNAME);
1254         
1255         st->new = view3d_new;
1256         st->free = view3d_free;
1257         st->init = view3d_init;
1258         st->listener = space_view3d_listener;
1259         st->duplicate = view3d_duplicate;
1260         st->operatortypes = view3d_operatortypes;
1261         st->keymap = view3d_keymap;
1262         st->dropboxes = view3d_dropboxes;
1263         st->context = view3d_context;
1264         
1265         /* regions: main window */
1266         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d main region");
1267         art->regionid = RGN_TYPE_WINDOW;
1268         art->keymapflag = ED_KEYMAP_GPENCIL;
1269         art->draw = view3d_main_area_draw;
1270         art->init = view3d_main_area_init;
1271         art->exit = view3d_main_area_exit;
1272         art->free = view3d_main_area_free;
1273         art->duplicate = view3d_main_area_duplicate;
1274         art->listener = view3d_main_area_listener;
1275         art->cursor = view3d_main_area_cursor;
1276         art->lock = 1;   /* can become flag, see BKE_spacedata_draw_locks */
1277         BLI_addhead(&st->regiontypes, art);
1278         
1279         /* regions: listview/buttons */
1280         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d buttons region");
1281         art->regionid = RGN_TYPE_UI;
1282         art->prefsizex = 180; /* XXX */
1283         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
1284         art->listener = view3d_buttons_area_listener;
1285         art->init = view3d_buttons_area_init;
1286         art->draw = view3d_buttons_area_draw;
1287         BLI_addhead(&st->regiontypes, art);
1288
1289         view3d_buttons_register(art);
1290
1291         /* regions: tool(bar) */
1292         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tools region");
1293         art->regionid = RGN_TYPE_TOOLS;
1294         art->prefsizex = 160; /* XXX */
1295         art->prefsizey = 50; /* XXX */
1296         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
1297         art->listener = view3d_buttons_area_listener;
1298         art->init = view3d_tools_area_init;
1299         art->draw = view3d_tools_area_draw;
1300         BLI_addhead(&st->regiontypes, art);
1301         
1302 #if 0
1303         /* unfinished still */
1304         view3d_toolshelf_register(art);
1305 #endif
1306
1307         /* regions: tool properties */
1308         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tool properties region");
1309         art->regionid = RGN_TYPE_TOOL_PROPS;
1310         art->prefsizex = 0;
1311         art->prefsizey = 120;
1312         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
1313         art->listener = view3d_props_area_listener;
1314         art->init = view3d_tools_area_init;
1315         art->draw = view3d_tools_area_draw;
1316         BLI_addhead(&st->regiontypes, art);
1317         
1318         view3d_tool_props_register(art);
1319         
1320         
1321         /* regions: header */
1322         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d header region");
1323         art->regionid = RGN_TYPE_HEADER;
1324         art->prefsizey = HEADERY;
1325         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
1326         art->listener = view3d_header_area_listener;
1327         art->init = view3d_header_area_init;
1328         art->draw = view3d_header_area_draw;
1329         BLI_addhead(&st->regiontypes, art);
1330         
1331         BKE_spacetype_register(st);
1332 }
1333