diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-09-27 21:22:59 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-09-27 21:22:59 +0400 |
commit | e310b302ae08caf68c32da232560786801e681c7 (patch) | |
tree | 29bdbca42efcbe6746e46f9438e138c193165bd5 /source | |
parent | f8e5e953c5abd7242242ccc37ccd5ea833d4420e (diff) |
minor console fixes
- selection doesnt mess up alignment when text is added to the buffer.
- tab key is now alligned to 4 (rather then adding 4 spaces).
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/space_console/console_draw.c | 25 | ||||
-rw-r--r-- | source/blender/editors/space_console/console_ops.c | 22 | ||||
-rw-r--r-- | source/blender/editors/space_console/space_console.c | 2 |
3 files changed, 33 insertions, 16 deletions
diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c index 4bff21ab3d2..e12ccd03d04 100644 --- a/source/blender/editors/space_console/console_draw.c +++ b/source/blender/editors/space_console/console_draw.c @@ -207,11 +207,11 @@ static int console_draw_string(ConsoleDrawContext *cdc, char *str, int str_len, cdc->sel[1] = str_len - sel_orig[0]; if(bg) { - glColor3ub(bg[0], bg[1], bg[2]); + glColor3ubv(bg); glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, (cdc->xy[1]+(cdc->lheight*tot_lines))+rct_ofs); } - glColor3ub(fg[0], fg[1], fg[2]); + glColor3ubv(fg); /* last part needs no clipping */ BLF_position(mono, cdc->xy[0], cdc->xy[1], 0); @@ -222,7 +222,7 @@ static int console_draw_string(ConsoleDrawContext *cdc, char *str, int str_len, // glColor4ub(255, 0, 0, 96); // debug console_draw_sel(cdc->sel, cdc->xy, str_len % cdc->console_width, cdc->cwidth, cdc->console_width, cdc->lheight); STEP_SEL(cdc->console_width); - glColor3ub(fg[0], fg[1], fg[2]); + glColor3ubv(fg); } cdc->xy[1] += cdc->lheight; @@ -240,7 +240,7 @@ static int console_draw_string(ConsoleDrawContext *cdc, char *str, int str_len, // glColor4ub(0, 255, 0, 96); // debug console_draw_sel(cdc->sel, cdc->xy, cdc->console_width, cdc->cwidth, cdc->console_width, cdc->lheight); STEP_SEL(cdc->console_width); - glColor3ub(fg[0], fg[1], fg[2]); + glColor3ubv(fg); } cdc->xy[1] += cdc->lheight; @@ -258,11 +258,11 @@ static int console_draw_string(ConsoleDrawContext *cdc, char *str, int str_len, else { /* simple, no wrap */ if(bg) { - glColor3ub(bg[0], bg[1], bg[2]); + glColor3ubv(bg); glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, cdc->xy[1]+cdc->lheight-rct_ofs); } - glColor3ub(fg[0], fg[1], fg[2]); + glColor3ubv(fg); BLF_position(mono, cdc->xy[0], cdc->xy[1], 0); BLF_draw(mono, str); @@ -334,14 +334,13 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion * if(sc->sel_start != sc->sel_end) { sel[0]= sc->sel_start; sel[1]= sc->sel_end; - // printf("%d %d\n", sel[0], sel[1]); } /* text */ if(draw) { prompt_len= strlen(sc->prompt); console_line_color(fg, CONSOLE_LINE_INPUT); - glColor3ub(fg[0], fg[1], fg[2]); + glColor3ubv(fg); /* command line */ if(prompt_len) { @@ -353,7 +352,7 @@ static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion * /* cursor */ UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg); - glColor3ub(fg[0], fg[1], fg[2]); + glColor3ubv(fg); glRecti(xy[0]+(cwidth*cl->cursor) -1, xy[1]-2, xy[0]+(cwidth*cl->cursor) +1, xy[1]+sc->lheight-2); xy[0]= x_orig; /* remove prompt offset */ @@ -443,11 +442,15 @@ void *console_text_pick(struct SpaceConsole *sc, struct ARegion *ar, ReportList return (void *)mouse_pick; } -// XXX - breaks with line wrap int console_char_pick(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int mval[2]) { int pos_pick= 0; void *mouse_pick= NULL; - console_text_main__internal(sc, ar, reports, 0, mval, &mouse_pick, &pos_pick); + int mval_clamp[2]; + + mval_clamp[0]= CLAMPIS(mval[0], CONSOLE_DRAW_MARGIN, ar->winx-(CONSOLE_DRAW_SCROLL + CONSOLE_DRAW_MARGIN)); + mval_clamp[1]= CLAMPIS(mval[1], CONSOLE_DRAW_MARGIN, ar->winy-CONSOLE_DRAW_MARGIN); + + console_text_main__internal(sc, ar, reports, 0, mval_clamp, &mouse_pick, &pos_pick); return pos_pick; } diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c index 802e3a75929..34e6add81ef 100644 --- a/source/blender/editors/space_console/console_ops.c +++ b/source/blender/editors/space_console/console_ops.c @@ -205,7 +205,11 @@ ConsoleLine *console_history_add_str(const bContext *C, char *str, int own) } ConsoleLine *console_scrollback_add_str(const bContext *C, char *str, int own) { - return console_lb_add_str__internal(&CTX_wm_space_console(C)->scrollback, C, str, own); + SpaceConsole *sc= CTX_wm_space_console(C); + ConsoleLine *ci= console_lb_add_str__internal(&sc->scrollback, C, str, own); + sc->sel_start += ci->len + 1; + sc->sel_end += ci->len + 1; + return ci; } ConsoleLine *console_history_verify(const bContext *C) @@ -359,13 +363,23 @@ void CONSOLE_OT_move(wmOperatorType *ot) RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to."); } - +#define TAB_LENGTH 4 static int insert_exec(bContext *C, wmOperator *op) { ConsoleLine *ci= console_history_verify(C); char *str= RNA_string_get_alloc(op->ptr, "text", NULL, 0); - - int len= console_line_insert(ci, str); + int len; + + // XXX, alligned tab key hack + if(str[0]=='\t' && str[1]=='\0') { + int len= TAB_LENGTH - (ci->cursor % TAB_LENGTH); + MEM_freeN(str); + MEM_mallocN(len + 1, "insert_exec"); + memset(str, ' ', len); + str[len]= '\0'; + } + + len= console_line_insert(ci, str); MEM_freeN(str); diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c index 4ee69bbd809..c30897bbb87 100644 --- a/source/blender/editors/space_console/space_console.c +++ b/source/blender/editors/space_console/space_console.c @@ -354,7 +354,7 @@ void console_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "CONSOLE_OT_select_set", LEFTMOUSE, KM_PRESS, 0, 0); - RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, 0, 0)->ptr, "text", " "); /* fake tabs */ + RNA_string_set(WM_keymap_add_item(keymap, "CONSOLE_OT_insert", TABKEY, KM_PRESS, 0, 0)->ptr, "text", "\t"); /* fake tabs */ WM_keymap_add_item(keymap, "CONSOLE_OT_insert", KM_TEXTINPUT, KM_ANY, KM_ANY, 0); // last! } |