41#define MIN_MAJOR_LINE_DISTANCE (U.v2d_min_gridsize * UI_SCALE_FAC)
52 const int divisors[3] = {2, 3, 5};
54 bool divides_no_remainder[num_divisors];
56 for (
int i = 0; i < num_divisors; i++) {
57 const int divisor = divisors[i];
63 if (has_no_remainder &&
result == 2) {
66 divides_no_remainder[i] = has_no_remainder;
70 for (
int i = 0; i < num_divisors; i++) {
71 if (divides_no_remainder[i]) {
89 const float pixel_width,
90 const float view_width,
91 const float min_distance)
93 if (
IS_EQF(view_width, 0.0f)) {
96 const float pixels_per_view_unit = pixel_width / view_width;
98 if (pixels_per_view_unit *
distance > min_distance) {
103 if (pixels_per_view_unit *
result < min_distance) {
114 while (pixels_per_view_unit *
distance < min_distance &&
distance < (1 << 30)) {
124 const float pixel_width,
125 const float view_width,
126 const float min_distance)
157 float *r_start_value,
160 if (view_bounds.x >= view_bounds.y) {
167 *r_start_value =
ceilf(view_bounds.x / line_distance) * line_distance;
169 if (view_bounds.x <= *r_start_value && view_bounds.y >= *r_start_value) {
170 *r_steps = std::max(0.0f,
floorf((view_bounds.y - *r_start_value) / line_distance)) + 1;
183 const rcti *rect_mask,
185 const char direction)
188 uint steps, steps_max;
190 if (direction ==
'v') {
206 if (steps >= steps_max) [[unlikely]] {
215 if (
U.pixelsize > 1.0f) {
231 if (direction ==
'v') {
232 for (
uint i = 0; i < steps; i++) {
233 const float xpos = start_value + i * line_distance;
239 for (
uint i = 0; i < steps; i++) {
240 const float ypos = start_value + i * line_distance;
251 const float line_distance,
262 const float major_distance,
263 const bool display_minor_lines,
264 const char direction)
266 if (display_minor_lines) {
267 uchar minor_color[3];
270 if (major_distance > 1) {
281 const float line_distance = major_distance / divisor;
291 uchar major_color[3];
304 void (*)(
const Scene *scene,
float value,
float step,
char *r_str,
uint str_maxncpy);
328 if (steps >= steps_max) [[unlikely]] {
343 for (
uint i = 0; i < steps; i++) {
344 const float xpos_view = start_value + i *
distance;
347 const float text_width =
BLF_width(font_id, text, strlen(text));
348 BLF_draw_default(xpos_region - std::trunc(text_width / 2.0f), ypos, 0.0f, text,
sizeof(text));
358 float display_offset,
375 if (steps >= steps_max) [[unlikely]] {
389 float shadow_color[4];
394 const float x_offset = 8.0f;
396 const float ymin = rect->
ymin;
397 const float ymax = rect->
ymax;
398 const float y_offset = (
BLF_height(font_id,
"0", 1) / 2.0f) -
U.pixelsize;
400 for (
uint i = 0; i < steps; i++) {
401 const float ypos_view = start + i *
distance;
406 if (ypos_region - y_offset >= ymin && ypos_region + y_offset <= ymax) {
423 const Scene *scene,
const float frame,
const float step,
char *r_str,
const uint str_maxncpy)
425 int brevity_level = -1;
433 frame /
float(scene->frames_per_second()),
434 scene->frames_per_second(),
446 const uint str_maxncpy)
451 else if (
step >= 0.5f) {
454 else if (
step >= 0.01f) {
474 to_string(scene,
abs(data_bounds.x), 0, text,
sizeof(text));
475 const float left_text_width =
BLF_width(font_id, text, strlen(text));
476 to_string(scene,
abs(data_bounds.y), 0, text,
sizeof(text));
477 const float right_text_width =
BLF_width(font_id, text, strlen(text));
478 const float max_text_width =
max_ff(left_text_width, right_text_width);
480 constexpr int text_padding = 6;
481 return max_text_width + text_padding;
490 const bool display_seconds)
494 if (display_seconds) {
532 const bool display_seconds,
533 const bool show_fractions,
534 bool draw_minor_lines,
538 float major_line_distance;
540 if (show_fractions && !display_seconds) {
547 draw_minor_lines = draw_minor_lines && (major_line_distance > 1);
556 const bool display_seconds,
557 const bool show_fractions,
558 const bool draw_minor_lines)
566 float major_line_distance;
567 if (show_fractions) {
589 const ARegion *region,
const View2D *v2d,
const rcti *rect,
const int colorid,
const int base)
600 const bool display_seconds,
601 const bool show_fractions,
609 if (show_fractions && !display_seconds) {
618 if (display_seconds) {
float distance(float, float) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
const char * to_string(ShaderStage stage)
void font_theme_color_set(int fontid, int colorid)
void get_color_4fv(int colorid, float col[4])
void get_color_shade_3ubv(int colorid, int offset, unsigned char col[3])
void get_color_3ubv(int colorid, unsigned char col[3])
static void draw_horizontal_scale_indicators(const ARegion *region, const View2D *v2d, const float distance, const rcti *rect, PositionToString to_string, const Scene *scene, const int colorid)
void view2d_view_ortho(const View2D *v2d)
void view2d_draw_scale_x(const ARegion *region, const View2D *v2d, const rcti *rect, const Scene *scene, bool display_seconds, bool show_fractions, int colorid, int base)
static void draw_parallel_lines(const float line_distance, const rctf *rect, const rcti *rect_mask, const uchar color[3], const char direction)
static float calculate_grid_step_fractions(const int base, const float pixel_width, const float view_width, const float min_distance)
static void get_parallel_lines_draw_steps(const float line_distance, const float2 view_bounds, float *r_start_value, uint *r_steps)
static void view2d_draw_lines_internal(const View2D *v2d, const float line_distance, const uchar color[3], char direction)
static void frame_to_time_string(const Scene *scene, const float frame, const float step, char *r_str, const uint str_maxncpy)
static int calculate_grid_step(const int base, const float pixel_width, const float view_width, const float min_distance)
float view2d_grid_resolution_y__values(const View2D *v2d, int base)
void view2d_draw_lines_x(const View2D *v2d, const Scene *scene, bool display_seconds, bool show_fractions, bool draw_minor_lines, int base)
static void frame_to_string(const Scene *, const float frame, const float step, char *r_str, const uint str_maxncpy)
void(*)(const Scene *scene, float value, float step, char *r_str, uint str_maxncpy) PositionToString
float view2d_view_to_region_y(const View2D *v2d, float y)
static void view2d_draw_lines(const View2D *v2d, const float major_distance, const bool display_minor_lines, const char direction)
constexpr int subframe_range
void view2d_draw_lines_y(const View2D *v2d, bool show_fractions, int base)
float view2d_scale_get_y(const View2D *v2d)
float view2d_grid_resolution_x(const View2D *v2d, const Scene *scene, bool display_seconds)
float view2d_region_to_view_x(const View2D *v2d, float x)
float view2d_region_to_view_y(const View2D *v2d, float y)
static float get_min_line_distance_x(const View2D *v2d, const Scene *scene, const bool display_seconds)
float view2d_scale_get_x(const View2D *v2d)
static void draw_vertical_scale_indicators(const ARegion *region, const View2D *v2d, float distance, float display_offset, const rcti *rect, PositionToString to_string, const Scene *scene, int colorid)
void view2d_draw_scale_y(const ARegion *region, const View2D *v2d, const rcti *rect, int colorid, int base)
static float get_label_width(PositionToString to_string, const Scene *scene, const float2 data_bounds)
void view2d_draw_lines_x_frames(const View2D *v2d, const Scene *scene, bool display_seconds, bool show_fractions, bool draw_minor_lines)
static int get_divisor(const int distance)
float view2d_view_to_region_x(const View2D *v2d, float x)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void wmOrtho2_region_pixelspace(const ARegion *region)
void BLF_shadow_offset(int fontid, int x, int y)
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
MINLINE int round_fl_to_int(float a)
GPUVertFormat * immVertexFormat()
void BLF_batch_draw_begin()
void immBegin(GPUPrimType, uint vertex_len)
MINLINE int max_ii(int a, int b)
void BLF_disable(int fontid, FontFlags flag)
void immUniformColor3ubv(const unsigned char rgb[3])
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
void immVertex2f(uint attr_id, float x, float y)
void GPU_viewport_size_get_f(float coords[4])
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void BLF_batch_draw_end()
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
size_t BLI_timecode_string_from_time(char *str, size_t maxncpy, int brevity_level, float time_seconds, double fps, short timecode_style) ATTR_NONNULL()
void GPU_matrix_pop_projection()
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
MINLINE float max_ff(float a, float b)
void immUniform2fv(const char *name, const float data[2])
void GPU_matrix_push_projection()
void BLF_enable(int fontid, FontFlags flag)
MINLINE int round_db_to_int(double a)
#define MIN_MAJOR_LINE_DISTANCE