diff options
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r-- | source/blender/editors/space_image/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_buttons.c | 92 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_draw.c | 583 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_edit.c | 40 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_intern.h | 5 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 292 | ||||
-rw-r--r-- | source/blender/editors/space_image/space_image.c | 251 |
7 files changed, 530 insertions, 734 deletions
diff --git a/source/blender/editors/space_image/CMakeLists.txt b/source/blender/editors/space_image/CMakeLists.txt index c60d194b620..0bc09981ba5 100644 --- a/source/blender/editors/space_image/CMakeLists.txt +++ b/source/blender/editors/space_image/CMakeLists.txt @@ -25,6 +25,7 @@ set(INC ../../blenlib ../../blentranslation ../../bmesh + ../../depsgraph ../../imbuf ../../gpu ../../makesdna diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c index 26bd560b31f..26162266441 100644 --- a/source/blender/editors/space_image/image_buttons.c +++ b/source/blender/editors/space_image/image_buttons.c @@ -125,7 +125,7 @@ static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, /* the frame number, even if we cant */ if (ima->source == IMA_SRC_SEQUENCE) { /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */ - const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0, NULL); + const int framenr = BKE_image_user_frame_get(iuser, CFRA, NULL); ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(", Frame: %d"), framenr); } } @@ -291,23 +291,24 @@ static void ui_imageuser_slot_menu(bContext *UNUSED(C), uiLayout *layout, void * { uiBlock *block = uiLayoutGetBlock(layout); Image *image = image_p; - int slot; + int slot_id; uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Slot"), 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); uiItemS(layout); - slot = IMA_MAX_RENDER_SLOT; - while (slot--) { + slot_id = BLI_listbase_count(&image->renderslots) - 1; + for (RenderSlot *slot = image->renderslots.last; slot; slot = slot->prev) { char str[64]; - if (image->render_slots[slot].name[0] != '\0') { - BLI_strncpy(str, image->render_slots[slot].name, sizeof(str)); + if (slot->name[0] != '\0') { + BLI_strncpy(str, slot->name, sizeof(str)); } else { - BLI_snprintf(str, sizeof(str), IFACE_("Slot %d"), slot + 1); + BLI_snprintf(str, sizeof(str), IFACE_("Slot %d"), slot_id + 1); } uiDefButS(block, UI_BTYPE_BUT_MENU, B_NOP, str, 0, 0, - UI_UNIT_X * 5, UI_UNIT_X, &image->render_slot, (float) slot, 0.0, 0, -1, ""); + UI_UNIT_X * 5, UI_UNIT_X, &image->render_slot, (float) slot_id, 0.0, 0, -1, ""); + slot_id--; } } @@ -708,8 +709,9 @@ static void uiblock_layer_pass_buttons( /* menu buts */ if (render_slot) { char str[64]; - if (image->render_slots[*render_slot].name[0] != '\0') { - BLI_strncpy(str, image->render_slots[*render_slot].name, sizeof(str)); + RenderSlot *slot = BKE_image_get_renderslot(image, *render_slot); + if (slot && slot->name[0] != '\0') { + BLI_strncpy(str, slot->name, sizeof(str)); } else { BLI_snprintf(str, sizeof(str), IFACE_("Slot %d"), *render_slot + 1); @@ -861,7 +863,7 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char ima = imaptr.data; iuser = userptr->data; - BKE_image_user_check_frame_calc(iuser, (int)scene->r.cfra, 0); + BKE_image_user_check_frame_calc(iuser, (int)scene->r.cfra); cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb"); cb->ptr = *ptr; @@ -874,7 +876,7 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char if (!compact) { uiTemplateID( layout, C, ptr, propname, - ima ? NULL : "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL); + ima ? NULL : "IMAGE_OT_new", "IMAGE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); } if (ima) { @@ -998,25 +1000,6 @@ void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char col = uiLayoutColumn(layout, false); uiItemR(col, &imaptr, "use_deinterlace", 0, IFACE_("Deinterlace"), ICON_NONE); } - - split = uiLayoutSplit(layout, 0.0f, false); - - col = uiLayoutColumn(split, false); - /* XXX Why only display fields_per_frame only for video image types? - * And why allow fields for non-video image types at all??? */ - if (BKE_image_is_animated(ima)) { - uiLayout *subsplit = uiLayoutSplit(col, 0.0f, false); - uiLayout *subcol = uiLayoutColumn(subsplit, false); - uiItemR(subcol, &imaptr, "use_fields", 0, NULL, ICON_NONE); - subcol = uiLayoutColumn(subsplit, false); - uiLayoutSetActive(subcol, RNA_boolean_get(&imaptr, "use_fields")); - uiItemR(subcol, userptr, "fields_per_frame", 0, IFACE_("Fields"), ICON_NONE); - } - else - uiItemR(col, &imaptr, "use_fields", 0, NULL, ICON_NONE); - row = uiLayoutRow(col, false); - uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_fields")); - uiItemR(row, &imaptr, "field_order", UI_ITEM_R_EXPAND, NULL, ICON_NONE); } } @@ -1068,19 +1051,19 @@ void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, bool color_ma PointerRNA display_settings_ptr; PropertyRNA *prop; const int depth_ok = BKE_imtype_valid_depths(imf->imtype); - /* some settings depend on this being a scene thats rendered */ + /* some settings depend on this being a scene that's rendered */ const bool is_render_out = (id && GS(id->name) == ID_SCE); - uiLayout *col, *row, *split, *sub; + uiLayout *col; bool show_preview = false; col = uiLayoutColumn(layout, false); - split = uiLayoutSplit(col, 0.5f, false); + uiLayoutSetPropSep(col, true); + uiLayoutSetPropDecorate(col, false); - uiItemR(split, imfptr, "file_format", 0, "", ICON_NONE); - sub = uiLayoutRow(split, false); - uiItemR(sub, imfptr, "color_mode", UI_ITEM_R_EXPAND, IFACE_("Color"), ICON_NONE); + uiItemR(col, imfptr, "file_format", 0, NULL, ICON_NONE); + uiItemR(uiLayoutRow(col, true), imfptr, "color_mode", UI_ITEM_R_EXPAND, IFACE_("Color"), ICON_NONE); /* only display depth setting if multiple depths can be used */ if ((ELEM(depth_ok, @@ -1092,10 +1075,7 @@ void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, bool color_ma R_IMF_CHAN_DEPTH_24, R_IMF_CHAN_DEPTH_32)) == 0) { - row = uiLayoutRow(col, false); - - uiItemL(row, IFACE_("Color Depth:"), ICON_NONE); - uiItemR(row, imfptr, "color_depth", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiItemR(uiLayoutRow(col, true), imfptr, "color_depth", UI_ITEM_R_EXPAND, NULL, ICON_NONE); } if (BKE_imtype_supports_quality(imf->imtype)) { @@ -1110,22 +1090,20 @@ void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr, bool color_ma uiItemR(col, imfptr, "exr_codec", 0, NULL, ICON_NONE); } - row = uiLayoutRow(col, false); if (BKE_imtype_supports_zbuf(imf->imtype)) { - uiItemR(row, imfptr, "use_zbuffer", 0, NULL, ICON_NONE); + uiItemR(col, imfptr, "use_zbuffer", 0, NULL, ICON_NONE); } if (is_render_out && ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) { show_preview = true; - uiItemR(row, imfptr, "use_preview", 0, NULL, ICON_NONE); + uiItemR(col, imfptr, "use_preview", 0, NULL, ICON_NONE); } if (imf->imtype == R_IMF_IMTYPE_JP2) { uiItemR(col, imfptr, "jpeg2k_codec", 0, NULL, ICON_NONE); - row = uiLayoutRow(col, false); - uiItemR(row, imfptr, "use_jpeg2k_cinema_preset", 0, NULL, ICON_NONE); - uiItemR(row, imfptr, "use_jpeg2k_cinema_48", 0, NULL, ICON_NONE); + uiItemR(col, imfptr, "use_jpeg2k_cinema_preset", 0, NULL, ICON_NONE); + uiItemR(col, imfptr, "use_jpeg2k_cinema_48", 0, NULL, ICON_NONE); uiItemR(col, imfptr, "use_jpeg2k_ycc", 0, NULL, ICON_NONE); } @@ -1201,17 +1179,19 @@ void uiTemplateImageStereo3d(uiLayout *layout, PointerRNA *stereo3d_format_ptr) static void uiTemplateViewsFormat(uiLayout *layout, PointerRNA *ptr, PointerRNA *stereo3d_format_ptr) { - uiLayout *col, *box; + uiLayout *col; col = uiLayoutColumn(layout, false); - uiItemL(col, IFACE_("Views Format:"), ICON_NONE); - uiItemR(uiLayoutRow(col, false), ptr, "views_format", UI_ITEM_R_EXPAND, NULL, ICON_NONE); + uiLayoutSetPropSep(col, true); + uiLayoutSetPropDecorate(col, false); + + uiItemR(col, ptr, "views_format", UI_ITEM_R_EXPAND, NULL, ICON_NONE); - if (stereo3d_format_ptr) { - box = uiLayoutBox(col); - uiLayoutSetActive(box, RNA_enum_get(ptr, "views_format") == R_IMF_VIEWS_STEREO_3D); - uiTemplateImageStereo3d(box, stereo3d_format_ptr); + if (stereo3d_format_ptr && + RNA_enum_get(ptr, "views_format") == R_IMF_VIEWS_STEREO_3D) + { + uiTemplateImageStereo3d(col, stereo3d_format_ptr); } } @@ -1313,7 +1293,7 @@ static int image_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op)) void IMAGE_OT_properties(wmOperatorType *ot) { - ot->name = "Properties"; + ot->name = "Toggle Sidebar"; ot->idname = "IMAGE_OT_properties"; ot->description = "Toggle the properties region visibility"; @@ -1337,7 +1317,7 @@ static int image_scopes_toggle_exec(bContext *C, wmOperator *UNUSED(op)) void IMAGE_OT_toolshelf(wmOperatorType *ot) { - ot->name = "Tool Shelf"; + ot->name = "Toggle Toolbar"; ot->idname = "IMAGE_OT_toolshelf"; ot->description = "Toggles tool shelf display"; diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index c358b38520a..4cbe25462af 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -60,9 +60,13 @@ #include "BKE_image.h" #include "BKE_paint.h" -#include "BIF_gl.h" #include "BIF_glutil.h" +#include "GPU_immediate.h" +#include "GPU_immediate_util.h" +#include "GPU_matrix.h" +#include "GPU_state.h" + #include "BLF_api.h" #include "ED_gpencil.h" @@ -87,7 +91,6 @@ static void draw_render_info(const bContext *C, float zoomx, float zoomy) { - RenderResult *rr; Render *re = RE_GetSceneRender(scene); RenderData *rd = RE_engine_get_render_data(re); Scene *stats_scene = ED_render_job_get_scene(C); @@ -95,7 +98,7 @@ static void draw_render_info(const bContext *C, stats_scene = CTX_data_scene(C); } - rr = BKE_image_acquire_renderresult(stats_scene, ima); + RenderResult *rr = BKE_image_acquire_renderresult(stats_scene, ima); if (rr && rr->text) { float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.25f}; @@ -107,39 +110,41 @@ static void draw_render_info(const bContext *C, if (re) { int total_tiles; bool need_free_tiles; - rcti *tiles; - - tiles = RE_engine_get_current_tiles(re, &total_tiles, &need_free_tiles); + rcti *tiles = RE_engine_get_current_tiles(re, &total_tiles, &need_free_tiles); if (total_tiles) { - int i, x, y; - rcti *tile; - /* find window pixel coordinates of origin */ + int x, y; UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y); - glPushMatrix(); - glTranslatef(x, y, 0.0f); - glScalef(zoomx, zoomy, 1.0f); + GPU_matrix_push(); + GPU_matrix_translate_2f(x, y); + GPU_matrix_scale_2f(zoomx, zoomy); if (rd->mode & R_BORDER) { - glTranslatef((int)(-rd->border.xmin * rd->xsch * rd->size / 100.0f), - (int)(-rd->border.ymin * rd->ysch * rd->size / 100.0f), - 0.0f); + /* TODO: round or floor instead of casting to int */ + GPU_matrix_translate_2f((int)(-rd->border.xmin * rd->xsch * rd->size * 0.01f), + (int)(-rd->border.ymin * rd->ysch * rd->size * 0.01f)); } - UI_ThemeColor(TH_FACE_SELECT); + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformThemeColor(TH_FACE_SELECT); - glLineWidth(1.0f); - for (i = 0, tile = tiles; i < total_tiles; i++, tile++) { - glaDrawBorderCorners(tile, zoomx, zoomy); + GPU_line_width(1.0f); + + rcti *tile = tiles; + for (int i = 0; i < total_tiles; i++, tile++) { + immDrawBorderCorners(pos, tile, zoomx, zoomy); } + immUnbindProgram(); + if (need_free_tiles) { MEM_freeN(tiles); } - glPopMatrix(); + GPU_matrix_pop(); } } } @@ -166,31 +171,37 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d float hue = 0, sat = 0, val = 0, lum = 0, u = 0, v = 0; float col[4], finalcol[4]; - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); + GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); + GPU_blend(true); + + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); /* noisy, high contrast make impossible to read if lower alpha is used. */ - glColor4ub(0, 0, 0, 190); - glRecti(0.0, 0.0, BLI_rcti_size_x(&ar->winrct) + 1, UI_UNIT_Y); - glDisable(GL_BLEND); + immUniformColor4ub(0, 0, 0, 190); + immRecti(pos, 0, 0, BLI_rcti_size_x(&ar->winrct) + 1, UI_UNIT_Y); + + immUnbindProgram(); + + GPU_blend(false); BLF_size(blf_mono_font, 11 * U.pixelsize, U.dpi); - glColor3ub(255, 255, 255); + BLF_color3ub(blf_mono_font, 255, 255, 255); BLI_snprintf(str, sizeof(str), "X:%-4d Y:%-4d |", x, y); BLF_position(blf_mono_font, dx, dy, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); if (zp) { - glColor3ub(255, 255, 255); + BLF_color3ub(blf_mono_font, 255, 255, 255); BLI_snprintf(str, sizeof(str), " Z:%-.4f |", 0.5f + 0.5f * (((float)*zp) / (float)0x7fffffff)); BLF_position(blf_mono_font, dx, dy, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); } if (zpf) { - glColor3ub(255, 255, 255); + BLF_color3ub(blf_mono_font, 255, 255, 255); BLI_snprintf(str, sizeof(str), " Z:%-.3f |", *zpf); BLF_position(blf_mono_font, dx, dy, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); @@ -204,14 +215,14 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d else if (cp != NULL) { BLI_snprintf(str, sizeof(str), " Val:%-.3f |", cp[0] / 255.0f); } - glColor3ub(255, 255, 255); + BLF_color3ub(blf_mono_font, 255, 255, 255); BLF_position(blf_mono_font, dx, dy, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); } if (channels >= 3) { - glColor3ubv(red); + BLF_color3ubv(blf_mono_font, red); if (fp) BLI_snprintf(str, sizeof(str), " R:%-.5f", fp[0]); else if (cp) @@ -222,7 +233,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); - glColor3ubv(green); + BLF_color3ubv(blf_mono_font, green); if (fp) BLI_snprintf(str, sizeof(str), " G:%-.5f", fp[1]); else if (cp) @@ -233,7 +244,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d BLF_draw_ascii(blf_mono_font, str, sizeof(str)); dx += BLF_width(blf_mono_font, str, sizeof(str)); - glColor3ubv(blue); + BLF_color3ubv(blf_mono_font, blue); if (fp) BLI_snprintf(str, sizeof(str), " B:%-.5f", fp[2]); else if (cp) @@ -245,7 +256,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d dx += BLF_width(blf_mono_font, str, sizeof(str)); if (channels == 4) { - glColor3ub(255, 255, 255); + BLF_color3ub(blf_mono_font, 255, 255, 255); if (fp) BLI_snprintf(str, sizeof(str), " A:%-.4f", fp[3]); else if (cp) @@ -267,9 +278,9 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d rgba[3] = linearcol[3]; if (use_default_view) - IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, NULL, &scene->display_settings); + IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, NULL, &scene->display_settings); else - IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, &scene->view_settings, &scene->display_settings); + IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, &scene->view_settings, &scene->display_settings); BLI_snprintf(str, sizeof(str), " | CM R:%-.4f G:%-.4f B:%-.4f", rgba[0], rgba[1], rgba[2]); BLF_position(blf_mono_font, dx, dy, 0); @@ -305,26 +316,31 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d if (color_manage) { if (use_default_view) - IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, NULL, &scene->display_settings); + IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, NULL, &scene->display_settings); else - IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, &scene->view_settings, &scene->display_settings); + IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, &scene->view_settings, &scene->display_settings); } else { copy_v4_v4(finalcol, col); } - glDisable(GL_BLEND); + GPU_blend(false); dx += 0.25f * UI_UNIT_X; BLI_rcti_init(&color_rect, dx, dx + (1.5f * UI_UNIT_X), 0.15f * UI_UNIT_Y, 0.85f * UI_UNIT_Y); + /* BLF uses immediate mode too, so we must reset our vertex format */ + pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + if (channels == 4) { rcti color_rect_half; int color_quater_x, color_quater_y; color_rect_half = color_rect; color_rect_half.xmax = BLI_rcti_cent_x(&color_rect); - glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); + /* what color ??? */ + immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); color_rect_half = color_rect; color_rect_half.xmin = BLI_rcti_cent_x(&color_rect); @@ -332,31 +348,34 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d color_quater_x = BLI_rcti_cent_x(&color_rect_half); color_quater_y = BLI_rcti_cent_y(&color_rect_half); - glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255); - glRecti(color_rect_half.xmin, color_rect_half.ymin, color_rect_half.xmax, color_rect_half.ymax); + immUniformColor3ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK); + immRecti(pos, color_rect_half.xmin, color_rect_half.ymin, color_rect_half.xmax, color_rect_half.ymax); - glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255); - glRecti(color_quater_x, color_quater_y, color_rect_half.xmax, color_rect_half.ymax); - glRecti(color_rect_half.xmin, color_rect_half.ymin, color_quater_x, color_quater_y); + immUniformColor3ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT); + immRecti(pos, color_quater_x, color_quater_y, color_rect_half.xmax, color_rect_half.ymax); + immRecti(pos, color_rect_half.xmin, color_rect_half.ymin, color_quater_x, color_quater_y); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(UNPACK3(finalcol), fp ? fp[3] : (cp[3] / 255.0f)); - glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); - glDisable(GL_BLEND); + GPU_blend(true); + immUniformColor3fvAlpha(finalcol, fp ? fp[3] : (cp[3] / 255.0f)); + immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); + GPU_blend(false); } else { - glColor3fv(finalcol); - glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); + immUniformColor3fv(finalcol); + immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); } + immUnbindProgram(); /* draw outline */ - glColor3ub(128, 128, 128); - sdrawbox(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); + pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformColor3ub(128, 128, 128); + imm_draw_box_wire_2d(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax); + immUnbindProgram(); dx += 1.75f * UI_UNIT_X; - glColor3ub(255, 255, 255); + BLF_color3ub(blf_mono_font, 255, 255, 255); if (channels == 1) { if (fp) { rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val); @@ -375,7 +394,6 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d BLI_snprintf(str, sizeof(str), " L:%-.4f", lum); BLF_position(blf_mono_font, dx, dy, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str, sizeof(str)); } else if (channels >= 3) { rgb_to_hsv(finalcol[0], finalcol[1], finalcol[2], &hue, &sat, &val); @@ -399,69 +417,36 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d BLI_snprintf(str, sizeof(str), " L:%-.4f", lum); BLF_position(blf_mono_font, dx, dy, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str, sizeof(str)); } - - (void)dx; } /* image drawing */ - -static void sima_draw_alpha_pixels(float x1, float y1, int rectx, int recty, unsigned int *recti) +static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int *rect, + float zoomx, float zoomy) { + float red[4] = {1.0f, 0.0f, 0.0f, 0.0f}; - /* swap bytes, so alpha is most significant one, then just draw it as luminance int */ - if (ENDIAN_ORDER == B_ENDIAN) - glPixelStorei(GL_UNPACK_SWAP_BYTES, 1); + /* Slowwww */ + int *recti = MEM_mallocN(rectx * recty * sizeof(int), "temp"); + for (int a = rectx * recty - 1; a >= 0; a--) { + /* zbuffer values are signed, so we need to shift color range */ + recti[a] = rect[a] * 0.5f + 0.5f; + } - glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_UNSIGNED_INT, recti); - glPixelStorei(GL_UNPACK_SWAP_BYTES, 0); -} + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); + GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red); -static void sima_draw_alpha_pixelsf(float x1, float y1, int rectx, int recty, float *rectf) -{ - float *trectf = MEM_mallocN(rectx * recty * 4, "temp"); - int a, b; - - for (a = rectx * recty - 1, b = 4 * a + 3; a >= 0; a--, b -= 4) - trectf[a] = rectf[b]; - - glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_FLOAT, trectf); - MEM_freeN(trectf); - /* ogl trick below is slower... (on ATI 9600) */ -// glColorMask(1, 0, 0, 0); -// glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_RGBA, GL_FLOAT, rectf + 3); -// glColorMask(0, 1, 0, 0); -// glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_RGBA, GL_FLOAT, rectf + 2); -// glColorMask(0, 0, 1, 0); -// glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_RGBA, GL_FLOAT, rectf + 1); -// glColorMask(1, 1, 1, 1); -} + immDrawPixelsTex(&state, x1, y1, rectx, recty, GL_RED, GL_INT, GL_NEAREST, recti, zoomx, zoomy, NULL); -static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int *recti) -{ - /* zbuffer values are signed, so we need to shift color range */ - glPixelTransferf(GL_RED_SCALE, 0.5f); - glPixelTransferf(GL_GREEN_SCALE, 0.5f); - glPixelTransferf(GL_BLUE_SCALE, 0.5f); - glPixelTransferf(GL_RED_BIAS, 0.5f); - glPixelTransferf(GL_GREEN_BIAS, 0.5f); - glPixelTransferf(GL_BLUE_BIAS, 0.5f); - - glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_INT, recti); - - glPixelTransferf(GL_RED_SCALE, 1.0f); - glPixelTransferf(GL_GREEN_SCALE, 1.0f); - glPixelTransferf(GL_BLUE_SCALE, 1.0f); - glPixelTransferf(GL_RED_BIAS, 0.0f); - glPixelTransferf(GL_GREEN_BIAS, 0.0f); - glPixelTransferf(GL_BLUE_BIAS, 0.0f); + MEM_freeN(recti); } -static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rectx, int recty, float *rect_float) +static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rectx, int recty, + float *rect_float, float zoomx, float zoomy) { float bias, scale, *rectf, clipend; int a; + float red[4] = {1.0f, 0.0f, 0.0f, 0.0f}; if (scene->camera && scene->camera->type == OB_CAMERA) { bias = ((Camera *)scene->camera->data)->clipsta; @@ -474,7 +459,7 @@ static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rec clipend = 100.0f; } - rectf = MEM_mallocN(rectx * recty * 4, "temp"); + rectf = MEM_mallocN(rectx * recty * sizeof(float), "temp"); for (a = rectx * recty - 1; a >= 0; a--) { if (rect_float[a] > clipend) rectf[a] = 0.0f; @@ -485,195 +470,82 @@ static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rec rectf[a] *= rectf[a]; } } - glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_FLOAT, rectf); - MEM_freeN(rectf); -} + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); + GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red); -static int draw_image_channel_offset(SpaceImage *sima) -{ -#ifdef __BIG_ENDIAN__ - if (sima->flag & SI_SHOW_R) return 0; - else if (sima->flag & SI_SHOW_G) return 1; - else return 2; -#else - if (sima->flag & SI_SHOW_R) return 1; - else if (sima->flag & SI_SHOW_G) return 2; - else return 3; -#endif + immDrawPixelsTex(&state, x1, y1, rectx, recty, GL_RED, GL_FLOAT, GL_NEAREST, rectf, zoomx, zoomy, NULL); + + MEM_freeN(rectf); } static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy) { int x, y; - /* set zoom */ - glPixelZoom(zoomx, zoomy); - - glaDefine2DArea(&ar->winrct); - /* find window pixel coordinates of origin */ UI_view2d_view_to_region(&ar->v2d, fx, fy, &x, &y); /* this part is generic image display */ - if (sima->flag & SI_SHOW_ALPHA) { - if (ibuf->rect) - sima_draw_alpha_pixels(x, y, ibuf->x, ibuf->y, ibuf->rect); - else if (ibuf->rect_float && ibuf->channels == 4) - sima_draw_alpha_pixelsf(x, y, ibuf->x, ibuf->y, ibuf->rect_float); - } - else if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) { + if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) { if (ibuf->zbuf) - sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf); + sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf, zoomx, zoomy); else if (ibuf->zbuf_float) - sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->zbuf_float); + sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->zbuf_float, zoomx, zoomy); else if (ibuf->channels == 1) - sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->rect_float); + sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->rect_float, zoomx, zoomy); } else { + int clip_max_x, clip_max_y; + UI_view2d_view_to_region(&ar->v2d, + ar->v2d.cur.xmax, ar->v2d.cur.ymax, + &clip_max_x, &clip_max_y); + if (sima->flag & SI_USE_ALPHA) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + imm_draw_box_checker_2d(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy); - fdrawcheckerboard(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy); + GPU_blend(true); + GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); } - if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B)) == 0) { - int clip_max_x, clip_max_y; - UI_view2d_view_to_region(&ar->v2d, - ar->v2d.cur.xmax, ar->v2d.cur.ymax, - &clip_max_x, &clip_max_y); + /* If RGBA display with color management */ + if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) { + glaDrawImBuf_glsl_ctx_clipping(C, ibuf, x, y, GL_NEAREST, - 0, 0, clip_max_x, clip_max_y); + 0, 0, clip_max_x, clip_max_y, zoomx, zoomy); } else { + float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f}; unsigned char *display_buffer; void *cache_handle; - - /* TODO(sergey): Ideally GLSL shading should be capable of either - * disabling some channels or displaying buffer with custom offset. - */ - display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); - - if (display_buffer != NULL) { - int channel_offset = draw_image_channel_offset(sima); - glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, - display_buffer - (4 - channel_offset)); - } - if (cache_handle != NULL) { - IMB_display_buffer_release(cache_handle); + ColorManagedViewSettings *view_settings; + ColorManagedDisplaySettings *display_settings; + + if (sima->flag & SI_SHOW_R) + shuffle[0] = 1.0f; + else if (sima->flag & SI_SHOW_G) + shuffle[1] = 1.0f; + else if (sima->flag & SI_SHOW_B) + shuffle[2] = 1.0f; + else if (sima->flag & SI_SHOW_ALPHA) + shuffle[3] = 1.0f; + + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR); + GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, shuffle); + + IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings); + display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle); + + if (display_buffer) { + immDrawPixelsTex_clipping(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer, + 0, 0, clip_max_x, clip_max_y, zoomx, zoomy, NULL); } - } - - if (sima->flag & SI_USE_ALPHA) - glDisable(GL_BLEND); - } - - /* reset zoom */ - glPixelZoom(1.0f, 1.0f); -} - -static unsigned int *get_part_from_buffer(unsigned int *buffer, int width, short startx, short starty, short endx, short endy) -{ - unsigned int *rt, *rp, *rectmain; - short y, heigth, len; - - /* the right offset in rectot */ - - rt = buffer + (starty * width + startx); - len = (endx - startx); - heigth = (endy - starty); - - rp = rectmain = MEM_mallocN(heigth * len * sizeof(int), "rect"); - - for (y = 0; y < heigth; y++) { - memcpy(rp, rt, len * 4); - rt += width; - rp += len; - } - return rectmain; -} - -static void draw_image_buffer_tiled(SpaceImage *sima, ARegion *ar, Scene *scene, Image *ima, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy) -{ - unsigned char *display_buffer; - unsigned int *rect; - int dx, dy, sx, sy, x, y; - void *cache_handle; - int channel_offset = -1; - - /* verify valid values, just leave this a while */ - if (ima->xrep < 1) return; - if (ima->yrep < 1) return; - - if (ima->flag & IMA_VIEW_AS_RENDER) - display_buffer = IMB_display_buffer_acquire(ibuf, &scene->view_settings, &scene->display_settings, &cache_handle); - else - display_buffer = IMB_display_buffer_acquire(ibuf, NULL, &scene->display_settings, &cache_handle); - - if (!display_buffer) - return; - - glPixelZoom(zoomx, zoomy); - - if (sima->curtile >= ima->xrep * ima->yrep) - sima->curtile = ima->xrep * ima->yrep - 1; - - /* retrieve part of image buffer */ - dx = max_ii(ibuf->x / ima->xrep, 1); - dy = max_ii(ibuf->y / ima->yrep, 1); - sx = (sima->curtile % ima->xrep) * dx; - sy = (sima->curtile / ima->xrep) * dy; - rect = get_part_from_buffer((unsigned int *)display_buffer, ibuf->x, sx, sy, sx + dx, sy + dy); - - /* draw repeated */ - if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B)) != 0) { - channel_offset = draw_image_channel_offset(sima); - } - for (sy = 0; sy + dy <= ibuf->y; sy += dy) { - for (sx = 0; sx + dx <= ibuf->x; sx += dx) { - UI_view2d_view_to_region(&ar->v2d, fx + (float)sx / (float)ibuf->x, fy + (float)sy / (float)ibuf->y, &x, &y); - if (channel_offset == -1) { - glaDrawPixelsSafe(x, y, dx, dy, dx, GL_RGBA, GL_UNSIGNED_BYTE, rect); - } - else { - glaDrawPixelsSafe(x, y, dx, dy, dx, GL_LUMINANCE, GL_UNSIGNED_INT, - (unsigned char *)rect - (4 - channel_offset)); - } + IMB_display_buffer_release(cache_handle); } - } - - glPixelZoom(1.0f, 1.0f); - - IMB_display_buffer_release(cache_handle); - - MEM_freeN(rect); -} - -static void draw_image_buffer_repeated(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, Image *ima, ImBuf *ibuf, float zoomx, float zoomy) -{ - const double time_current = PIL_check_seconds_timer(); - - const int xmax = ceil(ar->v2d.cur.xmax); - const int ymax = ceil(ar->v2d.cur.ymax); - const int xmin = floor(ar->v2d.cur.xmin); - const int ymin = floor(ar->v2d.cur.ymin); - int x; - - for (x = xmin; x < xmax; x++) { - int y; - for (y = ymin; y < ymax; y++) { - if (ima && (ima->tpageflag & IMA_TILES)) - draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, x, y, zoomx, zoomy); - else - draw_image_buffer(C, sima, ar, scene, ibuf, x, y, zoomx, zoomy); - - /* only draw until running out of time */ - if ((PIL_check_seconds_timer() - time_current) > 0.25) - return; - } + if (sima->flag & SI_USE_ALPHA) + GPU_blend(false); } } @@ -701,134 +573,62 @@ void draw_image_sample_line(SpaceImage *sima) if (sima->sample_line_hist.flag & HISTO_FLAG_SAMPLELINE) { Histogram *hist = &sima->sample_line_hist; - glBegin(GL_LINES); - glColor3ub(0, 0, 0); - glVertex2fv(hist->co[0]); - glVertex2fv(hist->co[1]); - glEnd(); - - setlinestyle(1); - glBegin(GL_LINES); - glColor3ub(255, 255, 255); - glVertex2fv(hist->co[0]); - glVertex2fv(hist->co[1]); - glEnd(); - setlinestyle(0); + GPUVertFormat *format = immVertexFormat(); + uint shdr_dashed_pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); - } -} + immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR); -/* XXX becomes WM paint cursor */ -#if 0 -static void draw_image_view_tool(Scene *scene) -{ - ToolSettings *settings = scene->toolsettings; - Brush *brush = settings->imapaint.brush; - int mval[2]; - float radius; - int draw = 0; - - if (brush) { - if (settings->imapaint.flag & IMAGEPAINT_DRAWING) { - if (settings->imapaint.flag & IMAGEPAINT_DRAW_TOOL_DRAWING) - draw = 1; - } - else if (settings->imapaint.flag & IMAGEPAINT_DRAW_TOOL) - draw = 1; + float viewport_size[4]; + GPU_viewport_size_get_f(viewport_size); + immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC); - if (draw) { - getmouseco_areawin(mval); + immUniform1i("colors_len", 2); /* Advanced dashes. */ + immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2); + immUniform1f("dash_width", 2.0f); - radius = BKE_brush_size_get(brush) * G.sima->zoom; - fdrawXORcirc(mval[0], mval[1], radius); + immBegin(GPU_PRIM_LINES, 2); + immVertex2fv(shdr_dashed_pos, hist->co[0]); + immVertex2fv(shdr_dashed_pos, hist->co[1]); + immEnd(); - if (brush->innerradius != 1.0) { - radius *= brush->innerradius; - fdrawXORcirc(mval[0], mval[1], radius); - } - } + immUnbindProgram(); } } -#endif - -static unsigned char *get_alpha_clone_image(const bContext *C, Scene *scene, int *width, int *height) -{ - Brush *brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint); - ImBuf *ibuf; - unsigned int size, alpha; - unsigned char *display_buffer; - unsigned char *rect, *cp; - void *cache_handle; - - if (!brush || !brush->clone.image) - return NULL; - - ibuf = BKE_image_acquire_ibuf(brush->clone.image, NULL, NULL); - - if (!ibuf) - return NULL; - - display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); - - if (!display_buffer) { - BKE_image_release_ibuf(brush->clone.image, ibuf, NULL); - IMB_display_buffer_release(cache_handle); - - return NULL; - } - - rect = MEM_dupallocN(display_buffer); - - IMB_display_buffer_release(cache_handle); - - if (!rect) { - BKE_image_release_ibuf(brush->clone.image, ibuf, NULL); - return NULL; - } - - *width = ibuf->x; - *height = ibuf->y; - - size = (*width) * (*height); - alpha = (unsigned char)255 * brush->clone.alpha; - cp = rect; - - while (size-- > 0) { - cp[3] = alpha; - cp += 4; - } - - BKE_image_release_ibuf(brush->clone.image, ibuf, NULL); - - return rect; -} static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scene, float zoomx, float zoomy) { Brush *brush; - int x, y, w, h; - unsigned char *clonerect; + int x, y; + ImBuf *ibuf; brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint); - if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) { - /* this is not very efficient, but glDrawPixels doesn't allow - * drawing with alpha */ - clonerect = get_alpha_clone_image(C, scene, &w, &h); + if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE) && brush->clone.image) { + ibuf = BKE_image_acquire_ibuf(brush->clone.image, NULL, NULL); - if (clonerect) { + if (ibuf) { + void *cache_handle = NULL; + float col[4] = {1.0f, 1.0f, 1.0f, brush->clone.alpha}; UI_view2d_view_to_region(&ar->v2d, brush->clone.offset[0], brush->clone.offset[1], &x, &y); - glPixelZoom(zoomx, zoomy); + unsigned char *display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, clonerect); - glDisable(GL_BLEND); + if (!display_buffer) { + BKE_image_release_ibuf(brush->clone.image, ibuf, NULL); + IMB_display_buffer_release(cache_handle); + return; + } - glPixelZoom(1.0, 1.0); + GPU_blend(true); + GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); - MEM_freeN(clonerect); + IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR); + immDrawPixelsTex(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer, zoomx, zoomy, col); + + GPU_blend(false); + + BKE_image_release_ibuf(brush->clone.image, ibuf, NULL); + IMB_display_buffer_release(cache_handle); } } } @@ -899,13 +699,7 @@ void draw_image_main(const bContext *C, ARegion *ar) ED_region_grid_draw(ar, zoomx, zoomy); } else { - - if (sima->flag & SI_DRAW_TILE) - draw_image_buffer_repeated(C, sima, ar, scene, ima, ibuf, zoomx, zoomy); - else if (ima && (ima->tpageflag & IMA_TILES)) - draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, 0.0f, 0.0, zoomx, zoomy); - else - draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy); + draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy); if (sima->flag & SI_DRAW_METADATA) { int x, y; @@ -924,23 +718,6 @@ void draw_image_main(const bContext *C, ARegion *ar) if (show_paint) draw_image_paint_helpers(C, ar, scene, zoomx, zoomy); - /* XXX integrate this code */ -#if 0 - if (ibuf) { - float xoffs = 0.0f, yoffs = 0.0f; - - if (image_preview_active(sa, &xim, &yim)) { - xoffs = scene->r.disprect.xmin; - yoffs = scene->r.disprect.ymin; - glColor3ub(0, 0, 0); - calc_image_view(sima, 'f'); - myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax); - glRectf(0.0f, 0.0f, 1.0f, 1.0f); - glLoadIdentity(); - } - } -#endif - if (show_viewer) { BLI_thread_unlock(LOCK_DRAW_IMAGE); } @@ -982,8 +759,8 @@ void draw_image_cache(const bContext *C, ARegion *ar) mask = ED_space_image_get_mask(sima); } - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + GPU_blend(true); + GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA); /* Draw cache background. */ ED_region_cache_draw_background(ar); @@ -997,13 +774,17 @@ void draw_image_cache(const bContext *C, ARegion *ar) ED_region_cache_draw_cached_segments(ar, num_segments, points, sfra + sima->iuser.offset, efra + sima->iuser.offset); } - glDisable(GL_BLEND); + GPU_blend(false); /* Draw current frame. */ x = (cfra - sfra) / (efra - sfra + 1) * ar->winx; - UI_ThemeColor(TH_CFRAME); - glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC); + uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + immUniformThemeColor(TH_CFRAME); + immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC); + immUnbindProgram(); + ED_region_cache_draw_curfra_label(cfra, x, 8.0f * UI_DPI_FAC); if (mask != NULL) { diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c index 5eaefcc9bb2..96c3f55df92 100644 --- a/source/blender/editors/space_image/image_edit.c +++ b/source/blender/editors/space_image/image_edit.c @@ -34,17 +34,20 @@ #include "DNA_scene_types.h" #include "BLI_rect.h" +#include "BLI_listbase.h" #include "BKE_colortools.h" #include "BKE_context.h" +#include "BKE_editmesh.h" #include "BKE_global.h" #include "BKE_image.h" -#include "BKE_editmesh.h" #include "BKE_library.h" #include "BKE_main.h" #include "IMB_imbuf_types.h" +#include "DEG_depsgraph.h" + #include "ED_image.h" /* own include */ #include "ED_mesh.h" #include "ED_screen.h" @@ -62,11 +65,8 @@ Image *ED_space_image(SpaceImage *sima) } /* called to assign images to UV faces */ -void ED_space_image_set(Main *bmain, SpaceImage *sima, Scene *scene, Object *obedit, Image *ima) +void ED_space_image_set(Main *bmain, SpaceImage *sima, Scene *UNUSED(scene), Object *obedit, Image *ima) { - /* context may be NULL, so use global */ - ED_uvedit_assign_image(bmain, scene, obedit, ima, sima->image); - /* change the space ima after because uvedit_face_visible_test uses the space ima * to check if the face is displayed in UV-localview */ sima->image = ima; @@ -303,17 +303,19 @@ bool ED_image_slot_cycle(struct Image *image, int direction) BLI_assert(ELEM(direction, -1, 1)); - for (i = 1; i < IMA_MAX_RENDER_SLOT; i++) { - slot = (cur + ((direction == -1) ? -i : i)) % IMA_MAX_RENDER_SLOT; - if (slot < 0) slot += IMA_MAX_RENDER_SLOT; + int num_slots = BLI_listbase_count(&image->renderslots); + for (i = 1; i < num_slots; i++) { + slot = (cur + ((direction == -1) ? -i : i)) % num_slots; + if (slot < 0) slot += num_slots; - if (image->renders[slot] || slot == image->last_render_slot) { + RenderSlot *render_slot = BKE_image_get_renderslot(image, slot); + if ((render_slot && render_slot->render) || slot == image->last_render_slot) { image->render_slot = slot; break; } } - if (i == IMA_MAX_RENDER_SLOT) { + if (i == num_slots) { image->render_slot = ((cur == 1) ? 0 : 1); } @@ -359,8 +361,14 @@ bool ED_space_image_show_paint(SpaceImage *sima) bool ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit) { - if (sima && (ED_space_image_show_render(sima) || ED_space_image_show_paint(sima))) - return false; + if (sima) { + if (ED_space_image_show_render(sima)) { + return false; + } + if (sima->mode != SI_MODE_UV) { + return false; + } + } if (obedit && obedit->type == OB_MESH) { struct BMEditMesh *em = BKE_editmesh_from_object(obedit); @@ -375,10 +383,10 @@ bool ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit) } /* matches clip function */ -bool ED_space_image_check_show_maskedit(Scene *scene, SpaceImage *sima) +bool ED_space_image_check_show_maskedit(SpaceImage *sima, ViewLayer *view_layer) { /* check editmode - this is reserved for UV editing */ - Object *ob = OBACT; + Object *ob = OBACT(view_layer); if (ob && ob->mode & OB_MODE_EDIT && ED_space_image_show_uvedit(sima, ob)) { return false; } @@ -391,8 +399,8 @@ bool ED_space_image_maskedit_poll(bContext *C) SpaceImage *sima = CTX_wm_space_image(C); if (sima) { - Scene *scene = CTX_data_scene(C); - return ED_space_image_check_show_maskedit(scene, sima); + ViewLayer *view_layer = CTX_data_view_layer(C); + return ED_space_image_check_show_maskedit(sima, view_layer); } return false; diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index f7fec4ed396..5d9c496d584 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -83,6 +83,9 @@ void IMAGE_OT_unpack(struct wmOperatorType *ot); void IMAGE_OT_invert(struct wmOperatorType *ot); void IMAGE_OT_cycle_render_slot(struct wmOperatorType *ot); +void IMAGE_OT_clear_render_slot(struct wmOperatorType *ot); +void IMAGE_OT_add_render_slot(struct wmOperatorType *ot); +void IMAGE_OT_remove_render_slot(struct wmOperatorType *ot); void IMAGE_OT_sample(struct wmOperatorType *ot); void IMAGE_OT_sample_line(struct wmOperatorType *ot); @@ -90,7 +93,7 @@ void IMAGE_OT_curves_point_set(struct wmOperatorType *ot); void IMAGE_OT_change_frame(struct wmOperatorType *ot); -void IMAGE_OT_read_renderlayers(struct wmOperatorType *ot); +void IMAGE_OT_read_viewlayers(struct wmOperatorType *ot); void IMAGE_OT_render_border(struct wmOperatorType *ot); void IMAGE_OT_clear_render_border(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index df303a7bf11..67727c661a0 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -48,6 +48,7 @@ #include "BLT_translation.h" +#include "DNA_camera_types.h" #include "DNA_object_types.h" #include "DNA_node_types.h" #include "DNA_packedFile_types.h" @@ -56,8 +57,6 @@ #include "BKE_colortools.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" -#include "BKE_DerivedMesh.h" #include "BKE_icons.h" #include "BKE_image.h" #include "BKE_global.h" @@ -70,8 +69,9 @@ #include "BKE_sound.h" #include "BKE_scene.h" +#include "DEG_depsgraph.h" + #include "GPU_draw.h" -#include "GPU_buffers.h" #include "IMB_colormanagement.h" #include "IMB_imbuf.h" @@ -277,8 +277,9 @@ static bool space_image_main_area_not_uv_brush_poll(bContext *C) Scene *scene = CTX_data_scene(C); ToolSettings *toolsettings = scene->toolsettings; - if (sima && !toolsettings->uvsculpt && !scene->obedit) + if (sima && !toolsettings->uvsculpt && (CTX_data_edit_object(C) == NULL)) { return 1; + } return 0; } @@ -287,13 +288,12 @@ static bool image_sample_poll(bContext *C) { SpaceImage *sima = CTX_wm_space_image(C); if (sima) { - Scene *scene = CTX_data_scene(C); Object *obedit = CTX_data_edit_object(C); - ToolSettings *toolsettings = scene->toolsettings; - if (obedit) { - if (ED_space_image_show_uvedit(sima, obedit) && (toolsettings->use_uv_sculpt)) + /* Disable when UV editing so it doesn't swallow all click events (use for setting cursor). */ + if (ED_space_image_show_uvedit(sima, obedit)) { return false; + } } else if (sima->mode != SI_MODE_VIEW) { return false; @@ -421,7 +421,7 @@ static void image_view_pan_cancel(bContext *C, wmOperator *op) void IMAGE_OT_view_pan(wmOperatorType *ot) { /* identifiers */ - ot->name = "View Pan"; + ot->name = "Pan View"; ot->idname = "IMAGE_OT_view_pan"; ot->description = "Pan the view"; @@ -637,7 +637,7 @@ void IMAGE_OT_view_zoom(wmOperatorType *ot) PropertyRNA *prop; /* identifiers */ - ot->name = "View Zoom"; + ot->name = "Zoom View"; ot->idname = "IMAGE_OT_view_zoom"; ot->description = "Zoom in/out the image"; @@ -792,6 +792,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) SpaceImage *sima; ARegion *ar; Scene *scene; + ViewLayer *view_layer; Object *obedit; Image *ima; @@ -799,6 +800,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) sima = CTX_wm_space_image(C); ar = CTX_wm_region(C); scene = CTX_data_scene(C); + view_layer = CTX_data_view_layer(C); obedit = CTX_data_edit_object(C); ima = ED_space_image(sima); @@ -810,7 +812,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; } } - else if (ED_space_image_check_show_maskedit(scene, sima)) { + else if (ED_space_image_check_show_maskedit(sima, view_layer)) { if (!ED_mask_selected_minmax(C, min, max)) { return OPERATOR_CANCELLED; } @@ -1038,15 +1040,15 @@ void IMAGE_OT_view_zoom_border(wmOperatorType *ot) ot->idname = "IMAGE_OT_view_zoom_border"; /* api callbacks */ - ot->invoke = WM_gesture_border_invoke; + ot->invoke = WM_gesture_box_invoke; ot->exec = image_view_zoom_border_exec; - ot->modal = WM_gesture_border_modal; - ot->cancel = WM_gesture_border_cancel; + ot->modal = WM_gesture_box_modal; + ot->cancel = WM_gesture_box_cancel; ot->poll = space_image_main_region_poll; /* rna */ - WM_operator_properties_gesture_border_zoom(ot); + WM_operator_properties_gesture_box_zoom(ot); } /**************** load/replace/save callbacks ******************/ @@ -1228,7 +1230,6 @@ static int image_open_exec(bContext *C, wmOperator *op) Object *obedit = CTX_data_edit_object(C); ImageUser *iuser = NULL; ImageOpenData *iod = op->customdata; - PointerRNA idptr; Image *ima = NULL; char filepath[FILE_MAX]; int frame_seq_len = 0; @@ -1294,8 +1295,9 @@ static int image_open_exec(bContext *C, wmOperator *op) * pointer use also increases user, so this compensates it */ id_us_min(&ima->id); - RNA_id_pointer_create(&ima->id, &idptr); - RNA_property_pointer_set(&iod->pprop.ptr, iod->pprop.prop, idptr); + PointerRNA imaptr; + RNA_id_pointer_create(&ima->id, &imaptr); + RNA_property_pointer_set(&iod->pprop.ptr, iod->pprop.prop, imaptr); RNA_property_update(C, &iod->pprop.ptr, iod->pprop.prop); } @@ -1307,21 +1309,23 @@ static int image_open_exec(bContext *C, wmOperator *op) ED_space_image_set(bmain, sima, scene, obedit, ima); iuser = &sima->iuser; } - else if (sa && sa->spacetype == SPACE_VIEW3D) { - View3D *v3d = sa->spacedata.first; - - for (BGpic *bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { - if (bgpic->ima == ima) { - iuser = &bgpic->iuser; - break; - } - } - } else { Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data; if (tex && tex->type == TEX_IMAGE) { iuser = &tex->iuser; } + + if (iuser == NULL) { + Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data; + if (cam) { + for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) { + if (bgpic->ima == ima) { + iuser = &bgpic->iuser; + break; + } + } + } + } } /* initialize because of new image */ @@ -1335,7 +1339,6 @@ static int image_open_exec(bContext *C, wmOperator *op) else { iuser->offset = frame_ofs - 1; } - iuser->fie_ima = 2; iuser->scene = scene; BKE_image_init_imageuser(ima, iuser); } @@ -1425,7 +1428,7 @@ static void image_open_draw(bContext *UNUSED(C), wmOperator *op) /* main draw call */ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); - uiDefAutoButsRNA(layout, &ptr, image_open_draw_check_prop, NULL, '\0'); + uiDefAutoButsRNA(layout, &ptr, image_open_draw_check_prop, NULL, UI_BUT_LABEL_ALIGN_NONE, false); /* image template */ RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr); @@ -1491,7 +1494,7 @@ static int image_match_len_exec(bContext *C, wmOperator *UNUSED(op)) if (!anim) return OPERATOR_CANCELLED; iuser->frames = IMB_anim_get_duration(anim, IMB_TC_RECORD_RUN); - BKE_image_user_frame_calc(iuser, scene->r.cfra, 0); + BKE_image_user_frame_calc(iuser, scene->r.cfra); return OPERATOR_FINISHED; } @@ -2147,7 +2150,7 @@ static void image_save_as_draw(bContext *UNUSED(C), wmOperator *op) /* main draw call */ RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); - uiDefAutoButsRNA(layout, &ptr, image_save_as_draw_check_prop, NULL, '\0'); + uiDefAutoButsRNA(layout, &ptr, image_save_as_draw_check_prop, NULL, UI_BUT_LABEL_ALIGN_NONE, false); /* multiview template */ if (is_multiview) @@ -2349,7 +2352,7 @@ static int image_reload_exec(bContext *C, wmOperator *UNUSED(op)) // XXX other users? BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_RELOAD); - DAG_id_tag_update(&ima->id, 0); + DEG_id_tag_update(&ima->id, 0); WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); @@ -2379,6 +2382,30 @@ enum { GEN_CONTEXT_PAINT_STENCIL = 2 }; +typedef struct ImageNewData { + PropertyPointerRNA pprop; +} ImageNewData; + +static ImageNewData *image_new_init(bContext *C, wmOperator *op) +{ + if (op->customdata) { + return op->customdata; + } + + ImageNewData *data = MEM_callocN(sizeof(ImageNewData), __func__); + UI_context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop); + op->customdata = data; + return data; +} + +static void image_new_free(wmOperator *op) +{ + if (op->customdata) { + MEM_freeN(op->customdata); + op->customdata = NULL; + } +} + static int image_new_exec(bContext *C, wmOperator *op) { SpaceImage *sima; @@ -2386,13 +2413,11 @@ static int image_new_exec(bContext *C, wmOperator *op) Object *obedit; Image *ima; Main *bmain; - PointerRNA ptr, idptr; PropertyRNA *prop; char name_buffer[MAX_ID_NAME - 2]; const char *name; float color[4]; int width, height, floatbuf, gen_type, alpha; - int gen_context; int stereo3d; /* retrieve state */ @@ -2416,7 +2441,6 @@ static int image_new_exec(bContext *C, wmOperator *op) gen_type = RNA_enum_get(op->ptr, "generated_type"); RNA_float_get_array(op->ptr, "color", color); alpha = RNA_boolean_get(op->ptr, "alpha"); - gen_context = RNA_enum_get(op->ptr, "gen_context"); stereo3d = RNA_boolean_get(op->ptr, "use_stereo_3d"); if (!alpha) @@ -2424,83 +2448,47 @@ static int image_new_exec(bContext *C, wmOperator *op) ima = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color, stereo3d); - if (!ima) + if (!ima) { + image_new_free(op); return OPERATOR_CANCELLED; + } /* hook into UI */ - UI_context_active_but_prop_get_templateID(C, &ptr, &prop); + ImageNewData *data = image_new_init(C, op); - if (prop) { + if (data->pprop.prop) { /* when creating new ID blocks, use is already 1, but RNA * pointer use also increases user, so this compensates it */ id_us_min(&ima->id); - RNA_id_pointer_create(&ima->id, &idptr); - RNA_property_pointer_set(&ptr, prop, idptr); - RNA_property_update(C, &ptr, prop); + PointerRNA imaptr; + RNA_id_pointer_create(&ima->id, &imaptr); + RNA_property_pointer_set(&data->pprop.ptr, data->pprop.prop, imaptr); + RNA_property_update(C, &data->pprop.ptr, data->pprop.prop); } else if (sima) { ED_space_image_set(bmain, sima, scene, obedit, ima); } - else if (gen_context == GEN_CONTEXT_PAINT_CANVAS) { - bScreen *sc; - Object *ob = CTX_data_active_object(C); - - GPU_drawobject_free(ob->derivedFinal); - if (scene->toolsettings->imapaint.canvas) - id_us_min(&scene->toolsettings->imapaint.canvas->id); - scene->toolsettings->imapaint.canvas = ima; - - for (sc = bmain->screen.first; sc; sc = sc->id.next) { - ScrArea *sa; - for (sa = sc->areabase.first; sa; sa = sa->next) { - SpaceLink *sl; - for (sl = sa->spacedata.first; sl; sl = sl->next) { - if (sl->spacetype == SPACE_IMAGE) { - SpaceImage *sima_other = (SpaceImage *)sl; - - if (!sima_other->pin) { - ED_space_image_set(bmain, sima_other, scene, scene->obedit, ima); - } - } - } - } - } - BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); - WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL); - } - else if (gen_context == GEN_CONTEXT_PAINT_STENCIL) { - Object *ob = CTX_data_active_object(C); - if (scene->toolsettings->imapaint.stencil) - id_us_min(&scene->toolsettings->imapaint.stencil->id); - scene->toolsettings->imapaint.stencil = ima; - BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); - WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL); - } - else { - Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data; - if (tex && tex->type == TEX_IMAGE) { - if (tex->ima) - id_us_min(&tex->ima->id); - tex->ima = ima; - ED_area_tag_redraw(CTX_wm_area(C)); - } - } BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_USER_NEW_IMAGE); WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima); + image_new_free(op); + return OPERATOR_FINISHED; } -/* XXX, Ton is not a fan of OK buttons but using this function to avoid undo/redo bug while in mesh-editmode, - campbell */ -/* XXX Note: the WM_operator_props_dialog_popup() doesn't work for UI_context_active_but_prop_get_templateID(), image is not being that way */ static int image_new_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) { + /* Get property in advance, it doesn't work after WM_operator_props_dialog_popup. */ + ImageNewData *data; + op->customdata = data = MEM_callocN(sizeof(ImageNewData), __func__); + UI_context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop); + /* Better for user feedback. */ RNA_string_set(op->ptr, "name", DATA_(IMA_DEF_NAME)); - return WM_operator_props_dialog_popup(C, op, 15 * UI_UNIT_X, 5 * UI_UNIT_Y); + return WM_operator_props_dialog_popup(C, op, 300, 100); } static void image_new_draw(bContext *UNUSED(C), wmOperator *op) @@ -2550,18 +2538,16 @@ static void image_new_draw(bContext *UNUSED(C), wmOperator *op) #endif } +static void image_new_cancel(bContext *UNUSED(C), wmOperator *op) +{ + image_new_free(op); +} + void IMAGE_OT_new(wmOperatorType *ot) { PropertyRNA *prop; static float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - static const EnumPropertyItem gen_context_items[] = { - {GEN_CONTEXT_NONE, "NONE", 0, "None", ""}, - {GEN_CONTEXT_PAINT_CANVAS, "PAINT_CANVAS", 0, "Paint Canvas", ""}, - {GEN_CONTEXT_PAINT_STENCIL, "PAINT_STENCIL", 0, "Paint Stencil", ""}, - {0, NULL, 0, NULL, NULL} - }; - /* identifiers */ ot->name = "New Image"; ot->description = "Create a new image"; @@ -2571,6 +2557,7 @@ void IMAGE_OT_new(wmOperatorType *ot) ot->exec = image_new_exec; ot->invoke = image_new_invoke; ot->ui = image_new_draw; + ot->cancel = image_new_cancel; /* flags */ ot->flag = OPTYPE_UNDO; @@ -2588,7 +2575,6 @@ void IMAGE_OT_new(wmOperatorType *ot) RNA_def_enum(ot->srna, "generated_type", rna_enum_image_generated_type_items, IMA_GENTYPE_BLANK, "Generated Type", "Fill the image with a grid for UV map testing"); RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth"); - prop = RNA_def_enum(ot->srna, "gen_context", gen_context_items, 0, "Gen Context", "Generation context"); RNA_def_property_flag(prop, PROP_HIDDEN); prop = RNA_def_boolean(ot->srna, "use_stereo_3d", 0, "Stereo 3D", "Create an image with left and right views"); RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN); @@ -3461,7 +3447,8 @@ static int image_cycle_render_slot_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL); /* no undo push for browsing existing */ - if (ima->renders[ima->render_slot] || ima->render_slot == ima->last_render_slot) + RenderSlot *slot = BKE_image_get_renderslot(ima, ima->render_slot); + if ((slot && slot->render) || ima->render_slot == ima->last_render_slot) return OPERATOR_CANCELLED; return OPERATOR_FINISHED; @@ -3484,6 +3471,97 @@ void IMAGE_OT_cycle_render_slot(wmOperatorType *ot) RNA_def_boolean(ot->srna, "reverse", 0, "Cycle in Reverse", ""); } +/********************* clear render slot operator *********************/ + +static int image_clear_render_slot_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceImage *sima = CTX_wm_space_image(C); + Image *ima = CTX_data_edit_image(C); + + if (!BKE_image_clear_renderslot(ima, &sima->iuser, ima->render_slot)) { + return OPERATOR_CANCELLED; + } + + WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL); + + return OPERATOR_FINISHED; +} + +void IMAGE_OT_clear_render_slot(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Clear Render Slot"; + ot->idname = "IMAGE_OT_clear_render_slot"; + ot->description = "Clear the currently selected render slot"; + + /* api callbacks */ + ot->exec = image_clear_render_slot_exec; + ot->poll = image_cycle_render_slot_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER; +} + +/********************* add render slot operator *********************/ + +static int image_add_render_slot_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Image *ima = CTX_data_edit_image(C); + + RenderSlot *slot = BKE_image_add_renderslot(ima, NULL); + ima->render_slot = BLI_findindex(&ima->renderslots, slot); + + WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL); + + return OPERATOR_FINISHED; +} + +void IMAGE_OT_add_render_slot(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Add Render Slot"; + ot->idname = "IMAGE_OT_add_render_slot"; + ot->description = "Add a new render slot"; + + /* api callbacks */ + ot->exec = image_add_render_slot_exec; + ot->poll = image_cycle_render_slot_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER; +} + +/********************* remove render slot operator *********************/ + +static int image_remove_render_slot_exec(bContext *C, wmOperator *UNUSED(op)) +{ + SpaceImage *sima = CTX_wm_space_image(C); + Image *ima = CTX_data_edit_image(C); + + if (!BKE_image_remove_renderslot(ima, &sima->iuser, ima->render_slot)) { + return OPERATOR_CANCELLED; + } + + WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL); + + return OPERATOR_FINISHED; +} + +void IMAGE_OT_remove_render_slot(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Remove Render Slot"; + ot->idname = "IMAGE_OT_remove_render_slot"; + ot->description = "Remove the current render slot"; + + /* api callbacks */ + ot->exec = image_remove_render_slot_exec; + ot->poll = image_cycle_render_slot_poll; + + /* flags */ + ot->flag = OPTYPE_REGISTER; +} + /********************** change frame operator *********************/ static bool change_frame_poll(bContext *C) @@ -3602,7 +3680,7 @@ void IMAGE_OT_change_frame(wmOperatorType *ot) /* Reload cached render results... */ /* goes over all scenes, reads render layers */ -static int image_read_renderlayers_exec(bContext *C, wmOperator *UNUSED(op)) +static int image_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); @@ -3620,14 +3698,14 @@ static int image_read_renderlayers_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_FINISHED; } -void IMAGE_OT_read_renderlayers(wmOperatorType *ot) +void IMAGE_OT_read_viewlayers(wmOperatorType *ot) { - ot->name = "Read Render Layers"; - ot->idname = "IMAGE_OT_read_renderlayers"; - ot->description = "Read all the current scene's render layers from cache, as needed"; + ot->name = "Open Cached Render"; + ot->idname = "IMAGE_OT_read_viewlayers"; + ot->description = "Read all the current scene's view layers from cache, as needed"; ot->poll = space_image_main_region_poll; - ot->exec = image_read_renderlayers_exec; + ot->exec = image_read_viewlayers_exec; /* flags */ ot->flag = 0; @@ -3691,10 +3769,10 @@ void IMAGE_OT_render_border(wmOperatorType *ot) ot->idname = "IMAGE_OT_render_border"; /* api callbacks */ - ot->invoke = WM_gesture_border_invoke; + ot->invoke = WM_gesture_box_invoke; ot->exec = render_border_exec; - ot->modal = WM_gesture_border_modal; - ot->cancel = WM_gesture_border_cancel; + ot->modal = WM_gesture_box_modal; + ot->cancel = WM_gesture_box_cancel; ot->poll = image_cycle_render_slot_poll; /* flags */ diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index fd661883f79..01d2fc28c6b 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -44,10 +44,16 @@ #include "BKE_colortools.h" #include "BKE_context.h" +#include "BKE_editmesh.h" #include "BKE_image.h" +#include "BKE_layer.h" #include "BKE_library.h" +#include "BKE_material.h" #include "BKE_scene.h" #include "BKE_screen.h" +#include "BKE_workspace.h" + +#include "DEG_depsgraph.h" #include "IMB_imbuf_types.h" @@ -59,6 +65,7 @@ #include "ED_space_api.h" #include "ED_screen.h" #include "ED_uvedit.h" +#include "ED_transform.h" #include "BIF_gl.h" @@ -66,12 +73,14 @@ #include "WM_api.h" #include "WM_types.h" +#include "WM_message.h" #include "UI_resources.h" #include "UI_interface.h" #include "UI_view2d.h" #include "image_intern.h" +#include "GPU_framebuffer.h" /**************************** common state *****************************/ @@ -156,7 +165,7 @@ ARegion *image_has_tools_region(ScrArea *sa) /* ******************** default callbacks for image space ***************** */ -static SpaceLink *image_new(const bContext *UNUSED(C)) +static SpaceLink *image_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene)) { ARegion *ar; SpaceImage *simage; @@ -165,12 +174,11 @@ static SpaceLink *image_new(const bContext *UNUSED(C)) simage->spacetype = SPACE_IMAGE; simage->zoom = 1.0f; simage->lock = true; - simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA; + simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA | SI_COORDFLOATS; simage->iuser.ok = true; - simage->iuser.fie_ima = 2; simage->iuser.frames = 100; - simage->iuser.flag = IMA_SHOW_STEREO; + simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS; scopes_new(&simage->scopes); simage->sample_line_hist.height = 100; @@ -180,7 +188,7 @@ static SpaceLink *image_new(const bContext *UNUSED(C)) BLI_addtail(&simage->regionbase, ar); ar->regiontype = RGN_TYPE_HEADER; - ar->alignment = RGN_ALIGN_BOTTOM; + ar->alignment = RGN_ALIGN_TOP; /* buttons/list view */ ar = MEM_callocN(sizeof(ARegion), "buttons for image"); @@ -265,6 +273,9 @@ static void image_operatortypes(void) WM_operatortype_append(IMAGE_OT_invert); WM_operatortype_append(IMAGE_OT_cycle_render_slot); + WM_operatortype_append(IMAGE_OT_clear_render_slot); + WM_operatortype_append(IMAGE_OT_add_render_slot); + WM_operatortype_append(IMAGE_OT_remove_render_slot); WM_operatortype_append(IMAGE_OT_sample); WM_operatortype_append(IMAGE_OT_sample_line); @@ -275,106 +286,19 @@ static void image_operatortypes(void) WM_operatortype_append(IMAGE_OT_change_frame); - WM_operatortype_append(IMAGE_OT_read_renderlayers); + WM_operatortype_append(IMAGE_OT_read_viewlayers); WM_operatortype_append(IMAGE_OT_render_border); WM_operatortype_append(IMAGE_OT_clear_render_border); } static void image_keymap(struct wmKeyConfig *keyconf) { - wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Image Generic", SPACE_IMAGE, 0); - wmKeyMapItem *kmi; - int i; - - WM_keymap_add_item(keymap, "IMAGE_OT_new", NKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_open", OKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_reload", RKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_read_renderlayers", RKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_save", SKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_save_as", F3KEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_properties", NKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_toolshelf", TKEY, KM_PRESS, 0, 0); - - WM_keymap_add_item(keymap, "IMAGE_OT_cycle_render_slot", JKEY, KM_PRESS, 0, 0); - RNA_boolean_set(WM_keymap_add_item(keymap, "IMAGE_OT_cycle_render_slot", JKEY, KM_PRESS, KM_ALT, 0)->ptr, "reverse", true); - - keymap = WM_keymap_ensure(keyconf, "Image", SPACE_IMAGE, 0); - - WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); - - kmi = WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, KM_SHIFT, 0); - RNA_boolean_set(kmi->ptr, "fit_view", true); - - WM_keymap_add_item(keymap, "IMAGE_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_pan", MOUSEPAN, 0, 0, 0); - -#ifdef WITH_INPUT_NDOF - WM_keymap_add_item(keymap, "IMAGE_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0); // or view selected? - WM_keymap_add_item(keymap, "IMAGE_OT_view_ndof", NDOF_MOTION, 0, 0, 0); -#endif - - WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", WHEELINMOUSE, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", WHEELOUTMOUSE, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_in", PADPLUSKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_out", PADMINUS, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MOUSEZOOM, 0, 0, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom", MOUSEPAN, 0, KM_CTRL, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0); - - /* ctrl now works as well, shift + numpad works as arrow keys on Windows */ - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 8.0f); - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 4.0f); - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_CTRL, 0)->ptr, "ratio", 2.0f); - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f); - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f); - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f); - - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f); - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f); - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f); - RNA_float_set(WM_keymap_add_item(keymap, "IMAGE_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f); - - WM_keymap_add_item(keymap, "IMAGE_OT_change_frame", LEFTMOUSE, KM_PRESS, 0, 0); - - WM_keymap_add_item(keymap, "IMAGE_OT_sample", ACTIONMOUSE, KM_PRESS, 0, 0); - RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_curves_point_set", ACTIONMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "point", 0); - RNA_enum_set(WM_keymap_add_item(keymap, "IMAGE_OT_curves_point_set", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "point", 1); - - /* toggle editmode is handy to have while UV unwrapping */ - kmi = WM_keymap_add_item(keymap, "OBJECT_OT_mode_set", TABKEY, KM_PRESS, 0, 0); - RNA_enum_set(kmi->ptr, "mode", OB_MODE_EDIT); - RNA_boolean_set(kmi->ptr, "toggle", true); - - /* fast switch to render slots */ - for (i = 0; i < MIN2(IMA_MAX_RENDER_SLOT, 9); i++) { - kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_int", ONEKEY + i, KM_PRESS, 0, 0); - RNA_string_set(kmi->ptr, "data_path", "space_data.image.render_slots.active_index"); - RNA_int_set(kmi->ptr, "value", i); - } - - /* pivot */ - kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0); - RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point"); - RNA_string_set(kmi->ptr, "value", "CENTER"); - - kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0); - RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point"); - RNA_string_set(kmi->ptr, "value", "MEDIAN"); - - kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0); - RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point"); - RNA_string_set(kmi->ptr, "value", "CURSOR"); - - /* render border */ - WM_keymap_add_item(keymap, "IMAGE_OT_render_border", BKEY, KM_PRESS, KM_CTRL, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_clear_render_border", BKEY, KM_PRESS, KM_CTRL | KM_ALT, 0); + WM_keymap_ensure(keyconf, "Image Generic", SPACE_IMAGE, 0); + WM_keymap_ensure(keyconf, "Image", SPACE_IMAGE, 0); } /* dropboxes */ -static bool image_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event)) +static bool image_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event), const char **UNUSED(tooltip)) { if (drag->type == WM_DRAG_PATH) if (ELEM(drag->icon, 0, ICON_FILE_IMAGE, ICON_FILE_MOVIE, ICON_FILE_BLANK)) /* rule might not work? */ @@ -404,12 +328,11 @@ static void image_refresh(const bContext *C, ScrArea *sa) { Scene *scene = CTX_data_scene(C); SpaceImage *sima = sa->spacedata.first; - Object *obedit = CTX_data_edit_object(C); Image *ima; ima = ED_space_image(sima); - BKE_image_user_check_frame_calc(&sima->iuser, scene->r.cfra, 0); + BKE_image_user_check_frame_calc(&sima->iuser, scene->r.cfra); /* check if we have to set the image from the editmesh */ if (ima && (ima->source == IMA_SRC_VIEWER && sima->mode == SI_MODE_MASK)) { @@ -420,38 +343,10 @@ static void image_refresh(const bContext *C, ScrArea *sa) } } } - else if (ima && (ima->source == IMA_SRC_VIEWER || sima->pin)) { - /* pass */ - } - else if (obedit && obedit->type == OB_MESH) { - Mesh *me = (Mesh *)obedit->data; - struct BMEditMesh *em = me->edit_btmesh; - bool sloppy = true; /* partially selected face is ok */ - bool selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* only selected active face? */ - - if (BKE_scene_use_new_shading_nodes(scene)) { - /* new shading system does not alter image */ - } - else { - /* old shading system, we set texface */ - if (em && EDBM_uv_check(em)) { - MTexPoly *tf; - if (EDBM_uv_active_face_get(em, sloppy, selected, &tf)) { - /* don't need to check for pin here, see above */ - sima->image = tf->tpage; - - if ((sima->flag & SI_EDITTILE) == 0) { - sima->curtile = tf->tile; - } - } - } - } - } } -static void image_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn) +static void image_listener(wmWindow *win, ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene)) { - Scene *scene = sc->scene; SpaceImage *sima = (SpaceImage *)sa->spacedata.first; /* context changes */ @@ -544,7 +439,8 @@ static void image_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn) case ND_TRANSFORM: case ND_MODIFIER: { - Object *ob = OBACT; + ViewLayer *view_layer = WM_window_get_active_view_layer(win); + Object *ob = OBACT(view_layer); if (ob && (ob == wmn->reference) && (ob->mode & OB_MODE_EDIT)) { if (sima->lock && (sima->flag & SI_DRAWSHADOW)) { ED_area_tag_refresh(sa); @@ -596,29 +492,50 @@ static int image_context(const bContext *C, const char *member, bContextDataResu return 0; } +static void IMAGE_GGT_gizmo2d(wmGizmoGroupType *gzgt) +{ + gzgt->name = "UV Transform Gizmo"; + gzgt->idname = "IMAGE_GGT_gizmo2d"; + + gzgt->gzmap_params.spaceid = SPACE_IMAGE; + gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW; + + gzgt->poll = ED_widgetgroup_gizmo2d_poll; + gzgt->setup = ED_widgetgroup_gizmo2d_setup; + gzgt->refresh = ED_widgetgroup_gizmo2d_refresh; + gzgt->draw_prepare = ED_widgetgroup_gizmo2d_draw_prepare; +} + +static void image_widgets(void) +{ + WM_gizmogrouptype_append(IMAGE_GGT_gizmo2d); +} + /************************** main region ***************************/ /* sets up the fields of the View2D from zoom and offset */ static void image_main_region_set_view2d(SpaceImage *sima, ARegion *ar) { Image *ima = ED_space_image(sima); - float x1, y1, w, h; - int width, height, winx, winy; -#if 0 - if (image_preview_active(curarea, &width, &height)) {} - else -#endif + int width, height; ED_space_image_get_size(sima, &width, &height); - w = width; - h = height; + float w = width; + float h = height; if (ima) h *= ima->aspy / ima->aspx; - winx = BLI_rcti_size_x(&ar->winrct) + 1; - winy = BLI_rcti_size_y(&ar->winrct) + 1; + int winx = BLI_rcti_size_x(&ar->winrct) + 1; + int winy = BLI_rcti_size_y(&ar->winrct) + 1; + + /* For region overlap, move center so image doesn't overlap header. */ + rcti visible_rect; + ED_region_visible_rect(ar, &visible_rect); + const int visible_winy = BLI_rcti_size_y(&visible_rect) + 1; + int visible_centerx = 0; + int visible_centery = visible_rect.ymin + (visible_winy - winy) / 2; ar->v2d.tot.xmin = 0; ar->v2d.tot.ymin = 0; @@ -630,8 +547,8 @@ static void image_main_region_set_view2d(SpaceImage *sima, ARegion *ar) ar->v2d.mask.ymax = winy; /* which part of the image space do we see? */ - x1 = ar->winrct.xmin + (winx - sima->zoom * w) / 2.0f; - y1 = ar->winrct.ymin + (winy - sima->zoom * h) / 2.0f; + float x1 = ar->winrct.xmin + visible_centerx + (winx - sima->zoom * w) / 2.0f; + float y1 = ar->winrct.ymin + visible_centery + (winy - sima->zoom * h) / 2.0f; x1 -= sima->zoom * sima->xof; y1 -= sima->zoom * sima->yof; @@ -684,7 +601,6 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar) WM_event_add_keymap_handler(&ar->handlers, keymap); keymap = WM_keymap_ensure(wm->defaultconf, "Image", SPACE_IMAGE, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); - } static void image_main_region_draw(const bContext *C, ARegion *ar) @@ -693,9 +609,11 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) SpaceImage *sima = CTX_wm_space_image(C); Object *obact = CTX_data_active_object(C); Object *obedit = CTX_data_edit_object(C); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Mask *mask = NULL; bool curve = false; Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); View2D *v2d = &ar->v2d; //View2DScrollers *scrollers; float col[3]; @@ -705,8 +623,8 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) /* clear and setup matrix */ UI_GetThemeColor3fv(TH_BACK, col); - glClearColor(col[0], col[1], col[2], 0.0); - glClear(GL_COLOR_BUFFER_BIT); + GPU_clear_color(col[0], col[1], col[2], 0.0); + GPU_clear(GPU_COLOR_BIT); image_user_refresh_scene(C, sima); @@ -721,7 +639,7 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); - ED_uvedit_draw_main(sima, ar, scene, obedit, obact); + ED_uvedit_draw_main(sima, ar, scene, view_layer, obedit, obact, depsgraph); /* check for mask (delay draw) */ if (ED_space_image_show_uvedit(sima, obedit)) { @@ -790,6 +708,8 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); } + WM_gizmomap_draw(ar->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D); + draw_image_cache(C, ar); /* scrollers? */ @@ -800,10 +720,16 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) #endif } -static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar, wmNotifier *wmn) +static void image_main_region_listener( + wmWindow *UNUSED(win), ScrArea *sa, ARegion *ar, + wmNotifier *wmn, const Scene *UNUSED(scene)) { /* context changes */ switch (wmn->category) { + case NC_GEOM: + if (ELEM(wmn->data, ND_DATA, ND_SELECT)) + WM_gizmomap_tag_refresh(ar->gizmo_map); + break; case NC_GPENCIL: if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) ED_region_tag_redraw(ar); @@ -813,6 +739,7 @@ static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion case NC_IMAGE: if (wmn->action == NA_PAINTING) ED_region_tag_redraw(ar); + WM_gizmomap_tag_refresh(ar->gizmo_map); break; case NC_MATERIAL: if (wmn->data == ND_SHADING_LINKS) { @@ -822,6 +749,11 @@ static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion ED_region_tag_redraw(ar); } break; + case NC_SCREEN: + if (ELEM(wmn->data, ND_LAYER)) { + ED_region_tag_redraw(ar); + } + break; } } @@ -841,10 +773,12 @@ static void image_buttons_region_init(wmWindowManager *wm, ARegion *ar) static void image_buttons_region_draw(const bContext *C, ARegion *ar) { - ED_region_panels(C, ar, NULL, -1, true); + ED_region_panels(C, ar); } -static void image_buttons_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) +static void image_buttons_region_listener( + wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar, + wmNotifier *wmn, const Scene *UNUSED(scene)) { /* context changes */ switch (wmn->category) { @@ -914,10 +848,12 @@ static void image_tools_region_draw(const bContext *C, ARegion *ar) } ED_space_image_release_buffer(sima, ibuf, lock); - ED_region_panels(C, ar, NULL, -1, true); + ED_region_panels(C, ar); } -static void image_tools_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) +static void image_tools_region_listener( + wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar, + wmNotifier *wmn, const Scene *UNUSED(scene)) { /* context changes */ switch (wmn->category) { @@ -968,7 +904,9 @@ static void image_header_region_draw(const bContext *C, ARegion *ar) ED_region_header(C, ar); } -static void image_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) +static void image_header_region_listener( + wmWindow *UNUSED(win), ScrArea *UNUSED(sa), ARegion *ar, + wmNotifier *wmn, const Scene *UNUSED(scene)) { /* context changes */ switch (wmn->category) { @@ -1037,16 +975,16 @@ void ED_spacetype_image(void) st->refresh = image_refresh; st->listener = image_listener; st->context = image_context; + st->gizmos = image_widgets; st->id_remap = image_id_remap; /* regions: main window */ art = MEM_callocN(sizeof(ARegionType), "spacetype image region"); art->regionid = RGN_TYPE_WINDOW; - art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; + art->keymapflag = ED_KEYMAP_GIZMO | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; art->init = image_main_region_init; art->draw = image_main_region_draw; art->listener = image_main_region_listener; - BLI_addhead(&st->regiontypes, art); /* regions: listview/buttons */ @@ -1065,9 +1003,12 @@ void ED_spacetype_image(void) /* regions: statistics/scope buttons */ art = MEM_callocN(sizeof(ARegionType), "spacetype image region"); art->regionid = RGN_TYPE_TOOLS; - art->prefsizex = 220; // XXX + art->prefsizex = 58; /* XXX */ + art->prefsizey = 50; /* XXX */ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; art->listener = image_tools_region_listener; + art->message_subscribe = ED_region_generic_tools_region_message_subscribe; + art->snap_size = ED_region_generic_tools_region_snap_size; art->init = image_tools_region_init; art->draw = image_tools_region_draw; BLI_addhead(&st->regiontypes, art); @@ -1083,5 +1024,9 @@ void ED_spacetype_image(void) BLI_addhead(&st->regiontypes, art); + /* regions: hud */ + art = ED_area_type_hud(st->spaceid); + BLI_addhead(&st->regiontypes, art); + BKE_spacetype_register(st); } |