This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/editors/interface/interface_eyedropper.c

183 lines
6.1 KiB
C
Raw Normal View History

/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Blender Foundation, Joshua Leung
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/interface/interface_eyedropper.c
* \ingroup edinterface
*/
#include "DNA_space_types.h"
#include "DNA_screen_types.h"
#include "BLI_blenlib.h"
#include "BLI_math_vector.h"
#include "BKE_context.h"
#include "BKE_screen.h"
#include "UI_interface.h"
#include "WM_api.h"
#include "WM_types.h"
#include "interface_intern.h"
#include "interface_eyedropper_intern.h" /* own include */
/* -------------------------------------------------------------------- */
/* Keymap
*/
/** \name Modal Keymap
* \{ */
wmKeyMap *eyedropper_modal_keymap(wmKeyConfig *keyconf)
{
static const EnumPropertyItem modal_items[] = {
{EYE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
{EYE_MODAL_SAMPLE_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
{EYE_MODAL_SAMPLE_BEGIN, "SAMPLE_BEGIN", 0, "Start Sampling", ""},
{EYE_MODAL_SAMPLE_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
{0, NULL, 0, NULL, NULL}
};
wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Eyedropper Modal Map");
/* this function is called for each spacetype, only needs to add map once */
if (keymap && keymap->modal_items)
return NULL;
keymap = WM_modalkeymap_add(keyconf, "Eyedropper Modal Map", modal_items);
/* items for modal map */
WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, EYE_MODAL_CANCEL);
WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, EYE_MODAL_CANCEL);
WM_modalkeymap_add_item(keymap, RETKEY, KM_RELEASE, KM_ANY, 0, EYE_MODAL_SAMPLE_CONFIRM);
WM_modalkeymap_add_item(keymap, PADENTER, KM_RELEASE, KM_ANY, 0, EYE_MODAL_SAMPLE_CONFIRM);
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, EYE_MODAL_SAMPLE_CONFIRM);
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, EYE_MODAL_SAMPLE_BEGIN);
WM_modalkeymap_add_item(keymap, SPACEKEY, KM_RELEASE, KM_ANY, 0, EYE_MODAL_SAMPLE_RESET);
/* assign to operators */
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorband");
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_color");
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_id");
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_depth");
Driver Setup Workflow Improvement: Property Eyedropper This commit brings some long requested improvements to the workflow for setting up drivers, which should make it easier and faster to set up new drivers in a more interactive fashion. The new workflow is as follows: 1) Hover over the property (e.g. "Lamp Energy" or "Y Location") or properties ("Rotation") you wish to add drivers to. We'll refer to this as the "destination" 2) Ctrl-D to active the new "Add Drivers" eyedropper 3) Click on the property you want to use as the source/target. The property under the mouse will be used to drive the property you invoked Ctrl-D on. For example, to drive the X, Y, and Z location of the Cube using the Y Location of the Lamp, hover over any of the X/Y/Z location buttons, hit Ctrl-D, then click on the Y-Location button of the Lamp object. Drivers will be added to the X, Y, and Z Location properties of the Cube; each driver will have a single variable, which uses the Y-Location Transform Channel of the Lamp. Tips: - Transform properties will automatically create "Transform Channel" driver variables. Everything else will use "Single Property" ones - Due to the way that Blender's UI Context works, you'll need two Properties Panel instances open (and to have pinned one of the two to show the properties for the unselected object). It's slightly clunky, but necessary for implementing a workflow like this, as the UI cannot be manipulated while using eyedroppers to pick data. - The eyedropper operator implemented here actually has three modes of operation. 1) The "1-N" (one to many) mode is the default used for Ctrl-D, and "Add Driver to All" in the RMB Menu. This is the behaviour described above. 2) There's also a "1-1" (one to one) mode that is used for the "Add Single Driver" in the RMB Menu. 3) Finally, there's the "N-N" mode (many to many), which isn't currently exposed. The point of this is to allow mapping XYZ to XYZ elementwise (i.e. direct copying) which is useful for things like locations, rotations, scaling, and colours. Implementation Notes: - The bulk of the driver adding logic is in editors/animation/drivers.c, where most of the Driver UI operators and tools are defined - The property eyedropper code is in interface_eyedropper.c along with all the other eyedroppers (even though they don't share much actual code in common). However, this turns out to be necessary, as we can't get access to many of the low-level buttons API's otherwise. Todo: - It may be necessary to restore a way to access the old behaviour (i.e. "manual setup") in case it is not practical to immediately pick a property. - Other things to investigate here include extra hotkeys (e.g. Ctrl-Shift-D for Add Single?), and to expose the N-N mode. - Other things we could try include interactively applying scaling factors, picking multiple targets (e.g. for location difference and rotation difference drivers), and/or other ways of using these property picking methods.
2016-03-26 17:55:42 +13:00
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_driver");
return keymap;
}
wmKeyMap *eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf)
{
static const EnumPropertyItem modal_items_point[] = {
{EYE_MODAL_POINT_CANCEL, "CANCEL", 0, "Cancel", ""},
{EYE_MODAL_POINT_SAMPLE, "SAMPLE_SAMPLE", 0, "Sample a point", ""},
{EYE_MODAL_POINT_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""},
{EYE_MODAL_POINT_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""},
{0, NULL, 0, NULL, NULL}
};
wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Eyedropper ColorBand PointSampling Map");
if (keymap && keymap->modal_items)
return keymap;
keymap = WM_modalkeymap_add(keyconf, "Eyedropper ColorBand PointSampling Map", modal_items_point);
/* items for modal map */
WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, EYE_MODAL_CANCEL);
WM_modalkeymap_add_item(keymap, BACKSPACEKEY, KM_PRESS, KM_ANY, 0, EYE_MODAL_POINT_REMOVE_LAST);
WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, EYE_MODAL_POINT_CONFIRM);
WM_modalkeymap_add_item(keymap, RETKEY, KM_RELEASE, KM_ANY, 0, EYE_MODAL_POINT_CONFIRM);
WM_modalkeymap_add_item(keymap, PADENTER, KM_RELEASE, KM_ANY, 0, EYE_MODAL_POINT_CONFIRM);
WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, EYE_MODAL_POINT_SAMPLE);
WM_modalkeymap_add_item(keymap, SPACEKEY, KM_RELEASE, KM_ANY, 0, EYE_MODAL_POINT_RESET);
/* assign to operators */
WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorband_point");
return keymap;
}
/** \} */
/* -------------------------------------------------------------------- */
/* Utility Functions
*/
/** \name Generic Shared Functions
* \{ */
void eyedropper_draw_cursor_text(const struct bContext *C, const ARegion *ar, const char *name)
{
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
wmWindow *win = CTX_wm_window(C);
int x = win->eventstate->x;
int y = win->eventstate->y;
const unsigned char fg[4] = {255, 255, 255, 255};
const unsigned char bg[4] = {0, 0, 0, 50};
if ((name[0] == '\0') ||
(BLI_rcti_isect_pt(&ar->winrct, x, y) == false))
{
return;
}
x = x - ar->winrct.xmin;
y = y - ar->winrct.ymin;
y += U.widget_unit;
UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, fg, bg);
}
/**
* Utility to retrieve a button representing a RNA property that is currently under the cursor.
*
* This is to be used by any eyedroppers which fetch properties (e.g. UI_OT_eyedropper_driver).
* Especially during modal operations (e.g. as with the eyedroppers), context cannot be relied
* upon to provide this information, as it is not updated until the operator finishes.
*
* \return A button under the mouse which relates to some RNA Property, or NULL
*/
uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, event->x, event->y);
ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_ANY, event->x, event->y);
uiBut *but = ui_but_find_mouse_over(ar, event);
if (ELEM(NULL, but, but->rnapoin.data, but->rnaprop)) {
return NULL;
}
else {
return but;
}
}
/** \} */