Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RadarDemo 3DDemo RadarDemoT
Revision 3:1ddc4aa1e5cb, committed 2016-11-11
- Comitter:
- karpent
- Date:
- Fri Nov 11 12:05:16 2016 +0000
- Parent:
- 2:02b7b78e8510
- Commit message:
- Missing method DrawChar() added, DrawText() corrected.
Changed in this revision
| Canvas.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Canvas.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Canvas.cpp Thu Nov 10 15:34:43 2016 +0000
+++ b/Canvas.cpp Fri Nov 11 12:05:16 2016 +0000
@@ -141,24 +141,39 @@
}
+void Canvas::DrawChar(int posX, int posY, char ch)
+{
+ if (ch < 32)
+ return;
+
+ const sFONT *font = _selectedFont.GetSystemFont();
+ const uint8_t rowLen = font->Width/8 + 1;
+ const uint8_t *pByte = font->table + (ch-32) * font->Height * rowLen;
+
+ for (int rowY = 0; rowY < font->Height; rowY++) {
+ for (int bx = 0; bx < rowLen; bx++) {
+ for (int shift = 0; shift < 8; shift++) {
+ DrawPoint(
+ posX + bx * 8 + shift,
+ posY + rowY,
+ *pByte & (0x80 >> shift)
+ );
+ }
+
+ // Get next byte
+ pByte++;
+ }
+ }
+}
+
+
void Canvas::DrawText(int posX, int posY, char * str)
{
- const uint8_t *table = _selectedFont.GetSystemFont()->table;
-
// Draw text horizontaly
- int fontWidth = _selectedFont.Width();
- int fontHeight = _selectedFont.Height();
int x = posX;
- uint8_t charLineBytesCount = 1 + fontWidth / 8;
- //uint8_t charDataLen = fontHeight * charLineBytesCount;
-
- for(int i=0; i < strlen(str); i++) {
- int y = posY;
-
- // TODO: Draw character
- DrawPoint(x, y, _drawColor);
-
- x += fontWidth;
+ for (int i = 0; i < strlen(str); i++) {
+ DrawChar(x, posY, str[i]);
+ x += _selectedFont.GetSystemFont()->Width;
}
}
--- a/Canvas.h Thu Nov 10 15:34:43 2016 +0000
+++ b/Canvas.h Fri Nov 11 12:05:16 2016 +0000
@@ -128,6 +128,14 @@
bool IsSet();
/// <summary>
+ /// Draws single character using actual font type and size.
+ /// </summary>
+ /// <param name="posX">The position x.</param>
+ /// <param name="posY">The position y.</param>
+ /// <param name="ch">The character.</param>
+ void DrawChar(int posX, int posY, char ch);
+
+ /// <summary>
/// Draws the text using actual font type and size.
/// </summary>
/// <param name="posX">The position x.</param>
@@ -137,7 +145,7 @@
private:
/// <summary>
- /// Resets this instance.
+ /// Resets canvas properties.
/// </summary>
void Reset();