Updated ui_widget.cpp

This commit is contained in:
Furrtek 2017-10-28 19:27:18 +02:00
parent 90b76f00d9
commit 046d1c7c15
2 changed files with 37 additions and 13 deletions

View File

@ -1465,7 +1465,7 @@ int32_t SymField::clip_value(const uint32_t index, const uint32_t value) {
Waveform::Waveform( Waveform::Waveform(
Rect parent_rect, Rect parent_rect,
int8_t * data, int16_t * data,
uint32_t length, uint32_t length,
uint32_t offset, uint32_t offset,
bool digital, bool digital,
@ -1480,6 +1480,16 @@ Waveform::Waveform(
//set_focusable(false); //set_focusable(false);
} }
void Waveform::set_cursor(const uint32_t i, const int16_t position) {
if (i < 2) {
if (position != cursors[i]) {
cursors[i] = position;
set_dirty();
}
show_cursors = true;
}
}
void Waveform::set_offset(const uint32_t new_offset) { void Waveform::set_offset(const uint32_t new_offset) {
if (new_offset != offset_) { if (new_offset != offset_) {
offset_ = new_offset; offset_ = new_offset;
@ -1495,28 +1505,26 @@ void Waveform::set_length(const uint32_t new_length) {
} }
void Waveform::paint(Painter& painter) { void Waveform::paint(Painter& painter) {
uint32_t n, point_count; size_t n;
Coord y, y_offset = screen_rect().location().y(); Coord y, y_offset = screen_rect().location().y();
Coord prev_x = screen_rect().location().x(), prev_y; Coord prev_x = screen_rect().location().x(), prev_y;
float x, x_inc; float x, x_inc;
Dim h = screen_rect().size().height(); Dim h = screen_rect().size().height();
int8_t * data_start = data_ + offset_; const float y_scale = (float)(h - 1) / 65536.0;
int16_t * data_start = data_ + offset_;
// Clear // Clear
painter.fill_rectangle(screen_rect(), Color::black()); painter.fill_rectangle(screen_rect(), Color::black());
if (!length_) return;
x_inc = (float)screen_rect().size().width() / length_; x_inc = (float)screen_rect().size().width() / length_;
point_count = length_;
const float y_scale = (float)(h - 1) / 256; // TODO: Make variable
if (!point_count) return;
if (digital_) { if (digital_) {
// Digital waveform: each value is an horizontal line // Digital waveform: each value is an horizontal line
x = 0; x = 0;
h--; h--;
for (n = 0; n < point_count; n++) { for (n = 0; n < length_; n++) {
y = *(data_start++) ? h : 0; y = *(data_start++) ? h : 0;
if (n) { if (n) {
@ -1532,9 +1540,9 @@ void Waveform::paint(Painter& painter) {
} else { } else {
// Analog waveform: each value is a point's Y coordinate // Analog waveform: each value is a point's Y coordinate
x = prev_x + x_inc; x = prev_x + x_inc;
h = h / 2; h /= 2;
prev_y = y_offset + h - (*(data_start++) * y_scale); prev_y = y_offset + h - (*(data_start++) * y_scale);
for (n = 1; n < point_count; n++) { for (n = 1; n < length_; n++) {
y = y_offset + h - (*(data_start++) * y_scale); y = y_offset + h - (*(data_start++) * y_scale);
display.draw_line( {prev_x, prev_y}, {(Coord)x, y}, color_); display.draw_line( {prev_x, prev_y}, {(Coord)x, y}, color_);
@ -1543,6 +1551,17 @@ void Waveform::paint(Painter& painter) {
x += x_inc; x += x_inc;
} }
} }
// Cursors
if (show_cursors) {
for (n = 0; n < 2; n++) {
painter.draw_vline(
Point(std::min(screen_rect().size().width(), (int)cursors[n]), y_offset),
screen_rect().size().height(),
cursor_colors[n]
);
}
}
} }

View File

@ -598,7 +598,7 @@ private:
class Waveform : public Widget { class Waveform : public Widget {
public: public:
Waveform(Rect parent_rect, int8_t * data, uint32_t length, uint32_t offset, bool digital, Color color); Waveform(Rect parent_rect, int16_t * data, uint32_t length, uint32_t offset, bool digital, Color color);
Waveform(const Waveform&) = delete; Waveform(const Waveform&) = delete;
Waveform(Waveform&&) = delete; Waveform(Waveform&&) = delete;
@ -607,15 +607,20 @@ public:
void set_offset(const uint32_t new_offset); void set_offset(const uint32_t new_offset);
void set_length(const uint32_t new_length); void set_length(const uint32_t new_length);
void set_cursor(const uint32_t i, const int16_t position);
void paint(Painter& painter) override; void paint(Painter& painter) override;
private: private:
int8_t * data_; const Color cursor_colors[2] = { Color::cyan(), Color::magenta() };
int16_t * data_;
uint32_t length_; uint32_t length_;
uint32_t offset_; uint32_t offset_;
bool digital_ { false }; bool digital_ { false };
Color color_; Color color_;
int16_t cursors[2] { };
bool show_cursors { false };
}; };
class VuMeter : public Widget { class VuMeter : public Widget {