Cleanup: move space text vars into a runtime struct
Also use more descriptive names.
This commit is contained in:
@@ -7376,10 +7376,7 @@ static void direct_link_area(FileData *fd, ScrArea *area)
|
||||
}
|
||||
else if (sl->spacetype == SPACE_TEXT) {
|
||||
SpaceText *st = (SpaceText *)sl;
|
||||
|
||||
st->drawcache = NULL;
|
||||
st->scroll_ofs_px[0] = 0;
|
||||
st->scroll_ofs_px[1] = 0;
|
||||
memset(&st->runtime, 0, sizeof(st->runtime));
|
||||
}
|
||||
else if (sl->spacetype == SPACE_SEQ) {
|
||||
SpaceSeq *sseq = (SpaceSeq *)sl;
|
||||
|
||||
@@ -117,7 +117,7 @@ static SpaceLink *text_duplicate(SpaceLink *sl)
|
||||
|
||||
/* clear or remove stuff from old */
|
||||
|
||||
stextn->drawcache = NULL; /* space need it's own cache */
|
||||
stextn->runtime.drawcache = NULL; /* space need it's own cache */
|
||||
|
||||
return (SpaceLink *)stextn;
|
||||
}
|
||||
@@ -314,8 +314,9 @@ static void text_cursor(wmWindow *win, ScrArea *sa, ARegion *ar)
|
||||
SpaceText *st = sa->spacedata.first;
|
||||
int wmcursor = WM_CURSOR_TEXT_EDIT;
|
||||
|
||||
if (st->text &&
|
||||
BLI_rcti_isect_pt(&st->txtbar, win->eventstate->x - ar->winrct.xmin, st->txtbar.ymin)) {
|
||||
if (st->text && BLI_rcti_isect_pt(&st->runtime.scroll_region_handle,
|
||||
win->eventstate->x - ar->winrct.xmin,
|
||||
st->runtime.scroll_region_handle.ymin)) {
|
||||
wmcursor = WM_CURSOR_DEFAULT;
|
||||
}
|
||||
|
||||
|
||||
@@ -83,11 +83,11 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
|
||||
|
||||
text_update_character_width(st);
|
||||
|
||||
x = TXT_BODY_LEFT(st) + (st->cwidth * (st->text->curc - st->left));
|
||||
y = ar->winy - st->lheight_dpi * l - 2;
|
||||
x = TXT_BODY_LEFT(st) + (st->runtime.cwidth_px * (st->text->curc - st->left));
|
||||
y = ar->winy - st->runtime.lheight_px * l - 2;
|
||||
|
||||
w = SUGG_LIST_WIDTH * st->cwidth + U.widget_unit;
|
||||
h = SUGG_LIST_SIZE * st->lheight_dpi + 0.4f * U.widget_unit;
|
||||
w = SUGG_LIST_WIDTH * st->runtime.cwidth_px + U.widget_unit;
|
||||
h = SUGG_LIST_SIZE * st->runtime.lheight_px + 0.4f * U.widget_unit;
|
||||
|
||||
// XXX getmouseco_areawin(mval);
|
||||
|
||||
@@ -101,7 +101,7 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
|
||||
}
|
||||
|
||||
/* Work out the target item index in the visible list */
|
||||
tgti = (y - mval[1] - 4) / st->lheight_dpi;
|
||||
tgti = (y - mval[1] - 4) / st->runtime.lheight_px;
|
||||
if (tgti < 0 || tgti > SUGG_LIST_SIZE) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -47,13 +47,14 @@ void text_update_cursor_moved(struct bContext *C);
|
||||
/* Padding around line numbers in character widths. */
|
||||
#define TXT_NUMCOL_PAD 1.0f
|
||||
/* Total width of the optional line numbers column. */
|
||||
#define TXT_NUMCOL_WIDTH(st) (st->cwidth * (st->linenrs_tot + (2 * TXT_NUMCOL_PAD)))
|
||||
#define TXT_NUMCOL_WIDTH(st) \
|
||||
(st->runtime.cwidth_px * (st->runtime.line_number_display_digits + (2 * TXT_NUMCOL_PAD)))
|
||||
|
||||
/* Padding on left of body text in character units. */
|
||||
#define TXT_BODY_LPAD 1.0f
|
||||
/* Left position of body text. */
|
||||
#define TXT_BODY_LEFT(st) \
|
||||
(st->showlinenrs ? TXT_NUMCOL_WIDTH(st) : 0) + (TXT_BODY_LPAD * st->cwidth)
|
||||
(st->showlinenrs ? TXT_NUMCOL_WIDTH(st) : 0) + (TXT_BODY_LPAD * st->runtime.cwidth_px)
|
||||
|
||||
#define TXT_SCROLL_WIDTH U.widget_unit
|
||||
#define TXT_SCROLL_SPACE ((int)(0.1f * U.widget_unit))
|
||||
@@ -61,9 +62,9 @@ void text_update_cursor_moved(struct bContext *C);
|
||||
/* Space between lines, in relation to letter height. */
|
||||
#define TXT_LINE_VPAD 0.3f
|
||||
/* Space between lines. */
|
||||
#define TXT_LINE_SPACING(st) ((int)(TXT_LINE_VPAD * st->lheight_dpi))
|
||||
#define TXT_LINE_SPACING(st) ((int)(TXT_LINE_VPAD * st->runtime.lheight_px))
|
||||
/* Total height of each line. */
|
||||
#define TXT_LINE_HEIGHT(st) ((int)((1.0f + TXT_LINE_VPAD) * st->lheight_dpi))
|
||||
#define TXT_LINE_HEIGHT(st) ((int)((1.0f + TXT_LINE_VPAD) * st->runtime.lheight_px))
|
||||
|
||||
#define SUGG_LIST_SIZE 7
|
||||
#define SUGG_LIST_WIDTH 20
|
||||
|
||||
@@ -143,7 +143,7 @@ static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size)
|
||||
BLI_INLINE int text_pixel_x_to_column(SpaceText *st, const int x)
|
||||
{
|
||||
/* Add half the char width so mouse cursor selection is in between letters. */
|
||||
return (x + (st->cwidth / 2)) / st->cwidth;
|
||||
return (x + (st->runtime.cwidth_px / 2)) / st->runtime.cwidth_px;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
@@ -270,8 +270,8 @@ static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
st->text = text;
|
||||
st->left = 0;
|
||||
st->top = 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;
|
||||
text_drawcache_tag_update(st, 1);
|
||||
}
|
||||
|
||||
@@ -353,8 +353,8 @@ static int text_open_exec(bContext *C, wmOperator *op)
|
||||
st->text = text;
|
||||
st->left = 0;
|
||||
st->top = 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;
|
||||
}
|
||||
|
||||
text_drawcache_tag_update(st, 1);
|
||||
@@ -2206,7 +2206,7 @@ static int text_move_cursor(bContext *C, int type, bool select)
|
||||
|
||||
case PREV_PAGE:
|
||||
if (st) {
|
||||
cursor_skip(st, ar, st->text, -st->viewlines, select);
|
||||
cursor_skip(st, ar, st->text, -st->runtime.viewlines, select);
|
||||
}
|
||||
else {
|
||||
cursor_skip(NULL, NULL, text, -10, select);
|
||||
@@ -2215,7 +2215,7 @@ static int text_move_cursor(bContext *C, int type, bool select)
|
||||
|
||||
case NEXT_PAGE:
|
||||
if (st) {
|
||||
cursor_skip(st, ar, st->text, st->viewlines, select);
|
||||
cursor_skip(st, ar, st->text, st->runtime.viewlines, select);
|
||||
}
|
||||
else {
|
||||
cursor_skip(NULL, NULL, text, 10, select);
|
||||
@@ -2497,7 +2497,7 @@ static void txt_screen_clamp(SpaceText *st, ARegion *ar)
|
||||
else {
|
||||
int last;
|
||||
last = text_get_total_lines(st, ar);
|
||||
last = last - (st->viewlines / 2);
|
||||
last = last - (st->runtime.viewlines / 2);
|
||||
if (last > 0 && st->top > last) {
|
||||
st->top = last;
|
||||
}
|
||||
@@ -2544,9 +2544,9 @@ static void text_scroll_state_init(TextScroll *tsc, SpaceText *st, ARegion *ar)
|
||||
tsc->state.ofs_init[1] = st->top;
|
||||
|
||||
tsc->state.ofs_max[0] = INT_MAX;
|
||||
tsc->state.ofs_max[1] = text_get_total_lines(st, ar) - (st->viewlines / 2);
|
||||
tsc->state.ofs_max[1] = text_get_total_lines(st, ar) - (st->runtime.viewlines / 2);
|
||||
|
||||
tsc->state.size_px[0] = st->cwidth;
|
||||
tsc->state.size_px[0] = st->runtime.cwidth_px;
|
||||
tsc->state.size_px[1] = TXT_LINE_HEIGHT(st);
|
||||
}
|
||||
|
||||
@@ -2602,7 +2602,8 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
tsc->ofs_delta_px[1] += tsc->mval_delta[1];
|
||||
}
|
||||
else {
|
||||
tsc->ofs_delta_px[1] -= (tsc->mval_delta[1] * st->pix_per_line) * tsc->state.size_px[1];
|
||||
tsc->ofs_delta_px[1] -= (tsc->mval_delta[1] * st->runtime.scroll_px_per_line) *
|
||||
tsc->state.size_px[1];
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i += 1) {
|
||||
@@ -2651,12 +2652,12 @@ static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
if (scroll_ofs_new[0] != st->left || scroll_ofs_new[1] != st->top ||
|
||||
/* Horizontal sub-pixel offset currently isn't used. */
|
||||
/* scroll_ofs_px_new[0] != st->scroll_ofs_px[0] || */
|
||||
scroll_ofs_px_new[1] != st->scroll_ofs_px[1]) {
|
||||
scroll_ofs_px_new[1] != st->runtime.scroll_ofs_px[1]) {
|
||||
|
||||
st->left = scroll_ofs_new[0];
|
||||
st->top = scroll_ofs_new[1];
|
||||
st->scroll_ofs_px[0] = scroll_ofs_px_new[0];
|
||||
st->scroll_ofs_px[1] = scroll_ofs_px_new[1];
|
||||
st->runtime.scroll_ofs_px[0] = scroll_ofs_px_new[0];
|
||||
st->runtime.scroll_ofs_px[1] = scroll_ofs_px_new[1];
|
||||
ED_area_tag_redraw(CTX_wm_area(C));
|
||||
}
|
||||
|
||||
@@ -2671,12 +2672,12 @@ static void scroll_exit(bContext *C, wmOperator *op)
|
||||
|
||||
st->flags &= ~ST_SCROLL_SELECT;
|
||||
|
||||
if (st->scroll_ofs_px[1] > tsc->state.size_px[1] / 2) {
|
||||
if (st->runtime.scroll_ofs_px[1] > tsc->state.size_px[1] / 2) {
|
||||
st->top += 1;
|
||||
}
|
||||
|
||||
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;
|
||||
ED_area_tag_redraw(CTX_wm_area(C));
|
||||
|
||||
MEM_freeN(op->customdata);
|
||||
@@ -2700,7 +2701,7 @@ static int text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
if (event->val == KM_RELEASE) {
|
||||
if (ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
|
||||
txt_screen_skip(
|
||||
st, ar, st->viewlines * (tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1));
|
||||
st, ar, st->runtime.viewlines * (tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1));
|
||||
|
||||
ED_area_tag_redraw(CTX_wm_area(C));
|
||||
}
|
||||
@@ -2744,8 +2745,8 @@ static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
tsc->mval_prev[0] = event->x;
|
||||
tsc->mval_prev[1] = event->y;
|
||||
/* Sensitivity of scroll set to 4pix per line/char */
|
||||
tsc->mval_delta[0] = (event->x - event->prevx) * st->cwidth / 4;
|
||||
tsc->mval_delta[1] = (event->y - event->prevy) * st->lheight_dpi / 4;
|
||||
tsc->mval_delta[0] = (event->x - event->prevx) * st->runtime.cwidth_px / 4;
|
||||
tsc->mval_delta[1] = (event->y - event->prevy) * st->runtime.lheight_px / 4;
|
||||
tsc->is_first = false;
|
||||
tsc->is_scrollbar = false;
|
||||
text_scroll_apply(C, op, event);
|
||||
@@ -2819,13 +2820,15 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev
|
||||
}
|
||||
|
||||
/* verify we are in the right zone */
|
||||
if (mval[0] > st->txtbar.xmin && mval[0] < st->txtbar.xmax) {
|
||||
if (mval[1] >= st->txtbar.ymin && mval[1] <= st->txtbar.ymax) {
|
||||
if (mval[0] > st->runtime.scroll_region_handle.xmin &&
|
||||
mval[0] < st->runtime.scroll_region_handle.xmax) {
|
||||
if (mval[1] >= st->runtime.scroll_region_handle.ymin &&
|
||||
mval[1] <= st->runtime.scroll_region_handle.ymax) {
|
||||
/* mouse inside scroll handle */
|
||||
zone = SCROLLHANDLE_BAR;
|
||||
}
|
||||
else if (mval[1] > TXT_SCROLL_SPACE && mval[1] < ar->winy - TXT_SCROLL_SPACE) {
|
||||
if (mval[1] < st->txtbar.ymin) {
|
||||
if (mval[1] < st->runtime.scroll_region_handle.ymin) {
|
||||
zone = SCROLLHANDLE_MIN_OUTSIDE;
|
||||
}
|
||||
else {
|
||||
@@ -2850,8 +2853,8 @@ static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *ev
|
||||
|
||||
/* jump scroll, works in v2d but needs to be added here too :S */
|
||||
if (event->type == MIDDLEMOUSE) {
|
||||
tsc->mval_prev[0] = ar->winrct.xmin + BLI_rcti_cent_x(&st->txtbar);
|
||||
tsc->mval_prev[1] = ar->winrct.ymin + BLI_rcti_cent_y(&st->txtbar);
|
||||
tsc->mval_prev[0] = ar->winrct.xmin + BLI_rcti_cent_x(&st->runtime.scroll_region_handle);
|
||||
tsc->mval_prev[1] = ar->winrct.ymin + BLI_rcti_cent_y(&st->runtime.scroll_region_handle);
|
||||
|
||||
tsc->is_first = false;
|
||||
tsc->zone = SCROLLHANDLE_BAR;
|
||||
@@ -3228,7 +3231,7 @@ static int text_selection_set_invoke(bContext *C, wmOperator *op, const wmEvent
|
||||
SpaceText *st = CTX_wm_space_text(C);
|
||||
SetSelection *ssel;
|
||||
|
||||
if (event->mval[0] >= st->txtbar.xmin) {
|
||||
if (event->mval[0] >= st->runtime.scroll_region_handle.xmin) {
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
@@ -3309,7 +3312,7 @@ static int text_cursor_set_invoke(bContext *C, wmOperator *op, const wmEvent *ev
|
||||
{
|
||||
SpaceText *st = CTX_wm_space_text(C);
|
||||
|
||||
if (event->mval[0] >= st->txtbar.xmin) {
|
||||
if (event->mval[0] >= st->runtime.scroll_region_handle.xmin) {
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
@@ -3358,7 +3361,8 @@ static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wm
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
if (!(mval[0] > 2 && mval[0] < (TXT_NUMCOL_WIDTH(st) + (TXT_BODY_LPAD * st->cwidth)) &&
|
||||
if (!(mval[0] > 2 &&
|
||||
mval[0] < (TXT_NUMCOL_WIDTH(st) + (TXT_BODY_LPAD * st->runtime.cwidth_px)) &&
|
||||
mval[1] > 2 && mval[1] < ar->winy - 2)) {
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
}
|
||||
|
||||
@@ -1167,6 +1167,41 @@ typedef enum eSpaceImage_OtherUVFilter {
|
||||
/** \name Text Editor
|
||||
* \{ */
|
||||
|
||||
typedef struct SpaceText_Runtime {
|
||||
|
||||
/** Actual line height, scaled by dpi. */
|
||||
int lheight_px;
|
||||
|
||||
/** Runtime computed, character width. */
|
||||
int cwidth_px;
|
||||
|
||||
/** The handle of the scroll-bar which can be clicked and dragged. */
|
||||
struct rcti scroll_region_handle;
|
||||
/** The region for selected text to show in the scrolling area. */
|
||||
struct rcti scroll_region_select;
|
||||
|
||||
/** Number of digits to show in the line numbers column (when enabled). */
|
||||
int line_number_display_digits;
|
||||
|
||||
/** Number of lines this window can display (even when they aren't used). */
|
||||
int viewlines;
|
||||
|
||||
/** Use for drawing scroll-bar & calculating scroll operator motion scaling. */
|
||||
float scroll_px_per_line;
|
||||
|
||||
/**
|
||||
* Run-time for scroll increments smaller than a line (smooth scroll).
|
||||
* Values must be between zero and the line, column width: (cwidth, TXT_LINE_HEIGHT(st)).
|
||||
*/
|
||||
int scroll_ofs_px[2];
|
||||
|
||||
char _pad1[4];
|
||||
|
||||
/** Cache for faster drawing. */
|
||||
void *drawcache;
|
||||
|
||||
} SpaceText_Runtime;
|
||||
|
||||
/* Text Editor */
|
||||
typedef struct SpaceText {
|
||||
SpaceLink *next, *prev;
|
||||
@@ -1179,30 +1214,26 @@ typedef struct SpaceText {
|
||||
|
||||
struct Text *text;
|
||||
|
||||
int top, viewlines;
|
||||
short flags, menunr;
|
||||
int top, left;
|
||||
char _pad1[4];
|
||||
|
||||
short flags;
|
||||
|
||||
/** User preference, is font_size! */
|
||||
short lheight;
|
||||
/**
|
||||
* Runtime computed, character width
|
||||
* and the number of chars to use when showing line numbers.
|
||||
*/
|
||||
char cwidth, linenrs_tot;
|
||||
int left;
|
||||
int showlinenrs;
|
||||
|
||||
int tabnumber;
|
||||
|
||||
short showsyntax;
|
||||
short line_hlight;
|
||||
short overwrite;
|
||||
/* Booleans */
|
||||
char wordwrap;
|
||||
char doplugins;
|
||||
char showlinenrs;
|
||||
char showsyntax;
|
||||
char line_hlight;
|
||||
char overwrite;
|
||||
/** Run python while editing, evil. */
|
||||
short live_edit;
|
||||
float pix_per_line;
|
||||
|
||||
struct rcti txtscroll, txtbar;
|
||||
|
||||
int wordwrap, doplugins;
|
||||
char live_edit;
|
||||
char _pad2[1];
|
||||
|
||||
/** ST_MAX_FIND_STR. */
|
||||
char findstr[256];
|
||||
@@ -1211,26 +1242,18 @@ typedef struct SpaceText {
|
||||
|
||||
/** Column number to show right margin at. */
|
||||
short margin_column;
|
||||
/** Actual lineheight, dpi controlled. */
|
||||
short lheight_dpi;
|
||||
char _pad[4];
|
||||
char _pad3[2];
|
||||
|
||||
/** Cache for faster drawing. */
|
||||
void *drawcache;
|
||||
|
||||
/**
|
||||
* Run-time for scroll increments smaller than a line (smooth scroll).
|
||||
* Values must be between zero and the line, column width: (cwidth, TXT_LINE_HEIGHT(st)).
|
||||
*/
|
||||
int scroll_ofs_px[2];
|
||||
/** Keep last. */
|
||||
SpaceText_Runtime runtime;
|
||||
} SpaceText;
|
||||
|
||||
/* SpaceText flags (moved from DNA_text_types.h) */
|
||||
typedef enum eSpaceText_Flags {
|
||||
/* scrollable */
|
||||
ST_SCROLL_SELECT = (1 << 0),
|
||||
/* clear namespace after script execution (BPY_main.c) */
|
||||
ST_CLEAR_NAMESPACE = (1 << 4),
|
||||
|
||||
ST_FLAG_UNUSED_4 = (1 << 4), /* dirty */
|
||||
|
||||
ST_FIND_WRAP = (1 << 5),
|
||||
ST_FIND_ALL = (1 << 6),
|
||||
|
||||
@@ -36,7 +36,8 @@ typedef struct TextLine {
|
||||
/** May be NULL if syntax is off or not yet formatted. */
|
||||
char *format;
|
||||
/** Blen unused. */
|
||||
int len, blen;
|
||||
int len;
|
||||
char _pad0[4];
|
||||
} TextLine;
|
||||
|
||||
typedef struct Text {
|
||||
|
||||
@@ -4699,7 +4699,7 @@ static void rna_def_space_text(BlenderRNA *brna)
|
||||
|
||||
prop = RNA_def_property(srna, "visible_lines", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_int_sdna(prop, NULL, "viewlines");
|
||||
RNA_def_property_int_sdna(prop, NULL, "runtime.viewlines");
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Visible Lines", "Amount of lines that can be visible in current editor");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user