}
void LogicSignal::paint(QGLWidget &widget, const QRect &rect,
- uint64_t scale, int64_t offset)
+ double scale, double offset)
{
Point2F *vertex;
vector< pair<int64_t, bool> > edges;
+ assert(scale > 0);
assert(_data);
const queue< shared_ptr<LogicDataSnapshot> > &snapshots =
const shared_ptr<LogicDataSnapshot> &snapshot = snapshots.front();
- const uint64_t samplerate = _data->get_samplerate();
- const int64_t start_time = _data->get_start_time();
- const float samples_per_pixel = samplerate * scale / 1e15f;
- const int64_t start = samplerate * (offset - start_time) /
- 1000000000000000ULL;
- const int64_t end = start + samples_per_pixel * rect.width();
+ 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 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));
for(vector<LogicDataSnapshot::EdgePair>::const_iterator i = edges.begin() + 1;
i != edges.end() - 1; i++)
{
- const int x = (int)((*i).first / samples_per_pixel) +
+ const int x = (int)((*i).first / samples_per_pixel - pixels_offset) +
rect.left();
vertex->x = x, vertex->y = 10 + rect.top() - 1;
{
const int y = ((*i).second ? 10 : 40) + rect.top();
- vertex->x = (int)((*i).first / samples_per_pixel) +
+ vertex->x = (int)((*i).first / samples_per_pixel - pixels_offset) +
rect.left() - 1;
vertex->y = y;
vertex++;
- vertex->x = (int)((*(i+1)).first / samples_per_pixel) +
+ vertex->x = (int)((*(i+1)).first / samples_per_pixel - pixels_offset) +
rect.left();
vertex->y = y;
vertex++;
* Paints the signal into a QGLWidget.
* @param widget the QGLWidget to paint into.
* @param rect the rectangular area to draw the trace into.
- * @param scale the scale in femtoseconds per pixel.
+ * @param scale the scale in seconds per pixel.
* @param offset the time to show at the left hand edge of
- * the view in femtoseconds.
+ * the view in seconds.
**/
- void paint(QGLWidget &widget, const QRect &rect, uint64_t scale,
- int64_t offset);
+ void paint(QGLWidget &widget, const QRect &rect, double scale,
+ double offset);
private:
static void paint_lines(Point2F *points, int count);
* Paints the signal into a QGLWidget.
* @param widget the QGLWidget to paint into.
* @param rect the rectangular area to draw the trace into.
- * @param scale the scale in femtoseconds per pixel.
+ * @param scale the scale in seconds per pixel.
* @param offset the time to show at the left hand edge of
- * the view in femtoseconds.
+ * the view in seconds.
**/
virtual void paint(QGLWidget &widget, const QRect &rect,
- uint64_t scale, int64_t offset) = 0;
+ double scale, double offset) = 0;
protected:
QString _name;
using namespace std;
-SignalData::SignalData(uint64_t samplerate) :
+SignalData::SignalData(double samplerate) :
_samplerate(samplerate),
_start_time(0)
{
}
-uint64_t SignalData::get_samplerate() const
+double SignalData::get_samplerate() const
{
return _samplerate;
}
-int64_t SignalData::get_start_time() const
+double SignalData::get_start_time() const
{
return _start_time;
}
\ No newline at end of file
class SignalData
{
public:
- SignalData(uint64_t samplerate);
+ SignalData(double samplerate);
public:
- uint64_t get_samplerate() const;
- int64_t get_start_time() const;
+ double get_samplerate() const;
+ double get_start_time() const;
protected:
- const uint64_t _samplerate;
- const int64_t _start_time;
+ const double _samplerate;
+ const double _start_time;
};
SigView::SigView(SigSession &session, QWidget *parent) :
QGLWidget(parent),
_session(session),
- _scale(1000000000ULL),
+ _scale(1e-6),
_offset(0)
{
connect(&_session, SIGNAL(dataUpdated()),
{
assert(event);
+ const double cursor_offset = _offset + _scale * (double)event->x();
+
switch(event->button())
{
case Qt::LeftButton:
- _scale = (_scale * 2) / 3;
+ _scale *= 2.0 / 3.0;
break;
case Qt::RightButton:
- _scale = (_scale * 3) / 2;
+ _scale *= 3.0 / 2.0;
break;
}
+ _offset = cursor_offset - _scale * (double)event->x();
+
updateGL();
}
private:
SigSession &_session;
- uint64_t _scale;
- int64_t _offset;
+ double _scale;
+ double _offset;
};
#endif // SIGVIEW_H