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>2009-07-17 02:47:27 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-07-17 02:47:27 +0400
commitdeb180e37f324ab789ecbf608d08c9f031953749 (patch)
tree1e8c4525cc9180ed9b7eb88523c9bef32345c90f /source/blender/editors/space_console/console_draw.c
parent9eebb2ca36fc7ea05fb46eb23cca8821e81889b8 (diff)
- Scrollbars for the console (use View2D functions)
- Set View2D operators not to register, got in the way a lot with the console. - Made autocomplete Ctrl+Enter so Tab can be used. - Should work with python 2.5 now. (patch from Vilda) - Moved report struct definitions into DNA_windowmanager_types.h, could also have DNA_report_types.h however the reports are not saved, its just needed so the report list can be used in the wmWindowManager struct. Fixes a crash reported by ZanQdo. - Store the report message length in the report so calculating the total height including word wrap is not so slow.
Diffstat (limited to 'source/blender/editors/space_console/console_draw.c')
-rw-r--r--source/blender/editors/space_console/console_draw.c121
1 files changed, 87 insertions, 34 deletions
diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c
index 0a725d0c69f..96641fd8fbd 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -68,7 +68,7 @@ static void console_font_begin(SpaceConsole *sc)
BLF_set(mono);
BLF_aspect(1.0);
- BLF_size(sc->lheight, 72);
+ BLF_size(sc->lheight-2, 72);
}
static void console_line_color(unsigned char *fg, int type)
@@ -106,12 +106,24 @@ static void console_report_color(unsigned char *fg, int type)
/* return 0 if the last line is off the screen
* should be able to use this for any string type */
-static int console_draw_string(char *str, int str_len, int console_width, int lheight, unsigned char *fg, unsigned char *bg, int winx, int winy, int *x, int *y)
+static int console_draw_string( char *str, int str_len,
+ int console_width, int lheight,
+ unsigned char *fg, unsigned char *bg,
+ int winx, int winy,
+ int *x, int *y, int draw)
{
int rct_ofs= lheight/4;
+ int tot_lines = (str_len/console_width)+1; /* total number of lines for wrapping */
+
+ /* just advance the height */
+ if(draw==0) {
+ if(str_len > console_width) (*y) += tot_lines * lheight;
+ else (*y) += lheight;
+
+ return 1;
+ }
if(str_len > console_width) { /* wrap? */
- int tot_lines = (str_len/console_width)+1; /* total number of lines for wrapping */
char *line_stride= str + ((tot_lines-1) * console_width); /* advance to the last line and draw it first */
char eol; /* baclup the end of wrapping */
@@ -160,11 +172,13 @@ static int console_draw_string(char *str, int str_len, int console_width, int lh
return 1;
}
-#define CONSOLE_DRAW_MARGIN 8
-#define CONSOLE_LINE_MARGIN 6
+#define CONSOLE_DRAW_MARGIN 4
+#define CONSOLE_DRAW_SCROLL 16
-void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports)
+static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int draw)
{
+ View2D *v2d= &ar->v2d;
+
ConsoleLine *cl= sc->history.last;
int x_orig=CONSOLE_DRAW_MARGIN, y_orig=CONSOLE_DRAW_MARGIN;
@@ -176,41 +190,54 @@ void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, ReportList *
console_font_begin(sc);
cwidth = BLF_fixed_width();
- console_width= (ar->winx - CONSOLE_DRAW_MARGIN*2)/cwidth;
+ console_width= (ar->winx - (CONSOLE_DRAW_SCROLL + CONSOLE_DRAW_MARGIN*2) )/cwidth;
if (console_width < 8) console_width= 8;
x= x_orig; y= y_orig;
if(sc->type==CONSOLE_TYPE_PYTHON) {
- int prompt_len= strlen(sc->prompt);
+ int prompt_len;
/* text */
- console_line_color(fg, CONSOLE_LINE_INPUT);
- glColor3ub(fg[0], fg[1], fg[2]);
-
- /* command line */
- if(prompt_len) {
- BLF_position(x, y, 0); x += cwidth * prompt_len;
- BLF_draw(sc->prompt);
+ if(draw) {
+ prompt_len= strlen(sc->prompt);
+ console_line_color(fg, CONSOLE_LINE_INPUT);
+ glColor3ub(fg[0], fg[1], fg[2]);
+
+ /* command line */
+ if(prompt_len) {
+ BLF_position(x, y, 0); x += cwidth * prompt_len;
+ BLF_draw(sc->prompt);
+ }
+ BLF_position(x, y, 0);
+ BLF_draw(cl->line);
+
+ /* cursor */
+ console_line_color(fg, CONSOLE_LINE_ERROR); /* lazy */
+ glColor3ub(fg[0], fg[1], fg[2]);
+ glRecti(x+(cwidth*cl->cursor) -1, y-2, x+(cwidth*cl->cursor) +1, y+sc->lheight-2);
+
+ x= x_orig; /* remove prompt offset */
}
- BLF_position(x, y, 0);
- BLF_draw(cl->line);
-
- /* cursor */
- console_line_color(fg, CONSOLE_LINE_ERROR); /* lazy */
- glColor3ub(fg[0], fg[1], fg[2]);
- glRecti(x+(cwidth*cl->cursor) -1, y-2, x+(cwidth*cl->cursor) +1, y+sc->lheight-2);
-
- x= x_orig; /* remove prompt offset */
y += sc->lheight;
for(cl= sc->scrollback.last; cl; cl= cl->prev) {
- console_line_color(fg, cl->type);
- if(!console_draw_string(cl->line, cl->len, console_width, sc->lheight+CONSOLE_LINE_MARGIN, fg, NULL, ar->winx, ar->winy, &x, &y))
- break; /* past the y limits */
-
+ if(draw)
+ console_line_color(fg, cl->type);
+
+ if(!console_draw_string( cl->line, cl->len,
+ console_width, sc->lheight,
+ fg, NULL,
+ ar->winx-CONSOLE_DRAW_MARGIN, v2d->cur.ymax,
+ &x, &y, draw))
+ {
+ /* when drawing, if we pass v2d->cur.ymax, then quit */
+ if(draw) {
+ break; /* past the y limits */
+ }
+ }
}
}
else {
@@ -219,8 +246,10 @@ void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, ReportList *
int bool= 0;
unsigned char bg[3] = {114, 114, 114};
- glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
+ if(draw) {
+ glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
/* convert our display toggles into a flag compatible with BKE_report flags */
if(sc->rpt_mask & CONSOLE_RPT_DEBUG) report_mask |= RPT_DEBUG_ALL;
@@ -232,15 +261,39 @@ void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, ReportList *
for(report=reports->list.last; report; report=report->prev) {
if(report->type & report_mask) {
- console_report_color(fg, report->type);
- if(!console_draw_string(report->message, strlen(report->message), console_width, sc->lheight+CONSOLE_LINE_MARGIN, fg, bool?bg:NULL, ar->winx, ar->winy, &x, &y))
- break; /* past the y limits */
- y+=CONSOLE_LINE_MARGIN;
+ if(draw)
+ console_report_color(fg, report->type);
+
+ if(!console_draw_string( report->message, report->len,
+ console_width, sc->lheight,
+ fg, bool?bg:NULL,
+ ar->winx-CONSOLE_DRAW_MARGIN, v2d->cur.ymax,
+ &x, &y, draw))
+ {
+ /* when drawing, if we pass v2d->cur.ymax, then quit */
+ if(draw) {
+ break; /* past the y limits */
+ }
+ }
+
bool = !(bool);
}
}
}
+ y += sc->lheight*2;
+
+ return y-y_orig;
+}
+
+void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports)
+{
+ console_text_main__internal(sc, ar, reports, 1);
+}
+
+int console_text_height(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports)
+{
+ return console_text_main__internal(sc, ar, reports, 0);
}