Tool System: publish/subscribe to tool changes

This commit is contained in:
Campbell Barton 2018-04-27 08:24:20 +02:00
parent 5752e4f06f
commit 0908fc1190
2 changed files with 29 additions and 0 deletions

View File

@ -50,8 +50,11 @@
#include "UI_resources.h"
#include "UI_view2d.h"
#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
#include "WM_message.h"
/* ******************** default callbacks for topbar space ***************** */
@ -194,6 +197,22 @@ static void topbar_header_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARe
}
}
static void topbar_header_region_message_subscribe(
const struct bContext *UNUSED(C),
struct WorkSpace *workspace, struct Scene *UNUSED(scene),
struct bScreen *UNUSED(screen), struct ScrArea *UNUSED(sa), struct ARegion *ar,
struct wmMsgBus *mbus)
{
wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
.owner = ar,
.user_data = ar,
.notify = ED_region_do_msg_notify_tag_redraw,
};
WM_msg_subscribe_rna_prop(
mbus, &workspace->id, workspace,
WorkSpace, tool_keymap, &msg_sub_value_region_tag_redraw);
}
static void recent_files_menu_draw(const bContext *UNUSED(C), Menu *menu)
{
struct RecentFile *recent;
@ -258,6 +277,7 @@ void ED_spacetype_topbar(void)
art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
art->listener = topbar_header_listener;
art->message_subscribe = topbar_header_region_message_subscribe;
art->init = topbar_header_region_init;
art->draw = topbar_header_region_draw;

View File

@ -38,8 +38,11 @@
#include "BKE_library.h"
#include "BKE_main.h"
#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
#include "WM_message.h"
void WM_toolsystem_unlink(bContext *C, WorkSpace *workspace)
{
@ -93,6 +96,12 @@ void WM_toolsystem_set(bContext *C, const bToolDef *tool)
}
WM_toolsystem_link(C, workspace);
{
struct wmMsgBus *mbus = CTX_wm_message_bus(C);
WM_msg_publish_rna_prop(
mbus, &workspace->id, workspace, WorkSpace, tool_keymap);
}
}
void WM_toolsystem_init(bContext *C)