2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-07-16 00:50:27 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-07-16 00:50:27 +00:00
|
|
|
*
|
|
|
|
* Contributor(s): Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_console/console_draw.c
|
|
|
|
* \ingroup spconsole
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
2009-07-19 00:49:44 +00:00
|
|
|
#include <limits.h>
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
#include "BLF_api.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
#include "BKE_report.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2010-10-02 22:31:48 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
#include "BIF_gl.h"
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
#include "ED_datafiles.h"
|
2009-07-19 00:49:44 +00:00
|
|
|
#include "ED_types.h"
|
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
#include "UI_resources.h"
|
|
|
|
|
2009-07-28 08:50:11 +00:00
|
|
|
#include "console_intern.h"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
BugFix:
[#20854] PROPERTIES STAMP: Rendering stamp flickers in output renders
Blenfont was not thread safe, that is why one thread can change
the font properties (size, dpi, color, etc) at the same time
that the stamp draw on the image, and then the problem.
To make blenfont thread safe I have to change two important things:
1) Every BLF_* function take one argument, the font id.
2) We have two new function to make font "thread safe":
BLF_load_unique
BLF_load_mem_unique
This two function are for case like stamp, that need and own font
that don't share the glyph cache, so can draw without problem
in a different thread.
Why the BLF_*_unique function ?
Because blenfont keep only one copy of a font and keep a list of
"glyph cache". Every glyph cache have size and dpi, so if two
different thread access the same font at the same time, they can
change value and finish with something like the stamp problem.
Why don't remove the glyph cache ?
Because if we do that, we finish with a font object for every size
and dpi, and the stamp is really a special case that happen in
the rendering process, so I really thing is better keep the
glyph cache and make this two new function to handle this
special case.
(When I say "font object" I mean have the same freetype font multiple
times just to have differents size and dpi)
As Matt point we still can have one case that two thread access
the BLF_*_unique function at the same time, but I am looking to
fix this with some class of thread lock.
For now I test and work fine, so if some one found problem, please
let me know.
Campbell I have to change the python api (python/generic/blf_api.c)
to the new syntax, so maybe you can take a look at this.
2010-04-22 10:56:45 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
#include "../space_info/textview.h"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
static void console_line_color(unsigned char fg[3], int type)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
switch (type) {
|
|
|
|
case CONSOLE_LINE_OUTPUT:
|
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_OUTPUT, fg);
|
|
|
|
break;
|
|
|
|
case CONSOLE_LINE_INPUT:
|
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_INPUT, fg);
|
|
|
|
break;
|
|
|
|
case CONSOLE_LINE_INFO:
|
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_INFO, fg);
|
|
|
|
break;
|
|
|
|
case CONSOLE_LINE_ERROR:
|
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_ERROR, fg);
|
|
|
|
break;
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
typedef struct ConsoleDrawContext {
|
|
|
|
int cwidth;
|
|
|
|
int lheight;
|
|
|
|
int console_width;
|
|
|
|
int winx;
|
|
|
|
int ymin, ymax;
|
2011-06-11 17:05:20 +00:00
|
|
|
#if 0 /* used by textview, may use later */
|
2009-12-27 20:22:06 +00:00
|
|
|
int *xy; // [2]
|
|
|
|
int *sel; // [2]
|
2012-10-20 20:20:02 +00:00
|
|
|
int *pos_pick; /* bottom of view == 0, top of file == combine chars, end of line is lower then start. */
|
2009-12-27 20:22:06 +00:00
|
|
|
int *mval; // [2]
|
|
|
|
int draw;
|
2011-06-11 17:05:20 +00:00
|
|
|
#endif
|
2009-12-27 20:22:06 +00:00
|
|
|
} ConsoleDrawContext;
|
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
|
2009-12-27 20:22:06 +00:00
|
|
|
{
|
2010-11-11 05:45:55 +00:00
|
|
|
/* fake the edit line being in the scroll buffer */
|
2012-03-28 11:53:18 +00:00
|
|
|
ConsoleLine *cl = sc->history.last;
|
2012-10-14 19:57:49 +00:00
|
|
|
int prompt_len = strlen(sc->prompt);
|
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
cl_dummy->type = CONSOLE_LINE_INPUT;
|
2012-10-14 19:57:49 +00:00
|
|
|
cl_dummy->len = prompt_len + cl->len;
|
2012-03-28 11:53:18 +00:00
|
|
|
cl_dummy->len_alloc = cl_dummy->len + 1;
|
|
|
|
cl_dummy->line = MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
|
2012-10-14 19:57:49 +00:00
|
|
|
memcpy(cl_dummy->line, sc->prompt, prompt_len);
|
|
|
|
memcpy(cl_dummy->line + prompt_len, cl->line, cl->len + 1);
|
2010-11-11 05:45:55 +00:00
|
|
|
BLI_addtail(&sc->scrollback, cl_dummy);
|
|
|
|
}
|
|
|
|
void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
|
|
|
|
{
|
|
|
|
MEM_freeN(cl_dummy->line);
|
|
|
|
BLI_remlink(&sc->scrollback, cl_dummy);
|
|
|
|
}
|
2009-07-19 00:49:44 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
#define CONSOLE_DRAW_MARGIN 4
|
|
|
|
#define CONSOLE_DRAW_SCROLL 16
|
2010-09-27 15:14:58 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
/* console textview callbacks */
|
|
|
|
static int console_textview_begin(TextViewContext *tvc)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
|
|
|
|
tvc->lheight = sc->lheight;
|
|
|
|
tvc->sel_start = sc->sel_start;
|
|
|
|
tvc->sel_end = sc->sel_end;
|
2010-11-11 05:45:55 +00:00
|
|
|
|
|
|
|
/* iterator */
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter = sc->scrollback.last;
|
2010-11-11 05:45:55 +00:00
|
|
|
|
|
|
|
return (tvc->iter != NULL);
|
|
|
|
}
|
2009-12-27 20:22:06 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
static void console_textview_end(TextViewContext *tvc)
|
2009-12-27 20:22:06 +00:00
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
|
2010-11-11 05:45:55 +00:00
|
|
|
(void)sc;
|
2010-09-27 16:35:14 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
}
|
2009-12-27 20:22:06 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
static int console_textview_step(TextViewContext *tvc)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
return ((tvc->iter = (void *)((Link *)tvc->iter)->prev) != NULL);
|
2010-11-11 05:45:55 +00:00
|
|
|
}
|
2010-02-26 23:56:16 +00:00
|
|
|
|
2010-11-11 06:35:45 +00:00
|
|
|
static int console_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
|
2010-11-11 05:45:55 +00:00
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
ConsoleLine *cl = (ConsoleLine *)tvc->iter;
|
|
|
|
*line = cl->line;
|
|
|
|
*len = cl->len;
|
2010-02-26 23:56:16 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2009-07-16 07:11:46 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
static int console_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char UNUSED(bg[3]))
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
ConsoleLine *cl_iter = (ConsoleLine *)tvc->iter;
|
2010-09-27 15:14:58 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
/* annoying hack, to draw the prompt */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tvc->iter_index == 0) {
|
2012-03-28 11:53:18 +00:00
|
|
|
const SpaceConsole *sc = (SpaceConsole *)tvc->arg1;
|
|
|
|
const ConsoleLine *cl = (ConsoleLine *)sc->history.last;
|
|
|
|
const int prompt_len = strlen(sc->prompt);
|
|
|
|
const int cursor_loc = cl->cursor + prompt_len;
|
2012-10-14 19:57:49 +00:00
|
|
|
const int line_len = cl->len + prompt_len;
|
2010-11-11 05:45:55 +00:00
|
|
|
int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN};
|
2010-11-29 20:42:03 +00:00
|
|
|
int pen[2];
|
2012-03-28 11:53:18 +00:00
|
|
|
xy[1] += tvc->lheight / 6;
|
2010-11-29 20:42:03 +00:00
|
|
|
|
|
|
|
/* account for wrapping */
|
2012-10-14 19:57:49 +00:00
|
|
|
if (line_len < tvc->console_width) {
|
2010-11-29 20:42:03 +00:00
|
|
|
/* simple case, no wrapping */
|
2012-03-28 11:53:18 +00:00
|
|
|
pen[0] = tvc->cwidth * cursor_loc;
|
|
|
|
pen[1] = -2;
|
2010-11-29 20:42:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* wrap */
|
2012-03-28 11:53:18 +00:00
|
|
|
pen[0] = tvc->cwidth * (cursor_loc % tvc->console_width);
|
2012-10-14 19:57:49 +00:00
|
|
|
pen[1] = -2 + (((line_len / tvc->console_width) - (cursor_loc / tvc->console_width)) * tvc->lheight);
|
2010-11-29 20:42:03 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
/* cursor */
|
2010-12-20 03:59:22 +00:00
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, fg);
|
2010-09-27 17:22:59 +00:00
|
|
|
glColor3ubv(fg);
|
2009-07-16 07:11:46 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
glRecti((xy[0] + pen[0]) - 1,
|
|
|
|
(xy[1] + pen[1]),
|
|
|
|
(xy[0] + pen[0]) + 1,
|
|
|
|
(xy[1] + pen[1] + tvc->lheight)
|
|
|
|
);
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
2009-07-16 07:11:46 +00:00
|
|
|
|
2010-12-03 12:30:59 +00:00
|
|
|
console_line_color(fg, cl_iter->type);
|
2009-07-16 07:11:46 +00:00
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
return TVC_LINE_FG;
|
|
|
|
}
|
2009-07-16 07:11:46 +00:00
|
|
|
|
2010-11-02 13:12:30 +00:00
|
|
|
|
2012-07-26 22:47:05 +00:00
|
|
|
static int console_textview_main__internal(struct SpaceConsole *sc, ARegion *ar, int draw, int mval[2], void **mouse_pick, int *pos_pick)
|
2010-11-11 05:45:55 +00:00
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
ConsoleLine cl_dummy = {NULL};
|
|
|
|
int ret = 0;
|
2010-11-11 05:45:55 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
View2D *v2d = &ar->v2d;
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
TextViewContext tvc = {0};
|
2010-11-30 22:39:41 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc.begin = console_textview_begin;
|
|
|
|
tvc.end = console_textview_end;
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc.step = console_textview_step;
|
|
|
|
tvc.line_get = console_textview_line_get;
|
|
|
|
tvc.line_color = console_textview_line_color;
|
2010-11-11 05:45:55 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc.arg1 = sc;
|
|
|
|
tvc.arg2 = NULL;
|
2010-11-11 05:45:55 +00:00
|
|
|
|
2010-11-11 13:36:57 +00:00
|
|
|
/* view */
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc.sel_start = sc->sel_start;
|
|
|
|
tvc.sel_end = sc->sel_end;
|
|
|
|
tvc.lheight = sc->lheight;
|
2012-03-24 02:51:46 +00:00
|
|
|
tvc.ymin = v2d->cur.ymin;
|
|
|
|
tvc.ymax = v2d->cur.ymax;
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc.winx = ar->winx;
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2010-11-11 13:36:57 +00:00
|
|
|
console_scrollback_prompt_begin(sc, &cl_dummy);
|
2012-03-28 11:53:18 +00:00
|
|
|
ret = textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
|
2010-11-11 13:36:57 +00:00
|
|
|
console_scrollback_prompt_end(sc, &cl_dummy);
|
2009-07-19 00:49:44 +00:00
|
|
|
|
2010-11-11 13:36:57 +00:00
|
|
|
return ret;
|
2009-07-16 22:47:27 +00:00
|
|
|
}
|
|
|
|
|
2010-11-11 05:45:55 +00:00
|
|
|
|
2012-07-26 22:47:05 +00:00
|
|
|
void console_textview_main(struct SpaceConsole *sc, ARegion *ar)
|
2009-07-16 22:47:27 +00:00
|
|
|
{
|
2009-12-27 20:22:06 +00:00
|
|
|
int mval[2] = {INT_MAX, INT_MAX};
|
2010-11-30 22:39:41 +00:00
|
|
|
console_textview_main__internal(sc, ar, 1, mval, NULL, NULL);
|
2009-07-16 22:47:27 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 22:47:05 +00:00
|
|
|
int console_textview_height(struct SpaceConsole *sc, ARegion *ar)
|
2009-07-16 22:47:27 +00:00
|
|
|
{
|
2009-12-27 20:22:06 +00:00
|
|
|
int mval[2] = {INT_MAX, INT_MAX};
|
2010-11-30 22:39:41 +00:00
|
|
|
return console_textview_main__internal(sc, ar, 0, mval, NULL, NULL);
|
2009-07-19 00:49:44 +00:00
|
|
|
}
|
|
|
|
|
2012-07-26 22:47:05 +00:00
|
|
|
int console_char_pick(struct SpaceConsole *sc, ARegion *ar, int mval[2])
|
2009-12-27 20:22:06 +00:00
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
int pos_pick = 0;
|
|
|
|
void *mouse_pick = NULL;
|
2010-09-27 17:22:59 +00:00
|
|
|
int mval_clamp[2];
|
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
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);
|
2010-09-27 17:22:59 +00:00
|
|
|
|
2010-11-30 22:39:41 +00:00
|
|
|
console_textview_main__internal(sc, ar, 0, mval_clamp, &mouse_pick, &pos_pick);
|
2009-12-27 20:22:06 +00:00
|
|
|
return pos_pick;
|
|
|
|
}
|