2009-07-16 00:50:27 +00:00
|
|
|
/**
|
2009-07-16 02:04:31 +00:00
|
|
|
* $Id$
|
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
|
|
|
*
|
|
|
|
|
* 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 *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#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 "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLF_api.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
// #include "BKE_suggestions.h"
|
|
|
|
|
#include "BKE_text.h"
|
|
|
|
|
#include "BKE_report.h"
|
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#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_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
2009-07-28 08:50:11 +00:00
|
|
|
#include "console_intern.h"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
static void console_font_begin(SpaceConsole *sc)
|
|
|
|
|
{
|
|
|
|
|
static int mono= -1; // XXX needs proper storage
|
|
|
|
|
|
|
|
|
|
if(mono == -1)
|
|
|
|
|
mono= BLF_load_mem("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
|
|
|
|
|
|
|
|
|
|
BLF_set(mono);
|
|
|
|
|
BLF_aspect(1.0);
|
|
|
|
|
|
2009-07-16 22:47:27 +00:00
|
|
|
BLF_size(sc->lheight-2, 72);
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
2009-07-16 07:11:46 +00:00
|
|
|
static void console_line_color(unsigned char *fg, int type)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2009-07-16 07:11:46 +00:00
|
|
|
switch(type) {
|
2009-07-16 00:50:27 +00:00
|
|
|
case CONSOLE_LINE_OUTPUT:
|
2010-01-15 22:40:33 +00:00
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_OUTPUT, (char *)fg);
|
2009-07-16 00:50:27 +00:00
|
|
|
break;
|
|
|
|
|
case CONSOLE_LINE_INPUT:
|
2010-01-15 22:40:33 +00:00
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_INPUT, (char *)fg);
|
2009-07-16 00:50:27 +00:00
|
|
|
break;
|
|
|
|
|
case CONSOLE_LINE_INFO:
|
2010-01-15 22:40:33 +00:00
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_INFO, (char *)fg);
|
2009-07-16 00:50:27 +00:00
|
|
|
break;
|
|
|
|
|
case CONSOLE_LINE_ERROR:
|
2010-01-15 22:40:33 +00:00
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_ERROR, (char *)fg);
|
2009-07-16 00:50:27 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-19 00:49:44 +00:00
|
|
|
static void console_report_color(unsigned char *fg, unsigned char *bg, Report *report, int bool)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2009-07-16 07:11:46 +00:00
|
|
|
/*
|
|
|
|
|
if (type & RPT_ERROR_ALL) { fg[0]=220; fg[1]=0; fg[2]=0; }
|
|
|
|
|
else if (type & RPT_WARNING_ALL) { fg[0]=220; fg[1]=96; fg[2]=96; }
|
|
|
|
|
else if (type & RPT_OPERATOR_ALL) { fg[0]=96; fg[1]=128; fg[2]=255; }
|
|
|
|
|
else if (type & RPT_INFO_ALL) { fg[0]=0; fg[1]=170; fg[2]=0; }
|
|
|
|
|
else if (type & RPT_DEBUG_ALL) { fg[0]=196; fg[1]=196; fg[2]=196; }
|
|
|
|
|
else { fg[0]=196; fg[1]=196; fg[2]=196; }
|
|
|
|
|
*/
|
2009-07-19 00:49:44 +00:00
|
|
|
if(report->flag & SELECT) {
|
|
|
|
|
fg[0]=255; fg[1]=255; fg[2]=255;
|
|
|
|
|
if(bool) {
|
|
|
|
|
bg[0]=96; bg[1]=128; bg[2]=255;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bg[0]=90; bg[1]=122; bg[2]=249;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
fg[0]=0; fg[1]=0; fg[2]=0;
|
|
|
|
|
|
|
|
|
|
if(bool) {
|
|
|
|
|
bg[0]=120; bg[1]=120; bg[2]=120;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bg[0]=114; bg[1]=114; bg[2]=114;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2009-12-27 20:22:06 +00:00
|
|
|
}
|
2009-07-19 00:49:44 +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;
|
|
|
|
|
int *xy; // [2]
|
|
|
|
|
int *sel; // [2]
|
|
|
|
|
int *pos_pick;
|
|
|
|
|
int *mval; // [2]
|
|
|
|
|
int draw;
|
|
|
|
|
} ConsoleDrawContext;
|
|
|
|
|
|
|
|
|
|
static void console_draw_sel(int sel[2], int xy[2], int str_len, int cwidth, int console_width, int lheight)
|
|
|
|
|
{
|
2010-02-26 23:56:16 +00:00
|
|
|
if(sel[0] <= str_len && sel[1] >= 0) {
|
2009-12-27 20:22:06 +00:00
|
|
|
int sta = MAX2(sel[0], 0);
|
|
|
|
|
int end = MIN2(sel[1], str_len);
|
2010-02-26 23:56:16 +00:00
|
|
|
|
|
|
|
|
/* highly confusing but draws correctly */
|
|
|
|
|
if(sel[0] < 0 || sel[1] > str_len) {
|
|
|
|
|
if(sel[0] > 0) {
|
|
|
|
|
end= sta;
|
|
|
|
|
sta= 0;
|
|
|
|
|
}
|
|
|
|
|
if (sel[1] <= str_len) {
|
|
|
|
|
sta= end;
|
|
|
|
|
end= str_len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* end confusement */
|
|
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
{
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-19 00:49:44 +00:00
|
|
|
|
2010-02-26 23:56:16 +00:00
|
|
|
sel[0] -= str_len + 1;
|
|
|
|
|
sel[1] -= str_len + 1;
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* return 0 if the last line is off the screen
|
|
|
|
|
* should be able to use this for any string type */
|
2009-12-27 20:22:06 +00:00
|
|
|
|
|
|
|
|
static int console_draw_string(ConsoleDrawContext *cdc, char *str, int str_len, unsigned char *fg, unsigned char *bg)
|
|
|
|
|
{
|
|
|
|
|
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;
|
2009-07-16 22:47:27 +00:00
|
|
|
|
|
|
|
|
/* just advance the height */
|
2009-12-27 20:22:06 +00:00
|
|
|
if(cdc->draw==0) {
|
|
|
|
|
if(cdc->pos_pick) {
|
|
|
|
|
if((cdc->mval[1] != INT_MAX) && cdc->xy[1] <= cdc->mval[1]) {
|
|
|
|
|
if((cdc->xy[1]+cdc->lheight >= cdc->mval[1])) {
|
|
|
|
|
int ofs = (int)floor(((float)cdc->mval[0] / (float)cdc->cwidth));
|
|
|
|
|
*cdc->pos_pick += MIN2(ofs, str_len);
|
|
|
|
|
} else
|
2010-02-26 23:56:16 +00:00
|
|
|
*cdc->pos_pick += str_len + 1;
|
2009-12-27 20:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cdc->xy[1]= y_next;
|
2009-07-18 16:27:25 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
2009-12-27 20:22:06 +00:00
|
|
|
else if (y_next-cdc->lheight < cdc->ymin) {
|
2009-07-18 16:27:25 +00:00
|
|
|
/* have not reached the drawable area so don't break */
|
2009-12-27 20:22:06 +00:00
|
|
|
cdc->xy[1]= y_next;
|
2010-02-26 23:56:16 +00:00
|
|
|
|
|
|
|
|
/* adjust selection even if not drawing */
|
|
|
|
|
if(cdc->sel[0] != cdc->sel[1]) {
|
|
|
|
|
cdc->sel[0] -= str_len + 1;
|
|
|
|
|
cdc->sel[1] -= str_len + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 22:47:27 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
2009-07-16 07:11:46 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
if(str_len > cdc->console_width) { /* wrap? */
|
|
|
|
|
char *line_stride= str + ((tot_lines-1) * cdc->console_width); /* advance to the last line and draw it first */
|
2009-07-18 16:27:25 +00:00
|
|
|
char eol; /* baclup the end of wrapping */
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-07-16 07:11:46 +00:00
|
|
|
if(bg) {
|
|
|
|
|
glColor3ub(bg[0], bg[1], bg[2]);
|
2009-12-27 20:22:06 +00:00
|
|
|
glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, (cdc->xy[1]+(cdc->lheight*tot_lines))+rct_ofs);
|
2009-07-16 07:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glColor3ub(fg[0], fg[1], fg[2]);
|
|
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* last part needs no clipping */
|
2009-12-27 20:22:06 +00:00
|
|
|
BLF_position(cdc->xy[0], cdc->xy[1], 0);
|
2009-07-16 00:50:27 +00:00
|
|
|
BLF_draw(line_stride);
|
2009-12-27 20:22:06 +00:00
|
|
|
|
|
|
|
|
if(cdc->sel[0] != cdc->sel[1]) {
|
|
|
|
|
cdc->sel[0] += str_len - (cdc->console_width % str_len);
|
|
|
|
|
cdc->sel[1] += str_len - (cdc->console_width % str_len);
|
|
|
|
|
console_draw_sel(cdc->sel, cdc->xy, cdc->console_width % str_len, cdc->cwidth, cdc->console_width, cdc->lheight);
|
|
|
|
|
glColor3ub(fg[0], fg[1], fg[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cdc->xy[1] += cdc->lheight;
|
|
|
|
|
|
|
|
|
|
line_stride -= cdc->console_width;
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
for(; line_stride >= str; line_stride -= cdc->console_width) {
|
|
|
|
|
eol = line_stride[cdc->console_width];
|
|
|
|
|
line_stride[cdc->console_width]= '\0';
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
BLF_position(cdc->xy[0], cdc->xy[1], 0);
|
2009-07-16 00:50:27 +00:00
|
|
|
BLF_draw(line_stride);
|
|
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
if(cdc->sel[0] != cdc->sel[1]) {
|
|
|
|
|
console_draw_sel(cdc->sel, cdc->xy, cdc->console_width, cdc->cwidth, cdc->console_width, cdc->lheight);
|
|
|
|
|
glColor3ub(fg[0], fg[1], fg[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cdc->xy[1] += cdc->lheight;
|
|
|
|
|
|
|
|
|
|
line_stride[cdc->console_width] = eol; /* restore */
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
/* check if were out of view bounds */
|
2009-12-27 20:22:06 +00:00
|
|
|
if(cdc->xy[1] > cdc->ymax)
|
2009-07-16 00:50:27 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else { /* simple, no wrap */
|
2009-07-16 07:11:46 +00:00
|
|
|
|
|
|
|
|
if(bg) {
|
|
|
|
|
glColor3ub(bg[0], bg[1], bg[2]);
|
2009-12-27 20:22:06 +00:00
|
|
|
glRecti(0, cdc->xy[1]-rct_ofs, cdc->winx, cdc->xy[1]+cdc->lheight-rct_ofs);
|
2009-07-16 07:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glColor3ub(fg[0], fg[1], fg[2]);
|
|
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
BLF_position(cdc->xy[0], cdc->xy[1], 0);
|
2009-07-16 00:50:27 +00:00
|
|
|
BLF_draw(str);
|
|
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
if(cdc->sel[0] != cdc->sel[1])
|
|
|
|
|
console_draw_sel(cdc->sel, cdc->xy, str_len, cdc->cwidth, cdc->console_width, cdc->lheight);
|
|
|
|
|
|
|
|
|
|
cdc->xy[1] += cdc->lheight;
|
|
|
|
|
|
|
|
|
|
if(cdc->xy[1] > cdc->ymax)
|
2009-07-16 00:50:27 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-16 22:47:27 +00:00
|
|
|
#define CONSOLE_DRAW_MARGIN 4
|
|
|
|
|
#define CONSOLE_DRAW_SCROLL 16
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
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)
|
2009-07-16 00:50:27 +00:00
|
|
|
{
|
2009-07-16 22:47:27 +00:00
|
|
|
View2D *v2d= &ar->v2d;
|
|
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
ConsoleLine *cl= sc->history.last;
|
2009-12-27 20:22:06 +00:00
|
|
|
ConsoleDrawContext cdc;
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
int x_orig=CONSOLE_DRAW_MARGIN, y_orig=CONSOLE_DRAW_MARGIN;
|
2009-12-27 20:22:06 +00:00
|
|
|
int xy[2], y_prev;
|
2009-07-16 00:50:27 +00:00
|
|
|
int cwidth;
|
|
|
|
|
int console_width; /* number of characters that fit into the width of the console (fixed width) */
|
2009-12-27 20:22:06 +00:00
|
|
|
int sel[2]= {-1, -1}; /* defaults disabled */
|
2009-07-16 07:11:46 +00:00
|
|
|
unsigned char fg[3];
|
2009-12-27 20:22:06 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
console_font_begin(sc);
|
|
|
|
|
cwidth = BLF_fixed_width();
|
|
|
|
|
|
2009-07-16 22:47:27 +00:00
|
|
|
console_width= (ar->winx - (CONSOLE_DRAW_SCROLL + CONSOLE_DRAW_MARGIN*2) )/cwidth;
|
2009-07-16 00:50:27 +00:00
|
|
|
if (console_width < 8) console_width= 8;
|
|
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
xy[0]= x_orig; xy[1]= y_orig;
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
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;
|
2009-07-19 00:49:44 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
if(sc->type==CONSOLE_TYPE_PYTHON) {
|
2009-07-16 22:47:27 +00:00
|
|
|
int prompt_len;
|
2009-12-27 20:22:06 +00:00
|
|
|
|
|
|
|
|
if(sc->sel_start != sc->sel_end) {
|
|
|
|
|
sel[0]= sc->sel_start;
|
|
|
|
|
sel[1]= sc->sel_end;
|
2010-02-26 23:56:16 +00:00
|
|
|
// printf("%d %d\n", sel[0], sel[1]);
|
2009-12-27 20:22:06 +00:00
|
|
|
}
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
/* text */
|
2009-07-16 22:47:27 +00:00
|
|
|
if(draw) {
|
|
|
|
|
prompt_len= strlen(sc->prompt);
|
|
|
|
|
console_line_color(fg, CONSOLE_LINE_INPUT);
|
|
|
|
|
glColor3ub(fg[0], fg[1], fg[2]);
|
|
|
|
|
|
|
|
|
|
/* command line */
|
|
|
|
|
if(prompt_len) {
|
2009-12-27 20:22:06 +00:00
|
|
|
BLF_position(xy[0], xy[1], 0); xy[0] += cwidth * prompt_len;
|
2009-07-16 22:47:27 +00:00
|
|
|
BLF_draw(sc->prompt);
|
|
|
|
|
}
|
2009-12-27 20:22:06 +00:00
|
|
|
BLF_position(xy[0], xy[1], 0);
|
2009-07-16 22:47:27 +00:00
|
|
|
BLF_draw(cl->line);
|
|
|
|
|
|
|
|
|
|
/* cursor */
|
2010-02-15 02:39:40 +00:00
|
|
|
UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, (char *)fg);
|
2009-07-16 22:47:27 +00:00
|
|
|
glColor3ub(fg[0], fg[1], fg[2]);
|
2009-12-27 20:22:06 +00:00
|
|
|
glRecti(xy[0]+(cwidth*cl->cursor) -1, xy[1]-2, xy[0]+(cwidth*cl->cursor) +1, xy[1]+sc->lheight-2);
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
xy[0]= x_orig; /* remove prompt offset */
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
xy[1] += sc->lheight;
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
for(cl= sc->scrollback.last; cl; cl= cl->prev) {
|
2009-12-27 20:22:06 +00:00
|
|
|
y_prev= xy[1];
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-07-16 22:47:27 +00:00
|
|
|
if(draw)
|
|
|
|
|
console_line_color(fg, cl->type);
|
|
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
if(!console_draw_string(&cdc, cl->line, cl->len, fg, NULL)) {
|
2009-07-16 22:47:27 +00:00
|
|
|
/* when drawing, if we pass v2d->cur.ymax, then quit */
|
|
|
|
|
if(draw) {
|
|
|
|
|
break; /* past the y limits */
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-19 00:49:44 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
if((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) {
|
2009-07-19 00:49:44 +00:00
|
|
|
*mouse_pick= (void *)cl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Report *report;
|
|
|
|
|
int report_mask= 0;
|
2009-07-16 07:11:46 +00:00
|
|
|
int bool= 0;
|
2009-07-19 00:49:44 +00:00
|
|
|
unsigned char bg[3];
|
|
|
|
|
|
2009-07-16 22:47:27 +00:00
|
|
|
if(draw) {
|
|
|
|
|
glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
}
|
2009-07-16 07:11:46 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
/* convert our display toggles into a flag compatible with BKE_report flags */
|
2009-07-19 00:49:44 +00:00
|
|
|
report_mask= console_report_mask(sc);
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
for(report=reports->list.last; report; report=report->prev) {
|
|
|
|
|
|
|
|
|
|
if(report->type & report_mask) {
|
2009-12-27 20:22:06 +00:00
|
|
|
y_prev= xy[1];
|
2009-07-16 07:11:46 +00:00
|
|
|
|
2009-07-16 22:47:27 +00:00
|
|
|
if(draw)
|
2009-07-19 00:49:44 +00:00
|
|
|
console_report_color(fg, bg, report, bool);
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
if(!console_draw_string(&cdc, report->message, report->len, fg, bg)) {
|
2009-07-16 22:47:27 +00:00
|
|
|
/* when drawing, if we pass v2d->cur.ymax, then quit */
|
|
|
|
|
if(draw) {
|
|
|
|
|
break; /* past the y limits */
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-12-27 20:22:06 +00:00
|
|
|
if((mval[1] != INT_MAX) && (mval[1] >= y_prev && mval[1] <= xy[1])) {
|
2009-07-19 00:49:44 +00:00
|
|
|
*mouse_pick= (void *)report;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2009-07-16 07:11:46 +00:00
|
|
|
bool = !(bool);
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-12-27 20:22:06 +00:00
|
|
|
xy[1] += sc->lheight*2;
|
2009-07-16 22:47:27 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-12-27 20:22:06 +00:00
|
|
|
return xy[1]-y_orig;
|
2009-07-16 22:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void console_text_main(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports)
|
|
|
|
|
{
|
2009-12-27 20:22:06 +00:00
|
|
|
int mval[2] = {INT_MAX, INT_MAX};
|
|
|
|
|
console_text_main__internal(sc, ar, reports, 1, mval, NULL, NULL);
|
2009-07-16 22:47:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int console_text_height(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports)
|
|
|
|
|
{
|
2009-12-27 20:22:06 +00:00
|
|
|
int mval[2] = {INT_MAX, INT_MAX};
|
|
|
|
|
return console_text_main__internal(sc, ar, reports, 0, mval, NULL, NULL);
|
2009-07-19 00:49:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *console_text_pick(struct SpaceConsole *sc, struct ARegion *ar, ReportList *reports, int mouse_y)
|
|
|
|
|
{
|
2009-12-27 20:22:06 +00:00
|
|
|
int mval[2] = {0, mouse_y};
|
2009-07-19 00:49:44 +00:00
|
|
|
void *mouse_pick= NULL;
|
2009-12-27 20:22:06 +00:00
|
|
|
console_text_main__internal(sc, ar, reports, 0, mval, &mouse_pick, NULL);
|
2009-07-19 00:49:44 +00:00
|
|
|
return (void *)mouse_pick;
|
2009-07-16 00:50:27 +00:00
|
|
|
}
|
2009-12-27 20:22:06 +00:00
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
return pos_pick;
|
|
|
|
|
}
|