Esempio n. 1
0
static int text_draw_wrapped(SpaceText *st, char *str, int x, int y, int w, char *format, int skip)
{
	FlattenString fs;
	int basex, i, a, len, start, end, max, lines;
	
	len= flatten_string(st, &fs, str);
	str= fs.buf;
	max= w/st->cwidth;
	if(max<8) max= 8;
	basex= x;

	lines= 1;
	start= 0;
	end= max;
	for(i=0; i<len; i++) {
		if(i-start >= max) {
			/* skip hidden part of line */
			if(skip) {
				skip--;
				start= end;
				end += max;
				continue;
			}

			/* Draw the visible portion of text on the overshot line */
			for(a=start; a<end; a++) {
				if(st->showsyntax && format) format_draw_color(format[a]);
				x += text_font_draw_character(st, x, y, str[a]);
			}
			y -= st->lheight;
			x= basex;
			lines++;
			start= end;
			end += max;

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

	/* Draw the remaining text */
	for(a=start; a<len && y > 0; a++) {
		if(st->showsyntax && format)
			format_draw_color(format[a]);

		x += text_font_draw_character(st, x, y, str[a]);
	}

	flatten_string_free(&fs);

	return lines;
}
Esempio n. 2
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;
}
Esempio n. 3
0
static void draw_brackets(SpaceText *st, ARegion *ar)
{
	TextLine *startl, *endl, *linep;
	Text *text = st->text;
	int b, fc, find, stack, viewc, viewl, offl, offc, x, y;
	int startc, endc, c;
	
	char ch;

	// showsyntax must be on or else the format string will be null
	if (!text->curl || !st->showsyntax) return;

	startl = text->curl;
	startc = text->curc;
	b = text_check_bracket(startl->line[startc]);
	if (b == 0 && startc > 0) b = text_check_bracket(startl->line[--startc]);
	if (b == 0) return;

	linep = startl;
	c = startc;
	fc = txt_utf8_offset_to_index(linep->line, startc);
	endl = NULL;
	endc = -1;
	find = -b;
	stack = 0;
	
	/* Don't highlight backets if syntax HL is off or bracket in string or comment. */
	if (!linep->format || linep->format[fc] == FMT_TYPE_STRING || linep->format[fc] == FMT_TYPE_COMMENT)
		return;

	if (b > 0) {
		/* opening bracket, search forward for close */
		fc++;
		c += BLI_str_utf8_size_safe(linep->line + c);
		while (linep) {
			while (c < linep->len) {
				if (linep->format && linep->format[fc] != FMT_TYPE_STRING && linep->format[fc] != FMT_TYPE_COMMENT) {
					b = text_check_bracket(linep->line[c]);
					if (b == find) {
						if (stack == 0) {
							endl = linep;
							endc = c;
							break;
						}
						stack--;
					}
					else if (b == -find) {
						stack++;
					}
				}
				fc++;
				c += BLI_str_utf8_size_safe(linep->line + c);
			}
			if (endl) break;
			linep = linep->next;
			c = 0;
			fc = 0;
		}
	}
	else {
		/* closing bracket, search backward for open */
		fc--;
		if (c > 0) c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c);
		while (linep) {
			while (fc >= 0) {
				if (linep->format && linep->format[fc] != FMT_TYPE_STRING && linep->format[fc] != FMT_TYPE_COMMENT) {
					b = text_check_bracket(linep->line[c]);
					if (b == find) {
						if (stack == 0) {
							endl = linep;
							endc = c;
							break;
						}
						stack--;
					}
					else if (b == -find) {
						stack++;
					}
				}
				fc--;
				if (c > 0) c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c);
			}
			if (endl) break;
			linep = linep->prev;
			if (linep) {
				if (linep->format) fc = strlen(linep->format) - 1;
				else fc = -1;
				if (linep->len) c = BLI_str_prev_char_utf8(linep->line + linep->len) - linep->line;
				else fc = -1;
			}
		}
	}

	if (!endl || endc == -1)
		return;

	UI_ThemeColor(TH_HILITE);
	x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
	y = ar->winy - st->lheight_dpi;

	/* draw opening bracket */
	ch = startl->line[startc];
	wrap_offset(st, ar, startl, startc, &offl, &offc);
	viewc = text_get_char_pos(st, startl->line, startc) - st->left + offc;

	if (viewc >= 0) {
		viewl = txt_get_span(text->lines.first, startl) - st->top + offl;

		text_font_draw_character(st, x + viewc * st->cwidth, y - viewl * (st->lheight_dpi + TXT_LINE_SPACING), ch);
		text_font_draw_character(st, x + viewc * st->cwidth + 1, y - viewl * (st->lheight_dpi + TXT_LINE_SPACING), ch);
	}

	/* draw closing bracket */
	ch = endl->line[endc];
	wrap_offset(st, ar, endl, endc, &offl, &offc);
	viewc = text_get_char_pos(st, endl->line, endc) - st->left + offc;

	if (viewc >= 0) {
		viewl = txt_get_span(text->lines.first, endl) - st->top + offl;

		text_font_draw_character(st, x + viewc * st->cwidth, y - viewl * (st->lheight_dpi + TXT_LINE_SPACING), ch);
		text_font_draw_character(st, x + viewc * st->cwidth + 1, y - viewl * (st->lheight_dpi + TXT_LINE_SPACING), ch);
	}
}
Esempio n. 4
0
static void draw_brackets(SpaceText *st, ARegion *ar)
{
	TextLine *startl, *endl, *linep;
	Text *text = st->text;
	int b, c, startc, endc, find, stack;
	int viewc, viewl, offl, offc, x, y;
	char ch;

	// showsyntax must be on or else the format string will be null
	if(!text->curl || !st->showsyntax) return;

	startl= text->curl;
	startc= text->curc;
	b= text_check_bracket(startl->line[startc]);
	if(b==0 && startc>0) b = text_check_bracket(startl->line[--startc]);
	if(b==0) return;
	
	linep= startl;
	c= startc;
	endl= NULL;
	endc= -1;
	find= -b;
	stack= 0;
	
	/* Dont highlight backets if syntax HL is off or bracket in string or comment. */
	if(!linep->format || linep->format[c] == 'l' || linep->format[c] == '#')
		return;

	if(b>0) {
		/* opening bracket, search forward for close */
		c++;
		while(linep) {
			while(c<linep->len) {
				if(linep->format && linep->format[c] != 'l' && linep->format[c] != '#') {
					b= text_check_bracket(linep->line[c]);
					if(b==find) {
						if(stack==0) {
							endl= linep;
							endc= c;
							break;
						}
						stack--;
					}
					else if(b==-find) {
						stack++;
					}
				}
				c++;
			}
			if(endl) break;
			linep= linep->next;
			c= 0;
		}
	}
	else {
		/* closing bracket, search backward for open */
		c--;
		while(linep) {
			while(c>=0) {
				if(linep->format && linep->format[c] != 'l' && linep->format[c] != '#') {
					b= text_check_bracket(linep->line[c]);
					if(b==find) {
						if(stack==0) {
							endl= linep;
							endc= c;
							break;
						}
						stack--;
					}
					else if(b==-find) {
						stack++;
					}
				}
				c--;
			}
			if(endl) break;
			linep= linep->prev;
			if(linep) c= linep->len-1;
		}
	}

	if(!endl || endc==-1)
		return;

	UI_ThemeColor(TH_HILITE);	
	x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
	y= ar->winy - st->lheight;

	/* draw opening bracket */
	ch= startl->line[startc];
	wrap_offset(st, ar, startl, startc, &offl, &offc);
	viewc= text_get_char_pos(st, startl->line, startc) - st->left + offc;

	if(viewc >= 0){
		viewl= txt_get_span(text->lines.first, startl) - st->top + offl;

		text_font_draw_character(st, x+viewc*st->cwidth, y-viewl*st->lheight, ch);
		text_font_draw_character(st, x+viewc*st->cwidth+1, y-viewl*st->lheight, ch);
	}

	/* draw closing bracket */
	ch= endl->line[endc];
	wrap_offset(st, ar, endl, endc, &offl, &offc);
	viewc= text_get_char_pos(st, endl->line, endc) - st->left + offc;

	if(viewc >= 0) {
		viewl= txt_get_span(text->lines.first, endl) - st->top + offl;

		text_font_draw_character(st, x+viewc*st->cwidth, y-viewl*st->lheight, ch);
		text_font_draw_character(st, x+viewc*st->cwidth+1, y-viewl*st->lheight, ch);
	}
}