mirror of
https://github.com/Hopiu/rpi-rgb-led-matrix.git
synced 2026-03-16 22:10:27 +00:00
o minor style issues.
This commit is contained in:
parent
d7fd1fb561
commit
90283819e5
3 changed files with 27 additions and 20 deletions
|
|
@ -40,16 +40,20 @@ public:
|
|||
// does not exist.
|
||||
int CharacterWidth(uint32_t unicode_codepoint) const;
|
||||
|
||||
// Draws the unicode character at position "x","y" with "color". The "y"
|
||||
// position is the baseline of the font.
|
||||
// Draws the unicode character at position "x","y"
|
||||
// with "color" on "background_color" (background_color can be NULL for
|
||||
// transparency.
|
||||
// The "y" position is the baseline of the font.
|
||||
// If we don't have it in the font, draws the replacement character "<22>" if
|
||||
// available.
|
||||
// Returns how much we advance on the screen, which is the width of the
|
||||
// character or 0 if we didn't draw any chracter.
|
||||
int DrawGlyph(Canvas *c, int x, int y, const Color &color,
|
||||
int DrawGlyph(Canvas *c, int x, int y,
|
||||
const Color &color, const Color *background_color,
|
||||
uint32_t unicode_codepoint) const;
|
||||
// Background is untouched if null.
|
||||
int DrawGlyph(Canvas *c, int x, int y, const Color &color, const Color *background,
|
||||
|
||||
// Same without background. Deprecated, use the one above instead.
|
||||
int DrawGlyph(Canvas *c, int x, int y, const Color &color,
|
||||
uint32_t unicode_codepoint) const;
|
||||
private:
|
||||
Font(const Font& x); // No copy constructor. Use references or pointer instead.
|
||||
|
|
@ -67,11 +71,14 @@ private:
|
|||
// -- Some utility functions.
|
||||
|
||||
// Draw text, encoded in UTF-8, with given "font" at "x","y" with "color".
|
||||
// "background_color" can be NULL for transparency.
|
||||
// Returns how far we advance on the screen.
|
||||
int DrawText(Canvas *c, const Font &font, int x, int y, const Color &color,
|
||||
int DrawText(Canvas *c, const Font &font, int x, int y,
|
||||
const Color &color, const Color *background_color,
|
||||
const char *utf8_text);
|
||||
// Background is untouched if null.
|
||||
int DrawText(Canvas *c, const Font &font, int x, int y, const Color &color, const Color *background,
|
||||
|
||||
// Same without background. Deprecated, use the one above instead.
|
||||
int DrawText(Canvas *c, const Font &font, int x, int y, const Color &color,
|
||||
const char *utf8_text);
|
||||
|
||||
// Draw a circle centered at "x", "y", with a radius of "radius" and with "color"
|
||||
|
|
|
|||
|
|
@ -106,7 +106,8 @@ int Font::CharacterWidth(uint32_t unicode_codepoint) const {
|
|||
return g ? g->width : -1;
|
||||
}
|
||||
|
||||
int Font::DrawGlyph(Canvas *c, int x_pos, int y_pos, const Color &color, const Color *background,
|
||||
int Font::DrawGlyph(Canvas *c, int x_pos, int y_pos,
|
||||
const Color &color, const Color *bgcolor,
|
||||
uint32_t unicode_codepoint) const {
|
||||
const Glyph *g = FindGlyph(unicode_codepoint);
|
||||
if (g == NULL) g = FindGlyph(kUnicodeReplacementCodepoint);
|
||||
|
|
@ -118,9 +119,8 @@ int Font::DrawGlyph(Canvas *c, int x_pos, int y_pos, const Color &color, const C
|
|||
for (int x = 0; x < g->width; ++x, x_mask >>= 1) {
|
||||
if (row & x_mask) {
|
||||
c->SetPixel(x_pos + x, y_pos + y, color.r, color.g, color.b);
|
||||
} else {
|
||||
if (background)
|
||||
c->SetPixel(x_pos + x, y_pos + y, background->r, background->g, background->b);
|
||||
} else if (bgcolor) {
|
||||
c->SetPixel(x_pos + x, y_pos + y, bgcolor->r, bgcolor->g, bgcolor->b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,21 +26,21 @@ int DrawText(Canvas *c, const Font &font,
|
|||
}
|
||||
|
||||
int DrawText(Canvas *c, const Font &font,
|
||||
int x, int y, const Color &color, const Color *background,
|
||||
int x, int y, const Color &color, const Color *background_color,
|
||||
const char *utf8_text) {
|
||||
const int start_x = x;
|
||||
while (*utf8_text) {
|
||||
const uint32_t cp = utf8_next_codepoint(utf8_text);
|
||||
x += font.DrawGlyph(c, x, y, color, background, cp);
|
||||
x += font.DrawGlyph(c, x, y, color, background_color, cp);
|
||||
}
|
||||
return x - start_x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DrawCircle(Canvas *c, int x0, int y0, int radius, const Color &color) {
|
||||
int x = radius, y = 0;
|
||||
int radiusError = 1 - x;
|
||||
|
||||
|
||||
while (y <= x) {
|
||||
c->SetPixel(x + x0, y + y0, color.r, color.g, color.b);
|
||||
c->SetPixel(y + x0, x + y0, color.r, color.g, color.b);
|
||||
|
|
@ -59,10 +59,10 @@ void DrawCircle(Canvas *c, int x0, int y0, int radius, const Color &color) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DrawLine(Canvas *c, int x0, int y0, int x1, int y1, const Color &color) {
|
||||
int dy = y1 - y0, dx = x1 - x0, gradient, x, y, shift = 0x10;
|
||||
|
||||
|
||||
if (abs(dx) > abs(dy)) {
|
||||
// x variation is bigger than y variation
|
||||
if (x1 < x0) {
|
||||
|
|
@ -70,7 +70,7 @@ void DrawLine(Canvas *c, int x0, int y0, int x1, int y1, const Color &color) {
|
|||
std::swap(y0, y1);
|
||||
}
|
||||
gradient = (dy << shift) / dx ;
|
||||
|
||||
|
||||
for (x = x0 , y = 0x8000 + (y0 << shift); x <= x1; ++x, y += gradient) {
|
||||
c->SetPixel(x, y >> shift, color.r, color.g, color.b);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue