Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/paint_image.c
| Show First 20 Lines • Show All 936 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /******************** sample color operator ********************/ | /******************** sample color operator ********************/ | ||||
| typedef struct { | typedef struct { | ||||
| bool show_cursor; | bool show_cursor; | ||||
| short event_type; | short event_type; | ||||
| float initcolor[3]; | float initcolor[3]; | ||||
| bool sample_palette; | bool sample_palette; | ||||
| struct EDSelectID_Context *sel_id_ctx; | |||||
| } SampleColorData; | } SampleColorData; | ||||
| static void sample_color_data_free(SampleColorData *data) | |||||
| { | |||||
| if (data->sel_id_ctx) { | |||||
| ED_view3d_select_id_context_destroy(data->sel_id_ctx); | |||||
| } | |||||
| MEM_freeN(data); | |||||
| } | |||||
| static void sample_color_update_header(SampleColorData *data, bContext *C) | static void sample_color_update_header(SampleColorData *data, bContext *C) | ||||
| { | { | ||||
| char msg[UI_MAX_DRAW_STR]; | char msg[UI_MAX_DRAW_STR]; | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| if (sa) { | if (sa) { | ||||
| BLI_snprintf(msg, | BLI_snprintf(msg, | ||||
| sizeof(msg), | sizeof(msg), | ||||
| Show All 20 Lines | static int sample_color_exec(bContext *C, wmOperator *op) | ||||
| WM_paint_cursor_tag_redraw(win, ar); | WM_paint_cursor_tag_redraw(win, ar); | ||||
| WM_redraw_windows(C); | WM_redraw_windows(C); | ||||
| RNA_int_get_array(op->ptr, "location", location); | RNA_int_get_array(op->ptr, "location", location); | ||||
| const bool use_palette = RNA_boolean_get(op->ptr, "palette"); | const bool use_palette = RNA_boolean_get(op->ptr, "palette"); | ||||
| const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && | const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && | ||||
| !RNA_boolean_get(op->ptr, "merged"); | !RNA_boolean_get(op->ptr, "merged"); | ||||
| paint_sample_color(C, ar, location[0], location[1], use_sample_texture, use_palette); | struct EDSelectID_Context *sel_id_ctx = NULL; | ||||
| paint_sample_color( | |||||
| C, ar, &sel_id_ctx, location[0], location[1], use_sample_texture, use_palette); | |||||
| if (sel_id_ctx) { | |||||
| ED_view3d_select_id_context_destroy(sel_id_ctx); | |||||
| } | |||||
| if (show_cursor) { | if (show_cursor) { | ||||
| paint->flags |= PAINT_SHOW_BRUSH; | paint->flags |= PAINT_SHOW_BRUSH; | ||||
| } | } | ||||
| WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); | WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event) | static int sample_color_invoke(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Paint *paint = BKE_paint_get_active_from_context(C); | Paint *paint = BKE_paint_get_active_from_context(C); | ||||
| Brush *brush = BKE_paint_brush(paint); | Brush *brush = BKE_paint_brush(paint); | ||||
| SampleColorData *data = MEM_mallocN(sizeof(SampleColorData), "sample color custom data"); | SampleColorData *data = MEM_mallocN(sizeof(SampleColorData), "sample color custom data"); | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| data->event_type = event->type; | data->event_type = event->type; | ||||
| data->show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0); | data->show_cursor = ((paint->flags & PAINT_SHOW_BRUSH) != 0); | ||||
| copy_v3_v3(data->initcolor, BKE_brush_color_get(scene, brush)); | copy_v3_v3(data->initcolor, BKE_brush_color_get(scene, brush)); | ||||
| data->sample_palette = false; | data->sample_palette = false; | ||||
| data->sel_id_ctx = NULL; | |||||
| op->customdata = data; | op->customdata = data; | ||||
| paint->flags &= ~PAINT_SHOW_BRUSH; | paint->flags &= ~PAINT_SHOW_BRUSH; | ||||
| sample_color_update_header(data, C); | sample_color_update_header(data, C); | ||||
| WM_event_add_modal_handler(C, op); | WM_event_add_modal_handler(C, op); | ||||
| /* force redraw without cursor */ | /* force redraw without cursor */ | ||||
| WM_paint_cursor_tag_redraw(win, ar); | WM_paint_cursor_tag_redraw(win, ar); | ||||
| WM_redraw_windows(C); | WM_redraw_windows(C); | ||||
| RNA_int_set_array(op->ptr, "location", event->mval); | RNA_int_set_array(op->ptr, "location", event->mval); | ||||
| ePaintMode mode = BKE_paintmode_get_active_from_context(C); | ePaintMode mode = BKE_paintmode_get_active_from_context(C); | ||||
| const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && | const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && | ||||
| !RNA_boolean_get(op->ptr, "merged"); | !RNA_boolean_get(op->ptr, "merged"); | ||||
| paint_sample_color(C, ar, event->mval[0], event->mval[1], use_sample_texture, false); | paint_sample_color( | ||||
| C, ar, &data->sel_id_ctx, event->mval[0], event->mval[1], use_sample_texture, false); | |||||
| WM_cursor_modal_set(win, BC_EYEDROPPER_CURSOR); | WM_cursor_modal_set(win, BC_EYEDROPPER_CURSOR); | ||||
| WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); | WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); | ||||
| return OPERATOR_RUNNING_MODAL; | return OPERATOR_RUNNING_MODAL; | ||||
| } | } | ||||
| static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event) | static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SampleColorData *data = op->customdata; | SampleColorData *data = op->customdata; | ||||
| Paint *paint = BKE_paint_get_active_from_context(C); | Paint *paint = BKE_paint_get_active_from_context(C); | ||||
| Brush *brush = BKE_paint_brush(paint); | Brush *brush = BKE_paint_brush(paint); | ||||
| if ((event->type == data->event_type) && (event->val == KM_RELEASE)) { | if ((event->type == data->event_type) && (event->val == KM_RELEASE)) { | ||||
| if (data->show_cursor) { | if (data->show_cursor) { | ||||
| paint->flags |= PAINT_SHOW_BRUSH; | paint->flags |= PAINT_SHOW_BRUSH; | ||||
| } | } | ||||
| if (data->sample_palette) { | if (data->sample_palette) { | ||||
| BKE_brush_color_set(scene, brush, data->initcolor); | BKE_brush_color_set(scene, brush, data->initcolor); | ||||
| RNA_boolean_set(op->ptr, "palette", true); | RNA_boolean_set(op->ptr, "palette", true); | ||||
| } | } | ||||
| WM_cursor_modal_restore(CTX_wm_window(C)); | WM_cursor_modal_restore(CTX_wm_window(C)); | ||||
| MEM_freeN(data); | sample_color_data_free(data); | ||||
| ED_workspace_status_text(C, NULL); | ED_workspace_status_text(C, NULL); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| ePaintMode mode = BKE_paintmode_get_active_from_context(C); | ePaintMode mode = BKE_paintmode_get_active_from_context(C); | ||||
| const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && | const bool use_sample_texture = (mode == PAINT_MODE_TEXTURE_3D) && | ||||
| !RNA_boolean_get(op->ptr, "merged"); | !RNA_boolean_get(op->ptr, "merged"); | ||||
| switch (event->type) { | switch (event->type) { | ||||
| case MOUSEMOVE: { | case MOUSEMOVE: { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| RNA_int_set_array(op->ptr, "location", event->mval); | RNA_int_set_array(op->ptr, "location", event->mval); | ||||
| paint_sample_color(C, ar, event->mval[0], event->mval[1], use_sample_texture, false); | paint_sample_color( | ||||
| C, ar, &data->sel_id_ctx, event->mval[0], event->mval[1], use_sample_texture, false); | |||||
| WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); | WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); | ||||
| break; | break; | ||||
| } | } | ||||
| case LEFTMOUSE: | case LEFTMOUSE: | ||||
| if (event->val == KM_PRESS) { | if (event->val == KM_PRESS) { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| RNA_int_set_array(op->ptr, "location", event->mval); | RNA_int_set_array(op->ptr, "location", event->mval); | ||||
| paint_sample_color(C, ar, event->mval[0], event->mval[1], use_sample_texture, true); | paint_sample_color( | ||||
| C, ar, &data->sel_id_ctx, event->mval[0], event->mval[1], use_sample_texture, true); | |||||
| if (!data->sample_palette) { | if (!data->sample_palette) { | ||||
| data->sample_palette = true; | data->sample_palette = true; | ||||
| sample_color_update_header(data, C); | sample_color_update_header(data, C); | ||||
| } | } | ||||
| WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); | WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 264 Lines • Show Last 20 Lines | |||||