Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_text/text_draw.c')
-rw-r--r--source/blender/editors/space_text/text_draw.c249
1 files changed, 137 insertions, 112 deletions
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index a8b141eff15..96fa9f87398 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -52,22 +52,22 @@
typedef struct TextDrawContext {
int font_id;
- int cwidth;
- int lheight_dpi;
+ int cwidth_px;
+ int lheight_px;
bool syntax_highlight;
} TextDrawContext;
static void text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
{
tdc->font_id = blf_mono_font;
- tdc->cwidth = 0;
- tdc->lheight_dpi = st->lheight_dpi;
+ tdc->cwidth_px = 0;
+ tdc->lheight_px = st->runtime.lheight_px;
tdc->syntax_highlight = st->showsyntax && ED_text_is_syntax_highlight_supported(st->text);
}
static void text_font_begin(const TextDrawContext *tdc)
{
- BLF_size(tdc->font_id, tdc->lheight_dpi, 72);
+ BLF_size(tdc->font_id, tdc->lheight_px, 72);
}
static void text_font_end(const TextDrawContext *UNUSED(tdc))
@@ -79,9 +79,9 @@ static int text_font_draw(const TextDrawContext *tdc, int x, int y, const char *
int columns;
BLF_position(tdc->font_id, x, y, 0);
- columns = BLF_draw_mono(tdc->font_id, str, BLF_DRAW_STR_DUMMY_MAX, tdc->cwidth);
+ columns = BLF_draw_mono(tdc->font_id, str, BLF_DRAW_STR_DUMMY_MAX, tdc->cwidth_px);
- return tdc->cwidth * columns;
+ return tdc->cwidth_px * columns;
}
static int text_font_draw_character(const TextDrawContext *tdc, int x, int y, char c)
@@ -89,7 +89,7 @@ static int text_font_draw_character(const TextDrawContext *tdc, int x, int y, ch
BLF_position(tdc->font_id, x, y, 0);
BLF_draw(tdc->font_id, &c, 1);
- return tdc->cwidth;
+ return tdc->cwidth_px;
}
static int text_font_draw_character_utf8(const TextDrawContext *tdc, int x, int y, const char *c)
@@ -98,9 +98,9 @@ static int text_font_draw_character_utf8(const TextDrawContext *tdc, int x, int
const size_t len = BLI_str_utf8_size_safe(c);
BLF_position(tdc->font_id, x, y, 0);
- columns = BLF_draw_mono(tdc->font_id, c, len, tdc->cwidth);
+ columns = BLF_draw_mono(tdc->font_id, c, len, tdc->cwidth_px);
- return tdc->cwidth * columns;
+ return tdc->cwidth_px * columns;
}
#if 0
@@ -193,7 +193,7 @@ int wrap_width(const SpaceText *st, ARegion *ar)
int x, max;
x = TXT_BODY_LEFT(st);
- max = st->cwidth ? (winx - x) / st->cwidth : 0;
+ max = st->runtime.cwidth_px ? (winx - x) / st->runtime.cwidth_px : 0;
return max > 8 ? max : 8;
}
@@ -429,11 +429,11 @@ static int text_draw_wrapped(const SpaceText *st,
int mi, ma, mstart, mend; /* mem */
char fmt_prev = 0xff;
/* don't draw lines below this */
- const int clip_min_y = -(int)(st->lheight_dpi - 1);
+ const int clip_min_y = -(int)(st->runtime.lheight_px - 1);
flatten_string(st, &fs, str);
str = fs.buf;
- max = w / st->cwidth;
+ max = w / st->runtime.cwidth_px;
if (max < 8) {
max = 8;
}
@@ -549,7 +549,7 @@ static void text_draw(const SpaceText *st,
return; /* String is shorter than shift or ends with a padding */
}
- x += tdc->cwidth * padding;
+ x += tdc->cwidth_px * padding;
if (use_syntax) {
int a, str_shift = 0;
@@ -579,7 +579,7 @@ typedef struct DrawCache {
/* this is needed to check cache relevance */
int winx, wordwrap, showlinenrs, tabnumber;
short lheight;
- char cwidth;
+ char cwidth_px;
char text_id[MAX_ID_NAME];
/* for partial lines recalculation */
@@ -595,7 +595,7 @@ static void text_drawcache_init(SpaceText *st)
drawcache->nlines = BLI_listbase_count(&st->text->lines);
drawcache->text_id[0] = '\0';
- st->drawcache = drawcache;
+ st->runtime.drawcache = drawcache;
}
static void text_update_drawcache(SpaceText *st, ARegion *ar)
@@ -604,13 +604,13 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
int full_update = 0, nlines = 0;
Text *txt = st->text;
- if (!st->drawcache) {
+ if (st->runtime.drawcache == NULL) {
text_drawcache_init(st);
}
text_update_character_width(st);
- drawcache = (DrawCache *)st->drawcache;
+ drawcache = st->runtime.drawcache;
nlines = drawcache->nlines;
/* check if full cache update is needed */
@@ -624,9 +624,9 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
/* word-wrapping option was toggled */
full_update |= drawcache->tabnumber != st->tabnumber;
/* word-wrapping option was toggled */
- full_update |= drawcache->lheight != st->lheight_dpi;
+ full_update |= drawcache->lheight != st->runtime.lheight_px;
/* word-wrapping option was toggled */
- full_update |= drawcache->cwidth != st->cwidth;
+ full_update |= drawcache->cwidth_px != st->runtime.cwidth_px;
/* text datablock was changed */
full_update |= !STREQLEN(drawcache->text_id, txt->id.name, MAX_ID_NAME);
@@ -661,7 +661,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
drawcache->total_lines = 0;
if (st->showlinenrs) {
- st->linenrs_tot = integer_digits_i(nlines);
+ st->runtime.line_number_display_digits = integer_digits_i(nlines);
}
while (line) {
@@ -696,7 +696,7 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
nlines = BLI_listbase_count(&txt->lines);
if (st->showlinenrs) {
- st->linenrs_tot = integer_digits_i(nlines);
+ st->runtime.line_number_display_digits = integer_digits_i(nlines);
}
}
@@ -708,8 +708,8 @@ static void text_update_drawcache(SpaceText *st, ARegion *ar)
/* store settings */
drawcache->winx = ar->winx;
drawcache->wordwrap = st->wordwrap;
- drawcache->lheight = st->lheight_dpi;
- drawcache->cwidth = st->cwidth;
+ drawcache->lheight = st->runtime.lheight_px;
+ drawcache->cwidth_px = st->runtime.cwidth_px;
drawcache->showlinenrs = st->showlinenrs;
drawcache->tabnumber = st->tabnumber;
@@ -728,8 +728,8 @@ void text_drawcache_tag_update(SpaceText *st, int full)
return;
}
- if (st->drawcache) {
- DrawCache *drawcache = (DrawCache *)st->drawcache;
+ if (st->runtime.drawcache != NULL) {
+ DrawCache *drawcache = st->runtime.drawcache;
Text *txt = st->text;
if (drawcache->update_flag) {
@@ -772,7 +772,7 @@ void text_drawcache_tag_update(SpaceText *st, int full)
void text_free_caches(SpaceText *st)
{
- DrawCache *drawcache = (DrawCache *)st->drawcache;
+ DrawCache *drawcache = st->runtime.drawcache;
if (drawcache) {
if (drawcache->line_height) {
@@ -788,7 +788,7 @@ void text_free_caches(SpaceText *st)
/* cache should be updated in caller */
static int text_get_visible_lines_no(const SpaceText *st, int lineno)
{
- const DrawCache *drawcache = st->drawcache;
+ const DrawCache *drawcache = st->runtime.drawcache;
return drawcache->line_height[lineno];
}
@@ -859,7 +859,7 @@ int text_get_total_lines(SpaceText *st, ARegion *ar)
DrawCache *drawcache;
text_update_drawcache(st, ar);
- drawcache = st->drawcache;
+ drawcache = st->runtime.drawcache;
return drawcache->total_lines;
}
@@ -876,7 +876,7 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
pix_bottom_margin = (0.4 * U.widget_unit);
pix_available = ar->winy - pix_top_margin - pix_bottom_margin;
ltexth = text_get_total_lines(st, ar);
- blank_lines = st->viewlines / 2;
+ blank_lines = st->runtime.viewlines / 2;
/* nicer code: use scroll rect for entire bar */
back->xmin = ar->winx - (0.6 * U.widget_unit);
@@ -891,13 +891,13 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
/* when re-sizing a view-port with the bar at the bottom to a greater height
* more blank lines will be added */
- if (ltexth + blank_lines < st->top + st->viewlines) {
- blank_lines = st->top + st->viewlines - ltexth;
+ if (ltexth + blank_lines < st->top + st->runtime.viewlines) {
+ blank_lines = st->top + st->runtime.viewlines - ltexth;
}
ltexth += blank_lines;
- barheight = (ltexth > 0) ? (st->viewlines * pix_available) / ltexth : 0;
+ barheight = (ltexth > 0) ? (st->runtime.viewlines * pix_available) / ltexth : 0;
pix_bardiff = 0;
if (barheight < 20) {
pix_bardiff = 20 - barheight; /* take into account the now non-linear sizing of the bar */
@@ -905,16 +905,16 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
}
barstart = (ltexth > 0) ? ((pix_available - pix_bardiff) * st->top) / ltexth : 0;
- st->txtbar = *scroll;
- st->txtbar.ymax -= barstart;
- st->txtbar.ymin = st->txtbar.ymax - barheight;
+ st->runtime.scroll_region_handle = *scroll;
+ st->runtime.scroll_region_handle.ymax -= barstart;
+ st->runtime.scroll_region_handle.ymin = st->runtime.scroll_region_handle.ymax - barheight;
- CLAMP(st->txtbar.ymin, pix_bottom_margin, ar->winy - pix_top_margin);
- CLAMP(st->txtbar.ymax, pix_bottom_margin, ar->winy - pix_top_margin);
+ CLAMP(st->runtime.scroll_region_handle.ymin, pix_bottom_margin, ar->winy - pix_top_margin);
+ CLAMP(st->runtime.scroll_region_handle.ymax, pix_bottom_margin, ar->winy - pix_top_margin);
- st->pix_per_line = (pix_available > 0) ? (float)ltexth / pix_available : 0;
- if (st->pix_per_line < 0.1f) {
- st->pix_per_line = 0.1f;
+ st->runtime.scroll_px_per_line = (pix_available > 0) ? (float)ltexth / pix_available : 0;
+ if (st->runtime.scroll_px_per_line < 0.1f) {
+ st->runtime.scroll_px_per_line = 0.1f;
}
curl_off = text_get_span_wrap(st, ar, st->text->lines.first, st->text->curl);
@@ -929,12 +929,13 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
/* the scrollbar is non-linear sized */
if (pix_bardiff > 0) {
/* the start of the highlight is in the current viewport */
- if (st->viewlines && lhlstart >= st->top && lhlstart <= st->top + st->viewlines) {
+ if (st->runtime.viewlines && lhlstart >= st->top &&
+ lhlstart <= st->top + st->runtime.viewlines) {
/* speed the progresion of the start of the highlight through the scrollbar */
hlstart = (((pix_available - pix_bardiff) * lhlstart) / ltexth) +
- (pix_bardiff * (lhlstart - st->top) / st->viewlines);
+ (pix_bardiff * (lhlstart - st->top) / st->runtime.viewlines);
}
- else if (lhlstart > st->top + st->viewlines && hlstart < barstart + barheight &&
+ else if (lhlstart > st->top + st->runtime.viewlines && hlstart < barstart + barheight &&
hlstart > barstart) {
/* push hl start down */
hlstart = barstart + barheight;
@@ -949,17 +950,18 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
}
/* the end of the highlight is in the current viewport */
- if (st->viewlines && lhlend >= st->top && lhlend <= st->top + st->viewlines) {
+ if (st->runtime.viewlines && lhlend >= st->top &&
+ lhlend <= st->top + st->runtime.viewlines) {
/* speed the progresion of the end of the highlight through the scrollbar */
hlend = (((pix_available - pix_bardiff) * lhlend) / ltexth) +
- (pix_bardiff * (lhlend - st->top) / st->viewlines);
+ (pix_bardiff * (lhlend - st->top) / st->runtime.viewlines);
}
else if (lhlend < st->top && hlend >= barstart - 2 && hlend < barstart + barheight) {
/* push hl end up */
hlend = barstart;
}
- else if (lhlend > st->top + st->viewlines && lhlstart < st->top + st->viewlines &&
- hlend < barstart + barheight) {
+ else if (lhlend > st->top + st->runtime.viewlines &&
+ lhlstart < st->top + st->runtime.viewlines && hlend < barstart + barheight) {
/* fill out end */
hlend = barstart + barheight;
}
@@ -978,12 +980,12 @@ static void calc_text_rcts(SpaceText *st, ARegion *ar, rcti *scroll, rcti *back)
hlend = hlstart + 2;
}
- st->txtscroll = *scroll;
- st->txtscroll.ymax = ar->winy - pix_top_margin - hlstart;
- st->txtscroll.ymin = ar->winy - pix_top_margin - hlend;
+ st->runtime.scroll_region_select = *scroll;
+ st->runtime.scroll_region_select.ymax = ar->winy - pix_top_margin - hlstart;
+ st->runtime.scroll_region_select.ymin = ar->winy - pix_top_margin - hlend;
- CLAMP(st->txtscroll.ymin, pix_bottom_margin, ar->winy - pix_top_margin);
- CLAMP(st->txtscroll.ymax, pix_bottom_margin, ar->winy - pix_top_margin);
+ CLAMP(st->runtime.scroll_region_select.ymin, pix_bottom_margin, ar->winy - pix_top_margin);
+ CLAMP(st->runtime.scroll_region_select.ymax, pix_bottom_margin, ar->winy - pix_top_margin);
}
static void draw_textscroll(const SpaceText *st, rcti *scroll, rcti *back)
@@ -1001,18 +1003,21 @@ static void draw_textscroll(const SpaceText *st, rcti *scroll, rcti *back)
immRecti(pos, back->xmin, back->ymin, back->xmax, back->ymax);
immUnbindProgram();
- UI_draw_widget_scroll(
- &wcol, scroll, &st->txtbar, (st->flags & ST_SCROLL_SELECT) ? UI_SCROLL_PRESSED : 0);
+ UI_draw_widget_scroll(&wcol,
+ scroll,
+ &st->runtime.scroll_region_handle,
+ (st->flags & ST_SCROLL_SELECT) ? UI_SCROLL_PRESSED : 0);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- rad = 0.4f * min_ii(BLI_rcti_size_x(&st->txtscroll), BLI_rcti_size_y(&st->txtscroll));
+ rad = 0.4f * min_ii(BLI_rcti_size_x(&st->runtime.scroll_region_select),
+ BLI_rcti_size_y(&st->runtime.scroll_region_select));
UI_GetThemeColor3fv(TH_HILITE, col);
col[3] = 0.18f;
UI_draw_roundbox_aa(true,
- st->txtscroll.xmin + 1,
- st->txtscroll.ymin,
- st->txtscroll.xmax - 1,
- st->txtscroll.ymax,
+ st->runtime.scroll_region_select.xmin + 1,
+ st->runtime.scroll_region_select.ymin,
+ st->runtime.scroll_region_select.xmax - 1,
+ st->runtime.scroll_region_select.ymax,
rad,
col);
}
@@ -1052,13 +1057,13 @@ static void draw_documentation(const SpaceText *st, ARegion *ar)
return;
}
- x = TXT_BODY_LEFT(st) + (st->cwidth * (st->text->curc - st->left));
+ x = TXT_BODY_LEFT(st) + (st->runtime.cwidth_px * (st->text->curc - st->left));
if (texttool_suggest_first()) {
- x += SUGG_LIST_WIDTH * st->cwidth + 50;
+ x += SUGG_LIST_WIDTH * st->runtime.cwidth_px + 50;
}
- /* top = */ /* UNUSED */ y = ar->winy - st->lheight_dpi * l - 2;
- boxw = DOC_WIDTH * st->cwidth + 20;
+ /* top = */ /* UNUSED */ y = ar->winy - st->runtime.lheight_px * l - 2;
+ boxw = DOC_WIDTH * st->runtime.cwidth_px + 20;
boxh = (DOC_HEIGHT + 1) * TXT_LINE_HEIGHT(st);
/* Draw panel */
@@ -1103,7 +1108,7 @@ static void draw_documentation(const SpaceText *st, ARegion *ar)
else if (*p == '\n') {
buf[i] = '\0';
if (lines >= 0) {
- y -= st->lheight_dpi;
+ y -= st->runtime.lheight_px;
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, NULL);
}
i = 0;
@@ -1114,7 +1119,7 @@ static void draw_documentation(const SpaceText *st, ARegion *ar)
if (i == DOC_WIDTH) { /* Reached the width, go to last break and wrap there */
buf[br] = '\0';
if (lines >= 0) {
- y -= st->lheight_dpi;
+ y -= st->runtime.lheight_px;
text_draw(st, &tdc, buf, 0, 0, x + 4, y - 3, NULL);
}
p -= i - br - 1; /* Rewind pointer to last break */
@@ -1162,15 +1167,15 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
vcurl = txt_get_span(st->text->lines.first, st->text->curl) - st->top + offl;
vcurc = text_get_char_pos(st, st->text->curl->line, st->text->curc) - st->left + offc;
- x = TXT_BODY_LEFT(st) + (vcurc * st->cwidth);
+ x = TXT_BODY_LEFT(st) + (vcurc * st->runtime.cwidth_px);
y = ar->winy - (vcurl + 1) * lheight - 2;
/* offset back so the start of the text lines up with the suggestions,
* not essential but makes suggestions easier to follow */
- x -= st->cwidth *
+ x -= st->runtime.cwidth_px *
(st->text->curc - text_find_identifier_start(st->text->curl->line, st->text->curc));
- boxw = SUGG_LIST_WIDTH * st->cwidth + 20;
+ boxw = SUGG_LIST_WIDTH * st->runtime.cwidth_px + 20;
boxh = SUGG_LIST_SIZE * lheight + 8;
if (x + boxw > ar->winx) {
@@ -1203,7 +1208,7 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
BLI_strncpy(str, item->name, len + 1);
- w = st->cwidth * text_get_char_pos(st, str, len);
+ w = st->runtime.cwidth_px * text_get_char_pos(st, str, len);
if (item == sel) {
uint posi = GPU_vertformat_attr_add(
@@ -1270,17 +1275,25 @@ static void draw_text_decoration(SpaceText *st, ARegion *ar)
x = TXT_BODY_LEFT(st);
y = ar->winy;
if (st->flags & ST_SCROLL_SELECT) {
- y += st->scroll_ofs_px[1];
+ y += st->runtime.scroll_ofs_px[1];
}
if (vcurl == vsell) {
y -= vcurl * lheight;
if (vcurc < vselc) {
- immRecti(pos, x + vcurc * st->cwidth, y, x + vselc * st->cwidth, y - lheight);
+ immRecti(pos,
+ x + vcurc * st->runtime.cwidth_px,
+ y,
+ x + vselc * st->runtime.cwidth_px,
+ y - lheight);
}
else {
- immRecti(pos, x + vselc * st->cwidth, y, x + vcurc * st->cwidth, y - lheight);
+ immRecti(pos,
+ x + vselc * st->runtime.cwidth_px,
+ y,
+ x + vcurc * st->runtime.cwidth_px,
+ y - lheight);
}
}
else {
@@ -1301,7 +1314,7 @@ static void draw_text_decoration(SpaceText *st, ARegion *ar)
y -= froml * lheight;
- immRecti(pos, x + fromc * st->cwidth - U.pixelsize, y, ar->winx, y - lheight);
+ immRecti(pos, x + fromc * st->runtime.cwidth_px - U.pixelsize, y, ar->winx, y - lheight);
y -= lheight;
for (i = froml + 1; i < tol; i++) {
@@ -1309,8 +1322,8 @@ static void draw_text_decoration(SpaceText *st, ARegion *ar)
y -= lheight;
}
- if (x + toc * st->cwidth > x) {
- immRecti(pos, x - U.pixelsize, y, x + toc * st->cwidth, y - lheight);
+ if (x + toc * st->runtime.cwidth_px > x) {
+ immRecti(pos, x - U.pixelsize, y, x + toc * st->runtime.cwidth_px, y - lheight);
}
y -= lheight;
}
@@ -1347,10 +1360,10 @@ static void draw_text_decoration(SpaceText *st, ARegion *ar)
if (!hidden) {
/* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */
- x = TXT_BODY_LEFT(st) + (vselc * st->cwidth);
+ x = TXT_BODY_LEFT(st) + (vselc * st->runtime.cwidth_px);
y = ar->winy - vsell * lheight;
if (st->flags & ST_SCROLL_SELECT) {
- y += st->scroll_ofs_px[1];
+ y += st->runtime.scroll_ofs_px[1];
}
immUniformThemeColor(TH_HILITE);
@@ -1359,7 +1372,7 @@ static void draw_text_decoration(SpaceText *st, ARegion *ar)
char ch = text->sell->line[text->selc];
y += TXT_LINE_SPACING(st);
- w = st->cwidth;
+ w = st->runtime.cwidth_px;
if (ch == '\t') {
w *= st->tabnumber - (vselc + st->left) % st->tabnumber;
}
@@ -1502,9 +1515,9 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
UI_FontThemeColor(tdc->font_id, TH_HILITE);
x = TXT_BODY_LEFT(st);
- y = ar->winy - st->lheight_dpi;
+ y = ar->winy - st->runtime.lheight_px;
if (st->flags & ST_SCROLL_SELECT) {
- y += st->scroll_ofs_px[1];
+ y += st->runtime.scroll_ofs_px[1];
}
/* draw opening bracket */
@@ -1515,8 +1528,10 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
if (viewc >= 0) {
viewl = txt_get_span(text->lines.first, startl) - st->top + offl;
- text_font_draw_character(tdc, x + viewc * st->cwidth, y - viewl * TXT_LINE_HEIGHT(st), ch);
- text_font_draw_character(tdc, x + viewc * st->cwidth + 1, y - viewl * TXT_LINE_HEIGHT(st), ch);
+ text_font_draw_character(
+ tdc, x + viewc * st->runtime.cwidth_px, y - viewl * TXT_LINE_HEIGHT(st), ch);
+ text_font_draw_character(
+ tdc, x + viewc * st->runtime.cwidth_px + 1, y - viewl * TXT_LINE_HEIGHT(st), ch);
}
/* draw closing bracket */
@@ -1527,8 +1542,10 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
if (viewc >= 0) {
viewl = txt_get_span(text->lines.first, endl) - st->top + offl;
- text_font_draw_character(tdc, x + viewc * st->cwidth, y - viewl * TXT_LINE_HEIGHT(st), ch);
- text_font_draw_character(tdc, x + viewc * st->cwidth + 1, y - viewl * TXT_LINE_HEIGHT(st), ch);
+ text_font_draw_character(
+ tdc, x + viewc * st->runtime.cwidth_px, y - viewl * TXT_LINE_HEIGHT(st), ch);
+ text_font_draw_character(
+ tdc, x + viewc * st->runtime.cwidth_px + 1, y - viewl * TXT_LINE_HEIGHT(st), ch);
}
}
@@ -1552,12 +1569,14 @@ void draw_text_main(SpaceText *st, ARegion *ar)
}
/* dpi controlled line height and font size */
- st->lheight_dpi = (U.widget_unit * st->lheight) / 20;
+ st->runtime.lheight_px = (U.widget_unit * st->lheight) / 20;
/* don't draw lines below this */
- const int clip_min_y = -(int)(st->lheight_dpi - 1);
+ const int clip_min_y = -(int)(st->runtime.lheight_px - 1);
- st->viewlines = (st->lheight_dpi) ? (int)(ar->winy - clip_min_y) / TXT_LINE_HEIGHT(st) : 0;
+ st->runtime.viewlines = (st->runtime.lheight_px) ?
+ (int)(ar->winy - clip_min_y) / TXT_LINE_HEIGHT(st) :
+ 0;
text_draw_context_init(st, &tdc);
@@ -1603,8 +1622,8 @@ void draw_text_main(SpaceText *st, ARegion *ar)
text_font_begin(&tdc);
- tdc.cwidth = max_ii((int)BLF_fixed_width(tdc.font_id), 1);
- st->cwidth = tdc.cwidth;
+ tdc.cwidth_px = max_ii((int)BLF_fixed_width(tdc.font_id), 1);
+ st->runtime.cwidth_px = tdc.cwidth_px;
/* draw line numbers background */
if (st->showlinenrs) {
@@ -1616,14 +1635,14 @@ void draw_text_main(SpaceText *st, ARegion *ar)
immUnbindProgram();
}
else {
- st->linenrs_tot = 0; /* not used */
+ st->runtime.line_number_display_digits = 0; /* not used */
}
x = TXT_BODY_LEFT(st);
- y = ar->winy - st->lheight_dpi;
- int viewlines = st->viewlines;
+ y = ar->winy - st->runtime.lheight_px;
+ int viewlines = st->runtime.viewlines;
if (st->flags & ST_SCROLL_SELECT) {
- y += st->scroll_ofs_px[1];
+ y += st->runtime.scroll_ofs_px[1];
viewlines += 1;
}
@@ -1649,9 +1668,13 @@ void draw_text_main(SpaceText *st, ARegion *ar)
UI_FontThemeColor(tdc.font_id, TH_LINENUMBERS);
}
- BLI_snprintf(linenr, sizeof(linenr), "%*d", st->linenrs_tot, i + linecount + 1);
+ BLI_snprintf(linenr,
+ sizeof(linenr),
+ "%*d",
+ st->runtime.line_number_display_digits,
+ i + linecount + 1);
/* itoa(i + linecount + 1, linenr, 10); */ /* not ansi-c :/ */
- text_font_draw(&tdc, TXT_NUMCOL_PAD * st->cwidth, y, linenr);
+ text_font_draw(&tdc, TXT_NUMCOL_PAD * st->runtime.cwidth_px, y, linenr);
if (tmp == text->curl) {
UI_FontThemeColor(tdc.font_id, TH_TEXT);
@@ -1665,7 +1688,8 @@ void draw_text_main(SpaceText *st, ARegion *ar)
}
else {
/* draw unwrapped text */
- text_draw(st, &tdc, tmp->line, st->left, ar->winx / st->cwidth, x, y, tmp->format);
+ text_draw(
+ st, &tdc, tmp->line, st->left, ar->winx / st->runtime.cwidth_px, x, y, tmp->format);
y -= TXT_LINE_HEIGHT(st);
}
@@ -1673,7 +1697,7 @@ void draw_text_main(SpaceText *st, ARegion *ar)
}
if (st->flags & ST_SHOW_MARGIN) {
- margin_column_x = x + st->cwidth * (st->margin_column - st->left);
+ margin_column_x = x + st->runtime.cwidth_px * (st->margin_column - st->left);
if (margin_column_x >= x) {
uint pos = GPU_vertformat_attr_add(
immVertexFormat(), "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT);
@@ -1707,8 +1731,8 @@ void text_update_character_width(SpaceText *st)
text_draw_context_init(st, &tdc);
text_font_begin(&tdc);
- st->cwidth = BLF_fixed_width(tdc.font_id);
- st->cwidth = MAX2(st->cwidth, (char)1);
+ st->runtime.cwidth_px = BLF_fixed_width(tdc.font_id);
+ st->runtime.cwidth_px = MAX2(st->runtime.cwidth_px, (char)1);
text_font_end(&tdc);
}
@@ -1735,13 +1759,13 @@ void text_scroll_to_cursor(SpaceText *st, ARegion *ar, const bool center)
}
if (center) {
- if (st->top + st->viewlines <= i || st->top > i) {
- st->top = i - st->viewlines / 2;
+ if (st->top + st->runtime.viewlines <= i || st->top > i) {
+ st->top = i - st->runtime.viewlines / 2;
}
}
else {
- if (st->top + st->viewlines <= i) {
- st->top = i - (st->viewlines - 1);
+ if (st->top + st->runtime.viewlines <= i) {
+ st->top = i - (st->runtime.viewlines - 1);
}
else if (st->top > i) {
st->top = i;
@@ -1752,20 +1776,20 @@ void text_scroll_to_cursor(SpaceText *st, ARegion *ar, const bool center)
st->left = 0;
}
else {
- x = st->cwidth * (text_get_char_pos(st, text->sell->line, text->selc) - st->left);
+ x = st->runtime.cwidth_px * (text_get_char_pos(st, text->sell->line, text->selc) - st->left);
winx -= TXT_BODY_LEFT(st) + TXT_SCROLL_WIDTH;
if (center) {
if (x <= 0 || x > winx) {
- st->left += (x - winx / 2) / st->cwidth;
+ st->left += (x - winx / 2) / st->runtime.cwidth_px;
}
}
else {
if (x <= 0) {
- st->left += ((x + 1) / st->cwidth) - 1;
+ st->left += ((x + 1) / st->runtime.cwidth_px) - 1;
}
else if (x > winx) {
- st->left += ((x - (winx + 1)) / st->cwidth) + 1;
+ st->left += ((x - (winx + 1)) / st->runtime.cwidth_px) + 1;
}
}
}
@@ -1777,8 +1801,8 @@ void text_scroll_to_cursor(SpaceText *st, ARegion *ar, const bool center)
st->left = 0;
}
- st->scroll_ofs_px[0] = 0;
- st->scroll_ofs_px[1] = 0;
+ st->runtime.scroll_ofs_px[0] = 0;
+ st->runtime.scroll_ofs_px[1] = 0;
}
/* takes an area instead of a region, use for listeners */
@@ -1830,9 +1854,10 @@ bool ED_text_region_location_from_cursor(SpaceText *st,
int char_pos = text_get_char_pos(st, line->line, cursor_co[1]);
wrap_offset(st, ar, line, cursor_co[1], &offl, &offc);
- r_pixel_co[0] = (char_pos + offc - st->left) * st->cwidth + linenr_offset;
+ r_pixel_co[0] = (char_pos + offc - st->left) * st->runtime.cwidth_px + linenr_offset;
r_pixel_co[1] = (cursor_co[0] + offl - st->top) * TXT_LINE_HEIGHT(st);
- r_pixel_co[1] = (ar->winy - (r_pixel_co[1] + (TXT_BODY_LPAD * st->cwidth))) - st->lheight_dpi;
+ r_pixel_co[1] = (ar->winy - (r_pixel_co[1] + (TXT_BODY_LPAD * st->runtime.cwidth_px))) -
+ st->runtime.lheight_px;
}
return true;