Esempio n. 1
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);
}
Esempio n. 2
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);
}