kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Merge pull request #70 from pimoroni/patch-runtime-set-font
Adding support for differing font heights (Replaces #55)pull/104/head
commit
3547d74702
|
@ -9,4 +9,13 @@ add_resource(explorer fox.tga)
|
|||
target_link_libraries(explorer pico_stdlib pico_explorer msa301)
|
||||
|
||||
# create map/bin/hex file etc.
|
||||
pico_add_extra_outputs(explorer)
|
||||
pico_add_extra_outputs(explorer)
|
||||
|
||||
add_executable(
|
||||
text_demo
|
||||
text_demo.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(text_demo pico_stdlib pico_explorer msa301)
|
||||
|
||||
pico_add_extra_outputs(text_demo)
|
|
@ -0,0 +1,43 @@
|
|||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "pico_explorer.hpp"
|
||||
#include "font6_data.hpp"
|
||||
#include "font8_data.hpp"
|
||||
#include "msa301.hpp"
|
||||
|
||||
using namespace pimoroni;
|
||||
|
||||
extern unsigned char _binary_fox_tga_start[];
|
||||
|
||||
uint16_t buffer[PicoExplorer::WIDTH * PicoExplorer::HEIGHT];
|
||||
PicoExplorer pico_explorer(buffer);
|
||||
MSA301 msa301;
|
||||
|
||||
int main() {
|
||||
pico_explorer.init();
|
||||
pico_explorer.set_font(&font8);
|
||||
msa301.init();
|
||||
|
||||
uint32_t i = 0;
|
||||
while(true) {
|
||||
pico_explorer.set_pen(120, 40, 60);
|
||||
pico_explorer.clear();
|
||||
|
||||
pico_explorer.set_pen(255, 255, 255);
|
||||
pico_explorer.set_font(&font6);
|
||||
pico_explorer.text("6x6: The quick, brown fox jumps over the lazy dog! UPPER. lower.", Point(10, 10), 220);
|
||||
pico_explorer.text("0123456789 !$%^&*()", Point(10, 70), 220);
|
||||
pico_explorer.set_font(&font8);
|
||||
pico_explorer.text("6x8: The quick, brown fox jumps over the lazy dog! UPPER. lower.", Point(10, 120), 220);
|
||||
pico_explorer.text("0123456789 !$%^&*()", Point(10, 180), 220);
|
||||
|
||||
pico_explorer.update();
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1 +1 @@
|
|||
include(pico_graphics.cmake)
|
||||
include(pico_graphics.cmake)
|
||||
|
|
|
@ -26,6 +26,7 @@ It supports drawing text, primitive and individual pixels and includes basic typ
|
|||
- [rectangle](#rectangle)
|
||||
- [circle](#circle)
|
||||
- [Text](#text)
|
||||
- [Change Font](#change-font)
|
||||
|
||||
## Function Reference
|
||||
|
||||
|
@ -232,7 +233,23 @@ void PicoGraphics::text(const std::string &t, const point &p, int32_t wrap, uint
|
|||
|
||||
`text` allows you to draw a string at `point p`, with a maximum line-width of `int32_t wrap`.
|
||||
|
||||
The 6x6 pixel font characters are encoded in `font_data.cpp` along with their character widths so that text can be drawn variable-width.
|
||||
The 6x6 and 6x8 pixel font characters are encoded in `font6_data.hpp` and `font8_data.hpp` along with their character widths so that text can be drawn variable-width.
|
||||
|
||||
You can scale text with `uint8_t scale` for 12x12, 18x18, etc character sizes.
|
||||
|
||||
### Change Font
|
||||
|
||||
```c++
|
||||
void PicoGraphics::set_font(const Font *font);
|
||||
```
|
||||
|
||||
|
||||
`set_font` allows you to change the font that PicoGraphics uses to draw text.
|
||||
|
||||
If you:
|
||||
|
||||
```c++
|
||||
#include "font8_data.hpp"
|
||||
```
|
||||
|
||||
Then you can: `set_font(&font8);` to use a font with upper/lowercase characters.
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace pimoroni {
|
||||
struct Font {
|
||||
const uint8_t height;
|
||||
const uint8_t max_width;
|
||||
const uint8_t widths[96];
|
||||
const uint8_t data[];
|
||||
};
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
#pragma once
|
||||
|
||||
#include "font.hpp"
|
||||
|
||||
const pimoroni::Font font6 {
|
||||
.height = 6,
|
||||
.max_width = 6,
|
||||
.widths = {
|
||||
3, 2, 4, 6, 6, 6, 7, 2, 3, 3, 4, 4, 2, 4, 2, 4,
|
||||
6, 3, 5, 5, 6, 5, 6, 6, 6, 6, 2, 2, 4, 4, 4, 5,
|
||||
7, 6, 6, 5, 6, 5, 5, 6, 5, 4, 5, 5, 5, 6, 6, 6,
|
||||
6, 6, 6, 5, 6, 6, 6, 6, 5, 5, 5, 3, 4, 3, 4, 4,
|
||||
3, 6, 6, 5, 6, 5, 5, 6, 5, 4, 5, 5, 5, 6, 6, 6,
|
||||
6, 6, 6, 5, 6, 6, 6, 6, 5, 5, 5, 4, 2, 4, 4, 2
|
||||
},
|
||||
.data = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00, //
|
||||
0x2e,0x00,0x00,0x00,0x00,0x00, // !
|
||||
0x06,0x00,0x06,0x00,0x00,0x00, // "
|
||||
0x14,0x3e,0x14,0x3e,0x14,0x00, // #
|
||||
0x04,0x2a,0x3e,0x2a,0x10,0x00, // $
|
||||
0x22,0x10,0x08,0x04,0x22,0x00, // %
|
||||
0x14,0x2a,0x2a,0x2c,0x10,0x28, // &
|
||||
0x06,0x00,0x00,0x00,0x00,0x00, // '
|
||||
0x1c,0x22,0x00,0x00,0x00,0x00, // (
|
||||
0x22,0x1c,0x00,0x00,0x00,0x00, // )
|
||||
0x14,0x08,0x14,0x00,0x00,0x00, // *
|
||||
0x08,0x1c,0x08,0x00,0x00,0x00, // +
|
||||
0x60,0x00,0x00,0x00,0x00,0x00, // ,
|
||||
0x08,0x08,0x08,0x00,0x00,0x00, // -
|
||||
0x20,0x00,0x00,0x00,0x00,0x00, // .
|
||||
0x30,0x0c,0x02,0x00,0x00,0x00, // /
|
||||
0x1c,0x22,0x22,0x22,0x1e,0x00, // 0
|
||||
0x02,0x3e,0x00,0x00,0x00,0x00, // 1
|
||||
0x32,0x2a,0x2a,0x24,0x00,0x00, // 2
|
||||
0x2a,0x2a,0x2a,0x16,0x00,0x00, // 3
|
||||
0x0e,0x10,0x10,0x3e,0x10,0x00, // 4
|
||||
0x2e,0x2a,0x2a,0x12,0x00,0x00, // 5
|
||||
0x3c,0x2a,0x2a,0x2a,0x12,0x00, // 6
|
||||
0x06,0x02,0x22,0x12,0x0e,0x00, // 7
|
||||
0x14,0x2a,0x2a,0x2a,0x16,0x00, // 8
|
||||
0x04,0x2a,0x2a,0x2a,0x1e,0x00, // 9
|
||||
0x24,0x00,0x00,0x00,0x00,0x00, // :
|
||||
0x64,0x00,0x00,0x00,0x00,0x00, // ;
|
||||
0x08,0x14,0x22,0x00,0x00,0x00, // <
|
||||
0x14,0x14,0x14,0x00,0x00,0x00, // =
|
||||
0x22,0x14,0x08,0x00,0x00,0x00, // >
|
||||
0x02,0x2a,0x0a,0x04,0x00,0x00, // ?
|
||||
0x3c,0x02,0x1a,0x2a,0x22,0x1e, // @
|
||||
0x3c,0x12,0x12,0x12,0x3e,0x00, // A
|
||||
0x3c,0x2a,0x2a,0x2e,0x10,0x00, // B
|
||||
0x1c,0x22,0x22,0x22,0x00,0x00, // C
|
||||
0x3c,0x22,0x22,0x22,0x1c,0x00, // D
|
||||
0x3c,0x2a,0x2a,0x2a,0x00,0x00, // E
|
||||
0x3c,0x12,0x12,0x12,0x00,0x00, // F
|
||||
0x3c,0x22,0x22,0x2a,0x1a,0x00, // G
|
||||
0x3e,0x08,0x08,0x3e,0x00,0x00, // H
|
||||
0x22,0x3e,0x22,0x00,0x00,0x00, // I
|
||||
0x30,0x22,0x22,0x1e,0x00,0x00, // J
|
||||
0x3e,0x08,0x0c,0x32,0x00,0x00, // K
|
||||
0x3e,0x20,0x20,0x20,0x00,0x00, // L
|
||||
0x3c,0x02,0x3c,0x02,0x3c,0x00, // M
|
||||
0x3c,0x02,0x02,0x02,0x3e,0x00, // N
|
||||
0x1c,0x22,0x22,0x22,0x1e,0x00, // O
|
||||
0x3c,0x12,0x12,0x12,0x0e,0x00, // P
|
||||
0x1c,0x22,0x22,0x62,0x1e,0x00, // Q
|
||||
0x3c,0x12,0x12,0x32,0x0e,0x00, // R
|
||||
0x24,0x2a,0x2a,0x12,0x00,0x00, // S
|
||||
0x02,0x02,0x3e,0x02,0x02,0x00, // T
|
||||
0x1e,0x20,0x20,0x20,0x1e,0x00, // U
|
||||
0x0e,0x10,0x20,0x10,0x0e,0x00, // V
|
||||
0x3e,0x20,0x1e,0x20,0x1e,0x00, // W
|
||||
0x36,0x08,0x08,0x36,0x00,0x00, // X
|
||||
0x26,0x28,0x28,0x1e,0x00,0x00, // Y
|
||||
0x32,0x2a,0x2a,0x26,0x00,0x00, // Z
|
||||
0x3e,0x22,0x00,0x00,0x00,0x00, // [
|
||||
0x02,0x0c,0x30,0x00,0x00,0x00, // "\"
|
||||
0x22,0x3e,0x00,0x00,0x00,0x00, // ]
|
||||
0x04,0x02,0x04,0x00,0x00,0x00, // ^
|
||||
0x20,0x20,0x20,0x00,0x00,0x00, // _
|
||||
0x02,0x04,0x00,0x00,0x00,0x00, // `
|
||||
0x3c,0x12,0x12,0x12,0x3e,0x00, // a
|
||||
0x3c,0x2a,0x2a,0x2e,0x10,0x00, // b
|
||||
0x1c,0x22,0x22,0x22,0x00,0x00, // c
|
||||
0x3c,0x22,0x22,0x22,0x1c,0x00, // d
|
||||
0x3c,0x2a,0x2a,0x2a,0x00,0x00, // e
|
||||
0x3c,0x12,0x12,0x12,0x00,0x00, // f
|
||||
0x3c,0x22,0x22,0x2a,0x1a,0x00, // g
|
||||
0x3e,0x08,0x08,0x3e,0x00,0x00, // h
|
||||
0x22,0x3e,0x22,0x00,0x00,0x00, // i
|
||||
0x30,0x22,0x22,0x1e,0x00,0x00, // j
|
||||
0x3e,0x08,0x0c,0x32,0x00,0x00, // k
|
||||
0x3e,0x20,0x20,0x20,0x00,0x00, // l
|
||||
0x3c,0x02,0x3c,0x02,0x3e,0x00, // m
|
||||
0x3c,0x02,0x02,0x02,0x3e,0x00, // n
|
||||
0x1c,0x22,0x22,0x22,0x1e,0x00, // o
|
||||
0x3c,0x12,0x12,0x12,0x0e,0x00, // p
|
||||
0x1c,0x22,0x22,0x62,0x1e,0x00, // q
|
||||
0x3c,0x12,0x12,0x32,0x0e,0x00, // r
|
||||
0x24,0x2a,0x2a,0x12,0x00,0x00, // s
|
||||
0x02,0x02,0x3e,0x02,0x02,0x00, // t
|
||||
0x1e,0x20,0x20,0x20,0x1e,0x00, // u
|
||||
0x0e,0x10,0x20,0x10,0x0e,0x00, // v
|
||||
0x3e,0x20,0x1e,0x20,0x1e,0x00, // w
|
||||
0x36,0x08,0x08,0x36,0x00,0x00, // x
|
||||
0x26,0x28,0x28,0x1e,0x00,0x00, // y
|
||||
0x32,0x2a,0x2a,0x26,0x00,0x00, // z
|
||||
0x08,0x3e,0x22,0x00,0x00,0x00, // {
|
||||
0x3e,0x00,0x00,0x00,0x00,0x00, // |
|
||||
0x22,0x3e,0x08,0x00,0x00,0x00, // }
|
||||
0x04,0x02,0x02,0x00,0x00,0x00, // ~
|
||||
0x00,0x00,0x00,0x00,0x00,0x00
|
||||
}
|
||||
};
|
|
@ -0,0 +1,114 @@
|
|||
#pragma once
|
||||
|
||||
#include "font.hpp"
|
||||
|
||||
const pimoroni::Font font8 {
|
||||
.height = 8,
|
||||
.max_width = 6,
|
||||
.widths = {
|
||||
2, 2, 4, 6, 5, 5, 5, 2, 4, 4, 4, 4, 3, 4, 3, 5,
|
||||
5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 2, 3, 4, 4, 4, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 6, 5, 5,
|
||||
5, 5, 5, 5, 6, 5, 5, 6, 5, 5, 5, 3, 5, 3, 4, 4,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 4, 6, 5, 5,
|
||||
5, 5, 5, 5, 5, 5, 5, 6, 5, 5, 5, 4, 2, 4, 5, 2
|
||||
},
|
||||
.data = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00, //
|
||||
0x5f,0x00,0x00,0x00,0x00,0x00, // !
|
||||
0x03,0x00,0x03,0x00,0x00,0x00, // "
|
||||
0x28,0x7c,0x28,0x7c,0x28,0x00, // #
|
||||
0x24,0x7a,0x2f,0x12,0x00,0x00, // $
|
||||
0x66,0x10,0x08,0x66,0x00,0x00, // %
|
||||
0x36,0x49,0x49,0x7c,0x00,0x00, // &
|
||||
0x03,0x00,0x00,0x00,0x00,0x00, // '
|
||||
0x1c,0x22,0x41,0x00,0x00,0x00, // (
|
||||
0x41,0x22,0x1c,0x00,0x00,0x00, // )
|
||||
0x54,0x38,0x54,0x00,0x00,0x00, // *
|
||||
0x10,0x38,0x10,0x00,0x00,0x00, // +
|
||||
0x80,0x60,0x00,0x00,0x00,0x00, // ,
|
||||
0x10,0x10,0x10,0x00,0x00,0x00, // -
|
||||
0x60,0x60,0x00,0x00,0x00,0x00, // .
|
||||
0x60,0x18,0x06,0x01,0x00,0x00, // /
|
||||
0x3e,0x41,0x41,0x3e,0x00,0x00, // 0
|
||||
0x42,0x7f,0x40,0x00,0x00,0x00, // 1
|
||||
0x62,0x51,0x49,0x46,0x00,0x00, // 2
|
||||
0x21,0x49,0x4d,0x33,0x00,0x00, // 3
|
||||
0x18,0x16,0x11,0x7f,0x00,0x00, // 4
|
||||
0x4f,0x49,0x49,0x31,0x00,0x00, // 5
|
||||
0x3c,0x4a,0x49,0x30,0x00,0x00, // 6
|
||||
0x01,0x61,0x19,0x07,0x00,0x00, // 7
|
||||
0x36,0x49,0x49,0x36,0x00,0x00, // 8
|
||||
0x06,0x49,0x29,0x1e,0x00,0x00, // 9
|
||||
0x33,0x00,0x00,0x00,0x00,0x00, // :
|
||||
0x80,0x6c,0x00,0x00,0x00,0x00, // ;
|
||||
0x10,0x28,0x44,0x00,0x00,0x00, // <
|
||||
0x28,0x28,0x28,0x00,0x00,0x00, // =
|
||||
0x44,0x28,0x10,0x00,0x00,0x00, // >
|
||||
0x02,0x51,0x09,0x06,0x00,0x00, // ?
|
||||
0x3e,0x49,0x55,0x5e,0x00,0x00, // @
|
||||
0x7e,0x09,0x09,0x7e,0x00,0x00, // A
|
||||
0x7f,0x49,0x49,0x36,0x00,0x00, // B
|
||||
0x3e,0x41,0x41,0x22,0x00,0x00, // C
|
||||
0x7f,0x41,0x41,0x3e,0x00,0x00, // D
|
||||
0x7f,0x49,0x49,0x41,0x00,0x00, // E
|
||||
0x7f,0x09,0x09,0x01,0x00,0x00, // F
|
||||
0x3e,0x41,0x49,0x79,0x00,0x00, // G
|
||||
0x7f,0x08,0x08,0x7f,0x00,0x00, // H
|
||||
0x41,0x7f,0x41,0x00,0x00,0x00, // I
|
||||
0x30,0x40,0x40,0x3f,0x00,0x00, // J
|
||||
0x7f,0x08,0x14,0x63,0x00,0x00, // K
|
||||
0x7f,0x40,0x40,0x40,0x00,0x00, // L
|
||||
0x7f,0x02,0x04,0x02,0x7f,0x00, // M
|
||||
0x7f,0x02,0x04,0x7f,0x00,0x00, // N
|
||||
0x3e,0x41,0x41,0x3e,0x00,0x00, // O
|
||||
0x7f,0x09,0x09,0x06,0x00,0x00, // P
|
||||
0x3e,0x41,0x21,0x5e,0x00,0x00, // Q
|
||||
0x7f,0x09,0x19,0x66,0x00,0x00, // R
|
||||
0x46,0x49,0x49,0x31,0x00,0x00, // S
|
||||
0x01,0x01,0x7f,0x01,0x01,0x00, // T
|
||||
0x3f,0x40,0x40,0x3f,0x00,0x00, // U
|
||||
0x7f,0x40,0x20,0x1f,0x00,0x00, // V
|
||||
0x3f,0x40,0x20,0x40,0x3f,0x00, // W
|
||||
0x77,0x08,0x08,0x77,0x00,0x00, // X
|
||||
0x47,0x48,0x48,0x3f,0x00,0x00, // Y
|
||||
0x71,0x49,0x45,0x43,0x00,0x00, // Z
|
||||
0x7f,0x41,0x00,0x00,0x00,0x00, // [
|
||||
0x01,0x06,0x18,0x60,0x00,0x00, // "\"
|
||||
0x41,0x7f,0x00,0x00,0x00,0x00, // ]
|
||||
0x04,0x02,0x04,0x00,0x00,0x00, // ^
|
||||
0x40,0x40,0x40,0x00,0x00,0x00, // _
|
||||
0x01,0x01,0x00,0x00,0x00,0x00, // `
|
||||
0x20,0x54,0x54,0x78,0x00,0x00, // a
|
||||
0x7f,0x44,0x44,0x38,0x00,0x00, // b
|
||||
0x38,0x44,0x44,0x28,0x00,0x00, // c
|
||||
0x38,0x44,0x44,0x7f,0x00,0x00, // d
|
||||
0x38,0x54,0x54,0x58,0x00,0x00, // e
|
||||
0x7e,0x09,0x09,0x02,0x00,0x00, // f
|
||||
0x18,0xa4,0xa4,0x7c,0x00,0x00, // g
|
||||
0x7f,0x04,0x04,0x78,0x00,0x00, // h
|
||||
0x04,0x7d,0x40,0x00,0x00,0x00, // i
|
||||
0x60,0x80,0x80,0x7d,0x00,0x00, // j
|
||||
0x7f,0x10,0x28,0x44,0x00,0x00, // k
|
||||
0x01,0x7f,0x40,0x00,0x00,0x00, // l
|
||||
0x7c,0x04,0x78,0x04,0x78,0x00, // m
|
||||
0x7c,0x04,0x04,0x78,0x00,0x00, // n
|
||||
0x38,0x44,0x44,0x38,0x00,0x00, // o
|
||||
0xfc,0x24,0x24,0x18,0x00,0x00, // p
|
||||
0x18,0x24,0x24,0xfc,0x00,0x00, // q
|
||||
0x7c,0x08,0x04,0x04,0x00,0x00, // r
|
||||
0x48,0x54,0x54,0x24,0x00,0x00, // s
|
||||
0x3e,0x44,0x44,0x20,0x00,0x00, // t
|
||||
0x3c,0x40,0x40,0x7c,0x00,0x00, // u
|
||||
0x7c,0x40,0x20,0x1c,0x00,0x00, // v
|
||||
0x3c,0x40,0x20,0x40,0x3c,0x00, // w
|
||||
0x6c,0x10,0x10,0x6c,0x00,0x00, // x
|
||||
0x1c,0xa0,0xa0,0x7c,0x00,0x00, // y
|
||||
0x64,0x54,0x4c,0x00,0x00,0x00, // z
|
||||
0x08,0x3e,0x41,0x00,0x00,0x00, // {
|
||||
0x7f,0x00,0x00,0x00,0x00,0x00, // |
|
||||
0x41,0x3e,0x08,0x00,0x00,0x00, // }
|
||||
0x08,0x04,0x08,0x04,0x00,0x00, // ~
|
||||
0x00,0x00,0x00,0x00,0x00,0x00
|
||||
}
|
||||
};
|
|
@ -1,110 +0,0 @@
|
|||
#include <cstdint>
|
||||
|
||||
uint8_t font_data[96][6] = {
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00}, //
|
||||
{0x2e,0x00,0x00,0x00,0x00,0x00}, // !
|
||||
{0x06,0x00,0x06,0x00,0x00,0x00}, // "
|
||||
{0x14,0x3e,0x14,0x3e,0x14,0x00}, // #
|
||||
{0x04,0x2a,0x3e,0x2a,0x10,0x00}, // $
|
||||
{0x22,0x10,0x08,0x04,0x22,0x00}, // %
|
||||
{0x14,0x2a,0x2a,0x2c,0x10,0x28}, // &
|
||||
{0x06,0x00,0x00,0x00,0x00,0x00}, // '
|
||||
{0x1c,0x22,0x00,0x00,0x00,0x00}, // (
|
||||
{0x22,0x1c,0x00,0x00,0x00,0x00}, // )
|
||||
{0x14,0x08,0x14,0x00,0x00,0x00}, // *
|
||||
{0x08,0x1c,0x08,0x00,0x00,0x00}, // +
|
||||
{0x60,0x00,0x00,0x00,0x00,0x00}, // ,
|
||||
{0x08,0x08,0x08,0x00,0x00,0x00}, // -
|
||||
{0x20,0x00,0x00,0x00,0x00,0x00}, // .
|
||||
{0x30,0x0c,0x02,0x00,0x00,0x00}, // /
|
||||
{0x1c,0x22,0x22,0x22,0x1e,0x00}, // 0
|
||||
{0x02,0x3e,0x00,0x00,0x00,0x00}, // 1
|
||||
{0x32,0x2a,0x2a,0x24,0x00,0x00}, // 2
|
||||
{0x2a,0x2a,0x2a,0x16,0x00,0x00}, // 3
|
||||
{0x0e,0x10,0x10,0x3e,0x10,0x00}, // 4
|
||||
{0x2e,0x2a,0x2a,0x12,0x00,0x00}, // 5
|
||||
{0x3c,0x2a,0x2a,0x2a,0x12,0x00}, // 6
|
||||
{0x06,0x02,0x22,0x12,0x0e,0x00}, // 7
|
||||
{0x14,0x2a,0x2a,0x2a,0x16,0x00}, // 8
|
||||
{0x04,0x2a,0x2a,0x2a,0x1e,0x00}, // 9
|
||||
{0x24,0x00,0x00,0x00,0x00,0x00}, // :
|
||||
{0x64,0x00,0x00,0x00,0x00,0x00}, // ;
|
||||
{0x08,0x14,0x22,0x00,0x00,0x00}, // <
|
||||
{0x14,0x14,0x14,0x00,0x00,0x00}, // =
|
||||
{0x22,0x14,0x08,0x00,0x00,0x00}, // >
|
||||
{0x02,0x2a,0x0a,0x04,0x00,0x00}, // ?
|
||||
{0x3c,0x02,0x1a,0x2a,0x22,0x1e}, // @
|
||||
{0x3c,0x12,0x12,0x12,0x3e,0x00}, // A
|
||||
{0x3c,0x2a,0x2a,0x2e,0x10,0x00}, // B
|
||||
{0x1c,0x22,0x22,0x22,0x00,0x00}, // C
|
||||
{0x3c,0x22,0x22,0x22,0x1c,0x00}, // D
|
||||
{0x3c,0x2a,0x2a,0x2a,0x00,0x00}, // E
|
||||
{0x3c,0x12,0x12,0x12,0x00,0x00}, // F
|
||||
{0x3c,0x22,0x22,0x2a,0x1a,0x00}, // G
|
||||
{0x3e,0x08,0x08,0x3e,0x00,0x00}, // H
|
||||
{0x22,0x3e,0x22,0x00,0x00,0x00}, // I
|
||||
{0x30,0x22,0x22,0x1e,0x00,0x00}, // J
|
||||
{0x3e,0x08,0x0c,0x32,0x00,0x00}, // K
|
||||
{0x3e,0x20,0x20,0x20,0x00,0x00}, // L
|
||||
{0x3c,0x02,0x3c,0x02,0x3c,0x00}, // M
|
||||
{0x3c,0x02,0x02,0x02,0x3e,0x00}, // N
|
||||
{0x1c,0x22,0x22,0x22,0x1e,0x00}, // O
|
||||
{0x3c,0x12,0x12,0x12,0x0e,0x00}, // P
|
||||
{0x1c,0x22,0x22,0x62,0x1e,0x00}, // Q
|
||||
{0x3c,0x12,0x12,0x32,0x0e,0x00}, // R
|
||||
{0x24,0x2a,0x2a,0x12,0x00,0x00}, // S
|
||||
{0x02,0x02,0x3e,0x02,0x02,0x00}, // T
|
||||
{0x1e,0x20,0x20,0x20,0x1e,0x00}, // U
|
||||
{0x0e,0x10,0x20,0x10,0x0e,0x00}, // V
|
||||
{0x3e,0x20,0x1e,0x20,0x1e,0x00}, // W
|
||||
{0x36,0x08,0x08,0x36,0x00,0x00}, // X
|
||||
{0x26,0x28,0x28,0x1e,0x00,0x00}, // Y
|
||||
{0x32,0x2a,0x2a,0x26,0x00,0x00}, // Z
|
||||
{0x3e,0x22,0x00,0x00,0x00,0x00}, // [
|
||||
{0x02,0x0c,0x30,0x00,0x00,0x00}, // "\"
|
||||
{0x22,0x3e,0x00,0x00,0x00,0x00}, // ]
|
||||
{0x04,0x02,0x04,0x00,0x00,0x00}, // ^
|
||||
{0x20,0x20,0x20,0x00,0x00,0x00}, // _
|
||||
{0x02,0x04,0x00,0x00,0x00,0x00}, // `
|
||||
{0x3c,0x12,0x12,0x12,0x3e,0x00}, // a
|
||||
{0x3c,0x2a,0x2a,0x2e,0x10,0x00}, // b
|
||||
{0x1c,0x22,0x22,0x22,0x00,0x00}, // c
|
||||
{0x3c,0x22,0x22,0x22,0x1c,0x00}, // d
|
||||
{0x3c,0x2a,0x2a,0x2a,0x00,0x00}, // e
|
||||
{0x3c,0x12,0x12,0x12,0x00,0x00}, // f
|
||||
{0x3c,0x22,0x22,0x2a,0x1a,0x00}, // g
|
||||
{0x3e,0x08,0x08,0x3e,0x00,0x00}, // h
|
||||
{0x22,0x3e,0x22,0x00,0x00,0x00}, // i
|
||||
{0x30,0x22,0x22,0x1e,0x00,0x00}, // j
|
||||
{0x3e,0x08,0x0c,0x32,0x00,0x00}, // k
|
||||
{0x3e,0x20,0x20,0x20,0x00,0x00}, // l
|
||||
{0x3c,0x02,0x3c,0x02,0x3e,0x00}, // m
|
||||
{0x3c,0x02,0x02,0x02,0x3e,0x00}, // n
|
||||
{0x1c,0x22,0x22,0x22,0x1e,0x00}, // o
|
||||
{0x3c,0x12,0x12,0x12,0x0e,0x00}, // p
|
||||
{0x1c,0x22,0x22,0x62,0x1e,0x00}, // q
|
||||
{0x3c,0x12,0x12,0x32,0x0e,0x00}, // r
|
||||
{0x24,0x2a,0x2a,0x12,0x00,0x00}, // s
|
||||
{0x02,0x02,0x3e,0x02,0x02,0x00}, // t
|
||||
{0x1e,0x20,0x20,0x20,0x1e,0x00}, // u
|
||||
{0x0e,0x10,0x20,0x10,0x0e,0x00}, // v
|
||||
{0x3e,0x20,0x1e,0x20,0x1e,0x00}, // w
|
||||
{0x36,0x08,0x08,0x36,0x00,0x00}, // x
|
||||
{0x26,0x28,0x28,0x1e,0x00,0x00}, // y
|
||||
{0x32,0x2a,0x2a,0x26,0x00,0x00}, // z
|
||||
{0x08,0x3e,0x22,0x00,0x00,0x00}, // {
|
||||
{0x3e,0x00,0x00,0x00,0x00,0x00}, // |
|
||||
{0x22,0x3e,0x08,0x00,0x00,0x00}, // }
|
||||
{0x04,0x02,0x02,0x00,0x00,0x00}, // ~
|
||||
{0x00,0x00,0x00,0x00,0x00,0x00}
|
||||
};
|
||||
|
||||
uint8_t character_widths[96] = {
|
||||
3, 2, 4, 6, 6, 6, 7, 2, 3, 3, 4, 4, 2, 4, 2, 4,
|
||||
6, 3, 5, 5, 6, 5, 6, 6, 6, 6, 2, 2, 4, 4, 4, 5,
|
||||
7, 6, 6, 5, 6, 5, 5, 6, 5, 4, 5, 5, 5, 6, 6, 6,
|
||||
6, 6, 6, 5, 6, 6, 6, 6, 5, 5, 5, 3, 4, 3, 4, 4,
|
||||
3, 6, 6, 5, 6, 5, 5, 6, 5, 4, 5, 5, 5, 6, 6, 6,
|
||||
6, 6, 6, 5, 6, 6, 6, 6, 5, 5, 5, 4, 2, 4, 4, 2
|
||||
};
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
add_library(pico_graphics
|
||||
${CMAKE_CURRENT_LIST_DIR}/types.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/font_data.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/pico_graphics.cpp)
|
||||
${CMAKE_CURRENT_LIST_DIR}/pico_graphics.cpp
|
||||
)
|
||||
|
||||
target_include_directories(pico_graphics INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
target_include_directories(pico_graphics INTERFACE ${CMAKE_CURRENT_LIST_DIR})
|
|
@ -1,9 +1,14 @@
|
|||
#include "pico_graphics.hpp"
|
||||
|
||||
extern uint8_t font_data[96][6];
|
||||
extern uint8_t character_widths[96];
|
||||
|
||||
namespace pimoroni {
|
||||
PicoGraphics::PicoGraphics(uint16_t width, uint16_t height, uint16_t *frame_buffer)
|
||||
: frame_buffer(frame_buffer), bounds(0, 0, width, height), clip(0, 0, width, height) {
|
||||
set_font(&font6);
|
||||
};
|
||||
|
||||
void PicoGraphics::set_font(const Font *font){
|
||||
this->font = font;
|
||||
}
|
||||
|
||||
void PicoGraphics::set_pen(uint8_t r, uint8_t g, uint8_t b) {
|
||||
pen = create_pen(r, g, b);
|
||||
|
@ -106,13 +111,13 @@ namespace pimoroni {
|
|||
|
||||
void PicoGraphics::character(const char c, const Point &p, uint8_t scale) {
|
||||
uint8_t char_index = c - 32;
|
||||
Rect char_bounds(p.x, p.y, character_widths[char_index] * scale, 6 * scale);
|
||||
Rect char_bounds(p.x, p.y, font->widths[char_index] * scale, font->height * scale);
|
||||
|
||||
if(!clip.intersects(char_bounds)) return;
|
||||
|
||||
const uint8_t *d = &font_data[char_index][0];
|
||||
for(uint8_t cx = 0; cx < character_widths[char_index]; cx++) {
|
||||
for(uint8_t cy = 0; cy < 6; cy++) {
|
||||
const uint8_t *d = &font->data[char_index * font->max_width];
|
||||
for(uint8_t cx = 0; cx < font->widths[char_index]; cx++) {
|
||||
for(uint8_t cy = 0; cy < font->height; cy++) {
|
||||
if((1U << cy) & *d) {
|
||||
rectangle(Rect(p.x + (cx * scale), p.y + (cy * scale), scale, scale));
|
||||
}
|
||||
|
@ -136,24 +141,24 @@ namespace pimoroni {
|
|||
|
||||
uint16_t word_width = 0;
|
||||
for(size_t j = i; j < next_space; j++) {
|
||||
word_width += character_widths[t[j] - 32] * scale;
|
||||
word_width += font->widths[t[j] - 32] * scale;
|
||||
}
|
||||
|
||||
// if this word would exceed the wrap limit then
|
||||
// move to the next line
|
||||
if(co != 0 && co + word_width > (uint32_t)wrap) {
|
||||
co = 0;
|
||||
lo += 7 * scale;
|
||||
lo += (font->height + 1) * scale;
|
||||
}
|
||||
|
||||
// draw word
|
||||
for(size_t j = i; j < next_space; j++) {
|
||||
character(t[j], Point(p.x + co, p.y + lo), scale);
|
||||
co += character_widths[t[j] - 32] * scale;
|
||||
co += font->widths[t[j] - 32] * scale;
|
||||
}
|
||||
|
||||
// move character offset to end of word and add a space
|
||||
co += character_widths[0] * scale;
|
||||
co += font->widths[0] * scale;
|
||||
i = next_space + 1;
|
||||
}
|
||||
}
|
||||
|
@ -315,8 +320,8 @@ namespace pimoroni {
|
|||
}else{
|
||||
// steep version
|
||||
int32_t s = std::abs(dy); // number of steps
|
||||
int32_t sy = dy < 0 ? -1 : 1; // x step value
|
||||
int32_t sx = (dx << 16) / s; // y step value in fixed 16:16
|
||||
int32_t sy = dy < 0 ? -1 : 1; // y step value
|
||||
int32_t sx = (dx << 16) / s; // x step value in fixed 16:16
|
||||
int32_t y = p1.y;
|
||||
int32_t x = p1.x << 16;
|
||||
while(s--) {
|
||||
|
@ -326,4 +331,4 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include "font6_data.hpp"
|
||||
|
||||
// a tiny little graphics library for our Pico products
|
||||
// supports only 16-bit (565) RGB framebuffers
|
||||
|
@ -51,10 +52,11 @@ namespace pimoroni {
|
|||
|
||||
Pen pen;
|
||||
|
||||
public:
|
||||
PicoGraphics(uint16_t width, uint16_t height, uint16_t *frame_buffer)
|
||||
: frame_buffer(frame_buffer), bounds(0, 0, width, height), clip(0, 0, width, height) {}
|
||||
const Font *font;
|
||||
|
||||
public:
|
||||
PicoGraphics(uint16_t width, uint16_t height, uint16_t *frame_buffer);
|
||||
void set_font(const Font *font);
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b);
|
||||
void set_pen(Pen p);
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ target_sources(usermod_pico_display INTERFACE
|
|||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7789/st7789.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/types.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/font_data.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_pico_display INTERFACE
|
||||
|
|
|
@ -7,7 +7,6 @@ target_sources(usermod_pico_explorer INTERFACE
|
|||
${CMAKE_CURRENT_LIST_DIR}/../../../drivers/st7789/st7789.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/pico_graphics.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/types.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../libraries/pico_graphics/font_data.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_pico_explorer INTERFACE
|
||||
|
|
Ładowanie…
Reference in New Issue