Merge with 2.5 rev 20373.
[blender.git] / source / blender / editors / space_info / space_info.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include "DNA_object_types.h"
33 #include "DNA_space_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36
37 #include "MEM_guardedalloc.h"
38
39 #include "BLI_blenlib.h"
40 #include "BLI_arithb.h"
41 #include "BLI_rand.h"
42
43 #include "BKE_context.h"
44 #include "BKE_colortools.h"
45 #include "BKE_screen.h"
46 #include "BKE_utildefines.h"
47
48 #include "ED_space_api.h"
49 #include "ED_screen.h"
50
51 #include "BIF_gl.h"
52
53 #include "WM_api.h"
54 #include "WM_types.h"
55
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58 #include "UI_view2d.h"
59
60 #include "ED_markers.h"
61
62 #include "info_intern.h"        // own include
63
64 /* ******************** default callbacks for info space ***************** */
65
66 static SpaceLink *info_new(const bContext *C)
67 {
68         ARegion *ar;
69         SpaceInfo *sinfo;
70         
71         sinfo= MEM_callocN(sizeof(SpaceInfo), "initinfo");
72         sinfo->spacetype= SPACE_INFO;
73         
74         /* header */
75         ar= MEM_callocN(sizeof(ARegion), "header for info");
76         
77         BLI_addtail(&sinfo->regionbase, ar);
78         ar->regiontype= RGN_TYPE_HEADER;
79         ar->alignment= RGN_ALIGN_BOTTOM;
80         
81         /* main area */
82         ar= MEM_callocN(sizeof(ARegion), "main area for info");
83         
84         BLI_addtail(&sinfo->regionbase, ar);
85         ar->regiontype= RGN_TYPE_WINDOW;
86         
87         /* channel list region XXX */
88
89         
90         return (SpaceLink *)sinfo;
91 }
92
93 /* not spacelink itself */
94 static void info_free(SpaceLink *sl)
95 {       
96 //      SpaceInfo *sinfo= (SpaceInfo*) sl;
97         
98 }
99
100
101 /* spacetype; init callback */
102 static void info_init(struct wmWindowManager *wm, ScrArea *sa)
103 {
104
105 }
106
107 static SpaceLink *info_duplicate(SpaceLink *sl)
108 {
109         SpaceInfo *sinfon= MEM_dupallocN(sl);
110         
111         /* clear or remove stuff from old */
112         
113         return (SpaceLink *)sinfon;
114 }
115
116
117
118 /* add handlers, stuff you only do once or on area/region changes */
119 static void info_main_area_init(wmWindowManager *wm, ARegion *ar)
120 {
121         ListBase *keymap;
122         
123         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
124         
125         /* own keymap */
126         keymap= WM_keymap_listbase(wm, "info", SPACE_INFO, 0);  /* XXX weak? */
127         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
128 }
129
130 static void info_main_area_draw(const bContext *C, ARegion *ar)
131 {
132         /* draw entirely, view changes should be handled here */
133         // SpaceInfo *sinfo= (SpaceInfo*)CTX_wm_space_data(C);
134         View2D *v2d= &ar->v2d;
135         float col[3];
136
137         /* clear and setup matrix */
138         UI_GetThemeColor3fv(TH_BACK, col);
139         glClearColor(col[0], col[1], col[2], 0.0);
140         glClear(GL_COLOR_BUFFER_BIT);
141         
142         UI_view2d_view_ortho(C, v2d);
143                 
144         /* data... */
145
146         /* reset view matrix */
147         UI_view2d_view_restore(C);
148         
149         /* scrollers? */
150 }
151
152 void info_operatortypes(void)
153 {
154         
155 }
156
157 void info_keymap(struct wmWindowManager *wm)
158 {
159         
160 }
161
162 /* add handlers, stuff you only do once or on area/region changes */
163 static void info_header_area_init(wmWindowManager *wm, ARegion *ar)
164 {
165         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
166 }
167
168 static void info_header_area_draw(const bContext *C, ARegion *ar)
169 {
170         float col[3];
171         
172         /* clear */
173         if(ED_screen_area_active(C))
174                 UI_GetThemeColor3fv(TH_HEADER, col);
175         else
176                 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
177         
178         glClearColor(col[0], col[1], col[2], 0.0);
179         glClear(GL_COLOR_BUFFER_BIT);
180         
181         /* set view2d view matrix for scrolling (without scrollers) */
182         UI_view2d_view_ortho(C, &ar->v2d);
183         
184         info_header_buttons(C, ar);
185         
186         /* restore view matrix? */
187         UI_view2d_view_restore(C);
188 }
189
190 static void info_main_area_listener(ARegion *ar, wmNotifier *wmn)
191 {
192         /* context changes */
193 }
194
195 static void info_header_listener(ARegion *ar, wmNotifier *wmn)
196 {
197         /* context changes */
198         switch(wmn->category) {
199                 case NC_SCREEN:
200                         if(ELEM(wmn->data, ND_SCREENCAST, ND_ANIMPLAY))
201                                 ED_region_tag_redraw(ar);
202                         break;
203                 case NC_SCENE:
204                         if(wmn->data==ND_RENDER_RESULT)
205                                 ED_region_tag_redraw(ar);
206                         break;
207         }
208         
209 }
210
211 /* only called once, from space/spacetypes.c */
212 void ED_spacetype_info(void)
213 {
214         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype info");
215         ARegionType *art;
216         
217         st->spaceid= SPACE_INFO;
218         
219         st->new= info_new;
220         st->free= info_free;
221         st->init= info_init;
222         st->duplicate= info_duplicate;
223         st->operatortypes= info_operatortypes;
224         st->keymap= info_keymap;
225         
226         /* regions: main window */
227         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
228         art->regionid = RGN_TYPE_WINDOW;
229         art->init= info_main_area_init;
230         art->draw= info_main_area_draw;
231         art->listener= info_main_area_listener;
232         art->keymapflag= ED_KEYMAP_VIEW2D;
233
234         BLI_addhead(&st->regiontypes, art);
235         
236         /* regions: header */
237         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
238         art->regionid = RGN_TYPE_HEADER;
239         art->minsizey= HEADERY;
240         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
241         art->listener= info_header_listener;
242         art->init= info_header_area_init;
243         art->draw= info_header_area_draw;
244         
245         BLI_addhead(&st->regiontypes, art);
246         
247         
248         BKE_spacetype_register(st);
249 }
250