84
85
#if 0 /* used by textview, may use later */
87
int *pos_pick; // bottom of view == 0, top of file == combine chars, end of line is lower then start.
89
int *pos_pick; /* bottom of view == 0, top of file == combine chars, end of line is lower then start. */
95
97
/* fake the edit line being in the scroll buffer */
96
98
ConsoleLine *cl = sc->history.last;
99
int prompt_len = strlen(sc->prompt);
97
101
cl_dummy->type = CONSOLE_LINE_INPUT;
98
cl_dummy->len = cl_dummy->len_alloc = strlen(sc->prompt) + cl->len;
102
cl_dummy->len = prompt_len + cl->len;
99
103
cl_dummy->len_alloc = cl_dummy->len + 1;
100
104
cl_dummy->line = MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
101
memcpy(cl_dummy->line, sc->prompt, (cl_dummy->len_alloc - cl->len));
102
memcpy(cl_dummy->line + ((cl_dummy->len_alloc - cl->len)) - 1, cl->line, cl->len + 1);
105
memcpy(cl_dummy->line, sc->prompt, prompt_len);
106
memcpy(cl_dummy->line + prompt_len, cl->line, cl->len + 1);
103
107
BLI_addtail(&sc->scrollback, cl_dummy);
105
109
void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
111
115
#define CONSOLE_DRAW_MARGIN 4
112
#define CONSOLE_DRAW_SCROLL 16
116
117
/* console textview callbacks */
117
118
static int console_textview_begin(TextViewContext *tvc)
119
120
SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
120
tvc->lheight = sc->lheight;
121
tvc->lheight = sc->lheight * UI_DPI_FAC;
121
122
tvc->sel_start = sc->sel_start;
122
123
tvc->sel_end = sc->sel_end;
156
158
if (tvc->iter_index == 0) {
157
159
const SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
158
160
const ConsoleLine *cl = (ConsoleLine *)sc->history.last;
159
const int prompt_len = strlen(sc->prompt);
160
const int cursor_loc = cl->cursor + prompt_len;
161
const int prompt_len = BLI_strlen_utf8(sc->prompt);
162
const int cursor_loc = BLI_strnlen_utf8(cl->line, cl->cursor) + prompt_len;
163
const int line_len = BLI_strlen_utf8(cl->line) + prompt_len;
161
164
int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN};
163
166
xy[1] += tvc->lheight / 6;
165
168
/* account for wrapping */
166
if (cl->len < tvc->console_width) {
169
if (line_len < tvc->console_width) {
167
170
/* simple case, no wrapping */
168
171
pen[0] = tvc->cwidth * cursor_loc;
190
193
return TVC_LINE_FG;
196
static void console_textview_const_colors(TextViewContext *UNUSED(tvc), unsigned char bg_sel[4])
198
UI_GetThemeColor4ubv(TH_CONSOLE_SELECT, bg_sel);
194
static int console_textview_main__internal(struct SpaceConsole *sc, struct ARegion *ar, int draw, int mval[2], void **mouse_pick, int *pos_pick)
201
static int console_textview_main__internal(struct SpaceConsole *sc, ARegion *ar, int draw,
202
int mval[2], void **mouse_pick, int *pos_pick)
196
204
ConsoleLine cl_dummy = {NULL};
214
223
tvc.sel_start = sc->sel_start;
215
224
tvc.sel_end = sc->sel_end;
216
tvc.lheight = sc->lheight;
225
tvc.lheight = sc->lheight * UI_DPI_FAC;
217
226
tvc.ymin = v2d->cur.ymin;
218
227
tvc.ymax = v2d->cur.ymax;
228
tvc.winx = ar->winx - V2D_SCROLL_WIDTH;
221
230
console_scrollback_prompt_begin(sc, &cl_dummy);
222
231
ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
229
void console_textview_main(struct SpaceConsole *sc, struct ARegion *ar)
238
void console_textview_main(struct SpaceConsole *sc, ARegion *ar)
231
240
int mval[2] = {INT_MAX, INT_MAX};
232
241
console_textview_main__internal(sc, ar, 1, mval, NULL, NULL);
235
int console_textview_height(struct SpaceConsole *sc, struct ARegion *ar)
244
int console_textview_height(struct SpaceConsole *sc, ARegion *ar)
237
246
int mval[2] = {INT_MAX, INT_MAX};
238
247
return console_textview_main__internal(sc, ar, 0, mval, NULL, NULL);
241
int console_char_pick(struct SpaceConsole *sc, struct ARegion *ar, int mval[2])
250
int console_char_pick(struct SpaceConsole *sc, ARegion *ar, const int mval[2])
243
252
int pos_pick = 0;
244
253
void *mouse_pick = NULL;
245
254
int mval_clamp[2];
247
mval_clamp[0] = CLAMPIS(mval[0], CONSOLE_DRAW_MARGIN, ar->winx - (CONSOLE_DRAW_SCROLL + CONSOLE_DRAW_MARGIN));
256
mval_clamp[0] = CLAMPIS(mval[0], CONSOLE_DRAW_MARGIN, ar->winx - CONSOLE_DRAW_MARGIN);
248
257
mval_clamp[1] = CLAMPIS(mval[1], CONSOLE_DRAW_MARGIN, ar->winy - CONSOLE_DRAW_MARGIN);
250
259
console_textview_main__internal(sc, ar, 0, mval_clamp, &mouse_pick, &pos_pick);