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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-07-12 06:06:15 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-07-12 06:06:15 +0400
commit3116062a828e24ed2e91c219ab338a38030f2f42 (patch)
treefe77a0722deaee3afd521b4a596bbe5c1c827b2e /source/blender/editors/space_text
parent8b9bb47a3faf753cb0ca2ec0e9c6a741c7af31c2 (diff)
2.5: Couple of small fun features
* Text window font size now supports full range 8-32, instead of just 12 and 15. I added BLF_fixed_width to get the character width of a fixed size font. * Buttons do undo push on change again. * Animated/Keyframe/Driver colors are now themable, with blend value to blend with original color. Set this to 0.5 now to give colors less constrast. * Fix tooltip popping up with RMB menu open, and missing redraw. * Autokeyframe now works for buttons. * Driver expressions can be edited in place in a button now. (still some refresh issues). * Also made python driver default for the Add Driver function in the RMB button. This way you don't have to open a Graph editor if you just want to type an expression. Also, the default expression then is the current value. * Tooltips now show some extra info, not sure what is good to have, but currently I added: * Shortcut key for operator buttons. * Python struct & property name for RNA buttons. * Expression for driven values. * Value for text/search/pointer buttons.
Diffstat (limited to 'source/blender/editors/space_text')
-rw-r--r--source/blender/editors/space_text/text_draw.c78
-rw-r--r--source/blender/editors/space_text/text_intern.h1
-rw-r--r--source/blender/editors/space_text/text_ops.c16
-rw-r--r--source/blender/editors/space_text/text_python.c8
4 files changed, 62 insertions, 41 deletions
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index f58af47a6bd..adba7ef100a 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -95,13 +95,7 @@ static int text_font_draw_character(SpaceText *st, int x, int y, char c)
BLF_position(x, y, 0);
BLF_draw(str);
- return text_font_width_character(st);
-}
-
-int text_font_width_character(SpaceText *st)
-{
- // XXX need quick BLF function, or cache it somewhere
- return (st->lheight == 12)? 7: 9;
+ return st->cwidth;
}
int text_font_width(SpaceText *st, char *str)
@@ -523,7 +517,7 @@ int wrap_width(SpaceText *st, ARegion *ar)
int x, max;
x= st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
- max= (ar->winx-x)/text_font_width_character(st);
+ max= (ar->winx-x)/st->cwidth;
return max>8 ? max : 8;
}
@@ -615,7 +609,7 @@ static int text_draw_wrapped(SpaceText *st, char *str, int x, int y, int w, char
len= flatten_string(st, &fs, str);
str= fs.buf;
- max= w/text_font_width_character(st);
+ max= w/st->cwidth;
if(max<8) max= 8;
basex= x;
@@ -687,7 +681,7 @@ static int text_draw(SpaceText *st, char *str, int cshift, int maxwidth, int dra
}
else {
while(w-- && *acc++ < maxwidth)
- r+= text_font_width_character(st);
+ r+= st->cwidth;
}
flatten_string_free(&fs);
@@ -877,18 +871,18 @@ static void draw_markers(SpaceText *st, ARegion *ar)
if(y1==y2) {
y -= y1*st->lheight;
glBegin(GL_LINE_LOOP);
- glVertex2i(x+x2*text_font_width_character(st)+1, y);
- glVertex2i(x+x1*text_font_width_character(st)-2, y);
- glVertex2i(x+x1*text_font_width_character(st)-2, y-st->lheight);
- glVertex2i(x+x2*text_font_width_character(st)+1, y-st->lheight);
+ glVertex2i(x+x2*st->cwidth+1, y);
+ glVertex2i(x+x1*st->cwidth-2, y);
+ glVertex2i(x+x1*st->cwidth-2, y-st->lheight);
+ glVertex2i(x+x2*st->cwidth+1, y-st->lheight);
glEnd();
}
else {
y -= y1*st->lheight;
glBegin(GL_LINE_STRIP);
glVertex2i(ar->winx, y);
- glVertex2i(x+x1*text_font_width_character(st)-2, y);
- glVertex2i(x+x1*text_font_width_character(st)-2, y-st->lheight);
+ glVertex2i(x+x1*st->cwidth-2, y);
+ glVertex2i(x+x1*st->cwidth-2, y-st->lheight);
glVertex2i(ar->winx, y-st->lheight);
glEnd();
y-=st->lheight;
@@ -905,8 +899,8 @@ static void draw_markers(SpaceText *st, ARegion *ar)
glBegin(GL_LINE_STRIP);
glVertex2i(x, y);
- glVertex2i(x+x2*text_font_width_character(st)+1, y);
- glVertex2i(x+x2*text_font_width_character(st)+1, y-st->lheight);
+ glVertex2i(x+x2*st->cwidth+1, y);
+ glVertex2i(x+x2*st->cwidth+1, y-st->lheight);
glVertex2i(x, y-st->lheight);
glEnd();
}
@@ -940,18 +934,18 @@ static void draw_documentation(SpaceText *st, ARegion *ar)
if(l<0) return;
if(st->showlinenrs) {
- x= text_font_width_character(st)*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
+ x= st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
- x= text_font_width_character(st)*(st->text->curc-st->left) + TXT_OFFSET - 4;
+ x= st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
}
if(texttool_suggest_first()) {
- x += SUGG_LIST_WIDTH*text_font_width_character(st) + 50;
+ x += SUGG_LIST_WIDTH*st->cwidth + 50;
}
top= y= ar->winy - st->lheight*l - 2;
len= strlen(docs);
- boxw= DOC_WIDTH*text_font_width_character(st) + 20;
+ boxw= DOC_WIDTH*st->cwidth + 20;
boxh= (DOC_HEIGHT+1)*st->lheight;
/* Draw panel */
@@ -1034,14 +1028,14 @@ static void draw_suggestion_list(SpaceText *st, ARegion *ar)
if(l<0) return;
if(st->showlinenrs) {
- x = text_font_width_character(st)*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
+ x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
- x = text_font_width_character(st)*(st->text->curc-st->left) + TXT_OFFSET - 4;
+ x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
}
y = ar->winy - st->lheight*l - 2;
- boxw = SUGG_LIST_WIDTH*text_font_width_character(st) + 20;
+ boxw = SUGG_LIST_WIDTH*st->cwidth + 20;
boxh = SUGG_LIST_SIZE*st->lheight + 8;
UI_ThemeColor(TH_SHADE1);
@@ -1111,9 +1105,9 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
if(vcurl==vsell) {
y -= vcurl*st->lheight;
if(vcurc < vselc)
- glRecti(x+vcurc*text_font_width_character(st)-1, y, x+vselc*text_font_width_character(st), y-st->lheight);
+ glRecti(x+vcurc*st->cwidth-1, y, x+vselc*st->cwidth, y-st->lheight);
else
- glRecti(x+vselc*text_font_width_character(st)-1, y, x+vcurc*text_font_width_character(st), y-st->lheight);
+ glRecti(x+vselc*st->cwidth-1, y, x+vcurc*st->cwidth, y-st->lheight);
}
else {
int froml, fromc, tol, toc;
@@ -1128,11 +1122,11 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
}
y -= froml*st->lheight;
- glRecti(x+fromc*text_font_width_character(st)-1, y, ar->winx, y-st->lheight); y-=st->lheight;
+ glRecti(x+fromc*st->cwidth-1, y, ar->winx, y-st->lheight); y-=st->lheight;
for(i=froml+1; i<tol; i++)
glRecti(x-4, y, ar->winx, y-st->lheight), y-=st->lheight;
- glRecti(x-4, y, x+toc*text_font_width_character(st), y-st->lheight); y-=st->lheight;
+ glRecti(x-4, y, x+toc*st->cwidth, y-st->lheight); y-=st->lheight;
}
}
else {
@@ -1149,13 +1143,13 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
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;
- x += vselc*text_font_width_character(st);
+ x += vselc*st->cwidth;
y= ar->winy-2 - vsell*st->lheight;
if(st->overwrite) {
char ch= text->sell->line[text->selc];
if(!ch) ch= ' ';
- w= text_font_width_character(st);
+ w= st->cwidth;
UI_ThemeColor(TH_HILITE);
glRecti(x, y-st->lheight-1, x+w, y-st->lheight+1);
}
@@ -1255,8 +1249,8 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
if(viewc >= 0){
viewl= txt_get_span(text->lines.first, startl) - st->top + offl;
- text_font_draw_character(st, x+viewc*text_font_width_character(st), y-viewl*st->lheight, ch);
- text_font_draw_character(st, x+viewc*text_font_width_character(st)+1, y-viewl*st->lheight, ch);
+ 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 */
@@ -1267,8 +1261,8 @@ static void draw_brackets(SpaceText *st, ARegion *ar)
if(viewc >= 0) {
viewl= txt_get_span(text->lines.first, endl) - st->top + offl;
- text_font_draw_character(st, x+viewc*text_font_width_character(st), y-viewl*st->lheight, ch);
- text_font_draw_character(st, x+viewc*text_font_width_character(st)+1, y-viewl*st->lheight, ch);
+ 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);
}
}
@@ -1313,6 +1307,8 @@ void draw_text_main(SpaceText *st, ARegion *ar)
}
text_font_begin(st);
+ st->cwidth= BLF_fixed_width();
+ st->cwidth= MAX2(st->cwidth, 1);
/* draw cursor */
draw_cursor(st, ar);
@@ -1371,6 +1367,14 @@ void draw_text_main(SpaceText *st, ARegion *ar)
/************************** update ***************************/
+void text_update_character_width(SpaceText *st)
+{
+ text_font_begin(st);
+ st->cwidth= BLF_fixed_width();
+ st->cwidth= MAX2(st->cwidth, 1);
+ text_font_end(st);
+}
+
/* Moves the view to the cursor location,
also used to make sure the view isnt outside the file */
void text_update_cursor_moved(SpaceText *st, ARegion *ar)
@@ -1380,6 +1384,8 @@ void text_update_cursor_moved(SpaceText *st, ARegion *ar)
if(!text || !text->curl) return;
+ text_update_character_width(st);
+
i= txt_get_span(text->lines.first, text->sell);
if(st->top+st->viewlines <= i || st->top > i)
st->top= i - st->viewlines/2;
@@ -1391,7 +1397,7 @@ void text_update_cursor_moved(SpaceText *st, ARegion *ar)
x= text_draw(st, text->sell->line, st->left, text->selc, 0, 0, 0, NULL);
if(x==0 || x>ar->winx)
- st->left= text->curc-0.5*(ar->winx)/text_font_width_character(st);
+ st->left= text->curc-0.5*(ar->winx)/st->cwidth;
}
if(st->top < 0) st->top= 0;
diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h
index 31d29ac7f17..5ea33e1660d 100644
--- a/source/blender/editors/space_text/text_intern.h
+++ b/source/blender/editors/space_text/text_intern.h
@@ -55,6 +55,7 @@ int text_font_width(struct SpaceText *st, char *str);
void text_update_line_edited(struct Text *text, struct TextLine *line);
void text_update_edited(struct Text *text);
+void text_update_character_width(struct SpaceText *st);
void text_update_cursor_moved(struct SpaceText *st, struct ARegion *ar);
#define TEXTXLOC 38
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 5568900e621..f9485f17bdc 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -1289,6 +1289,8 @@ static void wrap_move_bol(SpaceText *st, ARegion *ar, short sel)
Text *text= st->text;
int offl, offc, lin;
+ text_update_character_width(st);
+
lin= txt_get_span(text->lines.first, text->sell);
wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
@@ -1307,6 +1309,8 @@ static void wrap_move_eol(SpaceText *st, ARegion *ar, short sel)
Text *text= st->text;
int offl, offc, lin, startl, c;
+ text_update_character_width(st);
+
lin= txt_get_span(text->lines.first, text->sell);
wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
startl= offl;
@@ -1331,6 +1335,8 @@ static void wrap_move_up(SpaceText *st, ARegion *ar, short sel)
Text *text= st->text;
int offl, offl_1, offc, fromline, toline, c, target;
+ text_update_character_width(st);
+
wrap_offset(st, ar, text->sell, 0, &offl_1, &offc);
wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
fromline= toline= txt_get_span(text->lines.first, text->sell);
@@ -1376,6 +1382,8 @@ static void wrap_move_down(SpaceText *st, ARegion *ar, short sel)
Text *text= st->text;
int offl, startoff, offc, fromline, toline, c, target;
+ text_update_character_width(st);
+
wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
fromline= toline= txt_get_span(text->lines.first, text->sell);
target= text->selc + offc;
@@ -1754,6 +1762,8 @@ static void scroll_apply(bContext *C, wmOperator *op, wmEvent *event)
TextScroll *tsc= op->customdata;
short *mval= event->mval;
+ text_update_character_width(st);
+
if(tsc->first) {
tsc->old[0]= mval[0];
tsc->old[1]= mval[1];
@@ -1763,7 +1773,7 @@ static void scroll_apply(bContext *C, wmOperator *op, wmEvent *event)
}
if(!tsc->scrollbar) {
- tsc->delta[0]= (tsc->hold[0]-mval[0])/text_font_width_character(st);
+ tsc->delta[0]= (tsc->hold[0]-mval[0])/st->cwidth;
tsc->delta[1]= (mval[1]-tsc->hold[1])/st->lheight;
}
else
@@ -1906,6 +1916,8 @@ static void set_cursor_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel)
int *charp;
int w;
+ text_update_character_width(st);
+
if(sel) { linep= &text->sell; charp= &text->selc; }
else { linep= &text->curl; charp= &text->curc; }
@@ -1917,7 +1929,7 @@ static void set_cursor_to_pos(SpaceText *st, ARegion *ar, int x, int y, int sel)
x-= TXT_OFFSET;
if(x<0) x= 0;
- x = (x/text_font_width_character(st)) + st->left;
+ x = (x/st->cwidth) + st->left;
if(st->wordwrap) {
int i, j, endj, curs, max, chop, start, end, chars, loop;
diff --git a/source/blender/editors/space_text/text_python.c b/source/blender/editors/space_text/text_python.c
index 4fa54cdf27b..b606f8cb141 100644
--- a/source/blender/editors/space_text/text_python.c
+++ b/source/blender/editors/space_text/text_python.c
@@ -66,16 +66,18 @@ int text_do_suggest_select(SpaceText *st, ARegion *ar)
/* Count the visible lines to the cursor */
for(tmp=st->text->curl, l=-st->top; tmp; tmp=tmp->prev, l++);
if(l<0) return 0;
+
+ text_update_character_width(st);
if(st->showlinenrs) {
- x = text_font_width_character(st)*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
+ x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET + TEXTXLOC - 4;
}
else {
- x = text_font_width_character(st)*(st->text->curc-st->left) + TXT_OFFSET - 4;
+ x = st->cwidth*(st->text->curc-st->left) + TXT_OFFSET - 4;
}
y = ar->winy - st->lheight*l - 2;
- w = SUGG_LIST_WIDTH*text_font_width_character(st) + 20;
+ w = SUGG_LIST_WIDTH*st->cwidth + 20;
h = SUGG_LIST_SIZE*st->lheight + 8;
// XXX getmouseco_areawin(mval);