Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-08-11 09:21:43 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-08-11 09:21:43 +0400
commitd739a1788d338795039530c2d6503b93ab805161 (patch)
treedff0da4b00dfa597811ea531527ea735ca496067 /source/blender
parent8c393269622bf250ec9b0fbd3e689b534ad1e1ec (diff)
small edits to text editor from writing a python editor extension.
- rename TextLine.line -> body, ConsoleLine.line -> body - minor speedups when setting the body text, also re-allocate console lines if they are < half the length. - added option to highlight current line in the text editor.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/editors/space_image/image_ops.c1
-rw-r--r--source/blender/editors/space_text/text_draw.c16
-rw-r--r--source/blender/makesdna/DNA_space_types.h3
-rw-r--r--source/blender/makesrna/intern/rna_space.c51
-rw-r--r--source/blender/makesrna/intern/rna_text.c18
5 files changed, 55 insertions, 34 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index fc1a5f345ae..314d5dd9043 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -747,7 +747,6 @@ static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
}
if (ima==NULL) {
- SpaceButs *sbuts= CTX_wm_space_buts(C);
Tex *tex= CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
if(tex && tex->type==TEX_IMAGE)
ima= tex->ima;
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index 926ccc1914a..6fbfc463c45 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -1101,6 +1101,20 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
}
}
+ if(st->line_hlight) {
+ /* TODO, dont draw if hidden */
+ 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, 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;
@@ -1288,7 +1302,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);
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index e5308cccdfe..c365d33a9a4 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -303,7 +303,8 @@ typedef struct SpaceText {
int showlinenrs;
int tabnumber;
- int showsyntax;
+ short showsyntax;
+ short line_hlight;
short overwrite;
short live_edit; /* run python while editing, evil */
float pix_per_line;
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 436e9f60dc7..d72eb25dd2f 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -567,31 +567,30 @@ static void rna_SpaceProperties_align_set(PointerRNA *ptr, int value)
}
/* Space Console */
-static void rna_ConsoleLine_line_get(PointerRNA *ptr, char *value)
+static void rna_ConsoleLine_body_get(PointerRNA *ptr, char *value)
{
ConsoleLine *ci= (ConsoleLine*)ptr->data;
strcpy(value, ci->line);
}
-static int rna_ConsoleLine_line_length(PointerRNA *ptr)
+static int rna_ConsoleLine_body_length(PointerRNA *ptr)
{
ConsoleLine *ci= (ConsoleLine*)ptr->data;
return ci->len;
}
-static void rna_ConsoleLine_line_set(PointerRNA *ptr, const char *value)
+static void rna_ConsoleLine_body_set(PointerRNA *ptr, const char *value)
{
ConsoleLine *ci= (ConsoleLine*)ptr->data;
int len= strlen(value);
- if(len < ci->len_alloc) { /* allocated size is enough? */
- strcpy(ci->line, value);
- }
- else { /* allocate a new strnig */
+ if((len >= ci->len_alloc) || (len * 2 < ci->len_alloc) ) { /* allocate a new strnig */
MEM_freeN(ci->line);
- ci->line= BLI_strdup(value);
- ci->len_alloc= len;
+ ci->line= MEM_mallocN((len + 1) * sizeof(char), "rna_consoleline");
+ ci->len_alloc= len + 1;
}
+
+ memcpy(ci->line, value, len + 1);
ci->len= len;
if(ci->cursor > len) /* clamp the cursor */
@@ -1536,31 +1535,28 @@ static void rna_def_space_text(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
/* display */
- prop= RNA_def_property(srna, "syntax_highlight", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "showsyntax", 0);
- RNA_def_property_ui_text(prop, "Syntax Highlight", "Syntax highlight for scripting");
- RNA_def_property_ui_icon(prop, ICON_SYNTAX_OFF, 1);
- RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
-
- prop= RNA_def_property(srna, "word_wrap", PROP_BOOLEAN, PROP_NONE);
+ prop= RNA_def_property(srna, "show_word_wrap", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "wordwrap", 0);
RNA_def_property_boolean_funcs(prop, NULL, "rna_SpaceTextEditor_word_wrap_set");
RNA_def_property_ui_text(prop, "Word Wrap", "Wrap words if there is not enough horizontal space");
RNA_def_property_ui_icon(prop, ICON_WORDWRAP_OFF, 1);
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
- prop= RNA_def_property(srna, "line_numbers", PROP_BOOLEAN, PROP_NONE);
+ prop= RNA_def_property(srna, "show_line_numbers", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "showlinenrs", 0);
RNA_def_property_ui_text(prop, "Line Numbers", "Show line numbers next to the text");
RNA_def_property_ui_icon(prop, ICON_LINENUMBERS_OFF, 1);
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
- prop= RNA_def_property(srna, "overwrite", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_ui_text(prop, "Overwrite", "Overwrite characters when typing rather than inserting them");
+ prop= RNA_def_property(srna, "show_syntax_highlight", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "showsyntax", 0);
+ RNA_def_property_ui_text(prop, "Syntax Highlight", "Syntax highlight for scripting");
+ RNA_def_property_ui_icon(prop, ICON_SYNTAX_OFF, 1);
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
- prop= RNA_def_property(srna, "live_edit", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_ui_text(prop, "Live Edit", "Run python while editing");
+ prop= RNA_def_property(srna, "show_line_highlight", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "line_hlight", 0);
+ RNA_def_property_ui_text(prop, "Highlight Line", "Highlight the current line");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
prop= RNA_def_property(srna, "tab_width", PROP_INT, PROP_NONE);
@@ -1575,6 +1571,15 @@ static void rna_def_space_text(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Font Size", "Font size to use for displaying the text");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
+ /* functionality options */
+ prop= RNA_def_property(srna, "overwrite", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Overwrite", "Overwrite characters when typing rather than inserting them");
+ RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
+
+ prop= RNA_def_property(srna, "live_edit", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Live Edit", "Run python while editing");
+ RNA_def_property_update(prop, NC_SPACE|ND_SPACE_TEXT, NULL);
+
/* find */
prop= RNA_def_property(srna, "find_all", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", ST_FIND_ALL);
@@ -1925,8 +1930,8 @@ static void rna_def_console_line(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "Console Input", "Input line for the interactive console");
// XXX using non-inited "prop", uh? RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CONSOLE, NULL);
- prop= RNA_def_property(srna, "line", PROP_STRING, PROP_NONE);
- RNA_def_property_string_funcs(prop, "rna_ConsoleLine_line_get", "rna_ConsoleLine_line_length", "rna_ConsoleLine_line_set");
+ prop= RNA_def_property(srna, "body", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_ConsoleLine_body_get", "rna_ConsoleLine_body_length", "rna_ConsoleLine_body_set");
RNA_def_property_ui_text(prop, "Line", "Text in the line");
RNA_def_property_update(prop, NC_SPACE|ND_SPACE_CONSOLE, NULL);
diff --git a/source/blender/makesrna/intern/rna_text.c b/source/blender/makesrna/intern/rna_text.c
index d8651e5d05d..e8d1422d045 100644
--- a/source/blender/makesrna/intern/rna_text.c
+++ b/source/blender/makesrna/intern/rna_text.c
@@ -76,7 +76,7 @@ static int rna_Text_modified_get(PointerRNA *ptr)
return text_file_modified(text);
}
-static void rna_TextLine_line_get(PointerRNA *ptr, char *value)
+static void rna_TextLine_body_get(PointerRNA *ptr, char *value)
{
TextLine *line= (TextLine*)ptr->data;
@@ -86,21 +86,23 @@ static void rna_TextLine_line_get(PointerRNA *ptr, char *value)
strcpy(value, "");
}
-static int rna_TextLine_line_length(PointerRNA *ptr)
+static int rna_TextLine_body_length(PointerRNA *ptr)
{
TextLine *line= (TextLine*)ptr->data;
return line->len;
}
-static void rna_TextLine_line_set(PointerRNA *ptr, const char *value)
+static void rna_TextLine_body_set(PointerRNA *ptr, const char *value)
{
TextLine *line= (TextLine*)ptr->data;
+ int len= strlen(value);
if(line->line)
MEM_freeN(line->line);
-
- line->line= BLI_strdup(value);
- line->len= strlen(line->line);
+
+ line->line= MEM_mallocN((len + 1) * sizeof(char), "rna_text_body");
+ line->len= len;
+ memcpy(line->line, value, len + 1);
if(line->format) {
MEM_freeN(line->format);
@@ -118,8 +120,8 @@ static void rna_def_text_line(BlenderRNA *brna)
srna = RNA_def_struct(brna, "TextLine", NULL);
RNA_def_struct_ui_text(srna, "Text Line", "Line of text in a Text datablock");
- prop= RNA_def_property(srna, "line", PROP_STRING, PROP_NONE);
- RNA_def_property_string_funcs(prop, "rna_TextLine_line_get", "rna_TextLine_line_length", "rna_TextLine_line_set");
+ prop= RNA_def_property(srna, "body", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_TextLine_body_get", "rna_TextLine_body_length", "rna_TextLine_body_set");
RNA_def_property_ui_text(prop, "Line", "Text in the line");
RNA_def_property_update(prop, NC_TEXT|NA_EDITED, NULL);
}