_colour = Qt::blue;
}
-void AnalogSignal::paint(QPainter &p, const QRect &rect, double scale,
+void AnalogSignal::paint(QPainter &p, int y, int left, int right, double scale,
double offset)
{
assert(scale > 0);
assert(_data);
+ assert(right >= left);
const deque< shared_ptr<pv::data::AnalogSnapshot> > &snapshots =
_data->get_snapshots();
const int64_t last_sample = snapshot->get_sample_count() - 1;
const double samples_per_pixel = samplerate * scale;
const double start = samplerate * (offset - start_time);
- const double end = start + samples_per_pixel * rect.width();
+ const double end = start + samples_per_pixel * (right - left);
const int64_t start_sample = min(max((int64_t)floor(start),
(int64_t)0), last_sample);
const int64_t end_sample = min(max((int64_t)ceil(end),
(int64_t)0), last_sample);
- const int y_offset = rect.center().y();
-
const float* samples = snapshot->get_samples();
assert(samples);
for (int64_t sample = start_sample;
sample != end_sample; sample++) {
const float x = (sample / samples_per_pixel -
- pixels_offset) + rect.left();
- const float y = samples[sample] + y_offset;
- *point++ = QPointF(x, y);
+ pixels_offset) + left;
+ *point++ = QPointF(x, samples[sample] + y);
}
p.drawPoints(points, point - points);
delete[] points;
}
-int AnalogSignal::get_nominal_offset(const QRect &rect) const
-{
- return rect.center().y();
-}
-
} // namespace view
} // namespace pv
/**
* Paints the signal with a QPainter
* @param p the QPainter to paint into.
- * @param rect the rectangular area to draw the trace into.
+ * @param y the y-coordinate to draw the signal at.
+ * @param left the x-coordinate of the left edge of the signal.
+ * @param right the x-coordinate of the right edge of the signal.
* @param scale the scale in seconds per pixel.
* @param offset the time to show at the left hand edge of
* the view in seconds.
**/
- void paint(QPainter &p, const QRect &rect,
- double scale, double offset);
-
-private:
-
- /**
- * When painting into the rectangle, calculate the y
- * offset of the zero point.
- **/
- int get_nominal_offset(const QRect &rect) const;
+ void paint(QPainter &p, int y, int left, int right, double scale,
+ double offset);
private:
boost::shared_ptr<pv::data::Analog> _data;
{
assert(s);
- const QRect signal_heading_rect(
- 0, s->get_v_offset() - v_offset,
- w, View::SignalHeight);
-
- if (s->pt_in_label_rect(signal_heading_rect, pt))
+ if (s->pt_in_label_rect(s->get_v_offset() - v_offset,
+ 0, w, pt))
return s;
}
{
assert(s);
- const QRect signal_heading_rect(
- 0, s->get_v_offset() - v_offset,
- w, View::SignalHeight);
-
+ const int y = s->get_v_offset() - v_offset;
const bool highlight = !dragging && s->pt_in_label_rect(
- signal_heading_rect, _mouse_point);
- s->paint_label(painter, signal_heading_rect, highlight);
+ y, 0, w, _mouse_point);
+ s->paint_label(painter, y, w, highlight);
}
painter.end();
#include <math.h>
#include "logicsignal.h"
+#include "view.h"
#include "pv/data/logic.h"
#include "pv/data/logicsnapshot.h"
_probe_index % countof(LogicSignalColours)];
}
-void LogicSignal::paint(QPainter &p, const QRect &rect, double scale,
- double offset)
+void LogicSignal::paint(QPainter &p, int y, int left, int right,
+ double scale, double offset)
{
+ using pv::view::View;
+
QLineF *line;
vector< pair<int64_t, bool> > edges;
assert(scale > 0);
assert(_data);
+ assert(right >= left);
- const float high_offset = rect.top() + 0.5f;
- const float low_offset = rect.bottom() + 0.5f;
+ const float high_offset = y - View::SignalHeight + 0.5f;
+ const float low_offset = y + 0.5f;
const deque< shared_ptr<pv::data::LogicSnapshot> > &snapshots =
_data->get_snapshots();
const int64_t last_sample = snapshot->get_sample_count() - 1;
const double samples_per_pixel = samplerate * scale;
const double start = samplerate * (offset - start_time);
- const double end = start + samples_per_pixel * rect.width();
+ const double end = start + samples_per_pixel * (right - left);
snapshot->get_subsampled_edges(edges,
min(max((int64_t)floor(start), (int64_t)0), last_sample),
edges.begin() + 1;
i != edges.end() - 1; i++) {
const float x = ((*i).first / samples_per_pixel -
- pixels_offset) + rect.left();
+ pixels_offset) + left;
*line++ = QLineF(x, high_offset, x, low_offset);
}
p.setPen(HighColour);
paint_caps(p, cap_lines, edges, true, samples_per_pixel,
- pixels_offset, rect.left(), high_offset);
+ pixels_offset, left, high_offset);
p.setPen(LowColour);
paint_caps(p, cap_lines, edges, false, samples_per_pixel,
- pixels_offset, rect.left(), low_offset);
+ pixels_offset, left, low_offset);
delete[] cap_lines;
}
p.drawLines(lines, line - lines);
}
-int LogicSignal::get_nominal_offset(const QRect &rect) const
-{
- return rect.bottom();
-}
-
} // namespace view
} // namespace pv
/**
* Paints the signal with a QPainter
* @param p the QPainter to paint into.
- * @param rect the rectangular area to draw the trace into.
+ * @param y the y-coordinate to draw the signal at.
+ * @param left the x-coordinate of the left edge of the signal.
+ * @param right the x-coordinate of the right edge of the signal.
* @param scale the scale in seconds per pixel.
* @param offset the time to show at the left hand edge of
* the view in seconds.
**/
- void paint(QPainter &p, const QRect &rect, double scale, double offset);
+ void paint(QPainter &p, int y, int left, int right, double scale,
+ double offset);
private:
bool level, double samples_per_pixel, double pixels_offset,
float x_offset, float y_offset);
- /**
- * 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<pv::data::Logic> _data;
_selected = select;
}
-void Signal::paint_label(QPainter &p, const QRect &rect, bool hover)
+void Signal::paint_label(QPainter &p, int y, int right, bool hover)
{
p.setBrush(_colour);
const QColor colour = get_colour();
- const float nominal_offset = get_nominal_offset(rect);
compute_text_size(p);
- const QRectF label_rect = get_label_rect(rect);
+ const QRectF label_rect = get_label_rect(y, right);
// Paint the label
const QPointF points[] = {
label_rect.topLeft(),
label_rect.topRight(),
- QPointF(rect.right(), nominal_offset),
+ QPointF(right, y),
label_rect.bottomRight(),
label_rect.bottomLeft()
};
const QPointF highlight_points[] = {
QPointF(label_rect.left() + 1, label_rect.top() + 1),
QPointF(label_rect.right(), label_rect.top() + 1),
- QPointF(rect.right() - 1, nominal_offset),
+ QPointF(right - 1, y),
QPointF(label_rect.right(), label_rect.bottom() - 1),
QPointF(label_rect.left() + 1, label_rect.bottom() - 1)
};
p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
}
-bool Signal::pt_in_label_rect(const QRect &rect, const QPoint &point)
+bool Signal::pt_in_label_rect(int y, int left, int right,
+ const QPoint &point)
{
- const QRectF label = get_label_rect(rect);
+ const QRectF label = get_label_rect(y, right);
return QRectF(
QPointF(label.left() - LabelHitPadding,
label.top() - LabelHitPadding),
- QPointF(rect.right(),
- label.bottom() + LabelHitPadding)
- ).contains(point);
+ QPointF(right, label.bottom() + LabelHitPadding)
+ ).contains(point);
}
void Signal::compute_text_size(QPainter &p)
_text_size = p.boundingRect(QRectF(), 0, _name).size();
}
-QRectF Signal::get_label_rect(const QRect &rect)
+QRectF Signal::get_label_rect(int y, int right)
{
using pv::view::View;
- const float nominal_offset = get_nominal_offset(rect) + 0.5;
const QSizeF label_size(
_text_size.width() + View::LabelPadding.width() * 2,
_text_size.height() + View::LabelPadding.height() * 2);
const float label_arrow_length = label_size.height() / 2;
return QRectF(
- rect.right() - label_arrow_length -
- label_size.width() - 0.5,
- nominal_offset - label_size.height() / 2,
+ right - label_arrow_length - label_size.width() - 0.5,
+ y + 0.5f - label_size.height() / 2,
label_size.width(), label_size.height());
}
/**
* Paints the signal with a QPainter
* @param p the QPainter to paint into.
- * @param rect the rectangular area to draw the trace into.
+ * @param y the y-coordinate to draw the signal at
+ * @param left the x-coordinate of the left edge of the signal
+ * @param right the x-coordinate of the right edge of the signal
* @param scale the scale in seconds per pixel.
* @param offset the time to show at the left hand edge of
* the view in seconds.
**/
- virtual void paint(QPainter &p, const QRect &rect, double scale,
- double offset) = 0;
-
+ virtual void paint(QPainter &p, int y, int left, int right,
+ 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.
+ * @param y the y-coordinate of the signal.
+ * @param right the x-coordinate of the right edge of the header
+ * area.
* @param hover true if the label is being hovered over by the mouse.
*/
- virtual void paint_label(QPainter &p, const QRect &rect,
+ virtual void paint_label(QPainter &p, int y, int right,
bool hover);
/**
* Determines if a point is in the header label rect.
- * @param rect the rectangular area to draw the label into.
+ * @param y the y-coordinate of the signal.
+ * @param left the x-coordinate of the left edge of the header
+ * area.
+ * @param right the x-coordinate of the right edge of the header
+ * area.
* @param point the point to test.
*/
- bool pt_in_label_rect(const QRect &rect, const QPoint &point);
+ bool pt_in_label_rect(int y, int left, int right,
+ const QPoint &point);
private:
/**
* Computes the outline rectangle of a label.
* @param p the QPainter to lay out text with.
- * @param rect The rectangle of the signal header.
+ * @param y the y-coordinate of the signal.
+ * @param right the x-coordinate of the right edge of the header
+ * area.
* @return Returns the rectangle of the signal label.
*/
- QRectF get_label_rect(const QRect &rect);
-
-protected:
- /**
- * When painting into the rectangle, calculate the y
- * offset of the zero point.
- **/
- virtual int get_nominal_offset(const QRect &rect) const = 0;
+ QRectF get_label_rect(int y, int right);
protected:
QString _name;
void View::reset_signal_layout()
{
- int offset = SignalMargin;
+ int offset = SignalMargin + SignalHeight;
const vector< shared_ptr<Signal> > sigs(_session.get_signals());
BOOST_FOREACH(shared_ptr<Signal> s, sigs) {
s->set_v_offset(offset);
BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
{
assert(s);
-
- const QRect signal_rect(0, s->get_v_offset() - v_offset,
- width(), View::SignalHeight);
-
- s->paint(p, signal_rect, _view.scale(), _view.offset());
+ s->paint(p, s->get_v_offset() - v_offset, 0, width(),
+ _view.scale(), _view.offset());
}
draw_cursors_foreground(p);