Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_toolsystem.c
| Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (tref_rt->data_block[0]) { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| if ((tref->space_type == SPACE_VIEW3D) && (tref->mode == CTX_MODE_PARTICLE)) { | if ((tref->space_type == SPACE_VIEW3D) && (tref->mode == CTX_MODE_PARTICLE)) { | ||||
| const EnumPropertyItem *items = rna_enum_particle_edit_hair_brush_items; | const EnumPropertyItem *items = rna_enum_particle_edit_hair_brush_items; | ||||
| const int i = RNA_enum_from_identifier(items, tref_rt->data_block); | const int i = RNA_enum_from_identifier(items, tref_rt->data_block); | ||||
| if (i != -1) { | if (i != -1) { | ||||
| const int value = items[i].value; | const int value = items[i].value; | ||||
| wmWindowManager *wm = bmain->wm.first; | wmWindowManager *wm = bmain->wm.first; | ||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| if (workspace == WM_window_get_active_workspace(win)) { | if (workspace == WM_window_get_active_workspace(win)) { | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| ToolSettings *ts = scene->toolsettings; | ToolSettings *ts = scene->toolsettings; | ||||
| ts->particle.brushtype = value; | ts->particle.brushtype = value; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| const ePaintMode paint_mode = BKE_paintmode_get_from_tool(tref); | const ePaintMode paint_mode = BKE_paintmode_get_from_tool(tref); | ||||
| BLI_assert(paint_mode != PAINT_MODE_INVALID); | BLI_assert(paint_mode != PAINT_MODE_INVALID); | ||||
| const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); | const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); | ||||
| BLI_assert(items != NULL); | BLI_assert(items != NULL); | ||||
| const int i = items ? RNA_enum_from_identifier(items, tref_rt->data_block) : -1; | const int i = items ? RNA_enum_from_identifier(items, tref_rt->data_block) : -1; | ||||
| if (i != -1) { | if (i != -1) { | ||||
| const int slot_index = items[i].value; | const int slot_index = items[i].value; | ||||
| wmWindowManager *wm = bmain->wm.first; | wmWindowManager *wm = bmain->wm.first; | ||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| if (workspace == WM_window_get_active_workspace(win)) { | if (workspace == WM_window_get_active_workspace(win)) { | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| BKE_paint_ensure_from_paintmode(scene, paint_mode); | BKE_paint_ensure_from_paintmode(scene, paint_mode); | ||||
| Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); | Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); | ||||
| struct Brush *brush = BKE_paint_toolslots_brush_get(paint, slot_index); | struct Brush *brush = BKE_paint_toolslots_brush_get(paint, slot_index); | ||||
| if (brush == NULL) { | if (brush == NULL) { | ||||
| /* Could make into a function. */ | /* Could make into a function. */ | ||||
| brush = (struct Brush *)BKE_libblock_find_name(bmain, ID_BR, items[i].name); | brush = (struct Brush *)BKE_libblock_find_name(bmain, ID_BR, items[i].name); | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | void WM_toolsystem_refresh_all(struct bContext *C, struct WorkSpace *workspace) | ||||
| LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { | LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { | ||||
| toolsystem_refresh_ref(C, workspace, tref); | toolsystem_refresh_ref(C, workspace, tref); | ||||
| } | } | ||||
| } | } | ||||
| void WM_toolsystem_reinit_all(struct bContext *C, wmWindow *win) | void WM_toolsystem_reinit_all(struct bContext *C, wmWindow *win) | ||||
| { | { | ||||
| bScreen *screen = WM_window_get_active_screen(win); | bScreen *screen = WM_window_get_active_screen(win); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| for (ScrArea *area = screen->areabase.first; area; area = area->next) { | LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | ||||
| if (((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK) == 0) { | if (((1 << area->spacetype) & WM_TOOLSYSTEM_SPACE_MASK) == 0) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| WorkSpace *workspace = WM_window_get_active_workspace(win); | WorkSpace *workspace = WM_window_get_active_workspace(win); | ||||
| const bToolKey tkey = { | const bToolKey tkey = { | ||||
| .space_type = area->spacetype, | .space_type = area->spacetype, | ||||
| .mode = WM_toolsystem_mode_from_spacetype(view_layer, area, area->spacetype), | .mode = WM_toolsystem_mode_from_spacetype(view_layer, area, area->spacetype), | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| */ | */ | ||||
| void WM_toolsystem_ref_sync_from_context(Main *bmain, WorkSpace *workspace, bToolRef *tref) | void WM_toolsystem_ref_sync_from_context(Main *bmain, WorkSpace *workspace, bToolRef *tref) | ||||
| { | { | ||||
| bToolRef_Runtime *tref_rt = tref->runtime; | bToolRef_Runtime *tref_rt = tref->runtime; | ||||
| if ((tref_rt == NULL) || (tref_rt->data_block[0] == '\0')) { | if ((tref_rt == NULL) || (tref_rt->data_block[0] == '\0')) { | ||||
| return; | return; | ||||
| } | } | ||||
| wmWindowManager *wm = bmain->wm.first; | wmWindowManager *wm = bmain->wm.first; | ||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| if (workspace != WM_window_get_active_workspace(win)) { | if (workspace != WM_window_get_active_workspace(win)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| Scene *scene = WM_window_get_active_scene(win); | Scene *scene = WM_window_get_active_scene(win); | ||||
| ToolSettings *ts = scene->toolsettings; | ToolSettings *ts = scene->toolsettings; | ||||
| const ViewLayer *view_layer = WM_window_get_active_view_layer(win); | const ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| const Object *ob = OBACT(view_layer); | const Object *ob = OBACT(view_layer); | ||||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | |||||
| * depending on the mode and space type. | * depending on the mode and space type. | ||||
| * | * | ||||
| * Used when undoing since the active mode may have changed. | * Used when undoing since the active mode may have changed. | ||||
| */ | */ | ||||
| void WM_toolsystem_refresh_active(bContext *C) | void WM_toolsystem_refresh_active(bContext *C) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { | for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { | ||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| WorkSpace *workspace = WM_window_get_active_workspace(win); | WorkSpace *workspace = WM_window_get_active_workspace(win); | ||||
| bScreen *screen = WM_window_get_active_screen(win); | bScreen *screen = WM_window_get_active_screen(win); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| /* Could skip loop for modes that don't depend on space type. */ | /* Could skip loop for modes that don't depend on space type. */ | ||||
| int space_type_mask_handled = 0; | int space_type_mask_handled = 0; | ||||
| for (ScrArea *area = screen->areabase.first; area; area = area->next) { | LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | ||||
| /* Don't change the space type of the active tool, only update it's mode. */ | /* Don't change the space type of the active tool, only update it's mode. */ | ||||
| const int space_type_mask = (1 << area->spacetype); | const int space_type_mask = (1 << area->spacetype); | ||||
| if ((space_type_mask & WM_TOOLSYSTEM_SPACE_MASK) && | if ((space_type_mask & WM_TOOLSYSTEM_SPACE_MASK) && | ||||
| ((space_type_mask_handled & space_type_mask) == 0)) { | ((space_type_mask_handled & space_type_mask) == 0)) { | ||||
| space_type_mask_handled |= space_type_mask; | space_type_mask_handled |= space_type_mask; | ||||
| const bToolKey tkey = { | const bToolKey tkey = { | ||||
| .space_type = area->spacetype, | .space_type = area->spacetype, | ||||
| .mode = WM_toolsystem_mode_from_spacetype(view_layer, area, area->spacetype), | .mode = WM_toolsystem_mode_from_spacetype(view_layer, area, area->spacetype), | ||||
| Show All 10 Lines | void WM_toolsystem_refresh_active(bContext *C) | ||||
| BKE_workspace_id_tag_all_visible(bmain, LIB_TAG_DOIT); | BKE_workspace_id_tag_all_visible(bmain, LIB_TAG_DOIT); | ||||
| LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) { | LISTBASE_FOREACH (WorkSpace *, workspace, &bmain->workspaces) { | ||||
| if (workspace->id.tag & LIB_TAG_DOIT) { | if (workspace->id.tag & LIB_TAG_DOIT) { | ||||
| workspace->id.tag &= ~LIB_TAG_DOIT; | workspace->id.tag &= ~LIB_TAG_DOIT; | ||||
| /* Refresh to ensure data is initialized. | /* Refresh to ensure data is initialized. | ||||
| * This is needed because undo can load a state which no longer has the underlying DNA data | * This is needed because undo can load a state which no longer has the underlying DNA data | ||||
| * needed for the tool (un-initialized paint-slots for eg), see: T64339. */ | * needed for the tool (un-initialized paint-slots for eg), see: T64339. */ | ||||
| for (bToolRef *tref = workspace->tools.first; tref; tref = tref->next) { | LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { | ||||
| toolsystem_refresh_ref(C, workspace, tref); | toolsystem_refresh_ref(C, workspace, tref); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void WM_toolsystem_refresh_screen_area(WorkSpace *workspace, ViewLayer *view_layer, ScrArea *area) | void WM_toolsystem_refresh_screen_area(WorkSpace *workspace, ViewLayer *view_layer, ScrArea *area) | ||||
| { | { | ||||
| area->runtime.tool = NULL; | area->runtime.tool = NULL; | ||||
| area->runtime.is_tool_set = true; | area->runtime.is_tool_set = true; | ||||
| const int mode = WM_toolsystem_mode_from_spacetype(view_layer, area, area->spacetype); | const int mode = WM_toolsystem_mode_from_spacetype(view_layer, area, area->spacetype); | ||||
| for (bToolRef *tref = workspace->tools.first; tref; tref = tref->next) { | LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { | ||||
| if (tref->space_type == area->spacetype) { | if (tref->space_type == area->spacetype) { | ||||
| if (tref->mode == mode) { | if (tref->mode == mode) { | ||||
| area->runtime.tool = tref; | area->runtime.tool = tref; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void WM_toolsystem_refresh_screen_all(Main *bmain) | void WM_toolsystem_refresh_screen_all(Main *bmain) | ||||
| { | { | ||||
| /* Update all ScrArea's tools */ | /* Update all ScrArea's tools */ | ||||
| for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { | for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { | ||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| WorkSpace *workspace = WM_window_get_active_workspace(win); | WorkSpace *workspace = WM_window_get_active_workspace(win); | ||||
| bool space_type_has_tools[SPACE_TYPE_LAST + 1] = {0}; | bool space_type_has_tools[SPACE_TYPE_LAST + 1] = {0}; | ||||
| for (bToolRef *tref = workspace->tools.first; tref; tref = tref->next) { | LISTBASE_FOREACH (bToolRef *, tref, &workspace->tools) { | ||||
| space_type_has_tools[tref->space_type] = true; | space_type_has_tools[tref->space_type] = true; | ||||
| } | } | ||||
| bScreen *screen = WM_window_get_active_screen(win); | bScreen *screen = WM_window_get_active_screen(win); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| for (ScrArea *area = screen->areabase.first; area; area = area->next) { | LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | ||||
| area->runtime.tool = NULL; | area->runtime.tool = NULL; | ||||
| area->runtime.is_tool_set = true; | area->runtime.is_tool_set = true; | ||||
| if (space_type_has_tools[area->spacetype]) { | if (space_type_has_tools[area->spacetype]) { | ||||
| WM_toolsystem_refresh_screen_area(workspace, view_layer, area); | WM_toolsystem_refresh_screen_area(workspace, view_layer, area); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void toolsystem_refresh_screen_from_active_tool(Main *bmain, | static void toolsystem_refresh_screen_from_active_tool(Main *bmain, | ||||
| WorkSpace *workspace, | WorkSpace *workspace, | ||||
| bToolRef *tref) | bToolRef *tref) | ||||
| { | { | ||||
| /* Update all ScrArea's tools */ | /* Update all ScrArea's tools */ | ||||
| for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { | for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { | ||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| if (workspace == WM_window_get_active_workspace(win)) { | if (workspace == WM_window_get_active_workspace(win)) { | ||||
| bScreen *screen = WM_window_get_active_screen(win); | bScreen *screen = WM_window_get_active_screen(win); | ||||
| ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ViewLayer *view_layer = WM_window_get_active_view_layer(win); | ||||
| for (ScrArea *area = screen->areabase.first; area; area = area->next) { | LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | ||||
| if (area->spacetype == tref->space_type) { | if (area->spacetype == tref->space_type) { | ||||
| int mode = WM_toolsystem_mode_from_spacetype(view_layer, area, area->spacetype); | int mode = WM_toolsystem_mode_from_spacetype(view_layer, area, area->spacetype); | ||||
| if (mode == tref->mode) { | if (mode == tref->mode) { | ||||
| area->runtime.tool = tref; | area->runtime.tool = tref; | ||||
| area->runtime.is_tool_set = true; | area->runtime.is_tool_set = true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | void WM_toolsystem_update_from_context_view3d(bContext *C) | ||||
| /* Multi window support. */ | /* Multi window support. */ | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| wmWindowManager *wm = bmain->wm.first; | wmWindowManager *wm = bmain->wm.first; | ||||
| if (!BLI_listbase_is_single(&wm->windows)) { | if (!BLI_listbase_is_single(&wm->windows)) { | ||||
| wmWindow *win_prev = CTX_wm_window(C); | wmWindow *win_prev = CTX_wm_window(C); | ||||
| ScrArea *area_prev = CTX_wm_area(C); | ScrArea *area_prev = CTX_wm_area(C); | ||||
| ARegion *region_prev = CTX_wm_region(C); | ARegion *region_prev = CTX_wm_region(C); | ||||
| for (wmWindow *win = wm->windows.first; win; win = win->next) { | LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { | ||||
| if (win != win_prev) { | if (win != win_prev) { | ||||
| WorkSpace *workspace_iter = WM_window_get_active_workspace(win); | WorkSpace *workspace_iter = WM_window_get_active_workspace(win); | ||||
| if (workspace_iter != workspace) { | if (workspace_iter != workspace) { | ||||
| CTX_wm_window_set(C, win); | CTX_wm_window_set(C, win); | ||||
| wm_toolsystem_update_from_context_view3d_impl(C, workspace_iter); | wm_toolsystem_update_from_context_view3d_impl(C, workspace_iter); | ||||
| ▲ Show 20 Lines • Show All 127 Lines • Show Last 20 Lines | |||||