Blender V5.0
wm_toolsystem.cc File Reference
#include <cstring>
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "DNA_ID.h"
#include "DNA_brush_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_workspace_types.h"
#include "BKE_asset_edit.hh"
#include "BKE_brush.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_idprop.hh"
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_main.hh"
#include "BKE_paint.hh"
#include "BKE_paint_types.hh"
#include "BKE_workspace.hh"
#include "RNA_access.hh"
#include "RNA_enum_types.hh"
#include "WM_api.hh"
#include "WM_message.hh"
#include "WM_toolsystem.hh"
#include "WM_types.hh"

Go to the source code of this file.

Functions

static void toolsystem_reinit_with_toolref (bContext *C, WorkSpace *, bToolRef *tref)
static bToolReftoolsystem_reinit_ensure_toolref (bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char *default_tool)
static void toolsystem_refresh_screen_from_active_tool (Main *bmain, WorkSpace *workspace, bToolRef *tref)
static void toolsystem_ref_set_by_brush_type (bContext *C, const char *brush_type)
static void toolsystem_ref_set_by_id_pending (Main *bmain, bToolRef *tref, const char *idname_pending)
static void toolsystem_unlink_ref (bContext *C, WorkSpace *, bToolRef *tref)
void WM_toolsystem_unlink (bContext *C, WorkSpace *workspace, const bToolKey *tkey)
static void toolsystem_ref_link (Main *bmain, WorkSpace *workspace, bToolRef *tref)
static void toolsystem_refresh_ref (const bContext *C, WorkSpace *workspace, bToolRef *tref)
void WM_toolsystem_refresh (const bContext *C, WorkSpace *workspace, const bToolKey *tkey)
static void toolsystem_reinit_ref (bContext *C, WorkSpace *workspace, bToolRef *tref)
void WM_toolsystem_reinit (bContext *C, WorkSpace *workspace, const bToolKey *tkey)
void WM_toolsystem_unlink_all (bContext *C, WorkSpace *workspace)
void WM_toolsystem_refresh_all (const bContext *C, WorkSpace *workspace)
void WM_toolsystem_reinit_all (bContext *C, wmWindow *win)
void WM_toolsystem_ref_set_from_runtime (bContext *C, WorkSpace *workspace, bToolRef *tref, const bToolRef_Runtime *tref_rt, const char *idname)
void WM_toolsystem_ref_sync_from_context (Main *bmain, WorkSpace *workspace, bToolRef *tref)
void WM_toolsystem_init (const bContext *C)
static bool toolsystem_key_ensure_check (const bToolKey *tkey)
int WM_toolsystem_mode_from_spacetype (const Scene *scene, ViewLayer *view_layer, ScrArea *area, int space_type)
bool WM_toolsystem_key_from_context (const Scene *scene, ViewLayer *view_layer, ScrArea *area, bToolKey *tkey)
void WM_toolsystem_refresh_active (bContext *C)
bool WM_toolsystem_refresh_screen_area (WorkSpace *workspace, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
void WM_toolsystem_refresh_screen_window (wmWindow *win)
void WM_toolsystem_refresh_screen_all (Main *bmain)
bToolRefWM_toolsystem_ref_set_by_id_ex (bContext *C, WorkSpace *workspace, const bToolKey *tkey, const char *name, bool cycle)
bToolRefWM_toolsystem_ref_set_by_id (bContext *C, const char *name)
static const char * toolsystem_default_tool (const bToolKey *tkey)
static void wm_toolsystem_update_from_context_view3d_impl (bContext *C, WorkSpace *workspace)
void WM_toolsystem_update_from_context_view3d (bContext *C)
void WM_toolsystem_update_from_context (bContext *C, WorkSpace *workspace, const Scene *scene, ViewLayer *view_layer, ScrArea *area)
bool WM_toolsystem_active_tool_is_brush (const bContext *C)
bool WM_toolsystem_active_tool_has_custom_cursor (const bContext *C)
void WM_toolsystem_do_msg_notify_tag_refresh (bContext *C, wmMsgSubscribeKey *, wmMsgSubscribeValue *msg_val)
static IDPropertyidprops_ensure_named_group (IDProperty *group, const char *idname)
IDPropertyWM_toolsystem_ref_properties_get_idprops (bToolRef *tref)
IDPropertyWM_toolsystem_ref_properties_ensure_idprops (bToolRef *tref)
bool WM_toolsystem_ref_properties_get_ex (bToolRef *tref, const char *idname, StructRNA *type, PointerRNA *r_ptr)
void WM_toolsystem_ref_properties_ensure_ex (bToolRef *tref, const char *idname, StructRNA *type, PointerRNA *r_ptr)
void WM_toolsystem_ref_properties_init_for_keymap (bToolRef *tref, PointerRNA *dst_ptr, PointerRNA *src_ptr, wmOperatorType *ot)
Tool Reference API
bToolRefWM_toolsystem_ref_from_context (const bContext *C)
bToolRef_RuntimeWM_toolsystem_runtime_from_context (const bContext *C)
bToolRefWM_toolsystem_ref_find (WorkSpace *workspace, const bToolKey *tkey)
bToolRef_RuntimeWM_toolsystem_runtime_find (WorkSpace *workspace, const bToolKey *tkey)
bool WM_toolsystem_ref_ensure (WorkSpace *workspace, const bToolKey *tkey, bToolRef **r_tref)
static bToolKey toolsystem_key_from_context_or_view3d (const Scene *scene, ViewLayer *view_layer, ScrArea *area)
static const bToolReftoolsystem_active_tool_from_context_or_view3d (const bContext *C)
Brush Tools
static const char * brush_type_identifier_get (const int brush_type, const PaintMode paint_mode)
static bool brush_type_matches_active_tool (bContext *C, const int brush_type)
static NamedBrushAssetReferencetoolsystem_brush_type_binding_lookup (const Paint *paint, const char *brush_type_name)
static void toolsystem_main_brush_binding_update_from_active (Paint *paint)
static void toolsystem_brush_type_binding_update (Paint *paint, const PaintMode paint_mode, const int brush_type)
bool WM_toolsystem_activate_brush_and_tool (bContext *C, Paint *paint, Brush *brush)
static void toolsystem_brush_activate_from_toolref_for_object_particle (const Main *bmain, const WorkSpace *workspace, const bToolRef *tref)
static void toolsystem_brush_activate_from_toolref_for_object_paint (Main *bmain, const WorkSpace *workspace, const bToolRef *tref)
static void toolsystem_brush_activate_from_toolref (Main *bmain, const WorkSpace *workspace, const bToolRef *tref)
static void toolsystem_brush_sync_for_texture_paint (Main *bmain, WorkSpace *workspace, bToolRef *tref)
static void toolsystem_brush_clear_paint_reference (Main *bmain, WorkSpace *workspace, bToolRef *tref)

Detailed Description

Tool-system used to define tools in Blender's toolbar. See: ./scripts/startup/bl_ui/space_toolsystem_common.py, ToolDef for a detailed description of tool definitions.

Note
Tools are stored per workspace. Notice many functions take Main & WorkSpace and not window/screen/scene data. This is intentional as changing tools must account for all scenes using that workspace. Functions that refreshes on tool change are responsible for updating all windows using this workspace.

Definition in file wm_toolsystem.cc.

Function Documentation

◆ brush_type_identifier_get()

◆ brush_type_matches_active_tool()

◆ idprops_ensure_named_group()

◆ toolsystem_active_tool_from_context_or_view3d()

const bToolRef * toolsystem_active_tool_from_context_or_view3d ( const bContext * C)
static

Get the active tool for the current context (space and mode) if the current space supports tools or, fallback to the active tool of the 3D View in the current mode.

Use this instead of WM_toolsystem_ref_from_context() when usage from properties editors should be possible, which shows tool settings of the 3D View.

Definition at line 165 of file wm_toolsystem.cc.

References C, CTX_data_scene(), CTX_data_view_layer(), CTX_wm_area(), CTX_wm_workspace(), bToolKey::mode, bToolKey::space_type, SPACE_VIEW3D, ScrArea::spacetype, WM_toolsystem_mode_from_spacetype(), WM_toolsystem_ref_find(), WM_toolsystem_ref_from_context(), and WM_TOOLSYSTEM_SPACE_MASK.

Referenced by brush_type_matches_active_tool(), and WM_toolsystem_activate_brush_and_tool().

◆ toolsystem_brush_activate_from_toolref()

void toolsystem_brush_activate_from_toolref ( Main * bmain,
const WorkSpace * workspace,
const bToolRef * tref )
static

◆ toolsystem_brush_activate_from_toolref_for_object_paint()

◆ toolsystem_brush_activate_from_toolref_for_object_particle()

◆ toolsystem_brush_clear_paint_reference()

◆ toolsystem_brush_sync_for_texture_paint()

void toolsystem_brush_sync_for_texture_paint ( Main * bmain,
WorkSpace * workspace,
bToolRef * tref )
static

Special case, the active brush data-block for the image & 3D viewport are shared. This means changing the active brush tool in one space must change the tool for the other space as well, see: #131062.

Definition at line 457 of file wm_toolsystem.cc.

References CTX_MODE_PAINT_TEXTURE, bToolRef::idname, bToolKey::mode, bToolRef::mode, SI_MODE_PAINT, SPACE_IMAGE, bToolKey::space_type, bToolRef::space_type, SPACE_VIEW3D, toolsystem_ref_set_by_id_pending(), and WM_toolsystem_ref_find().

Referenced by toolsystem_ref_link().

◆ toolsystem_brush_type_binding_lookup()

NamedBrushAssetReference * toolsystem_brush_type_binding_lookup ( const Paint * paint,
const char * brush_type_name )
static

◆ toolsystem_brush_type_binding_update()

◆ toolsystem_default_tool()

◆ toolsystem_key_ensure_check()

bool toolsystem_key_ensure_check ( const bToolKey * tkey)
static

◆ toolsystem_key_from_context_or_view3d()

bToolKey toolsystem_key_from_context_or_view3d ( const Scene * scene,
ViewLayer * view_layer,
ScrArea * area )
static

◆ toolsystem_main_brush_binding_update_from_active()

void toolsystem_main_brush_binding_update_from_active ( Paint * paint)
static

◆ toolsystem_ref_link()

◆ toolsystem_ref_set_by_brush_type()

◆ toolsystem_ref_set_by_id_pending()

void toolsystem_ref_set_by_id_pending ( Main * bmain,
bToolRef * tref,
const char * idname_pending )
static

Request a tool ID be activated in a context where it's not known if the tool exists, when the areas using this tool are not visible. In this case, set the idname as pending and flag tools area for updating.

If the tool doesn't exist then the current tool is to be left as-is.

Definition at line 1056 of file wm_toolsystem.cc.

References AREA_FLAG_ACTIVE_TOOL_UPDATE, BLI_assert, bToolRef::idname, bToolRef::idname_pending, LISTBASE_FOREACH, Main::screens, STREQ, and STRNCPY_UTF8.

Referenced by toolsystem_brush_sync_for_texture_paint().

◆ toolsystem_refresh_ref()

void toolsystem_refresh_ref ( const bContext * C,
WorkSpace * workspace,
bToolRef * tref )
static

◆ toolsystem_refresh_screen_from_active_tool()

◆ toolsystem_reinit_ensure_toolref()

bToolRef * toolsystem_reinit_ensure_toolref ( bContext * C,
WorkSpace * workspace,
const bToolKey * tkey,
const char * default_tool )
static

◆ toolsystem_reinit_ref()

void toolsystem_reinit_ref ( bContext * C,
WorkSpace * workspace,
bToolRef * tref )
static

Definition at line 550 of file wm_toolsystem.cc.

References C, and toolsystem_reinit_with_toolref().

Referenced by WM_toolsystem_reinit(), and WM_toolsystem_reinit_all().

◆ toolsystem_reinit_with_toolref()

◆ toolsystem_unlink_ref()

◆ WM_toolsystem_activate_brush_and_tool()

bool WM_toolsystem_activate_brush_and_tool ( bContext * C,
Paint * paint,
Brush * brush )

◆ WM_toolsystem_active_tool_has_custom_cursor()

bool WM_toolsystem_active_tool_has_custom_cursor ( const bContext * C)

◆ WM_toolsystem_active_tool_is_brush()

◆ WM_toolsystem_do_msg_notify_tag_refresh()

◆ WM_toolsystem_init()

void WM_toolsystem_init ( const bContext * C)

◆ WM_toolsystem_key_from_context()

bool WM_toolsystem_key_from_context ( const Scene * scene,
ViewLayer * view_layer,
ScrArea * area,
bToolKey * tkey )

◆ WM_toolsystem_mode_from_spacetype()

◆ WM_toolsystem_ref_ensure()

bool WM_toolsystem_ref_ensure ( WorkSpace * workspace,
const bToolKey * tkey,
bToolRef ** r_tref )

◆ WM_toolsystem_ref_find()

◆ WM_toolsystem_ref_from_context()

◆ WM_toolsystem_ref_properties_ensure_ex()

void WM_toolsystem_ref_properties_ensure_ex ( bToolRef * tref,
const char * idname,
StructRNA * type,
PointerRNA * r_ptr )

◆ WM_toolsystem_ref_properties_ensure_idprops()

IDProperty * WM_toolsystem_ref_properties_ensure_idprops ( bToolRef * tref)

◆ WM_toolsystem_ref_properties_get_ex()

bool WM_toolsystem_ref_properties_get_ex ( bToolRef * tref,
const char * idname,
StructRNA * type,
PointerRNA * r_ptr )

◆ WM_toolsystem_ref_properties_get_idprops()

IDProperty * WM_toolsystem_ref_properties_get_idprops ( bToolRef * tref)

◆ WM_toolsystem_ref_properties_init_for_keymap()

◆ WM_toolsystem_ref_set_by_id()

◆ WM_toolsystem_ref_set_by_id_ex()

◆ WM_toolsystem_ref_set_from_runtime()

◆ WM_toolsystem_ref_sync_from_context()

◆ WM_toolsystem_refresh()

void WM_toolsystem_refresh ( const bContext * C,
WorkSpace * workspace,
const bToolKey * tkey )

◆ WM_toolsystem_refresh_active()

void WM_toolsystem_refresh_active ( bContext * C)

◆ WM_toolsystem_refresh_all()

void WM_toolsystem_refresh_all ( const bContext * C,
WorkSpace * workspace )

◆ WM_toolsystem_refresh_screen_all()

void WM_toolsystem_refresh_screen_all ( Main * bmain)

◆ WM_toolsystem_refresh_screen_area()

bool WM_toolsystem_refresh_screen_area ( WorkSpace * workspace,
const Scene * scene,
ViewLayer * view_layer,
ScrArea * area )

◆ WM_toolsystem_refresh_screen_window()

◆ WM_toolsystem_reinit()

void WM_toolsystem_reinit ( bContext * C,
WorkSpace * workspace,
const bToolKey * tkey )

Definition at line 554 of file wm_toolsystem.cc.

References C, toolsystem_reinit_ref(), and WM_toolsystem_ref_find().

◆ WM_toolsystem_reinit_all()

◆ WM_toolsystem_runtime_find()

bToolRef_Runtime * WM_toolsystem_runtime_find ( WorkSpace * workspace,
const bToolKey * tkey )

Definition at line 116 of file wm_toolsystem.cc.

References bToolRef::runtime, and WM_toolsystem_ref_find().

◆ WM_toolsystem_runtime_from_context()

◆ WM_toolsystem_unlink()

void WM_toolsystem_unlink ( bContext * C,
WorkSpace * workspace,
const bToolKey * tkey )

◆ WM_toolsystem_unlink_all()

void WM_toolsystem_unlink_all ( bContext * C,
WorkSpace * workspace )

Operate on all active tools.

Definition at line 562 of file wm_toolsystem.cc.

References C, LISTBASE_FOREACH, WorkSpace::tools, and toolsystem_unlink_ref().

◆ WM_toolsystem_update_from_context()

void WM_toolsystem_update_from_context ( bContext * C,
WorkSpace * workspace,
const Scene * scene,
ViewLayer * view_layer,
ScrArea * area )

◆ WM_toolsystem_update_from_context_view3d()

◆ wm_toolsystem_update_from_context_view3d_impl()

void wm_toolsystem_update_from_context_view3d_impl ( bContext * C,
WorkSpace * workspace )
static