diff options
Diffstat (limited to 'source/blender/editors/space_text/text_draw.c')
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 99 |
1 files changed, 68 insertions, 31 deletions
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 873deb30511..62274fc664a 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -44,14 +44,11 @@ #include "DNA_userdef_types.h" #include "BKE_context.h" -#include "BKE_global.h" -#include "BKE_main.h" #include "BKE_suggestions.h" #include "BKE_text.h" #include "BKE_utildefines.h" #include "BIF_gl.h" -#include "BIF_glutil.h" #include "ED_datafiles.h" #include "UI_interface.h" @@ -113,8 +110,8 @@ static void flatten_string_append(FlattenString *fs, char c, int accum) nbuf= MEM_callocN(sizeof(*fs->buf)*fs->len, "fs->buf"); naccum= MEM_callocN(sizeof(*fs->accum)*fs->len, "fs->accum"); - memcpy(nbuf, fs->buf, fs->pos); - memcpy(naccum, fs->accum, fs->pos); + memcpy(nbuf, fs->buf, fs->pos * sizeof(*fs->buf)); + memcpy(naccum, fs->accum, fs->pos * sizeof(*fs->accum)); if(fs->buf != fs->fixedbuf) { MEM_freeN(fs->buf); @@ -174,12 +171,13 @@ void flatten_string_free(FlattenString *fs) static int find_builtinfunc(char *string) { int a, i; - char builtinfuncs[][11] = {"and", "as", "assert", "break", "class", "continue", "def", + char builtinfuncs[][9] = {"and", "as", "assert", "break", "class", "continue", "def", "del", "elif", "else", "except", "exec", "finally", "for", "from", "global", "if", "import", "in", "is", "lambda", "not", "or", "pass", "print", - "raise", "return", "try", "while", "yield"}; - for(a=0; a<30; a++) { + "raise", "return", "try", "while", "yield", "with"}; + + for(a=0; a < sizeof(builtinfuncs)/sizeof(builtinfuncs[0]); a++) { i = 0; while(1) { /* If we hit the end of a keyword... (eg. "def") */ @@ -224,6 +222,18 @@ static int find_specialvar(char *string) return i; } +static int find_decorator(char *string) +{ + if(string[0] == '@') { + int i = 1; + while(text_check_identifier(string[i])) { + i++; + } + return i; + } + return -1; +} + static int find_bool(char *string) { int i = 0; @@ -377,6 +387,8 @@ static void txt_format_line(SpaceText *st, TextLine *line, int do_next) prev = 'v'; else if((i=find_builtinfunc(str)) != -1) prev = 'b'; + else if((i=find_decorator(str)) != -1) + prev = 'v'; /* could have a new color for this */ if(i>0) { while(i>1) { *fmt = prev; fmt++; str++; @@ -1102,6 +1114,22 @@ static void draw_cursor(SpaceText *st, ARegion *ar) } } + if(st->line_hlight) { + y= ar->winy-2 - vsell*st->lheight; + if(!(y<0 || y > ar->winy)) { /* check we need to draw */ + int x1= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; + int x2= x1 + ar->winx; + y= ar->winy-2 - vsell*st->lheight; + + glColor4ub(255, 255, 255, 32); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glRecti(x1-4, y, x2, y-st->lheight+1); + glDisable(GL_BLEND); + } + } + if(!hidden) { /* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */ x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET; @@ -1132,7 +1160,8 @@ static void draw_brackets(SpaceText *st, ARegion *ar) int viewc, viewl, offl, offc, x, y; char ch; - if(!text->curl) return; + // showsyntax must be on or else the format string will be null + if(!text->curl || !st->showsyntax) return; startl= text->curl; startc= text->curc; @@ -1146,23 +1175,29 @@ static void draw_brackets(SpaceText *st, ARegion *ar) 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) { - b= text_check_bracket(linep->line[c]); - if(b==find) { - if(stack==0) { - endl= linep; - endc= c; - break; + 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++; } - stack--; - } - else if(b==-find) { - stack++; } c++; } @@ -1176,17 +1211,19 @@ static void draw_brackets(SpaceText *st, ARegion *ar) c--; while(linep) { while(c>=0) { - b= text_check_bracket(linep->line[c]); - if(b==find) { - if(stack==0) { - endl= linep; - endc= c; - break; + 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++; } - stack--; - } - else if(b==-find) { - stack++; } c--; } @@ -1280,7 +1317,7 @@ void draw_text_main(SpaceText *st, ARegion *ar) } y= ar->winy-st->lheight; winx= ar->winx - TXT_SCROLL_WIDTH; - + /* draw cursor */ draw_cursor(st, ar); @@ -1348,7 +1385,7 @@ void text_update_cursor_moved(bContext *C) ARegion *ar; int i, x, winx= 0; - if(!st || !st->text || st->text->curl) return; + if(ELEM3(NULL, st, st->text, st->text->curl)) return; text= st->text; |