82 const char tab_columns = 1;
92 const char tab_columns = 1;
103 const char tab_columns = 1;
112static void txt_format_text(
SpaceText *st)
121 txt_format_line(st,
linep, 0);
129 switch (formatchar) {
213 int i, j, start, end,
max;
235 if (
linep == linein) {
247 (*offl) += lines - 1;
277 if (
i + columns - start >
max) {
278 end = std::min(end,
i);
283 *offc -= end - start;
290 *offc -= end - start;
296 else if (
ELEM(ch,
' ',
'-')) {
306 if (
linep == linein) {
316 int i, j, start, end, chars,
max;
341 ch = linein->
line[j];
354 if (
i + columns - start >
max) {
355 end = std::min(end,
i);
360 *offc -= end - start;
367 *offc -= end - start;
373 else if (
ELEM(ch,
' ',
'-')) {
390 if (line[
i] ==
'\t') {
405 if (columns -
col < 0) {
435 int mi, ma, mstart, mend;
436 char fmt_prev = 0xff;
438 const int clip_min_y = -(st->
runtime->lheight_px - 1);
454 if (
i + columns > end) {
470 for (a = fstart, ma = mstart; ma < mend; a++) {
472 if (fmt_prev !=
format[a]) {
489 if (
y <= clip_min_y) {
493 else if (
ELEM(
str[mi],
' ',
'-')) {
500 for (a = fstart, ma = mstart;
str[ma] &&
y > clip_min_y; a++) {
502 if (fmt_prev !=
format[a]) {
529 const char *
in =
nullptr;
545 if (maxwidth &&
w + columns > cshift + maxwidth) {
562 int a, str_shift = 0;
563 char fmt_prev = 0xff;
565 for (a = 0; a < amount; a++) {
566 if (
format[a] != fmt_prev) {
606 drawcache->
winx = -1;
610 st->
runtime->drawcache = drawcache;
616 bool full_update =
false;
620 if (st->
runtime->drawcache ==
nullptr) {
627 nlines = drawcache->
nlines;
632 full_update |= drawcache->
winx != region->
winx;
656 int lineno = 0,
size, lines_count;
657 int *fp = drawcache->
line_height, *new_tail, *old_tail;
660 size =
sizeof(int) * nlines;
666 fp =
static_cast<int *
>(
MEM_callocN(
size,
"text drawcache line_height"));
671 new_tail = fp + nlines - drawcache->
valid_tail;
672 memmove(new_tail, old_tail, drawcache->
valid_tail);
682 lines_count = fp[lineno];
685 else if (lineno > new_tail - fp) {
686 lines_count = fp[lineno];
692 fp[lineno] = lines_count;
705 if (full_update || drawcache->
update) {
716 drawcache->
nlines = nlines;
729 drawcache->
update =
false;
741 if (st->
runtime->drawcache !=
nullptr) {
755 if (curlno < sellno) {
812 int i, j, start, end,
max, lines, chars;
833 if (
i + columns - start >
max) {
835 start = std::min(end,
i);
838 else if (
ELEM(ch,
' ',
'-')) {
890 int lhlstart, lhlend, ltexth, sell_off, curl_off;
891 short barheight, barstart, hlstart, hlend, blank_lines;
892 short pix_available, pix_top_margin, pix_bottom_margin, pix_bardiff;
894 pix_top_margin = (0.4 *
U.widget_unit);
895 pix_bottom_margin = (0.4 *
U.widget_unit);
896 pix_available = region->
winy - pix_top_margin - pix_bottom_margin;
898 blank_lines = st->
runtime->viewlines / 2;
901 r_back->
xmin = region->
winx - (0.6 *
U.widget_unit);
906 r_scroll->
xmax = region->
winx - (0.2 *
U.widget_unit);
907 r_scroll->
xmin = r_scroll->
xmax - (0.4 *
U.widget_unit);
908 r_scroll->
ymin = pix_top_margin;
909 r_scroll->
ymax = pix_available;
913 if (ltexth + blank_lines < st->
top + st->
runtime->viewlines) {
914 blank_lines = st->
top + st->
runtime->viewlines - ltexth;
917 ltexth += blank_lines;
919 barheight = (ltexth > 0) ? (st->
runtime->viewlines * pix_available) / ltexth : 0;
921 if (barheight < 20) {
922 pix_bardiff = 20 - barheight;
925 barstart = (ltexth > 0) ? ((pix_available - pix_bardiff) * st->
top) / ltexth : 0;
927 st->
runtime->scroll_region_handle = *r_scroll;
928 st->
runtime->scroll_region_handle.ymax -= barstart;
929 st->
runtime->scroll_region_handle.ymin = st->
runtime->scroll_region_handle.ymax - barheight;
931 CLAMP(st->
runtime->scroll_region_handle.ymin, pix_bottom_margin, region->
winy - pix_top_margin);
932 CLAMP(st->
runtime->scroll_region_handle.ymax, pix_bottom_margin, region->
winy - pix_top_margin);
934 st->
runtime->scroll_px_per_line = (pix_available > 0) ?
float(ltexth) / pix_available : 0;
935 st->
runtime->scroll_px_per_line = std::max(st->
runtime->scroll_px_per_line, 0.1f);
941 lhlstart = std::min(curl_off, sell_off);
942 lhlend = std::max(curl_off, sell_off);
945 hlstart = (lhlstart * pix_available) / ltexth;
946 hlend = (lhlend * pix_available) / ltexth;
949 if (pix_bardiff > 0) {
951 if (st->
runtime->viewlines && lhlstart >= st->
top &&
955 hlstart = (((pix_available - pix_bardiff) * lhlstart) / ltexth) +
956 (pix_bardiff * (lhlstart - st->
top) / st->
runtime->viewlines);
958 else if (lhlstart > st->
top + st->
runtime->viewlines && hlstart < barstart + barheight &&
962 hlstart = barstart + barheight;
964 else if (lhlend > st->
top && lhlstart < st->
top && hlstart > barstart) {
969 if (hlend <= hlstart) {
974 if (st->
runtime->viewlines && lhlend >= st->
top &&
978 hlend = (((pix_available - pix_bardiff) * lhlend) / ltexth) +
979 (pix_bardiff * (lhlend - st->
top) / st->
runtime->viewlines);
981 else if (lhlend < st->
top && hlend >= barstart - 2 && hlend < barstart + barheight) {
985 else if (lhlend > st->
top + st->
runtime->viewlines &&
986 lhlstart < st->
top + st->
runtime->viewlines && hlend < barstart + barheight)
989 hlend = barstart + barheight;
992 if (hlend <= hlstart) {
1002 if (hlend - hlstart < 2) {
1003 hlend = hlstart + 2;
1006 st->
runtime->scroll_region_select = *r_scroll;
1007 st->
runtime->scroll_region_select.ymax = region->
winy - pix_top_margin - hlstart;
1008 st->
runtime->scroll_region_select.ymin = region->
winy - pix_top_margin - hlend;
1010 CLAMP(st->
runtime->scroll_region_select.ymin, pix_bottom_margin, region->
winy - pix_top_margin);
1011 CLAMP(st->
runtime->scroll_region_select.ymax, pix_bottom_margin, region->
winy - pix_top_margin);
1031 &st->
runtime->scroll_region_handle,
1041 rect.
xmin = st->
runtime->scroll_region_select.xmin + 1;
1042 rect.
xmax = st->
runtime->scroll_region_select.xmax - 1;
1043 rect.
ymin = st->
runtime->scroll_region_select.ymin;
1044 rect.
ymax = st->
runtime->scroll_region_select.ymax;
1056 SuggItem *item, *first, *last, *sel;
1058 int offl, offc, vcurl, vcurc;
1059 int w, boxw = 0, boxh,
i,
x,
y, *
top;
1061 const int margin_x = 2;
1073 if (!first || !last) {
1087 y = region->
winy - (vcurl + 1) * lheight - 2;
1097 if (
x + boxw > region->
winx) {
1098 x = std::max(0, region->
winx - boxw);
1105 rect.
xmax =
x + boxw;
1106 rect.
ymin =
y - boxh;
1123 for (
i = 0, item = first;
i < *
top && item->
next;
i++, item = item->
next) {
1142 immRectf(posi,
x + margin_x,
y - 3,
x + margin_x +
w,
y + lheight - 3);
1165 int vcurl, vcurc, vsell, vselc;
1166 bool hidden =
false;
1196 vcurc = std::max(vcurc, 0);
1201 int y = region->
winy;
1203 y += st->
runtime->scroll_ofs_px[1];
1206 if (vcurl == vsell) {
1207 y -= vcurl * lheight;
1209 if (vcurc < vselc) {
1211 x + vcurc * st->
runtime->cwidth_px,
1213 x + vselc * st->
runtime->cwidth_px,
1218 x + vselc * st->
runtime->cwidth_px,
1220 x + vcurc * st->
runtime->cwidth_px,
1225 int froml, fromc, tol, toc;
1227 if (vcurl < vsell) {
1240 y -= froml * lheight;
1243 pos,
x + fromc * st->
runtime->cwidth_px -
U.pixelsize,
y, region->
winx,
y - lheight);
1246 for (
int i = froml + 1;
i < tol;
i++) {
1251 if (
x + toc * st->
runtime->cwidth_px >
x) {
1268 y1 = region->
winy - (vsell - offl) * lheight;
1270 y1 += st->
runtime->scroll_ofs_px[1];
1272 y2 = y1 - (lheight * visible_lines);
1275 y1 = region->
winy - vsell * lheight;
1277 y1 += st->
runtime->scroll_ofs_px[1];
1279 y2 = y1 - (lheight);
1282 if (!(y1 < 0 || y2 > region->
winy)) {
1283 float highlight_color[4];
1285 highlight_color[3] = 0.1f;
1296 int y = region->
winy - vsell * lheight;
1298 y += st->
runtime->scroll_ofs_px[1];
1313 pos,
x,
y - lheight -
U.pixelsize,
x +
w +
U.pixelsize,
y - lheight - (3 *
U.pixelsize));
1333 int b, fc, find, stack, viewc, viewl, offl, offc,
x,
y;
1334 int startc, endc, c;
1343 startl = text->
curl;
1344 startc = text->
curc;
1346 if (
b == 0 && startc > 0) {
1373 while (c < linep->
len) {
1386 else if (
b == -find) {
1421 else if (
b == -find) {
1435 if (
linep->format) {
1436 fc = strlen(
linep->format) - 1;
1451 if (!endl || endc == -1) {
1459 y += st->
runtime->scroll_ofs_px[1];
1463 ch = startl->
line[startc];
1477 ch = endl->line[endc];
1505 int i,
x,
y, winx, linecount = 0, lineno = 0;
1506 int wraplinecount = 0, wrap_skip = 0;
1507 int margin_column_x;
1518 const int clip_min_y = -(st->
runtime->lheight_px - 1);
1540 for (
i = 0;
i < st->
top && tmp;
i++) {
1548 if (wraplinecount + lines > st->
top) {
1549 wrap_skip = st->
top - wraplinecount;
1553 wraplinecount += lines;
1580 st->
runtime->line_number_display_digits = 0;
1585 int viewlines = st->
runtime->viewlines;
1587 y += st->
runtime->scroll_ofs_px[1];
1599 for (
i = 0;
y > clip_min_y &&
i < viewlines && tmp;
i++, tmp = tmp->
next) {
1616 st, &tdc, tmp->
line,
x,
y, winx -
x, tmp->
format, wrap_skip);
1631 if (margin_column_x >=
x) {
1635 float margin_color[4];
1637 margin_color[3] = 0.2f;
1640 immRectf(
pos, margin_column_x, 0, margin_column_x +
U.pixelsize, region->
winy);
1693 int i,
x, winx = region->
winx;
1719 else if (st->
top >
i) {
1741 else if (
x > winx) {
1742 st->
left += ((
x - (winx + 1)) / st->
runtime->cwidth_px) + 1;
1747 st->
top = std::max(st->
top, 0);
1750 st->
runtime->scroll_ofs_px[0] = 0;
1751 st->
runtime->scroll_ofs_px[1] = 0;
1779 const int cursor_co[2],
1794 if (char_ofs < 0 || char_ofs > line->
len) {
1807 r_pixel_co[0] = (char_pos + offc - st->
left) * st->
runtime->cwidth_px + linenr_offset;
1808 r_pixel_co[1] = (region->
winy - ((cursor_co[0] + offl - st->
top) * lheight)) - lheight;
SpaceText * CTX_wm_space_text(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
void txt_clean_text(struct Text *text)
int text_check_bracket(char ch)
int txt_get_span(const struct TextLine *from, const struct TextLine *to)
int text_find_identifier_start(const char *str, int i)
short texttool_text_is_active(struct Text *text)
int * texttool_suggest_top(void)
SuggItem * texttool_suggest_first(void)
SuggItem * texttool_suggest_last(void)
SuggItem * texttool_suggest_selected(void)
void BLF_size(int fontid, float size)
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
#define BLF_DRAW_STR_DUMMY_MAX
void BLF_position(int fontid, float x, float y, float z)
int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth, int tab_columns) ATTR_NONNULL(2)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
MINLINE int integer_digits_i(int i)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
char * STRNCPY(char(&dst)[N], const char *src)
int BLI_str_utf8_offset_from_index(const char *str, size_t str_len, int index_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define SNPRINTF_UTF8(dst, format,...)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
int BLI_str_utf8_char_width_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t size_t BLI_strnlen_utf8(const char *strc, size_t strc_maxlen) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_str_utf8_offset_to_index(const char *str, size_t str_len, int offset_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
const char * BLI_str_find_prev_char_utf8(const char *p, const char *str_start) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1
int BLI_str_utf8_offset_to_column(const char *str, size_t str_len, int offset_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define STREQLEN(a, b, n)
bool ED_text_is_syntax_highlight_supported(Text *text)
@ GPU_SHADER_3D_UNIFORM_COLOR
void GPU_blend(GPUBlend blend)
Read Guarded memory(de)allocation.
#define MEM_reallocN(vmemh, len)
void ui_draw_dropshadow(const rctf *rct, float radius, float width, float aspect, float alpha)
void UI_draw_roundbox_corner_set(int type)
void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *slider, int state)
void UI_draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
void UI_GetThemeColor3fv(int colorid, float col[3])
void UI_GetThemeColor4fv(int colorid, float col[4])
void UI_FontThemeColor(int fontid, int colorid)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
void * MEM_callocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
float wrap(float value, float max, float min)
char text_id[MAX_ID_NAME - 2]
SpaceText_Runtime * runtime
void(* format_line)(SpaceText *st, TextLine *line, bool do_next)
uiWidgetColors wcol_scroll
void text_pop_suggest_list()
static int text_font_draw(const TextDrawContext *tdc, int x, int y, const char *str)
int ED_space_text_visible_lines_get(const SpaceText *st)
static int space_text_get_visible_lines_no(const SpaceText *st, int lineno)
static int text_font_draw_character(const TextDrawContext *tdc, int x, int y, char c)
static void space_text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
void space_text_drawcache_tag_update(SpaceText *st, const bool full)
void ED_space_text_scroll_to_cursor(SpaceText *st, ARegion *region, const bool center)
void space_text_free_caches(SpaceText *st)
static int text_font_draw_character_utf8(const TextDrawContext *tdc, int x, int y, const char *c, const int c_len)
static void draw_textscroll(const SpaceText *st, const rcti *scroll, const rcti *back)
static void text_font_end(const TextDrawContext *)
void draw_text_main(SpaceText *st, ARegion *region)
bool ED_text_activate_in_screen(bContext *C, Text *text)
void space_text_update_cursor_moved(bContext *C)
void space_text_update_character_width(SpaceText *st)
int space_text_get_visible_lines(const SpaceText *st, const ARegion *region, const char *str)
static void text_font_begin(const TextDrawContext *tdc)
void space_text_wrap_offset_in_line(const SpaceText *st, const ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
static void format_draw_color(const TextDrawContext *tdc, char formatchar)
static const char * txt_utf8_forward_columns(const char *str, int columns, int *padding)
static int space_text_draw_wrapped(const SpaceText *st, const TextDrawContext *tdc, const char *str, int x, int y, int w, const char *format, int skip)
bool ED_space_text_region_location_from_cursor(const SpaceText *st, const ARegion *region, const int cursor_co[2], int r_pixel_co[2])
static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegion *region)
int space_text_get_span_wrap(const SpaceText *st, const ARegion *region, const TextLine *from, const TextLine *to)
static void calc_text_rcts(SpaceText *st, ARegion *region, rcti *r_scroll, rcti *r_back)
int space_text_get_total_lines(SpaceText *st, const ARegion *region)
static void draw_text_decoration(SpaceText *st, ARegion *region)
static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc, ARegion *region)
static void space_text_drawcache_init(SpaceText *st)
int space_text_get_char_pos(const SpaceText *st, const char *line, int cur)
static void space_text_update_drawcache(SpaceText *st, const ARegion *region)
static void space_text_draw(const SpaceText *st, const TextDrawContext *tdc, char *str, int cshift, int maxwidth, int x, int y, const char *format)
void space_text_scroll_to_cursor_with_area(SpaceText *st, ScrArea *area, const bool center)
int flatten_string(const SpaceText *st, FlattenString *fs, const char *in)
void flatten_string_free(FlattenString *fs)
TextFormatType * ED_text_format_get(Text *text)
int space_text_wrap_width(const SpaceText *st, const ARegion *region)
#define TXT_LINE_SPACING(st)
#define TXT_LINE_HEIGHT(st)
#define TXT_NUMCOL_WIDTH(st)
void space_text_wrap_offset(const SpaceText *st, const ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
#define TXT_BODY_LEFT(st)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)