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_node_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_space_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
38 #include "MEM_guardedalloc.h"
40 #include "BLI_blenlib.h"
41 #include "BLI_arithb.h"
44 #include "BKE_colortools.h"
45 #include "BKE_context.h"
46 #include "BKE_screen.h"
48 #include "ED_space_api.h"
49 #include "ED_screen.h"
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
60 #include "node_intern.h" // own include
62 /* ******************** default callbacks for node space ***************** */
64 static SpaceLink *node_new(void)
69 snode= MEM_callocN(sizeof(SpaceNode), "initnode");
70 snode->spacetype= SPACE_NODE;
73 ar= MEM_callocN(sizeof(ARegion), "header for node");
75 BLI_addtail(&snode->regionbase, ar);
76 ar->regiontype= RGN_TYPE_HEADER;
77 ar->alignment= RGN_ALIGN_BOTTOM;
80 ar= MEM_callocN(sizeof(ARegion), "main area for node");
82 BLI_addtail(&snode->regionbase, ar);
83 ar->regiontype= RGN_TYPE_WINDOW;
85 ar->v2d.tot.xmin= -10.0f;
86 ar->v2d.tot.ymin= -10.0f;
87 ar->v2d.tot.xmax= 512.0f;
88 ar->v2d.tot.ymax= 512.0f;
90 ar->v2d.cur.xmin= 0.0f;
91 ar->v2d.cur.ymin= 0.0f;
92 ar->v2d.cur.xmax= 512.0f;
93 ar->v2d.cur.ymax= 512.0f;
98 ar->v2d.max[0]= 32000.0f;
99 ar->v2d.max[1]= 32000.0f;
101 ar->v2d.minzoom= 0.5f;
102 ar->v2d.maxzoom= 1.21f;
105 ar->v2d.keepzoom= V2D_KEEPZOOM|V2D_KEEPASPECT;
109 return (SpaceLink *)snode;
112 /* not spacelink itself */
113 static void node_free(SpaceLink *sl)
115 // SpaceNode *snode= (SpaceNode*) sl;
117 // XXX if(snode->gpd) free_gpencil_data(snode->gpd);
121 /* spacetype; init callback */
122 static void node_init(struct wmWindowManager *wm, ScrArea *sa)
127 static SpaceLink *node_duplicate(SpaceLink *sl)
129 SpaceNode *snoden= MEM_dupallocN(sl);
131 /* clear or remove stuff from old */
132 snoden->nodetree= NULL;
133 // XXX snoden->gpd= gpencil_data_duplicate(snode->gpd);
135 return (SpaceLink *)snoden;
140 /* add handlers, stuff you only do once or on area/region changes */
141 static void node_main_area_init(wmWindowManager *wm, ARegion *ar)
145 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
148 keymap= WM_keymap_listbase(wm, "Node", SPACE_NODE, 0); /* XXX weak? */
149 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
152 static void node_main_area_draw(const bContext *C, ARegion *ar)
154 /* draw entirely, view changes should be handled here */
155 // SpaceNode *snode= (SpaceNode*)CTX_wm_space_data(C);
156 View2D *v2d= &ar->v2d;
160 /* clear and setup matrix */
161 UI_GetThemeColor3fv(TH_BACK, col);
162 glClearColor(col[0], col[1], col[2], 0.0);
163 glClear(GL_COLOR_BUFFER_BIT);
165 UI_view2d_view_ortho(C, v2d);
169 grid= UI_view2d_grid_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP, ar->winx, ar->winy);
170 UI_view2d_grid_draw(C, v2d, grid, V2D_GRIDLINES_ALL);
171 UI_view2d_grid_free(grid);
177 /* reset view matrix */
178 UI_view2d_view_restore(C);
183 void node_operatortypes(void)
188 void node_keymap(struct wmWindowManager *wm)
193 /* add handlers, stuff you only do once or on area/region changes */
194 static void node_header_area_init(wmWindowManager *wm, ARegion *ar)
196 UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
199 static void node_header_area_draw(const bContext *C, ARegion *ar)
204 if(ED_screen_area_active(C))
205 UI_GetThemeColor3fv(TH_HEADER, col);
207 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
209 glClearColor(col[0], col[1], col[2], 0.0);
210 glClear(GL_COLOR_BUFFER_BIT);
212 /* set view2d view matrix for scrolling (without scrollers) */
213 UI_view2d_view_ortho(C, &ar->v2d);
215 node_header_buttons(C, ar);
217 /* restore view matrix? */
218 UI_view2d_view_restore(C);
221 static void node_main_area_listener(ARegion *ar, wmNotifier *wmn)
223 /* context changes */
226 /* only called once, from space/spacetypes.c */
227 void ED_spacetype_node(void)
229 SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype node");
232 st->spaceid= SPACE_NODE;
237 st->duplicate= node_duplicate;
238 st->operatortypes= node_operatortypes;
239 st->keymap= node_keymap;
241 /* regions: main window */
242 art= MEM_callocN(sizeof(ARegionType), "spacetype node region");
243 art->regionid = RGN_TYPE_WINDOW;
244 art->init= node_main_area_init;
245 art->draw= node_main_area_draw;
246 art->listener= node_main_area_listener;
247 art->keymapflag= ED_KEYMAP_VIEW2D;
249 BLI_addhead(&st->regiontypes, art);
251 /* regions: header */
252 art= MEM_callocN(sizeof(ARegionType), "spacetype node region");
253 art->regionid = RGN_TYPE_HEADER;
254 art->minsizey= HEADERY;
255 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
257 art->init= node_header_area_init;
258 art->draw= node_header_area_draw;
260 BLI_addhead(&st->regiontypes, art);
262 /* regions: channels */
263 art= MEM_callocN(sizeof(ARegionType), "spacetype node region");
264 art->regionid = RGN_TYPE_CHANNELS;
266 art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
268 // art->init= node_channel_area_init;
269 // art->draw= node_channel_area_draw;
271 BLI_addhead(&st->regiontypes, art);
274 BKE_spacetype_register(st);