Foundation classes for a basic GUI implementing simple widgets and events

Dependents:   TouchScreenGUIDemo

Committer:
duncanFrance
Date:
Sat May 28 14:50:14 2016 +0000
Revision:
18:d849f3ada858
Parent:
8:a460cabc85ac
Moved the event queue into the EventDispatcher; Improved event handling across Window/Widget

Who changed what in which revision?

UserRevisionLine numberNew contents of line
duncanFrance 7:303850a4b30c 1
duncanFrance 7:303850a4b30c 2 #include "FastFont.h"
duncanFrance 7:303850a4b30c 3
duncanFrance 7:303850a4b30c 4 FastFont::FastFont(uint8_t* fastFont)
duncanFrance 7:303850a4b30c 5 : _font(fastFont)
duncanFrance 7:303850a4b30c 6 {
duncanFrance 7:303850a4b30c 7 _totalBytesPerGlyph = dataBytesPerGlyph() + 1;
duncanFrance 7:303850a4b30c 8 _bytesPerRow = dataBytesPerGlyph() / height();
duncanFrance 7:303850a4b30c 9 }
duncanFrance 7:303850a4b30c 10
duncanFrance 7:303850a4b30c 11 /***************************************
duncanFrance 7:303850a4b30c 12 * Implementation of the Font interface
duncanFrance 7:303850a4b30c 13 ***************************************/
duncanFrance 7:303850a4b30c 14 uint8_t FastFont::firstAscii()
duncanFrance 7:303850a4b30c 15 {
duncanFrance 7:303850a4b30c 16 return _font[FAST_FONT_FIRST_ASCII];
duncanFrance 7:303850a4b30c 17 }
duncanFrance 7:303850a4b30c 18
duncanFrance 7:303850a4b30c 19 uint8_t FastFont::lastAscii()
duncanFrance 7:303850a4b30c 20 {
duncanFrance 7:303850a4b30c 21 return _font[FAST_FONT_LAST_ASCII];
duncanFrance 7:303850a4b30c 22 }
duncanFrance 7:303850a4b30c 23
duncanFrance 7:303850a4b30c 24 /**
duncanFrance 7:303850a4b30c 25 * The unzoomed width of the character. Includes a following pixel
duncanFrance 7:303850a4b30c 26 **/
duncanFrance 7:303850a4b30c 27 uint8_t FastFont::widthOf(char c)
duncanFrance 7:303850a4b30c 28 {
duncanFrance 7:303850a4b30c 29 if(c < _font[FAST_FONT_FIRST_ASCII] || c > _font[FAST_FONT_LAST_ASCII]) {
duncanFrance 7:303850a4b30c 30 return 0;
duncanFrance 7:303850a4b30c 31 }
duncanFrance 7:303850a4b30c 32
duncanFrance 7:303850a4b30c 33 return _font[FAST_FONT_DATA + ((c - _font[FAST_FONT_FIRST_ASCII]) * _totalBytesPerGlyph)];
duncanFrance 7:303850a4b30c 34 }
duncanFrance 7:303850a4b30c 35
duncanFrance 7:303850a4b30c 36 uint8_t FastFont::zoomedWidthOf(char c) {
duncanFrance 7:303850a4b30c 37 return (widthOf(c) * _zoomX);
duncanFrance 7:303850a4b30c 38 }
duncanFrance 7:303850a4b30c 39
duncanFrance 7:303850a4b30c 40 /**
duncanFrance 7:303850a4b30c 41 * The unzoomed height of a character
duncanFrance 7:303850a4b30c 42 **/
duncanFrance 7:303850a4b30c 43 uint8_t FastFont::height()
duncanFrance 7:303850a4b30c 44 {
duncanFrance 7:303850a4b30c 45 return _font[FAST_FONT_HEIGHT];
duncanFrance 7:303850a4b30c 46 }
duncanFrance 7:303850a4b30c 47
duncanFrance 7:303850a4b30c 48 uint8_t FastFont::zoomedHeight()
duncanFrance 7:303850a4b30c 49 {
duncanFrance 7:303850a4b30c 50 return _zoomY * _font[FAST_FONT_HEIGHT];
duncanFrance 7:303850a4b30c 51 }
duncanFrance 7:303850a4b30c 52
duncanFrance 7:303850a4b30c 53 bool FastFont::isProportional()
duncanFrance 7:303850a4b30c 54 {
duncanFrance 7:303850a4b30c 55 return _font[FAST_FONT_PROPORTIONAL];
duncanFrance 7:303850a4b30c 56 }
duncanFrance 7:303850a4b30c 57
duncanFrance 7:303850a4b30c 58
duncanFrance 7:303850a4b30c 59 /***************************************
duncanFrance 7:303850a4b30c 60 * Custom methods for this class
duncanFrance 7:303850a4b30c 61 ***************************************/
duncanFrance 7:303850a4b30c 62
duncanFrance 7:303850a4b30c 63 uint8_t FastFont::totalBytesPerGlyph()
duncanFrance 7:303850a4b30c 64 {
duncanFrance 7:303850a4b30c 65 return _totalBytesPerGlyph;
duncanFrance 7:303850a4b30c 66 }
duncanFrance 7:303850a4b30c 67
duncanFrance 7:303850a4b30c 68
duncanFrance 7:303850a4b30c 69 uint8_t FastFont::dataBytesPerGlyph()
duncanFrance 7:303850a4b30c 70 {
duncanFrance 7:303850a4b30c 71 return _font[FAST_FONT_DATA_BYTES_PER_GLYPH];
duncanFrance 7:303850a4b30c 72 }
duncanFrance 7:303850a4b30c 73
duncanFrance 7:303850a4b30c 74 uint8_t FastFont::bytesPerRow()
duncanFrance 7:303850a4b30c 75 {
duncanFrance 7:303850a4b30c 76 return _bytesPerRow;
duncanFrance 7:303850a4b30c 77 }
duncanFrance 7:303850a4b30c 78
duncanFrance 7:303850a4b30c 79 uint8_t* FastFont::glyph(char c)
duncanFrance 7:303850a4b30c 80 {
duncanFrance 7:303850a4b30c 81 if(c < _font[FAST_FONT_FIRST_ASCII] || c > _font[FAST_FONT_LAST_ASCII]) {
duncanFrance 7:303850a4b30c 82 return 0;
duncanFrance 7:303850a4b30c 83 }
duncanFrance 7:303850a4b30c 84
duncanFrance 7:303850a4b30c 85 return _font + FAST_FONT_DATA + ((c - _font[FAST_FONT_FIRST_ASCII]) * _totalBytesPerGlyph) + 1;
duncanFrance 7:303850a4b30c 86 }