Cleanup: use booleans for text drawing & editing
This commit is contained in:
@@ -191,7 +191,8 @@ void wrap_offset(
|
||||
{
|
||||
Text *text;
|
||||
TextLine *linep;
|
||||
int i, j, start, end, max, chop;
|
||||
int i, j, start, end, max;
|
||||
bool chop;
|
||||
char ch;
|
||||
|
||||
*offl = *offc = 0;
|
||||
@@ -234,7 +235,7 @@ void wrap_offset(
|
||||
while (linep) {
|
||||
start = 0;
|
||||
end = max;
|
||||
chop = 1;
|
||||
chop = true;
|
||||
*offc = 0;
|
||||
for (i = 0, j = 0; linep->line[j]; j += BLI_str_utf8_size_safe(linep->line + j)) {
|
||||
int chars;
|
||||
@@ -271,11 +272,11 @@ void wrap_offset(
|
||||
|
||||
start = end;
|
||||
end += max;
|
||||
chop = 1;
|
||||
chop = true;
|
||||
}
|
||||
else if (ELEM(ch, ' ', '-')) {
|
||||
end = i + 1;
|
||||
chop = 0;
|
||||
chop = false;
|
||||
if (linep == linein && i >= cursin) {
|
||||
return;
|
||||
}
|
||||
@@ -293,7 +294,8 @@ void wrap_offset(
|
||||
void wrap_offset_in_line(
|
||||
const SpaceText *st, ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
|
||||
{
|
||||
int i, j, start, end, chars, max, chop;
|
||||
int i, j, start, end, chars, max;
|
||||
bool chop;
|
||||
char ch;
|
||||
|
||||
*offl = *offc = 0;
|
||||
@@ -309,7 +311,7 @@ void wrap_offset_in_line(
|
||||
|
||||
start = 0;
|
||||
end = max;
|
||||
chop = 1;
|
||||
chop = true;
|
||||
*offc = 0;
|
||||
cursin = BLI_str_utf8_offset_to_column(linein->line, linein->len, cursin);
|
||||
|
||||
@@ -347,11 +349,11 @@ void wrap_offset_in_line(
|
||||
|
||||
start = end;
|
||||
end += max;
|
||||
chop = 1;
|
||||
chop = true;
|
||||
}
|
||||
else if (ELEM(ch, ' ', '-')) {
|
||||
end = i + 1;
|
||||
chop = 0;
|
||||
chop = false;
|
||||
if (i >= cursin) {
|
||||
return;
|
||||
}
|
||||
@@ -576,8 +578,8 @@ struct DrawCache {
|
||||
char cwidth_px;
|
||||
char text_id[MAX_ID_NAME];
|
||||
|
||||
/* for partial lines recalculation */
|
||||
short update_flag;
|
||||
/** For partial lines recalculation. */
|
||||
bool update;
|
||||
int valid_head, valid_tail; /* amount of unchanged lines */
|
||||
};
|
||||
|
||||
@@ -596,7 +598,8 @@ static void text_drawcache_init(SpaceText *st)
|
||||
static void text_update_drawcache(SpaceText *st, ARegion *region)
|
||||
{
|
||||
DrawCache *drawcache;
|
||||
int full_update = 0, nlines = 0;
|
||||
bool full_update = false;
|
||||
int nlines = 0;
|
||||
Text *txt = st->text;
|
||||
|
||||
if (st->runtime.drawcache == nullptr) {
|
||||
@@ -630,10 +633,10 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
|
||||
if (full_update || !drawcache->line_height) {
|
||||
drawcache->valid_head = 0;
|
||||
drawcache->valid_tail = 0;
|
||||
drawcache->update_flag = 1;
|
||||
drawcache->update = true;
|
||||
}
|
||||
|
||||
if (drawcache->update_flag) {
|
||||
if (drawcache->update) {
|
||||
TextLine *line = static_cast<TextLine *>(st->text->lines.first);
|
||||
int lineno = 0, size, lines_count;
|
||||
int *fp = drawcache->line_height, *new_tail, *old_tail;
|
||||
@@ -684,7 +687,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
|
||||
else {
|
||||
MEM_SAFE_FREE(drawcache->line_height);
|
||||
|
||||
if (full_update || drawcache->update_flag) {
|
||||
if (full_update || drawcache->update) {
|
||||
nlines = BLI_listbase_count(&txt->lines);
|
||||
|
||||
if (st->showlinenrs) {
|
||||
@@ -708,7 +711,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *region)
|
||||
STRNCPY(drawcache->text_id, txt->id.name);
|
||||
|
||||
/* clear update flag */
|
||||
drawcache->update_flag = 0;
|
||||
drawcache->update = false;
|
||||
drawcache->valid_head = 0;
|
||||
drawcache->valid_tail = 0;
|
||||
}
|
||||
@@ -724,7 +727,7 @@ void text_drawcache_tag_update(SpaceText *st, const bool full)
|
||||
DrawCache *drawcache = static_cast<DrawCache *>(st->runtime.drawcache);
|
||||
Text *txt = st->text;
|
||||
|
||||
if (drawcache->update_flag) {
|
||||
if (drawcache->update) {
|
||||
/* happens when tagging update from space listener */
|
||||
/* should do nothing to prevent locally tagged cache be fully recalculated */
|
||||
return;
|
||||
@@ -758,7 +761,7 @@ void text_drawcache_tag_update(SpaceText *st, const bool full)
|
||||
drawcache->valid_tail = 0;
|
||||
}
|
||||
|
||||
drawcache->update_flag = 1;
|
||||
drawcache->update = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1145,7 +1148,8 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
|
||||
static void draw_text_decoration(SpaceText *st, ARegion *region)
|
||||
{
|
||||
Text *text = st->text;
|
||||
int vcurl, vcurc, vsell, vselc, hidden = 0;
|
||||
int vcurl, vcurc, vsell, vselc;
|
||||
bool hidden = false;
|
||||
int x, y, w, i;
|
||||
int offl, offc;
|
||||
const int lheight = TXT_LINE_HEIGHT(st);
|
||||
@@ -1157,7 +1161,7 @@ static void draw_text_decoration(SpaceText *st, ARegion *region)
|
||||
|
||||
if (vselc < 0) {
|
||||
vselc = 0;
|
||||
hidden = 1;
|
||||
hidden = true;
|
||||
}
|
||||
|
||||
if (text->curl == text->sell && text->curc == text->selc && !st->line_hlight && hidden) {
|
||||
|
||||
@@ -909,11 +909,11 @@ static int text_refresh_pyconstraints_exec(bContext * /*C*/, wmOperator * /*op*/
|
||||
Text *text = CTX_data_edit_text(C);
|
||||
Object *ob;
|
||||
bConstraint *con;
|
||||
short update;
|
||||
bool update;
|
||||
|
||||
/* check all pyconstraints */
|
||||
for (ob = bmain->objects.first; ob; ob = ob->id.next) {
|
||||
update = 0;
|
||||
update = false;
|
||||
if (ob->type == OB_ARMATURE && ob->pose) {
|
||||
bPoseChannel *pchan;
|
||||
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
|
||||
@@ -923,7 +923,7 @@ static int text_refresh_pyconstraints_exec(bContext * /*C*/, wmOperator * /*op*/
|
||||
if (data->text == text) {
|
||||
BPY_pyconstraint_update(ob, con);
|
||||
}
|
||||
update = 1;
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -934,7 +934,7 @@ static int text_refresh_pyconstraints_exec(bContext * /*C*/, wmOperator * /*op*/
|
||||
if (data->text == text) {
|
||||
BPY_pyconstraint_update(ob, con);
|
||||
}
|
||||
update = 1;
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1752,14 +1752,15 @@ static const EnumPropertyItem move_type_items[] = {
|
||||
static int text_get_cursor_rel(
|
||||
SpaceText *st, ARegion *region, TextLine *linein, int rell, int relc)
|
||||
{
|
||||
int i, j, start, end, max, chop, curs, loop, endj, found, selc;
|
||||
int i, j, start, end, max, curs, endj, selc;
|
||||
bool chop, loop, found;
|
||||
char ch;
|
||||
|
||||
max = wrap_width(st, region);
|
||||
|
||||
selc = start = endj = curs = found = 0;
|
||||
selc = start = endj = curs = found = false;
|
||||
end = max;
|
||||
chop = loop = 1;
|
||||
chop = loop = true;
|
||||
|
||||
for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe(linein->line + j)) {
|
||||
int chars;
|
||||
@@ -1780,7 +1781,7 @@ static int text_get_cursor_rel(
|
||||
/* current position could be wrapped to next line */
|
||||
/* this should be checked when end of current line would be reached */
|
||||
selc = j;
|
||||
found = 1;
|
||||
found = true;
|
||||
}
|
||||
else if (i - end <= relc && i + columns - end > relc) {
|
||||
curs = j;
|
||||
@@ -1794,7 +1795,7 @@ static int text_get_cursor_rel(
|
||||
if (selc > endj && !chop) {
|
||||
selc = endj;
|
||||
}
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1804,12 +1805,12 @@ static int text_get_cursor_rel(
|
||||
|
||||
start = end;
|
||||
end += max;
|
||||
chop = 1;
|
||||
chop = true;
|
||||
rell--;
|
||||
|
||||
if (rell == 0 && i + columns - start > relc) {
|
||||
selc = curs;
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1817,23 +1818,23 @@ static int text_get_cursor_rel(
|
||||
if (!found) {
|
||||
selc = linein->len;
|
||||
}
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
else if (ELEM(ch, ' ', '-')) {
|
||||
if (found) {
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rell == 0 && i + columns - start > relc) {
|
||||
selc = curs;
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
end = i + 1;
|
||||
endj = j;
|
||||
chop = 0;
|
||||
chop = false;
|
||||
}
|
||||
i += columns;
|
||||
}
|
||||
@@ -1936,7 +1937,8 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
|
||||
Text *text = st->text;
|
||||
TextLine **linep;
|
||||
int *charp;
|
||||
int oldc, i, j, max, start, end, endj, chop, loop;
|
||||
int oldc, i, j, max, start, end, endj;
|
||||
bool chop, loop;
|
||||
char ch;
|
||||
|
||||
text_update_character_width(st);
|
||||
@@ -1956,7 +1958,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
|
||||
|
||||
start = endj = 0;
|
||||
end = max;
|
||||
chop = loop = 1;
|
||||
chop = loop = true;
|
||||
*charp = 0;
|
||||
|
||||
for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe((*linep)->line + j)) {
|
||||
@@ -1984,7 +1986,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
|
||||
*charp = BLI_str_utf8_offset_from_column_with_tabs(
|
||||
(*linep)->line, (*linep)->len, start, TXT_TABSIZE);
|
||||
}
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1994,19 +1996,19 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
|
||||
|
||||
start = end;
|
||||
end += max;
|
||||
chop = 1;
|
||||
chop = true;
|
||||
}
|
||||
else if (ELEM(ch, ' ', '-', '\0')) {
|
||||
if (j >= oldc) {
|
||||
*charp = BLI_str_utf8_offset_from_column_with_tabs(
|
||||
(*linep)->line, (*linep)->len, start, TXT_TABSIZE);
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
|
||||
end = i + 1;
|
||||
endj = j + 1;
|
||||
chop = 0;
|
||||
chop = false;
|
||||
}
|
||||
i += columns;
|
||||
}
|
||||
@@ -2022,7 +2024,8 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
|
||||
Text *text = st->text;
|
||||
TextLine **linep;
|
||||
int *charp;
|
||||
int oldc, i, j, max, start, end, endj, chop, loop;
|
||||
int oldc, i, j, max, start, end, endj;
|
||||
bool chop, loop;
|
||||
char ch;
|
||||
|
||||
text_update_character_width(st);
|
||||
@@ -2042,7 +2045,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
|
||||
|
||||
start = endj = 0;
|
||||
end = max;
|
||||
chop = loop = 1;
|
||||
chop = loop = true;
|
||||
*charp = 0;
|
||||
|
||||
for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe((*linep)->line + j)) {
|
||||
@@ -2074,23 +2077,23 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
|
||||
else {
|
||||
*charp = endj;
|
||||
}
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
|
||||
start = end;
|
||||
end += max;
|
||||
chop = 1;
|
||||
chop = true;
|
||||
}
|
||||
else if (ch == '\0') {
|
||||
*charp = (*linep)->len;
|
||||
loop = 0;
|
||||
loop = false;
|
||||
break;
|
||||
}
|
||||
else if (ELEM(ch, ' ', '-')) {
|
||||
end = i + 1;
|
||||
endj = j;
|
||||
chop = 0;
|
||||
chop = false;
|
||||
}
|
||||
i += columns;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user