Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2017-07-26 01:12:46 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-07-26 01:34:09 +0300
commit54bc49e6f940c6e4b1ee893ac28b87fa1b150656 (patch)
treee1b8ffaf29cf667dcebf7130fb3728b87cda52e8 /source/blender/windowmanager/manipulators/intern/wm_manipulator.c
parentdee19b8cb7c6287d183a833ea9e360be67631455 (diff)
Manipulator: refactor/fix selection logic
- Cleanup array access, move into functions. - Store allocated size to avoid realloc's on every add/remove. - Make select editable from Python. - Rename select callback to select_refresh (collided with select boolean). - Call select_refresh when de-selecting as well as selection.
Diffstat (limited to 'source/blender/windowmanager/manipulators/intern/wm_manipulator.c')
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator.c78
1 files changed, 31 insertions, 47 deletions
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
index 4246ecf93c0..e61200fa67b 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -201,7 +201,7 @@ void WM_manipulator_free(ListBase *manipulatorlist, wmManipulatorMap *mmap, wmMa
wm_manipulatormap_modal_set(mmap, C, NULL, NULL);
}
if (mpr->state & WM_MANIPULATOR_STATE_SELECT) {
- wm_manipulator_deselect(mmap, mpr);
+ WM_manipulator_select_set(mmap, mpr, false);
}
if (mpr->op_data.ptr.data) {
@@ -386,73 +386,57 @@ void WM_manipulator_set_fn_custom_modal(struct wmManipulator *mpr, wmManipulator
/* -------------------------------------------------------------------- */
/**
- * Remove \a manipulator from selection.
+ * Add/Remove \a manipulator to selection.
* Reallocates memory for selected manipulators so better not call for selecting multiple ones.
*
* \return if the selection has changed.
*/
-bool wm_manipulator_deselect(wmManipulatorMap *mmap, wmManipulator *mpr)
+bool wm_manipulator_select_set_ex(wmManipulatorMap *mmap, wmManipulator *mpr, bool select, bool use_array)
{
- if (!mmap->mmap_context.selected)
- return false;
-
- wmManipulator ***sel = &mmap->mmap_context.selected;
- int *selected_len = &mmap->mmap_context.selected_len;
bool changed = false;
- /* caller should check! */
- BLI_assert(mpr->state & WM_MANIPULATOR_STATE_SELECT);
-
- /* remove manipulator from selected_manipulators array */
- for (int i = 0; i < (*selected_len); i++) {
- if ((*sel)[i] == mpr) {
- for (int j = i; j < ((*selected_len) - 1); j++) {
- (*sel)[j] = (*sel)[j + 1];
+ if (select) {
+ if ((mpr->state & WM_MANIPULATOR_STATE_SELECT) == 0) {
+ if (use_array) {
+ wm_manipulatormap_select_array_push_back(mmap, mpr);
}
+ mpr->state |= WM_MANIPULATOR_STATE_SELECT;
changed = true;
- break;
}
}
-
- /* update array data */
- if ((*selected_len) <= 1) {
- wm_manipulatormap_selected_clear(mmap);
- }
else {
- *sel = MEM_reallocN(*sel, sizeof(**sel) * (*selected_len));
- (*selected_len)--;
+ if (mpr->state & WM_MANIPULATOR_STATE_SELECT) {
+ if (use_array) {
+ wm_manipulatormap_select_array_remove(mmap, mpr);
+ }
+ mpr->state &= ~WM_MANIPULATOR_STATE_SELECT;
+ changed = true;
+ }
+ }
+
+ if (changed) {
+ if (mpr->type->select_refresh) {
+ mpr->type->select_refresh(mpr);
+ }
}
- mpr->state &= ~WM_MANIPULATOR_STATE_SELECT;
return changed;
}
-/**
- * Add \a manipulator to selection.
- * Reallocates memory for selected manipulators so better not call for selecting multiple ones.
- *
- * \return if the selection has changed.
- */
-bool wm_manipulator_select(bContext *C, wmManipulatorMap *mmap, wmManipulator *mpr)
+bool WM_manipulator_select_set(wmManipulatorMap *mmap, wmManipulator *mpr, bool select)
{
- wmManipulator ***sel = &mmap->mmap_context.selected;
- int *selected_len = &mmap->mmap_context.selected_len;
+ return wm_manipulator_select_set_ex(mmap, mpr, select, true);
+}
- if (!mpr || (mpr->state & WM_MANIPULATOR_STATE_SELECT))
+bool wm_manipulator_select_and_highlight(bContext *C, wmManipulatorMap *mmap, wmManipulator *mpr)
+{
+ if (WM_manipulator_select_set(mmap, mpr, true)) {
+ wm_manipulatormap_highlight_set(mmap, C, mpr, mpr->highlight_part);
+ return true;
+ }
+ else {
return false;
-
- (*selected_len)++;
-
- *sel = MEM_reallocN(*sel, sizeof(wmManipulator *) * (*selected_len));
- (*sel)[(*selected_len) - 1] = mpr;
-
- mpr->state |= WM_MANIPULATOR_STATE_SELECT;
- if (mpr->type->select) {
- mpr->type->select(C, mpr, SEL_SELECT);
}
- wm_manipulatormap_highlight_set(mmap, C, mpr, mpr->highlight_part);
-
- return true;
}
void wm_manipulator_calculate_scale(wmManipulator *mpr, const bContext *C)