#include <math.h>
+#include "extdef.h"
+
#include "logicdata.h"
#include "logicdatasnapshot.h"
#include "logicsignal.h"
const float LogicSignal::HighColour[3] = {0.00f, 0.75f, 0.00f};
const float LogicSignal::LowColour[3] = {0.75f, 0.00f, 0.00f};
+const QColor LogicSignal::LogicSignalColours[10] = {
+ QColor(0x16, 0x19, 0x1A), // Black
+ QColor(0x8F, 0x52, 0x02), // Brown
+ QColor(0xCC, 0x00, 0x00), // Red
+ QColor(0xF5, 0x79, 0x00), // Orange
+ QColor(0xED, 0xD4, 0x00), // Yellow
+ QColor(0x73, 0xD2, 0x16), // Green
+ QColor(0x34, 0x65, 0xA4), // Blue
+ QColor(0x75, 0x50, 0x7B), // Violet
+ QColor(0x88, 0x8A, 0x85), // Grey
+ QColor(0xEE, 0xEE, 0xEC), // White
+};
+
LogicSignal::LogicSignal(QString name, shared_ptr<LogicData> data,
int probe_index) :
Signal(name),
glDeleteBuffers(1, &vbo_id);
}
+
+QColor LogicSignal::get_colour() const
+{
+ return LogicSignalColours[_probe_index % countof(LogicSignalColours)];
+}
+
+int LogicSignal::get_nominal_offset(const QRect &rect) const
+{
+ return rect.bottom() - Margin;
+}
static const float HighColour[3];
static const float LowColour[3];
+ static const QColor LogicSignalColours[10];
+
public:
LogicSignal(QString name,
boost::shared_ptr<LogicData> data,
static void paint_lines(Point2F *points, int count);
+ /**
+ * Get the colour of the logic signal
+ */
+ QColor get_colour() const;
+
+ /**
+ * When painting into the rectangle, calculate the y
+ * offset of the zero point.
+ **/
+ int get_nominal_offset(const QRect &rect) const;
+
private:
int _probe_index;
boost::shared_ptr<LogicData> _data;
#include "signal.h"
-#include <memory.h>
+#include "extdef.h"
+
+const QSizeF Signal::LabelPadding(4, 0);
Signal::Signal(QString name) :
_name(name)
{
return _name;
}
+
+void Signal::paint_label(QPainter &p, const QRect &rect)
+{
+ p.setBrush(get_colour());
+
+ const QString text(_name);
+ const QColor colour = get_colour();
+
+ const QSizeF text_size = p.boundingRect(
+ QRectF(0, 0, rect.width(), 0), 0, text).size();
+
+ const float nominal_offset = get_nominal_offset(rect);
+ const QSizeF label_size(
+ text_size.width() + LabelPadding.width() * 2,
+ text_size.height() + LabelPadding.height() * 2);
+ const float label_arrow_length = label_size.height() / 2;
+ const QRectF label_rect(
+ rect.right() - label_arrow_length - label_size.width(),
+ nominal_offset - label_size.height() / 2,
+ label_size.width(), label_size.height());
+
+ // Paint the label
+ const QPointF points[] = {
+ label_rect.topLeft(),
+ label_rect.topRight(),
+ QPointF(rect.right(), nominal_offset),
+ label_rect.bottomRight(),
+ label_rect.bottomLeft()
+ };
+
+ p.setPen(Qt::black);
+ p.setBrush(colour);
+ p.drawPolygon(points, countof(points));
+
+ // Paint the text
+ p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white);
+ p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, text);
+}
#include <boost/shared_ptr.hpp>
#include <QGLWidget>
+#include <QPainter>
#include <QRect>
#include <QString>
class Signal
{
+private:
+ static const QSizeF LabelPadding;
+
protected:
Signal(QString name);
virtual void paint(QGLWidget &widget, const QRect &rect,
double scale, double offset) = 0;
+ /**
+ * Paints the signal label into a QGLWidget.
+ * @param p the QPainter to paint into.
+ * @param rect the rectangular area to draw the label into.
+ */
+ virtual void paint_label(QPainter &p, const QRect &rect);
+
+protected:
+
+ /**
+ * Get the colour of the logic signal
+ */
+ virtual QColor get_colour() const = 0;
+
+ /**
+ * When painting into the rectangle, calculate the y
+ * offset of the zero point.
+ **/
+ virtual int get_nominal_offset(const QRect &rect) const = 0;
+
protected:
QString _name;
};
using namespace std;
const int SigView::SignalHeight = 50;
+const int SigView::LabelMarginWidth = 70;
SigView::SigView(SigSession &session, QWidget *parent) :
QGLWidget(parent),
this, SLOT(dataUpdated()));
setMouseTracking(true);
+ setAutoFillBackground(false);
}
void SigView::initializeGL()
{
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_COLOR_MATERIAL);
- glEnable(GL_BLEND);
- glEnable(GL_POLYGON_SMOOTH);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glClearColor(1.0, 1.0, 1.0, 0);
}
void SigView::resizeGL(int width, int height)
{
- glViewport(0, 0, (GLint)width, (GLint)height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, width, height, 0, -1, 1);
- glMatrixMode(GL_MODELVIEW);
+ setupViewport(width, height);
}
-void SigView::paintGL()
+void SigView::paintEvent(QPaintEvent *event)
{
- glClear(GL_COLOR_BUFFER_BIT);
+ int offset;
- QRect rect(0, 0, width(), SignalHeight);
const vector< shared_ptr<Signal> > &sigs =
_session.get_signals();
+
+ // Prepare for OpenGL rendering
+ makeCurrent();
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+
+ setupViewport(width(), height());
+
+ qglClearColor(Qt::white);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ // Plot the signal
+ offset = 0;
+ BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
+ {
+ assert(s);
+
+ const QRect signal_rect(LabelMarginWidth, offset,
+ width() - LabelMarginWidth, SignalHeight);
+
+ s->paint(*this, signal_rect, _scale, _offset);
+
+ offset += SignalHeight;
+ }
+
+ // Prepare for QPainter rendering
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+
+ QPainter painter(this);
+ painter.setRenderHint(QPainter::Antialiasing);
+
+ // Paint the label
+ offset = 0;
BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
{
assert(s);
- s->paint(*this, rect, _scale, _offset);
- rect.translate(0, SignalHeight);
+
+ const QRect label_rect(0, offset,
+ LabelMarginWidth, SignalHeight);
+ s->paint_label(painter, label_rect);
+
+ offset += SignalHeight;
}
+
+ painter.end();
}
void SigView::dataUpdated()
_offset = cursor_offset - _scale * (double)event->x();
- updateGL();
+ update();
}
+void SigView::setupViewport(int width, int height)
+{
+ glViewport(0, 0, (GLint)width, (GLint)height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, width, height, 0, -1, 1);
+ glMatrixMode(GL_MODELVIEW);
+}
#include <QtOpenGL/QGLWidget>
#include <QTimer>
+class QPaintEvent;
class SigSession;
class SigView : public QGLWidget
private:
static const int SignalHeight;
+ static const int LabelMarginWidth;
public:
explicit SigView(SigSession &session, QWidget *parent = 0);
void resizeGL(int width, int height);
- void paintGL();
+ void paintEvent(QPaintEvent *event);
private:
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
+private:
+ void setupViewport(int width, int height);
+
private slots:
void dataUpdated();