| 
									
										
										
										
											2013-10-08 15:07:52 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup edinterface | 
					
						
							| 
									
										
										
										
											2013-10-08 15:07:52 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_screen_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "DNA_space_types.h"
 | 
					
						
							| 
									
										
										
										
											2013-10-08 15:07:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "UI_interface.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-08 15:32:54 +00:00
										 |  |  | #include "interface_intern.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #include "interface_eyedropper_intern.h" /* own include */
 | 
					
						
							| 
									
										
										
										
											2016-02-29 18:46:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Keymap
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | /** \name Modal Keymap
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | wmKeyMap *eyedropper_modal_keymap(wmKeyConfig *keyconf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   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}, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 10:58:00 +11:00
										 |  |  |   wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper Modal Map"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* this function is called for each spacetype, only needs to add map once */ | 
					
						
							|  |  |  |   if (keymap && keymap->modal_items) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 10:58:00 +11:00
										 |  |  |   keymap = WM_modalkeymap_ensure(keyconf, "Eyedropper Modal Map", modal_items); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* assign to operators */ | 
					
						
							|  |  |  |   WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp"); | 
					
						
							|  |  |  |   WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_color"); | 
					
						
							|  |  |  |   WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_id"); | 
					
						
							|  |  |  |   WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_depth"); | 
					
						
							|  |  |  |   WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_driver"); | 
					
						
							| 
									
										
										
										
											2019-10-11 13:28:22 +02:00
										 |  |  |   WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_gpencil_color"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return keymap; | 
					
						
							| 
									
										
										
										
											2016-02-29 18:46:20 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-12 10:19:55 +11:00
										 |  |  | wmKeyMap *eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   static const EnumPropertyItem modal_items_point[] = { | 
					
						
							|  |  |  |       {EYE_MODAL_POINT_CANCEL, "CANCEL", 0, "Cancel", ""}, | 
					
						
							| 
									
										
										
										
											2020-10-24 11:42:17 -07:00
										 |  |  |       {EYE_MODAL_POINT_SAMPLE, "SAMPLE_SAMPLE", 0, "Sample a Point", ""}, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       {EYE_MODAL_POINT_CONFIRM, "SAMPLE_CONFIRM", 0, "Confirm Sampling", ""}, | 
					
						
							|  |  |  |       {EYE_MODAL_POINT_RESET, "SAMPLE_RESET", 0, "Reset Sampling", ""}, | 
					
						
							|  |  |  |       {0, NULL, 0, NULL, NULL}, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 10:58:00 +11:00
										 |  |  |   wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Eyedropper ColorRamp PointSampling Map"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (keymap && keymap->modal_items) { | 
					
						
							|  |  |  |     return keymap; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 10:58:00 +11:00
										 |  |  |   keymap = WM_modalkeymap_ensure( | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       keyconf, "Eyedropper ColorRamp PointSampling Map", modal_items_point); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* assign to operators */ | 
					
						
							|  |  |  |   WM_modalkeymap_assign(keymap, "UI_OT_eyedropper_colorramp_point"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return keymap; | 
					
						
							| 
									
										
										
										
											2017-12-12 10:19:55 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-29 18:46:20 +01:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 08:01:40 +11:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Utility Functions
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | /** \name Generic Shared Functions
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  | void eyedropper_draw_cursor_text(const struct bContext *C, const ARegion *region, const char *name) | 
					
						
							| 
									
										
										
										
											2015-01-14 08:01:40 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; | 
					
						
							|  |  |  |   wmWindow *win = CTX_wm_window(C); | 
					
						
							|  |  |  |   int x = win->eventstate->x; | 
					
						
							|  |  |  |   int y = win->eventstate->y; | 
					
						
							|  |  |  |   const float col_fg[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | 
					
						
							|  |  |  |   const float col_bg[4] = {0.0f, 0.0f, 0.0f, 0.2f}; | 
					
						
							| 
									
										
										
										
											2015-01-20 15:48:40 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   if ((name[0] == '\0') || (BLI_rcti_isect_pt(®ion->winrct, x, y) == false)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-01-14 08:01:40 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   x = x - region->winrct.xmin; | 
					
						
							|  |  |  |   y = y - region->winrct.ymin; | 
					
						
							| 
									
										
										
										
											2015-01-14 08:01:40 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   y += U.widget_unit; | 
					
						
							| 
									
										
										
										
											2015-01-14 08:01:40 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, col_fg, col_bg); | 
					
						
							| 
									
										
										
										
											2015-01-14 08:01:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-27 01:22:19 +13:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * 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 | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2017-12-12 15:16:13 +11:00
										 |  |  | uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event) | 
					
						
							| 
									
										
										
										
											2016-03-27 01:22:19 +13:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bScreen *screen = CTX_wm_screen(C); | 
					
						
							| 
									
										
										
										
											2020-04-03 13:25:03 +02:00
										 |  |  |   ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->x, event->y); | 
					
						
							|  |  |  |   ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_ANY, event->x, event->y); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 16:56:42 +01:00
										 |  |  |   uiBut *but = ui_but_find_mouse_over(region, event); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (ELEM(NULL, but, but->rnapoin.data, but->rnaprop)) { | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-07-03 14:20:10 +02:00
										 |  |  |   return but; | 
					
						
							| 
									
										
										
										
											2016-03-27 01:22:19 +13:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-14 08:01:40 +11:00
										 |  |  | /** \} */ |