Beispiel #1
0
static int text_draw_wrapped(SpaceText *st, const char *str, int x, int y, int w, const char *format, int skip)
{
	FlattenString fs;
	int basex, lines;
	int i, wrap, end, max, columns, padding; /* column */
	int a, fstart, fpos;                     /* utf8 chars */
	int mi, ma, mstart, mend;                /* mem */
	char fmt_prev = 0xff;
	
	flatten_string(st, &fs, str);
	str = fs.buf;
	max = w / st->cwidth;
	if (max < 8) max = 8;
	basex = x;
	lines = 1;
	
	fpos = fstart = 0; mstart = 0;
	mend = txt_utf8_forward_columns(str, max, &padding) - str;
	end = wrap = max - padding;
	
	for (i = 0, mi = 0; str[mi]; i += columns, mi += BLI_str_utf8_size_safe(str + mi)) {
		columns = BLI_str_utf8_char_width_safe(str + mi);
		if (i + columns > end) {
			/* skip hidden part of line */
			if (skip) {
				skip--;
				fstart = fpos; mstart = mend;
				mend = txt_utf8_forward_columns(str + mend, max, &padding) - str;
				end = (wrap += max - padding);
				continue;
			}

			/* Draw the visible portion of text on the overshot line */
			for (a = fstart, ma = mstart; ma < mend; a++, ma += BLI_str_utf8_size_safe(str + ma)) {
				if (st->showsyntax && format) {
					if (fmt_prev != format[a]) format_draw_color(fmt_prev = format[a]);
				}
				x += text_font_draw_character_utf8(st, x, y, str + ma);
				fpos++;
			}
			y -= st->lheight_dpi + TXT_LINE_SPACING;
			x = basex;
			lines++;
			fstart = fpos; mstart = mend;
			mend = txt_utf8_forward_columns(str + mend, max, &padding) - str;
			end = (wrap += max - padding);

			if (y <= 0) break;
		}
		else if (str[mi] == ' ' || str[mi] == '-') {
			wrap = i + 1; mend = mi + 1;
		}
	}

	/* Draw the remaining text */
	for (a = fstart, ma = mstart; str[ma] && y > 0; a++, ma += BLI_str_utf8_size_safe(str + ma)) {
		if (st->showsyntax && format) {
			if (fmt_prev != format[a]) format_draw_color(fmt_prev = format[a]);
		}

		x += text_font_draw_character_utf8(st, x, y, str + ma);
	}

	flatten_string_free(&fs);

	return lines;
}
Beispiel #2
0
static void draw_suggestion_list(SpaceText *st, ARegion *ar)
{
	SuggItem *item, *first, *last, *sel;
	char str[SUGG_LIST_WIDTH * BLI_UTF8_MAX + 1];
	int offl, offc, vcurl, vcurc;
	int w, boxw = 0, boxh, i, x, y, *top;
	const int lheight = st->lheight_dpi + TXT_LINE_SPACING;
	const int margin_x = 2;
	
	if (!st->text) return;
	if (!texttool_text_is_active(st->text)) return;

	first = texttool_suggest_first();
	last = texttool_suggest_last();

	if (!first || !last) return;

	text_pop_suggest_list();
	sel = texttool_suggest_selected();
	top = texttool_suggest_top();

	wrap_offset(st, ar, st->text->curl, st->text->curc, &offl, &offc);
	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 = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
	x += vcurc * st->cwidth - 4;
	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 * (st->text->curc - text_find_identifier_start(st->text->curl->line, st->text->curc));

	boxw = SUGG_LIST_WIDTH * st->cwidth + 20;
	boxh = SUGG_LIST_SIZE * lheight + 8;
	
	if (x + boxw > ar->winx)
		x = MAX2(0, ar->winx - boxw);

	/* not needed but stands out nicer */
	uiDrawBoxShadow(220, x, y - boxh, x + boxw, y);

	UI_ThemeColor(TH_SHADE1);
	glRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1);
	UI_ThemeColorShade(TH_BACK, 16);
	glRecti(x, y, x + boxw, y - boxh);

	/* Set the top 'item' of the visible list */
	for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ;

	for (i = 0; i < SUGG_LIST_SIZE && item; i++, item = item->next) {
		int len = txt_utf8_forward_columns(item->name, SUGG_LIST_WIDTH, NULL) - item->name;

		y -= lheight;

		BLI_strncpy(str, item->name, len + 1);

		w = st->cwidth * text_get_char_pos(st, str, len);
		
		if (item == sel) {
			UI_ThemeColor(TH_SHADE2);
			glRecti(x + margin_x, y - 3, x + margin_x + w, y + lheight - 3);
		}

		format_draw_color(item->type);
		text_draw(st, str, 0, 0, x + margin_x, y - 1, NULL);

		if (item == last) break;
	}
}
Beispiel #3
0
static int text_draw_wrapped(
        const SpaceText *st, const TextDrawContext *tdc,
        const char *str, int x, int y, int w, const char *format, int skip)
{
	const bool use_syntax = (st->showsyntax && format);
	FlattenString fs;
	int basex, lines;
	int i, wrap, end, max, columns, padding; /* column */
	/* warning, only valid when 'use_syntax' is set */
	int a, fstart, fpos;                     /* utf8 chars */
	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);

	flatten_string(st, &fs, str);
	str = fs.buf;
	max = w / st->cwidth;
	if (max < 8) max = 8;
	basex = x;
	lines = 1;
	
	fpos = fstart = 0; mstart = 0;
	mend = txt_utf8_forward_columns(str, max, &padding) - str;
	end = wrap = max - padding;
	
	for (i = 0, mi = 0; str[mi]; i += columns, mi += BLI_str_utf8_size_safe(str + mi)) {
		columns = BLI_str_utf8_char_width_safe(str + mi);
		if (i + columns > end) {
			/* skip hidden part of line */
			if (skip) {
				skip--;
				if (use_syntax) {
					/* currently fpos only used when formatting */
					fpos += BLI_strnlen_utf8(str + mstart, mend - mstart);
				}
				fstart = fpos; mstart = mend;
				mend = txt_utf8_forward_columns(str + mend, max, &padding) - str;
				end = (wrap += max - padding);
				continue;
			}

			/* Draw the visible portion of text on the overshot line */
			for (a = fstart, ma = mstart; ma < mend; a++, ma += BLI_str_utf8_size_safe(str + ma)) {
				if (use_syntax) {
					if (fmt_prev != format[a]) format_draw_color(fmt_prev = format[a]);
				}
				x += text_font_draw_character_utf8(tdc, x, y, str + ma);
				fpos++;
			}
			y -= st->lheight_dpi + TXT_LINE_SPACING;
			x = basex;
			lines++;
			fstart = fpos; mstart = mend;
			mend = txt_utf8_forward_columns(str + mend, max, &padding) - str;
			end = (wrap += max - padding);

			if (y <= clip_min_y)
				break;
		}
		else if (str[mi] == ' ' || str[mi] == '-') {
			wrap = i + 1; mend = mi + 1;
		}
	}

	/* Draw the remaining text */
	for (a = fstart, ma = mstart; str[ma] && y > clip_min_y; a++, ma += BLI_str_utf8_size_safe(str + ma)) {
		if (use_syntax) {
			if (fmt_prev != format[a]) format_draw_color(fmt_prev = format[a]);
		}

		x += text_font_draw_character_utf8(tdc, x, y, str + ma);
	}

	flatten_string_free(&fs);

	return lines;
}