示例#1
0
static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int draw, int x, int y, char *format)
{
	FlattenString fs;
	int r=0, w= 0, amount;
	int *acc;
	char *in;

	w= flatten_string(st, &fs, str);
	if(w < cshift) {
		flatten_string_free(&fs);
		return 0; /* String is shorter than shift */
	}
	
	in= fs.buf+cshift;
	acc= fs.accum+cshift;
	w= w-cshift;

	if(draw) {
		if(st->showsyntax && format) {
			int a;
			format = format+cshift;
		
			amount = strlen(in);
			if(maxwidth)
				amount= MIN2(amount, maxwidth);
			
			for(a = 0; a < amount; a++) {
				format_draw_color(format[a]);
				x += text_font_draw_character(st, x, y, in[a]);
			}
		}
		else {
			amount = strlen(in);
			if(maxwidth)
				amount= MIN2(amount, maxwidth);

			in[amount]= 0;
			text_font_draw(st, x, y, in);
		}
	}
	else {
		while(w-- && *acc++ < maxwidth)
			r+= st->cwidth;
	}

	flatten_string_free(&fs);

	if(cshift && r==0)
		return 0;
	else if(st->showlinenrs)
		return r+TXT_OFFSET+TEXTXLOC;
	else
		return r+TXT_OFFSET;
}
示例#2
0
static void text_draw(
        const SpaceText *st, const TextDrawContext *tdc,
        char *str, int cshift, int maxwidth, int x, int y, const char *format)
{
	const bool use_syntax = (st->showsyntax && format);
	FlattenString fs;
	int columns, size, n, w = 0, padding, amount = 0;
	const char *in = NULL;

	for (n = flatten_string(st, &fs, str), str = fs.buf; n > 0; n--) {
		columns = BLI_str_utf8_char_width_safe(str);
		size = BLI_str_utf8_size_safe(str);

		if (!in) {
			if (w >= cshift) {
				padding = w - cshift;
				in = str;
			}
			else if (format)
				format++;
		}
		if (in) {
			if (maxwidth && w + columns > cshift + maxwidth)
				break;
			amount++;
		}

		w += columns;
		str += size;
	}
	if (!in) {
		flatten_string_free(&fs);
		return; /* String is shorter than shift or ends with a padding */
	}

	x += tdc->cwidth * padding;

	if (use_syntax) {
		int a, str_shift = 0;
		char fmt_prev = 0xff;

		for (a = 0; a < amount; a++) {
			if (format[a] != fmt_prev) format_draw_color(fmt_prev = format[a]);
			x += text_font_draw_character_utf8(tdc, x, y, in + str_shift);
			str_shift += BLI_str_utf8_size_safe(in + str_shift);
		}
	}
	else {
		text_font_draw(tdc, x, y, in);
	}

	flatten_string_free(&fs);
}
示例#3
0
void draw_text_main(SpaceText *st, ARegion *ar)
{
	Text *text = st->text;
	TextFormatType *tft;
	TextLine *tmp;
	rcti scroll, back;
	char linenr[12];
	int i, x, y, winx, linecount = 0, lineno = 0;
	int wraplinecount = 0, wrap_skip = 0;
	int margin_column_x;

	/* if no text, nothing to do */
	if (!text)
		return;

	/* dpi controlled line height and font size */
	st->lheight_dpi = (U.widget_unit * st->lheight) / 20;
	st->viewlines = (st->lheight_dpi) ? (int)ar->winy / (st->lheight_dpi + TXT_LINE_SPACING) : 0;
	
	text_update_drawcache(st, ar);

	/* make sure all the positional pointers exist */
	if (!text->curl || !text->sell || !text->lines.first || !text->lines.last)
		txt_clean_text(text);
	
	/* update rects for scroll */
	calc_text_rcts(st, ar, &scroll, &back); /* scroll will hold the entire bar size */

	/* update syntax formatting if needed */
	tft = ED_text_format_get(text);
	tmp = text->lines.first;
	lineno = 0;
	for (i = 0; i < st->top && tmp; i++) {
		if (st->showsyntax && !tmp->format)
			tft->format_line(st, tmp, 0);

		if (st->wordwrap) {
			int lines = text_get_visible_lines_no(st, lineno);

			if (wraplinecount + lines > st->top) {
				wrap_skip = st->top - wraplinecount;
				break;
			}
			else {
				wraplinecount += lines;
				tmp = tmp->next;
				linecount++;
			}
		}
		else {
			tmp = tmp->next;
			linecount++;
		}

		lineno++;
	}

	text_font_begin(st);
	st->cwidth = BLF_fixed_width(mono);
	st->cwidth = MAX2(st->cwidth, (char)1);

	/* draw line numbers background */
	if (st->showlinenrs) {
		x = TXT_OFFSET + TEXTXLOC;

		UI_ThemeColor(TH_GRID);
		glRecti((TXT_OFFSET - 12), 0, (TXT_OFFSET - 5) + TEXTXLOC, ar->winy - 2);
	}
	else {
		st->linenrs_tot = 0; /* not used */
		x = TXT_OFFSET;
	}
	y = ar->winy - st->lheight_dpi;
	winx = ar->winx - TXT_SCROLL_WIDTH;
	
	/* draw cursor */
	draw_cursor(st, ar);

	/* draw the text */
	UI_ThemeColor(TH_TEXT);

	for (i = 0; y > 0 && i < st->viewlines && tmp; i++, tmp = tmp->next) {
		if (st->showsyntax && !tmp->format)
			tft->format_line(st, tmp, 0);

		if (st->showlinenrs && !wrap_skip) {
			/* draw line number */
			if (tmp == text->curl)
				UI_ThemeColor(TH_HILITE);
			else
				UI_ThemeColor(TH_TEXT);

			BLI_snprintf(linenr, sizeof(linenr), "%*d", st->linenrs_tot, i + linecount + 1);
			/* itoa(i + linecount + 1, linenr, 10); */ /* not ansi-c :/ */
			text_font_draw(st, TXT_OFFSET - 7, y, linenr);

			UI_ThemeColor(TH_TEXT);
		}

		if (st->wordwrap) {
			/* draw word wrapped text */
			int lines = text_draw_wrapped(st, tmp->line, x, y, winx - x, tmp->format, wrap_skip);
			y -= lines * (st->lheight_dpi + TXT_LINE_SPACING);
		}
		else {
			/* draw unwrapped text */
			text_draw(st, tmp->line, st->left, ar->winx / st->cwidth, x, y, tmp->format);
			y -= st->lheight_dpi + TXT_LINE_SPACING;
		}
		
		wrap_skip = 0;
	}
	
	if (st->flags & ST_SHOW_MARGIN) {
		UI_ThemeColor(TH_HILITE);

		margin_column_x = x + st->cwidth * (st->margin_column - st->left);
		
		if (margin_column_x >= x) {
			glBegin(GL_LINES);
			glVertex2i(margin_column_x, 0);
			glVertex2i(margin_column_x, ar->winy - 2);
			glEnd();
		}
	}

	/* draw other stuff */
	draw_brackets(st, ar);
	glTranslatef(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0f); /* XXX scroll requires exact pixel space */
	draw_textscroll(st, &scroll, &back);
	draw_documentation(st, ar);
	draw_suggestion_list(st, ar);
	
	text_font_end(st);
}
示例#4
0
void draw_text_main(SpaceText *st, ARegion *ar)
{
	Text *text= st->text;
	TextLine *tmp;
	rcti scroll, back;
	char linenr[12];
	int i, x, y, winx, linecount= 0, lineno= 0;
	int wraplinecount= 0, wrap_skip= 0;

	/* if no text, nothing to do */
	if(!text)
		return;
	
	text_update_drawcache(st, ar);

	/* make sure all the positional pointers exist */
	if(!text->curl || !text->sell || !text->lines.first || !text->lines.last)
		txt_clean_text(text);
	
	if(st->lheight) st->viewlines= (int)ar->winy/st->lheight;
	else st->viewlines= 0;
	
	/* update rects for scroll */
	calc_text_rcts(st, ar, &scroll, &back);	/* scroll will hold the entire bar size */

	/* update syntax formatting if needed */
	tmp= text->lines.first;
	lineno= 0;
	for(i= 0; i<st->top && tmp; i++) {
		if(st->showsyntax && !tmp->format)
			txt_format_line(st, tmp, 0);

		if(st->wordwrap) {
			int lines= text_get_visible_lines_no(st, lineno);

			if (wraplinecount+lines>st->top) {
				wrap_skip= st->top-wraplinecount;
				break;
			} else {
				wraplinecount+= lines;
				tmp= tmp->next;
				linecount++;
			}
		} else {
			tmp= tmp->next;
			linecount++;
		}

		lineno++;
	}

	text_font_begin(st);
	st->cwidth= BLF_fixed_width(mono);
	st->cwidth= MAX2(st->cwidth, 1);

	/* draw line numbers background */
	if(st->showlinenrs) {
		x= TXT_OFFSET + TEXTXLOC;

		UI_ThemeColor(TH_GRID);
		glRecti((TXT_OFFSET-12), 0, (TXT_OFFSET-5) + TEXTXLOC, ar->winy - 2);
	}
	else {
		st->linenrs_tot= 0; /* not used */
		x= TXT_OFFSET;
	}
	y= ar->winy-st->lheight;
	winx= ar->winx - TXT_SCROLL_WIDTH;
	
	/* draw cursor */
	draw_cursor(st, ar);

	/* draw the text */
	UI_ThemeColor(TH_TEXT);

	for(i=0; y>0 && i<st->viewlines && tmp; i++, tmp= tmp->next) {
		if(st->showsyntax && !tmp->format)
			txt_format_line(st, tmp, 0);

		if(st->showlinenrs && !wrap_skip) {
			/* draw line number */
			if(tmp == text->curl)
				UI_ThemeColor(TH_HILITE);
			else
				UI_ThemeColor(TH_TEXT);

			sprintf(linenr, "%d", i + linecount + 1);
			/* itoa(i + linecount + 1, linenr, 10); */ /* not ansi-c :/ */
			text_font_draw(st, TXT_OFFSET - 7, y, linenr);

			UI_ThemeColor(TH_TEXT);
		}

		if(st->wordwrap) {
			/* draw word wrapped text */
			int lines = text_draw_wrapped(st, tmp->line, x, y, winx-x, tmp->format, wrap_skip);
			y -= lines*st->lheight;
		}
		else {
			/* draw unwrapped text */
			text_draw(st, tmp->line, st->left, ar->winx/st->cwidth, 1, x, y, tmp->format);
			y -= st->lheight;
		}

		wrap_skip= 0;
	}
	
	/* draw other stuff */
	draw_brackets(st, ar);
	draw_markers(st, ar);
	glTranslatef(0.375f, 0.375f, 0.0f); /* XXX scroll requires exact pixel space */
	draw_textscroll(st, &scroll, &back);
	draw_documentation(st, ar);
	draw_suggestion_list(st, ar);
	
	text_font_end(st);
}