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
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')
-rw-r--r--source/blender/editors/space_console/console_draw.c121
-rw-r--r--source/blender/editors/space_console/console_intern.h1
-rw-r--r--source/blender/editors/space_console/console_ops.c6
-rw-r--r--source/blender/editors/space_console/space_console.c70
4 files changed, 136 insertions, 62 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);
}
diff --git a/source/blender/editors/space_console/console_intern.h b/source/blender/editors/space_console/console_intern.h
index 55474844d87..2e5af9c5ffd 100644
--- a/source/blender/editors/space_console/console_intern.h
+++ b/source/blender/editors/space_console/console_intern.h
@@ -39,6 +39,7 @@ struct ReportList;
/* console_draw.c */
void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, struct ReportList *reports);
+int console_text_height(struct SpaceConsole *sc, struct ARegion *ar, struct ReportList *reports); /* needed to calculate the scrollbar */
/* console_ops.c */
void console_history_free(SpaceConsole *sc, ConsoleLine *cl);
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c
index d2cd4df6426..c82463eb768 100644
--- a/source/blender/editors/space_console/console_ops.c
+++ b/source/blender/editors/space_console/console_ops.c
@@ -287,8 +287,10 @@ static int insert_exec(const bContext *C, wmOperator *op)
static int insert_invoke(const bContext *C, wmOperator *op, wmEvent *event)
{
- char str[2] = {event->ascii, '\0'};
- RNA_string_set(op->ptr, "text", str);
+ if(!RNA_property_is_set(op->ptr, "text")) {
+ char str[2] = {event->ascii, '\0'};
+ RNA_string_set(op->ptr, "text", str);
+ }
return insert_exec(C, op);
}
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index ee80fe3d2d9..f5bccbce3f5 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -60,6 +60,13 @@
#include "console_intern.h" // own include
+static void console_update_rect(bContext *C, ARegion *ar)
+{
+ SpaceConsole *sc= CTX_wm_space_console(C);
+ View2D *v2d= &ar->v2d;
+
+ UI_view2d_totRect_set(v2d, ar->winx-1, console_text_height(sc, ar, CTX_wm_reports(C)));
+}
/* ******************** default callbacks for console space ***************** */
@@ -89,12 +96,17 @@ static SpaceLink *console_new(const bContext *C)
BLI_addtail(&sconsole->regionbase, ar);
ar->regiontype= RGN_TYPE_WINDOW;
- ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM_O);
- ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
+
+ ar->v2d.scroll |= (V2D_SCROLL_LEFT);
+ ar->v2d.align |= V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_NEG_Y; /* align bottom left */
+ ar->v2d.keepofs |= V2D_LOCKOFS_X;
ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
- ar->v2d.keeptot= V2D_KEEPTOT_STRICT;
+ ar->v2d.keeptot= V2D_KEEPTOT_BOUNDS;
ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
-
+
+ /* for now, aspect ratio should be maintained, and zoom is clamped within sane default limits */
+ //ar->v2d.keepzoom= (V2D_KEEPASPECT|V2D_KEEPZOOM);
+
return (SpaceLink *)sconsole;
}
@@ -136,9 +148,9 @@ static SpaceLink *console_duplicate(SpaceLink *sl)
static void console_main_area_init(wmWindowManager *wm, ARegion *ar)
{
ListBase *keymap;
-
- UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
-
+
+ UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
+
/* own keymap */
keymap= WM_keymap_listbase(wm, "Console", SPACE_CONSOLE, 0); /* XXX weak? */
WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
@@ -148,21 +160,10 @@ static void console_main_area_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
SpaceConsole *sc= CTX_wm_space_console(C);
- //View2D *v2d= &ar->v2d;
+ View2D *v2d= &ar->v2d;
+ View2DScrollers *scrollers;
//float col[3];
- /* clear and setup matrix */
- //UI_GetThemeColor3fv(TH_BACK, col);
- //glClearColor(col[0], col[1], col[2], 0.0);
- glClearColor(0, 0, 0, 1.0);
-
- glClear(GL_COLOR_BUFFER_BIT);
-
- /* worlks best with no view2d matrix set */
- /*UI_view2d_view_ortho(C, v2d);*/
-
- /* data... */
-
/* add helper text, why not? */
if(sc->scrollback.first==NULL) {
console_scrollback_add_str(C, " * Python Interactive Console *", 0);
@@ -170,23 +171,34 @@ static void console_main_area_draw(const bContext *C, ARegion *ar)
console_scrollback_add_str(C, "Cursor: Left/Right Home/End", 0);
console_scrollback_add_str(C, "Remove: Backspace/Delete", 0);
console_scrollback_add_str(C, "Execute: Enter", 0);
- console_scrollback_add_str(C, "Autocomplete: Tab", 0);
+ console_scrollback_add_str(C, "Autocomplete: Ctrl+Enter", 0);
console_scrollback_add_str(C, "Ctrl +/- Wheel: Zoom", 0);
console_scrollback_add_str(C, "Builtin Modules: bpy, bpy.data, bpy.ops, bpy.props, bpy.types, bpy.ui", 0);
}
+ /* clear and setup matrix */
+ //UI_GetThemeColor3fv(TH_BACK, col);
+ //glClearColor(col[0], col[1], col[2], 0.0);
+ glClearColor(0, 0, 0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ console_update_rect(C, ar);
+
+ /* worlks best with no view2d matrix set */
+ UI_view2d_view_ortho(C, v2d);
+
+ /* data... */
+
console_history_verify(C); /* make sure we have some command line */
console_text_main(sc, ar, CTX_wm_reports(C));
/* reset view matrix */
- /* UI_view2d_view_restore(C); */
+ UI_view2d_view_restore(C);
/* scrollers */
- /*
- scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
+ scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_GRID_CLAMP);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
- */
}
void console_operatortypes(void)
@@ -255,8 +267,11 @@ void console_keymap(struct wmWindowManager *wm)
#ifndef DISABLE_PYTHON
WM_keymap_add_item(keymap, "CONSOLE_OT_exec", RETKEY, KM_PRESS, 0, 0); /* python operator - space_text.py */
- WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", TABKEY, KM_PRESS, 0, 0); /* python operator - space_text.py */
+ //WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", TABKEY, KM_PRESS, 0, 0); /* python operator - space_text.py */
+ WM_keymap_add_item(keymap, "CONSOLE_OT_autocomplete", RETKEY, KM_PRESS, KM_CTRL, 0); /* python operator - space_text.py */
#endif
+
+ RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, 0, 0)->ptr, "text", " "); /* fake tabs */
WM_keymap_add_item(keymap, "CONSOLE_OT_insert", KM_TEXTINPUT, KM_PRESS, KM_ANY, 0); // last!
}
@@ -310,11 +325,14 @@ void ED_spacetype_console(void)
/* regions: main window */
art= MEM_callocN(sizeof(ARegionType), "spacetype console region");
art->regionid = RGN_TYPE_WINDOW;
+ art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
+
art->init= console_main_area_init;
art->draw= console_main_area_draw;
+
BLI_addhead(&sc->regiontypes, art);
/* regions: header */