2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2008 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/editors/space_image/space_image.c
31 #include "DNA_mesh_types.h"
32 #include "DNA_mask_types.h"
33 #include "DNA_meshdata_types.h"
34 #include "DNA_object_types.h"
35 #include "DNA_scene_types.h"
37 #include "MEM_guardedalloc.h"
39 #include "BLI_blenlib.h"
42 #include "BKE_colortools.h"
43 #include "BKE_context.h"
44 #include "BKE_image.h"
45 #include "BKE_global.h"
46 #include "BKE_scene.h"
47 #include "BKE_screen.h"
48 #include "BKE_tessmesh.h"
49 #include "BKE_sequencer.h"
52 #include "IMB_imbuf_types.h"
58 #include "ED_space_api.h"
59 #include "ED_screen.h"
60 #include "ED_uvedit.h"
64 #include "RNA_access.h"
69 #include "UI_resources.h"
70 #include "UI_view2d.h"
72 #include "image_intern.h"
74 /**************************** common state *****************************/
76 static void image_scopes_tag_refresh(ScrArea *sa)
78 SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
81 /* only while histogram is visible */
82 for (ar = sa->regionbase.first; ar; ar = ar->next) {
83 if (ar->regiontype == RGN_TYPE_PREVIEW && ar->flag & RGN_FLAG_HIDDEN)
91 /* ******************** manage regions ********************* */
93 ARegion *image_has_buttons_region(ScrArea *sa)
97 ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
100 /* add subdiv level; after header */
101 ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
104 if (ar == NULL) return NULL;
106 arnew = MEM_callocN(sizeof(ARegion), "buttons for image");
108 BLI_insertlinkafter(&sa->regionbase, ar, arnew);
109 arnew->regiontype = RGN_TYPE_UI;
110 arnew->alignment = RGN_ALIGN_LEFT;
112 arnew->flag = RGN_FLAG_HIDDEN;
117 ARegion *image_has_scope_region(ScrArea *sa)
121 ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW);
124 /* add subdiv level; after buttons */
125 ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
128 if (ar == NULL) return NULL;
130 arnew = MEM_callocN(sizeof(ARegion), "scopes for image");
132 BLI_insertlinkafter(&sa->regionbase, ar, arnew);
133 arnew->regiontype = RGN_TYPE_PREVIEW;
134 arnew->alignment = RGN_ALIGN_RIGHT;
136 arnew->flag = RGN_FLAG_HIDDEN;
138 image_scopes_tag_refresh(sa);
143 /* ******************** default callbacks for image space ***************** */
145 static SpaceLink *image_new(const bContext *UNUSED(C))
150 simage = MEM_callocN(sizeof(SpaceImage), "initimage");
151 simage->spacetype = SPACE_IMAGE;
155 simage->iuser.ok = TRUE;
156 simage->iuser.fie_ima = 2;
157 simage->iuser.frames = 100;
159 scopes_new(&simage->scopes);
160 simage->sample_line_hist.height = 100;
163 ar = MEM_callocN(sizeof(ARegion), "header for image");
165 BLI_addtail(&simage->regionbase, ar);
166 ar->regiontype = RGN_TYPE_HEADER;
167 ar->alignment = RGN_ALIGN_BOTTOM;
169 /* buttons/list view */
170 ar = MEM_callocN(sizeof(ARegion), "buttons for image");
172 BLI_addtail(&simage->regionbase, ar);
173 ar->regiontype = RGN_TYPE_UI;
174 ar->alignment = RGN_ALIGN_LEFT;
175 ar->flag = RGN_FLAG_HIDDEN;
178 ar = MEM_callocN(sizeof(ARegion), "buttons for image");
180 BLI_addtail(&simage->regionbase, ar);
181 ar->regiontype = RGN_TYPE_PREVIEW;
182 ar->alignment = RGN_ALIGN_RIGHT;
183 ar->flag = RGN_FLAG_HIDDEN;
186 ar = MEM_callocN(sizeof(ARegion), "main area for image");
188 BLI_addtail(&simage->regionbase, ar);
189 ar->regiontype = RGN_TYPE_WINDOW;
191 return (SpaceLink *)simage;
194 /* not spacelink itself */
195 static void image_free(SpaceLink *sl)
197 SpaceImage *simage = (SpaceImage *) sl;
200 curvemapping_free(simage->cumap);
201 scopes_free(&simage->scopes);
205 /* spacetype; init callback, add handlers */
206 static void image_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
208 ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
211 WM_event_add_dropbox_handler(&sa->handlers, lb);
215 static SpaceLink *image_duplicate(SpaceLink *sl)
217 SpaceImage *simagen = MEM_dupallocN(sl);
219 /* clear or remove stuff from old */
221 simagen->cumap = curvemapping_copy(simagen->cumap);
223 scopes_new(&simagen->scopes);
225 return (SpaceLink *)simagen;
228 static void image_operatortypes(void)
230 WM_operatortype_append(IMAGE_OT_view_all);
231 WM_operatortype_append(IMAGE_OT_view_pan);
232 WM_operatortype_append(IMAGE_OT_view_selected);
233 WM_operatortype_append(IMAGE_OT_view_zoom);
234 WM_operatortype_append(IMAGE_OT_view_zoom_in);
235 WM_operatortype_append(IMAGE_OT_view_zoom_out);
236 WM_operatortype_append(IMAGE_OT_view_zoom_ratio);
237 WM_operatortype_append(IMAGE_OT_view_ndof);
239 WM_operatortype_append(IMAGE_OT_new);
240 WM_operatortype_append(IMAGE_OT_open);
241 WM_operatortype_append(IMAGE_OT_match_movie_length);
242 WM_operatortype_append(IMAGE_OT_replace);
243 WM_operatortype_append(IMAGE_OT_reload);
244 WM_operatortype_append(IMAGE_OT_save);
245 WM_operatortype_append(IMAGE_OT_save_as);
246 WM_operatortype_append(IMAGE_OT_save_sequence);
247 WM_operatortype_append(IMAGE_OT_pack);
248 WM_operatortype_append(IMAGE_OT_unpack);
250 WM_operatortype_append(IMAGE_OT_invert);
252 WM_operatortype_append(IMAGE_OT_cycle_render_slot);
254 WM_operatortype_append(IMAGE_OT_sample);
255 WM_operatortype_append(IMAGE_OT_sample_line);
256 WM_operatortype_append(IMAGE_OT_curves_point_set);
258 WM_operatortype_append(IMAGE_OT_record_composite);
260 WM_operatortype_append(IMAGE_OT_properties);
261 WM_operatortype_append(IMAGE_OT_scopes);
264 static void image_keymap(struct wmKeyConfig *keyconf)
266 wmKeyMap *keymap = WM_keymap_find(keyconf, "Image Generic", SPACE_IMAGE, 0);
270 WM_keymap_add_item(keymap, "IMAGE_OT_new", NKEY, KM_PRESS, KM_ALT, 0);
271 WM_keymap_add_item(keymap, "IMAGE_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
272 WM_keymap_add_item(keymap, "IMAGE_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
273 WM_keymap_add_item(keymap, "IMAGE_OT_save", SKEY, KM_PRESS, KM_ALT, 0);
274 WM_keymap_add_item(keymap, "IMAGE_OT_save_as", F3KEY, KM_PRESS, 0, 0);
275 WM_keymap_add_item(keymap, "IMAGE_OT_properties", NKEY, KM_PRESS, 0, 0);
276 WM_keymap_add_item(keymap, "IMAGE_OT_scopes", TKEY, KM_PRESS, 0, 0);
278 WM_keymap_add_item(keymap, "IMAGE_OT_cycle_render_slot", JKEY, KM_PRESS, 0, 0);
279 RNA_boolean_set(WM_keymap_add_item(keymap, "IMAGE_OT_cycle_render_slot", JKEY, KM_PRESS, KM_ALT, 0)->ptr, "reverse", TRUE);
281 keymap = WM_keymap_find(keyconf, "Image", SPACE_IMAGE, 0);
283 WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
284 WM_keymap_add_item(keymap, "IMAGE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
285 WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
286 WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
287 WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MOUSEPAN, 0, 0, 0);
289 WM_keymap_add_item(keymap, "IMAGE_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); // or view selected?
290 WM_keymap_add_item(keymap, "IMAGE_OT_view_ndof", NDOF_MOTION, 0, 0, 0);
292 WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0);
293 WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0);
294 WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0);
295 WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0);
296 WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
297 WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MOUSEZOOM, 0, 0, 0);
299 RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
300 RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
301 RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
302 RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
303 RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
304 RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
305 RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
307 WM_keymap_add_item(keymap, "IMAGE_OT_sample", ACTIONMOUSE, KM_PRESS, 0, 0);
308 RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_curves_point_set", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "point", 0);
309 RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_curves_point_set", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "point", 1);
311 /* toggle editmode is handy to have while UV unwrapping */
312 kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, 0, 0);
313 RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT);
314 RNA_boolean_set(kmi->ptr, "toggle", TRUE);
316 /* fast switch to render slots */
317 for (i = 0; i < MAX2(IMA_MAX_RENDER_SLOT, 9); i++) {
318 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_int", ONEKEY + i, KM_PRESS, 0, 0);
319 RNA_string_set(kmi->ptr, "data_path", "space_data.image.render_slot");
320 RNA_int_set(kmi->ptr, "value", i);
324 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0);
325 RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
326 RNA_string_set(kmi->ptr, "value", "CENTER");
328 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0);
329 RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
330 RNA_string_set(kmi->ptr, "value", "MEDIAN");
332 kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0);
333 RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
334 RNA_string_set(kmi->ptr, "value", "CURSOR");
338 static int image_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
340 if (drag->type == WM_DRAG_PATH)
341 if (ELEM3(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_BLANK)) /* rule might not work? */
346 static void image_drop_copy(wmDrag *drag, wmDropBox *drop)
348 /* copy drag path to properties */
349 RNA_string_set(drop->ptr, "filepath", drag->path);
352 /* area+region dropbox definition */
353 static void image_dropboxes(void)
355 ListBase *lb = WM_dropboxmap_find("Image", SPACE_IMAGE, 0);
357 WM_dropbox_add(lb, "IMAGE_OT_open", image_drop_poll, image_drop_copy);
361 * \note take care not to get into feedback loop here,
362 * calling composite job causes viewer to refresh.
364 static void image_refresh(const bContext *C, ScrArea *sa)
366 Scene *scene = CTX_data_scene(C);
367 SpaceImage *sima = sa->spacedata.first;
368 Object *obedit = CTX_data_edit_object(C);
371 ima = ED_space_image(sima);
373 BKE_image_user_check_frame_calc(&sima->iuser, scene->r.cfra, 0);
375 /* check if we have to set the image from the editmesh */
376 if (ima && (ima->source == IMA_SRC_VIEWER && sima->mode == SI_MODE_MASK)) {
377 if (sima->lock == FALSE && G.moving) {
381 if (scene->nodetree) {
382 Mask *mask = ED_space_image_get_mask(sima);
384 ED_node_composite_job(C, scene->nodetree, scene);
389 else if (ima && (ima->source == IMA_SRC_VIEWER || sima->pin)) {
392 else if (obedit && obedit->type == OB_MESH) {
393 Mesh *me = (Mesh *)obedit->data;
394 struct BMEditMesh *em = me->edit_btmesh;
395 int sloppy = TRUE; /* partially selected face is ok */
396 int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* only selected active face? */
398 if (BKE_scene_use_new_shading_nodes(scene)) {
399 /* new shading system, get image from material */
400 BMFace *efa = BM_active_face_get(em->bm, sloppy, selected);
404 ED_object_get_active_image(obedit, efa->mat_nr + 1, &node_ima, NULL, NULL);
407 sima->image = node_ima;
411 /* old shading system, we set texface */
414 if (em && EDBM_mtexpoly_check(em)) {
417 tf = EDBM_mtexpoly_active_get(em, NULL, sloppy, selected);
420 /* don't need to check for pin here, see above */
421 sima->image = tf->tpage;
423 if (sima->flag & SI_EDITTILE) ;
424 else sima->curtile = tf->tile;
431 static void image_listener(ScrArea *sa, wmNotifier *wmn)
433 SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
435 /* context changes */
436 switch (wmn->category) {
440 image_scopes_tag_refresh(sa);
441 ED_area_tag_refresh(sa);
442 ED_area_tag_redraw(sa);
445 case ND_RENDER_RESULT:
446 case ND_COMPO_RESULT:
447 if (ED_space_image_show_render(sima))
448 image_scopes_tag_refresh(sa);
449 ED_area_tag_redraw(sa);
454 if (wmn->reference == sima->image || !wmn->reference) {
455 image_scopes_tag_refresh(sa);
456 ED_area_tag_refresh(sa);
457 ED_area_tag_redraw(sa);
461 if (wmn->data == ND_SPACE_IMAGE) {
462 image_scopes_tag_refresh(sa);
463 ED_area_tag_redraw(sa);
468 // Scene *scene = wmn->window->screen->scene;
469 /* ideally would check for: ED_space_image_check_show_maskedit(scene, sima) but we cant get the scene */
470 if (sima->mode == SI_MODE_MASK) {
473 ED_area_tag_redraw(sa);
477 /* causes node-recalc */
478 ED_area_tag_redraw(sa);
479 ED_area_tag_refresh(sa);
482 switch (wmn->action) {
484 ED_area_tag_redraw(sa);
487 /* causes node-recalc */
488 ED_area_tag_redraw(sa);
489 ED_area_tag_refresh(sa);
499 image_scopes_tag_refresh(sa);
500 ED_area_tag_refresh(sa);
501 ED_area_tag_redraw(sa);
506 Object *ob = (Object *)wmn->reference;
510 if (ob && (ob->mode & OB_MODE_EDIT) && sima->lock && (sima->flag & SI_DRAWSHADOW)) {
511 ED_area_tag_refresh(sa);
512 ED_area_tag_redraw(sa);
520 const char *image_context_dir[] = {"edit_image", "edit_mask", NULL};
522 static int image_context(const bContext *C, const char *member, bContextDataResult *result)
524 SpaceImage *sima = CTX_wm_space_image(C);
526 if (CTX_data_dir(member)) {
527 CTX_data_dir_set(result, image_context_dir);
529 else if (CTX_data_equals(member, "edit_image")) {
530 CTX_data_id_pointer_set(result, (ID *)ED_space_image(sima));
533 else if (CTX_data_equals(member, "edit_mask")) {
534 Mask *mask = ED_space_image_get_mask(sima);
536 CTX_data_id_pointer_set(result, &mask->id);
543 /************************** main region ***************************/
545 /* sets up the fields of the View2D from zoom and offset */
546 static void image_main_area_set_view2d(SpaceImage *sima, ARegion *ar)
548 Image *ima = ED_space_image(sima);
550 int width, height, winx, winy;
553 if (image_preview_active(curarea, &width, &height)) ;
556 ED_space_image_get_size(sima, &width, &height);
562 h *= ima->aspy / ima->aspx;
564 winx = BLI_RCT_SIZE_X(&ar->winrct) + 1;
565 winy = BLI_RCT_SIZE_Y(&ar->winrct) + 1;
567 ar->v2d.tot.xmin = 0;
568 ar->v2d.tot.ymin = 0;
569 ar->v2d.tot.xmax = w;
570 ar->v2d.tot.ymax = h;
572 ar->v2d.mask.xmin = ar->v2d.mask.ymin = 0;
573 ar->v2d.mask.xmax = winx;
574 ar->v2d.mask.ymax = winy;
576 /* which part of the image space do we see? */
577 x1 = ar->winrct.xmin + (winx - sima->zoom * w) / 2.0f;
578 y1 = ar->winrct.ymin + (winy - sima->zoom * h) / 2.0f;
580 x1 -= sima->zoom * sima->xof;
581 y1 -= sima->zoom * sima->yof;
583 /* relative display right */
584 ar->v2d.cur.xmin = ((ar->winrct.xmin - (float)x1) / sima->zoom);
585 ar->v2d.cur.xmax = ar->v2d.cur.xmin + ((float)winx / sima->zoom);
587 /* relative display left */
588 ar->v2d.cur.ymin = ((ar->winrct.ymin - (float)y1) / sima->zoom);
589 ar->v2d.cur.ymax = ar->v2d.cur.ymin + ((float)winy / sima->zoom);
591 /* normalize 0.0..1.0 */
592 ar->v2d.cur.xmin /= w;
593 ar->v2d.cur.xmax /= w;
594 ar->v2d.cur.ymin /= h;
595 ar->v2d.cur.ymax /= h;
598 /* add handlers, stuff you only do once or on area/region changes */
599 static void image_main_area_init(wmWindowManager *wm, ARegion *ar)
603 // image space manages own v2d
604 // UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
606 /* mask polls mode */
607 keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
608 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
610 /* image paint polls for mode */
611 keymap = WM_keymap_find(wm->defaultconf, "Image Paint", 0, 0);
612 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
614 keymap = WM_keymap_find(wm->defaultconf, "UV Editor", 0, 0);
615 WM_event_add_keymap_handler(&ar->handlers, keymap);
617 keymap = WM_keymap_find(wm->defaultconf, "UV Sculpt", 0, 0);
618 WM_event_add_keymap_handler(&ar->handlers, keymap);
621 keymap = WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
622 WM_event_add_keymap_handler(&ar->handlers, keymap);
623 keymap = WM_keymap_find(wm->defaultconf, "Image", SPACE_IMAGE, 0);
624 WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
628 static void image_main_area_draw(const bContext *C, ARegion *ar)
630 /* draw entirely, view changes should be handled here */
631 SpaceImage *sima = CTX_wm_space_image(C);
632 Object *obact = CTX_data_active_object(C);
633 Object *obedit = CTX_data_edit_object(C);
635 Scene *scene = CTX_data_scene(C);
636 View2D *v2d = &ar->v2d;
637 //View2DScrollers *scrollers;
640 /* XXX not supported yet, disabling for now */
641 scene->r.scemode &= ~R_COMP_CROP;
643 /* clear and setup matrix */
644 UI_GetThemeColor3fv(TH_BACK, col);
645 glClearColor(col[0], col[1], col[2], 0.0);
646 glClear(GL_COLOR_BUFFER_BIT);
648 /* put scene context variable in iuser */
649 sima->iuser.scene = scene;
651 /* we set view2d from own zoom and offset each time */
652 image_main_area_set_view2d(sima, ar);
654 /* we draw image in pixelspace */
655 draw_image_main(sima, ar, scene);
657 /* and uvs in 0.0-1.0 space */
658 UI_view2d_view_ortho(v2d);
659 draw_uvedit_main(sima, ar, scene, obedit, obact);
661 /* check for mask (delay draw) */
662 if (ED_space_image_show_uvedit(sima, obedit)) {
665 else if (sima->mode == SI_MODE_MASK) {
666 mask = ED_space_image_get_mask(sima);
667 draw_image_cursor(sima, ar);
670 ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
672 /* Grease Pencil too (in addition to UV's) */
673 draw_image_grease_pencil((bContext *)C, 1);
676 draw_image_sample_line(sima);
678 UI_view2d_view_restore(C);
680 /* draw Grease Pencil - screen space only */
681 draw_image_grease_pencil((bContext *)C, 0);
686 ED_space_image_get_size(sima, &width, &height);
687 ED_space_image_get_aspect(sima, &aspx, &aspy);
688 ED_mask_draw_region(mask, ar,
689 sima->mask_info.draw_flag, sima->mask_info.draw_type,
695 ED_mask_draw_frames(mask, ar, CFRA, mask->sfra, mask->efra);
697 draw_image_cursor(sima, ar);
702 scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
703 UI_view2d_scrollers_draw(C, v2d, scrollers);
704 UI_view2d_scrollers_free(scrollers);
708 static void image_main_area_listener(ARegion *ar, wmNotifier *wmn)
710 /* context changes */
711 switch (wmn->category) {
713 if (wmn->data == ND_GPENCIL)
714 ED_region_tag_redraw(ar);
719 /* *********************** buttons region ************************ */
721 /* add handlers, stuff you only do once or on area/region changes */
722 static void image_buttons_area_init(wmWindowManager *wm, ARegion *ar)
726 ED_region_panels_init(wm, ar);
728 keymap = WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
729 WM_event_add_keymap_handler(&ar->handlers, keymap);
732 static void image_buttons_area_draw(const bContext *C, ARegion *ar)
734 ED_region_panels(C, ar, 1, NULL, -1);
737 static void image_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
739 /* context changes */
740 switch (wmn->category) {
742 if (wmn->data == ND_GPENCIL)
743 ED_region_tag_redraw(ar);
746 if (wmn->action == NA_EDITED)
747 ED_region_tag_redraw(ar);
751 /* sending by texture render job and needed to properly update displaying
752 * brush texture icon */
753 ED_region_tag_redraw(ar);
758 /* *********************** scopes region ************************ */
760 /* add handlers, stuff you only do once or on area/region changes */
761 static void image_scope_area_init(wmWindowManager *wm, ARegion *ar)
765 ED_region_panels_init(wm, ar);
767 keymap = WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0);
768 WM_event_add_keymap_handler(&ar->handlers, keymap);
771 static void image_scope_area_draw(const bContext *C, ARegion *ar)
773 SpaceImage *sima = CTX_wm_space_image(C);
774 Scene *scene = CTX_data_scene(C);
776 ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock);
778 if (!sima->scopes.ok) {
779 BKE_histogram_update_sample_line(&sima->sample_line_hist, ibuf, scene->r.color_mgt_flag & R_COLOR_MANAGEMENT);
781 scopes_update(&sima->scopes, ibuf, scene->r.color_mgt_flag & R_COLOR_MANAGEMENT);
783 ED_space_image_release_buffer(sima, lock);
785 ED_region_panels(C, ar, 1, NULL, -1);
788 static void image_scope_area_listener(ARegion *ar, wmNotifier *wmn)
790 /* context changes */
791 switch (wmn->category) {
795 case ND_RENDER_RESULT:
796 case ND_COMPO_RESULT:
797 ED_region_tag_redraw(ar);
802 ED_region_tag_redraw(ar);
805 ED_region_tag_redraw(ar);
811 /************************* header region **************************/
813 /* add handlers, stuff you only do once or on area/region changes */
814 static void image_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
816 ED_region_header_init(ar);
819 static void image_header_area_draw(const bContext *C, ARegion *ar)
821 ED_region_header(C, ar);
824 static void image_header_area_listener(ARegion *ar, wmNotifier *wmn)
826 /* context changes */
827 switch (wmn->category) {
831 case ND_TOOLSETTINGS:
832 ED_region_tag_redraw(ar);
840 ED_region_tag_redraw(ar);
847 /**************************** spacetype *****************************/
849 /* only called once, from space/spacetypes.c */
850 void ED_spacetype_image(void)
852 SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype image");
855 st->spaceid = SPACE_IMAGE;
856 strncpy(st->name, "Image", BKE_ST_MAXNAME);
859 st->free = image_free;
860 st->init = image_init;
861 st->duplicate = image_duplicate;
862 st->operatortypes = image_operatortypes;
863 st->keymap = image_keymap;
864 st->dropboxes = image_dropboxes;
865 st->refresh = image_refresh;
866 st->listener = image_listener;
867 st->context = image_context;
869 /* regions: main window */
870 art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
871 art->regionid = RGN_TYPE_WINDOW;
872 art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL;
873 art->init = image_main_area_init;
874 art->draw = image_main_area_draw;
875 art->listener = image_main_area_listener;
877 BLI_addhead(&st->regiontypes, art);
879 /* regions: listview/buttons */
880 art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
881 art->regionid = RGN_TYPE_UI;
882 art->prefsizex = 220; // XXX
883 art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
884 art->listener = image_buttons_area_listener;
885 art->init = image_buttons_area_init;
886 art->draw = image_buttons_area_draw;
887 BLI_addhead(&st->regiontypes, art);
889 image_buttons_register(art);
890 ED_uvedit_buttons_register(art);
892 /* regions: statistics/scope buttons */
893 art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
894 art->regionid = RGN_TYPE_PREVIEW;
895 art->prefsizex = 220; // XXX
896 art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
897 art->listener = image_scope_area_listener;
898 art->init = image_scope_area_init;
899 art->draw = image_scope_area_draw;
900 BLI_addhead(&st->regiontypes, art);
902 /* regions: header */
903 art = MEM_callocN(sizeof(ARegionType), "spacetype image region");
904 art->regionid = RGN_TYPE_HEADER;
905 art->prefsizey = HEADERY;
906 art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
907 art->listener = image_header_area_listener;
908 art->init = image_header_area_init;
909 art->draw = image_header_area_draw;
911 BLI_addhead(&st->regiontypes, art);
913 BKE_spacetype_register(st);