Blender V5.3
interface_template_scopes.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 "BLI_string_ref.hh"
10
11#include "DNA_color_types.h"
12
13#include "RNA_access.hh"
14#include "RNA_prototypes.hh"
15
16#include "UI_interface.hh"
18
19namespace blender::ui {
20
21/* -------------------------------------------------------------------- */
24
25void template_histogram(Layout *layout, PointerRNA *ptr, const StringRefNull propname)
26{
27 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
28
29 if (!prop || RNA_property_type(prop) != PROP_POINTER) {
30 return;
31 }
32
33 const PointerRNA cptr = RNA_property_pointer_get(ptr, prop);
34 if (!cptr || !RNA_struct_is_a(cptr.type, RNA_Histogram)) {
35 return;
36 }
37 Histogram *hist = static_cast<Histogram *>(cptr.data);
38
39 if (hist->height < UI_UNIT_Y) {
40 hist->height = UI_UNIT_Y;
41 }
42 else if (hist->height > UI_UNIT_Y * 20) {
43 hist->height = UI_UNIT_Y * 20;
44 }
45
46 Layout &col = layout->column(true);
47 Block *block = col.block();
48
49 uiDefBut(block, ButtonType::Histogram, "", 0, 0, UI_UNIT_X * 10, hist->height, hist, 0, 0, "");
50
51 /* Resize grip. */
52 uiDefIconButV(block,
54 ICON_GRIP,
55 0,
56 0,
57 UI_UNIT_X * 10,
58 short(UI_UNIT_Y * 0.3f),
59 &hist->height,
61 UI_UNIT_Y * 20.0f,
62 "");
63}
64
66
67/* -------------------------------------------------------------------- */
70
71void template_waveform(Layout *layout, PointerRNA *ptr, const StringRefNull propname)
72{
73 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
74
75 if (!prop || RNA_property_type(prop) != PROP_POINTER) {
76 return;
77 }
78
79 const PointerRNA cptr = RNA_property_pointer_get(ptr, prop);
80 if (!cptr || !RNA_struct_is_a(cptr.type, RNA_Scopes)) {
81 return;
82 }
83 Scopes *scopes = static_cast<Scopes *>(cptr.data);
84
85 Layout &col = layout->column(true);
86 Block *block = col.block();
87
88 if (scopes->wavefrm_height < UI_UNIT_Y) {
89 scopes->wavefrm_height = UI_UNIT_Y;
90 }
91 else if (scopes->wavefrm_height > UI_UNIT_Y * 20) {
92 scopes->wavefrm_height = UI_UNIT_Y * 20;
93 }
94
95 uiDefBut(block,
97 "",
98 0,
99 0,
100 UI_UNIT_X * 10,
101 scopes->wavefrm_height,
102 scopes,
103 0,
104 0,
105 "");
106
107 /* Resize grip. */
108 uiDefIconButV(block,
110 ICON_GRIP,
111 0,
112 0,
113 UI_UNIT_X * 10,
114 short(UI_UNIT_Y * 0.3f),
115 &scopes->wavefrm_height,
116 UI_UNIT_Y,
117 UI_UNIT_Y * 20.0f,
118 "");
119}
120
122
123/* -------------------------------------------------------------------- */
126
127void template_vectorscope(Layout *layout, PointerRNA *ptr, const StringRefNull propname)
128{
129 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
130
131 if (!prop || RNA_property_type(prop) != PROP_POINTER) {
132 return;
133 }
134
135 const PointerRNA cptr = RNA_property_pointer_get(ptr, prop);
136 if (!cptr || !RNA_struct_is_a(cptr.type, RNA_Scopes)) {
137 return;
138 }
139 Scopes *scopes = static_cast<Scopes *>(cptr.data);
140
141 if (scopes->vecscope_height < UI_UNIT_Y) {
142 scopes->vecscope_height = UI_UNIT_Y;
143 }
144 else if (scopes->vecscope_height > UI_UNIT_Y * 20) {
145 scopes->vecscope_height = UI_UNIT_Y * 20;
146 }
147
148 Layout &col = layout->column(true);
149 Block *block = col.block();
150
151 uiDefBut(block,
153 "",
154 0,
155 0,
156 UI_UNIT_X * 10,
157 scopes->vecscope_height,
158 scopes,
159 0,
160 0,
161 "");
162
163 /* Resize grip. */
164 uiDefIconButV(block,
166 ICON_GRIP,
167 0,
168 0,
169 UI_UNIT_X * 10,
170 short(UI_UNIT_Y * 0.3f),
171 &scopes->vecscope_height,
172 UI_UNIT_Y,
173 UI_UNIT_Y * 20.0f,
174 "");
175}
176
178
179} // namespace blender::ui
#define UI_UNIT_Y
#define UI_UNIT_X
constexpr const char * c_str() const
void template_histogram(Layout *layout, PointerRNA *ptr, StringRefNull propname)
Button * uiDefIconButV(Block *block, ButtonType type, int icon, int x, int y, short width, short height, T *poin, float min, float max, std::optional< StringRef > tip)
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)
void template_waveform(Layout *layout, PointerRNA *ptr, StringRefNull propname)
void template_vectorscope(Layout *layout, PointerRNA *ptr, StringRefNull propname)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
PropertyType RNA_property_type(PropertyRNA *prop)
@ PROP_POINTER
Definition RNA_types.hh:215
StructRNA * type
Definition RNA_types.hh:63
Layout & column(bool align)