2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2010-11-11 13:36:57 +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,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2010 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_info/info_draw.c
|
|
|
|
* \ingroup spinfo
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-11-11 13:36:57 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "BLF_api.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2010-11-11 13:36:57 +00:00
|
|
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
// #include "BKE_suggestions.h"
|
|
|
|
#include "BKE_report.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-11-11 13:36:57 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
#include "ED_datafiles.h"
|
|
|
|
#include "ED_types.h"
|
|
|
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
2010-12-02 21:48:46 +00:00
|
|
|
#include "info_intern.h"
|
2010-11-11 13:36:57 +00:00
|
|
|
#include "../space_info/textview.h"
|
|
|
|
|
2010-12-02 21:48:46 +00:00
|
|
|
/* complicates things a bit, so leaving in old simple code */
|
|
|
|
#define USE_INFO_NEWLINE
|
|
|
|
|
2012-06-01 20:28:53 +00:00
|
|
|
static void info_report_color(unsigned char *fg, unsigned char *bg, Report *report, const short do_tint)
|
2010-11-11 13:36:57 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (report->flag & SELECT) {
|
2012-03-28 11:53:18 +00:00
|
|
|
fg[0] = 255; fg[1] = 255; fg[2] = 255;
|
2012-06-01 20:28:53 +00:00
|
|
|
if (do_tint) {
|
2012-03-28 11:53:18 +00:00
|
|
|
bg[0] = 96; bg[1] = 128; bg[2] = 255;
|
2010-11-11 13:36:57 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-28 11:53:18 +00:00
|
|
|
bg[0] = 90; bg[1] = 122; bg[2] = 249;
|
2010-11-11 13:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-28 11:53:18 +00:00
|
|
|
fg[0] = 0; fg[1] = 0; fg[2] = 0;
|
2011-02-20 21:32:21 +00:00
|
|
|
|
|
|
|
if (report->type & RPT_ERROR_ALL) {
|
2012-06-01 20:28:53 +00:00
|
|
|
if (do_tint) { bg[0] = 220; bg[1] = 0; bg[2] = 0; }
|
|
|
|
else { bg[0] = 214; bg[1] = 0; bg[2] = 0; }
|
2011-02-20 21:32:21 +00:00
|
|
|
}
|
|
|
|
else if (report->type & RPT_WARNING_ALL) {
|
2012-06-01 20:28:53 +00:00
|
|
|
if (do_tint) { bg[0] = 220; bg[1] = 128; bg[2] = 96; }
|
|
|
|
else { bg[0] = 214; bg[1] = 122; bg[2] = 90; }
|
2011-02-20 21:32:21 +00:00
|
|
|
}
|
2011-09-25 12:31:21 +00:00
|
|
|
#if 0 // XXX: this looks like the selected color, so don't use this
|
2011-02-20 21:32:21 +00:00
|
|
|
else if (report->type & RPT_OPERATOR_ALL) {
|
2012-06-01 20:28:53 +00:00
|
|
|
if (do_tint) { bg[0] = 96; bg[1] = 128; bg[2] = 255; }
|
|
|
|
else { bg[0] = 90; bg[1] = 122; bg[2] = 249; }
|
2011-02-20 21:32:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (report->type & RPT_INFO_ALL) {
|
2012-06-01 20:28:53 +00:00
|
|
|
if (do_tint) { bg[0] = 0; bg[1] = 170; bg[2] = 0; }
|
|
|
|
else { bg[0] = 0; bg[1] = 164; bg[2] = 0; }
|
2011-02-20 21:32:21 +00:00
|
|
|
}
|
|
|
|
else if (report->type & RPT_DEBUG_ALL) {
|
2012-06-01 20:28:53 +00:00
|
|
|
if (do_tint) { bg[0] = 196; bg[1] = 196; bg[2] = 196; }
|
|
|
|
else { bg[0] = 190; bg[1] = 190; bg[2] = 190; }
|
2010-11-11 13:36:57 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-01 20:28:53 +00:00
|
|
|
if (do_tint) { bg[0] = 120; bg[1] = 120; bg[2] = 120; }
|
|
|
|
else { bg[0] = 114; bg[1] = 114; bg[2] = 114; }
|
2010-11-11 13:36:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reports! */
|
2010-12-02 21:48:46 +00:00
|
|
|
#ifdef USE_INFO_NEWLINE
|
|
|
|
static void report_textview_init__internal(TextViewContext *tvc)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
Report *report = (Report *)tvc->iter;
|
|
|
|
const char *str = report->message;
|
|
|
|
const char *next_str = strchr(str + tvc->iter_char, '\n');
|
2010-12-02 21:48:46 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (next_str) {
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter_char_next = (int)(next_str - str);
|
2010-12-02 21:48:46 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter_char_next = report->len;
|
2010-12-02 21:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int report_textview_skip__internal(TextViewContext *tvc)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
SpaceInfo *sinfo = (SpaceInfo *)tvc->arg1;
|
|
|
|
const int report_mask = info_report_mask(sinfo);
|
|
|
|
while (tvc->iter && (((Report *)tvc->iter)->type & report_mask) == 0) {
|
|
|
|
tvc->iter = (void *)((Link *)tvc->iter)->prev;
|
2010-12-02 21:48:46 +00:00
|
|
|
}
|
|
|
|
return (tvc->iter != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_INFO_NEWLINE
|
|
|
|
|
2010-11-11 13:36:57 +00:00
|
|
|
static int report_textview_begin(TextViewContext *tvc)
|
|
|
|
{
|
|
|
|
// SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
|
2012-03-28 11:53:18 +00:00
|
|
|
ReportList *reports = (ReportList *)tvc->arg2;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->lheight = 14; //sc->lheight;
|
|
|
|
tvc->sel_start = 0;
|
|
|
|
tvc->sel_end = 0;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
|
|
|
/* iterator */
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter = reports->list.last;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
glClearColor(120.0 / 255.0, 120.0 / 255.0, 120.0 / 255.0, 1.0);
|
2010-11-11 13:36:57 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
2010-12-02 21:48:46 +00:00
|
|
|
#ifdef USE_INFO_NEWLINE
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter_tmp = 0;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tvc->iter && report_textview_skip__internal(tvc)) {
|
2010-12-02 21:48:46 +00:00
|
|
|
/* init the newline iterator */
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter_char = 0;
|
2010-12-02 21:48:46 +00:00
|
|
|
report_textview_init__internal(tvc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#else
|
2010-11-11 13:36:57 +00:00
|
|
|
return (tvc->iter != NULL);
|
2010-12-02 21:48:46 +00:00
|
|
|
#endif
|
2010-11-11 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void report_textview_end(TextViewContext *UNUSED(tvc))
|
|
|
|
{
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
|
2010-12-02 21:48:46 +00:00
|
|
|
#ifdef USE_INFO_NEWLINE
|
|
|
|
static int report_textview_step(TextViewContext *tvc)
|
|
|
|
{
|
|
|
|
/* simple case, but no newline support */
|
2012-03-28 11:53:18 +00:00
|
|
|
Report *report = (Report *)tvc->iter;
|
2010-12-02 21:48:46 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (report->len <= tvc->iter_char_next) {
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter = (void *)((Link *)tvc->iter)->prev;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tvc->iter && report_textview_skip__internal(tvc)) {
|
2010-12-02 21:48:46 +00:00
|
|
|
tvc->iter_tmp++;
|
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter_char = 0; /* reset start */
|
2010-12-02 21:48:46 +00:00
|
|
|
report_textview_init__internal(tvc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* step to the next newline */
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter_char = tvc->iter_char_next + 1;
|
2010-12-02 21:48:46 +00:00
|
|
|
report_textview_init__internal(tvc);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
Report *report = (Report *)tvc->iter;
|
|
|
|
*line = report->message + tvc->iter_char;
|
|
|
|
*len = tvc->iter_char_next - tvc->iter_char;
|
2010-12-02 21:48:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3])
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
Report *report = (Report *)tvc->iter;
|
2010-12-02 21:48:46 +00:00
|
|
|
info_report_color(fg, bg, report, tvc->iter_tmp % 2);
|
|
|
|
return TVC_LINE_FG | TVC_LINE_BG;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#else // USE_INFO_NEWLINE
|
|
|
|
|
2010-11-11 13:36:57 +00:00
|
|
|
static int report_textview_step(TextViewContext *tvc)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
SpaceInfo *sinfo = (SpaceInfo *)tvc->arg1;
|
|
|
|
const int report_mask = info_report_mask(sinfo);
|
2010-12-02 21:48:46 +00:00
|
|
|
do {
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc->iter = (void *)((Link *)tvc->iter)->prev;
|
|
|
|
} while (tvc->iter && (((Report *)tvc->iter)->type & report_mask) == 0);
|
2010-12-02 21:48:46 +00:00
|
|
|
|
|
|
|
return (tvc->iter != NULL);
|
2010-11-11 13:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
Report *report = (Report *)tvc->iter;
|
|
|
|
*line = report->message;
|
|
|
|
*len = report->len;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3])
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
Report *report = (Report *)tvc->iter;
|
2010-12-02 21:48:46 +00:00
|
|
|
info_report_color(fg, bg, report, tvc->iter_tmp % 2);
|
2010-11-11 13:36:57 +00:00
|
|
|
return TVC_LINE_FG | TVC_LINE_BG;
|
|
|
|
}
|
|
|
|
|
2010-12-02 21:48:46 +00:00
|
|
|
#endif // USE_INFO_NEWLINE
|
|
|
|
|
|
|
|
#undef USE_INFO_NEWLINE
|
2010-11-11 13:36:57 +00:00
|
|
|
|
|
|
|
static int info_textview_main__internal(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports, int draw, int mval[2], void **mouse_pick, int *pos_pick)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
int ret = 0;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
View2D *v2d = &ar->v2d;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
TextViewContext tvc = {0};
|
|
|
|
tvc.begin = report_textview_begin;
|
|
|
|
tvc.end = report_textview_end;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc.step = report_textview_step;
|
|
|
|
tvc.line_get = report_textview_line_get;
|
|
|
|
tvc.line_color = report_textview_line_color;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc.arg1 = sinfo;
|
|
|
|
tvc.arg2 = reports;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
|
|
|
/* view */
|
2012-03-28 11:53:18 +00:00
|
|
|
tvc.sel_start = 0;
|
|
|
|
tvc.sel_end = 0;
|
|
|
|
tvc.lheight = 14; //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;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *info_text_pick(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports, int mouse_y)
|
|
|
|
{
|
2012-03-28 11:53:18 +00:00
|
|
|
void *mouse_pick = NULL;
|
2010-11-11 13:36:57 +00:00
|
|
|
int mval[2];
|
|
|
|
|
2012-03-28 11:53:18 +00:00
|
|
|
mval[0] = 0;
|
|
|
|
mval[1] = mouse_y;
|
2010-11-11 13:36:57 +00:00
|
|
|
|
|
|
|
info_textview_main__internal(sinfo, ar, reports, 0, mval, &mouse_pick, NULL);
|
|
|
|
return (void *)mouse_pick;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int info_textview_height(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports)
|
|
|
|
{
|
|
|
|
int mval[2] = {INT_MAX, INT_MAX};
|
|
|
|
return info_textview_main__internal(sinfo, ar, reports, 0, mval, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void info_textview_main(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports)
|
|
|
|
{
|
|
|
|
int mval[2] = {INT_MAX, INT_MAX};
|
|
|
|
info_textview_main__internal(sinfo, ar, reports, 1, mval, NULL, NULL);
|
|
|
|
}
|