Blender V5.3
interface_template_curve_mapping.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_colortools.hh"
10#include "BKE_context.hh"
11#include "BKE_library.hh"
12
13#include "BLI_bounds.hh"
14#include "BLI_math_base_c.hh"
16#include "BLI_rect.hh"
17#include "BLI_string_ref.hh"
18
19#include "BLT_translation.hh"
20
21#include "ED_screen.hh"
22#include "ED_undo.hh"
23
24#include "RNA_access.hh"
25#include "RNA_prototypes.hh"
26
28#include "interface_intern.hh"
30
31namespace blender::ui {
32
33using blender::Vector;
34
35namespace {
36struct CurveRuntimeProperties {
37 CurveMapPoint *last_pt = nullptr;
38 float2 last_pos;
39};
40} // namespace
41
43{
44 return (cumap->flag & CUMA_DO_CLIP) == 0 ||
45 (BLI_rctf_size_x(&cumap->curr) < BLI_rctf_size_x(&cumap->clipr));
46}
47
49{
50 return (cumap->flag & CUMA_DO_CLIP) == 0 ||
52}
53
54static void curvemap_zoom(CurveMapping &cumap, const float scale)
55{
56 const Bounds<float2> curr_bounds(float2(cumap.curr.xmin, cumap.curr.ymin),
57 float2(cumap.curr.xmax, cumap.curr.ymax));
58 const float2 offset = curr_bounds.size() * 0.5f * (scale - 1.0f);
59 const Bounds<float2> new_bounds(curr_bounds.min - offset, curr_bounds.max + offset);
60
61 Bounds<float2> clamped_bounds = new_bounds;
62 /* Clamp to clip bounds if enabled, snap if the difference is small. */
63 if (cumap.flag & CUMA_DO_CLIP) {
64 const Bounds<float2> clip_bounds(float2(cumap.clipr.xmin, cumap.clipr.ymin),
65 float2(cumap.clipr.xmax, cumap.clipr.ymax));
66 const float2 threshold = 0.01f * clip_bounds.size();
67 if (clamped_bounds.min.x < clip_bounds.min.x + threshold.x) {
68 clamped_bounds.min.x = clip_bounds.min.x;
69 }
70 if (clamped_bounds.min.y < clip_bounds.min.y + threshold.y) {
71 clamped_bounds.min.y = clip_bounds.min.y;
72 }
73 if (clamped_bounds.max.x > clip_bounds.max.x - threshold.x) {
74 clamped_bounds.max.x = clip_bounds.max.x;
75 }
76 if (clamped_bounds.max.y > clip_bounds.max.y - threshold.y) {
77 clamped_bounds.max.y = clip_bounds.max.y;
78 }
79 }
80 cumap.curr.xmin = clamped_bounds.min.x;
81 cumap.curr.ymin = clamped_bounds.min.y;
82 cumap.curr.xmax = clamped_bounds.max.x;
83 cumap.curr.ymax = clamped_bounds.max.y;
84}
85
87{
88 if (!curvemap_can_zoom_in(cumap)) {
89 return;
90 }
91
92 curvemap_zoom(*cumap, 0.7692f);
93
95}
96
98{
99 if (!curvemap_can_zoom_out(cumap)) {
100 return;
101 }
102
103 curvemap_zoom(*cumap, 1.3f);
104
106}
107
108/* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
109static Block *curvemap_clipping_func(bContext *C, ARegion *region, void *cumap_v)
110{
111 CurveMapping *cumap = static_cast<CurveMapping *>(cumap_v);
112 Button *bt;
113 const float width = 8 * UI_UNIT_X;
114
115 Block *block = block_begin(C, region, __func__, EmbossType::Emboss);
118
119 bt = uiDefButBit(block,
122 IFACE_("Clipping"),
123 0,
124 5 * UI_UNIT_Y,
125 width,
126 UI_UNIT_Y,
127 &cumap->flag,
128 0.0,
129 0.0,
130 "");
131 button_func_set(bt, [cumap](bContext & /*C*/) { BKE_curvemapping_changed(cumap, false); });
132
133 block_align_begin(block);
134 bt = uiDefButV(block,
136 IFACE_("Min X:"),
137 0,
138 4 * UI_UNIT_Y,
139 width,
140 UI_UNIT_Y,
141 &cumap->clipr.xmin,
142 -100.0,
143 cumap->clipr.xmax,
144 "");
147 bt = uiDefButV(block,
149 IFACE_("Min Y:"),
150 0,
151 3 * UI_UNIT_Y,
152 width,
153 UI_UNIT_Y,
154 &cumap->clipr.ymin,
155 -100.0,
156 cumap->clipr.ymax,
157 "");
160 bt = uiDefButV(block,
162 IFACE_("Max X:"),
163 0,
164 2 * UI_UNIT_Y,
165 width,
166 UI_UNIT_Y,
167 &cumap->clipr.xmax,
168 cumap->clipr.xmin,
169 100.0,
170 "");
173 bt = uiDefButV(block,
175 IFACE_("Max Y:"),
176 0,
177 UI_UNIT_Y,
178 width,
179 UI_UNIT_Y,
180 &cumap->clipr.ymax,
181 cumap->clipr.ymin,
182 100.0,
183 "");
186
187 block_bounds_set_normal(block, 0.3f * U.widget_unit);
189
190 return block;
191}
192
194 bContext *C, ARegion *region, RNAUpdateCb &cb, bool show_extend, CurveMapSlopeType reset_mode)
195{
196 PointerRNA cumap_ptr = RNA_property_pointer_get(&cb.ptr, cb.prop);
197 CurveMapping *cumap = static_cast<CurveMapping *>(cumap_ptr.data);
198
199 short yco = 0;
200 const short menuwidth = 10 * UI_UNIT_X;
201
202 Block *block = block_begin(C, region, __func__, EmbossType::Emboss);
203
204 {
205 Button *but = uiDefIconTextBut(block,
207 ICON_BLANK1,
208 IFACE_("Reset View"),
209 0,
210 yco -= UI_UNIT_Y,
211 menuwidth,
212 UI_UNIT_Y,
213 nullptr,
214 "");
215 button_func_set(but, [cumap](bContext &C) {
218 });
219 }
220
221 if (show_extend && !(cumap->flag & CUMA_USE_WRAPPING)) {
222 {
223 Button *but = uiDefIconTextBut(block,
225 ICON_BLANK1,
226 IFACE_("Extend Horizontal"),
227 0,
228 yco -= UI_UNIT_Y,
229 menuwidth,
230 UI_UNIT_Y,
231 nullptr,
232 "");
233 button_func_set(but, [cumap, cb](bContext &C) {
235 BKE_curvemapping_changed(cumap, false);
236 rna_update_cb(C, cb);
237 ED_undo_push(&C, "CurveMap tools");
239 });
240 }
241 {
242 Button *but = uiDefIconTextBut(block,
244 ICON_BLANK1,
245 IFACE_("Extend Extrapolated"),
246 0,
247 yco -= UI_UNIT_Y,
248 menuwidth,
249 UI_UNIT_Y,
250 nullptr,
251 "");
252 button_func_set(but, [cumap, cb](bContext &C) {
254 BKE_curvemapping_changed(cumap, false);
255 rna_update_cb(C, cb);
256 ED_undo_push(&C, "CurveMap tools");
258 });
259 }
260 }
261
262 {
263 Button *but = uiDefIconTextBut(block,
265 ICON_BLANK1,
266 IFACE_("Reset Curve"),
267 0,
268 yco -= UI_UNIT_Y,
269 menuwidth,
270 UI_UNIT_Y,
271 nullptr,
272 "");
273 button_func_set(but, [cumap, cb, reset_mode](bContext &C) {
274 CurveMap *cuma = cumap->cm + cumap->cur;
275 BKE_curvemap_reset(cuma, &cumap->clipr, cumap->preset, reset_mode);
276 BKE_curvemapping_changed(cumap, false);
277 rna_update_cb(C, cb);
278 ED_undo_push(&C, "CurveMap tools");
280 });
281 }
282
284 block_bounds_set_text(block, 3.0f * UI_UNIT_X);
285
286 return block;
287}
288
290{
291 return curvemap_tools_func(
292 C, region, *static_cast<RNAUpdateCb *>(cb_v), true, CurveMapSlopeType::Positive);
293}
294
296{
297 return curvemap_tools_func(
298 C, region, *static_cast<RNAUpdateCb *>(cb_v), true, CurveMapSlopeType::Negative);
299}
300
301static Block *curvemap_brush_tools_func(bContext *C, ARegion *region, void *cb_v)
302{
303 return curvemap_tools_func(
304 C, region, *static_cast<RNAUpdateCb *>(cb_v), false, CurveMapSlopeType::Positive);
305}
306
308{
309 return curvemap_tools_func(
310 C, region, *static_cast<RNAUpdateCb *>(cb_v), false, CurveMapSlopeType::Negative);
311}
312
317
318static void add_preset_button(Block *block,
319 const float dx,
320 const int icon,
321 std::optional<StringRef> tip,
322 CurveMapping *cumap,
323 const bool neg_slope,
324 const eCurveMappingPreset preset,
325 const RNAUpdateCb &cb)
326{
327 Button *bt = uiDefIconBut(
328 block, ButtonType::Row, icon, 0, 0, dx, dx, &cumap->cur, 0.0, 3.0, tip);
329 button_func_set(bt, [&, cumap, neg_slope, preset, cb](bContext &C) {
330 const CurveMapSlopeType slope = neg_slope ? CurveMapSlopeType::Negative :
333 cumap->preset = preset;
334 BKE_curvemap_reset(cumap->cm, &cumap->clipr, cumap->preset, slope);
335 BKE_curvemapping_changed(cumap, false);
336 rna_update_cb(C, cb);
337 });
338}
339
345static void curvemap_buttons_layout(Layout *layout,
346 PointerRNA *ptr,
347 char labeltype,
348 bool levels,
349 bool brush,
350 bool neg_slope,
351 bool tone,
352 bool presets,
353 const RNAUpdateCb &cb)
354{
355 CurveMapping *cumap = static_cast<CurveMapping *>(ptr->data);
356 CurveMap *cm = &cumap->cm[cumap->cur];
357 Button *bt;
358 const float dx = UI_UNIT_X;
360
361 Block *block = layout->block();
362
364
365 if (tone) {
366 Layout &split = layout->split(0.0f, false);
367 split.row(false).prop(ptr, "tone", ITEM_R_EXPAND, std::nullopt, ICON_NONE);
368 }
369
370 /* curve chooser */
371 Layout *row = &layout->row(false);
372
373 if (labeltype == 'v') {
374 /* vector */
375 Layout &sub = row->row(true);
377
378 if (cumap->cm[0].curve) {
379 bt = uiDefButV(block, ButtonType::Row, "X", 0, 0, dx, dx, &cumap->cur, 0.0, 0.0, "");
381 }
382 if (cumap->cm[1].curve) {
383 bt = uiDefButV(block, ButtonType::Row, "Y", 0, 0, dx, dx, &cumap->cur, 0.0, 1.0, "");
385 }
386 if (cumap->cm[2].curve) {
387 bt = uiDefButV(block, ButtonType::Row, "Z", 0, 0, dx, dx, &cumap->cur, 0.0, 2.0, "");
389 }
390 }
391 else if (labeltype == 'c' && cumap->tone != CURVE_TONE_FILMLIKE) {
392 /* color */
393 Layout &sub = row->row(true);
395
396 if (cumap->cm[3].curve) {
397 bt = uiDefButV(block,
400 0,
401 0,
402 dx,
403 dx,
404 &cumap->cur,
405 0.0,
406 3.0,
407 TIP_("Combined channels"));
409 }
410 if (cumap->cm[0].curve) {
411 bt = uiDefButV(block,
414 0,
415 0,
416 dx,
417 dx,
418 &cumap->cur,
419 0.0,
420 0.0,
421 TIP_("Red channel"));
423 }
424 if (cumap->cm[1].curve) {
425 bt = uiDefButV(block,
428 0,
429 0,
430 dx,
431 dx,
432 &cumap->cur,
433 0.0,
434 1.0,
435 TIP_("Green channel"));
437 }
438 if (cumap->cm[2].curve) {
439 bt = uiDefButV(block,
442 0,
443 0,
444 dx,
445 dx,
446 &cumap->cur,
447 0.0,
448 2.0,
449 TIP_("Blue channel"));
451 }
452 }
453 else if (labeltype == 'h') {
454 /* HSV */
455 Layout &sub = row->row(true);
457
458 if (cumap->cm[0].curve) {
459 bt = uiDefButV(block,
462 0,
463 0,
464 dx,
465 dx,
466 &cumap->cur,
467 0.0,
468 0.0,
469 TIP_("Hue level"));
471 }
472 if (cumap->cm[1].curve) {
473 bt = uiDefButV(block,
476 0,
477 0,
478 dx,
479 dx,
480 &cumap->cur,
481 0.0,
482 1.0,
483 TIP_("Saturation level"));
485 }
486 if (cumap->cm[2].curve) {
487 bt = uiDefButV(block,
490 0,
491 0,
492 dx,
493 dx,
494 &cumap->cur,
495 0.0,
496 2.0,
497 TIP_("Value level"));
499 }
500 }
501 else {
503 }
504
505 if (labeltype == 'h') {
506 bg = GRAD_H;
507 }
508
509 /* operation buttons */
510 /* (Right aligned) */
511 Layout &sub = row->row(true);
513
514 if (!(cumap->flag & CUMA_USE_WRAPPING)) {
515 /* Zoom in */
516 bt = uiDefIconBut(
517 block, ButtonType::But, ICON_ZOOM_IN, 0, 0, dx, dx, nullptr, 0.0, 0.0, TIP_("Zoom in"));
518 button_func_set(bt, [cumap](bContext &C) { curvemap_buttons_zoom_in(&C, cumap); });
519 if (!curvemap_can_zoom_in(cumap)) {
520 button_disable(bt, "");
521 }
522
523 /* Zoom out */
524 bt = uiDefIconBut(
525 block, ButtonType::But, ICON_ZOOM_OUT, 0, 0, dx, dx, nullptr, 0.0, 0.0, TIP_("Zoom out"));
526 button_func_set(bt, [cumap](bContext &C) { curvemap_buttons_zoom_out(&C, cumap); });
527 if (!curvemap_can_zoom_out(cumap)) {
528 button_disable(bt, "");
529 }
530
531 /* Clipping button. */
532 const int icon = (cumap->flag & CUMA_DO_CLIP) ? ICON_CLIPUV_HLT : ICON_CLIPUV_DEHLT;
534 block, curvemap_clipping_func, cumap, icon, 0, 0, dx, dx, TIP_("Clipping options"));
536 button_func_set(bt, [cb](bContext &C) { rna_update_cb(C, cb); });
537 }
538
539 RNAUpdateCb *tools_cb = MEM_new<RNAUpdateCb>(__func__, cb);
540 if (brush && neg_slope) {
541 bt = uiDefIconBlockBut(block,
543 tools_cb,
544 ICON_NONE,
545 0,
546 0,
547 dx,
548 dx,
549 TIP_("Tools"));
550 }
551 else if (brush) {
553 block, curvemap_brush_tools_func, tools_cb, ICON_NONE, 0, 0, dx, dx, TIP_("Tools"));
554 }
555 else if (neg_slope) {
557 block, curvemap_tools_negslope_func, tools_cb, ICON_NONE, 0, 0, dx, dx, TIP_("Tools"));
558 }
559 else {
561 block, curvemap_tools_posslope_func, tools_cb, ICON_NONE, 0, 0, dx, dx, TIP_("Tools"));
562 }
563 /* Pass ownership of `tools_cb` to the button. */
565 bt,
566 [](bContext *, void *, void *) {},
567 tools_cb,
568 nullptr,
571
572 block_funcN_set(block,
573 rna_update_cb,
574 MEM_new<RNAUpdateCb>(__func__, cb),
575 nullptr,
578
579 /* Curve itself. */
580 const int size = max_ii(layout->width(), UI_UNIT_X);
581 row = &layout->row(false);
582 ButtonCurveMapping *curve_but = static_cast<ButtonCurveMapping *>(
583 uiDefBut(block,
585 IFACE_("Edit Curve Map"),
586 0,
587 0,
588 size,
589 8.0f * UI_UNIT_X,
590 cumap,
591 0.0f,
592 1.0f,
593 ""));
594 curve_but->gradient_type = bg;
595 if (!layout->active()) {
597 }
598
599 /* Sliders for selected curve point. */
600 Vector<CurveMapPoint *> selected_points;
601 bool point_last_or_first = false;
602 for (int i = 0; i < cm->totpoint; i++) {
603 const bool selected = cm->curve[i].flag & CUMA_SELECT;
604 if (selected) {
605 selected_points.append(&cm->curve[i]);
606 }
607 if (ELEM(i, 0, cm->totpoint - 1) && selected) {
608 point_last_or_first = true;
609 }
610 }
611
612 if (!selected_points.is_empty()) {
613 CurveMap *active_cm = cumap->cm + cumap->cur;
614
615 rctf bounds;
616 if (cumap->flag & CUMA_DO_CLIP) {
617 bounds = cumap->clipr;
618 }
619 else {
620 bounds.xmin = bounds.ymin = -1000.0;
621 bounds.xmax = bounds.ymax = 1000.0;
622 }
623
625
626 layout->row(true);
627
628 /* Curve handle buttons. */
629 bt = uiDefIconBut(block,
631 ICON_HANDLE_AUTO,
632 0,
633 UI_UNIT_Y,
634 UI_UNIT_X,
635 UI_UNIT_Y,
636 nullptr,
637 0.0,
638 0.0,
639 TIP_("Auto handle"));
640 button_func_set(bt, [cumap, cb](bContext &C) {
641 CurveMap *cuma = cumap->cm + cumap->cur;
643 BKE_curvemapping_changed(cumap, false);
644 rna_update_cb(C, cb);
645 });
646
647 for (const CurveMapPoint *cmp : selected_points) {
648 const bool auto_anim_vec = ((cmp->flag & CUMA_HANDLE_AUTO_ANIM) == false) &&
649 ((cmp->flag & CUMA_HANDLE_VECTOR) == false);
650 if (auto_anim_vec) {
651 bt->flag |= UI_SELECT_DRAW;
652 }
653 }
654
655 bt = uiDefIconBut(block,
657 ICON_HANDLE_VECTOR,
658 0,
659 UI_UNIT_Y,
660 UI_UNIT_X,
661 UI_UNIT_Y,
662 nullptr,
663 0.0,
664 0.0,
665 TIP_("Vector handle"));
666 button_func_set(bt, [cumap, cb](bContext &C) {
667 CurveMap *cuma = cumap->cm + cumap->cur;
669 BKE_curvemapping_changed(cumap, false);
670 rna_update_cb(C, cb);
671 });
672
673 for (const CurveMapPoint *cmp : selected_points) {
674 const bool vec = (cmp->flag & CUMA_HANDLE_VECTOR);
675 if (vec) {
676 bt->flag |= UI_SELECT_DRAW;
677 }
678 }
679
680 bt = uiDefIconBut(block,
682 ICON_HANDLE_AUTOCLAMPED,
683 0,
684 UI_UNIT_Y,
685 UI_UNIT_X,
686 UI_UNIT_Y,
687 nullptr,
688 0.0,
689 0.0,
690 TIP_("Auto clamped"));
691 button_func_set(bt, [cumap, cb](bContext &C) {
692 CurveMap *cuma = cumap->cm + cumap->cur;
694 BKE_curvemapping_changed(cumap, false);
695 rna_update_cb(C, cb);
696 });
697
698 for (const CurveMapPoint *cmp : selected_points) {
699 const bool auto_anim = (cmp->flag & CUMA_HANDLE_AUTO_ANIM);
700 if (auto_anim) {
701 bt->flag |= UI_SELECT_DRAW;
702 }
703 }
704
705 /* Curve handle position */
706 auto curve_runtime = std::make_shared<CurveRuntimeProperties>();
707 curve_runtime->last_pt = BKE_curvemap_active_get(active_cm);
708 curve_runtime->last_pos.x = curve_runtime->last_pt->x;
709 curve_runtime->last_pos.y = curve_runtime->last_pt->y;
710
711 /* While the slider controls the active element, all selected points move together.
712 * Contract the slider range so the outermost selected points stay within the clip region. */
713 rctf slider_bounds = bounds;
714 if (selected_points.size() > 1) {
715 rctf selection_bounds;
716 BLI_rctf_init_minmax(&selection_bounds);
717
718 /* The slider only shows the active point's position, but moves all selected points by the
719 * same delta. Clamp the range so points at the edges of the selection can't be moved outside
720 * the clip region. */
721 for (const CurveMapPoint *cmp : selected_points) {
722 const float loc[2] = {cmp->x, cmp->y};
723 BLI_rctf_do_minmax_v(&selection_bounds, loc);
724 }
725
726 slider_bounds.xmin += curve_runtime->last_pt->x - selection_bounds.xmin;
727 slider_bounds.xmax += curve_runtime->last_pt->x - selection_bounds.xmax;
728 slider_bounds.ymin += curve_runtime->last_pt->y - selection_bounds.ymin;
729 slider_bounds.ymax += curve_runtime->last_pt->y - selection_bounds.ymax;
730 }
731
732 const char *const axis_labels[2] = {"X:", "Y:"};
733 float *const axis_ptrs[2] = {&curve_runtime->last_pt->x, &curve_runtime->last_pt->y};
734 const float axis_min[2] = {slider_bounds.xmin, slider_bounds.ymin};
735 const float axis_max[2] = {slider_bounds.xmax, slider_bounds.ymax};
736 for (int axis = 0; axis < 2; axis++) {
737 bt = uiDefButV(block,
739 axis_labels[axis],
740 0,
741 (2 - axis) * UI_UNIT_Y,
742 UI_UNIT_X * 10,
743 UI_UNIT_Y,
744 axis_ptrs[axis],
745 axis_min[axis],
746 axis_max[axis],
747 "");
750 if (selected_points.size() == 1) {
751 /* Simplified logic */
752 button_func_set(bt, [cumap, cb](bContext &C) {
753 BKE_curvemapping_changed(cumap, true);
754 rna_update_cb(C, cb);
755 });
756 }
757 else {
758 button_func_set(bt, [cumap, cb, curve_runtime, axis](bContext &C) {
759 CurveMap *cuma = cumap->cm + cumap->cur;
760 float *last_pt_co = &curve_runtime->last_pt->x;
761 const float delta = last_pt_co[axis] - curve_runtime->last_pos[axis];
762 /* Logically `-= delta`, better restore the original value. */
763 last_pt_co[axis] = curve_runtime->last_pos[axis];
764 float2 offset(0.0f);
765 offset[axis] = delta;
767 BKE_curvemapping_changed(cumap, true);
768 rna_update_cb(C, cb);
769
770 /* Update the active point if the pointer changed. */
771 curve_runtime->last_pt = BKE_curvemap_active_get(cuma);
772 last_pt_co = &curve_runtime->last_pt->x;
773 curve_runtime->last_pos[axis] = last_pt_co[axis];
774 });
775 }
776 }
777
778 /* Curve handle delete point */
779 bt = uiDefIconBut(
780 block, ButtonType::But, ICON_X, 0, 0, dx, dx, nullptr, 0.0, 0.0, TIP_("Delete points"));
781 button_func_set(bt, [cumap, cb](bContext &C) {
782 BKE_curvemap_remove(cumap->cm + cumap->cur, SELECT);
783 BKE_curvemapping_changed(cumap, false);
784 rna_update_cb(C, cb);
785 });
786 if (point_last_or_first) {
788 }
789 }
790
791 /* black/white levels */
792 if (levels) {
793 Layout &split = layout->split(0.0f, false);
794 split.column(false).prop(ptr, "black_level", ITEM_R_EXPAND, std::nullopt, ICON_NONE);
795 split.column(false).prop(ptr, "white_level", ITEM_R_EXPAND, std::nullopt, ICON_NONE);
796
797 layout->row(false);
798 bt = uiDefBut(block,
800 IFACE_("Reset"),
801 0,
802 0,
803 UI_UNIT_X * 10,
804 UI_UNIT_Y,
805 nullptr,
806 0.0f,
807 0.0f,
808 TIP_("Reset curves and black/white point"));
809 button_func_set(bt, [cumap, cb](bContext &C) {
810 cumap->preset = CURVE_PRESET_LINE;
811 for (int a = 0; a < CM_TOT; a++) {
813 cumap->cm + a, &cumap->clipr, cumap->preset, CurveMapSlopeType::Positive);
814 }
815
816 cumap->black[0] = cumap->black[1] = cumap->black[2] = 0.0f;
817 cumap->white[0] = cumap->white[1] = cumap->white[2] = 1.0f;
818 BKE_curvemapping_set_black_white(cumap, nullptr, nullptr);
819
820 BKE_curvemapping_changed(cumap, false);
821 rna_update_cb(C, cb);
822 });
823 }
824
825 if (presets) {
826 row = &layout->row(true);
828 add_preset_button(block,
829 dx,
830 ICON_SMOOTHCURVE,
831 TIP_("Smooth preset"),
832 cumap,
833 neg_slope,
835 cb);
836 add_preset_button(block,
837 dx,
838 ICON_SPHERECURVE,
839 TIP_("Round preset"),
840 cumap,
841 neg_slope,
843 cb);
845 block, dx, ICON_ROOTCURVE, TIP_("Root preset"), cumap, neg_slope, CURVE_PRESET_ROOT, cb);
846 add_preset_button(block,
847 dx,
848 ICON_SHARPCURVE,
849 TIP_("Sharp preset"),
850 cumap,
851 neg_slope,
853 cb);
855 block, dx, ICON_LINCURVE, TIP_("Linear preset"), cumap, neg_slope, CURVE_PRESET_LINE, cb);
857 block, dx, ICON_NOCURVE, TIP_("Constant preset"), cumap, neg_slope, CURVE_PRESET_MAX, cb);
858 }
859
860 block_funcN_set(block, nullptr, nullptr, nullptr);
861}
862
864 PointerRNA *ptr,
865 const StringRefNull propname,
866 int type,
867 bool levels,
868 bool brush,
869 bool neg_slope,
870 bool tone,
871 bool presets)
872{
873 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
874 Block *block = layout->block();
875
876 if (!prop) {
878 "curve property not found: %s.%s", RNA_struct_identifier(ptr->type), propname.c_str());
879 return;
880 }
881
882 if (RNA_property_type(prop) != PROP_POINTER) {
884 "curve is not a pointer: %s.%s", RNA_struct_identifier(ptr->type), propname.c_str());
885 return;
886 }
887
888 PointerRNA cptr = RNA_property_pointer_get(ptr, prop);
889 if (!cptr || !RNA_struct_is_a(cptr.type, RNA_CurveMapping)) {
890 return;
891 }
892
893 ID *id = cptr.owner_id;
895
897 layout, &cptr, type, levels, brush, neg_slope, tone, presets, RNAUpdateCb{*ptr, prop});
898
899 block_lock_clear(block);
900}
901
902} // namespace blender::ui
#define SELECT
Definition BKE_mask.hh:19
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_COLOR
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define CM_TOT
#define RNA_warning(format,...)
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
#define ELEM(...)
constexpr const char * c_str() const
void append(const T &value)
float3x3 scale(float3x3 mat, float2 scale)
#define CURVE_ZOOM_MAX
#define ERROR_LIBDATA_MESSAGE
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
Button * uiDefIconTextBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, int icon, StringRef str, int x, int y, short width, short height, void *poin, std::optional< StringRef > tip)
void block_lock_set(Block *block, bool val, const char *lockstr)
void block_direction_set(Block *block, char direction)
void button_func_set(Button *but, std::function< void(bContext &)> func)
void block_bounds_set_normal(Block *block, int addval)
Definition interface.cc:651
void block_lock_clear(Block *block)
void block_align_begin(Block *block)
void button_number_step_size_set(Button *but, float step_size)
void block_flag_enable(Block *block, int flag)
static void add_preset_button(Block *block, const float dx, const int icon, std::optional< StringRef > tip, CurveMapping *cumap, const bool neg_slope, const eCurveMappingPreset preset, const RNAUpdateCb &cb)
void block_bounds_set_text(Block *block, int addval)
Definition interface.cc:661
void button_number_precision_set(Button *but, float precision)
void button_disable(Button *but, const char *disabled_hint)
static Block * curvemap_tools_func(bContext *C, ARegion *region, RNAUpdateCb &cb, bool show_extend, CurveMapSlopeType reset_mode)
void button_flag_enable(Button *but, int64_t flag)
static Block * curvemap_brush_tools_negslope_func(bContext *C, ARegion *region, void *cb_v)
Block * block_begin(const bContext *C, ARegion *region, std::string name, EmbossType emboss)
static void curvemap_buttons_redraw(bContext &C)
Button * uiDefBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, StringRef str, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
static Block * curvemap_tools_negslope_func(bContext *C, ARegion *region, void *cb_v)
void * but_func_argN_copy(const void *argN)
void block_theme_style_set(Block *block, char theme_style)
static bool curvemap_can_zoom_in(CurveMapping *cumap)
static void curvemap_zoom(CurveMapping &cumap, const float scale)
void button_funcN_set(Button *but, ButtonHandleNFunc funcN, void *argN, void *arg2, ButtonArgNFree func_argN_free_fn=MEM_delete_void, ButtonArgNCopy func_argN_copy_fn=MEM_dupalloc_void)
static void curvemap_buttons_layout(Layout *layout, PointerRNA *ptr, char labeltype, bool levels, bool brush, bool neg_slope, bool tone, bool presets, const RNAUpdateCb &cb)
void block_emboss_set(Block *block, EmbossType emboss)
Button * uiDefButBit(Block *block, ButtonType type, int bit, StringRef str, int x, int y, short width, short height, T *poin, float min, float max, std::optional< StringRef > tip)
void but_func_argN_free(void *argN)
static void curvemap_buttons_zoom_out(bContext *C, CurveMapping *cumap)
Button * uiDefIconBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, int icon, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
static Block * curvemap_clipping_func(bContext *C, ARegion *region, void *cumap_v)
static Block * curvemap_tools_posslope_func(bContext *C, ARegion *region, void *cb_v)
Button * uiDefButV(Block *block, ButtonType type, StringRef str, int x, int y, short width, short height, T *poin, float min, float max, std::optional< StringRef > tip)
void template_curve_mapping(Layout *layout, PointerRNA *ptr, StringRefNull propname, int type, bool levels, bool brush, bool neg_slope, bool tone, bool presets)
static void curvemap_buttons_zoom_in(bContext *C, CurveMapping *cumap)
static Block * curvemap_brush_tools_func(bContext *C, ARegion *region, void *cb_v)
Button * uiDefIconBlockBut(Block *block, BlockCreateFunc func, void *arg, int icon, int x, int y, short width, short height, std::optional< StringRef > tip)
static bool curvemap_can_zoom_out(CurveMapping *cumap)
void block_funcN_set(Block *block, ButtonHandleNFunc funcN, void *argN, void *arg2, ButtonArgNFree func_argN_free_fn=MEM_delete_void, ButtonArgNCopy func_argN_copy_fn=MEM_dupalloc_void)
UserDef U
Definition blender.cc:58
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
void BKE_curvemap_remove(CurveMap *cuma, short flag)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
@ CURVE_TONE_FILMLIKE
void BLI_rctf_do_minmax_v(struct rctf *rect, const float xy[2])
Definition rct.cc:524
@ CURVE_PRESET_SMOOTH
MINLINE int max_ii(int a, int b)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
PropertyType RNA_property_type(PropertyRNA *prop)
VecBase< float, 2 > float2
@ CUMA_HANDLE_AUTO_ANIM
@ PROP_POINTER
Definition RNA_types.hh:215
void BKE_curvemap_reset(CurveMap *cuma, const rctf *clipr, int preset, CurveMapSlopeType slope)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
void BKE_curvemapping_changed(CurveMapping *cumap, bool rem_doubles)
void BKE_curvemapping_reset_view(CurveMapping *cumap)
void BLI_rctf_init_minmax(struct rctf *rect)
Definition rct.cc:494
CurveMapPoint * BKE_curvemap_active_get(CurveMap *cuma)
void BKE_curvemapping_set_black_white(CurveMapping *cumap, const float black[3], const float white[3])
void BKE_curvemap_translate_selection(CurveMap *cuma, const blender::float2 &offset)
const char * RNA_struct_identifier(const StructRNA *type)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
void BKE_curvemap_handle_set(CurveMap *cuma, int type)
ARegion * CTX_wm_region(const bContext *C)
@ CUMA_EXTEND_EXTRAPOLATE
eCurveMapPoint_Flag flag
CurveMapPoint * curve
eCurveMappingTone tone
eCurveMappingFlags flag
eCurveMappingPreset preset
StructRNA * type
Definition RNA_types.hh:63
void alignment_set(LayoutAlign alignment)
Layout & split(float percentage, bool align)
Layout & row(bool align)