38#define MIN_MAJOR_LINE_DISTANCE (U.v2d_min_gridsize * UI_SCALE_FAC)
49 const int divisors[3] = {2, 3, 5};
50 constexpr uint8_t num_divisors =
ARRAY_SIZE(divisors);
51 bool divides_no_remainder[num_divisors];
53 for (
int i = 0;
i < num_divisors;
i++) {
54 const int divisor = divisors[
i];
60 if (has_no_remainder &&
result == 2) {
63 divides_no_remainder[
i] = has_no_remainder;
67 for (
int i = 0;
i < num_divisors;
i++) {
68 if (divides_no_remainder[
i]) {
87 if (
IS_EQF(view_width, 0.0f) || base == 0) {
90 const float pixels_per_view_unit = pixel_width / view_width;
116 const float pixel_width,
117 const float view_width)
143 if (region_start >= region_end) {
155 if (region_start <= *r_first && region_end >= *r_first) {
156 *r_steps = std::max(0.0f,
floorf((region_end - *r_first) / lines->
distance)) + 1;
168 const rcti *rect_mask,
169 const uchar color[3],
173 uint steps, steps_max;
175 if (direction ==
'v') {
197 format,
"pos", blender::gpu::VertAttrType::SFLOAT_32_32);
199 if (
U.pixelsize > 1.0f) {
215 if (direction ==
'v') {
216 for (
uint i = 0;
i < steps;
i++) {
217 const float xpos = first +
i * lines->
distance;
223 for (
uint i = 0;
i < steps;
i++) {
224 const float ypos = first +
i * lines->
distance;
236 const uchar color[3],
246 const float major_distance,
247 const bool display_minor_lines,
248 const char direction)
250 if (display_minor_lines) {
251 uchar minor_color[3];
255 if (major_distance > 1) {
266 minor_lines.
distance = major_distance / divisor;
277 uchar major_color[3];
280 major_lines.
distance = major_distance;
290 void (*)(
void *user_data,
float v2d_pos,
float v2d_step,
char *r_str,
uint str_maxncpy);
297 void *to_string_data,
330 const float xmin = rect->
xmin;
331 const float xmax = rect->
xmax;
338 to_string(to_string_data, start, 0, text,
sizeof(text));
339 const float left_text_width =
BLF_width(font_id, text, strlen(text));
341 const float right_text_width =
BLF_width(font_id, text, strlen(text));
342 const float max_text_width =
max_ff(left_text_width, right_text_width);
344 draw_frequency =
ceil(
float(steps) / max_label_count);
347 if (draw_frequency != 0) {
348 const int start_index =
abs(
int(start /
distance)) % draw_frequency;
349 for (
uint i = start_index;
i < steps;
i += draw_frequency) {
350 const float xpos_view = start +
i *
distance;
353 const float text_width =
BLF_width(font_id, text, strlen(text));
355 if (xpos_region - text_width / 2.0f >= xmin && xpos_region + text_width / 2.0f <= xmax) {
357 xpos_region - std::trunc(text_width / 2.0f), ypos, 0.0f, text,
sizeof(text));
369 float display_offset,
372 void *to_string_data,
405 float shadow_color[4];
410 const float x_offset = 8.0f;
412 const float ymin = rect->
ymin;
413 const float ymax = rect->
ymax;
414 const float y_offset = (
BLF_height(font_id,
"0", 1) / 2.0f) -
U.pixelsize;
416 for (
uint i = 0;
i < steps;
i++) {
417 const float ypos_view = start +
i *
distance;
422 if (ypos_region - y_offset >= ymin && ypos_region + y_offset <= ymax) {
435 void * ,
float v2d_pos,
float ,
char *r_str,
uint str_maxncpy)
441 void *user_data,
float v2d_pos,
float v2d_step,
char *r_str,
uint str_maxncpy)
443 const Scene *scene = (
const Scene *)user_data;
445 int brevity_level = -1;
453 v2d_pos /
float(scene->frames_per_second()),
454 scene->frames_per_second(),
459 void * ,
float v2d_pos,
float v2d_step,
char *r_str,
uint str_maxncpy)
496 bool display_minor_lines)
501 v2d, major_line_distance, display_minor_lines && (major_line_distance > 1),
'v');
520 bool display_minor_lines)
525 v2d, major_line_distance, display_minor_lines && (major_line_distance > 1),
'v');
530 bool display_seconds,
531 bool display_minor_lines)
535 if (display_seconds) {
545 bool display_seconds)
548 if (display_seconds) {
560 const ARegion *region,
const View2D *v2d,
const rcti *rect,
int colorid,
const int base)
572 bool display_seconds,
578 if (display_seconds) {
592 bool display_seconds,
596 if (display_seconds) {
void BLF_enable(int fontid, FontFlags flag)
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
float BLF_height(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
void BLF_shadow_offset(int fontid, int x, int y)
void BLF_batch_draw_begin()
void BLF_batch_draw_end()
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_disable(int fontid, FontFlags flag)
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
MINLINE int round_fl_to_int(float a)
MINLINE float max_ff(float a, float b)
MINLINE int round_db_to_int(double a)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
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_push_projection()
void GPU_matrix_pop_projection()
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_viewport_size_get_f(float coords[4])
void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
void UI_GetThemeColor4fv(int colorid, float col[4])
void UI_FontThemeColor(int fontid, int colorid)
void UI_GetThemeColorShade3ubv(int colorid, int offset, unsigned char col[3])
float UI_view2d_region_to_view_y(const View2D *v2d, float y)
float UI_view2d_view_to_region_y(const View2D *v2d, float y)
void UI_view2d_view_ortho(const View2D *v2d)
float UI_view2d_scale_get_y(const View2D *v2d)
float UI_view2d_region_to_view_x(const View2D *v2d, float x)
float UI_view2d_view_to_region_x(const View2D *v2d, float x)
float UI_view2d_scale_get_x(const View2D *v2d)
static const char * to_string(const Interpolation &interp)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float distance(VecOp< float, D >, VecOp< float, D >) RET
void UI_view2d_draw_lines_x__values(const View2D *v2d, const int base)
float UI_view2d_grid_resolution_x__frames_or_seconds(const View2D *v2d, const Scene *scene)
static void draw_vertical_scale_indicators(const ARegion *region, const View2D *v2d, float distance, float display_offset, const rcti *rect, PositionToString to_string, void *to_string_data, int colorid)
static void draw_horizontal_scale_indicators(const ARegion *region, const View2D *v2d, float distance, const rcti *rect, PositionToString to_string, void *to_string_data, int colorid)
void UI_view2d_draw_scale_x__discrete_frames_or_seconds(const ARegion *region, const View2D *v2d, const rcti *rect, const Scene *scene, bool display_seconds, int colorid, const int base)
#define MIN_MAJOR_LINE_DISTANCE
void UI_view2d_draw_lines_x__discrete_values(const View2D *v2d, const int base, bool display_minor_lines)
void UI_view2d_draw_lines_y__values(const View2D *v2d, const int base)
static void view_to_string__frame_number(void *, float v2d_pos, float, char *r_str, uint str_maxncpy)
void UI_view2d_draw_lines_x__frames_or_seconds(const View2D *v2d, const Scene *scene, bool display_seconds)
static int get_divisor(const int distance)
void(*)(void *user_data, float v2d_pos, float v2d_step, char *r_str, uint str_maxncpy) PositionToString
static void view_to_string__time(void *user_data, float v2d_pos, float v2d_step, char *r_str, uint str_maxncpy)
static int calculate_grid_step(const int base, const float pixel_width, const float view_width)
void UI_view2d_draw_scale_y__values(const ARegion *region, const View2D *v2d, const rcti *rect, int colorid, const int base)
void UI_view2d_draw_lines_x__discrete_frames_or_seconds(const View2D *v2d, const Scene *scene, bool display_seconds, bool display_minor_lines)
static void view2d_draw_lines(const View2D *v2d, const float major_distance, const bool display_minor_lines, const char direction)
float UI_view2d_grid_resolution_y__values(const View2D *v2d, const int base)
static void view2d_draw_lines_internal(const View2D *v2d, const ParallelLinesSet *lines, const uchar color[3], char direction)
void UI_view2d_draw_lines_x__discrete_time(const View2D *v2d, const int base, bool display_minor_lines)
static float calculate_grid_step_subframes(const int base, const float pixel_width, const float view_width)
constexpr int subframe_range
static void view_to_string__value(void *, float v2d_pos, float v2d_step, char *r_str, uint str_maxncpy)
static void draw_parallel_lines(const ParallelLinesSet *lines, const rctf *rect, const rcti *rect_mask, const uchar color[3], char direction)
void UI_view2d_draw_scale_x__frames_or_seconds(const ARegion *region, const View2D *v2d, const rcti *rect, const Scene *scene, bool display_seconds, int colorid, const int base)
static void get_parallel_lines_draw_steps(const ParallelLinesSet *lines, float region_start, float region_end, float *r_first, uint *r_steps)
void wmOrtho2_region_pixelspace(const ARegion *region)