55#define SLIDE_PIXEL_DISTANCE (300.0f * UI_SCALE_FAC)
56#define OVERSHOOT_RANGE_DELTA 0.2f
57#define SLIDER_UNIT_STRING_SIZE 64
113 const bool facing_right,
123 const float triangle_side_length = facing_right ? 6 *
U.pixelsize : -6 *
U.pixelsize;
124 const float triangle_offset = facing_right ? 2 *
U.pixelsize : -2 *
U.pixelsize;
127 immVertex2f(shdr_pos_2d, x + triangle_offset + triangle_side_length, y);
128 immVertex2f(shdr_pos_2d, x + triangle_offset, y + triangle_side_length / 2);
129 immVertex2f(shdr_pos_2d, x + triangle_offset, y - triangle_side_length / 2);
138 const float end_factor,
139 const float line_start[2],
140 const float base_tick_height,
141 const float line_width,
142 const uint8_t color_overshoot[4],
146 const int tick_increment = 10;
149 int tick_percentage =
ceil((start_factor * 100) / tick_increment) * tick_increment;
151 while (tick_percentage <=
int(end_factor * 100)) {
155 if (tick_percentage % 100 == 0) {
156 tick_height = base_tick_height;
158 else if (tick_percentage % 50 == 0) {
159 tick_height = base_tick_height * 0.8;
162 tick_height = base_tick_height * 0.5;
165 const float x = line_start[0] +
168 tick_rect.
xmin = x - (line_width / 2);
169 tick_rect.xmax = x + (line_width / 2);
170 tick_rect.ymin = line_start[1] - (tick_height / 2);
171 tick_rect.ymax = line_start[1] + (tick_height / 2);
173 if (tick_percentage < 0 || tick_percentage > 100) {
179 tick_percentage += tick_increment;
185 const bool overshoot,
186 const uint8_t color_overshoot[4],
191 const float line_zero_percent = main_line_rect->
xmin -
195 const float clamped_line_zero_percent =
clamp_f(
196 line_zero_percent, main_line_rect->
xmin, main_line_rect->
xmax);
197 const float clamped_line_hundred_percent =
clamp_f(
200 rctf left_overshoot_line_rect{};
201 left_overshoot_line_rect.
xmin = main_line_rect->
xmin;
202 left_overshoot_line_rect.xmax = clamped_line_zero_percent;
203 left_overshoot_line_rect.ymin = main_line_rect->
ymin;
204 left_overshoot_line_rect.ymax = main_line_rect->
ymax;
206 rctf right_overshoot_line_rect{};
207 right_overshoot_line_rect.
xmin = clamped_line_hundred_percent;
208 right_overshoot_line_rect.xmax = main_line_rect->
xmax;
209 right_overshoot_line_rect.ymin = main_line_rect->
ymin;
210 right_overshoot_line_rect.ymax = main_line_rect->
ymax;
215 rctf non_overshoot_line_rect{};
216 non_overshoot_line_rect.
xmin = clamped_line_zero_percent;
217 non_overshoot_line_rect.xmax = clamped_line_hundred_percent;
218 non_overshoot_line_rect.ymin = main_line_rect->
ymin;
219 non_overshoot_line_rect.ymax = main_line_rect->
ymax;
228 const rctf *main_line_rect,
230 const short region_y_size,
231 const float base_tick_height,
232 const std::string &property_label)
234 float percent_string_pixel_size[2];
235 const char *percentage_string_placeholder =
"000%%";
237 percentage_string_placeholder,
238 sizeof(percentage_string_placeholder),
239 &percent_string_pixel_size[0],
240 &percent_string_pixel_size[1]);
242 float property_name_pixel_size[2];
244 property_label.c_str(),
245 property_label.size(),
246 &property_name_pixel_size[0],
247 &property_name_pixel_size[1]);
248 const float pad[2] = {(region_y_size - base_tick_height) / 2 + 12.0f *
U.pixelsize,
250 rctf backdrop_rect{};
251 backdrop_rect.
xmin = main_line_rect->
xmin - property_name_pixel_size[0] -
pad[0];
252 backdrop_rect.xmax = main_line_rect->
xmax + percent_string_pixel_size[0] +
pad[0];
253 backdrop_rect.ymin =
pad[1];
254 backdrop_rect.ymax = region_y_size -
pad[1];
283 color_overshoot[0] = color_overshoot[0] * 0.8;
284 color_overshoot[1] = color_overshoot[1] * 0.8;
285 color_overshoot[2] = color_overshoot[2] * 0.8;
295 const float line_width = 1.5 *
U.pixelsize;
296 const float base_tick_height = 12.0 *
U.pixelsize;
297 const float line_y = region->winy / 2;
299 rctf main_line_rect{};
302 main_line_rect.ymin = line_y - line_width / 2;
303 main_line_rect.ymax = line_y + line_width / 2;
305 float line_start_factor = 0;
311 handle_pos_x = region->winx / 2;
330 const float line_start_position[2] = {main_line_rect.xmin, line_y};
332 line_start_factor + factor_range,
352 handle_rect.
xmin = handle_pos_x - (line_width);
353 handle_rect.xmax = handle_pos_x + (line_width);
354 handle_rect.ymin = line_y - (base_tick_height / 2);
355 handle_rect.ymax = line_y + (base_tick_height / 2);
359 char factor_string[256];
370 float factor_string_pixel_size[2];
373 sizeof(factor_string),
374 &factor_string_pixel_size[0],
375 &factor_string_pixel_size[1]);
377 const float text_padding = 12.0 *
U.pixelsize;
378 const float factor_string_pos_x = main_line_rect.xmax + text_padding;
380 fontid, factor_string_pos_x, (region->winy / 2) - factor_string_pixel_size[1] / 2, 0.0f);
381 BLF_draw(fontid, factor_string,
sizeof(factor_string));
384 float property_name_pixel_size[2];
388 &property_name_pixel_size[0],
389 &property_name_pixel_size[1]);
391 main_line_rect.xmin - text_padding - property_name_pixel_size[0],
392 (region->winy / 2) - property_name_pixel_size[1] / 2,
403 const float factor_delta = (
event->xy[0] - slider->
last_cursor[0]) /
429 tSlider *slider = MEM_new<tSlider>(__func__);
474 bool event_handled =
true;
476 switch (event->
type) {
496 event_handled =
false;
502 return event_handled;
507 const size_t size_of_status_string)
510 char overshoot_str[50];
511 char precision_str[50];
512 char increments_str[50];
527 STRNCPY(precision_str,
IFACE_(
"[Shift] - Precision active"));
530 STRNCPY(precision_str,
IFACE_(
"Shift - Hold for precision"));
535 STRNCPY(increments_str,
IFACE_(
" | [Ctrl] - Increments active"));
538 STRNCPY(increments_str,
IFACE_(
" | Ctrl - Hold for 10% increments"));
542 increments_str[0] =
'\0';
546 size_of_status_string,
597 float factor_bound_lower,
598 float factor_bound_upper)
629 const float *mval_src = (
float *)arg_info;
630 const float mval_dst[2] = {
642 float viewport_size[4];
659#define MAX_METADATA_STR 1024
686 if (
STREQ(field,
"BlenderMultiChannel")) {
691 if (
STREQ(field,
"type")) {
711 SNPRINTF(temp_str,
"%s: %s", field, value);
722 const float margin = height / 8;
723 const float vertical_offset = (height + margin);
727 const float xmin = (rect->
xmin + margin);
728 const float xmax = (rect->
xmax - margin);
729 const float ymin = (rect->
ymin + margin) - descender;
730 const float ymax = (rect->
ymax - margin) - descender;
733 for (
int i = 0; i < 4; i++) {
736 bool do_newline =
false;
739 BLF_position(fontid, xmin, ymax - vertical_offset, 0.0f);
740 BLF_draw(fontid, temp_str,
sizeof(temp_str));
746 int line_width =
BLF_width(fontid, temp_str,
sizeof(temp_str));
747 BLF_position(fontid, xmax - line_width, ymax - vertical_offset, 0.0f);
748 BLF_draw(fontid, temp_str,
sizeof(temp_str));
753 ofs_y += vertical_offset;
756 else if (
ELEM(i, 1, 2)) {
759 BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f);
760 BLF_draw(fontid, temp_str,
sizeof(temp_str));
761 ofs_y += vertical_offset;
770 BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f);
771 BLF_draw(fontid, temp_str,
sizeof(temp_str), &info);
774 ofs_y += vertical_offset * info.
lines;
780 int line_width =
BLF_width(fontid, temp_str,
sizeof(temp_str));
781 BLF_position(fontid, xmax - line_width, ymax - vertical_offset - ofs_y, 0.0f);
782 BLF_draw(fontid, temp_str,
sizeof(temp_str));
783 ofs_y += vertical_offset;
798 for (
int i = 5; i < 10; i++) {
802 BLF_draw(fontid, temp_str,
sizeof(temp_str));
826 const float margin = (height / 8);
834 for (
int i = 2; i < 5; i++) {
857 for (
int i = 5; i < 10; i++) {
870 return (height + margin) *
count;
877 int x,
int y,
ImBuf *ibuf,
const rctf *frame,
float zoomx,
float zoomy)
952#undef MAX_METADATA_STR
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
bool BKE_stamp_is_known_field(const char *field_name)
void BLF_size(int fontid, float size)
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
void BLF_color3ubv(int fontid, const unsigned char rgb[3])
void BLF_clipping(int fontid, int xmin, int ymin, int xmax, int ymax)
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
void BLF_boundbox(int fontid, const char *str, size_t str_len, rcti *r_box, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
void BLF_disable(int fontid, int option)
void BLF_rotation(int fontid, float angle)
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
void BLF_enable(int fontid, int option)
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
void BLF_wordwrap(int fontid, int wrap_width)
void BLF_position(int fontid, float x, float y, float z)
#define LISTBASE_FOREACH(type, var, list)
MINLINE float max_ff(float a, float b)
MINLINE float clamp_f(float value, float min, float max)
MINLINE float min_ff(float a, float b)
MINLINE void copy_v2fl_v2i(float r[2], const int a[2])
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
#define STRNCPY(dst, src)
#define SNPRINTF(dst, format,...)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define SNPRINTF_RLEN(dst, format,...)
void ED_area_status_text(ScrArea *area, const char *str)
void ED_workspace_status_text(bContext *C, const char *str)
void ED_region_tag_redraw(ARegion *region)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
#define REGION_DRAW_POST_PIXEL
void GPU_matrix_scale_2f(float x, float y)
void GPU_matrix_translate_2f(float x, float y)
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_blend(eGPUBlend blend)
void GPU_line_width(float width)
void GPU_viewport_size_get_f(float coords[4])
void GPU_polygon_smooth(bool enable)
Contains defines and structs used throughout the imbuf module.
Read Guarded memory(de)allocation.
void UI_draw_roundbox_3ub_alpha(const rctf *rect, bool filled, float rad, const unsigned char col[3], unsigned char alpha)
const uiStyle * UI_style_get_dpi()
const uiStyle * UI_style_get()
void UI_FontThemeColor(int fontid, int colorid)
void UI_GetThemeColor4ubv(int colorid, unsigned char col[4])
int pad[32 - sizeof(int)]
void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy)
void ED_slider_allow_overshoot_set(tSlider *slider, const bool lower, const bool upper)
static void draw_overshoot_triangle(const uint8_t color[4], const bool facing_right, const float x, const float y)
void ED_slider_init(tSlider *slider, const wmEvent *event)
static void draw_ticks(const float start_factor, const float end_factor, const float line_start[2], const float base_tick_height, const float line_width, const uint8_t color_overshoot[4], const uint8_t color_line[4])
static void metadata_custom_draw_fields(const char *field, const char *value, void *ctx_v)
#define SLIDER_UNIT_STRING_SIZE
static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top)
static void metadata_custom_count_fields(const char *field, const char *, void *ctx_v)
void ED_slider_factor_set(tSlider *slider, const float factor)
SliderMode ED_slider_mode_get(const tSlider *slider)
void ED_slider_unit_set(tSlider *slider, const char *unit)
void ED_slider_mode_set(tSlider *slider, SliderMode mode)
void ED_slider_allow_increments_set(tSlider *slider, const bool value)
#define SLIDE_PIXEL_DISTANCE
void ED_slider_property_label_set(tSlider *slider, const char *property_label)
void ED_slider_destroy(bContext *C, tSlider *slider)
static const char * meta_data_list[]
BLI_INLINE bool metadata_is_custom_drawable(const char *field)
static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const bool is_top)
static void draw_main_line(const rctf *main_line_rect, const float factor, const bool overshoot, const uint8_t color_overshoot[4], const uint8_t color_line[4])
BLI_INLINE bool metadata_is_valid(ImBuf *ibuf, char *r_str, short index, int offset)
tSlider * ED_slider_create(bContext *C)
bool ED_slider_modal(tSlider *slider, const wmEvent *event)
#define OVERSHOOT_RANGE_DELTA
void ED_slider_factor_bounds_set(tSlider *slider, float factor_bound_lower, float factor_bound_upper)
bool ED_slider_allow_increments_get(const tSlider *slider)
static void slider_draw(const bContext *, ARegion *region, void *arg)
void ED_slider_status_string_get(const tSlider *slider, char *status_string, const size_t size_of_status_string)
void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *region, void *arg_info)
static void draw_backdrop(const int fontid, const rctf *main_line_rect, const uint8_t color_bg[4], const short region_y_size, const float base_tick_height, const std::string &property_label)
float ED_slider_factor_get(const tSlider *slider)
static void slider_update_factor(tSlider *slider, const wmEvent *event)
draw_view in_light_buf[] float
ccl_device_inline float3 ceil(const float3 a)
float wrap(float value, float max, float min)
struct ARegionType * type
char unit_string[SLIDER_UNIT_STRING_SIZE]
bool allow_overshoot_upper
bool allow_overshoot_lower
std::string property_label
struct wmEvent * eventstate