Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/view2d.c
| Show First 20 Lines • Show All 1,188 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Grid-Line Drawing | /** \name Grid-Line Drawing | ||||
| * \{ */ | * \{ */ | ||||
| /* Draw a constant grid in given 2d-region */ | |||||
| void UI_view2d_constant_grid_draw(const View2D *v2d, float step) | |||||
| { | |||||
| float start_x, start_y; | |||||
| int count_x, count_y; | |||||
| start_x = v2d->cur.xmin; | |||||
| if (start_x < 0.0) { | |||||
| start_x += -(float)fmod(v2d->cur.xmin, step); | |||||
| } | |||||
| else { | |||||
| start_x += (step - (float)fmod(v2d->cur.xmin, step)); | |||||
| } | |||||
| if (start_x > v2d->cur.xmax) { | |||||
| count_x = 0; | |||||
| } | |||||
| else { | |||||
| count_x = (v2d->cur.xmax - start_x) / step + 1; | |||||
| } | |||||
| start_y = v2d->cur.ymin; | |||||
| if (start_y < 0.0) { | |||||
| start_y += -(float)fmod(v2d->cur.ymin, step); | |||||
| } | |||||
| else { | |||||
| start_y += (step - (float)fabs(fmod(v2d->cur.ymin, step))); | |||||
| } | |||||
| if (start_y > v2d->cur.ymax) { | |||||
| count_y = 0; | |||||
| } | |||||
| else { | |||||
| count_y = (v2d->cur.ymax - start_y) / step + 1; | |||||
| } | |||||
| if (count_x > 0 || count_y > 0) { | |||||
| GPUVertFormat *format = immVertexFormat(); | |||||
| const uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | |||||
| const uint color = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | |||||
| float theme_color[3]; | |||||
| UI_GetThemeColorShade3fv(TH_BACK, -10, theme_color); | |||||
| immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR); | |||||
| immBegin(GPU_PRIM_LINES, count_x * 2 + count_y * 2 + 4); | |||||
| immAttr3fv(color, theme_color); | |||||
| for (int i = 0; i < count_x; start_x += step, i++) { | |||||
| immVertex2f(pos, start_x, v2d->cur.ymin); | |||||
| immVertex2f(pos, start_x, v2d->cur.ymax); | |||||
| } | |||||
| for (int i = 0; i < count_y; start_y += step, i++) { | |||||
| immVertex2f(pos, v2d->cur.xmin, start_y); | |||||
| immVertex2f(pos, v2d->cur.xmax, start_y); | |||||
| } | |||||
| /* X and Y axis */ | |||||
| UI_GetThemeColorShade3fv(TH_BACK, -18, theme_color); | |||||
| immAttr3fv(color, theme_color); | |||||
| immVertex2f(pos, 0.0f, v2d->cur.ymin); | |||||
| immVertex2f(pos, 0.0f, v2d->cur.ymax); | |||||
| immVertex2f(pos, v2d->cur.xmin, 0.0f); | |||||
| immVertex2f(pos, v2d->cur.xmax, 0.0f); | |||||
| immEnd(); | |||||
| immUnbindProgram(); | |||||
| } | |||||
| } | |||||
| /* Draw a multi-level grid in given 2d-region */ | /* Draw a multi-level grid in given 2d-region */ | ||||
| void UI_view2d_multi_grid_draw( | void UI_view2d_multi_grid_draw( | ||||
| const View2D *v2d, int colorid, float step, int level_size, int totlevels) | const View2D *v2d, int colorid, float step, int level_size, int totlevels) | ||||
| { | { | ||||
| /* Exit if there is nothing to draw */ | /* Exit if there is nothing to draw */ | ||||
| if (totlevels == 0) { | if (totlevels == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 632 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return BLI_rcti_size_x(&v2d->mask) / BLI_rctf_size_x(&v2d->cur); | return BLI_rcti_size_x(&v2d->mask) / BLI_rctf_size_x(&v2d->cur); | ||||
| } | } | ||||
| float UI_view2d_scale_get_y(const View2D *v2d) | float UI_view2d_scale_get_y(const View2D *v2d) | ||||
| { | { | ||||
| return BLI_rcti_size_y(&v2d->mask) / BLI_rctf_size_y(&v2d->cur); | return BLI_rcti_size_y(&v2d->mask) / BLI_rctf_size_y(&v2d->cur); | ||||
| } | } | ||||
| /** | /** | ||||
| * Same as ``UI_view2d_scale_get() - 1.0f / x, y`` | * Same as `UI_view2d_scale_get() - 1.0f / x, y`. | ||||
| */ | */ | ||||
| void UI_view2d_scale_get_inverse(const View2D *v2d, float *r_x, float *r_y) | void UI_view2d_scale_get_inverse(const View2D *v2d, float *r_x, float *r_y) | ||||
| { | { | ||||
| if (r_x) { | if (r_x) { | ||||
| *r_x = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); | *r_x = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask); | ||||
| } | } | ||||
| if (r_y) { | if (r_y) { | ||||
| *r_y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask); | *r_y = BLI_rctf_size_y(&v2d->cur) / BLI_rcti_size_y(&v2d->mask); | ||||
| ▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines | |||||