OSCAR-code/Graphs/gFlagsLine.cpp

214 lines
5.9 KiB
C++
Raw Normal View History

2011-06-26 08:30:44 +00:00
/********************************************************************
gFlagsLine Implementation
Copyright (c)2011 Mark Watkins <jedimark@users.sourceforge.net>
License: GPL
*********************************************************************/
#include <cmath>
#include <QVector>
2011-06-26 08:30:44 +00:00
#include "SleepLib/profiles.h"
#include "gFlagsLine.h"
gFlagsGroup::gFlagsGroup()
{
}
gFlagsGroup::~gFlagsGroup()
{
}
2011-07-27 09:21:53 +00:00
qint64 gFlagsGroup::Minx()
{
if (m_day) {
return m_day->first();
}
return 0;
}
qint64 gFlagsGroup::Maxx()
{
if (m_day) {
return m_day->last();
}
return 0;
}
void gFlagsGroup::Plot(gGraphWindow &w, float scrx, float scry)
{
if (!m_visible) return;
2011-07-27 09:21:53 +00:00
//if (!m_day) return;
int start_px=w.GetLeftMargin();
int start_py=w.GetBottomMargin();
int width=scrx-(w.GetLeftMargin()+w.GetRightMargin())-1;
int height=scry-(w.GetTopMargin()+w.GetBottomMargin());
QVector<gFlagsLine *> lvisible;
for (int i=0;i<layers.size();i++) {
2011-07-20 16:01:31 +00:00
gFlagsLine *f=dynamic_cast<gFlagsLine *>(layers[i]);
if (!f) continue;
if (!f->isEmpty() || f->isAlwaysVisible()) {
2011-07-27 09:21:53 +00:00
lvisible.push_back(f);
}
}
2011-07-27 09:21:53 +00:00
int vis=lvisible.size();
for (int i=0;i<lvisible.size();i++) {
2011-07-27 09:21:53 +00:00
lvisible[i]->line_num=i;
lvisible[i]->total_lines=vis;
lvisible[i]->Plot(w,scrx,scry);
}
glColor3f (0.0F, 0.0F, 0.0F);
glLineWidth (1);
glBegin (GL_LINE_LOOP);
glVertex2f (start_px-1, start_py);
glVertex2f (start_px-1, start_py+height);
glVertex2f (start_px+width,start_py+height);
glVertex2f (start_px+width, start_py);
glEnd ();
}
2011-06-26 08:30:44 +00:00
gFlagsLine::gFlagsLine(ChannelID code,QColor flag_color,QString label,bool always_visible,FlagType flt)
:gLayer(code),m_label(label),m_always_visible(always_visible),m_flt(flt),m_flag_color(flag_color)
2011-06-26 08:30:44 +00:00
{
}
gFlagsLine::~gFlagsLine()
{
}
void gFlagsLine::Plot(gGraphWindow & w,float scrx,float scry)
{
if (!m_visible) return;
2011-07-27 09:21:53 +00:00
if (!m_day) return;
2011-06-26 08:30:44 +00:00
double minx;
double maxx;
if (w.BlockZoom()) {
minx=w.rmin_x;
maxx=w.rmax_x;
} else {
minx=w.min_x;
maxx=w.max_x;
}
double xx=maxx-minx;
if (xx<=0) return;
int start_px=w.GetLeftMargin();
int start_py=w.GetBottomMargin();
2011-06-28 15:25:20 +00:00
int width=scrx-(w.GetLeftMargin()+w.GetRightMargin())-1;
2011-06-26 08:30:44 +00:00
int height=scry-(w.GetTopMargin()+w.GetBottomMargin());
double xmult=width/xx;
static QColor col1=QColor(0xd0,0xff,0xd0,0xff);
static QColor col2=QColor(0xff,0xff,0xff,0xff);
float line_h=float(height-2)/float(total_lines);
line_h=line_h;
float line_top=(start_py+height-line_h)-line_num*line_h;
// Alternating box color
QColor * barcol=&col2;
2011-06-26 08:30:44 +00:00
if (line_num & 1)
barcol=&col1;
int qo=0;
//if (evil_intel_graphics_card) qo=1;
2011-06-26 08:30:44 +00:00
// Filled rectangle
w.qglColor(*barcol);
2011-06-26 08:30:44 +00:00
glBegin(GL_QUADS);
glVertex2f(start_px+qo, line_top);
glVertex2f(start_px+qo, line_top+line_h);
2011-06-27 07:45:59 +00:00
glVertex2f(start_px+width-1, line_top+line_h);
glVertex2f(start_px+width-1, line_top);
2011-06-26 08:30:44 +00:00
glEnd();
qint32 vertcnt=0;
GLshort * vertarray=vertex_array[0];
qint32 quadcnt=0;
GLshort * quadarray=vertex_array[1];
if (!vertarray || !quadarray) {
qWarning() << "vertarray/quadarray==NULL";
return;
}
2011-06-26 08:30:44 +00:00
// Draw text label
float x,y;
GetTextExtent(m_label,x,y);
2011-08-06 12:46:27 +00:00
w.qglColor(Qt::black);
2011-08-06 23:22:06 +00:00
w.renderText(start_px-x-10,(scry-line_top)-(line_h/2)+(y/2),m_label);
2011-08-06 12:46:27 +00:00
//DrawText(w,m_label,start_px-x-10,(scry-line_top)-(line_h/2)+(y/2));
2011-06-26 08:30:44 +00:00
float x1,x2;
float top=floor(line_top)+2;
float bottom=top+floor(line_h)-3;
bool verts_exceeded=false;
2011-07-27 09:21:53 +00:00
qint64 X,Y;
for (QVector<Session *>::iterator s=m_day->begin();s!=m_day->end(); s++) {
2011-07-27 09:21:53 +00:00
if ((*s)->eventlist.find(m_code)==(*s)->eventlist.end()) continue;
EventList & el=*((*s)->eventlist[m_code][0]);
2011-06-26 08:30:44 +00:00
2011-07-27 09:21:53 +00:00
for (int i=0;i<el.count();i++) {
X=el.time(i);
Y=X-(el.data(i)*1000);
if (Y < minx) continue;
if (X > maxx) break;
x1=(X - minx) * xmult + w.GetLeftMargin();
if (m_flt==FT_Bar) {
2011-06-26 08:30:44 +00:00
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=top;
vertarray[vertcnt++]=x1;
vertarray[vertcnt++]=bottom;
if (vertcnt>maxverts) { verts_exceeded=true; break; }
} else if (m_flt==FT_Span) {
2011-07-27 09:21:53 +00:00
x2=(Y-minx)*xmult+w.GetLeftMargin();
2011-06-26 08:30:44 +00:00
//w1=x2-x1;
quadarray[quadcnt++]=x1;
quadarray[quadcnt++]=top;
quadarray[quadcnt++]=x1;
quadarray[quadcnt++]=bottom;
quadarray[quadcnt++]=x2;
quadarray[quadcnt++]=bottom;
quadarray[quadcnt++]=x2;
quadarray[quadcnt++]=top;
if (quadcnt>maxverts) { verts_exceeded=true; break; }
2011-06-26 08:30:44 +00:00
}
}
}
if (verts_exceeded) {
qWarning() << "maxverts exceeded in gFlagsLine::plot()";
}
2011-06-26 08:30:44 +00:00
glScissor(w.GetLeftMargin(),w.GetBottomMargin(),width,height);
glEnable(GL_SCISSOR_TEST);
bool antialias=pref["UseAntiAliasing"].toBool();
if (antialias) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glLineWidth (1.5);
} else glLineWidth (1);
2011-06-26 08:30:44 +00:00
glEnableClientState(GL_VERTEX_ARRAY);
w.qglColor(m_flag_color);
2011-06-26 08:30:44 +00:00
if (quadcnt>0) {
glVertexPointer(2, GL_SHORT, 0, quadarray);
glDrawArrays(GL_QUADS, 0, quadcnt>>1);
}
if (vertcnt>0) {
glVertexPointer(2, GL_SHORT, 0, vertarray);
glDrawArrays(GL_LINES, 0, vertcnt>>1);
}
glDisableClientState(GL_VERTEX_ARRAY);
2011-06-26 08:30:44 +00:00
if (antialias) {
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
glDisable(GL_SCISSOR_TEST);
}