kopia lustrzana https://github.com/pimoroni/pimoroni-pico
PicoGraphics: Enable thickness for all pens. Document.
rodzic
aed14aca22
commit
83f88c034d
|
@ -50,6 +50,10 @@ namespace pimoroni {
|
|||
}
|
||||
}
|
||||
|
||||
void PicoGraphics::set_thickness(uint t) {
|
||||
thickness = t;
|
||||
}
|
||||
|
||||
void PicoGraphics::set_clip(const Rect &r) {
|
||||
clip = bounds.intersection(r);
|
||||
}
|
||||
|
@ -284,6 +288,24 @@ namespace pimoroni {
|
|||
}
|
||||
|
||||
void PicoGraphics::thick_line(Point p1, Point p2, uint thickness) {
|
||||
// fast horizontal line
|
||||
if(p1.y == p2.y) {
|
||||
int32_t ht = thickness / 2;
|
||||
int32_t start = std::min(p1.x, p2.x);
|
||||
int32_t end = std::max(p1.x, p2.x);
|
||||
rectangle(Rect(start, p1.y - ht, end - start, thickness));
|
||||
return;
|
||||
}
|
||||
|
||||
// fast vertical line
|
||||
if(p1.x == p2.x) {
|
||||
int32_t ht = thickness / 2;
|
||||
int32_t start = std::min(p1.y, p2.y);
|
||||
int32_t length = std::max(p1.y, p2.y) - start;
|
||||
rectangle(Rect(p1.x - ht, start, thickness, length));
|
||||
return;
|
||||
}
|
||||
|
||||
// general purpose line
|
||||
// lines are either "shallow" or "steep" based on whether the x delta
|
||||
// is greater than the y delta
|
||||
|
|
|
@ -251,7 +251,7 @@ namespace pimoroni {
|
|||
virtual void set_pen(uint8_t r, uint8_t g, uint8_t b) = 0;
|
||||
virtual void set_pixel(const Point &p) = 0;
|
||||
virtual void set_pixel_span(const Point &p, uint l) = 0;
|
||||
virtual void set_thickness(uint t) = 0;
|
||||
void set_thickness(uint t);
|
||||
|
||||
virtual int get_palette_size();
|
||||
virtual RGB* get_palette();
|
||||
|
@ -304,7 +304,6 @@ namespace pimoroni {
|
|||
PicoGraphics_Pen1Bit(uint16_t width, uint16_t height, void *frame_buffer);
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override;
|
||||
|
||||
void set_pixel(const Point &p) override;
|
||||
void set_pixel_span(const Point &p, uint l) override;
|
||||
|
@ -321,7 +320,6 @@ namespace pimoroni {
|
|||
PicoGraphics_Pen1BitY(uint16_t width, uint16_t height, void *frame_buffer);
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override;
|
||||
|
||||
void set_pixel(const Point &p) override;
|
||||
void set_pixel_span(const Point &p, uint l) override;
|
||||
|
@ -364,7 +362,6 @@ namespace pimoroni {
|
|||
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override;
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen_hsv(float h, float s, float v) override;
|
||||
|
||||
|
@ -397,7 +394,6 @@ namespace pimoroni {
|
|||
PicoGraphics_PenP4(uint16_t width, uint16_t height, void *frame_buffer);
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override {};
|
||||
int update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen_hsv(float h, float s, float v) override;
|
||||
|
@ -431,7 +427,6 @@ namespace pimoroni {
|
|||
PicoGraphics_PenP8(uint16_t width, uint16_t height, void *frame_buffer);
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override {};
|
||||
int update_pen(uint8_t i, uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen_hsv(float h, float s, float v) override;
|
||||
|
@ -457,7 +452,6 @@ namespace pimoroni {
|
|||
PicoGraphics_PenRGB332(uint16_t width, uint16_t height, void *frame_buffer);
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override {};
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen_hsv(float h, float s, float v) override;
|
||||
void set_pixel(const Point &p) override;
|
||||
|
@ -480,7 +474,6 @@ namespace pimoroni {
|
|||
PicoGraphics_PenRGB565(uint16_t width, uint16_t height, void *frame_buffer);
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override {};
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen_hsv(float h, float s, float v) override;
|
||||
void set_pixel(const Point &p) override;
|
||||
|
@ -497,7 +490,6 @@ namespace pimoroni {
|
|||
PicoGraphics_PenRGB888(uint16_t width, uint16_t height, void *frame_buffer);
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override {};
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen_hsv(float h, float s, float v) override;
|
||||
void set_pixel(const Point &p) override;
|
||||
|
@ -570,7 +562,6 @@ namespace pimoroni {
|
|||
PicoGraphics_PenInky7(uint16_t width, uint16_t height, IDirectDisplayDriver<uint8_t> &direct_display_driver);
|
||||
void set_pen(uint c) override;
|
||||
void set_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
void set_thickness(uint t) override;
|
||||
int create_pen(uint8_t r, uint8_t g, uint8_t b) override;
|
||||
int create_pen_hsv(float h, float s, float v) override;
|
||||
void set_pixel(const Point &p) override;
|
||||
|
|
|
@ -18,10 +18,6 @@ namespace pimoroni {
|
|||
color = std::max(r, std::max(g, b)) >> 4;
|
||||
}
|
||||
|
||||
void PicoGraphics_Pen1Bit::set_thickness(uint t) {
|
||||
thickness = t;
|
||||
}
|
||||
|
||||
void PicoGraphics_Pen1Bit::set_pixel(const Point &p) {
|
||||
// pointer to byte in framebuffer that contains this pixel
|
||||
uint8_t *buf = (uint8_t *)frame_buffer;
|
||||
|
|
|
@ -18,10 +18,6 @@ namespace pimoroni {
|
|||
color = std::max(r, std::max(g, b));
|
||||
}
|
||||
|
||||
void PicoGraphics_Pen1BitY::set_thickness(uint t) {
|
||||
thickness = t;
|
||||
}
|
||||
|
||||
void PicoGraphics_Pen1BitY::set_pixel(const Point &p) {
|
||||
// pointer to byte in framebuffer that contains this pixel
|
||||
uint8_t *buf = (uint8_t *)frame_buffer;
|
||||
|
|
|
@ -44,9 +44,6 @@ namespace pimoroni {
|
|||
int PicoGraphics_Pen3Bit::create_pen_hsv(float h, float s, float v) {
|
||||
return RGB::from_hsv(h, s, v).to_rgb888() | 0x7f000000;
|
||||
}
|
||||
void PicoGraphics_Pen3Bit::set_thickness(uint t) {
|
||||
thickness = t;
|
||||
}
|
||||
void PicoGraphics_Pen3Bit::set_pixel(const Point &p) {
|
||||
if ((color & 0x7f000000) == 0x7f000000) {
|
||||
set_pixel_dither(p, RGB(color));
|
||||
|
|
|
@ -18,9 +18,6 @@ namespace pimoroni {
|
|||
int PicoGraphics_PenInky7::create_pen_hsv(float h, float s, float v) {
|
||||
return RGB::from_hsv(h, s, v).to_rgb888() | 0x7f000000;
|
||||
}
|
||||
void PicoGraphics_PenInky7::set_thickness(uint t) {
|
||||
thickness = t;
|
||||
}
|
||||
void PicoGraphics_PenInky7::set_pixel(const Point &p) {
|
||||
if ((color & 0x7f000000) == 0x7f000000) {
|
||||
set_pixel_dither(p, RGB(color));
|
||||
|
|
|
@ -25,6 +25,7 @@ Pico Graphics replaces the individual drivers for displays- if you're been using
|
|||
- [Get Bounds](#get-bounds)
|
||||
- [Text](#text)
|
||||
- [Changing The Font](#changing-the-font)
|
||||
- [Changing The Thickness](#changing-the-thickness)
|
||||
- [Drawing Text](#drawing-text)
|
||||
- [Basic Shapes](#basic-shapes)
|
||||
- [Line](#line)
|
||||
|
@ -311,6 +312,17 @@ These are aligned horizontally (x) to their left edge, but vertically (y) to the
|
|||
* `serif_italic`
|
||||
* `serif`
|
||||
|
||||
#### Changing The Thickness
|
||||
|
||||
Vector (Hershey) fonts are drawn with individual lines. By default these are 1px thick, making for very thin and typically illegible text.
|
||||
|
||||
To change the thickness of lines used for Vector fonts, use the `set_thickness` method:
|
||||
|
||||
```python
|
||||
display.set_thickness(n)
|
||||
```
|
||||
|
||||
Drawing thick text involves setting a lot more pixels and may slow your drawing down considerably. Be careful how and where you use this.
|
||||
|
||||
#### Drawing Text
|
||||
|
||||
|
@ -373,6 +385,12 @@ display.line(x1, y1, x2, y2)
|
|||
|
||||
The X1/Y1 and X2/Y2 coordinates describe the start and end of the line respectively.
|
||||
|
||||
If you need a thicker line, for an outline or UI elements you can supply a fifth parameter - thickness - like so:
|
||||
|
||||
```python
|
||||
display.line(x1, y1, x2, y2, thickness)
|
||||
```
|
||||
|
||||
#### Circle
|
||||
|
||||
To draw a circle:
|
||||
|
|
|
@ -758,13 +758,6 @@ mp_obj_t ModPicoGraphics_create_pen_hsv(size_t n_args, const mp_obj_t *args) {
|
|||
mp_obj_t ModPicoGraphics_set_thickness(mp_obj_t self_in, mp_obj_t pen) {
|
||||
ModPicoGraphics_obj_t *self = MP_OBJ_TO_PTR2(self_in, ModPicoGraphics_obj_t);
|
||||
|
||||
if(
|
||||
self->graphics->pen_type != PicoGraphics::PEN_1BIT
|
||||
&& self->graphics->pen_type != PicoGraphics::PEN_3BIT
|
||||
&& self->graphics->pen_type != PicoGraphics::PEN_INKY7) {
|
||||
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Thickness not supported!"));
|
||||
}
|
||||
|
||||
self->graphics->set_thickness(mp_obj_get_int(pen));
|
||||
|
||||
return mp_const_none;
|
||||
|
|
Ładowanie…
Reference in New Issue