Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_image/space_image.c
| Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
| #include "BIF_gl.h" | #include "BIF_gl.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "UI_interface.h" | |||||
| #include "UI_view2d.h" | #include "UI_view2d.h" | ||||
| #include "image_intern.h" | #include "image_intern.h" | ||||
| /**************************** common state *****************************/ | /**************************** common state *****************************/ | ||||
| static void image_scopes_tag_refresh(ScrArea *sa) | static void image_scopes_tag_refresh(ScrArea *sa) | ||||
| { | { | ||||
| SpaceImage *sima = (SpaceImage *)sa->spacedata.first; | SpaceImage *sima = (SpaceImage *)sa->spacedata.first; | ||||
| ARegion *ar; | ARegion *ar; | ||||
| /* only while histogram is visible */ | /* only while histogram is visible */ | ||||
| for (ar = sa->regionbase.first; ar; ar = ar->next) { | for (ar = sa->regionbase.first; ar; ar = ar->next) { | ||||
| if (ar->regiontype == RGN_TYPE_PREVIEW && ar->flag & RGN_FLAG_HIDDEN) | if (ar->regiontype == RGN_TYPE_TOOLS && ar->flag & RGN_FLAG_HIDDEN) | ||||
| return; | return; | ||||
| } | } | ||||
| sima->scopes.ok = 0; | sima->scopes.ok = 0; | ||||
| } | } | ||||
| /* ******************** manage regions ********************* */ | /* ******************** manage regions ********************* */ | ||||
| Show All 17 Lines | ARegion *image_has_buttons_region(ScrArea *sa) | ||||
| arnew->regiontype = RGN_TYPE_UI; | arnew->regiontype = RGN_TYPE_UI; | ||||
| arnew->alignment = RGN_ALIGN_RIGHT; | arnew->alignment = RGN_ALIGN_RIGHT; | ||||
| arnew->flag = RGN_FLAG_HIDDEN; | arnew->flag = RGN_FLAG_HIDDEN; | ||||
| return arnew; | return arnew; | ||||
| } | } | ||||
| ARegion *image_has_scope_region(ScrArea *sa) | ARegion *image_has_tools_region(ScrArea *sa) | ||||
| { | { | ||||
| ARegion *ar, *arnew; | ARegion *ar, *arnew; | ||||
| ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW); | ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS); | ||||
| if (ar) return ar; | if (ar) return ar; | ||||
| /* add subdiv level; after buttons */ | /* add subdiv level; after buttons */ | ||||
| ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); | ar = BKE_area_find_region_type(sa, RGN_TYPE_UI); | ||||
| /* is error! */ | /* is error! */ | ||||
| if (ar == NULL) return NULL; | if (ar == NULL) return NULL; | ||||
| arnew = MEM_callocN(sizeof(ARegion), "scopes for image"); | arnew = MEM_callocN(sizeof(ARegion), "scopes for image"); | ||||
| BLI_insertlinkafter(&sa->regionbase, ar, arnew); | BLI_insertlinkafter(&sa->regionbase, ar, arnew); | ||||
| arnew->regiontype = RGN_TYPE_PREVIEW; | arnew->regiontype = RGN_TYPE_TOOLS; | ||||
| arnew->alignment = RGN_ALIGN_LEFT; | arnew->alignment = RGN_ALIGN_LEFT; | ||||
| arnew->flag = RGN_FLAG_HIDDEN; | arnew->flag = RGN_FLAG_HIDDEN; | ||||
| image_scopes_tag_refresh(sa); | image_scopes_tag_refresh(sa); | ||||
| return arnew; | return arnew; | ||||
| } | } | ||||
| Show All 28 Lines | static SpaceLink *image_new(const bContext *UNUSED(C)) | ||||
| /* buttons/list view */ | /* buttons/list view */ | ||||
| ar = MEM_callocN(sizeof(ARegion), "buttons for image"); | ar = MEM_callocN(sizeof(ARegion), "buttons for image"); | ||||
| BLI_addtail(&simage->regionbase, ar); | BLI_addtail(&simage->regionbase, ar); | ||||
| ar->regiontype = RGN_TYPE_UI; | ar->regiontype = RGN_TYPE_UI; | ||||
| ar->alignment = RGN_ALIGN_RIGHT; | ar->alignment = RGN_ALIGN_RIGHT; | ||||
| ar->flag = RGN_FLAG_HIDDEN; | ar->flag = RGN_FLAG_HIDDEN; | ||||
| /* scopes */ | /* scopes/uv sculpt/paint */ | ||||
| ar = MEM_callocN(sizeof(ARegion), "buttons for image"); | ar = MEM_callocN(sizeof(ARegion), "buttons for image"); | ||||
| BLI_addtail(&simage->regionbase, ar); | BLI_addtail(&simage->regionbase, ar); | ||||
| ar->regiontype = RGN_TYPE_PREVIEW; | ar->regiontype = RGN_TYPE_TOOLS; | ||||
| ar->alignment = RGN_ALIGN_LEFT; | ar->alignment = RGN_ALIGN_LEFT; | ||||
| ar->flag = RGN_FLAG_HIDDEN; | ar->flag = RGN_FLAG_HIDDEN; | ||||
| /* main area */ | /* main area */ | ||||
| ar = MEM_callocN(sizeof(ARegion), "main area for image"); | ar = MEM_callocN(sizeof(ARegion), "main area for image"); | ||||
| BLI_addtail(&simage->regionbase, ar); | BLI_addtail(&simage->regionbase, ar); | ||||
| ar->regiontype = RGN_TYPE_WINDOW; | ar->regiontype = RGN_TYPE_WINDOW; | ||||
| ▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | static void image_operatortypes(void) | ||||
| WM_operatortype_append(IMAGE_OT_cycle_render_slot); | WM_operatortype_append(IMAGE_OT_cycle_render_slot); | ||||
| WM_operatortype_append(IMAGE_OT_sample); | WM_operatortype_append(IMAGE_OT_sample); | ||||
| WM_operatortype_append(IMAGE_OT_sample_line); | WM_operatortype_append(IMAGE_OT_sample_line); | ||||
| WM_operatortype_append(IMAGE_OT_curves_point_set); | WM_operatortype_append(IMAGE_OT_curves_point_set); | ||||
| WM_operatortype_append(IMAGE_OT_properties); | WM_operatortype_append(IMAGE_OT_properties); | ||||
| WM_operatortype_append(IMAGE_OT_scopes); | WM_operatortype_append(IMAGE_OT_toolshelf); | ||||
| } | } | ||||
| static void image_keymap(struct wmKeyConfig *keyconf) | static void image_keymap(struct wmKeyConfig *keyconf) | ||||
| { | { | ||||
| wmKeyMap *keymap = WM_keymap_find(keyconf, "Image Generic", SPACE_IMAGE, 0); | wmKeyMap *keymap = WM_keymap_find(keyconf, "Image Generic", SPACE_IMAGE, 0); | ||||
| wmKeyMapItem *kmi; | wmKeyMapItem *kmi; | ||||
| int i; | int i; | ||||
| WM_keymap_add_item(keymap, "IMAGE_OT_new", NKEY, KM_PRESS, KM_ALT, 0); | 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_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_reload", RKEY, KM_PRESS, KM_ALT, 0); | ||||
| WM_keymap_add_item(keymap, "IMAGE_OT_save", SKEY, KM_PRESS, KM_ALT, 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_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_properties", NKEY, KM_PRESS, 0, 0); | ||||
| WM_keymap_add_item(keymap, "IMAGE_OT_scopes", TKEY, 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); | 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); | 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_find(keyconf, "Image", SPACE_IMAGE, 0); | keymap = WM_keymap_find(keyconf, "Image", SPACE_IMAGE, 0); | ||||
| WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); | WM_keymap_add_item(keymap, "IMAGE_OT_view_all", HOMEKEY, KM_PRESS, 0, 0); | ||||
| ▲ Show 20 Lines • Show All 521 Lines • ▼ Show 20 Lines | case NC_MATERIAL: | ||||
| ED_region_tag_redraw(ar); | ED_region_tag_redraw(ar); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* *********************** scopes region ************************ */ | /* *********************** scopes region ************************ */ | ||||
| /* add handlers, stuff you only do once or on area/region changes */ | /* add handlers, stuff you only do once or on area/region changes */ | ||||
| static void image_scope_area_init(wmWindowManager *wm, ARegion *ar) | static void image_tools_area_init(wmWindowManager *wm, ARegion *ar) | ||||
| { | { | ||||
| wmKeyMap *keymap; | wmKeyMap *keymap; | ||||
| ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE; | ar->v2d.scroll = V2D_SCROLL_RIGHT | V2D_SCROLL_VERTICAL_HIDE; | ||||
| ED_region_panels_init(wm, ar); | ED_region_panels_init(wm, ar); | ||||
| keymap = WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0); | keymap = WM_keymap_find(wm->defaultconf, "Image Generic", SPACE_IMAGE, 0); | ||||
| WM_event_add_keymap_handler(&ar->handlers, keymap); | WM_event_add_keymap_handler(&ar->handlers, keymap); | ||||
| } | } | ||||
| static void image_scope_area_draw(const bContext *C, ARegion *ar) | static void image_tools_area_draw(const bContext *C, ARegion *ar) | ||||
| { | { | ||||
| SpaceImage *sima = CTX_wm_space_image(C); | SpaceImage *sima = CTX_wm_space_image(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| void *lock; | void *lock; | ||||
| ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock); | ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock); | ||||
| /* XXX performance regression if name of scopes category changes! */ | |||||
| PanelCategoryStack *category = UI_panel_category_active_find(ar, "Scopes"); | |||||
| /* only update scopes if scope category is active */ | |||||
| if (category) { | |||||
| if (ibuf) { | if (ibuf) { | ||||
| if (!sima->scopes.ok) { | if (!sima->scopes.ok) { | ||||
| BKE_histogram_update_sample_line(&sima->sample_line_hist, ibuf, &scene->view_settings, &scene->display_settings); | BKE_histogram_update_sample_line(&sima->sample_line_hist, ibuf, &scene->view_settings, &scene->display_settings); | ||||
| } | } | ||||
| if (sima->image->flag & IMA_VIEW_AS_RENDER) | if (sima->image->flag & IMA_VIEW_AS_RENDER) | ||||
| scopes_update(&sima->scopes, ibuf, &scene->view_settings, &scene->display_settings); | scopes_update(&sima->scopes, ibuf, &scene->view_settings, &scene->display_settings); | ||||
| else | else | ||||
| scopes_update(&sima->scopes, ibuf, NULL, &scene->display_settings); | scopes_update(&sima->scopes, ibuf, NULL, &scene->display_settings); | ||||
| } | } | ||||
brecht: I guess we'll have to live with that loose coupling, I don't think it's so bad.
The other… | |||||
| } | |||||
| ED_space_image_release_buffer(sima, ibuf, lock); | ED_space_image_release_buffer(sima, ibuf, lock); | ||||
| ED_region_panels(C, ar, 1, NULL, -1); | ED_region_panels(C, ar, 1, NULL, -1); | ||||
| } | } | ||||
| static void image_scope_area_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) | static void image_tools_area_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) | ||||
| { | { | ||||
| /* context changes */ | /* context changes */ | ||||
| switch (wmn->category) { | switch (wmn->category) { | ||||
| case NC_SCENE: | case NC_SCENE: | ||||
| switch (wmn->data) { | switch (wmn->data) { | ||||
| case ND_MODE: | case ND_MODE: | ||||
| case ND_RENDER_RESULT: | case ND_RENDER_RESULT: | ||||
| case ND_COMPO_RESULT: | case ND_COMPO_RESULT: | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | void ED_spacetype_image(void) | ||||
| art->regionid = RGN_TYPE_UI; | art->regionid = RGN_TYPE_UI; | ||||
| art->prefsizex = 220; // XXX | art->prefsizex = 220; // XXX | ||||
| art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; | art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; | ||||
| art->listener = image_buttons_area_listener; | art->listener = image_buttons_area_listener; | ||||
| art->init = image_buttons_area_init; | art->init = image_buttons_area_init; | ||||
| art->draw = image_buttons_area_draw; | art->draw = image_buttons_area_draw; | ||||
| BLI_addhead(&st->regiontypes, art); | BLI_addhead(&st->regiontypes, art); | ||||
| image_buttons_register(art); | |||||
| ED_uvedit_buttons_register(art); | ED_uvedit_buttons_register(art); | ||||
| image_buttons_register(art); | |||||
| /* regions: statistics/scope buttons */ | /* regions: statistics/scope buttons */ | ||||
| art = MEM_callocN(sizeof(ARegionType), "spacetype image region"); | art = MEM_callocN(sizeof(ARegionType), "spacetype image region"); | ||||
| art->regionid = RGN_TYPE_PREVIEW; | art->regionid = RGN_TYPE_TOOLS; | ||||
| art->prefsizex = 220; // XXX | art->prefsizex = 220; // XXX | ||||
| art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; | art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES; | ||||
| art->listener = image_scope_area_listener; | art->listener = image_tools_area_listener; | ||||
| art->init = image_scope_area_init; | art->init = image_tools_area_init; | ||||
| art->draw = image_scope_area_draw; | art->draw = image_tools_area_draw; | ||||
| BLI_addhead(&st->regiontypes, art); | BLI_addhead(&st->regiontypes, art); | ||||
| /* regions: header */ | /* regions: header */ | ||||
| art = MEM_callocN(sizeof(ARegionType), "spacetype image region"); | art = MEM_callocN(sizeof(ARegionType), "spacetype image region"); | ||||
| art->regionid = RGN_TYPE_HEADER; | art->regionid = RGN_TYPE_HEADER; | ||||
| art->prefsizey = HEADERY; | art->prefsizey = HEADERY; | ||||
| art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; | art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER; | ||||
| art->listener = image_header_area_listener; | art->listener = image_header_area_listener; | ||||
| art->init = image_header_area_init; | art->init = image_header_area_init; | ||||
| art->draw = image_header_area_draw; | art->draw = image_header_area_draw; | ||||
| BLI_addhead(&st->regiontypes, art); | BLI_addhead(&st->regiontypes, art); | ||||
| BKE_spacetype_register(st); | BKE_spacetype_register(st); | ||||
| } | } | ||||
I guess we'll have to live with that loose coupling, I don't think it's so bad.
The other solution would be to compute the scopes just in time before drawing, but I don't like that much either, since ideally the scopes should be computed as part of the dependency graph somehow for better threading.