Subversion Repositories libOLED

Rev

Rev 5 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "libOLED/displayclass.H"
  2.  
  3. void
  4. display_t::printString (font_t &font, char const *string, uint16_t length,
  5.                         colour_t colour)
  6. {
  7.   uint16_t const xSpacing = font.width () + 1;
  8.   for (uint16_t yt = 0; yt < font.height (); yt++) // iterate down scan lines
  9.     {
  10.       uint16_t ys = m_cursor_y + yt;
  11.       for (uint16_t xt = 0; xt < length; xt++)
  12.         {
  13.           unsigned char c = string[xt];
  14.           uint16_t xs = xt * xSpacing + m_cursor_x;
  15.           for (uint16_t j = 0; j < font.spacing (); j++)
  16.             {
  17.               if (font.getPixel (c, j, yt) != 0)
  18.                 drawPixel (j + xs, ys, colour);
  19.             }
  20.         }
  21.     }
  22.   // move the cursor.
  23.   m_cursor_x += xSpacing * length;
  24. }
  25.  
  26. // scale is multiplied by 256
  27. void
  28. display_t::printScaledString (font_t &font, char const *string,
  29.                                 uint16_t length, uint16_t scale,
  30.                                 colour_t colour)
  31. {
  32.   uint16_t xt, yt, jt, curr_x=0;
  33.   uint16_t curr_y = m_cursor_y;
  34.   if (scale < 1)
  35.     return;
  36.   for (yt = 0; yt < font.height () * 256; yt += scale) // iterate down scan lines
  37.     {
  38.       // iterate along the string
  39.       // local x plotting coordinate
  40.       curr_x = m_cursor_x;
  41.       for (xt = 0; xt < length; xt++)
  42.         {
  43.           for (jt = 0; jt < (font.spacing ()) * 256; jt += scale)
  44.             {
  45.               unsigned char c = (string[xt]);
  46.               if (font.getPixel (c, jt / 256, yt / 256))
  47.                 drawPixel (curr_x, curr_y, colour);
  48.               curr_x++;
  49.             }
  50.         }
  51.       curr_y++;
  52.     }
  53.   if (curr_x > width ())
  54.     {
  55.       curr_x = 0;
  56.     }
  57.   m_cursor_x = curr_x;
  58. }
  59.  
  60.