Fix #107499: Text Object Selection with Scale To Fit Mode
Allow mouse text selection and cursor positioning to work correctly when the text box has overflow mode set to "Scale to Fit." Pull Request: https://projects.blender.org/blender/blender/pulls/107510
This commit is contained in:
committed by
Harley Acheson
parent
71e4f48180
commit
22245115fd
@@ -1475,38 +1475,6 @@ static bool vfont_to_curve(Object *ob,
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor_params) {
|
||||
cursor_params->r_string_offset = -1;
|
||||
for (i = 0; i <= slen; i++, ct++) {
|
||||
info = &custrinfo[i];
|
||||
ascii = mem[i];
|
||||
if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) {
|
||||
ascii = towupper(ascii);
|
||||
}
|
||||
ct = &chartransdata[i];
|
||||
che = find_vfont_char(vfd, ascii);
|
||||
float charwidth = char_width(cu, che, info);
|
||||
float charhalf = (charwidth / 2.0f);
|
||||
if (cursor_params->cursor_location[1] >= ct->yof - (0.25f * linedist) &&
|
||||
cursor_params->cursor_location[1] <= (ct->yof + (0.75f * linedist)))
|
||||
{
|
||||
/* On this row. */
|
||||
if (cursor_params->cursor_location[0] >= (ct->xof) &&
|
||||
cursor_params->cursor_location[0] <= (ct->xof + charhalf))
|
||||
{
|
||||
/* Left half of character. */
|
||||
cursor_params->r_string_offset = i;
|
||||
}
|
||||
else if (cursor_params->cursor_location[0] >= (ct->xof + charhalf) &&
|
||||
cursor_params->cursor_location[0] <= (ct->xof + charwidth))
|
||||
{
|
||||
/* Right half of character. */
|
||||
cursor_params->r_string_offset = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ELEM(mode, FO_CURSUP, FO_CURSDOWN, FO_PAGEUP, FO_PAGEDOWN) &&
|
||||
iter_data->status == VFONT_TO_CURVE_INIT)
|
||||
{
|
||||
@@ -1772,6 +1740,38 @@ static bool vfont_to_curve(Object *ob,
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor_params) {
|
||||
cursor_params->r_string_offset = -1;
|
||||
for (i = 0; i <= slen; i++, ct++) {
|
||||
info = &custrinfo[i];
|
||||
ascii = mem[i];
|
||||
if (info->flag & CU_CHINFO_SMALLCAPS_CHECK) {
|
||||
ascii = towupper(ascii);
|
||||
}
|
||||
ct = &chartransdata[i];
|
||||
che = find_vfont_char(vfd, ascii);
|
||||
float charwidth = char_width(cu, che, info);
|
||||
float charhalf = (charwidth / 2.0f);
|
||||
if (cursor_params->cursor_location[1] >= (ct->yof - (0.25f * linedist)) * font_size &&
|
||||
cursor_params->cursor_location[1] <= (ct->yof + (0.75f * linedist)) * font_size)
|
||||
{
|
||||
/* On this row. */
|
||||
if (cursor_params->cursor_location[0] >= (ct->xof * font_size) &&
|
||||
cursor_params->cursor_location[0] <= ((ct->xof + charhalf) * font_size))
|
||||
{
|
||||
/* Left half of character. */
|
||||
cursor_params->r_string_offset = i;
|
||||
}
|
||||
else if (cursor_params->cursor_location[0] >= ((ct->xof + charhalf) * font_size) &&
|
||||
cursor_params->cursor_location[0] <= ((ct->xof + charwidth) * font_size))
|
||||
{
|
||||
/* Right half of character. */
|
||||
cursor_params->r_string_offset = i + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Scale to fit only works for single text box layouts. */
|
||||
if (ELEM(iter_data->status, VFONT_TO_CURVE_SCALE_ONCE, VFONT_TO_CURVE_BISECT)) {
|
||||
/* Always cleanup before going to the scale-to-fit repetition. */
|
||||
|
||||
@@ -1812,8 +1812,6 @@ void FONT_OT_text_insert(wmOperatorType *ot)
|
||||
|
||||
static int font_cursor_text_index_from_event(bContext *C, Object *obedit, const wmEvent *event)
|
||||
{
|
||||
Curve *cu = obedit->data;
|
||||
|
||||
/* Calculate a plane from the text object's orientation. */
|
||||
float plane[4];
|
||||
plane_from_point_normal_v3(plane, obedit->object_to_world[3], obedit->object_to_world[2]);
|
||||
@@ -1826,7 +1824,7 @@ static int font_cursor_text_index_from_event(bContext *C, Object *obedit, const
|
||||
/* Convert to object space and scale by font size. */
|
||||
mul_m4_v3(obedit->world_to_object, mouse_loc);
|
||||
|
||||
float curs_loc[2] = {mouse_loc[0] / cu->fsize, mouse_loc[1] / cu->fsize};
|
||||
float curs_loc[2] = {mouse_loc[0], mouse_loc[1]};
|
||||
return BKE_vfont_cursor_to_text_index(obedit, curs_loc);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user