Added methods and features

Fork of SPI_TFT_ILI9341 by Peter Drescher

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GraphicsDisplay.cpp Source File

GraphicsDisplay.cpp

00001 /* mbed GraphicsDisplay Display Library Base Class
00002  * Copyright (c) 2007-2009 sford
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005  
00006 #include "GraphicsDisplay.h"
00007 
00008 const unsigned char FONT8x8[97][8] = {
00009 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
00010 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
00011 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
00012 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
00013 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
00014 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
00015 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
00016 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
00017 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
00018 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
00019 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
00020 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
00021 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
00022 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
00023 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
00024 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
00025 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
00026 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
00027 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
00028 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
00029 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
00030 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
00031 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
00032 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
00033 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
00034 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
00035 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
00036 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
00037 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
00038 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
00039 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
00040 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
00041 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
00042 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
00043 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
00044 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
00045 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
00046 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
00047 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
00048 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
00049 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
00050 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
00051 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
00052 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
00053 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
00054 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
00055 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
00056 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
00057 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
00058 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
00059 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
00060 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
00061 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
00062 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
00063 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
00064 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
00065 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
00066 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
00067 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
00068 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
00069 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
00070 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
00071 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
00072 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
00073 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
00074 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
00075 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
00076 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
00077 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
00078 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
00079 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
00080 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
00081 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
00082 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
00083 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
00084 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
00085 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
00086 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
00087 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
00088 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
00089 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
00090 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
00091 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
00092 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
00093 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
00094 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
00095 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
00096 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
00097 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
00098 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
00099 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
00100 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
00101 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
00102 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
00103 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
00104 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
00105 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
00106 
00107     
00108 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
00109     foreground(0xFFFF);
00110     background(0x0000);
00111 }
00112     
00113 void GraphicsDisplay::character(int column, int row, int value) { 
00114     blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
00115 }
00116 
00117 void GraphicsDisplay::window(unsigned int x, unsigned int y, unsigned int w, unsigned  int h) {
00118     // current pixel location
00119     _x = x;
00120     _y = y;
00121     // window settings
00122     _x1 = x;
00123     _x2 = x + w - 1;
00124     _y1 = y;
00125     _y2 = y + h - 1;
00126 }
00127     
00128 void GraphicsDisplay::putp(int colour) {
00129     // put pixel at current pixel location
00130     pixel(_x, _y, colour);
00131     // update pixel location based on window settings
00132     _x++;
00133     if(_x > _x2) {
00134         _x = _x1;
00135         _y++;
00136         if(_y > _y2) {
00137             _y = _y1;
00138         }
00139     }
00140 }
00141 
00142 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { 
00143     int pixels = w*h;
00144     
00145     window(x, y, w, h);
00146     for(int i=0; i<pixels; i++) {
00147         putp(colour);
00148     }
00149 }
00150     
00151 void GraphicsDisplay::cls() {
00152     fill(0, 0, width(), height(), _background);
00153 }
00154     
00155 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { 
00156     int pixels = w*h;
00157     
00158     window(x, y, w, h);
00159     for(int i=0; i<pixels; i++) {
00160         putp(colour[i]);
00161     }
00162 }
00163     
00164 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
00165     int pixels = w*h;
00166         
00167     window(x, y, w, h);
00168     for(int i = 0; i < pixels; i++) {
00169         char byte = colour[i >> 3];
00170         int offset = i & 0x7;
00171         int c = ((byte << offset) & 0x80) ? _foreground : _background;
00172         putp(c);
00173     }
00174 }
00175     
00176 int GraphicsDisplay::columns() { 
00177     return width() / 8; 
00178 }
00179 
00180 int GraphicsDisplay::rows() { 
00181     return height() / 8; 
00182 }
00183