[Bf-blender-cvs] [b3c147a04f1] master: Cleanup: split eyedropper into separate files

Campbell Barton noreply at git.blender.org
Tue Dec 12 05:52:23 CET 2017


Commit: b3c147a04f16f6fe8ea4c902f9d58ec5dbcdb392
Author: Campbell Barton
Date:   Tue Dec 12 15:16:13 2017 +1100
Branches: master
https://developer.blender.org/rBb3c147a04f16f6fe8ea4c902f9d58ec5dbcdb392

Cleanup: split eyedropper into separate files

Each handles separate data-types and didn't share much logic,
better put each in it's own file.

===================================================================

M	source/blender/editors/interface/CMakeLists.txt
M	source/blender/editors/interface/interface_eyedropper.c
A	source/blender/editors/interface/interface_eyedropper_color.c
A	source/blender/editors/interface/interface_eyedropper_colorband.c
A	source/blender/editors/interface/interface_eyedropper_datablock.c
A	source/blender/editors/interface/interface_eyedropper_depth.c
A	source/blender/editors/interface/interface_eyedropper_driver.c
A	source/blender/editors/interface/interface_eyedropper_intern.h
M	source/blender/editors/interface/interface_intern.h

===================================================================

diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 7392db0c91b..a6315e0fcce 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -44,6 +44,11 @@ set(SRC
 	interface_anim.c
 	interface_draw.c
 	interface_eyedropper.c
+	interface_eyedropper_color.c
+	interface_eyedropper_colorband.c
+	interface_eyedropper_datablock.c
+	interface_eyedropper_depth.c
+	interface_eyedropper_driver.c
 	interface_handlers.c
 	interface_icons.c
 	interface_layout.c
diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c
index 9cf40c07c0d..381d9f3cc42 100644
--- a/source/blender/editors/interface/interface_eyedropper.c
+++ b/source/blender/editors/interface/interface_eyedropper.c
@@ -27,56 +27,23 @@
  *  \ingroup edinterface
  */
 
-#include "MEM_guardedalloc.h"
-
-#include "DNA_anim_types.h"
 #include "DNA_space_types.h"
 #include "DNA_screen_types.h"
-#include "DNA_object_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_math_vector.h"
 
-#include "BLT_translation.h"
-
 #include "BKE_context.h"
 #include "BKE_screen.h"
-#include "BKE_report.h"
-#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
-#include "BKE_idcode.h"
-#include "BKE_unit.h"
-
-#include "RNA_access.h"
-#include "RNA_define.h"
-
-#include "BIF_gl.h"
 
 #include "UI_interface.h"
 
-#include "IMB_colormanagement.h"
-
 #include "WM_api.h"
 #include "WM_types.h"
 
 #include "interface_intern.h"
 
-/* for HDR color sampling */
-#include "ED_image.h"
-#include "ED_node.h"
-#include "ED_clip.h"
-
-/* for ID data eyedropper */
-#include "ED_space_api.h"
-#include "ED_screen.h"
-#include "ED_view3d.h"
-
-/* for Driver eyedropper */
-#include "ED_keyframing.h"
-
-/* for colorband eyedropper*/
-#include "BLI_bitmap_draw_2d.h"
-#include "BKE_colorband.h"
+#include "interface_eyedropper_intern.h"  /* own include */
 
 /* -------------------------------------------------------------------- */
 /* Keymap
@@ -84,22 +51,6 @@
 /** \name Modal Keymap
  * \{ */
 
-enum {
-	EYE_MODAL_CANCEL = 1,
-	EYE_MODAL_SAMPLE_CONFIRM,
-	EYE_MODAL_SAMPLE_BEGIN,
-	EYE_MODAL_SAMPLE_RESET,
-};
-
-/* Color-band point sample. */
-enum {
-	EYE_MODAL_POINT_CANCEL = 1,
-	EYE_MODAL_POINT_SAMPLE,
-	EYE_MODAL_POINT_CONFIRM,
-	EYE_MODAL_POINT_RESET,
-	EYE_MODAL_POINT_REMOVE_LAST,
-};
-
 
 wmKeyMap *eyedropper_modal_keymap(wmKeyConfig *keyconf)
 {
@@ -178,7 +129,7 @@ wmKeyMap *eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf)
 /** \name Generic Shared Functions
  * \{ */
 
-static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, const char *name)
+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);
@@ -212,14 +163,14 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, c
  *
  * \return A button under the mouse which relates to some RNA Property, or NULL
  */
-static uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event)
+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;
 	}
@@ -230,1403 +181,3 @@ static uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEv
 
 /** \} */
 
-
-/* -------------------------------------------------------------------- */
-/* Eyedropper
- */
-
-/** \name Eyedropper (RGB Color)
- * \{ */
-
-typedef struct Eyedropper {
-	struct ColorManagedDisplay *display;
-
-	PointerRNA ptr;
-	PropertyRNA *prop;
-	int index;
-
-	float init_col[3]; /* for resetting on cancel */
-
-	bool  accum_start; /* has mouse been pressed */
-	float accum_col[3];
-	int   accum_tot;
-} Eyedropper;
-
-static bool eyedropper_init(bContext *C, wmOperator *op)
-{
-	Scene *scene = CTX_data_scene(C);
-	Eyedropper *eye;
-
-	op->customdata = eye = MEM_callocN(sizeof(Eyedropper), "Eyedropper");
-
-	UI_context_active_but_prop_get(C, &eye->ptr, &eye->prop, &eye->index);
-
-	if ((eye->ptr.data == NULL) ||
-	    (eye->prop == NULL) ||
-	    (RNA_property_editable(&eye->ptr, eye->prop) == false) ||
-	    (RNA_property_array_length(&eye->ptr, eye->prop) < 3) ||
-	    (RNA_property_type(eye->prop) != PROP_FLOAT))
-	{
-		return false;
-	}
-
-	if (RNA_property_subtype(eye->prop) != PROP_COLOR) {
-		const char *display_device;
-		float col[4];
-
-		display_device = scene->display_settings.display_device;
-		eye->display = IMB_colormanagement_display_get_named(display_device);
-
-		/* store inital color */
-		RNA_property_float_get_array(&eye->ptr, eye->prop, col);
-		if (eye->display) {
-			IMB_colormanagement_display_to_scene_linear_v3(col, eye->display);
-		}
-		copy_v3_v3(eye->init_col, col);
-	}
-
-	return true;
-}
-
-static void eyedropper_exit(bContext *C, wmOperator *op)
-{
-	WM_cursor_modal_restore(CTX_wm_window(C));
-
-	if (op->customdata) {
-		MEM_freeN(op->customdata);
-		op->customdata = NULL;
-	}
-}
-
-/* *** eyedropper_color_ helper functions *** */
-
-/**
- * \brief get the color from the screen.
- *
- * Special check for image or nodes where we MAY have HDR pixels which don't display.
- */
-static void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3])
-{
-
-	/* we could use some clever */
-	wmWindow *win = CTX_wm_window(C);
-	ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my);
-	const char *display_device = CTX_data_scene(C)->display_settings.display_device;
-	struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
-
-	if (sa) {
-		if (sa->spacetype == SPACE_IMAGE) {
-			ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my);
-			if (ar) {
-				SpaceImage *sima = sa->spacedata.first;
-				int mval[2] = {mx - ar->winrct.xmin,
-				               my - ar->winrct.ymin};
-
-				if (ED_space_image_color_sample(sima, ar, mval, r_col)) {
-					return;
-				}
-			}
-		}
-		else if (sa->spacetype == SPACE_NODE) {
-			ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my);
-			if (ar) {
-				SpaceNode *snode = sa->spacedata.first;
-				int mval[2] = {mx - ar->winrct.xmin,
-				               my - ar->winrct.ymin};
-
-				if (ED_space_node_color_sample(snode, ar, mval, r_col)) {
-					return;
-				}
-			}
-		}
-		else if (sa->spacetype == SPACE_CLIP) {
-			ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my);
-			if (ar) {
-				SpaceClip *sc = sa->spacedata.first;
-				int mval[2] = {mx - ar->winrct.xmin,
-				               my - ar->winrct.ymin};
-
-				if (ED_space_clip_color_sample(sc, ar, mval, r_col)) {
-					return;
-				}
-			}
-		}
-	}
-
-	/* fallback to simple opengl picker */
-	glReadBuffer(GL_FRONT);
-	glReadPixels(mx, my, 1, 1, GL_RGB, GL_FLOAT, r_col);
-	glReadBuffer(GL_BACK);
-	
-	IMB_colormanagement_display_to_scene_linear_v3(r_col, display);
-}
-
-/* sets the sample color RGB, maintaining A */
-static void eyedropper_color_set(bContext *C, Eyedropper *eye, const float col[3])
-{
-	float col_conv[4];
-
-	/* to maintain alpha */
-	RNA_property_float_get_array(&eye->ptr, eye->prop, col_conv);
-
-	/* convert from linear rgb space to display space */
-	if (eye->display) {
-		copy_v3_v3(col_conv, col);
-		IMB_colormanagement_scene_linear_to_display_v3(col_conv, eye->display);
-	}
-	else {
-		copy_v3_v3(col_conv, col);
-	}
-
-	RNA_property_float_set_array(&eye->ptr, eye->prop, col_conv);
-
-	RNA_property_update(C, &eye->ptr, eye->prop);
-}
-
-/* set sample from accumulated values */
-static void eyedropper_color_set_accum(bContext *C, Eyedropper *eye)
-{
-	float col[3];
-	mul_v3_v3fl(col, eye->accum_col, 1.0f / (float)eye->accum_tot);
-	eyedropper_color_set(C, eye, col);
-}
-
-/* single point sample & set */
-static void eyedropper_color_sample(bContext *C, Eyedropper *eye, int mx, int my)
-{
-	float col[3];
-	eyedropper_color_sample_fl(C, mx, my, col);
-	eyedropper_color_set(C, eye, col);
-}
-
-static void eyedropper_color_sample_accum(bContext *C, Eyedropper *eye, int mx, int my)
-{
-	float col[3];
-	eyedropper_color_sample_fl(C, mx, my, col);
-	/* delay linear conversion */
-	add_v3_v3(eye->accum_col, col);
-	eye->accum_tot++;
-}
-
-static void eyedropper_cancel(bContext *C, wmOperator *op)
-{
-	Eyedropper *eye = op->customdata;
-	eyedropper_color_set(C, eye, eye->init_col);
-	eyedropper_exit(C, op);
-}
-
-/* main modal status check */
-static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event)
-{
-	Eyedropper *eye = (Eyedropper *)op->customdata;
-
-	/* handle modal keymap */
-	if (event->type == EVT_MODAL_MAP) {
-		switch (event->val) {
-			case EYE_MODAL_CANCEL:
-				eyedropper_cancel(C, op);
-				return OPERATOR_CANCELLED;
-			case EYE_MODAL_SAMPLE_CONFIRM:
-				if (eye->accum_tot == 0) {
-					eyedropper_color_sample(C, eye, event->x, event->y);
-				}
-				else {
-					eyedropper_color_set_accum(C, eye);
-				}
-				eyedropper_exit(C, op);
-				return OPERATOR_FINISHED;
-			case EYE_MODAL_SAMPLE_BEGIN:
-				/* enable accum and make first sample */
-				eye->accum_start = true;
-				eyedropper_color_sample_accum(C, eye, event->x, event->y);
-				break;
-			case EYE_MODAL_SAMPLE_RESET:
-				eye->accum_tot = 0;
-				zero_v3(eye->accum_col);
-				eyedropper_color_sample_accum(C, eye, event->x, event->y);
-				eyedropper_color_set_accum(C, eye);
-				break;
-		}
-	}
-	else if (event->type == MOUSEMOVE) {
-		if (eye->accum_start) {
-			/* button is pressed so keep sampling */
-			eyedropper_color_sample_accum(C, eye, event->x, event->y);
-			eyedropper_color_set_accum(C, eye);
-		}
-	}
-
-	return OPERATOR_RUNNING_MODAL;
-}
-
-/* Modal Operator init */
-static int eyedropper_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
-	/* init */
-	if (eyedropper_init(C, op)) {
-		WM_cursor_modal_set(CTX_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list