Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / space_image / space_image.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_image/space_image.c
28  *  \ingroup spimage
29  */
30
31 #include "DNA_gpencil_types.h"
32 #include "DNA_mesh_types.h"
33 #include "DNA_mask_types.h"
34 #include "DNA_meshdata_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_image_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42 #include "BLI_math.h"
43 #include "BLI_threads.h"
44
45 #include "BKE_colortools.h"
46 #include "BKE_context.h"
47 #include "BKE_editmesh.h"
48 #include "BKE_image.h"
49 #include "BKE_layer.h"
50 #include "BKE_library.h"
51 #include "BKE_scene.h"
52 #include "BKE_screen.h"
53 #include "BKE_material.h"
54
55 #include "DEG_depsgraph.h"
56
57 #include "IMB_imbuf_types.h"
58
59 #include "ED_image.h"
60 #include "ED_mask.h"
61 #include "ED_mesh.h"
62 #include "ED_node.h"
63 #include "ED_render.h"
64 #include "ED_space_api.h"
65 #include "ED_screen.h"
66 #include "ED_uvedit.h"
67 #include "ED_transform.h"
68
69 #include "BIF_gl.h"
70
71 #include "RNA_access.h"
72
73 #include "WM_api.h"
74 #include "WM_types.h"
75
76 #include "UI_resources.h"
77 #include "UI_interface.h"
78 #include "UI_view2d.h"
79
80 #include "image_intern.h"
81
82 /**************************** common state *****************************/
83
84 static void image_scopes_tag_refresh(ScrArea *sa)
85 {
86         SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
87         ARegion *ar;
88
89         /* only while histogram is visible */
90         for (ar = sa->regionbase.first; ar; ar = ar->next) {
91                 if (ar->regiontype == RGN_TYPE_TOOLS && ar->flag & RGN_FLAG_HIDDEN)
92                         return;
93         }
94
95         sima->scopes.ok = 0;
96 }
97
98
99 /* ******************** manage regions ********************* */
100
101 ARegion *image_has_buttons_region(ScrArea *sa)
102 {
103         ARegion *ar, *arnew;
104
105         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
106         if (ar) return ar;
107         
108         /* add subdiv level; after header */
109         ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
110
111         /* is error! */
112         if (ar == NULL) return NULL;
113         
114         arnew = MEM_callocN(sizeof(ARegion), "buttons for image");
115         
116         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
117         arnew->regiontype = RGN_TYPE_UI;
118         arnew->alignment = RGN_ALIGN_RIGHT;
119         
120         arnew->flag = RGN_FLAG_HIDDEN;
121         
122         return arnew;
123 }
124
125 ARegion *image_has_tools_region(ScrArea *sa)
126 {
127         ARegion *ar, *arnew;
128
129         ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
130         if (ar) return ar;
131
132         /* add subdiv level; after buttons */
133         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
134
135         /* is error! */
136         if (ar == NULL) return NULL;
137         
138         arnew = MEM_callocN(sizeof(ARegion), "scopes for image");
139         
140         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
141         arnew->regiontype = RGN_TYPE_TOOLS;
142         arnew->alignment = RGN_ALIGN_LEFT;
143         
144         arnew->flag = RGN_FLAG_HIDDEN;
145
146         image_scopes_tag_refresh(sa);
147         
148         return arnew;
149 }
150
151 /* ******************** default callbacks for image space ***************** */
152
153 static SpaceLink *image_new(const bContext *UNUSED(C))
154 {
155         ARegion *ar;
156         SpaceImage *simage;
157         
158         simage = MEM_callocN(sizeof(SpaceImage), "initimage");
159         simage->spacetype = SPACE_IMAGE;
160         simage->zoom = 1.0f;
161         simage->lock = true;
162         simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA;
163
164         simage->iuser.ok = true;
165         simage->iuser.fie_ima = 2;
166         simage->iuser.frames = 100;
167         simage->iuser.flag = IMA_SHOW_STEREO;
168
169         scopes_new(&simage->scopes);
170         simage->sample_line_hist.height = 100;
171
172         /* header */
173         ar = MEM_callocN(sizeof(ARegion), "header for image");
174         
175         BLI_addtail(&simage->regionbase, ar);
176         ar->regiontype = RGN_TYPE_HEADER;
177         ar->alignment = RGN_ALIGN_BOTTOM;
178         
179         /* buttons/list view */
180         ar = MEM_callocN(sizeof(ARegion), "buttons for image");
181         
182         BLI_addtail(&simage->regionbase, ar);
183         ar->regiontype = RGN_TYPE_UI;
184         ar->alignment = RGN_ALIGN_RIGHT;
185         ar->flag = RGN_FLAG_HIDDEN;
186         
187         /* scopes/uv sculpt/paint */
188         ar = MEM_callocN(sizeof(ARegion), "buttons for image");
189         
190         BLI_addtail(&simage->regionbase, ar);
191         ar->regiontype = RGN_TYPE_TOOLS;
192         ar->alignment = RGN_ALIGN_LEFT;
193         ar->flag = RGN_FLAG_HIDDEN;
194
195         /* main area */
196         ar = MEM_callocN(sizeof(ARegion), "main area for image");
197         
198         BLI_addtail(&simage->regionbase, ar);
199         ar->regiontype = RGN_TYPE_WINDOW;
200         
201         return (SpaceLink *)simage;
202 }
203
204 /* not spacelink itself */
205 static void image_free(SpaceLink *sl)
206 {       
207         SpaceImage *simage = (SpaceImage *) sl;
208
209         scopes_free(&simage->scopes);
210 }
211
212
213 /* spacetype; init callback, add handlers */
214 static void image_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
215 {
216         ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
217
218         /* add drop boxes */
219         WM_event_add_dropbox_handler(&sa->handlers, lb);
220         
221 }
222
223 static SpaceLink *image_duplicate(SpaceLink *sl)
224 {
225         SpaceImage *simagen = MEM_dupallocN(sl);
226         
227         /* clear or remove stuff from old */
228
229         scopes_new(&simagen->scopes);
230
231         return (SpaceLink *)simagen;
232 }
233
234 static void image_operatortypes(void)
235 {
236         WM_operatortype_append(IMAGE_OT_view_all);
237         WM_operatortype_append(IMAGE_OT_view_pan);
238         WM_operatortype_append(IMAGE_OT_view_selected);
239         WM_operatortype_append(IMAGE_OT_view_zoom);
240         WM_operatortype_append(IMAGE_OT_view_zoom_in);
241         WM_operatortype_append(IMAGE_OT_view_zoom_out);
242         WM_operatortype_append(IMAGE_OT_view_zoom_ratio);
243         WM_operatortype_append(IMAGE_OT_view_zoom_border);
244 #ifdef WITH_INPUT_NDOF
245         WM_operatortype_append(IMAGE_OT_view_ndof);
246 #endif
247
248         WM_operatortype_append(IMAGE_OT_new);
249         WM_operatortype_append(IMAGE_OT_open);
250         WM_operatortype_append(IMAGE_OT_match_movie_length);
251         WM_operatortype_append(IMAGE_OT_replace);
252         WM_operatortype_append(IMAGE_OT_reload);
253         WM_operatortype_append(IMAGE_OT_save);
254         WM_operatortype_append(IMAGE_OT_save_as);
255         WM_operatortype_append(IMAGE_OT_save_sequence);
256         WM_operatortype_append(IMAGE_OT_pack);
257         WM_operatortype_append(IMAGE_OT_unpack);
258         
259         WM_operatortype_append(IMAGE_OT_invert);
260
261         WM_operatortype_append(IMAGE_OT_cycle_render_slot);
262
263         WM_operatortype_append(IMAGE_OT_sample);
264         WM_operatortype_append(IMAGE_OT_sample_line);
265         WM_operatortype_append(IMAGE_OT_curves_point_set);
266
267         WM_operatortype_append(IMAGE_OT_properties);
268         WM_operatortype_append(IMAGE_OT_toolshelf);
269
270         WM_operatortype_append(IMAGE_OT_change_frame);
271
272         WM_operatortype_append(IMAGE_OT_read_renderlayers);
273         WM_operatortype_append(IMAGE_OT_render_border);
274         WM_operatortype_append(IMAGE_OT_clear_render_border);
275 }
276
277 static void image_keymap(struct wmKeyConfig *keyconf)
278 {
279         wmKeyMap *keymap = WM_keymap_find(keyconf, "Image Generic", SPACE_IMAGE, 0);
280         wmKeyMapItem *kmi;
281         int i;
282         
283         WM_keymap_add_item(keymap, "IMAGE_OT_new", NKEY, KM_PRESS, KM_ALT, 0);
284         WM_keymap_add_item(keymap, "IMAGE_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
285         WM_keymap_add_item(keymap, "IMAGE_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
286         WM_keymap_add_item(keymap, "IMAGE_OT_read_renderlayers", RKEY, KM_PRESS, KM_CTRL, 0);
287         WM_keymap_add_item(keymap, "IMAGE_OT_save", SKEY, KM_PRESS, KM_ALT, 0);
288         WM_keymap_add_item(keymap, "IMAGE_OT_save_as", F3KEY, KM_PRESS, 0, 0);
289         WM_keymap_add_item(keymap, "IMAGE_OT_properties", NKEY, KM_PRESS, 0, 0);
290         WM_keymap_add_item(keymap, "IMAGE_OT_toolshelf", TKEY, KM_PRESS, 0, 0);
291
292         WM_keymap_add_item(keymap, "IMAGE_OT_cycle_render_slot", JKEY, KM_PRESS, 0, 0);
293         RNA_boolean_set(WM_keymap_add_item(keymap, "IMAGE_OT_cycle_render_slot", JKEY, KM_PRESS, KM_ALT, 0)->ptr, "reverse", true);
294         
295         keymap = WM_keymap_find(keyconf, "Image", SPACE_IMAGE, 0);
296         
297         WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
298
299         kmi = WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, KM_SHIFT, 0);
300         RNA_boolean_set(kmi->ptr, "fit_view", true);
301
302         WM_keymap_add_item(keymap, "IMAGE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
303         WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
304         WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
305         WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MOUSEPAN, 0, 0, 0);
306
307 #ifdef WITH_INPUT_NDOF
308         WM_keymap_add_item(keymap, "IMAGE_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); // or view selected?
309         WM_keymap_add_item(keymap, "IMAGE_OT_view_ndof", NDOF_MOTION, 0, 0, 0);
310 #endif
311
312         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
313         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
314         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
315         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0);
316         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
317         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MOUSEZOOM, 0, 0, 0);
318         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MOUSEPAN, 0, KM_CTRL, 0);
319         WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
320
321         /* ctrl now works as well, shift + numpad works as arrow keys on Windows */
322         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 8.0f);
323         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 4.0f);
324         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 2.0f);
325         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
326         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
327         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
328
329         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
330         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
331         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
332         RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
333
334         WM_keymap_add_item(keymap, "IMAGE_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0);
335
336         WM_keymap_add_item(keymap, "IMAGE_OT_sample", ACTIONMOUSE, KM_PRESS, 0, 0);
337         RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_curves_point_set", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "point", 0);
338         RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_curves_point_set", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "point", 1);
339
340         /* toggle editmode is handy to have while UV unwrapping */
341         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
342         RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
343         RNA_boolean_set(kmi->ptr, "toggle", true);
344
345         /* fast switch to render slots */
346         for (i = 0; i < MIN2(IMA_MAX_RENDER_SLOT, 9); i++) {
347                 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_int", ONEKEY + i, KM_PRESS, 0, 0);
348                 RNA_string_set(kmi->ptr, "data_path", "space_data.image.render_slots.active_index");
349                 RNA_int_set(kmi->ptr, "value", i);
350         }
351
352         /* pivot */
353         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0);
354         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
355         RNA_string_set(kmi->ptr, "value", "CENTER");
356
357         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0);
358         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
359         RNA_string_set(kmi->ptr, "value", "MEDIAN");
360
361         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0);
362         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
363         RNA_string_set(kmi->ptr, "value", "CURSOR");
364
365         /* render border */
366         WM_keymap_add_item(keymap, "IMAGE_OT_render_border", BKEY, KM_PRESS, KM_CTRL, 0);
367         WM_keymap_add_item(keymap, "IMAGE_OT_clear_render_border", BKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
368 }
369
370 /* dropboxes */
371 static int image_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
372 {
373         if (drag->type == WM_DRAG_PATH)
374                 if (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE, ICON_FILE_BLANK)) /* rule might not work? */
375                         return 1;
376         return 0;
377 }
378
379 static void image_drop_copy(wmDrag *drag, wmDropBox *drop)
380 {
381         /* copy drag path to properties */
382         RNA_string_set(drop->ptr, "filepath", drag->path);
383 }
384
385 /* area+region dropbox definition */
386 static void image_dropboxes(void)
387 {
388         ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
389         
390         WM_dropbox_add(lb, "IMAGE_OT_open", image_drop_poll, image_drop_copy);
391 }
392
393 /**
394  * \note take care not to get into feedback loop here,
395  *       calling composite job causes viewer to refresh.
396  */
397 static void image_refresh(const bContext *C, ScrArea *sa)
398 {
399         Scene *scene = CTX_data_scene(C);
400         SpaceImage *sima = sa->spacedata.first;
401         Object *obedit = CTX_data_edit_object(C);
402         Image *ima;
403
404         ima = ED_space_image(sima);
405
406         BKE_image_user_check_frame_calc(&sima->iuser, scene->r.cfra, 0);
407         
408         /* check if we have to set the image from the editmesh */
409         if (ima && (ima->source == IMA_SRC_VIEWER && sima->mode == SI_MODE_MASK)) {
410                 if (scene->nodetree) {
411                         Mask *mask = ED_space_image_get_mask(sima);
412                         if (mask) {
413                                 ED_node_composite_job(C, scene->nodetree, scene);
414                         }
415                 }
416         }
417         else if (ima && (ima->source == IMA_SRC_VIEWER || sima->pin)) {
418                 /* pass */
419         }
420         else if (obedit && obedit->type == OB_MESH) {
421                 Mesh *me = (Mesh *)obedit->data;
422                 struct BMEditMesh *em = me->edit_btmesh;
423                 bool sloppy = true; /* partially selected face is ok */
424                 bool selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* only selected active face? */
425
426                 if (BKE_scene_use_new_shading_nodes(scene)) {
427                         /* new shading system does not alter image */
428                 }
429                 else {
430                         /* old shading system, we set texface */
431                         if (em && EDBM_uv_check(em)) {
432                                 BMFace *efa = BM_mesh_active_face_get(em->bm, sloppy, selected);
433
434                                 if (efa) {
435                                         /* don't need to check for pin here, see above */
436                                         Image *image = BKE_object_material_edit_image_get(obedit, efa->mat_nr);
437
438                                         sima->image = image;
439                                 }
440                         }
441                 }
442         }
443 }
444
445 static void image_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *scene,
446                            WorkSpace *workspace)
447 {
448         SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
449         
450         /* context changes */
451         switch (wmn->category) {
452                 case NC_WINDOW:
453                         /* notifier comes from editing color space */
454                         image_scopes_tag_refresh(sa);
455                         ED_area_tag_redraw(sa);
456                         break;
457                 case NC_SCENE:
458                         switch (wmn->data) {
459                                 case ND_FRAME:
460                                         image_scopes_tag_refresh(sa);
461                                         ED_area_tag_refresh(sa);
462                                         ED_area_tag_redraw(sa);
463                                         break;
464                                 case ND_MODE:
465                                         if (wmn->subtype == NS_EDITMODE_MESH)
466                                                 ED_area_tag_refresh(sa);
467                                         ED_area_tag_redraw(sa);
468                                         break;
469                                 case ND_RENDER_RESULT:
470                                 case ND_RENDER_OPTIONS:
471                                 case ND_COMPO_RESULT:
472                                         if (ED_space_image_show_render(sima))
473                                                 image_scopes_tag_refresh(sa);
474                                         ED_area_tag_redraw(sa);
475                                         break;
476                         }
477                         break;
478                 case NC_IMAGE:
479                         if (wmn->reference == sima->image || !wmn->reference) {
480                                 if (wmn->action != NA_PAINTING) {
481                                         image_scopes_tag_refresh(sa);
482                                         ED_area_tag_refresh(sa);
483                                         ED_area_tag_redraw(sa);
484                                 }
485                         }
486                         break;
487                 case NC_SPACE:
488                         if (wmn->data == ND_SPACE_IMAGE) {
489                                 image_scopes_tag_refresh(sa);
490                                 ED_area_tag_redraw(sa);
491                         }
492                         break;
493                 case NC_MASK:
494                 {
495                         // Scene *scene = wmn->window->screen->scene;
496                         /* ideally would check for: ED_space_image_check_show_maskedit(scene, sima) but we cant get the scene */
497                         if (sima->mode == SI_MODE_MASK) {
498                                 switch (wmn->data) {
499                                         case ND_SELECT:
500                                                 ED_area_tag_redraw(sa);
501                                                 break;
502                                         case ND_DATA:
503                                         case ND_DRAW:
504                                                 /* causes node-recalc */
505                                                 ED_area_tag_redraw(sa);
506                                                 ED_area_tag_refresh(sa);
507                                                 break;
508                                 }
509                                 switch (wmn->action) {
510                                         case NA_SELECTED:
511                                                 ED_area_tag_redraw(sa);
512                                                 break;
513                                         case NA_EDITED:
514                                                 /* causes node-recalc */
515                                                 ED_area_tag_redraw(sa);
516                                                 ED_area_tag_refresh(sa);
517                                                 break;
518                                 }
519                         }
520                         break;
521                 }
522                 case NC_GEOM:
523                 {
524                         switch (wmn->data) {
525                                 case ND_DATA:
526                                 case ND_SELECT:
527                                         image_scopes_tag_refresh(sa);
528                                         ED_area_tag_refresh(sa);
529                                         ED_area_tag_redraw(sa);
530                                         break;
531                         }
532                         break;
533                 }
534                 case NC_OBJECT:
535                 {
536                         switch (wmn->data) {
537                                 case ND_TRANSFORM:
538                                 case ND_MODIFIER:
539                                 {
540                                         SceneLayer *sl = BKE_scene_layer_from_workspace_get(scene, workspace);
541                                         Object *ob = OBACT(sl);
542                                         if (ob && (ob == wmn->reference) && (ob->mode & OB_MODE_EDIT)) {
543                                                 if (sima->lock && (sima->flag & SI_DRAWSHADOW)) {
544                                                         ED_area_tag_refresh(sa);
545                                                         ED_area_tag_redraw(sa);
546                                                 }
547                                         }
548                                         break;
549                                 }
550                         }
551
552                         break;
553                 }
554                 case NC_ID:
555                 {
556                         if (wmn->action == NA_RENAME) {
557                                 ED_area_tag_redraw(sa);
558                         }
559                         break;
560                 }
561                 case NC_WM:
562                         if (wmn->data == ND_UNDO) {
563                                 ED_area_tag_redraw(sa);
564                                 ED_area_tag_refresh(sa);
565                         }
566                         break;
567         }
568 }
569
570 const char *image_context_dir[] = {"edit_image", "edit_mask", NULL};
571
572 static int image_context(const bContext *C, const char *member, bContextDataResult *result)
573 {
574         SpaceImage *sima = CTX_wm_space_image(C);
575
576         if (CTX_data_dir(member)) {
577                 CTX_data_dir_set(result, image_context_dir);
578         }
579         else if (CTX_data_equals(member, "edit_image")) {
580                 CTX_data_id_pointer_set(result, (ID *)ED_space_image(sima));
581                 return 1;
582         }
583         else if (CTX_data_equals(member, "edit_mask")) {
584                 Mask *mask = ED_space_image_get_mask(sima);
585                 if (mask) {
586                         CTX_data_id_pointer_set(result, &mask->id);
587                 }
588                 return true;
589         }
590         return 0;
591 }
592
593 static void IMAGE_WGT_manipulator2d(wmManipulatorGroupType *wgt)
594 {
595         wgt->name = "UV Transform Manipulator";
596         wgt->idname = "IMAGE_WGT_manipulator2d";
597
598         wgt->flag |= WM_MANIPULATORGROUPTYPE_PERSISTENT;
599
600         wgt->poll = ED_widgetgroup_manipulator2d_poll;
601         wgt->setup = ED_widgetgroup_manipulator2d_setup;
602         wgt->refresh = ED_widgetgroup_manipulator2d_refresh;
603         wgt->draw_prepare = ED_widgetgroup_manipulator2d_draw_prepare;
604 }
605
606 static void image_widgets(void)
607 {
608         wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(
609                 &(const struct wmManipulatorMapType_Params){SPACE_IMAGE, RGN_TYPE_WINDOW});
610
611         WM_manipulatorgrouptype_append_and_link(mmap_type, IMAGE_WGT_manipulator2d);
612 }
613
614 /************************** main region ***************************/
615
616 /* sets up the fields of the View2D from zoom and offset */
617 static void image_main_region_set_view2d(SpaceImage *sima, ARegion *ar)
618 {
619         Image *ima = ED_space_image(sima);
620         float x1, y1, w, h;
621         int width, height, winx, winy;
622         
623 #if 0
624         if (image_preview_active(curarea, &width, &height)) {}
625         else
626 #endif
627         ED_space_image_get_size(sima, &width, &height);
628
629         w = width;
630         h = height;
631         
632         if (ima)
633                 h *= ima->aspy / ima->aspx;
634
635         winx = BLI_rcti_size_x(&ar->winrct) + 1;
636         winy = BLI_rcti_size_y(&ar->winrct) + 1;
637                 
638         ar->v2d.tot.xmin = 0;
639         ar->v2d.tot.ymin = 0;
640         ar->v2d.tot.xmax = w;
641         ar->v2d.tot.ymax = h;
642         
643         ar->v2d.mask.xmin = ar->v2d.mask.ymin = 0;
644         ar->v2d.mask.xmax = winx;
645         ar->v2d.mask.ymax = winy;
646
647         /* which part of the image space do we see? */
648         x1 = ar->winrct.xmin + (winx - sima->zoom * w) / 2.0f;
649         y1 = ar->winrct.ymin + (winy - sima->zoom * h) / 2.0f;
650
651         x1 -= sima->zoom * sima->xof;
652         y1 -= sima->zoom * sima->yof;
653         
654         /* relative display right */
655         ar->v2d.cur.xmin = ((ar->winrct.xmin - (float)x1) / sima->zoom);
656         ar->v2d.cur.xmax = ar->v2d.cur.xmin + ((float)winx / sima->zoom);
657         
658         /* relative display left */
659         ar->v2d.cur.ymin = ((ar->winrct.ymin - (float)y1) / sima->zoom);
660         ar->v2d.cur.ymax = ar->v2d.cur.ymin + ((float)winy / sima->zoom);
661         
662         /* normalize 0.0..1.0 */
663         ar->v2d.cur.xmin /= w;
664         ar->v2d.cur.xmax /= w;
665         ar->v2d.cur.ymin /= h;
666         ar->v2d.cur.ymax /= h;
667 }
668
669 /* add handlers, stuff you only do once or on area/region changes */
670 static void image_main_region_init(wmWindowManager *wm, ARegion *ar)
671 {
672         wmKeyMap *keymap;
673         
674         // image space manages own v2d
675         // UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
676
677         /* manipulators */
678         if (ar->manipulator_map == NULL) {
679                 const struct wmManipulatorMapType_Params wmap_params = {
680                         .spaceid = SPACE_IMAGE,
681                         .regionid = RGN_TYPE_WINDOW,
682                 };
683                 ar->manipulator_map = WM_manipulatormap_new_from_type(&wmap_params);
684         }
685         WM_manipulatormap_add_handlers(ar, ar->manipulator_map);
686
687         /* mask polls mode */
688         keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
689         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
690
691         /* image paint polls for mode */
692         keymap = WM_keymap_find(wm->defaultconf, "Curve", 0, 0);
693         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
694
695         keymap = WM_keymap_find(wm->defaultconf, "Paint Curve", 0, 0);
696         WM_event_add_keymap_handler(&ar->handlers, keymap);
697
698         keymap = WM_keymap_find(wm->defaultconf, "Image Paint", 0, 0);
699         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
700
701         keymap = WM_keymap_find(wm->defaultconf, "UV Editor", 0, 0);
702         WM_event_add_keymap_handler(&ar->handlers, keymap);
703         
704         keymap = WM_keymap_find(wm->defaultconf, "UV Sculpt", 0, 0);
705         WM_event_add_keymap_handler(&ar->handlers, keymap);
706
707         /* own keymaps */
708         keymap = WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
709         WM_event_add_keymap_handler(&ar->handlers, keymap);
710         keymap = WM_keymap_find(wm->defaultconf, "Image", SPACE_IMAGE, 0);
711         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
712 }
713
714 static void image_main_region_draw(const bContext *C, ARegion *ar)
715 {
716         /* draw entirely, view changes should be handled here */
717         SpaceImage *sima = CTX_wm_space_image(C);
718         Object *obact = CTX_data_active_object(C);
719         Object *obedit = CTX_data_edit_object(C);
720         Depsgraph *depsgraph = CTX_data_depsgraph(C);
721         Mask *mask = NULL;
722         bool curve = false;
723         Scene *scene = CTX_data_scene(C);
724         SceneLayer *sl = CTX_data_scene_layer(C);
725         View2D *v2d = &ar->v2d;
726         //View2DScrollers *scrollers;
727         float col[3];
728
729         /* XXX not supported yet, disabling for now */
730         scene->r.scemode &= ~R_COMP_CROP;
731         
732         /* clear and setup matrix */
733         UI_GetThemeColor3fv(TH_BACK, col);
734         glClearColor(col[0], col[1], col[2], 0.0);
735         glClear(GL_COLOR_BUFFER_BIT);
736
737         /* put scene context variable in iuser */
738         if (sima->image && sima->image->type == IMA_TYPE_R_RESULT) {
739                 /* for render result, try to use the currently rendering scene */
740                 Scene *render_scene = ED_render_job_get_current_scene(C);
741                 if (render_scene)
742                         sima->iuser.scene = render_scene;
743                 else
744                         sima->iuser.scene = scene;
745         }
746         else
747                 sima->iuser.scene = scene;
748
749         /* we set view2d from own zoom and offset each time */
750         image_main_region_set_view2d(sima, ar);
751
752         /* we draw image in pixelspace */
753         draw_image_main(C, ar);
754
755         /* and uvs in 0.0-1.0 space */
756         UI_view2d_view_ortho(v2d);
757
758         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
759
760         ED_uvedit_draw_main(sima, ar, scene, sl, obedit, obact, depsgraph);
761
762         /* check for mask (delay draw) */
763         if (ED_space_image_show_uvedit(sima, obedit)) {
764                 /* pass */
765         }
766         else if (sima->mode == SI_MODE_MASK) {
767                 mask = ED_space_image_get_mask(sima);
768         }
769         else if (ED_space_image_paint_curve(C)) {
770                 curve = true;
771         }
772
773         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
774
775         if (sima->flag & SI_SHOW_GPENCIL) {
776                 /* Grease Pencil too (in addition to UV's) */
777                 draw_image_grease_pencil((bContext *)C, true);
778         }
779
780         /* sample line */
781         draw_image_sample_line(sima);
782
783         UI_view2d_view_restore(C);
784
785         if (sima->flag & SI_SHOW_GPENCIL) {
786                 /* draw Grease Pencil - screen space only */
787                 draw_image_grease_pencil((bContext *)C, false);
788         }
789
790         if (mask) {
791                 Image *image = ED_space_image(sima);
792                 int width, height, show_viewer;
793                 float aspx, aspy;
794
795                 show_viewer = (image && image->source == IMA_SRC_VIEWER);
796
797                 if (show_viewer) {
798                         /* ED_space_image_get* will acquire image buffer which requires
799                          * lock here by the same reason why lock is needed in draw_image_main
800                          */
801                         BLI_lock_thread(LOCK_DRAW_IMAGE);
802                 }
803
804                 ED_space_image_get_size(sima, &width, &height);
805                 ED_space_image_get_aspect(sima, &aspx, &aspy);
806
807                 if (show_viewer)
808                         BLI_unlock_thread(LOCK_DRAW_IMAGE);
809
810                 ED_mask_draw_region(mask, ar,
811                                     sima->mask_info.draw_flag,
812                                     sima->mask_info.draw_type,
813                                     sima->mask_info.overlay_mode,
814                                     width, height,
815                                     aspx, aspy,
816                                     true, false,
817                                     NULL, C);
818
819                 UI_view2d_view_ortho(v2d);
820                 ED_image_draw_cursor(ar, sima->cursor);
821                 UI_view2d_view_restore(C);
822         }
823         else if (curve) {
824                 UI_view2d_view_ortho(v2d);
825                 ED_image_draw_cursor(ar, sima->cursor);
826                 UI_view2d_view_restore(C);
827         }
828
829         WM_manipulatormap_draw(ar->manipulator_map, C, WM_MANIPULATORMAP_DRAWSTEP_2D);
830
831         draw_image_cache(C, ar);
832
833         /* scrollers? */
834 #if 0
835         scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
836         UI_view2d_scrollers_draw(C, v2d, scrollers);
837         UI_view2d_scrollers_free(scrollers);
838 #endif
839 }
840
841 static void image_main_region_listener(
842         bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar,
843         wmNotifier *wmn, const Scene *UNUSED(scene))
844 {
845         /* context changes */
846         switch (wmn->category) {
847                 case NC_GEOM:
848                         if (ELEM(wmn->data, ND_DATA, ND_SELECT))
849                                 WM_manipulatormap_tag_refresh(ar->manipulator_map);
850                         break;
851                 case NC_GPENCIL:
852                         if (ELEM(wmn->action, NA_EDITED, NA_SELECTED))
853                                 ED_region_tag_redraw(ar);
854                         else if (wmn->data & ND_GPENCIL_EDITMODE)
855                                 ED_region_tag_redraw(ar);
856                         break;
857                 case NC_IMAGE:
858                         if (wmn->action == NA_PAINTING)
859                                 ED_region_tag_redraw(ar);
860                         WM_manipulatormap_tag_refresh(ar->manipulator_map);
861                         break;
862                 case NC_MATERIAL:
863                         if (wmn->data == ND_SHADING_LINKS) {
864                                 SpaceImage *sima = sa->spacedata.first;
865
866                                 if (sima->iuser.scene && (sima->iuser.scene->toolsettings->uv_flag & UV_SHOW_SAME_IMAGE))
867                                         ED_region_tag_redraw(ar);
868                         }
869                         break;
870                 case NC_SCREEN:
871                         if (ELEM(wmn->data, ND_LAYER)) {
872                                 ED_region_tag_redraw(ar);
873                         }
874                         break;
875         }
876 }
877
878 /* *********************** buttons region ************************ */
879
880 /* add handlers, stuff you only do once or on area/region changes */
881 static void image_buttons_region_init(wmWindowManager *wm, ARegion *ar)
882 {
883         wmKeyMap *keymap;
884
885         ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
886         ED_region_panels_init(wm, ar);
887         
888         keymap = WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
889         WM_event_add_keymap_handler(&ar->handlers, keymap);
890 }
891
892 static void image_buttons_region_draw(const bContext *C, ARegion *ar)
893 {
894         ED_region_panels(C, ar, NULL, -1, true);
895 }
896
897 static void image_buttons_region_listener(
898         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
899         wmNotifier *wmn, const Scene *UNUSED(scene))
900 {
901         /* context changes */
902         switch (wmn->category) {
903                 case NC_TEXTURE:
904                 case NC_MATERIAL:
905                         /* sending by texture render job and needed to properly update displaying
906                          * brush texture icon */
907                         ED_region_tag_redraw(ar);
908                         break;
909                 case NC_SCENE:
910                         switch (wmn->data) {
911                                 case ND_MODE:
912                                 case ND_RENDER_RESULT:
913                                 case ND_COMPO_RESULT:
914                                         ED_region_tag_redraw(ar);
915                                         break;
916                         }
917                         break;
918                 case NC_IMAGE:
919                         if (wmn->action != NA_PAINTING)
920                                 ED_region_tag_redraw(ar);
921                         break;
922                 case NC_NODE:
923                         ED_region_tag_redraw(ar);
924                         break;
925                 case NC_GPENCIL:
926                         if (ELEM(wmn->action, NA_EDITED, NA_SELECTED))
927                                 ED_region_tag_redraw(ar);
928                         break;
929         }
930 }
931
932 /* *********************** scopes region ************************ */
933
934 /* add handlers, stuff you only do once or on area/region changes */
935 static void image_tools_region_init(wmWindowManager *wm, ARegion *ar)
936 {
937         wmKeyMap *keymap;
938         
939         ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE;
940         ED_region_panels_init(wm, ar);
941         
942         keymap = WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
943         WM_event_add_keymap_handler(&ar->handlers, keymap);
944 }
945
946 static void image_tools_region_draw(const bContext *C, ARegion *ar)
947 {
948         SpaceImage *sima = CTX_wm_space_image(C);
949         Scene *scene = CTX_data_scene(C);
950         void *lock;
951         ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
952         /* XXX performance regression if name of scopes category changes! */
953         PanelCategoryStack *category = UI_panel_category_active_find(ar, "Scopes");
954
955         /* only update scopes if scope category is active */
956         if (category) {
957                 if (ibuf) {
958                         if (!sima->scopes.ok) {
959                                 BKE_histogram_update_sample_line(&sima->sample_line_hist, ibuf, &scene->view_settings, &scene->display_settings);
960                         }
961                         if (sima->image->flag & IMA_VIEW_AS_RENDER)
962                                 ED_space_image_scopes_update(C, sima, ibuf, true);
963                         else
964                                 ED_space_image_scopes_update(C, sima, ibuf, false);
965                 }
966         }
967         ED_space_image_release_buffer(sima, ibuf, lock);
968         
969         ED_region_panels(C, ar, NULL, -1, true);
970 }
971
972 static void image_tools_region_listener(
973         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
974         wmNotifier *wmn, const Scene *UNUSED(scene))
975 {
976         /* context changes */
977         switch (wmn->category) {
978                 case NC_GPENCIL:
979                         if (wmn->data == ND_DATA || ELEM(wmn->action, NA_EDITED, NA_SELECTED))
980                                 ED_region_tag_redraw(ar);
981                         break;
982                 case NC_BRUSH:
983                         /* NA_SELECTED is used on brush changes */
984                         if (ELEM(wmn->action, NA_EDITED, NA_SELECTED))
985                                 ED_region_tag_redraw(ar);
986                         break;
987                 case NC_SCENE:
988                         switch (wmn->data) {
989                                 case ND_MODE:
990                                 case ND_RENDER_RESULT:
991                                 case ND_COMPO_RESULT:
992                                         ED_region_tag_redraw(ar);
993                                         break;
994                         }
995                         break;
996                 case NC_IMAGE:
997                         if (wmn->action != NA_PAINTING)
998                                 ED_region_tag_redraw(ar);
999                         break;
1000                 case NC_NODE:
1001                         ED_region_tag_redraw(ar);
1002                         break;
1003                         
1004         }
1005 }
1006
1007 /************************* header region **************************/
1008
1009 /* add handlers, stuff you only do once or on area/region changes */
1010 static void image_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
1011 {
1012         ED_region_header_init(ar);
1013 }
1014
1015 static void image_header_region_draw(const bContext *C, ARegion *ar)
1016 {
1017         ED_region_header(C, ar);
1018 }
1019
1020 static void image_header_region_listener(
1021         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
1022         wmNotifier *wmn, const Scene *UNUSED(scene))
1023 {
1024         /* context changes */
1025         switch (wmn->category) {
1026                 case NC_SCENE:
1027                         switch (wmn->data) {
1028                                 case ND_MODE:
1029                                 case ND_TOOLSETTINGS:
1030                                         ED_region_tag_redraw(ar);
1031                                         break;
1032                         }
1033                         break;
1034                 case NC_GEOM:
1035                         switch (wmn->data) {
1036                                 case ND_DATA:
1037                                 case ND_SELECT:
1038                                         ED_region_tag_redraw(ar);
1039                                         break;
1040                         }
1041                         break;
1042         }
1043 }
1044
1045 static void image_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
1046 {
1047         SpaceImage *simg = (SpaceImage *)slink;
1048
1049         if (!ELEM(GS(old_id->name), ID_IM, ID_GD, ID_MSK)) {
1050                 return;
1051         }
1052
1053         if ((ID *)simg->image == old_id) {
1054                 simg->image = (Image *)new_id;
1055                 id_us_ensure_real(new_id);
1056         }
1057
1058         if ((ID *)simg->gpd == old_id) {
1059                 simg->gpd = (bGPdata *)new_id;
1060                 id_us_min(old_id);
1061                 id_us_plus(new_id);
1062         }
1063
1064         if ((ID *)simg->mask_info.mask == old_id) {
1065                 simg->mask_info.mask = (Mask *)new_id;
1066                 id_us_ensure_real(new_id);
1067         }
1068 }
1069
1070 /**************************** spacetype *****************************/
1071
1072 /* only called once, from space/spacetypes.c */
1073 void ED_spacetype_image(void)
1074 {
1075         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype image");
1076         ARegionType *art;
1077         
1078         st->spaceid = SPACE_IMAGE;
1079         strncpy(st->name, "Image", BKE_ST_MAXNAME);
1080         
1081         st->new = image_new;
1082         st->free = image_free;
1083         st->init = image_init;
1084         st->duplicate = image_duplicate;
1085         st->operatortypes = image_operatortypes;
1086         st->keymap = image_keymap;
1087         st->dropboxes = image_dropboxes;
1088         st->refresh = image_refresh;
1089         st->listener = image_listener;
1090         st->context = image_context;
1091         st->manipulators = image_widgets;
1092         st->id_remap = image_id_remap;
1093
1094         /* regions: main window */
1095         art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
1096         art->regionid = RGN_TYPE_WINDOW;
1097         art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL;
1098         art->init = image_main_region_init;
1099         art->draw = image_main_region_draw;
1100         art->listener = image_main_region_listener;
1101
1102         BLI_addhead(&st->regiontypes, art);
1103         
1104         /* regions: listview/buttons */
1105         art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
1106         art->regionid = RGN_TYPE_UI;
1107         art->prefsizex = 220; // XXX
1108         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
1109         art->listener = image_buttons_region_listener;
1110         art->init = image_buttons_region_init;
1111         art->draw = image_buttons_region_draw;
1112         BLI_addhead(&st->regiontypes, art);
1113
1114         ED_uvedit_buttons_register(art);
1115         image_buttons_register(art);
1116
1117         /* regions: statistics/scope buttons */
1118         art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
1119         art->regionid = RGN_TYPE_TOOLS;
1120         art->prefsizex = 220; // XXX
1121         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
1122         art->listener = image_tools_region_listener;
1123         art->init = image_tools_region_init;
1124         art->draw = image_tools_region_draw;
1125         BLI_addhead(&st->regiontypes, art);
1126
1127         /* regions: header */
1128         art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
1129         art->regionid = RGN_TYPE_HEADER;
1130         art->prefsizey = HEADERY;
1131         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
1132         art->listener = image_header_region_listener;
1133         art->init = image_header_region_init;
1134         art->draw = image_header_region_draw;
1135         
1136         BLI_addhead(&st->regiontypes, art);
1137         
1138         BKE_spacetype_register(st);
1139 }
1140