Refactoring: Corrections and unifications in mathematics vfont gizmos #107193
|
@ -24,7 +24,8 @@ struct CharTrans {
|
|||
};
|
||||
|
||||
typedef struct EditFontSelBox {
|
||||
float x, y, w, h;
|
||||
float loc[2];
|
||||
float size[2];
|
||||
float rot;
|
||||
} EditFontSelBox;
|
||||
|
||||
|
@ -37,8 +38,11 @@ typedef struct EditFont {
|
|||
/** Text style info (aligned with `textbuf`). */
|
||||
struct CharInfo *textbufinfo;
|
||||
|
||||
/** Array of rectangles & rotation. */
|
||||
float textcurs[4][2];
|
||||
/* Location is centre of box.*/
|
||||
float curs_location[2];
|
||||
float curs_size[2];
|
||||
float curs_angle;
|
||||
/** Array of location & rotation. */
|
||||
EditFontSelBox *selboxes;
|
||||
int selboxes_len;
|
||||
|
||||
|
|
|
@ -1122,9 +1122,9 @@ static bool vfont_to_curve(Object *ob,
|
|||
|
||||
if (selboxes && (i >= selstart) && (i <= selend)) {
|
||||
sb = &selboxes[i - selstart];
|
||||
sb->y = yof * font_size - linedist * font_size * 0.1f;
|
||||
sb->h = linedist * font_size;
|
||||
sb->w = xof * font_size;
|
||||
sb->loc[1] = yof * font_size - linedist * font_size * 0.1f;
|
||||
const float size[2] = {linedist * font_size, xof * font_size};
|
||||
copy_v2_v2(sb->size, size);
|
||||
}
|
||||
|
||||
if (ascii == ' ') { /* Space character. */
|
||||
|
@ -1141,7 +1141,7 @@ static bool vfont_to_curve(Object *ob,
|
|||
xof += (twidth * wsfac * (1.0f + (info->kern / 40.0f))) + xtrax;
|
||||
|
||||
if (sb) {
|
||||
sb->w = (xof * font_size) - sb->w;
|
||||
sb->size[0] = (xof * font_size) - sb->size[0];
|
||||
}
|
||||
}
|
||||
ct++;
|
||||
|
@ -1442,8 +1442,7 @@ static bool vfont_to_curve(Object *ob,
|
|||
ct->yof = vec[1] + co * yof;
|
||||
|
||||
if (selboxes && (i >= selstart) && (i <= selend)) {
|
||||
EditFontSelBox *sb;
|
||||
sb = &selboxes[i - selstart];
|
||||
EditFontSelBox *sb = &selboxes[i - selstart];
|
||||
sb->rot = -ct->rot;
|
||||
}
|
||||
}
|
||||
|
@ -1452,12 +1451,11 @@ static bool vfont_to_curve(Object *ob,
|
|||
|
||||
if (selboxes) {
|
||||
ct = chartransdata;
|
||||
for (i = 0; i <= selend; i++, ct++) {
|
||||
if (i >= selstart) {
|
||||
selboxes[i - selstart].x = ct->xof * font_size;
|
||||
selboxes[i - selstart].y = (ct->yof - 0.25f) * font_size;
|
||||
selboxes[i - selstart].h = font_size;
|
||||
}
|
||||
ct += selstart;
|
||||
for (i = 0; i <= selend - selstart; i++, ct++) {
|
||||
copy_v2_v2(selboxes[i].loc, &ct->xof);
|
||||
mul_v2_fl(selboxes[i].loc, font_size);
|
||||
selboxes[i].size[1] = font_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1537,14 +1535,28 @@ static bool vfont_to_curve(Object *ob,
|
|||
/* Rectangle shape of first cursor. */
|
||||
if (ef) {
|
||||
ct = &chartransdata[ef->pos];
|
||||
// if (ef->pos < slen){}
|
||||
const float descender_downship = 0.25f;
|
||||
|
||||
const float centre = (0.5 - descender_downship) * font_size;
|
||||
float geom[2][2];
|
||||
angle_to_mat2(geom, -ct->rot);
|
||||
float offset_for_centre[2] = {0.0f, centre};
|
||||
mul_v2_m2v2(ef->curs_location, geom, offset_for_centre);
|
||||
add_v2_v2(ef->curs_location, &ct->xof);
|
||||
|
||||
ef->curs_size[0] = 0.05f;
|
||||
ef->curs_size[1] = 1.0f;
|
||||
mul_v2_fl(ef->curs_size, font_size / 2.0f);
|
||||
ef->curs_angle = -ct->rot;
|
||||
mul_v2_fl(ef->curs_location, font_size);
|
||||
#if 0
|
||||
float(*points)[4][2] = &ef->textcurs;
|
||||
|
||||
float geom[2][2];
|
||||
angle_to_mat2(geom, -ct->rot);
|
||||
|
||||
const float width = 0.05f / 2.0f;
|
||||
const float top_point = 0.8f;
|
||||
const float bottom_point = -0.2;
|
||||
|
||||
/* Bottom left corner point. */
|
||||
(*points)[0][0] = width;
|
||||
|
@ -1568,6 +1580,7 @@ static bool vfont_to_curve(Object *ob,
|
|||
add_v2_v2(*point, &ct->xof);
|
||||
mul_v2_fl(*point, font_size);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (mode == FO_SELCHANGE) {
|
||||
|
@ -1800,16 +1813,8 @@ bool BKE_vfont_to_curve_ex(Object *ob,
|
|||
};
|
||||
|
||||
do {
|
||||
data.ok &= vfont_to_curve(ob,
|
||||
cu,
|
||||
mode,
|
||||
&data,
|
||||
NULL,
|
||||
r_nubase,
|
||||
r_text,
|
||||
r_text_len,
|
||||
r_text_free,
|
||||
r_chartransdata);
|
||||
data.ok &= vfont_to_curve(
|
||||
ob, cu, mode, &data, NULL, r_nubase, r_text, r_text_len, r_text_free, r_chartransdata);
|
||||
} while (data.ok && ELEM(data.status, VFONT_TO_CURVE_SCALE_ONCE, VFONT_TO_CURVE_BISECT));
|
||||
|
||||
return data.ok;
|
||||
|
|
|
@ -66,18 +66,15 @@ void OVERLAY_edit_text_cache_init(OVERLAY_Data *vedata)
|
|||
}
|
||||
}
|
||||
|
||||
/* Use 2D quad corners to create a matrix that set
|
||||
* a [-1..1] quad at the right position. */
|
||||
static void v2_quad_corners_to_mat4(const float corners[4][2], float r_mat[4][4])
|
||||
static void v2_transform_to_mat4(const float loc[2],
|
||||
const float rot,
|
||||
const float scale[2],
|
||||
float r_mat[4][4])
|
||||
{
|
||||
unit_m4(r_mat);
|
||||
sub_v2_v2v2(r_mat[0], corners[1], corners[0]);
|
||||
sub_v2_v2v2(r_mat[1], corners[3], corners[0]);
|
||||
mul_v2_fl(r_mat[0], 0.5f);
|
||||
mul_v2_fl(r_mat[1], 0.5f);
|
||||
copy_v2_v2(r_mat[3], corners[0]);
|
||||
add_v2_v2(r_mat[3], r_mat[0]);
|
||||
add_v2_v2(r_mat[3], r_mat[1]);
|
||||
const float loc_v3[3] = {loc[0], loc[1], 0.0f};
|
||||
const float rot_v3[3] = {0.0f, 0.0f, rot};
|
||||
const float size_v3[3] = {scale[0], scale[1], 0.0f};
|
||||
loc_eul_size_to_mat4(r_mat, loc_v3, rot_v3, size_v3);
|
||||
}
|
||||
|
||||
static void edit_text_cache_populate_select(OVERLAY_Data *vedata, Object *ob)
|
||||
|
@ -85,42 +82,13 @@ static void edit_text_cache_populate_select(OVERLAY_Data *vedata, Object *ob)
|
|||
OVERLAY_PrivateData *pd = vedata->stl->pd;
|
||||
const Curve *cu = static_cast<Curve *>(ob->data);
|
||||
EditFont *ef = cu->editfont;
|
||||
float final_mat[4][4], box[4][2];
|
||||
struct GPUBatch *geom = DRW_cache_quad_get();
|
||||
|
||||
for (int i = 0; i < ef->selboxes_len; i++) {
|
||||
EditFontSelBox *sb = &ef->selboxes[i];
|
||||
|
||||
float selboxw;
|
||||
if (i + 1 != ef->selboxes_len) {
|
||||
if (ef->selboxes[i + 1].y == sb->y) {
|
||||
selboxw = ef->selboxes[i + 1].x - sb->x;
|
||||
}
|
||||
else {
|
||||
selboxw = sb->w;
|
||||
}
|
||||
}
|
||||
else {
|
||||
selboxw = sb->w;
|
||||
}
|
||||
/* NOTE: v2_quad_corners_to_mat4 don't need the 3rd corner. */
|
||||
if (sb->rot == 0.0f) {
|
||||
copy_v2_fl2(box[0], sb->x, sb->y);
|
||||
copy_v2_fl2(box[1], sb->x + selboxw, sb->y);
|
||||
copy_v2_fl2(box[3], sb->x, sb->y + sb->h);
|
||||
}
|
||||
else {
|
||||
float mat[2][2];
|
||||
angle_to_mat2(mat, sb->rot);
|
||||
copy_v2_fl2(box[0], sb->x, sb->y);
|
||||
mul_v2_v2fl(box[1], mat[0], selboxw);
|
||||
add_v2_v2(box[1], &sb->x);
|
||||
mul_v2_v2fl(box[3], mat[1], sb->h);
|
||||
add_v2_v2(box[3], &sb->x);
|
||||
}
|
||||
v2_quad_corners_to_mat4(box, final_mat);
|
||||
EditFontSelBox &sb = ef->selboxes[i];
|
||||
float final_mat[4][4];
|
||||
v2_transform_to_mat4(sb.loc, sb.rot, sb.size, final_mat);
|
||||
mul_m4_m4m4(final_mat, ob->object_to_world, final_mat);
|
||||
|
||||
DRW_shgroup_call_obmat(pd->edit_text_selection_grp, geom, final_mat);
|
||||
}
|
||||
}
|
||||
|
@ -129,11 +97,10 @@ static void edit_text_cache_populate_cursor(OVERLAY_Data *vedata, Object *ob)
|
|||
{
|
||||
OVERLAY_PrivateData *pd = vedata->stl->pd;
|
||||
const Curve *cu = static_cast<Curve *>(ob->data);
|
||||
EditFont *edit_font = cu->editfont;
|
||||
float(*cursor)[2] = edit_font->textcurs;
|
||||
float mat[4][4];
|
||||
EditFont &edit_font = *cu->editfont;
|
||||
|
||||
v2_quad_corners_to_mat4(cursor, mat);
|
||||
float mat[4][4];
|
||||
v2_transform_to_mat4(edit_font.curs_location, edit_font.curs_angle, edit_font.curs_size, mat);
|
||||
mul_m4_m4m4(mat, ob->object_to_world, mat);
|
||||
|
||||
struct GPUBatch *geom = DRW_cache_quad_get();
|
||||
|
|
|
@ -261,11 +261,12 @@ bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
|
|||
Curve *cu = static_cast<Curve *>(ob_act_eval->data);
|
||||
EditFont *ef = cu->editfont;
|
||||
|
||||
float geom[2][2];
|
||||
angle_to_mat2(geom, ef->curs_angle);
|
||||
zero_v3(lastofs);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
add_v2_v2(lastofs, ef->textcurs[i]);
|
||||
}
|
||||
mul_v2_fl(lastofs, 1.0f / 4.0f);
|
||||
lastofs[1] = ef->curs_size[1] / 2.0f;
|
||||
mul_m2_v2(geom, lastofs);
|
||||
add_v2_v2(lastofs, ef->curs_location);
|
||||
|
||||
mul_m4_v3(ob_act_eval->object_to_world, lastofs);
|
||||
|
||||
|
|
Loading…
Reference in New Issue