84 const char tab_columns = 1;
94 const char tab_columns = 1;
105 const char tab_columns = 1;
114static void txt_format_text(SpaceText *st)
122 for (linep = st->text->lines.first; linep; linep = linep->next) {
123 txt_format_line(st, linep, 0);
131 switch (formatchar) {
215 int i, j, start, end,
max;
231 linep = text->lines.first();
233 while (i > 0 && linep) {
237 if (linep == linein) {
249 (*offl) += lines - 1;
269 if (linep == linein && i < cursin) {
279 if (i + columns - start >
max) {
280 end = std::min(end, i);
282 if (chop && linep == linein && i >= cursin) {
285 *offc -= end - start;
292 *offc -= end - start;
298 else if (
ELEM(ch,
' ',
'-')) {
301 if (linep == linein && i >= cursin) {
308 if (linep == linein) {
318 int i, j, start, end, chars,
max;
343 ch = linein->
line[j];
356 if (i + columns - start >
max) {
357 end = std::min(end, i);
359 if (chop && i >= cursin) {
362 *offc -= end - start;
369 *offc -= end - start;
375 else if (
ELEM(ch,
' ',
'-')) {
392 if (line[i] ==
'\t') {
414 if (line[i] ==
'\t') {
429 if (columns - col < 0) {
459 int mi, ma, mstart, mend;
460 char fmt_prev = 0xff;
478 if (i + columns > end) {
494 for (a = fstart, ma = mstart; ma < mend; a++) {
496 if (fmt_prev != format[a]) {
513 if (
y <= clip_min_y) {
517 else if (
ELEM(
str[mi],
' ',
'-')) {
524 for (a = fstart, ma = mstart;
str[ma] &&
y > clip_min_y; a++) {
526 if (fmt_prev != format[a]) {
553 const char *
in =
nullptr;
569 if (maxwidth &&
w + columns > cshift + maxwidth) {
586 int a, str_shift = 0;
587 char fmt_prev = 0xff;
589 for (a = 0; a < amount; a++) {
590 if (format[a] != fmt_prev) {
630 drawcache->
winx = -1;
640 bool full_update =
false;
651 nlines = drawcache->
nlines;
656 full_update |= drawcache->
winx != region->
winx;
680 int lineno = 0, lines_count;
683 nlines = txt->lines.count();
694 new_tail = fp + nlines - drawcache->
valid_tail;
695 memmove(new_tail, old_tail, drawcache->
valid_tail);
705 lines_count = fp[lineno];
708 else if (lineno > new_tail - fp) {
709 lines_count = fp[lineno];
715 fp[lineno] = lines_count;
728 if (full_update || drawcache->
update) {
729 nlines = txt->lines.count();
739 drawcache->
nlines = nlines;
752 drawcache->
update =
false;
778 if (curlno < sellno) {
815 MEM_delete(drawcache);
835 int i, j, start, end,
max, lines, chars;
856 if (i + columns - start >
max) {
858 start = std::min(end, i);
861 else if (
ELEM(ch,
' ',
'-')) {
913 int lhlstart, lhlend, ltexth, sell_off, curl_off;
914 short barheight, barstart, hlstart, hlend, blank_lines;
915 short pix_available, pix_top_margin, pix_bottom_margin, pix_bardiff;
917 pix_top_margin = (0.4 *
U.widget_unit);
918 pix_bottom_margin = (0.4 *
U.widget_unit);
919 pix_available = region->
winy - pix_top_margin - pix_bottom_margin;
924 r_back->
xmin = region->
winx - (0.6 *
U.widget_unit);
929 r_scroll->
xmax = region->
winx - (0.2 *
U.widget_unit);
930 r_scroll->
xmin = r_scroll->
xmax - (0.4 *
U.widget_unit);
931 r_scroll->
ymin = pix_top_margin;
932 r_scroll->
ymax = pix_available;
940 ltexth += blank_lines;
942 barheight = (ltexth > 0) ? (st->
runtime->
viewlines * pix_available) / ltexth : 0;
944 if (barheight < 20) {
945 pix_bardiff = 20 - barheight;
948 barstart = (ltexth > 0) ? ((pix_available - pix_bardiff) * st->
top) / ltexth : 0;
962 lhlstart = std::min(curl_off, sell_off);
963 lhlend = std::max(curl_off, sell_off);
966 hlstart = (lhlstart * pix_available) / ltexth;
967 hlend = (lhlend * pix_available) / ltexth;
970 if (pix_bardiff > 0) {
976 hlstart = (((pix_available - pix_bardiff) * lhlstart) / ltexth) +
983 hlstart = barstart + barheight;
985 else if (lhlend > st->
top && lhlstart < st->top && hlstart > barstart) {
990 if (hlend <= hlstart) {
999 hlend = (((pix_available - pix_bardiff) * lhlend) / ltexth) +
1002 else if (lhlend < st->top && hlend >= barstart - 2 && hlend < barstart + barheight) {
1007 lhlstart < st->top + st->
runtime->
viewlines && hlend < barstart + barheight)
1010 hlend = barstart + barheight;
1013 if (hlend <= hlstart) {
1014 hlstart = hlend - 2;
1023 if (hlend - hlstart < 2) {
1024 hlend = hlstart + 2;
1076 SuggItem *item, *first, *last, *sel;
1078 int offl, offc, vcurl, vcurc;
1079 int w, boxw = 0, boxh, i,
x,
y, *top;
1081 const int margin_x = 2;
1093 if (!first || !last) {
1106 y = region->
winy - (vcurl + 1) * line_height - 2;
1116 if (
x + boxw > region->
winx) {
1117 x = std::max(0, region->
winx - boxw);
1124 rect.
xmax =
x + boxw;
1125 rect.
ymin =
y - boxh;
1134 immRectf(pos,
x - 1,
y + 1,
x + boxw + 1,
y - boxh - 1);
1141 for (i = 0, item = first; i < *top && item->
next; i++, item = item->
next) {
1160 immRectf(posi,
x + margin_x,
y - 3,
x + margin_x +
w,
y + line_height - 3);
1183 int vcurl, vcurc, vsell, vselc;
1184 bool hidden =
false;
1190 vsell =
txt_get_span(text->lines.first(), text->sell) - st->
top + offl;
1198 if (text->curl == text->sell && text->curc == text->selc && !st->
line_hlight && hidden) {
1207 if (text->curl != text->sell || text->curc != text->selc) {
1210 vcurl =
txt_get_span(text->lines.first(), text->curl) - st->
top + offl;
1213 vcurc = std::max(vcurc, 0);
1221 int y = region->
winy;
1226 if (vcurl == vsell) {
1227 y -= vcurl * line_height;
1229 if (vcurc < vselc) {
1245 int froml, fromc, tol, toc;
1247 if (vcurl < vsell) {
1260 y -= froml * line_height;
1269 for (
int i = froml + 1; i < tol; i++) {
1292 y1 = region->
winy - (vsell - offl) * line_height;
1296 y2 = y1 - (line_height * visible_lines);
1299 y1 = region->
winy - vsell * line_height;
1303 y2 = y1 - line_height;
1306 if (!(y1 < 0 || y2 > region->
winy)) {
1307 float highlight_color[4];
1309 highlight_color[3] = 0.1f;
1320 int y = region->
winy - vsell * line_height;
1328 char ch = text->sell->line[text->selc];
1338 y - line_height -
U.pixelsize,
1339 x +
w +
U.pixelsize,
1340 y - line_height - (3 *
U.pixelsize));
1343 immRectf(pos,
x -
U.pixelsize,
y,
x +
U.pixelsize,
y - line_height);
1360 int b, fc, find, stack, viewc, viewl, offl, offc,
x,
y;
1361 int startc, endc, c;
1370 startl = text->curl;
1371 startc = text->curc;
1373 if (
b == 0 && startc > 0) {
1400 while (c < linep->
len) {
1413 else if (
b == -find) {
1417 if (linep->
line[c] ==
'\t') {
1428 linep = linep->
next;
1437 if (linep->
line[c] ==
'\t') {
1462 else if (
b == -find) {
1468 if (linep->
line[c] ==
'\t') {
1483 linep = linep->
prev;
1499 if (!endl || endc == -1) {
1511 ch = startl->
line[startc];
1525 ch = endl->line[endc];
1553 int i,
x,
y, winx, linecount = 0, lineno = 0;
1554 int wraplinecount = 0, wrap_skip = 0;
1555 int margin_column_x;
1577 if (!text->curl || !text->sell || !text->lines.first_ || !text->lines.last()) {
1586 tmp = text->lines.first();
1588 for (i = 0; i < st->
top && tmp; i++) {
1596 if (wraplinecount + lines > st->
top) {
1597 wrap_skip = st->
top - wraplinecount;
1601 wraplinecount += lines;
1647 for (i = 0;
y > clip_min_y && i < viewlines && tmp; i++, tmp = tmp->
next) {
1665 st, &tdc, tmp->
line,
x,
y, winx -
x, tmp->
format, wrap_skip);
1686 if (margin_column_x >=
x) {
1690 float margin_color[4];
1692 margin_color[3] = 0.2f;
1695 immRectf(pos, margin_column_x, 0, margin_column_x +
U.pixelsize, region->
winy);
1748 int i,
x, winx = region->
winx;
1774 else if (st->
top > i) {
1796 else if (
x > winx) {
1802 st->
top = std::max(st->
top, 0);
1840 const int line_index,
1856 if (text ==
nullptr) {
1857 return std::nullopt;
1859 const int line_index =
txt_get_span(text->lines.first(), text->sell);
1868 const int cursor_co[2],
1883 if (char_ofs < 0 || char_ofs > line->
len) {
1889 r_pixel_co[0] = xy[0];
#define BLF_DRAW_STR_DUMMY_MAX
#define SNPRINTF_UTF8(dst, format,...)
Read Blender memory allocation and freeing.
#define STREQLEN(a, b, n)
#define MEM_realloc_uninitialized(vmemh, len)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
BLI_INLINE Texture * wrap(MTLTexture *texture)
void font_theme_color_set(int fontid, int colorid)
void get_color_3fv(int colorid, float col[3])
void get_color_4fv(int colorid, float col[4])
const bTheme * theme_get()
void draw_dropshadow(const rctf *rct, float radius, float width, float aspect, float alpha)
void draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *slider, int state)
void draw_roundbox_aa(const rctf *rect, bool filled, float rad, const float color[4])
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int flatten_string(const SpaceText *st, FlattenString *fs, const char *in)
ScrArea * CTX_wm_area(const bContext *C)
int txt_get_span(const struct TextLine *from, const struct TextLine *to)
char * STRNCPY(char(&dst)[N], const char *src)
uint padding(uint offset, uint alignment)
void BLF_position(int fontid, float x, float y, float z)
static int text_font_draw(const TextDrawContext *tdc, int x, int y, const char *str)
void space_text_drawcache_tag_update(SpaceText *st, const bool full)
int ED_space_text_visible_lines_get(const SpaceText *st)
static int space_text_get_visible_lines_no(const SpaceText *st, int lineno)
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
GPUVertFormat * immVertexFormat()
static int text_font_draw_character_utf8(const TextDrawContext *tdc, int x, int y, const char *c, const int c_len)
static int2 space_text_region_xy_from_cursor(const SpaceText *st, const ARegion *region, TextLine *line, const int line_index, const int char_ofs)
static void format_draw_color(const TextDrawContext *tdc, char formatchar)
static void draw_textscroll(const SpaceText *st, const rcti *scroll, const rcti *back)
MINLINE int integer_digits_i(int i)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
SuggItem * texttool_suggest_first()
void space_text_update_cursor_moved(bContext *C)
SuggItem * texttool_suggest_last()
MINLINE int max_ii(int a, int b)
static int space_text_get_format_index(const SpaceText *st, const char *line, int cur)
TextFormatType * ED_text_format_get(Text *text)
void immUniformColor4fv(const float rgba[4])
void space_text_wrap_offset(const SpaceText *st, const ARegion *region, TextLine *linein, int cursin, int *offl, int *offc)
int space_text_get_span_wrap(const SpaceText *st, const ARegion *region, const TextLine *from, const TextLine *to)
int text_find_identifier_start(const char *str, int i)
bool ED_text_activate_in_screen(bContext *C, Text *text)
int space_text_get_total_lines(SpaceText *st, const ARegion *region)
void ED_space_text_scroll_to_cursor(SpaceText *st, ARegion *region, bool center)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
SpaceText * CTX_wm_space_text(const bContext *C)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
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)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT 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)
void immUniformThemeColor(int color_id)
void BLF_size(int fontid, float size)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
void flatten_string_free(FlattenString *fs)
VecBase< int32_t, 2 > int2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void space_text_update_drawcache(SpaceText *st, const ARegion *region)
@ GPU_SHADER_3D_UNIFORM_COLOR
int space_text_get_char_pos(const SpaceText *st, const char *line, int cur)
short texttool_text_is_active(struct Text *text)
void txt_clean_text(struct Text *text)
void immUniformThemeColorShade(int color_id, int offset)
static void draw_text_decoration(SpaceText *st, ARegion *region)
int space_text_wrap_width(const SpaceText *st, const ARegion *region)
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT
int space_text_get_visible_lines(const SpaceText *st, const ARegion *region, const char *str)
static const char * txt_utf8_forward_columns(const char *str, int columns, int *padding)
bool ED_space_text_region_location_from_cursor(const SpaceText *st, const ARegion *region, const int cursor_co[2], int r_pixel_co[2])
void space_text_free_caches(SpaceText *st)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
static void calc_text_rcts(SpaceText *st, ARegion *region, rcti *r_scroll, rcti *r_back)
int BLI_str_utf8_offset_from_index(const char *str, size_t str_len, int index_target) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static void space_text_drawcache_init(SpaceText *st)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
int * texttool_suggest_top()
int BLF_draw_mono(int fontid, const char *str, size_t str_len, int char_width, int tab_columns) ATTR_NONNULL(2)
SuggItem * texttool_suggest_selected()
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 text_check_bracket(char ch)
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)
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
ScrArea * BKE_screen_find_big_area(const bScreen *screen, int spacetype, short min)
std::optional< int2 > space_text_cursor_region_xy_get(const SpaceText *st, const ARegion *region)
bScreen * CTX_wm_screen(const bContext *C)
static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegion *region)
void GPU_blend(GPUBlend blend)
bool ED_text_is_syntax_highlight_supported(Text *text)
void draw_text_main(SpaceText *st, ARegion *region)
void space_text_scroll_to_cursor_with_area(SpaceText *st, ScrArea *area, const bool center)
static void space_text_draw(const SpaceText *st, const TextDrawContext *tdc, char *str, int cshift, int maxwidth, int x, int y, const char *format)
MINLINE int min_ii(int a, int b)
void text_pop_suggest_list()
void space_text_update_character_width(SpaceText *st)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
static int text_font_draw_character(const TextDrawContext *tdc, int x, int y, char c)
static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc, ARegion *region)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static void text_font_end(const TextDrawContext *)
static void space_text_draw_context_init(const SpaceText *st, TextDrawContext *tdc)
uiWidgetColors wcol_scroll
char text_id[MAX_ID_NAME - 2]
ListBaseT< SpaceLink > spacedata
ed::text::SpaceText_Runtime * runtime
void(*) format_line(SpaceText *st, TextLine *line, bool do_next)
rcti scroll_region_select
int line_number_display_digits
rcti scroll_region_handle
#define TXT_LINE_SPACING(st)
#define TXT_LINE_HEIGHT(st)
#define TXT_NUMCOL_WIDTH(st)
#define TXT_BODY_LEFT(st)