2.5
[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         WM_operatortype_append(FILE_OT_pack_all);
155         WM_operatortype_append(FILE_OT_unpack_all);
156         WM_operatortype_append(FILE_OT_make_paths_relative);
157         WM_operatortype_append(FILE_OT_make_paths_absolute);
158         WM_operatortype_append(FILE_OT_report_missing_files);
159         WM_operatortype_append(FILE_OT_find_missing_files);
160 }
161
162 void info_keymap(struct wmWindowManager *wm)
163 {
164         
165 }
166
167 /* add handlers, stuff you only do once or on area/region changes */
168 static void info_header_area_init(wmWindowManager *wm, ARegion *ar)
169 {
170         ED_region_header_init(ar);
171 }
172
173 static void info_header_area_draw(const bContext *C, ARegion *ar)
174 {
175         ED_region_header(C, ar);
176 }
177
178 static void info_main_area_listener(ARegion *ar, wmNotifier *wmn)
179 {
180         /* context changes */
181 }
182
183 static void info_header_listener(ARegion *ar, wmNotifier *wmn)
184 {
185         /* context changes */
186         switch(wmn->category) {
187                 case NC_SCREEN:
188                         if(ELEM(wmn->data, ND_SCREENCAST, ND_ANIMPLAY))
189                                 ED_region_tag_redraw(ar);
190                         break;
191                 case NC_SCENE:
192                         if(wmn->data==ND_RENDER_RESULT)
193                                 ED_region_tag_redraw(ar);
194                         break;
195         }
196         
197 }
198
199 /* only called once, from space/spacetypes.c */
200 void ED_spacetype_info(void)
201 {
202         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype info");
203         ARegionType *art;
204         
205         st->spaceid= SPACE_INFO;
206         
207         st->new= info_new;
208         st->free= info_free;
209         st->init= info_init;
210         st->duplicate= info_duplicate;
211         st->operatortypes= info_operatortypes;
212         st->keymap= info_keymap;
213         
214         /* regions: main window */
215         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
216         art->regionid = RGN_TYPE_WINDOW;
217         art->init= info_main_area_init;
218         art->draw= info_main_area_draw;
219         art->listener= info_main_area_listener;
220         art->keymapflag= ED_KEYMAP_VIEW2D;
221
222         BLI_addhead(&st->regiontypes, art);
223         
224         /* regions: header */
225         art= MEM_callocN(sizeof(ARegionType), "spacetype info region");
226         art->regionid = RGN_TYPE_HEADER;
227         art->minsizey= HEADERY;
228         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
229         art->listener= info_header_listener;
230         art->init= info_header_area_init;
231         art->draw= info_header_area_draw;
232         
233         BLI_addhead(&st->regiontypes, art);
234         
235         
236         BKE_spacetype_register(st);
237 }
238