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