Beispiel #1
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));
	}
}
Rect AISRecentEntryDetailView::draw_field(
	Painter& painter,
	const Rect& draw_rect,
	const Style& style,
	const std::string& label,
	const std::string& value
) {
	const int label_length_max = 4;

	painter.draw_string(Point { draw_rect.left(), draw_rect.top() }, style, label);
	painter.draw_string(Point { draw_rect.left() + (label_length_max + 1) * 8, draw_rect.top() }, style, value);

	return { draw_rect.left(), draw_rect.top() + draw_rect.height(), draw_rect.width(), draw_rect.height() };
}
Beispiel #3
0
void RecentEntriesView<TPMSRecentEntries>::draw(
	const Entry& entry,
	const Rect& target_rect,
	Painter& painter,
	const Style& style,
	const bool is_selected
) {
	const auto& draw_style = is_selected ? style.invert() : style;

	std::string line = tpms::format::type(entry.type) + " " + tpms::format::id(entry.id);

	if( entry.last_pressure.is_valid() ) {
		line += " " + tpms::format::pressure(entry.last_pressure.value());
	} else {
		line += " " "   ";
	}

	if( entry.last_temperature.is_valid() ) {
		line += " " + tpms::format::temperature(entry.last_temperature.value());
	} else {
		line += " " "   ";
	}

	if( entry.received_count > 999 ) {
		line += " +++";
	} else {
		line += " " + to_string_dec_uint(entry.received_count, 3);
	}

	line.resize(target_rect.width() / 8, ' ');
	painter.draw_string(target_rect.pos, draw_style, line);
}
void NumberField::paint(Painter& painter) {
    const auto text = to_string_dec_int(value_, length_, fill_char);

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

    painter.draw_string(
        screen_pos(),
        paint_style,
        text
    );
}
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 OptionsField::paint(Painter& painter) {
    const auto paint_style = has_focus() ? style().invert() : style();

    if( selected_index() < options.size() ) {
        const auto text = options[selected_index()].first;
        painter.draw_string(
            screen_pos(),
            paint_style,
            text
        );
    }
}
void FrequencyField::paint(Painter& painter) {
	const auto mhz = to_string_dec_int(value_ / 1000000, 4);
	const auto hz100 = to_string_dec_int((value_ / 100) % 10000, 4, '0');

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

	painter.draw_string(
		screen_pos(),
		paint_style,
		mhz
	);
	painter.draw_string(
		screen_pos() + Point { 4 * 8, 0 },
		paint_style,
		"."
	);
	painter.draw_string(
		screen_pos() + Point { 5 * 8, 0 },
		paint_style,
		hz100
	);
}
Beispiel #8
0
void DebugRFFC5072RegistersWidget::draw_legend(Painter& painter) {
	for(size_t i=0; i<registers_count; i+=registers_per_row) {
		const Point offset {
			0, static_cast<Coord>((i / registers_per_row) * row_height)
		};

		const auto text = to_string_hex(i, legend_length);
		painter.draw_string(
			screen_pos() + offset,
			style(),
			text
		);
	}
}
Beispiel #9
0
void RegistersWidget::draw_legend(const Coord left, Painter& painter) {
	const auto pos = screen_pos();

	for(int i=0; i<config.registers_count; i+=config.registers_per_row) {
		const Point offset {
			left, (i / config.registers_per_row) * row_height
		};

		const auto text = to_string_hex(i, config.legend_length);
		painter.draw_string(
			pos + offset,
			style().invert(),
			text
		);
	}
}
Beispiel #10
0
void RecentEntriesView<ERTRecentEntries>::draw_header(
	const Rect& target_rect,
	Painter& painter,
	const Style& style
) {
	auto x = 0;
	for(const auto& column : ert_columns) {
		const auto width = column.second;
		auto text = column.first;
		if( width > text.length() ) {
			text.append(width - text.length(), ' ');
		}

		painter.draw_string({ x, target_rect.pos.y }, style, text);
		x += (width * 8) + 8;
	}
}
void RecentEntriesTable<ERTRecentEntries>::draw(
	const Entry& entry,
	const Rect& target_rect,
	Painter& painter,
	const Style& style
) {
	std::string line = ert::format::id(entry.id) + " " + ert::format::commodity_type(entry.commodity_type) + " " + ert::format::consumption(entry.last_consumption);

	if( entry.received_count > 999 ) {
		line += " +++";
	} else {
		line += " " + to_string_dec_uint(entry.received_count, 3);
	}

	line.resize(target_rect.width() / 8, ' ');
	painter.draw_string(target_rect.location(), style, line);
}
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 RecentEntriesView<AISRecentEntries>::draw(
	const Entry& entry,
	const Rect& target_rect,
	Painter& painter,
	const Style& style,
	const bool is_selected
) {
	const auto& draw_style = is_selected ? style.invert() : style;

	std::string line = ais::format::mmsi(entry.mmsi) + " ";
	if( !entry.name.empty() ) {
		line += entry.name;
	} else {
		line += entry.call_sign;
	}

	line.resize(target_rect.width() / 8, ' ');
	painter.draw_string(target_rect.pos, draw_style, line);
}
Beispiel #15
0
void DebugRFFC5072RegistersWidget::draw_values(
	Painter& painter,
	const rffc507x::RegisterMap registers
) {
	for(size_t i=0; i<registers_count; i++) {
		const Point offset = {
			static_cast<Coord>(legend_width + 8 + (i % registers_per_row) * (value_width + 8)),
			static_cast<Coord>((i / registers_per_row) * row_height)
		};

		const uint16_t value = registers.w[i];

		const auto text = to_string_hex(value, value_length);
		painter.draw_string(
			screen_pos() + offset,
			style(),
			text
		);
	}
}
Beispiel #16
0
void RecentEntriesView<ERTRecentEntries>::draw(
	const Entry& entry,
	const Rect& target_rect,
	Painter& painter,
	const Style& style,
	const bool is_selected
) {
	const auto& draw_style = is_selected ? style.invert() : style;

	std::string line = ert::format::id(entry.id) + " " + ert::format::commodity_type(entry.commodity_type) + " " + ert::format::consumption(entry.last_consumption);

	if( entry.received_count > 999 ) {
		line += " +++";
	} else {
		line += " " + to_string_dec_uint(entry.received_count, 3);
	}

	line.resize(target_rect.width() / 8, ' ');
	painter.draw_string(target_rect.pos, draw_style, line);
}
Beispiel #17
0
void RegistersWidget::draw_values(
	const Coord left,
	Painter& painter
) {
	const auto pos = screen_pos();

	for(int i=0; i<config.registers_count; i++) {
		const Point offset = {
			left + config.legend_width() + 8 + (i % config.registers_per_row) * (config.value_width() + 8),
			(i / config.registers_per_row) * row_height
		};

		const auto value = reader(i);

		const auto text = to_string_hex(value, config.value_length);
		painter.draw_string(
			pos + offset,
			style(),
			text
		);
	}
}