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_context.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         
87         /* main area */
88         ar= MEM_callocN(sizeof(ARegion), "main area for image");
89         
90         BLI_addtail(&simage->regionbase, ar);
91         ar->regiontype= RGN_TYPE_WINDOW;
92         
93         /* channel list region XXX */
94
95         
96         return (SpaceLink *)simage;
97 }
98
99 /* not spacelink itself */
100 static void image_free(SpaceLink *sl)
101 {       
102         SpaceImage *simage= (SpaceImage*) sl;
103         
104         if(simage->cumap)
105                 curvemapping_free(simage->cumap);
106 //      if(simage->gpd)
107 // XXX          free_gpencil_data(simage->gpd);
108         
109 }
110
111
112 /* spacetype; init callback */
113 static void image_init(struct wmWindowManager *wm, ScrArea *sa)
114 {
115
116 }
117
118 static SpaceLink *image_duplicate(SpaceLink *sl)
119 {
120         SpaceImage *simagen= MEM_dupallocN(sl);
121         
122         /* clear or remove stuff from old */
123         if(simagen->cumap)
124                 simagen->cumap= curvemapping_copy(simagen->cumap);
125         
126         return (SpaceLink *)simagen;
127 }
128
129
130
131 /* add handlers, stuff you only do once or on area/region changes */
132 static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
133 {
134         ListBase *keymap;
135         
136         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
137         
138         /* own keymap */
139         keymap= WM_keymap_listbase(wm, "Image", SPACE_IMAGE, 0);        /* XXX weak? */
140         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
141 }
142
143 static void image_main_area_draw(const bContext *C, ARegion *ar)
144 {
145         /* draw entirely, view changes should be handled here */
146         // SpaceImage *simage= (SpaceImage*)CTX_wm_space_data(C);
147         View2D *v2d= &ar->v2d;
148         float col[3];
149         
150         /* clear and setup matrix */
151         UI_GetThemeColor3fv(TH_BACK, col);
152         glClearColor(col[0], col[1], col[2], 0.0);
153         glClear(GL_COLOR_BUFFER_BIT);
154         
155         UI_view2d_view_ortho(C, v2d);
156                 
157         /* data... */
158         
159         
160         /* reset view matrix */
161         UI_view2d_view_restore(C);
162         
163         /* scrollers? */
164 }
165
166 void image_operatortypes(void)
167 {
168         
169 }
170
171 void image_keymap(struct wmWindowManager *wm)
172 {
173         
174 }
175
176 /* add handlers, stuff you only do once or on area/region changes */
177 static void image_header_area_init(wmWindowManager *wm, ARegion *ar)
178 {
179         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
180 }
181
182 static void image_header_area_draw(const bContext *C, ARegion *ar)
183 {
184         float col[3];
185         
186         /* clear */
187         if(ED_screen_area_active(C))
188                 UI_GetThemeColor3fv(TH_HEADER, col);
189         else
190                 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
191         
192         glClearColor(col[0], col[1], col[2], 0.0);
193         glClear(GL_COLOR_BUFFER_BIT);
194         
195         /* set view2d view matrix for scrolling (without scrollers) */
196         UI_view2d_view_ortho(C, &ar->v2d);
197         
198         image_header_buttons(C, ar);
199         
200         /* restore view matrix? */
201         UI_view2d_view_restore(C);
202 }
203
204 static void image_main_area_listener(ARegion *ar, wmNotifier *wmn)
205 {
206         /* context changes */
207 }
208
209 /* only called once, from space/spacetypes.c */
210 void ED_spacetype_image(void)
211 {
212         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype image");
213         ARegionType *art;
214         
215         st->spaceid= SPACE_IMAGE;
216         
217         st->new= image_new;
218         st->free= image_free;
219         st->init= image_init;
220         st->duplicate= image_duplicate;
221         st->operatortypes= image_operatortypes;
222         st->keymap= image_keymap;
223         
224         /* regions: main window */
225         art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
226         art->regionid = RGN_TYPE_WINDOW;
227         art->init= image_main_area_init;
228         art->draw= image_main_area_draw;
229         art->listener= image_main_area_listener;
230         art->keymapflag= ED_KEYMAP_VIEW2D;
231
232         BLI_addhead(&st->regiontypes, art);
233         
234         /* regions: header */
235         art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
236         art->regionid = RGN_TYPE_HEADER;
237         art->minsizey= HEADERY;
238         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
239         
240         art->init= image_header_area_init;
241         art->draw= image_header_area_draw;
242         
243         BLI_addhead(&st->regiontypes, art);
244         
245         /* regions: channels */
246         art= MEM_callocN(sizeof(ARegionType), "spacetype image region");
247         art->regionid = RGN_TYPE_CHANNELS;
248         art->minsizex= 80;
249         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
250         
251 //      art->init= image_channel_area_init;
252 //      art->draw= image_channel_area_draw;
253         
254         BLI_addhead(&st->regiontypes, art);
255         
256         
257         BKE_spacetype_register(st);
258 }
259