~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/editors/space_console/console_draw.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
#include "ED_datafiles.h"
51
51
#include "ED_types.h"
52
52
 
 
53
#include "UI_interface.h"
53
54
#include "UI_resources.h"
 
55
#include "UI_view2d.h"
54
56
 
55
57
#include "console_intern.h"
56
58
 
79
81
        int cwidth;
80
82
        int lheight;
81
83
        int console_width;
82
 
        int winx;
83
84
        int ymin, ymax;
84
85
#if 0 /* used by textview, may use later */
 
86
        int winx;
85
87
        int *xy; // [2]
86
88
        int *sel; // [2]
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. */
88
90
        int *mval; // [2]
89
91
        int draw;
90
92
#endif
94
96
{
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);
 
100
        
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);
104
108
}
105
109
void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dummy) 
109
113
}
110
114
 
111
115
#define CONSOLE_DRAW_MARGIN 4
112
 
#define CONSOLE_DRAW_SCROLL 16
113
 
 
114
 
 
115
116
 
116
117
/* console textview callbacks */
117
118
static int console_textview_begin(TextViewContext *tvc)
118
119
{
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;
123
124
        
144
145
        ConsoleLine *cl = (ConsoleLine *)tvc->iter;
145
146
        *line = cl->line;
146
147
        *len = cl->len;
147
 
 
 
148
        // printf("'%s' %d\n", *line, cl->len);
 
149
        BLI_assert(cl->line[cl->len] == '\0' && (cl->len == 0 || cl->line[cl->len - 1] != '\0'));
148
150
        return 1;
149
151
}
150
152
 
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};
162
165
                int pen[2];
163
166
                xy[1] += tvc->lheight / 6;
164
167
 
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;
169
172
                        pen[1] = -2;
171
174
                else {
172
175
                        /* wrap */
173
176
                        pen[0] = tvc->cwidth * (cursor_loc % tvc->console_width);
174
 
                        pen[1] = -2 + (((cl->len / tvc->console_width) - (cursor_loc / tvc->console_width)) * tvc->lheight);
 
177
                        pen[1] = -2 + (((line_len / tvc->console_width) - (cursor_loc / tvc->console_width)) * tvc->lheight);
175
178
                }
176
179
 
177
180
                /* cursor */
190
193
        return TVC_LINE_FG;
191
194
}
192
195
 
 
196
static void console_textview_const_colors(TextViewContext *UNUSED(tvc), unsigned char bg_sel[4])
 
197
{
 
198
        UI_GetThemeColor4ubv(TH_CONSOLE_SELECT, bg_sel);
 
199
}
193
200
 
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)
195
203
{
196
204
        ConsoleLine cl_dummy = {NULL};
197
205
        int ret = 0;
206
214
        tvc.step = console_textview_step;
207
215
        tvc.line_get = console_textview_line_get;
208
216
        tvc.line_color = console_textview_line_color;
 
217
        tvc.const_colors = console_textview_const_colors;
209
218
 
210
219
        tvc.arg1 = sc;
211
220
        tvc.arg2 = NULL;
213
222
        /* view */
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;
219
 
        tvc.winx = ar->winx;
 
228
        tvc.winx = ar->winx - V2D_SCROLL_WIDTH;
220
229
 
221
230
        console_scrollback_prompt_begin(sc, &cl_dummy);
222
231
        ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
226
235
}
227
236
 
228
237
 
229
 
void console_textview_main(struct SpaceConsole *sc, struct ARegion *ar)
 
238
void console_textview_main(struct SpaceConsole *sc, ARegion *ar)
230
239
{
231
240
        int mval[2] = {INT_MAX, INT_MAX};
232
241
        console_textview_main__internal(sc, ar, 1,  mval, NULL, NULL);
233
242
}
234
243
 
235
 
int console_textview_height(struct SpaceConsole *sc, struct ARegion *ar)
 
244
int console_textview_height(struct SpaceConsole *sc, ARegion *ar)
236
245
{
237
246
        int mval[2] = {INT_MAX, INT_MAX};
238
247
        return console_textview_main__internal(sc, ar, 0,  mval, NULL, NULL);
239
248
}
240
249
 
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])
242
251
{
243
252
        int pos_pick = 0;
244
253
        void *mouse_pick = NULL;
245
254
        int mval_clamp[2];
246
255
 
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);
249
258
 
250
259
        console_textview_main__internal(sc, ar, 0, mval_clamp, &mouse_pick, &pos_pick);