- Scrollbars for the console (use View2D functions)
authorCampbell Barton <ideasman42@gmail.com>
Thu, 16 Jul 2009 22:47:27 +0000 (22:47 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 16 Jul 2009 22:47:27 +0000 (22:47 +0000)
- 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.

14 files changed:
release/ui/space_console.py
source/blender/blenkernel/BKE_report.h
source/blender/blenkernel/intern/context.c
source/blender/blenkernel/intern/report.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/interface/view2d_ops.c
source/blender/editors/space_console/console_draw.c
source/blender/editors/space_console/console_intern.h
source/blender/editors/space_console/console_ops.c
source/blender/editors/space_console/space_console.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesdna/DNA_windowmanager_types.h
source/blender/windowmanager/intern/wm.c
source/blender/windowmanager/intern/wm_init_exit.c

index 6548a2249b23550a00f8be172dd0fda6657c457e..7d8ea3018c4a9cdbe52f34d4f298b5e646b56d15 100644 (file)
@@ -50,7 +50,7 @@ def get_console(console_id):
        
        console_id can be any hashable type
        '''
-       import sys, code, io
+       import sys, code
        
        try:    consoles = get_console.consoles
        except:consoles = get_console.consoles = {}
@@ -72,9 +72,11 @@ def get_console(console_id):
                console = code.InteractiveConsole(namespace)
                
                if sys.version.startswith('2'):
-                       stdout = io.BytesIO()  # Py2x support
-                       stderr = io.BytesIO()
+                       import cStringIO
+                       stdout = cStringIO.BytesIO()  # Py2x support
+                       stderr = cStringIO.BytesIO()
                else:
+                       import io
                        stdout = io.StringIO()
                        stderr = io.StringIO()
        
index 26853866ebbc1ca9f395d223604bfa82f9acfa6a..1d72b1c81f0edafa935822c05ee16767a4387ab7 100644 (file)
 extern "C" {
 #endif
 
-#include "DNA_listBase.h"
+#include "DNA_windowmanager_types.h"
 
 /* Reporting Information and Errors
  *
  * These functions also accept NULL in case no error reporting
  * is needed. */
 
-typedef enum ReportType {
-       RPT_DEBUG                                       = 1<<0,
-       RPT_INFO                                        = 1<<1,
-       RPT_OPERATOR                            = 1<<2,
-       RPT_WARNING                                     = 1<<3,
-       RPT_ERROR                                       = 1<<4,
-       RPT_ERROR_INVALID_INPUT         = 1<<5,
-       RPT_ERROR_INVALID_CONTEXT       = 1<<6,
-       RPT_ERROR_OUT_OF_MEMORY         = 1<<7
-} ReportType;
-
-#define RPT_DEBUG_ALL          (RPT_DEBUG)
-#define RPT_INFO_ALL           (RPT_INFO)
-#define RPT_OPERATOR_ALL       (RPT_OPERATOR)
-#define RPT_WARNING_ALL                (RPT_WARNING)
-#define RPT_ERROR_ALL          (RPT_ERROR|RPT_ERROR_INVALID_INPUT|RPT_ERROR_INVALID_CONTEXT|RPT_ERROR_OUT_OF_MEMORY)
-
-enum ReportListFlags {
-       RPT_PRINT = 1,
-       RPT_STORE = 2,
-};
-
-typedef struct Report {
-       struct Report *next, *prev;
-       ReportType type;
-       char *typestr;
-       char *message;
-} Report;
-
-typedef struct ReportList {
-       ListBase list;
-       ReportType printlevel;
-       ReportType storelevel;
-       int flag;
-} ReportList;
+/* report structures are stored in DNA */
 
 void BKE_reports_init(ReportList *reports, int flag);
 void BKE_reports_clear(ReportList *reports);
index bbf3ceb01e8fa9c09b61b0b7b2f90f915d3b8ab8..4bfc1484e5694c6493b7777a35b83c0646d5eab7 100644 (file)
@@ -206,7 +206,7 @@ struct ARegion *CTX_wm_menu(const bContext *C)
 
 struct ReportList *CTX_wm_reports(const bContext *C)
 {
-       return C->wm.manager->reports;
+       return &(C->wm.manager->reports);
 }
 
 View3D *CTX_wm_view3d(const bContext *C)
index 6564329ef8298ad5284223583504d44411a5dbb4..3e3dd4b0af0251904a7c9c27f728d24484600aac 100644 (file)
@@ -102,7 +102,7 @@ void BKE_report(ReportList *reports, ReportType type, const char *message)
                len= strlen(message);
                report->message= MEM_callocN(sizeof(char)*(len+1), "ReportMessage");
                memcpy(report->message, message, sizeof(char)*(len+1));
-               
+               report->len= len;
                BLI_addtail(&reports->list, report);
        }
 }
@@ -129,7 +129,7 @@ void BKE_reportf(ReportList *reports, ReportType type, const char *format, ...)
                va_end(args);
 
                report->message= BLI_dynstr_get_cstring(ds);
-
+               report->len= BLI_dynstr_get_len(ds);
                BLI_dynstr_free(ds);
 
                report->type= type;
@@ -155,6 +155,7 @@ void BKE_reports_prepend(ReportList *reports, const char *prepend)
                MEM_freeN(report->message);
 
                report->message= BLI_dynstr_get_cstring(ds);
+               report->len= BLI_dynstr_get_len(ds);
 
                BLI_dynstr_free(ds);
        }
@@ -179,6 +180,7 @@ void BKE_reports_prependf(ReportList *reports, const char *prepend, ...)
                MEM_freeN(report->message);
 
                report->message= BLI_dynstr_get_cstring(ds);
+               report->len= BLI_dynstr_get_len(ds);
 
                BLI_dynstr_free(ds);
        }
index 1d7ba88136fb2ab35f8a2c14b39876d72b67d39c..fbe7a07c7bef52de6fbfda8a1c3ef11b0ab2b076 100644 (file)
@@ -4221,7 +4221,8 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
        wm->keymaps.first= wm->keymaps.last= NULL;
        wm->paintcursors.first= wm->paintcursors.last= NULL;
        wm->queue.first= wm->queue.last= NULL;
-       wm->reports= NULL;
+       BKE_reports_init(&wm->reports, RPT_STORE);
+
        wm->jobs.first= wm->jobs.last= NULL;
        
        wm->windrawable= NULL;
index c6688aea5c5ec5a4e9795b8bd12f2ab15b6a71df..f0745ebfd7121dcf4763fc5f1bdba20ea74d4848 100644 (file)
@@ -257,7 +257,7 @@ void VIEW2D_OT_pan(wmOperatorType *ot)
        ot->modal= view_pan_modal;
        
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_BLOCKING;
+       ot->flag= OPTYPE_BLOCKING;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
@@ -303,7 +303,7 @@ void VIEW2D_OT_scroll_right(wmOperatorType *ot)
        ot->exec= view_scrollright_exec;
        
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       // ot->flag= OPTYPE_REGISTER;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
@@ -349,7 +349,7 @@ void VIEW2D_OT_scroll_left(wmOperatorType *ot)
        ot->exec= view_scrollleft_exec;
        
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       // ot->flag= OPTYPE_REGISTER;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
@@ -394,7 +394,7 @@ void VIEW2D_OT_scroll_down(wmOperatorType *ot)
        ot->exec= view_scrolldown_exec;
        
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       // ot->flag= OPTYPE_REGISTER;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
@@ -440,7 +440,7 @@ void VIEW2D_OT_scroll_up(wmOperatorType *ot)
        ot->exec= view_scrollup_exec;
        
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       // ot->flag= OPTYPE_REGISTER;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_int(ot->srna, "deltax", 0, INT_MIN, INT_MAX, "Delta X", "", INT_MIN, INT_MAX);
@@ -550,7 +550,7 @@ void VIEW2D_OT_zoom_in(wmOperatorType *ot)
        ot->exec= view_zoomin_exec;
        
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       // ot->flag= OPTYPE_REGISTER;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
@@ -586,7 +586,7 @@ void VIEW2D_OT_zoom_out(wmOperatorType *ot)
        ot->exec= view_zoomout_exec;
        
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER;
+       // ot->flag= OPTYPE_REGISTER;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_float(ot->srna, "zoomfacx", 0, -FLT_MAX, FLT_MAX, "Zoom Factor X", "", -FLT_MAX, FLT_MAX);
@@ -832,7 +832,7 @@ void VIEW2D_OT_zoom(wmOperatorType *ot)
        ot->modal= view_zoomdrag_modal;
        
        /* operator is repeatable */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_BLOCKING;
+       // ot->flag= OPTYPE_REGISTER|OPTYPE_BLOCKING;
        
        /* rna - must keep these in sync with the other operators */
        RNA_def_float(ot->srna, "deltax", 0, -FLT_MAX, FLT_MAX, "Delta X", "", -FLT_MAX, FLT_MAX);
index 0a725d0c69ffe1525492039e747abf9571b216c6..96641fd8fbdb1de6ca297f4c7117d50c0d58ed01 100644 (file)
@@ -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);
 }
index 55474844d87c7968863221c5d8bf48fd0d393a3b..2e5af9c5ffded503c78e640b9e9a5bd42d6455e8 100644 (file)
@@ -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);
index d2cd4df6426900d025ca22740f7452f0fb3f0b46..c82463eb7682c794e1be130ba547127e63a7d854 100644 (file)
@@ -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);
 }
 
index ee80fe3d2d99bfbd88a73fb2d54fe3641a5328e1..f5bccbce3f50a23d9b9d1a17d4d0158b538f2ba9 100644 (file)
 
 #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 */
index ca50d8494c065d62ddbe9dde5a7d8b6f7e078c62..6193108570737fe56f2e7b5ce0f460b6833ab499 100644 (file)
@@ -511,7 +511,7 @@ typedef struct SpaceConsole {
        int type; /* console/report/..? */
        int rpt_mask; /* which reports to display */
        int flag, lheight;
-       
+
        ListBase scrollback; /* ConsoleLine; output */
        ListBase history; /* ConsoleLine; command history, current edited line is the first */
        char prompt[8];
index 9a60e3c92b88c9afc3cc8a0a4db269b18d68dedc..69ab45d3389d6cfdb5472a468cfb1a849acf9e98 100644 (file)
@@ -52,6 +52,44 @@ struct wmTimer;
 struct StructRNA;
 struct PointerRNA;
 struct ReportList;
+struct Report;
+
+typedef enum ReportType {
+       RPT_DEBUG                                       = 1<<0,
+       RPT_INFO                                        = 1<<1,
+       RPT_OPERATOR                            = 1<<2,
+       RPT_WARNING                                     = 1<<3,
+       RPT_ERROR                                       = 1<<4,
+       RPT_ERROR_INVALID_INPUT         = 1<<5,
+       RPT_ERROR_INVALID_CONTEXT       = 1<<6,
+       RPT_ERROR_OUT_OF_MEMORY         = 1<<7
+} ReportType;
+
+#define RPT_DEBUG_ALL          (RPT_DEBUG)
+#define RPT_INFO_ALL           (RPT_INFO)
+#define RPT_OPERATOR_ALL       (RPT_OPERATOR)
+#define RPT_WARNING_ALL                (RPT_WARNING)
+#define RPT_ERROR_ALL          (RPT_ERROR|RPT_ERROR_INVALID_INPUT|RPT_ERROR_INVALID_CONTEXT|RPT_ERROR_OUT_OF_MEMORY)
+
+enum ReportListFlags {
+       RPT_PRINT = 1,
+       RPT_STORE = 2,
+};
+typedef struct Report {
+       struct Report *next, *prev;
+       int type; /* ReportType */
+       int len; /* strlen(message), saves some time calculating the word wrap  */
+       char *typestr;
+       char *message;
+} Report;
+typedef struct ReportList {
+       ListBase list;
+       int printlevel; /* ReportType */
+       int storelevel; /* ReportType */
+       int flag, pad;
+} ReportList;
+/* reports need to be before wmWindowManager */
+
 
 /* windowmanager is saved, tag WMAN */
 typedef struct wmWindowManager {
@@ -68,7 +106,7 @@ typedef struct wmWindowManager {
        
        ListBase queue;                 /* refresh/redraw wmNotifier structs */
        
-       struct ReportList *reports;     /* information and error reports */
+       struct ReportList reports;      /* information and error reports */
        
        ListBase jobs;                  /* threaded jobs manager */
        
@@ -258,6 +296,5 @@ typedef enum wmRadialControlMode {
        WM_RADIALCONTROL_ANGLE
 } wmRadialControlMode;
 
-
 #endif /* DNA_WINDOWMANAGER_TYPES_H */
 
index 6b3b128d34b3a74b3c5744a9a41b623e7447cd39..94200925a028a55d8eb26cfbffc7ccdcaaa292f0 100644 (file)
@@ -98,7 +98,7 @@ void wm_operator_register(bContext *C, wmOperator *op)
        
        /* Report the string representation of the operator */
        buf = WM_operator_pystring(op);
-       BKE_report(wm->reports, RPT_OPERATOR, buf);
+       BKE_report(CTX_wm_reports(C), RPT_OPERATOR, buf);
        MEM_freeN(buf);
        
        /* so the console is redrawn */
index 5938677afe7d0cebf812e7f36cbb05c73e0f8d8d..4c9c3059e5b1019101549d61ebaa311126a37fe7 100644 (file)
@@ -104,15 +104,11 @@ static void sound_init_listener(void)
 
 static void wm_init_reports(bContext *C)
 {
-       wmWindowManager *wm= CTX_wm_manager(C);
-       wm->reports= MEM_callocN(sizeof(ReportList), "wmReportList");
-       BKE_reports_init(wm->reports, RPT_STORE);
+       BKE_reports_init(CTX_wm_reports(C), RPT_STORE);
 }
 static void wm_free_reports(bContext *C)
 {
-       wmWindowManager *wm= CTX_wm_manager(C);
-       BKE_reports_clear(wm->reports);
-       MEM_freeN(wm->reports);
+       BKE_reports_clear(CTX_wm_reports(C));
 }