Text3d: move text selection boxes from Curve to EditFont struct

resolves T38079
This commit is contained in:
Campbell Barton 2014-01-07 17:04:19 +11:00
parent a97180046b
commit 4a372102c7
6 changed files with 53 additions and 42 deletions

View File

@ -53,18 +53,20 @@ struct CharTrans {
char dobreak;
};
typedef struct SelBox {
typedef struct EditFontSelBox {
float x, y, w, h;
float rot;
} SelBox;
} EditFontSelBox;
typedef struct EditFont {
typedef struct EditFont {
wchar_t *copybuf;
struct CharInfo *copybufinfo;
wchar_t *textbuf;
struct CharInfo *textbufinfo;
/* array of rectangles & rotation */
EditFontSelBox *selboxes;
float textcurs[4][2];
/* positional vars relative to the textbuf, textbufinfo (not utf8 bytes)

View File

@ -112,12 +112,12 @@ void BKE_curve_editfont_free(Curve *cu)
MEM_freeN(ef->copybuf);
if (ef->copybufinfo)
MEM_freeN(ef->copybufinfo);
if (ef->selboxes)
MEM_freeN(ef->selboxes);
MEM_freeN(ef);
cu->editfont = NULL;
}
MEM_SAFE_FREE(cu->selboxes);
}
void BKE_curve_editNurb_keyIndex_free(EditNurb *editnurb)
@ -224,7 +224,6 @@ Curve *BKE_curve_copy(Curve *cu)
cun->editnurb = NULL;
cun->editfont = NULL;
cun->selboxes = NULL;
cun->lastsel = NULL;
#if 0 // XXX old animation system

View File

@ -502,6 +502,7 @@ bool BKE_vfont_to_curve_ex(Main *bmain, Scene *scene, Object *ob, int mode,
{
Curve *cu = ob->data;
EditFont *ef = cu->editfont;
EditFontSelBox *selboxes = NULL;
VFont *vfont, *oldvfont;
VFontData *vfd = NULL;
CharInfo *info = NULL, *custrinfo;
@ -562,6 +563,18 @@ bool BKE_vfont_to_curve_ex(Main *bmain, Scene *scene, Object *ob, int mode,
if (cu->tb == NULL)
cu->tb = MEM_callocN(MAXTEXTBOX * sizeof(TextBox), "TextBox compat");
if (ef) {
if (ef->selboxes)
MEM_freeN(ef->selboxes);
if (BKE_vfont_select_get(ob, &selstart, &selend))
ef->selboxes = MEM_callocN((selend - selstart + 1) * sizeof(EditFontSelBox), "font selboxes");
else
ef->selboxes = NULL;
selboxes = ef->selboxes;
}
/* calc offset and rotation of each char */
ct = chartransdata = MEM_callocN((slen + 1) * sizeof(struct CharTrans), "buildtext");
@ -583,11 +596,6 @@ bool BKE_vfont_to_curve_ex(Main *bmain, Scene *scene, Object *ob, int mode,
for (i = 0; i < slen; i++) custrinfo[i].flag &= ~(CU_CHINFO_WRAP | CU_CHINFO_SMALLCAPS_CHECK);
if (cu->selboxes) MEM_freeN(cu->selboxes);
cu->selboxes = NULL;
if (BKE_vfont_select_get(ob, &selstart, &selend))
cu->selboxes = MEM_callocN((selend - selstart + 1) * sizeof(SelBox), "font selboxes");
tb = &(cu->tb[0]);
curbox = 0;
for (i = 0; i <= slen; i++) {
@ -729,7 +737,7 @@ makebreak:
xof = cu->xof + tabfac;
}
else {
SelBox *sb = NULL;
EditFontSelBox *sb = NULL;
float wsfac;
ct->xof = xof;
@ -737,8 +745,8 @@ makebreak:
ct->linenr = lnr;
ct->charnr = cnr++;
if (cu->selboxes && (i >= selstart) && (i <= selend)) {
sb = &(cu->selboxes[i - selstart]);
if (selboxes && (i >= selstart) && (i <= selend)) {
sb = &selboxes[i - selstart];
sb->y = yof * cu->fsize - linedist * cu->fsize * 0.1f;
sb->h = linedist * cu->fsize;
sb->w = xof * cu->fsize;
@ -929,9 +937,9 @@ makebreak:
ct->xof = vec[0] + si * yof;
ct->yof = vec[1] + co * yof;
if (cu->selboxes && (i >= selstart) && (i <= selend)) {
SelBox *sb;
sb = &(cu->selboxes[i - selstart]);
if (selboxes && (i >= selstart) && (i <= selend)) {
EditFontSelBox *sb;
sb = &selboxes[i - selstart];
sb->rot = -ct->rot;
}
@ -940,12 +948,12 @@ makebreak:
}
}
if (cu->selboxes) {
if (selboxes) {
ct = chartransdata;
for (i = 0; i <= selend; i++, ct++) {
if (i >= selstart) {
cu->selboxes[i - selstart].x = ct->xof * cu->fsize;
cu->selboxes[i - selstart].y = ct->yof * cu->fsize;
selboxes[i - selstart].x = ct->xof * cu->fsize;
selboxes[i - selstart].y = ct->yof * cu->fsize;
}
}
}

View File

@ -3335,8 +3335,6 @@ static void lib_link_curve(FileData *fd, Main *main)
cu->ipo = newlibadr_us(fd, cu->id.lib, cu->ipo); // XXX deprecated - old animation system
cu->key = newlibadr_us(fd, cu->id.lib, cu->key);
cu->selboxes = NULL; /* runtime, clear */
cu->id.flag -= LIB_NEED_LINK;
}

View File

@ -6815,7 +6815,9 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
case OB_FONT:
cu = ob->data;
if (cu->editfont) {
draw_textcurs(rv3d, cu->editfont->textcurs);
EditFont *ef = cu->editfont;
draw_textcurs(rv3d, ef->textcurs);
if (cu->flag & CU_FAST) {
cpack(0xFFFFFF);
@ -6866,18 +6868,19 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
setlinestyle(0);
if (BKE_vfont_select_get(ob, &selstart, &selend) && cu->selboxes) {
if (BKE_vfont_select_get(ob, &selstart, &selend) && ef->selboxes) {
const int seltot = selend - selstart;
float selboxw;
cpack(0xffffff);
set_inverted_drawing(1);
for (i = 0; i <= (selend - selstart); i++) {
SelBox *sb = &(cu->selboxes[i]);
for (i = 0; i <= seltot; i++) {
EditFontSelBox *sb = &ef->selboxes[i];
float tvec[3];
if (i < (selend - selstart)) {
if (cu->selboxes[i + 1].y == sb->y)
selboxw = cu->selboxes[i + 1].x - sb->x;
if (i != seltot) {
if (ef->selboxes[i + 1].y == sb->y)
selboxw = ef->selboxes[i + 1].x - sb->x;
else
selboxw = sb->w;
}

View File

@ -210,7 +210,8 @@ typedef struct Curve {
int actnu;
/* edit, last selected point */
void *lastsel;
/* font part */
short lines;
char spacemode, pad1;
@ -218,35 +219,35 @@ typedef struct Curve {
float xof, yof;
float linewidth;
int pad3;
int len_wchar; /* number of characters (strinfo) */
int len; /* number of bytes (str - utf8) */
char *str;
struct SelBox *selboxes; /* runtime variable for drawing selections (editmode data) */
struct EditFont *editfont;
/* copy of EditFont vars (wchar_t aligned),
* warning! don't use in editmode (storage only) */
int pos;
int selstart, selend;
int pad2;
/* text data */
int len_wchar; /* number of characters (strinfo) */
int len; /* number of bytes (str - utf8) */
char *str;
struct EditFont *editfont;
char family[64];
struct VFont *vfont;
struct VFont *vfontb;
struct VFont *vfonti;
struct VFont *vfontbi;
int pad4;
float ctime; /* current evaltime - for use by Objects parented to curves */
int totbox, actbox;
struct TextBox *tb;
int totbox, actbox;
struct CharInfo *strinfo;
struct CharInfo curinfo;
/* font part end */
float ctime; /* current evaltime - for use by Objects parented to curves */
float bevfac1, bevfac2;
char pad[4];
} Curve;
/* **************** CURVE ********************* */