void Channel::paint(Painter& painter) {
	const auto r = screen_rect();

	const int32_t db_min = -r.width();
	const int32_t x_0 = 0;
	const int32_t x_max = std::max(x_0, max_db_ - db_min);
	const int32_t x_lim = r.width();

	const Rect r0 {
		static_cast<ui::Coord>(r.left() + x_0), r.top(),
		static_cast<ui::Dim>(x_max - x_0), r.height()
	};
	painter.fill_rectangle(
		r0,
		Color::blue()
	);

	const Rect r1 {
		static_cast<ui::Coord>(r.left() + x_max), r.top(),
		1, r.height()
	};
	painter.fill_rectangle(
		r1,
		Color::white()
	);

	const Rect r2 {
		static_cast<ui::Coord>(r.left() + x_max + 1), r.top(),
		static_cast<ui::Dim>(x_lim - (x_max + 1)), r.height()
	};
	painter.fill_rectangle(
		r2,
		Color::black()
	);
}
void RSSI::paint(Painter& painter) {
	const auto r = screen_rect();
	/*
	constexpr int32_t rssi_min = 0.# * 256 / 3.3;
	constexpr int32_t rssi_max = 2.5 * 256 / 3.3;
	// (23 - 194) / 2
	*/
	/* TODO: Clip maximum */
	constexpr int32_t raw_min = 23;
	const int32_t x_0 = 0;
	const int32_t x_min = std::max(x_0, (min_ - raw_min) / 2);
	const int32_t x_avg = std::max(x_min, (avg_ - raw_min) / 2);
	const int32_t x_max = std::max(x_avg + 1, (max_ - raw_min) / 2);
	const int32_t x_lim = r.width();

	const Rect r0 {
		static_cast<ui::Coord>(r.left() + x_0), r.top(),
		static_cast<ui::Dim>(x_min - x_0), r.height()
	};
	painter.fill_rectangle(
		r0,
		Color::blue()
	);

	const Rect r1 {
		static_cast<ui::Coord>(r.left() + x_min), r.top(),
		static_cast<ui::Dim>(x_avg - x_min), r.height()
	};
	painter.fill_rectangle(
		r1,
		Color::red()
	);

	const Rect r2 {
		static_cast<ui::Coord>(r.left() + x_avg), r.top(),
		1, r.height()
	};
	painter.fill_rectangle(
		r2,
		Color::white()
	);

	const Rect r3 {
		static_cast<ui::Coord>(r.left() + x_avg + 1), r.top(),
		static_cast<ui::Dim>(x_max - (x_avg + 1)), r.height()
	};
	painter.fill_rectangle(
		r3,
		Color::red()
	);

	const Rect r4 {
		static_cast<ui::Coord>(r.left() + x_max), r.top(),
		static_cast<ui::Dim>(x_lim - x_max), r.height()
	};
	painter.fill_rectangle(
		r4,
		Color::black()
	);
}
Beispiel #3
0
void TemperatureWidget::paint(Painter& painter) {
	const auto logger = portapack::temperature_logger;

	const auto rect = screen_rect();
	const Color color_background { 0, 0, 64 };
	const Color color_foreground = Color::green();
	const Color color_reticle { 128, 128, 128 };

	const auto graph_width = static_cast<int>(logger.capacity()) * bar_width;
	const Rect graph_rect {
		rect.left() + (rect.width() - graph_width) / 2, rect.top() + 8,
		graph_width, rect.height()
	};
	const Rect frame_rect {
		graph_rect.left() - 1, graph_rect.top() - 1,
		graph_rect.width() + 2, graph_rect.height() + 2
	};
	painter.draw_rectangle(frame_rect, color_reticle);
	painter.fill_rectangle(graph_rect, color_background);

	const auto history = logger.history();
	for(size_t i=0; i<history.size(); i++) {
		const Coord x = graph_rect.right() - (history.size() - i) * bar_width;
		const auto sample = history[i];
		const auto temp = temperature(sample);
		const auto y = screen_y(temp, graph_rect);
		const Dim bar_height = graph_rect.bottom() - y;
		painter.fill_rectangle({ x, y, bar_width, bar_height }, color_foreground);
	}

	if( !history.empty() ) {
		const auto sample = history.back();
		const auto temp = temperature(sample);
		const auto last_y = screen_y(temp, graph_rect);
		const Coord x = graph_rect.right() + 8;
		const Coord y = last_y - 8;

		painter.draw_string({ x, y }, style(), temperature_str(temp));
	}

	const auto display_temp_max = display_temp_min + (graph_rect.height() / display_temp_scale);
	for(auto temp=display_temp_min; temp<=display_temp_max; temp+=10) {
		const int32_t tick_length = 6;
		const auto tick_x = graph_rect.left() - tick_length;
		const auto tick_y = screen_y(temp, graph_rect);
		painter.fill_rectangle({ tick_x, tick_y, tick_length, 1 }, color_reticle);
		const auto text_x = graph_rect.left() - temp_len * 8 - 8;
		const auto text_y = tick_y - 8;
		painter.draw_string({ text_x, text_y }, style(), temperature_str(temp));
	}
}
	void paint(Painter& painter) override {
		const auto r = screen_rect();
		const auto& s = style();

		Rect target_rect { r.pos, { r.width(), s.font.line_height() }};
		const size_t visible_item_count = r.height() / s.font.line_height();

		auto selected = recent.find(selected_key);
		if( selected == std::end(recent) ) {
			selected = std::begin(recent);
		}

		auto range = recent.range_around(selected, visible_item_count);

		for(auto p = range.first; p != range.second; p++) {
			const auto& entry = *p;
			const auto is_selected_key = (selected_key == entry.key());
			draw(entry, target_rect, painter, s, (has_focus() && is_selected_key));
			target_rect.pos.y += target_rect.height();
		}

		painter.fill_rectangle(
			{ target_rect.left(), target_rect.top(), target_rect.width(), r.bottom() - target_rect.top() },
			style().background
		);
	}
void Audio::paint(Painter& painter) {
	const auto r = screen_rect();

	constexpr int db_min = -96;
	constexpr int db_max = 0;
	constexpr int db_delta = db_max - db_min;
	const range_t<int> x_rms_range { 0, r.width() - 1 };
	const auto x_rms = x_rms_range.clip((rms_db_ - db_min) * r.width() / db_delta);
	const range_t<int> x_max_range { x_rms + 1, r.width() };
	const auto x_max = x_max_range.clip((max_db_ - db_min) * r.width() / db_delta);

	const Rect r0 {
		static_cast<ui::Coord>(r.left()), r.top(),
		static_cast<ui::Dim>(x_rms), r.height()
	};
	painter.fill_rectangle(
		r0,
		Color::green()
	);

	const Rect r1 {
		static_cast<ui::Coord>(r.left() + x_rms), r.top(),
		1, r.height()
	};
	painter.fill_rectangle(
		r1,
		Color::black()
	);

	const Rect r2 {
		static_cast<ui::Coord>(r.left() + x_rms + 1), r.top(),
		static_cast<ui::Dim>(x_max - (x_rms + 1)), r.height()
	};
	painter.fill_rectangle(
		r2,
		Color::red()
	);

	const Rect r3 {
		static_cast<ui::Coord>(r.left() + x_max), r.top(),
		static_cast<ui::Dim>(r.width() - x_max), r.height()
	};
	painter.fill_rectangle(
		r3,
		Color::black()
	);
}
void Text::paint(Painter& painter) {
    const auto rect = screen_rect();
    const auto s = style();

    painter.fill_rectangle(rect, s.background);

    painter.draw_string(
        rect.location(),
        s,
        text
    );
}
void MenuItemView::paint(Painter& painter) {
	const auto r = screen_rect();

	const auto paint_style = (highlighted() && parent()->has_focus()) ? style().invert() : style();

	const auto font_height = paint_style.font.line_height();

	painter.fill_rectangle(
		r,
		paint_style.background
	);

	painter.draw_string(
		{ r.left() + 8, r.top() + (r.height() - font_height) / 2 },
		paint_style,
		item.text
	);
}
void Button::paint(Painter& painter) {
    const auto r = screen_rect();

    const auto paint_style = (has_focus() || highlighted()) ? style().invert() : style();

    painter.draw_rectangle(r, style().foreground);

    painter.fill_rectangle(
    { r.left() + 1, r.top() + 1, r.width() - 2, r.height() - 2 },
    paint_style.background
    );

    const auto label_r = paint_style.font.size_of(text_);
    painter.draw_string(
    { r.left() + (r.width() - label_r.width()) / 2, r.top() + (r.height() - label_r.height()) / 2 },
    paint_style,
    text_
    );
}
void Rectangle::paint(Painter& painter) {
    painter.fill_rectangle(
        screen_rect(),
        color
    );
}
void View::paint(Painter& painter) {
    painter.fill_rectangle(
        screen_rect(),
        style().background
    );
}
Beispiel #11
0
void RSSI::paint(Painter& painter) {
    const auto r = screen_rect();

    constexpr int rssi_sample_range = 256;
    constexpr float rssi_voltage_min = 0.4;
    constexpr float rssi_voltage_max = 2.2;
    constexpr float adc_voltage_max = 3.3;
    constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
    constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
    constexpr int raw_delta = raw_max - raw_min;
    const range_t<int> x_avg_range { 0, r.width() - 1 };
    const auto x_avg = x_avg_range.clip((avg_ - raw_min) * r.width() / raw_delta);
    const range_t<int> x_min_range { 0, x_avg };
    const auto x_min = x_min_range.clip((min_ - raw_min) * r.width() / raw_delta);
    const range_t<int> x_max_range { x_avg + 1, r.width() };
    const auto x_max = x_max_range.clip((max_ - raw_min) * r.width() / raw_delta);

    const Rect r0 {
        static_cast<ui::Coord>(r.left()), r.top(),
        static_cast<ui::Dim>(x_min), r.height()
    };
    painter.fill_rectangle(
        r0,
        Color::blue()
    );

    const Rect r1 {
        static_cast<ui::Coord>(r.left() + x_min), r.top(),
        static_cast<ui::Dim>(x_avg - x_min), r.height()
    };
    painter.fill_rectangle(
        r1,
        Color::red()
    );

    const Rect r2 {
        static_cast<ui::Coord>(r.left() + x_avg), r.top(),
        1, r.height()
    };
    painter.fill_rectangle(
        r2,
        Color::white()
    );

    const Rect r3 {
        static_cast<ui::Coord>(r.left() + x_avg + 1), r.top(),
        static_cast<ui::Dim>(x_max - (x_avg + 1)), r.height()
    };
    painter.fill_rectangle(
        r3,
        Color::red()
    );

    const Rect r4 {
        static_cast<ui::Coord>(r.left() + x_max), r.top(),
        static_cast<ui::Dim>(r.width() - x_max), r.height()
    };
    painter.fill_rectangle(
        r4,
        Color::black()
    );

    if (pwmrssi_enabled) {
        const range_t<int> pwmrssi_avg_range { 0, 96 };
        const auto pwmrssi_avg = pwmrssi_avg_range.clip((avg_ - raw_min) * 96 / raw_delta);
        baseband::set_pwmrssi(pwmrssi_avg, true);
    }
}