add text
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "hal/draw.hpp"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#define FONT_HEIGHT 7
|
||||
#define FONT_WIDTH 5
|
||||
|
||||
namespace font {
|
||||
void putchar(char c, uint16_t x, uint16_t y, draw::color_t color);
|
||||
void puts(const std::string &s, uint16_t x, uint16_t y, draw::color_t color);
|
||||
} // namespace font
|
||||
+106
-1
@@ -1,4 +1,7 @@
|
||||
#include "../res/5x7_dotmatrix_charset.h"
|
||||
#include "config.hpp"
|
||||
#include "core/font.hpp"
|
||||
#include "core/helpers.hpp"
|
||||
#include "hal/draw.hpp"
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
@@ -71,4 +74,106 @@ draw::color_t get_altitude_color(uint32_t value) {
|
||||
}};
|
||||
return interpolateColor(value, stops);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum letter_id {
|
||||
LETTER_A,
|
||||
LETTER_B,
|
||||
LETTER_C,
|
||||
LETTER_D,
|
||||
LETTER_E,
|
||||
LETTER_F,
|
||||
LETTER_G,
|
||||
LETTER_H,
|
||||
LETTER_I,
|
||||
LETTER_J,
|
||||
LETTER_K,
|
||||
LETTER_L,
|
||||
LETTER_M,
|
||||
LETTER_N,
|
||||
LETTER_O,
|
||||
LETTER_P,
|
||||
LETTER_Q,
|
||||
LETTER_R,
|
||||
LETTER_S,
|
||||
LETTER_T,
|
||||
LETTER_U,
|
||||
LETTER_V,
|
||||
LETTER_W,
|
||||
LETTER_X,
|
||||
LETTER_Y,
|
||||
LETTER_Z,
|
||||
LETTER_a,
|
||||
LETTER_b,
|
||||
LETTER_c,
|
||||
LETTER_d,
|
||||
LETTER_e,
|
||||
LETTER_f,
|
||||
LETTER_g,
|
||||
LETTER_h,
|
||||
LETTER_i,
|
||||
LETTER_j,
|
||||
LETTER_k,
|
||||
LETTER_l,
|
||||
LETTER_m,
|
||||
LETTER_n,
|
||||
LETTER_o,
|
||||
LETTER_p,
|
||||
LETTER_q,
|
||||
LETTER_r,
|
||||
LETTER_s,
|
||||
LETTER_t,
|
||||
LETTER_u,
|
||||
LETTER_v,
|
||||
LETTER_w,
|
||||
LETTER_x,
|
||||
LETTER_y,
|
||||
LETTER_z,
|
||||
LETTER_0,
|
||||
LETTER_1,
|
||||
LETTER_2,
|
||||
LETTER_3,
|
||||
LETTER_4,
|
||||
LETTER_5,
|
||||
LETTER_6,
|
||||
LETTER_7,
|
||||
LETTER_8,
|
||||
LETTER_9
|
||||
};
|
||||
|
||||
namespace font {
|
||||
void putchar(const char c, uint16_t x, uint16_t y, const draw::color_t color) {
|
||||
uint8_t char_index;
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
char_index = (c - 'a') + LETTER_a;
|
||||
} else if (c >= 'A' && c <= 'Z') {
|
||||
char_index = (c - 'A') + LETTER_A;
|
||||
} else if (c >= '0' && c <= '9') {
|
||||
char_index = (c - '0') + LETTER_0;
|
||||
} else {
|
||||
return; // unsupported character
|
||||
}
|
||||
const uint16_t character_bit_offset = char_index * FONT_WIDTH;
|
||||
const uint16_t x_orig = x;
|
||||
for (uint8_t i = 0; i < FONT_HEIGHT; i++) {
|
||||
x = x_orig;
|
||||
for (uint8_t j = 0; j < FONT_WIDTH; j++) {
|
||||
if (get_Nth_bit_in_grid(_5x7_dotmatrix_charset,
|
||||
static_cast<typeof(character_bit_offset)>(
|
||||
character_bit_offset + j),
|
||||
static_cast<typeof(character_bit_offset)>(i),
|
||||
static_cast<typeof(character_bit_offset)>(
|
||||
_5X7_DOTMATRIX_CHARSET_WIDTH))) {
|
||||
draw::pixel(x, y, color);
|
||||
}
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
void puts(const std::string &s, uint16_t x, uint16_t y, draw::color_t color) {
|
||||
for (size_t i = 0; i < s.length(); i++) {
|
||||
putchar(s[i], x+((FONT_WIDTH+CONFIG_CHARACTER_SPACING)*i), y, color);
|
||||
}
|
||||
}
|
||||
} // namespace font
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
template <typename T>
|
||||
// all arguments are in bits
|
||||
static inline bool get_Nth_bit_in_grid(const void *p, T col_x, T row_y,
|
||||
T grid_width) {
|
||||
const unsigned char *bytes = static_cast<const unsigned char *>(p);
|
||||
return (bytes[row_y * ((grid_width + 7) / 8) + (col_x / 8)] >> (7 - (col_x % 8))) & 1;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "../res/station.h"
|
||||
#include "core/color.h"
|
||||
#include "core/config.hpp"
|
||||
#include "core/font.hpp"
|
||||
#include "core/units.hpp"
|
||||
#include "hal/draw.hpp"
|
||||
#include "hal/hal.hpp"
|
||||
@@ -12,6 +13,7 @@
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <numbers>
|
||||
#include <string>
|
||||
#include "core/global.hpp"
|
||||
#include "core/geo.hpp"
|
||||
#include "core/gfx.hpp"
|
||||
@@ -146,6 +148,7 @@ int main() {
|
||||
|
||||
draw::line(x_center, y_center,x_center + (vector_lenght*std::cos(track_rad)), y_center + (vector_lenght*std::sin(track_rad)), color);
|
||||
draw::rhombus(x_center, y_center, 8/*TODO: remove magic*/,color);
|
||||
font::puts("TEST123", x_center+10, y_center, color);
|
||||
} catch(...) {
|
||||
std::clog << YELLOW"[WARNING]" RESET " aircraft with no lat/lon data detected!\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user