4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
32 #include "DNA_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36 #include "DNA_view3d_types.h"
38 #include "MEM_guardedalloc.h"
40 #include "BLI_blenlib.h"
41 #include "BLI_arithb.h"
44 #include "BKE_context.h"
45 #include "BKE_global.h"
46 #include "BKE_screen.h"
48 #include "ED_space_api.h"
49 #include "ED_screen.h"
55 #include "UI_interface.h"
56 #include "UI_resources.h"
57 #include "UI_view2d.h"
59 #include "view3d_intern.h" // own include
61 /* ******************** default callbacks for view3d space ***************** */
63 static SpaceLink *view3d_new(void)
68 vd= MEM_callocN(sizeof(View3D), "initview3d");
69 vd->spacetype= SPACE_VIEW3D;
71 vd->lay= vd->layact= 1;
73 vd->lay= vd->layact= G.scene->lay;
74 vd->camera= G.scene->camera;
80 vd->drawtype= OB_WIRE;
82 vd->gridflag |= V3D_SHOW_X;
83 vd->gridflag |= V3D_SHOW_Y;
84 vd->gridflag |= V3D_SHOW_FLOOR;
85 vd->gridflag &= ~V3D_SHOW_Z;
89 /* XXX move view data to region? */
90 vd->viewquat[0]= 1.0f;
91 vd->viewquat[1]= vd->viewquat[2]= vd->viewquat[3]= 0.0f;
100 ar= MEM_callocN(sizeof(ARegion), "header for view3d");
102 BLI_addtail(&vd->regionbase, ar);
103 ar->regiontype= RGN_TYPE_HEADER;
104 ar->alignment= RGN_ALIGN_BOTTOM;
107 ar= MEM_callocN(sizeof(ARegion), "main area for view3d");
109 BLI_addtail(&vd->regionbase, ar);
110 ar->regiontype= RGN_TYPE_WINDOW;
112 return (SpaceLink *)vd;
115 /* not spacelink itself */
116 static void view3d_free(SpaceLink *sl)
118 View3D *vd= (View3D *) sl;
121 if(vd->bgpic->ima) vd->bgpic->ima->id.us--;
122 MEM_freeN(vd->bgpic);
125 if(vd->localvd) MEM_freeN(vd->localvd);
126 if(vd->clipbb) MEM_freeN(vd->clipbb);
128 if(vd->depths->depths) MEM_freeN(vd->depths->depths);
129 MEM_freeN(vd->depths);
133 // XXX retopo_free_view_data(vd);
135 if(vd->properties_storage) MEM_freeN(vd->properties_storage);
137 // XXX BIF_view3d_previewrender_free(vd);
143 /* spacetype; init callback */
144 static void view3d_init(struct wmWindowManager *wm, ScrArea *sa)
149 static SpaceLink *view3d_duplicate(SpaceLink *sl)
151 View3D *v3do= (View3D *)sl;
152 View3D *v3dn= MEM_dupallocN(sl);
154 /* clear or remove stuff from old */
156 // XXX BIF_view3d_previewrender_free(v3do);
158 v3do->retopo_view_data= NULL;
161 // XXX restore_localviewdata(v3do);
163 v3do->properties_storage= NULL;
165 v3do->lay &= 0xFFFFFF;
168 /* copy or clear inside new stuff */
171 v3dn->bgpic= MEM_dupallocN(v3dn->bgpic);
172 if(v3dn->bgpic->ima) v3dn->bgpic->ima->id.us++;
174 v3dn->clipbb= MEM_dupallocN(v3dn->clipbb);
176 v3dn->properties_storage= NULL;
178 return (SpaceLink *)v3dn;
181 static void view3d_main_area_draw(const bContext *C, ARegion *ar)
183 /* draw entirely, view changes should be handled here */
184 ScrArea *sa= CTX_wm_area(C);
185 View3D *v3d= sa->spacedata.first; /* XXX get from region */
187 drawview3dspace(CTX_data_scene(C), ar, v3d);
190 /* add handlers, stuff you only do once or on area/region changes */
191 static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
196 keymap= WM_keymap_listbase(wm, "View3D", SPACE_VIEW3D, 0); /* XXX weak? */
197 WM_event_add_keymap_handler_bb(&ar->handlers, keymap,NULL, NULL);
202 /* add handlers, stuff you only do once or on area/region changes */
203 static void view3d_header_area_init(wmWindowManager *wm, ARegion *ar)
205 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
208 static void view3d_header_area_draw(const bContext *C, ARegion *ar)
213 if(ED_screen_area_active(C))
214 UI_GetThemeColor3fv(TH_HEADER, col);
216 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
218 glClearColor(col[0], col[1], col[2], 0.0);
219 glClear(GL_COLOR_BUFFER_BIT);
221 /* set view2d view matrix for scrolling (without scrollers) */
222 UI_view2d_view_ortho(C, &ar->v2d);
224 view3d_header_buttons(C, ar);
226 /* restore view matrix? */
227 UI_view2d_view_restore(C);
231 /* only called once, from space/spacetypes.c */
232 void ED_spacetype_view3d(void)
234 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
237 st->spaceid= SPACE_VIEW3D;
240 st->free= view3d_free;
241 st->init= view3d_init;
242 st->duplicate= view3d_duplicate;
243 st->operatortypes= view3d_operatortypes;
244 st->keymap= view3d_keymap;
246 /* regions: main window */
247 art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
248 art->regionid = RGN_TYPE_WINDOW;
249 art->draw= view3d_main_area_draw;
250 art->init= view3d_main_area_init;
252 BLI_addhead(&st->regiontypes, art);
254 /* regions: header */
255 art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
256 art->regionid = RGN_TYPE_HEADER;
257 art->minsizey= HEADERY;
258 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
260 art->init= view3d_header_area_init;
261 art->draw= view3d_header_area_draw;
263 BLI_addhead(&st->regiontypes, art);
265 BKE_spacetype_register(st);