-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PicoVector 2 text word wrap and transform #1027
Closed
MichaelBell
wants to merge
35
commits into
pimoroni:feature/picovector2-and-layers
from
MichaelBell:feature/pv2-text-wrap
Closed
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
3de60d1
PicoGraphics: Layers.
Gadgetoid d528c6f
PicoGraphics: Support multiple layers in more types.
Gadgetoid 6c136e0
PicoVector: Rewrite around new C pretty-poly.h.
Gadgetoid 6f2d4bf
PicoVector: Rewrite MicroPython bindings.
Gadgetoid da262ac
PicoVector: Suppress errors.
Gadgetoid 0354b8b
PicoVector: Vendor pretty-poly and tweak rotation.
Gadgetoid 27fd61b
PicoVector: Swap rotate translation order.
Gadgetoid 1fe1d3c
PicoVector: alright-fonts bringup.
Gadgetoid 742c2cb
PicoVector: Break things until they work.
Gadgetoid 739c77c
PicoVector: fix pointer arithmatic in af_load_font_file.
Gadgetoid 58dcc62
PicoVector: Fix out of bounds drawing.
Gadgetoid 4698336
PicoVector: render text that doesn't end with a linebreak.
Gadgetoid 8a719c2
PicoVector: C++ basic bringup.
Gadgetoid 94d14ed
PicoVector: Remove alright_fonts.cpp from cmake.
Gadgetoid 031956a
PicoGraphics: Add RGB565 alpha blending support.
Gadgetoid dcc24fd
PicoVector: Fix x16 anti-aliasing.
Gadgetoid 263fe40
PicoGraphics: Add get_clip.
Gadgetoid 7d04ea7
PicoVector: Remove malloc from MicroPython bindings.
Gadgetoid 740e351
PicoVector: Support float types in MicroPython bindings.
Gadgetoid be0d617
PicoVector: Use tile renderer for all pens.
Gadgetoid 6f092a2
PicoVector: Rewrite around new linked-lists poly.
Gadgetoid 841225e
PicoVector: Update C++ examples.
Gadgetoid a123cfa
PicoVector: Big refactor, ppp primitives.
Gadgetoid adb9a1e
PicoGraphics: Add layer support to PicoVector tile renderer.
Gadgetoid 352bd47
PicoVector: Improve text rendering and control.
Gadgetoid 5bc852e
PicoGraphics: RGB565 skip layers if not enabled.
Gadgetoid a292905
PicoVector: Refactor text multiline support.
Gadgetoid 49b496d
PicoVector: Remove (ifdef guard) debug functions.
Gadgetoid 03a8d51
PicoGraphics: Add Presto.
Gadgetoid f2d84fa
Plasma: Add support for GPIOs >=32.
Gadgetoid 96beb08
PicoGraphics: Non-blocking Inky update for #936.
Gadgetoid 225ecfc
PicoVector: Prefix some pretty-poly variables.
Gadgetoid 0425d77
PicoVector: Add optional text max width and max height.
MichaelBell a4adf0d
PicoVector: Apply overall transform to text rendering.
MichaelBell 7a0fb98
PicoVector: Fix C++ example compilation.
MichaelBell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
add_subdirectory(mandelbrot) | ||
|
||
set(OUTPUT_NAME pico_display2_demo) | ||
|
||
add_executable( | ||
${OUTPUT_NAME} | ||
pico_display_2_demo.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(${OUTPUT_NAME} pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 st7789 pico_graphics) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(${OUTPUT_NAME}) | ||
include(pico_display_2_demo.cmake) | ||
include(pico_display_2_vector.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
add_executable( | ||
pico_display_2_demo | ||
pico_display_2_demo.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(pico_display_2_demo pico_stdlib hardware_spi hardware_pwm hardware_dma rgbled button pico_display_2 st7789 pico_graphics) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(pico_display_2_demo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function(static_asset NAME PATH) | ||
get_filename_component(PATH ${PATH} ABSOLUTE) | ||
get_filename_component(ASSET ${PATH} NAME) | ||
get_filename_component(PATH ${PATH} DIRECTORY) | ||
set(OBJNAME ${ASSET}.o) | ||
add_custom_command(OUTPUT ${OBJNAME} | ||
DEPENDS ${PATH}/${ASSET} | ||
COMMENT "Building ${OBJNAME}" | ||
WORKING_DIRECTORY "${PATH}" | ||
COMMAND ${CMAKE_LINKER} -r -b binary -o ${CMAKE_CURRENT_BINARY_DIR}/${OBJNAME} ${ASSET} | ||
COMMAND ${CMAKE_OBJDUMP} -t ${CMAKE_CURRENT_BINARY_DIR}/${OBJNAME} | ||
) | ||
# TODO figure out how to make static resources work | ||
## COMMAND ${CMAKE_OBJCOPY} --rename-section .data=.rodata,alloc,load,readonly,data,contents ${CMAKE_CURRENT_BINARY_DIR}/${OBJNAME} ${CMAKE_CURRENT_BINARY_DIR}/${OBJNAME}) | ||
target_sources(${NAME} PRIVATE ${OBJNAME}) | ||
endfunction() | ||
|
||
add_executable( | ||
pico_display_2_vector | ||
pico_display_2_vector.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(pico_display_2_vector | ||
pico_stdlib | ||
hardware_spi | ||
hardware_pwm | ||
hardware_dma | ||
pico_display_2 | ||
st7789 | ||
pico_graphics | ||
pico_vector | ||
) | ||
|
||
static_asset(pico_display_2_vector ${CMAKE_CURRENT_LIST_DIR}/vector/DynaPuff-Medium.af) | ||
|
||
pico_enable_stdio_usb(pico_display_2_vector 0) | ||
pico_enable_stdio_uart(pico_display_2_vector 1) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(pico_display_2_vector) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include <string.h> | ||
#include <math.h> | ||
#include <vector> | ||
#include <cstdlib> | ||
|
||
#include "libraries/pico_display_2/pico_display_2.hpp" | ||
#include "drivers/st7789/st7789.hpp" | ||
#include "libraries/pico_graphics/pico_graphics.hpp" | ||
#include "libraries/pico_vector/pico_vector.hpp" | ||
|
||
|
||
using namespace pimoroni; | ||
|
||
ST7789 st7789(320, 240, ROTATE_180, false, get_spi_pins(BG_SPI_FRONT)); | ||
PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); | ||
|
||
uint8_t vector_mem[PicoVector::pretty_poly_buffer_size()]; | ||
|
||
PicoVector vector(&graphics); | ||
|
||
extern char _binary_DynaPuff_Medium_af_start[]; | ||
extern size_t _binary_DynaPuff_Medium_af_size; | ||
|
||
int main() { | ||
stdio_init_all(); | ||
|
||
Pen BG = graphics.create_pen(120, 40, 60); | ||
Pen TEXT = graphics.create_pen(255, 255, 255); | ||
|
||
st7789.set_backlight(255); | ||
|
||
vector.set_font(_binary_DynaPuff_Medium_af_start, 30); | ||
|
||
unsigned int a = 0; | ||
|
||
while (true) { | ||
Point text_location(0, 0); | ||
graphics.set_pen(BG); | ||
graphics.clear(); | ||
graphics.set_pen(TEXT); | ||
graphics.text("Hello World", text_location, 320); | ||
|
||
pp_point_t outline[] = {{-64, -64}, {64, -64}, {64, 64}, {-64, 64}}; | ||
pp_point_t hole[] = {{ -32, 32}, { 32, 32}, { 32, -32}, { -32, -32}}; | ||
|
||
pp_poly_t *poly = pp_poly_new(); | ||
pp_path_add_points(pp_poly_add_path(poly), outline, sizeof(outline) / sizeof(pp_point_t)); | ||
pp_path_add_points(pp_poly_add_path(poly), hole, sizeof(hole) / sizeof(pp_point_t)); | ||
|
||
pp_mat3_t pos = pp_mat3_identity(); | ||
pp_mat3_translate(&pos, 50, 50); | ||
pp_mat3_rotate(&pos, a); | ||
vector.draw(poly); | ||
vector.text("Hello World", 0, 0, &pos); | ||
|
||
// update screen | ||
st7789.update(&graphics); | ||
a += 1; | ||
if (a > 359) { | ||
a = 0; | ||
} | ||
|
||
pp_poly_free(poly); | ||
} | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include(pico_w_explorer_vector.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
add_executable( | ||
pico_w_explorer_vector | ||
pico_w_explorer_vector.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(pico_w_explorer_vector pico_stdlib pico_graphics pico_vector st7789) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(pico_w_explorer_vector) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <string.h> | ||
#include <math.h> | ||
#include <vector> | ||
#include <cstdlib> | ||
|
||
#include "drivers/st7789/st7789.hpp" | ||
#include "libraries/pico_graphics/pico_graphics.hpp" | ||
#include "libraries/pico_vector/pico_vector.hpp" | ||
|
||
using namespace pimoroni; | ||
|
||
|
||
ST7789 st7789(320, 240, ROTATE_0, false, {PIMORONI_SPI_DEFAULT_INSTANCE, 17, SPI_DEFAULT_SCK, SPI_DEFAULT_MOSI, PIN_UNUSED, SPI_DEFAULT_MISO, 9}); | ||
PicoGraphics_PenRGB332 graphics(st7789.width, st7789.height, nullptr); | ||
PicoVector vector(&graphics); | ||
|
||
int main() { | ||
st7789.set_backlight(255); | ||
|
||
Pen WHITE = graphics.create_pen(255, 255, 255); | ||
Pen BLACK = graphics.create_pen(0, 0, 0); | ||
|
||
float angle = 0.0f; | ||
|
||
while(true) { | ||
graphics.set_pen(BLACK); | ||
graphics.clear(); | ||
|
||
graphics.set_pen(WHITE); | ||
graphics.text("Hello World", Point(0, 0), 320); | ||
|
||
pp_point_t outline[] = {{-128, -128}, {128, -128}, {128, 128}, {-128, 128}}; | ||
pp_point_t hole[] = {{ -64, 64}, { 64, 64}, { 64, -64}, { -64, -64}}; | ||
|
||
pp_poly_t *poly = pp_poly_new(); | ||
pp_path_add_points(pp_poly_add_path(poly), outline, sizeof(outline) / sizeof(pp_point_t)); | ||
pp_path_add_points(pp_poly_add_path(poly), hole, sizeof(hole) / sizeof(pp_point_t)); | ||
|
||
vector.rotate(poly, {0, 0}, angle); | ||
vector.translate(poly, {160, 120}); | ||
|
||
vector.draw(poly); | ||
|
||
pp_mat3_t t = pp_mat3_identity(); | ||
vector.text("Hello World", 0, 0, &t); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly uncommenting this was unwise as I don't have one of these to test. I got confused between this and the new RP2350 based explorer 😆 |
||
|
||
// update screen | ||
st7789.update(&graphics); | ||
|
||
angle += 1.0f; | ||
|
||
pp_poly_free(poly); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively could make these optional arguments if you prefer - I had kind of forgotten that this was also exposed to C++.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to make these optional, since it also bubbles up to Python. C isn't super helpful about that, though. I wonder if it makes sense to have them part of the text metrics, or if that's just too conceptually weird.
Sensible API design for this has been quite tricky!