Blender V2.61 - r43446

info_draw.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2010 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * Contributor(s): Blender Foundation
00022  *
00023  * ***** END GPL LICENSE BLOCK *****
00024  */
00025 
00032 #include <math.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <sys/stat.h>
00036 #include <limits.h>
00037 
00038 #include "BLF_api.h"
00039 
00040 #include "BLI_blenlib.h"
00041 #include "BLI_utildefines.h"
00042 
00043 #include "DNA_space_types.h"
00044 #include "DNA_screen_types.h"
00045 
00046 // #include "BKE_suggestions.h"
00047 #include "BKE_report.h"
00048 
00049 
00050 #include "MEM_guardedalloc.h"
00051 
00052 #include "BIF_gl.h"
00053 #include "BIF_glutil.h"
00054 
00055 #include "ED_datafiles.h"
00056 #include "ED_types.h"
00057 
00058 #include "UI_resources.h"
00059 
00060 #include "info_intern.h"
00061 #include "../space_info/textview.h"
00062 
00063 /* complicates things a bit, so leaving in old simple code */
00064 #define USE_INFO_NEWLINE
00065 
00066 static void info_report_color(unsigned char *fg, unsigned char *bg, Report *report, int bool)
00067 {
00068     if(report->flag & SELECT) {
00069         fg[0]=255; fg[1]=255; fg[2]=255;
00070         if(bool) {
00071             bg[0]=96; bg[1]=128; bg[2]=255;
00072         }
00073         else {
00074             bg[0]=90; bg[1]=122; bg[2]=249;
00075         }
00076     }
00077     else {
00078         fg[0]=0; fg[1]=0; fg[2]=0;
00079         
00080         if (report->type & RPT_ERROR_ALL) {
00081             if (bool) { bg[0]=220; bg[1]=0;   bg[2]=0;   }
00082             else      { bg[0]=214; bg[1]=0;   bg[2]=0;   }
00083         }
00084         else if (report->type & RPT_WARNING_ALL) {
00085             if (bool) { bg[0]=220; bg[1]=128; bg[2]=96;  }
00086             else      { bg[0]=214; bg[1]=122; bg[2]=90;  }
00087         }
00088 #if 0 // XXX: this looks like the selected color, so don't use this
00089         else if (report->type & RPT_OPERATOR_ALL) {
00090             if (bool) { bg[0]=96;  bg[1]=128; bg[2]=255; }
00091             else      { bg[0]=90;  bg[1]=122; bg[2]=249; }
00092         }
00093 #endif
00094         else if (report->type & RPT_INFO_ALL) {
00095             if (bool) { bg[0]=0;   bg[1]=170; bg[2]=0;   }
00096             else      { bg[0]=0;   bg[1]=164; bg[2]=0;   }
00097         }
00098         else if (report->type & RPT_DEBUG_ALL) {
00099             if (bool) { bg[0]=196; bg[1]=196; bg[2]=196; }
00100             else      { bg[0]=190; bg[1]=190; bg[2]=190; }
00101         }
00102         else {
00103             if (bool) { bg[0]=120; bg[1]=120; bg[2]=120; }
00104             else      { bg[0]=114; bg[1]=114; bg[2]=114; }
00105         }
00106     }
00107 }
00108 
00109 /* reports! */
00110 #ifdef USE_INFO_NEWLINE
00111 static void report_textview_init__internal(TextViewContext *tvc)
00112 {
00113     Report *report= (Report *)tvc->iter;
00114     const char *str= report->message;
00115     const char *next_str= strchr(str + tvc->iter_char, '\n');
00116 
00117     if(next_str) {
00118         tvc->iter_char_next= (int)(next_str - str);
00119     }
00120     else {
00121         tvc->iter_char_next= report->len;
00122     }
00123 }
00124 
00125 static int report_textview_skip__internal(TextViewContext *tvc)
00126 {
00127     SpaceInfo *sinfo= (SpaceInfo *)tvc->arg1;
00128     const int report_mask= info_report_mask(sinfo);
00129     while (tvc->iter && (((Report *)tvc->iter)->type & report_mask)==0) {
00130         tvc->iter= (void *)((Link *)tvc->iter)->prev;
00131     }
00132     return (tvc->iter != NULL);
00133 }
00134 
00135 #endif // USE_INFO_NEWLINE
00136 
00137 static int report_textview_begin(TextViewContext *tvc)
00138 {
00139     // SpaceConsole *sc= (SpaceConsole *)tvc->arg1;
00140     ReportList *reports= (ReportList *)tvc->arg2;
00141 
00142     tvc->lheight= 14; //sc->lheight;
00143     tvc->sel_start= 0;
00144     tvc->sel_end= 0;
00145 
00146     /* iterator */
00147     tvc->iter= reports->list.last;
00148 
00149     glClearColor(120.0/255.0, 120.0/255.0, 120.0/255.0, 1.0);
00150     glClear(GL_COLOR_BUFFER_BIT);
00151 
00152 #ifdef USE_INFO_NEWLINE
00153     tvc->iter_tmp= 0;
00154     if(tvc->iter && report_textview_skip__internal(tvc)) {
00155         /* init the newline iterator */
00156         tvc->iter_char= 0;
00157         report_textview_init__internal(tvc);
00158 
00159         return TRUE;
00160     }
00161     else {
00162         return FALSE;
00163     }
00164 #else
00165     return (tvc->iter != NULL);
00166 #endif
00167 }
00168 
00169 static void report_textview_end(TextViewContext *UNUSED(tvc))
00170 {
00171     /* pass */
00172 }
00173 
00174 #ifdef USE_INFO_NEWLINE
00175 static int report_textview_step(TextViewContext *tvc)
00176 {
00177     /* simple case, but no newline support */
00178     Report *report= (Report *)tvc->iter;
00179 
00180     if(report->len <= tvc->iter_char_next) {
00181         tvc->iter= (void *)((Link *)tvc->iter)->prev;
00182         if(tvc->iter && report_textview_skip__internal(tvc)) {
00183             tvc->iter_tmp++;
00184 
00185             tvc->iter_char= 0; /* reset start */
00186             report_textview_init__internal(tvc);
00187 
00188             return TRUE;
00189         }
00190         else {
00191             return FALSE;
00192         }
00193     }
00194     else {
00195         /* step to the next newline */
00196         tvc->iter_char= tvc->iter_char_next + 1;
00197         report_textview_init__internal(tvc);
00198 
00199         return TRUE;
00200     }
00201 }
00202 
00203 static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
00204 {
00205     Report *report= (Report *)tvc->iter;
00206     *line= report->message + tvc->iter_char;
00207     *len= tvc->iter_char_next - tvc->iter_char;
00208     return 1;
00209 }
00210 
00211 static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3])
00212 {
00213     Report *report= (Report *)tvc->iter;
00214     info_report_color(fg, bg, report, tvc->iter_tmp % 2);
00215     return TVC_LINE_FG | TVC_LINE_BG;
00216 }
00217 
00218 
00219 #else // USE_INFO_NEWLINE
00220 
00221 static int report_textview_step(TextViewContext *tvc)
00222 {
00223     SpaceInfo *sinfo= (SpaceInfo *)tvc->arg1;
00224     const int report_mask= info_report_mask(sinfo);
00225     do {
00226         tvc->iter= (void *)((Link *)tvc->iter)->prev;
00227     } while (tvc->iter && (((Report *)tvc->iter)->type & report_mask)==0);
00228 
00229     return (tvc->iter != NULL);
00230 }
00231 
00232 static int report_textview_line_get(struct TextViewContext *tvc, const char **line, int *len)
00233 {
00234     Report *report= (Report *)tvc->iter;
00235     *line= report->message;
00236     *len= report->len;
00237 
00238     return 1;
00239 }
00240 
00241 static int report_textview_line_color(struct TextViewContext *tvc, unsigned char fg[3], unsigned char bg[3])
00242 {
00243     Report *report= (Report *)tvc->iter;
00244     info_report_color(fg, bg, report, tvc->iter_tmp % 2);
00245     return TVC_LINE_FG | TVC_LINE_BG;
00246 }
00247 
00248 #endif // USE_INFO_NEWLINE
00249 
00250 #undef USE_INFO_NEWLINE
00251 
00252 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)
00253 {
00254     int ret= 0;
00255     
00256     View2D *v2d= &ar->v2d;
00257 
00258     TextViewContext tvc= {0};
00259     tvc.begin= report_textview_begin;
00260     tvc.end= report_textview_end;
00261 
00262     tvc.step= report_textview_step;
00263     tvc.line_get= report_textview_line_get;
00264     tvc.line_color= report_textview_line_color;
00265 
00266     tvc.arg1= sinfo;
00267     tvc.arg2= reports;
00268 
00269     /* view */
00270     tvc.sel_start= 0;
00271     tvc.sel_end= 0;
00272     tvc.lheight= 14; //sc->lheight;
00273     tvc.ymin= v2d->cur.ymin;
00274     tvc.ymax= v2d->cur.ymax;
00275     tvc.winx= ar->winx;
00276 
00277     ret= textview_draw(&tvc, draw, mval, mouse_pick, pos_pick);
00278     
00279     return ret;
00280 }
00281 
00282 void *info_text_pick(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports, int mouse_y)
00283 {
00284     void *mouse_pick= NULL;
00285     int mval[2];
00286 
00287     mval[0]= 0;
00288     mval[1]= mouse_y;
00289 
00290     info_textview_main__internal(sinfo, ar, reports, 0, mval, &mouse_pick, NULL);
00291     return (void *)mouse_pick;
00292 }
00293 
00294 
00295 int info_textview_height(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports)
00296 {
00297     int mval[2] = {INT_MAX, INT_MAX};
00298     return info_textview_main__internal(sinfo, ar, reports, 0,  mval, NULL, NULL);
00299 }
00300 
00301 void info_textview_main(struct SpaceInfo *sinfo, struct ARegion *ar, ReportList *reports)
00302 {
00303     int mval[2] = {INT_MAX, INT_MAX};
00304     info_textview_main__internal(sinfo, ar, reports, 1,  mval, NULL, NULL);
00305 }