Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_widgets.c
| Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | |||||
| 2, | 2, | ||||
| fcol); | fcol); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| #endif /* WITH_INPUT_IME */ | #endif /* WITH_INPUT_IME */ | ||||
| static bool widget_draw_text_underline_calc_center_x(const char *UNUSED(str), | static bool widget_draw_text_underline_calc_center_x(const char *UNUSED(str), | ||||
| const size_t str_step_ofs, | const size_t str_step_ofs, | ||||
campbellbarton: This can be a `size_t`, avoids the cast in the callback function. | |||||
| const rcti *glyph_step_bounds, | const rcti *glyph_step_bounds, | ||||
Not Done Inline ActionsThe ul_ prefix is redundant as destruct is already named to make it clear this deals with underline data. campbellbarton: The `ul_` prefix is redundant as destruct is already named to make it clear this deals with… | |||||
| const int UNUSED(glyph_advance_x), | const int UNUSED(glyph_advance_x), | ||||
| const rctf *glyph_bounds, | const rctf *glyph_bounds, | ||||
| const int glyph_bearing[2], | const int glyph_bearing[2], | ||||
| void *user_data) | void *user_data) | ||||
| { | { | ||||
| /* The index of the character to get, set to the x-position. */ | /* The index of the character to get, set to the x-position. */ | ||||
| int *ul_data = user_data; | int *ul_data = user_data; | ||||
| if (ul_data[0] == (int)str_step_ofs) { | if (ul_data[0] == (int)str_step_ofs) { | ||||
| ul_data[1] = glyph_step_bounds->xmin + glyph_bearing[0] + | /* full with of glyph including both bearings. */ | ||||
| (BLI_rctf_size_x(glyph_bounds) / 2.0f); | float width = glyph_bounds->xmin + BLI_rctf_size_x(glyph_bounds) + glyph_bounds->xmin; | ||||
| ul_data[2] = glyph_step_bounds->xmin + ((width - ul_data[1]) * 0.5f); | |||||
| ul_data[3] = glyph_bounds->ymin; | |||||
| /* Early exit. */ | /* Early exit. */ | ||||
| return false; | return false; | ||||
| } | } | ||||
Not Done Inline Actionsuse const. campbellbarton: use `const`. | |||||
| return true; | return true; | ||||
| } | } | ||||
| static void widget_draw_text(const uiFontStyle *fstyle, | static void widget_draw_text(const uiFontStyle *fstyle, | ||||
| const uiWidgetColors *wcol, | const uiWidgetColors *wcol, | ||||
| uiBut *but, | uiBut *but, | ||||
| rcti *rect) | rcti *rect) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| } | } | ||||
| if (ul_index != -1) { | if (ul_index != -1) { | ||||
| if (fstyle->kerning == 1) { | if (fstyle->kerning == 1) { | ||||
| BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| } | } | ||||
| int ul_data[2] = { | int ul_width = round(BLF_width(fstyle->uifont_id, "_", 2)); | ||||
| int ul_height = MAX2(fstyle->points * U.dpi_fac * 0.1f, U.pixelsize); | |||||
| int ul_data[4] = { | |||||
| ul_index, /* Character index to test. */ | ul_index, /* Character index to test. */ | ||||
| ul_width, /* Width of underline. */ | |||||
| 0, /* Write the x-offset here. */ | 0, /* Write the x-offset here. */ | ||||
Not Done Inline Actionsround_fl_to_int. campbellbarton: `round_fl_to_int`. | |||||
| 0, /* Write the y-offset here. */ | |||||
Not Done Inline ActionsMAX2 -> max_ii. campbellbarton: `MAX2` -> `max_ii`. | |||||
| }; | }; | ||||
campbellbartonUnsubmitted Not Done Inline ActionsSince this is getting more involved than a pair of numbers, more readable to make this into a struct. eg: struct UnderlineData {
/** The offset of the character to test. */
int str_test_offset;
/* The underline with in pixels. */
int char_width_px;
/** Write the X,Y offset here. */
int r_offset_px[2];
};campbellbarton: Since this is getting more involved than a pair of numbers, more readable to make this into a… | |||||
Not Done Inline ActionsAvoid relying on order of struct members. struct UnderlineData ul_data = {
.ul_str_offset = ul_str_offset,
.ul_width_px = ul_width,
};campbellbarton: Avoid relying on order of struct members.
```
struct UnderlineData ul_data = {
.ul_str_offset… | |||||
| BLF_boundbox_foreach_glyph(fstyle->uifont_id, | BLF_boundbox_foreach_glyph(fstyle->uifont_id, | ||||
| drawstr_ofs, | drawstr_ofs, | ||||
| ul_index + 1, | ul_index + 1, | ||||
| widget_draw_text_underline_calc_center_x, | widget_draw_text_underline_calc_center_x, | ||||
| ul_data); | ul_data); | ||||
| ul_data[1] -= BLF_width(fstyle->uifont_id, "_", 2) / 2.0f; | |||||
| GPU_blend(GPU_BLEND_ALPHA); | |||||
| BLF_position(fstyle->uifont_id, | const uint pos = GPU_vertformat_attr_add( | ||||
| rect->xmin + font_xofs + ul_data[1], | immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); | ||||
| rect->ymin + font_yofs, | immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); | ||||
| 0.0f); | immUniformColor4ubv(wcol->text); | ||||
| BLF_color4ubv(fstyle->uifont_id, wcol->text); | int pos_x = rect->xmin + font_xofs + ul_data[2]; | ||||
| BLF_draw(fstyle->uifont_id, "_", 2); | int pos_y = rect->ymin + font_yofs + ul_data[3] - U.pixelsize - U.pixelsize; | ||||
| immRecti(pos, pos_x, pos_y, pos_x + ul_width, pos_y - ul_height); | |||||
| immUnbindProgram(); | |||||
| GPU_blend(GPU_BLEND_NONE); | |||||
| if (fstyle->kerning == 1) { | if (fstyle->kerning == 1) { | ||||
| BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||
This can be a size_t, avoids the cast in the callback function.