Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_widgets.c
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| min_ii(width, rect_x - 2) - ofs_x, | min_ii(width, rect_x - 2) - ofs_x, | ||||
| 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), | struct UnderlineData { | ||||
| size_t str_offset; /* The string offset of the underlined character. */ | |||||
campbellbarton: This can be a `size_t`, avoids the cast in the callback function. | |||||
| int width_px; /* The underline width in pixels. */ | |||||
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… | |||||
| int r_offset_px[2]; /* Write the X,Y offset here. */ | |||||
| }; | |||||
| static bool widget_draw_text_underline_calc_position(const char *UNUSED(str), | |||||
| const size_t str_step_ofs, | const size_t str_step_ofs, | ||||
| const rcti *glyph_step_bounds, | const rcti *glyph_step_bounds, | ||||
| 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. */ | struct UnderlineData *ul_data = user_data; | ||||
| int *ul_data = user_data; | if (ul_data->str_offset == str_step_ofs) { | ||||
| if (ul_data[0] == (int)str_step_ofs) { | /* Full width of this glyph including both bearings. */ | ||||
| ul_data[1] = glyph_step_bounds->xmin + glyph_bearing[0] + | const float width = glyph_bounds->xmin + BLI_rctf_size_x(glyph_bounds) + glyph_bounds->xmin; | ||||
Not Done Inline Actionsuse const. campbellbarton: use `const`. | |||||
| (BLI_rctf_size_x(glyph_bounds) / 2.0f); | ul_data->r_offset_px[0] = glyph_step_bounds->xmin + ((width - ul_data->width_px) * 0.5f); | ||||
| /* Two line-widths below the lower glyph bounds. */ | |||||
| ul_data->r_offset_px[1] = glyph_bounds->ymin - U.pixelsize - U.pixelsize; | |||||
| /* Early exit. */ | /* Early exit. */ | ||||
| return false; | return false; | ||||
| } | } | ||||
| 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, | ||||
| ▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | |||||
| ul_index = (int)(drawstr_menu - drawstr_ofs); | ul_index = (int)(drawstr_menu - drawstr_ofs); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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_fl_to_int(BLF_width(fstyle->uifont_id, "_", 2)); | ||||
| ul_index, /* Character index to test. */ | int ul_height = max_ii(fstyle->points * U.dpi_fac * 0.1f, U.pixelsize); | ||||
| 0, /* Write the x-offset here. */ | |||||
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… | |||||
| struct UnderlineData ul_data = { | |||||
| .str_offset = ul_index, | |||||
| .width_px = ul_width, | |||||
| }; | }; | ||||
Not Done Inline ActionsMAX2 -> max_ii. campbellbarton: `MAX2` -> `max_ii`. | |||||
Not Done Inline Actionsround_fl_to_int. campbellbarton: `round_fl_to_int`. | |||||
| BLF_boundbox_foreach_glyph(fstyle->uifont_id, | BLF_boundbox_foreach_glyph(fstyle->uifont_id, | ||||
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… | |||||
| drawstr_ofs, | drawstr_ofs, | ||||
| ul_index + 1, | ul_index + 1, | ||||
| widget_draw_text_underline_calc_center_x, | widget_draw_text_underline_calc_position, | ||||
| 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); | const int pos_x = rect->xmin + font_xofs + ul_data.r_offset_px[0]; | ||||
| BLF_draw(fstyle->uifont_id, "_", 2); | const int pos_y = rect->ymin + font_yofs + ul_data.r_offset_px[1]; | ||||
| 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.