Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-11-11 08:45:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-11-11 08:45:55 +0300
commite47d84026d3a03e3faa7ac0a5ba87bd67bcf6c72 (patch)
tree6b02ba7a22bf9a562e9085f62a815be10971c587 /source
parent662b35a2c0815258adb8abc8265dca01ba703b3b (diff)
make console wrapped text drawing into its own function in preparation to move report view out of the console space type. (no functional changes)
also remove incorrect messages about the original copyright in the GPL headers.
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/space_console/console_draw.c423
-rw-r--r--source/blender/editors/space_console/console_intern.h4
-rw-r--r--source/blender/editors/space_console/console_ops.c5
-rw-r--r--source/blender/editors/space_console/console_report.c5
-rw-r--r--source/blender/editors/space_console/space_console.c4
-rw-r--r--source/blender/editors/space_info/CMakeLists.txt2
-rw-r--r--source/blender/editors/space_info/textview.c307
-rw-r--r--source/blender/editors/space_info/textview.h52
8 files changed, 512 insertions, 290 deletions
diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c
index f1fead47a0a..38222f097ce 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -17,11 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
@@ -58,18 +53,9 @@
#include "console_intern.h"
-static int mono= -1; // XXX needs proper storage and change all the BLF_* here!
-
-static void console_font_begin(SpaceConsole *sc)
-{
- if(mono == -1)
- mono= BLF_load_mem("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
-
- BLF_aspect(mono, 1.0);
- BLF_size(mono, sc->lheight-2, 72);
-}
+#include "../space_info/textview.h"
-static void console_line_color(unsigned char *fg, int type)
+static void console_line_color(unsigned char fg[3], int type)
{
switch(type) {
case CONSOLE_LINE_OUTPUT:
@@ -133,310 +119,203 @@ typedef struct ConsoleDrawContext {
int draw;
} ConsoleDrawContext;
-static void console_draw_sel(int sel[2], int xy[2], int str_len_draw, int cwidth, int lheight)
+void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
{
- if(sel[0] <= str_len_draw && sel[1] >= 0) {
- int sta = MAX2(sel[0], 0);
- int end = MIN2(sel[1], str_len_draw);
-
- glEnable(GL_POLYGON_STIPPLE);
- glPolygonStipple(stipple_halftone);
- glEnable( GL_BLEND );
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4ub(255, 255, 255, 96);
+ /* fake the edit line being in the scroll buffer */
+ ConsoleLine *cl= sc->history.last;
+ cl_dummy->type= CONSOLE_LINE_INPUT;
+ cl_dummy->len= cl_dummy->len_alloc= strlen(sc->prompt) + cl->len;
+ cl_dummy->len_alloc= cl_dummy->len + 1;
+ cl_dummy->line= MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
+ memcpy(cl_dummy->line, sc->prompt, (cl_dummy->len_alloc - cl->len));
+ memcpy(cl_dummy->line + ((cl_dummy->len_alloc - cl->len)) - 1, cl->line, cl->len + 1);
+ 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);
+}
- glRecti(xy[0]+(cwidth*sta), xy[1]-2 + lheight, xy[0]+(cwidth*end), xy[1]-2);
+#define CONSOLE_DRAW_MARGIN 4
+#define CONSOLE_DRAW_SCROLL 16
- glDisable(GL_POLYGON_STIPPLE);
- glDisable( GL_BLEND );
- }
-}
-/* return 0 if the last line is off the screen
- * should be able to use this for any string type */
+/* console textview callbacks */
+static int console_textview_begin(TextViewContext *tvc)
+{
+ SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
+ tvc->lheight= sc->lheight;
+ tvc->sel_start= sc->sel_start;
+ tvc->sel_end= sc->sel_end;
+
+ /* iterator */
+ tvc->iter= sc->scrollback.last;
+
+ return (tvc->iter != NULL);
+}
-static int console_draw_string(ConsoleDrawContext *cdc, char *str, int str_len, unsigned char *fg, unsigned char *bg)
+static void console_textview_end(TextViewContext *tvc)
{
-#define STEP_SEL(value) cdc->sel[0] += (value); cdc->sel[1] += (value)
- int rct_ofs= cdc->lheight/4;
- int tot_lines = (str_len/cdc->console_width)+1; /* total number of lines for wrapping */
- int y_next = (str_len > cdc->console_width) ? cdc->xy[1]+cdc->lheight*tot_lines : cdc->xy[1]+cdc->lheight;
-
- /* just advance the height */
- if(cdc->draw==0) {
- if(cdc->pos_pick && (cdc->mval[1] != INT_MAX)) {
- if(cdc->xy[1] <= cdc->mval[1]) {
- if((y_next >= cdc->mval[1])) {
- int ofs = (int)floor(((float)cdc->mval[0] / (float)cdc->cwidth));
-
- /* wrap */
- if(str_len > cdc->console_width)
- ofs += (cdc->console_width * ((int)((((float)(y_next - cdc->mval[1]) / (float)(y_next-cdc->xy[1])) * tot_lines))));
+ SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
+ (void)sc;
- CLAMP(ofs, 0, str_len);
- *cdc->pos_pick += str_len - ofs;
- } else
- *cdc->pos_pick += str_len + 1;
- }
- }
+}
- cdc->xy[1]= y_next;
- return 1;
- }
- else if (y_next-cdc->lheight < cdc->ymin) {
- /* have not reached the drawable area so don't break */
- cdc->xy[1]= y_next;
+static int console_textview_step(TextViewContext *tvc)
+{
+ return ((tvc->iter= (void *)((Link *)tvc->iter)->prev) != NULL);
+}
- /* adjust selection even if not drawing */
- if(cdc->sel[0] != cdc->sel[1]) {
- STEP_SEL(-(str_len + 1));
- }
+static int console_textview_line_get(struct TextViewContext *tvc, char **line, int *len)
+{
+ ConsoleLine *cl= (ConsoleLine *)tvc->iter;
+ *line= cl->line;
+ *len= cl->len;
- return 1;
- }
+ return 1;
+}
- if(str_len > cdc->console_width) { /* wrap? */
- const int initial_offset= ((tot_lines-1) * cdc->console_width);
- char *line_stride= str + initial_offset; /* advance to the last line and draw it first */
- char eol; /* baclup the end of wrapping */
-
- int sel_orig[2];
- VECCOPY2D(sel_orig, cdc->sel);
+static int console_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char UNUSED(bg[3]))
+{
+ ConsoleLine *cl= (ConsoleLine *)tvc->iter;
- /* invert and swap for wrapping */
- cdc->sel[0] = str_len - sel_orig[1];
- cdc->sel[1] = str_len - sel_orig[0];
+ /* annoying hack, to draw the prompt */
+ if(tvc->iter_index == 0) {
+ SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
+ int prompt_len= strlen(sc->prompt);
+ int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN};
+ const int cursor = ((ConsoleLine *)sc->history.last)->cursor;
- if(bg) {
- glColor3ubv(bg);
- glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, (cdc->xy[1]+(cdc->lheight*tot_lines))+rct_ofs);
- }
-
+ /* cursor */
+ UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
glColor3ubv(fg);
- /* last part needs no clipping */
- BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
- BLF_draw(mono, line_stride);
-
- if(cdc->sel[0] != cdc->sel[1]) {
- STEP_SEL(-initial_offset);
- // glColor4ub(255, 0, 0, 96); // debug
- console_draw_sel(cdc->sel, cdc->xy, str_len % cdc->console_width, cdc->cwidth, cdc->lheight);
- STEP_SEL(cdc->console_width);
- glColor3ubv(fg);
- }
-
- cdc->xy[1] += cdc->lheight;
-
- line_stride -= cdc->console_width;
-
- for(; line_stride >= str; line_stride -= cdc->console_width) {
- eol = line_stride[cdc->console_width];
- line_stride[cdc->console_width]= '\0';
-
- BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
- BLF_draw(mono, line_stride);
-
- if(cdc->sel[0] != cdc->sel[1]) {
- // glColor4ub(0, 255, 0, 96); // debug
- console_draw_sel(cdc->sel, cdc->xy, cdc->console_width, cdc->cwidth, cdc->lheight);
- STEP_SEL(cdc->console_width);
- glColor3ubv(fg);
- }
-
- cdc->xy[1] += cdc->lheight;
-
- line_stride[cdc->console_width] = eol; /* restore */
-
- /* check if were out of view bounds */
- if(cdc->xy[1] > cdc->ymax)
- return 0;
- }
-
- VECCOPY2D(cdc->sel, sel_orig);
- STEP_SEL(-(str_len + 1));
+ glRecti(xy[0]+(tvc->cwidth*(cursor+prompt_len)) -1, xy[1]-2, xy[0]+(tvc->cwidth*(cursor+prompt_len)) +1, xy[1]+tvc->lheight-2);
}
- else { /* simple, no wrap */
- if(bg) {
- glColor3ubv(bg);
- glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, cdc->xy[1]+cdc->lheight-rct_ofs);
- }
+ console_line_color(fg, cl->type);
- glColor3ubv(fg);
+ return TVC_LINE_FG;
+}
- BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
- BLF_draw(mono, str);
-
- if(cdc->sel[0] != cdc->sel[1]) {
- int isel[2];
- isel[0]= str_len - cdc->sel[1];
- isel[1]= str_len - cdc->sel[0];
- // glColor4ub(255, 255, 0, 96); // debug
- console_draw_sel(isel, cdc->xy, str_len, cdc->cwidth, cdc->lheight);
- STEP_SEL(-(str_len + 1));
- }
+/* reports! */
+static int report_textview_begin(TextViewContext *tvc)
+{
+ SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
+ ReportList *reports= (ReportList *)tvc->arg2;
- cdc->xy[1] += cdc->lheight;
+ tvc->lheight= sc->lheight;
+ tvc->sel_start= sc->sel_start;
+ tvc->sel_end= sc->sel_end;
+
+ /* iterator */
+ tvc->iter= reports->list.last;
+
+ glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ return (tvc->iter != NULL);
+}
- if(cdc->xy[1] > cdc->ymax)
- return 0;
- }
+static void report_textview_end(TextViewContext *UNUSED(tvc))
+{
+ /* pass */
+}
- return 1;
-#undef STEP_SEL
+static int report_textview_step(TextViewContext *tvc)
+{
+ return ((tvc->iter= (void *)((Link *)tvc->iter)->prev) != NULL);
}
-void console_scrollback_prompt_begin(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
+static int report_textview_line_get(struct TextViewContext *tvc, char **line, int *len)
{
- /* fake the edit line being in the scroll buffer */
- ConsoleLine *cl= sc->history.last;
- cl_dummy->type= CONSOLE_LINE_INPUT;
- cl_dummy->len= cl_dummy->len_alloc= strlen(sc->prompt) + cl->len;
- cl_dummy->len_alloc= cl_dummy->len + 1;
- cl_dummy->line= MEM_mallocN(cl_dummy->len_alloc, "cl_dummy");
- memcpy(cl_dummy->line, sc->prompt, (cl_dummy->len_alloc - cl->len));
- memcpy(cl_dummy->line + ((cl_dummy->len_alloc - cl->len)) - 1, cl->line, cl->len + 1);
- BLI_addtail(&sc->scrollback, cl_dummy);
+ Report *report= (Report *)tvc->iter;
+ *line= report->message;
+ *len= report->len;
+
+ return 1;
}
-void console_scrollback_prompt_end(struct SpaceConsole *sc, ConsoleLine *cl_dummy)
+
+static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3])
{
- MEM_freeN(cl_dummy->line);
- BLI_remlink(&sc->scrollback, cl_dummy);
+ Report *report= (Report *)tvc->iter;
+ console_report_color(fg, bg, report, tvc->iter_index % 2);
+ return TVC_LINE_FG | TVC_LINE_BG;
}
-#define CONSOLE_DRAW_MARGIN 4
-#define CONSOLE_DRAW_SCROLL 16
static int console_text_main__internal(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int draw, int mval[2], void **mouse_pick, int *pos_pick)
{
- View2D *v2d= &ar->v2d;
-
- ConsoleLine *cl= sc->history.last;
- ConsoleDrawContext cdc;
+ if(sc->type==CONSOLE_TYPE_PYTHON) {
+ int ret= 0;
+
+ View2D *v2d= &ar->v2d;
- int x_orig=CONSOLE_DRAW_MARGIN, y_orig=CONSOLE_DRAW_MARGIN;
- int xy[2], y_prev;
- int cwidth;
- int console_width; /* number of characters that fit into the width of the console (fixed width) */
- int sel[2]= {-1, -1}; /* defaults disabled */
- unsigned char fg[3];
-
- console_font_begin(sc);
- cwidth = BLF_fixed_width(mono);
+ TextViewContext tvc= {0};
+ tvc.begin= console_textview_begin;
+ tvc.end= console_textview_end;
- console_width= (ar->winx - (CONSOLE_DRAW_SCROLL + CONSOLE_DRAW_MARGIN*2) )/cwidth;
- if (console_width < 8) console_width= 8;
+ tvc.step= console_textview_step;
+ tvc.line_get= console_textview_line_get;
+ tvc.line_color= console_textview_line_color;
- xy[0]= x_orig; xy[1]= y_orig;
+ tvc.arg1= sc;
+ tvc.arg2= NULL;
- if(mval[1] != INT_MAX)
- mval[1] += (v2d->cur.ymin + CONSOLE_DRAW_MARGIN);
-
- if(pos_pick)
- *pos_pick = 0;
-
- /* constants for the sequencer context */
- cdc.cwidth= cwidth;
- cdc.lheight= sc->lheight;
- cdc.console_width= console_width;
- cdc.winx= ar->winx-(CONSOLE_DRAW_MARGIN+CONSOLE_DRAW_SCROLL);
- cdc.ymin= v2d->cur.ymin;
- cdc.ymax= v2d->cur.ymax;
- cdc.xy= xy;
- cdc.sel= sel;
- cdc.pos_pick= pos_pick;
- cdc.mval= mval;
- cdc.draw= draw;
-
- if(sc->type==CONSOLE_TYPE_PYTHON) {
- ConsoleLine cl_dummy= {0};
- int prompt_len= strlen(sc->prompt);
-
- if(sc->sel_start != sc->sel_end) {
- sel[0]= sc->sel_start;
- sel[1]= sc->sel_end;
+ /* view */
+ tvc.sel_start= sc->sel_start;
+ tvc.sel_end= sc->sel_end;
+ tvc.lheight= sc->lheight;
+ tvc.ymin= v2d->cur.ymin;
+ tvc.ymax= v2d->cur.ymax;
+ tvc.winx= ar->winx;
+
+ {
+ ConsoleLine cl_dummy= {0};
+ console_scrollback_prompt_begin(sc, &cl_dummy);
+ ret= textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
+ console_scrollback_prompt_end(sc, &cl_dummy);
}
- /* text */
- if(draw) {
- /* cursor */
- UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
- glColor3ubv(fg);
- glRecti(xy[0]+(cwidth*(cl->cursor+prompt_len)) -1, xy[1]-2, xy[0]+(cwidth*(cl->cursor+prompt_len)) +1, xy[1]+sc->lheight-2);
-
- xy[0]= x_orig; /* remove prompt offset */
- }
-
- console_scrollback_prompt_begin(sc, &cl_dummy);
-
- for(cl= sc->scrollback.last; cl; cl= cl->prev) {
- y_prev= xy[1];
-
- if(draw)
- console_line_color(fg, cl->type);
+ return ret;
+ }
+ else {
+ int ret= 0;
- if(!console_draw_string(&cdc, cl->line, cl->len, fg, NULL)) {
- /* when drawing, if we pass v2d->cur.ymax, then quit */
- if(draw) {
- break; /* past the y limits */
- }
- }
+ View2D *v2d= &ar->v2d;
- if((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) {
- *mouse_pick= (void *)cl;
- break;
- }
- }
-
- console_scrollback_prompt_end(sc, &cl_dummy);
- }
- else {
- Report *report;
- int report_mask= 0;
- int bool= 0;
- unsigned char bg[3];
-
- if(draw) {
- glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
+ TextViewContext tvc= {0};
+ tvc.begin= report_textview_begin;
+ tvc.end= report_textview_end;
+
+ tvc.step= report_textview_step;
+ tvc.line_get= report_textview_line_get;
+ tvc.line_color= report_textview_line_color;
+
+ tvc.arg1= sc;
+ tvc.arg2= reports;
+
+ /* view */
+ tvc.sel_start= sc->sel_start;
+ tvc.sel_end= sc->sel_end;
+ tvc.lheight= sc->lheight;
+ tvc.ymin= v2d->cur.ymin;
+ tvc.ymax= v2d->cur.ymax;
+ tvc.winx= ar->winx;
+
+ {
+ ret= textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
}
- /* convert our display toggles into a flag compatible with BKE_report flags */
- report_mask= console_report_mask(sc);
-
- for(report=reports->list.last; report; report=report->prev) {
-
- if(report->type & report_mask) {
- y_prev= xy[1];
-
- if(draw)
- console_report_color(fg, bg, report, bool);
-
- if(!console_draw_string(&cdc, report->message, report->len, fg, bg)) {
- /* when drawing, if we pass v2d->cur.ymax, then quit */
- if(draw) {
- break; /* past the y limits */
- }
- }
- if((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) {
- *mouse_pick= (void *)report;
- break;
- }
-
- bool = !(bool);
- }
- }
+ return ret;
}
- xy[1] += sc->lheight*2;
-
-
- return xy[1]-y_orig;
}
+
void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports)
{
int mval[2] = {INT_MAX, INT_MAX};
diff --git a/source/blender/editors/space_console/console_intern.h b/source/blender/editors/space_console/console_intern.h
index 1a48dd408bd..8e6b5dbfcdd 100644
--- a/source/blender/editors/space_console/console_intern.h
+++ b/source/blender/editors/space_console/console_intern.h
@@ -17,10 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
- *
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
diff --git a/source/blender/editors/space_console/console_ops.c b/source/blender/editors/space_console/console_ops.c
index ceb16d2aab9..c5c1f8d1d4c 100644
--- a/source/blender/editors/space_console/console_ops.c
+++ b/source/blender/editors/space_console/console_ops.c
@@ -17,11 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
diff --git a/source/blender/editors/space_console/console_report.c b/source/blender/editors/space_console/console_report.c
index 6483177a045..a714952eaaf 100644
--- a/source/blender/editors/space_console/console_report.c
+++ b/source/blender/editors/space_console/console_report.c
@@ -17,11 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index 72478133f1c..66e780f3a04 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -16,10 +16,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
*
* Contributor(s): Campbell Barton
*
diff --git a/source/blender/editors/space_info/CMakeLists.txt b/source/blender/editors/space_info/CMakeLists.txt
index 4187afd8df4..ff65efeead0 100644
--- a/source/blender/editors/space_info/CMakeLists.txt
+++ b/source/blender/editors/space_info/CMakeLists.txt
@@ -21,6 +21,7 @@
SET(INC
../include
+ ../../blenfont
../../blenkernel
../../blenlib
../../imbuf
@@ -33,6 +34,7 @@ SET(INC
SET(SRC
info_ops.c
info_stats.c
+ textview.c
space_info.c
)
diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c
new file mode 100644
index 00000000000..24f31da657f
--- /dev/null
+++ b/source/blender/editors/space_info/textview.c
@@ -0,0 +1,307 @@
+/**
+ * $Id: console_draw.c 32840 2010-11-02 13:12:30Z campbellbarton $
+ *
+ * ***** 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,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <math.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <limits.h>
+#include <assert.h>
+
+#include "BLF_api.h"
+
+#include "BKE_utildefines.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "ED_datafiles.h"
+
+#include "textview.h"
+
+
+static int mono= -1; // XXX needs proper storage and change all the BLF_* here!
+
+
+static void console_font_begin(TextViewContext *sc)
+{
+ if(mono == -1) {
+ mono= BLF_load_mem("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
+ }
+
+ BLF_aspect(mono, 1.0);
+ BLF_size(mono, sc->lheight-2, 72);
+}
+
+typedef struct ConsoleDrawContext {
+ int cwidth;
+ int lheight;
+ int console_width; /* number of characters that fit into the width of the console (fixed width) */
+ int winx;
+ int ymin, ymax;
+ int *xy; // [2]
+ int *sel; // [2]
+ int *pos_pick; // bottom of view == 0, top of file == combine chars, end of line is lower then start.
+ int *mval; // [2]
+ int draw;
+} ConsoleDrawContext;
+
+static void console_draw_sel(int sel[2], int xy[2], int str_len_draw, int cwidth, int lheight)
+{
+ if(sel[0] <= str_len_draw && sel[1] >= 0) {
+ int sta = MAX2(sel[0], 0);
+ int end = MIN2(sel[1], str_len_draw);
+
+ glEnable(GL_POLYGON_STIPPLE);
+ glPolygonStipple(stipple_halftone);
+ glEnable( GL_BLEND );
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4ub(255, 255, 255, 96);
+
+ glRecti(xy[0]+(cwidth*sta), xy[1]-2 + lheight, xy[0]+(cwidth*end), xy[1]-2);
+
+ glDisable(GL_POLYGON_STIPPLE);
+ glDisable( GL_BLEND );
+ }
+}
+
+
+/* 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(ConsoleDrawContext *cdc, char *str, int str_len, unsigned char *fg, unsigned char *bg)
+{
+#define STEP_SEL(value) cdc->sel[0] += (value); cdc->sel[1] += (value)
+ int rct_ofs= cdc->lheight/4;
+ int tot_lines = (str_len/cdc->console_width)+1; /* total number of lines for wrapping */
+ int y_next = (str_len > cdc->console_width) ? cdc->xy[1]+cdc->lheight*tot_lines : cdc->xy[1]+cdc->lheight;
+
+ /* just advance the height */
+ if(cdc->draw==0) {
+ if(cdc->pos_pick && (cdc->mval[1] != INT_MAX)) {
+ if(cdc->xy[1] <= cdc->mval[1]) {
+ if((y_next >= cdc->mval[1])) {
+ int ofs = (int)floor(((float)cdc->mval[0] / (float)cdc->cwidth));
+
+ /* wrap */
+ if(str_len > cdc->console_width)
+ ofs += (cdc->console_width * ((int)((((float)(y_next - cdc->mval[1]) / (float)(y_next-cdc->xy[1])) * tot_lines))));
+
+ CLAMP(ofs, 0, str_len);
+ *cdc->pos_pick += str_len - ofs;
+ } else
+ *cdc->pos_pick += str_len + 1;
+ }
+ }
+
+ cdc->xy[1]= y_next;
+ return 1;
+ }
+ else if (y_next-cdc->lheight < cdc->ymin) {
+ /* have not reached the drawable area so don't break */
+ cdc->xy[1]= y_next;
+
+ /* adjust selection even if not drawing */
+ if(cdc->sel[0] != cdc->sel[1]) {
+ STEP_SEL(-(str_len + 1));
+ }
+
+ return 1;
+ }
+
+ if(str_len > cdc->console_width) { /* wrap? */
+ const int initial_offset= ((tot_lines-1) * cdc->console_width);
+ char *line_stride= str + initial_offset; /* advance to the last line and draw it first */
+ char eol; /* baclup the end of wrapping */
+
+ int sel_orig[2];
+ VECCOPY2D(sel_orig, cdc->sel);
+
+ /* invert and swap for wrapping */
+ cdc->sel[0] = str_len - sel_orig[1];
+ cdc->sel[1] = str_len - sel_orig[0];
+
+ if(bg) {
+ glColor3ubv(bg);
+ glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, (cdc->xy[1]+(cdc->lheight*tot_lines))+rct_ofs);
+ }
+
+ glColor3ubv(fg);
+
+ /* last part needs no clipping */
+ BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
+ BLF_draw(mono, line_stride);
+
+ if(cdc->sel[0] != cdc->sel[1]) {
+ STEP_SEL(-initial_offset);
+ // glColor4ub(255, 0, 0, 96); // debug
+ console_draw_sel(cdc->sel, cdc->xy, str_len % cdc->console_width, cdc->cwidth, cdc->lheight);
+ STEP_SEL(cdc->console_width);
+ glColor3ubv(fg);
+ }
+
+ cdc->xy[1] += cdc->lheight;
+
+ line_stride -= cdc->console_width;
+
+ for(; line_stride >= str; line_stride -= cdc->console_width) {
+ eol = line_stride[cdc->console_width];
+ line_stride[cdc->console_width]= '\0';
+
+ BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
+ BLF_draw(mono, line_stride);
+
+ if(cdc->sel[0] != cdc->sel[1]) {
+ // glColor4ub(0, 255, 0, 96); // debug
+ console_draw_sel(cdc->sel, cdc->xy, cdc->console_width, cdc->cwidth, cdc->lheight);
+ STEP_SEL(cdc->console_width);
+ glColor3ubv(fg);
+ }
+
+ cdc->xy[1] += cdc->lheight;
+
+ line_stride[cdc->console_width] = eol; /* restore */
+
+ /* check if were out of view bounds */
+ if(cdc->xy[1] > cdc->ymax)
+ return 0;
+ }
+
+ VECCOPY2D(cdc->sel, sel_orig);
+ STEP_SEL(-(str_len + 1));
+ }
+ else { /* simple, no wrap */
+
+ if(bg) {
+ glColor3ubv(bg);
+ glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, cdc->xy[1]+cdc->lheight-rct_ofs);
+ }
+
+ glColor3ubv(fg);
+
+ BLF_position(mono, cdc->xy[0], cdc->xy[1], 0);
+ BLF_draw(mono, str);
+
+ if(cdc->sel[0] != cdc->sel[1]) {
+ int isel[2];
+
+ isel[0]= str_len - cdc->sel[1];
+ isel[1]= str_len - cdc->sel[0];
+
+ // glColor4ub(255, 255, 0, 96); // debug
+ console_draw_sel(isel, cdc->xy, str_len, cdc->cwidth, cdc->lheight);
+ STEP_SEL(-(str_len + 1));
+ }
+
+ cdc->xy[1] += cdc->lheight;
+
+ if(cdc->xy[1] > cdc->ymax)
+ return 0;
+ }
+
+ return 1;
+#undef STEP_SEL
+}
+
+#define CONSOLE_DRAW_MARGIN 4
+#define CONSOLE_DRAW_SCROLL 16
+
+int textview_draw(TextViewContext *tvc, int draw, int mval[2], void **mouse_pick, int *pos_pick)
+{
+ ConsoleDrawContext cdc= {0};
+
+ int x_orig=CONSOLE_DRAW_MARGIN, y_orig=CONSOLE_DRAW_MARGIN;
+ int xy[2], y_prev;
+ int sel[2]= {-1, -1}; /* defaults disabled */
+ unsigned char fg[3], bg[3];
+
+ console_font_begin(tvc);
+
+ xy[0]= x_orig; xy[1]= y_orig;
+
+ if(mval[1] != INT_MAX)
+ mval[1] += (tvc->ymin + CONSOLE_DRAW_MARGIN);
+
+ if(pos_pick)
+ *pos_pick = 0;
+
+ /* constants for the sequencer context */
+ cdc.cwidth= (int)BLF_fixed_width(mono);
+ assert(cdc.cwidth > 0);
+ cdc.lheight= tvc->lheight;
+ cdc.console_width= (tvc->winx - (CONSOLE_DRAW_SCROLL + CONSOLE_DRAW_MARGIN*2) ) / cdc.cwidth;
+ cdc.winx= tvc->winx-(CONSOLE_DRAW_MARGIN+CONSOLE_DRAW_SCROLL);
+ cdc.ymin= tvc->ymin;
+ cdc.ymax= tvc->ymax;
+ cdc.xy= xy;
+ cdc.sel= sel;
+ cdc.pos_pick= pos_pick;
+ cdc.mval= mval;
+ cdc.draw= draw;
+
+ /* shouldnt be needed */
+ tvc->cwidth= cdc.cwidth;
+ tvc->iter_index= 0;
+
+ if(tvc->sel_start != tvc->sel_end) {
+ sel[0]= tvc->sel_start;
+ sel[1]= tvc->sel_end;
+ }
+
+ if(tvc->begin(tvc)) {
+
+ do {
+ char *ext_line;
+ int ext_len;
+ int color_flag= 0;
+
+ y_prev= xy[1];
+
+ if(draw)
+ color_flag= tvc->line_color(tvc, fg, bg);
+
+ tvc->line_get(tvc, &ext_line, &ext_len);
+
+ if(!console_draw_string(&cdc, ext_line, ext_len, (color_flag & TVC_LINE_FG) ? fg : NULL, (color_flag & TVC_LINE_BG) ? bg : NULL)) {
+ /* when drawing, if we pass v2d->cur.ymax, then quit */
+ if(draw) {
+ break; /* past the y limits */
+ }
+ }
+
+ if((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) {
+ *mouse_pick= (void *)tvc->iter;
+ break;
+ }
+
+ tvc->iter_index++;
+
+ } while(tvc->step(tvc));
+ }
+
+ tvc->end(tvc);
+
+ xy[1] += tvc->lheight * 2;
+
+ return xy[1] - y_orig;
+}
diff --git a/source/blender/editors/space_info/textview.h b/source/blender/editors/space_info/textview.h
new file mode 100644
index 00000000000..9e29cd76436
--- /dev/null
+++ b/source/blender/editors/space_info/textview.h
@@ -0,0 +1,52 @@
+/**
+ * $Id: console_draw.c 32840 2010-11-02 13:12:30Z campbellbarton $
+ *
+ * ***** 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,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Campbell Barton
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+typedef struct TextViewContext {
+ int lheight;
+ int sel_start, sel_end;
+
+ /* view settings */
+ int cwidth; /* shouldnt be needed! */
+ int winx;
+ int ymin, ymax;
+
+ /* callbacks */
+ int (*begin)(struct TextViewContext *tvc);
+ void (*end)(struct TextViewContext *tvc);
+ void *arg1;
+ void *arg2;
+
+ /* iterator */
+ int (*step)(struct TextViewContext *tvc);
+ int (*line_get)(struct TextViewContext *tvc, char **, int *);
+ int (*line_color)(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3]);
+ void *iter;
+ int iter_index;
+
+} TextViewContext;
+
+int textview_draw(struct TextViewContext *tvc, int draw, int mval[2], void **mouse_pick, int *pos_pick);
+
+#define TVC_LINE_FG (1<<0)
+#define TVC_LINE_BG (1<<1)