2.5
[blender.git] / source / blender / editors / space_image / space_image.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_image_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"
37
38 #include "MEM_guardedalloc.h"
39
40 #include "BLI_blenlib.h"
41 #include "BLI_arithb.h"
42 #include "BLI_rand.h"
43
44 #include "BKE_colortools.h"
45 #include "BKE_global.h"
46 #include "BKE_screen.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 "image_intern.h"       // own include
63
64 /* ******************** default callbacks for image space ***************** */
65
66 static SpaceLink *image_new(void)
67 {
68         ARegion *ar;
69         SpaceImage *simage;
70         
71         simage= MEM_callocN(sizeof(SpaceImage), "initimage");
72         simage->spacetype= SPACE_IMAGE;
73         simage->zoom= 1;
74         
75         simage->iuser.ok= 1;
76         simage->iuser.fie_ima= 2;
77         simage->iuser.frames= 100;
78         
79         
80         /* header */
81         ar= MEM_callocN(sizeof(ARegion), "header for image");
82         
83         BLI_addtail(&simage->regionbase, ar);
84         ar->regiontype= RGN_TYPE_HEADER;
85         ar->alignment= RGN_ALIGN_BOTTOM;
86         UI_view2d_header_default(&ar->v2d);
87         
88         /* main area */
89         ar= MEM_callocN(sizeof(ARegion), "main area for image");
90         
91         BLI_addtail(&simage->regionbase, ar);
92         ar->regiontype= RGN_TYPE_WINDOW;
93         
94         ar->v2d.tot.xmin= 0.0f;
95         ar->v2d.tot.ymin= -10.0f;
96         ar->v2d.tot.xmax= 250.0;
97         ar->v2d.tot.ymax= 10.0f;
98         
99         ar->v2d.cur= ar->v2d.tot;
100         
101         ar->v2d.min[0]= 0.01f;
102         ar->v2d.min[1]= 0.01f;
103         
104         ar->v2d.max[0]= MAXFRAMEF;
105         ar->v2d.max[1]= 10000.0f;
106         
107         ar->v2d.scroll= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_BOTTOM);
108         ar->v2d.scroll |= (V2D_SCROLL_LEFT|V2D_SCROLL_SCALE_LEFT);
109         
110         ar->v2d.keeptot= 0;
111         
112         /* channel list region XXX */
113
114         
115         return (SpaceLink *)simage;
116 }
117
118 /* not spacelink itself */
119 static void image_free(SpaceLink *sl)
120 {       
121         SpaceImage *simage= (SpaceImage*) sl;
122         
123         if(simage->cumap)
124                 curvemapping_free(simage->cumap);
125 //      if(simage->gpd)
126 // XXX          free_gpencil_data(simage->gpd);
127         
128 }
129
130
131 /* spacetype; init callback */
132 static void image_init(struct wmWindowManager *wm, ScrArea *sa)
133 {
134
135 }
136
137 static SpaceLink *image_duplicate(SpaceLink *sl)
138 {
139         SpaceImage *simagen= MEM_dupallocN(sl);
140         
141         /* clear or remove stuff from old */
142         
143         return (SpaceLink *)simagen;
144 }
145
146
147
148 /* add handlers, stuff you only do once or on area/region changes */
149 static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
150 {
151         ListBase *keymap;
152         
153         UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
154         
155         /* own keymap */
156         keymap= WM_keymap_listbase(wm, "Image", SPACE_IMAGE, 0);        /* XXX weak? */
157         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
158 }
159
160 static void image_main_area_draw(const bContext *C, ARegion *ar)
161 {
162         /* draw entirely, view changes should be handled here */
163         // SpaceImage *simage= C->area->spacedata.first;
164         View2D *v2d= &ar->v2d;
165         float col[3];
166         
167         /* clear and setup matrix */
168         UI_GetThemeColor3fv(TH_BACK, col);
169         glClearColor(col[0], col[1], col[2], 0.0);
170         glClear(GL_COLOR_BUFFER_BIT);
171         
172         UI_view2d_view_ortho(C, v2d);
173                 
174         /* data... */
175         
176         
177         /* reset view matrix */
178         UI_view2d_view_restore(C);
179         
180         /* scrollers? */
181 }
182
183 void image_operatortypes(void)
184 {
185         
186 }
187
188 void image_keymap(struct wmWindowManager *wm)
189 {
190         
191 }
192
193 /* add handlers, stuff you only do once or on area/region changes */
194 static void image_header_area_init(wmWindowManager *wm, ARegion *ar)
195 {
196         UI_view2d_size_update(&ar->v2d, ar->winx, ar->winy);
197 }
198
199 static void image_header_area_draw(const bContext *C, ARegion *ar)
200 {
201         float col[3];
202         
203         /* clear */
204         if(ED_screen_area_active(C))
205                 UI_GetThemeColor3fv(TH_HEADER, col);
206         else
207                 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
208         
209         glClearColor(col[0], col[1], col[2], 0.0);
210         glClear(GL_COLOR_BUFFER_BIT);
211         
212         /* set view2d view matrix for scrolling (without scrollers) */
213         UI_view2d_view_ortho(C, &ar->v2d);
214         
215         image_header_buttons(C, ar);
216         
217         /* restore view matrix? */
218         UI_view2d_view_restore(C);
219 }
220
221 static void image_main_area_listener(ARegion *ar, wmNotifier *wmn)
222 {
223         /* context changes */
224 }
225
226 /* only called once, from space/spacetypes.c */
227 void ED_spacetype_image(void)
228 {
229         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype image");
230         ARegionType *art;
231         
232         st->spaceid= SPACE_IMAGE;
233         
234         st->new= image_new;
235         st->free= image_free;
236         st->init= image_init;
237         st->duplicate= image_duplicate;
238         st->operatortypes= image_operatortypes;
239         st->keymap= image_keymap;
240         
241         /* regions: main window */
242         art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
243         art->regionid = RGN_TYPE_WINDOW;
244         art->init= image_main_area_init;
245         art->draw= image_main_area_draw;
246         art->listener= image_main_area_listener;
247         art->keymapflag= ED_KEYMAP_VIEW2D;
248
249         BLI_addhead(&st->regiontypes, art);
250         
251         /* regions: header */
252         art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
253         art->regionid = RGN_TYPE_HEADER;
254         art->minsizey= HEADERY;
255         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
256         
257         art->init= image_header_area_init;
258         art->draw= image_header_area_draw;
259         
260         BLI_addhead(&st->regiontypes, art);
261         
262         /* regions: channels */
263         art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
264         art->regionid = RGN_TYPE_CHANNELS;
265         art->minsizex= 80;
266         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
267         
268 //      art->init= image_channel_area_init;
269 //      art->draw= image_channel_area_draw;
270         
271         BLI_addhead(&st->regiontypes, art);
272         
273         
274         BKE_spacetype_register(st);
275 }
276