]> sigrok.org Git - pulseview.git/blobdiff - logicsignal.cpp
Add initial scrolling support with a QAbstractScrollArea
[pulseview.git] / logicsignal.cpp
index 5377287362065aed52da22a35b0a867cd9bd9542..7580138fe24e87af7c164c595392968a36a08133 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <math.h>
 
+#include "extdef.h"
+
 #include "logicdata.h"
 #include "logicdatasnapshot.h"
 #include "logicsignal.h"
 using namespace boost;
 using namespace std;
 
-const float Log2 = logf(2.0f);
+const float LogicSignal::Margin = 10.0f;
+
+const float LogicSignal::EdgeColour[3] =       {0.50f, 0.50f, 0.50f};
+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) :
@@ -52,7 +71,10 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
        assert(scale > 0);
        assert(_data);
 
-       const queue< shared_ptr<LogicDataSnapshot> > &snapshots =
+       const float high_offset = rect.top() + Margin;
+       const float low_offset = rect.bottom() - Margin;
+
+       const deque< shared_ptr<LogicDataSnapshot> > &snapshots =
                _data->get_snapshots();
        if(snapshots.empty())
                return;
@@ -62,17 +84,15 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
        const double pixels_offset = offset / scale;
        const double samplerate = _data->get_samplerate();
        const double start_time = _data->get_start_time();
-       const int64_t last_sample = (int64_t)snapshot->get_sample_count() - 1;
+       const int64_t last_sample = snapshot->get_sample_count() - 1;
        const double samples_per_pixel = samplerate * scale;
-       const int64_t start = min(max((int64_t)(samplerate * (offset - start_time)),
-               (int64_t)0), last_sample);
-       const int64_t end = min((int64_t)(start + samples_per_pixel * rect.width()),
-               last_sample);
-       const int64_t quantization_length = 1LL << (int64_t)floorf(
-               max(logf(samples_per_pixel / Log2), 0.0f));
+       const double start = samplerate * (offset - start_time);
+       const double end = start + samples_per_pixel * rect.width();
 
-       snapshot->get_subsampled_edges(edges, start, end,
-               quantization_length, _probe_index);
+       snapshot->get_subsampled_edges(edges,
+               min(max((int64_t)floor(start), (int64_t)0), last_sample),
+               min(max((int64_t)ceil(end), (int64_t)0), last_sample),
+               samples_per_pixel, _probe_index);
 
        // Paint the edges
        const unsigned int edge_point_count = (edges.size() - 2) * 2;
@@ -85,40 +105,53 @@ void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
                const int x = (int)((*i).first / samples_per_pixel - pixels_offset) +
                        rect.left();
 
-               vertex->x = x, vertex->y = 10 + rect.top() - 1;
+               vertex->x = x, vertex->y = high_offset;
                vertex++;
-               vertex->x = x, vertex->y = 40 + rect.top();
+               vertex->x = x, vertex->y = low_offset;
                vertex++;
        }
 
-       glColor3f(0,0,1);
+       glColor3fv(EdgeColour);
        paint_lines(edge_points, edge_point_count);
        delete[] edge_points;
 
        // Paint the caps
-       const unsigned int cap_point_count = (edges.size() - 1) * 2;
-       Point2F *const cap_points = new Point2F[cap_point_count];
-       vertex = cap_points;
+       const unsigned int max_cap_point_count = (edges.size() - 1) * 2;
+       Point2F *const cap_points = new Point2F[max_cap_point_count];
 
-       for(vector<LogicDataSnapshot::EdgePair>::const_iterator i = edges.begin();
-           i != (edges.end() - 1); i++)
-       {
-               const int y = ((*i).second ? 10 : 40) + rect.top();
+       glColor3fv(HighColour);
+       paint_caps(cap_points, edges, true, samples_per_pixel,
+               pixels_offset, rect.left(), high_offset);
+       glColor3fv(LowColour);
+       paint_caps(cap_points, edges, false, samples_per_pixel,
+               pixels_offset, rect.left(), low_offset);
 
-               vertex->x = (int)((*i).first / samples_per_pixel - pixels_offset) +
-                       rect.left() - 1;
-               vertex->y = y;
-               vertex++;
+       delete[] cap_points;
+}
 
-               vertex->x = (int)((*(i+1)).first / samples_per_pixel - pixels_offset) +
-                       rect.left();
-               vertex->y = y;
-               vertex++;
-       }
+int LogicSignal::paint_caps(Point2F *const cap_points,
+       vector< pair<int64_t, bool> > &edges, bool level,
+       double samples_per_pixel, double pixels_offset, int x_offset,
+       int y_offset)
+{
+       Point2F *vertex = cap_points;
 
-       glColor3f(0,0,1);
-       paint_lines(cap_points, cap_point_count);
-       delete[] cap_points;
+       for(vector<LogicDataSnapshot::EdgePair>::const_iterator i = edges.begin();
+           i != (edges.end() - 1); i++)
+               if((*i).second == level)
+               {
+                       vertex->x = (int)((*i).first / samples_per_pixel -
+                               pixels_offset) + x_offset - 1;
+                       vertex->y = y_offset;
+                       vertex++;
+
+                       vertex->x = (int)((*(i+1)).first / samples_per_pixel -
+                               pixels_offset) + x_offset;
+                       vertex->y = y_offset;
+                       vertex++;
+               }
+
+       paint_lines(cap_points, vertex - cap_points);
 }
 
 void LogicSignal::paint_lines(Point2F *points, int count)
@@ -144,3 +177,13 @@ void LogicSignal::paint_lines(Point2F *points, int count)
 
        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;
+}