SToppuhr
GraphicsDisplay.cpp@0:862a4d510e20, 2015-12-17 (annotated)
- Committer:
- Lippi
- Date:
- Thu Dec 17 20:11:56 2015 +0000
- Revision:
- 0:862a4d510e20
Tinf Stoppuhr
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lippi | 0:862a4d510e20 | 1 | /* mbed GraphicsDisplay Display Library Base Class |
Lippi | 0:862a4d510e20 | 2 | * Copyright (c) 2007-2009 sford |
Lippi | 0:862a4d510e20 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
Lippi | 0:862a4d510e20 | 4 | */ |
Lippi | 0:862a4d510e20 | 5 | |
Lippi | 0:862a4d510e20 | 6 | #include "GraphicsDisplay.h" |
Lippi | 0:862a4d510e20 | 7 | |
Lippi | 0:862a4d510e20 | 8 | const unsigned char FONT8x8[97][8] = { |
Lippi | 0:862a4d510e20 | 9 | 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char |
Lippi | 0:862a4d510e20 | 10 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 |
Lippi | 0:862a4d510e20 | 11 | 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // ! |
Lippi | 0:862a4d510e20 | 12 | 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // " |
Lippi | 0:862a4d510e20 | 13 | 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // # |
Lippi | 0:862a4d510e20 | 14 | 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $ |
Lippi | 0:862a4d510e20 | 15 | 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // % |
Lippi | 0:862a4d510e20 | 16 | 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // & |
Lippi | 0:862a4d510e20 | 17 | 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // ' |
Lippi | 0:862a4d510e20 | 18 | 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // ( |
Lippi | 0:862a4d510e20 | 19 | 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // ) |
Lippi | 0:862a4d510e20 | 20 | 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // * |
Lippi | 0:862a4d510e20 | 21 | 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // + |
Lippi | 0:862a4d510e20 | 22 | 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // , |
Lippi | 0:862a4d510e20 | 23 | 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // - |
Lippi | 0:862a4d510e20 | 24 | 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // . |
Lippi | 0:862a4d510e20 | 25 | 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash) |
Lippi | 0:862a4d510e20 | 26 | 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30 |
Lippi | 0:862a4d510e20 | 27 | 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1 |
Lippi | 0:862a4d510e20 | 28 | 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2 |
Lippi | 0:862a4d510e20 | 29 | 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3 |
Lippi | 0:862a4d510e20 | 30 | 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4 |
Lippi | 0:862a4d510e20 | 31 | 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5 |
Lippi | 0:862a4d510e20 | 32 | 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6 |
Lippi | 0:862a4d510e20 | 33 | 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7 |
Lippi | 0:862a4d510e20 | 34 | 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8 |
Lippi | 0:862a4d510e20 | 35 | 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9 |
Lippi | 0:862a4d510e20 | 36 | 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // : |
Lippi | 0:862a4d510e20 | 37 | 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ; |
Lippi | 0:862a4d510e20 | 38 | 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // < |
Lippi | 0:862a4d510e20 | 39 | 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // = |
Lippi | 0:862a4d510e20 | 40 | 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // > |
Lippi | 0:862a4d510e20 | 41 | 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ? |
Lippi | 0:862a4d510e20 | 42 | 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40 |
Lippi | 0:862a4d510e20 | 43 | 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A |
Lippi | 0:862a4d510e20 | 44 | 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B |
Lippi | 0:862a4d510e20 | 45 | 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C |
Lippi | 0:862a4d510e20 | 46 | 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D |
Lippi | 0:862a4d510e20 | 47 | 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E |
Lippi | 0:862a4d510e20 | 48 | 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F |
Lippi | 0:862a4d510e20 | 49 | 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G |
Lippi | 0:862a4d510e20 | 50 | 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H |
Lippi | 0:862a4d510e20 | 51 | 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I |
Lippi | 0:862a4d510e20 | 52 | 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J |
Lippi | 0:862a4d510e20 | 53 | 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K |
Lippi | 0:862a4d510e20 | 54 | 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L |
Lippi | 0:862a4d510e20 | 55 | 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M |
Lippi | 0:862a4d510e20 | 56 | 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N |
Lippi | 0:862a4d510e20 | 57 | 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O |
Lippi | 0:862a4d510e20 | 58 | 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50 |
Lippi | 0:862a4d510e20 | 59 | 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q |
Lippi | 0:862a4d510e20 | 60 | 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R |
Lippi | 0:862a4d510e20 | 61 | 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S |
Lippi | 0:862a4d510e20 | 62 | 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T |
Lippi | 0:862a4d510e20 | 63 | 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U |
Lippi | 0:862a4d510e20 | 64 | 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V |
Lippi | 0:862a4d510e20 | 65 | 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W |
Lippi | 0:862a4d510e20 | 66 | 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X |
Lippi | 0:862a4d510e20 | 67 | 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y |
Lippi | 0:862a4d510e20 | 68 | 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z |
Lippi | 0:862a4d510e20 | 69 | 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [ |
Lippi | 0:862a4d510e20 | 70 | 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash) |
Lippi | 0:862a4d510e20 | 71 | 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ] |
Lippi | 0:862a4d510e20 | 72 | 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^ |
Lippi | 0:862a4d510e20 | 73 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _ |
Lippi | 0:862a4d510e20 | 74 | 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60 |
Lippi | 0:862a4d510e20 | 75 | 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a |
Lippi | 0:862a4d510e20 | 76 | 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b |
Lippi | 0:862a4d510e20 | 77 | 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c |
Lippi | 0:862a4d510e20 | 78 | 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d |
Lippi | 0:862a4d510e20 | 79 | 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e |
Lippi | 0:862a4d510e20 | 80 | 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f |
Lippi | 0:862a4d510e20 | 81 | 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g |
Lippi | 0:862a4d510e20 | 82 | 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h |
Lippi | 0:862a4d510e20 | 83 | 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i |
Lippi | 0:862a4d510e20 | 84 | 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j |
Lippi | 0:862a4d510e20 | 85 | 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k |
Lippi | 0:862a4d510e20 | 86 | 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l |
Lippi | 0:862a4d510e20 | 87 | 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m |
Lippi | 0:862a4d510e20 | 88 | 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n |
Lippi | 0:862a4d510e20 | 89 | 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o |
Lippi | 0:862a4d510e20 | 90 | 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p |
Lippi | 0:862a4d510e20 | 91 | 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q |
Lippi | 0:862a4d510e20 | 92 | 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r |
Lippi | 0:862a4d510e20 | 93 | 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s |
Lippi | 0:862a4d510e20 | 94 | 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t |
Lippi | 0:862a4d510e20 | 95 | 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u |
Lippi | 0:862a4d510e20 | 96 | 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v |
Lippi | 0:862a4d510e20 | 97 | 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w |
Lippi | 0:862a4d510e20 | 98 | 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x |
Lippi | 0:862a4d510e20 | 99 | 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y |
Lippi | 0:862a4d510e20 | 100 | 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z |
Lippi | 0:862a4d510e20 | 101 | 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // { |
Lippi | 0:862a4d510e20 | 102 | 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // | |
Lippi | 0:862a4d510e20 | 103 | 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } |
Lippi | 0:862a4d510e20 | 104 | 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ |
Lippi | 0:862a4d510e20 | 105 | 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL |
Lippi | 0:862a4d510e20 | 106 | |
Lippi | 0:862a4d510e20 | 107 | GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) { |
Lippi | 0:862a4d510e20 | 108 | foreground(0xFFFF); |
Lippi | 0:862a4d510e20 | 109 | background(0x0000); |
Lippi | 0:862a4d510e20 | 110 | } |
Lippi | 0:862a4d510e20 | 111 | |
Lippi | 0:862a4d510e20 | 112 | void GraphicsDisplay::character(int column, int row, int value) { |
Lippi | 0:862a4d510e20 | 113 | blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0])); |
Lippi | 0:862a4d510e20 | 114 | } |
Lippi | 0:862a4d510e20 | 115 | |
Lippi | 0:862a4d510e20 | 116 | void GraphicsDisplay::window(int x, int y, int w, int h) { |
Lippi | 0:862a4d510e20 | 117 | // current pixel location |
Lippi | 0:862a4d510e20 | 118 | _x = x; |
Lippi | 0:862a4d510e20 | 119 | _y = y; |
Lippi | 0:862a4d510e20 | 120 | // window settings |
Lippi | 0:862a4d510e20 | 121 | _x1 = x; |
Lippi | 0:862a4d510e20 | 122 | _x2 = x + w - 1; |
Lippi | 0:862a4d510e20 | 123 | _y1 = y; |
Lippi | 0:862a4d510e20 | 124 | _y2 = y + h - 1; |
Lippi | 0:862a4d510e20 | 125 | } |
Lippi | 0:862a4d510e20 | 126 | |
Lippi | 0:862a4d510e20 | 127 | void GraphicsDisplay::putp(int colour) { |
Lippi | 0:862a4d510e20 | 128 | // put pixel at current pixel location |
Lippi | 0:862a4d510e20 | 129 | pixel(_x, _y, colour); |
Lippi | 0:862a4d510e20 | 130 | // update pixel location based on window settings |
Lippi | 0:862a4d510e20 | 131 | _x++; |
Lippi | 0:862a4d510e20 | 132 | if(_x > _x2) { |
Lippi | 0:862a4d510e20 | 133 | _x = _x1; |
Lippi | 0:862a4d510e20 | 134 | _y++; |
Lippi | 0:862a4d510e20 | 135 | if(_y > _y2) { |
Lippi | 0:862a4d510e20 | 136 | _y = _y1; |
Lippi | 0:862a4d510e20 | 137 | } |
Lippi | 0:862a4d510e20 | 138 | } |
Lippi | 0:862a4d510e20 | 139 | } |
Lippi | 0:862a4d510e20 | 140 | |
Lippi | 0:862a4d510e20 | 141 | void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { |
Lippi | 0:862a4d510e20 | 142 | window(x, y, w, h); |
Lippi | 0:862a4d510e20 | 143 | for(int i=0; i<w*h; i++) { |
Lippi | 0:862a4d510e20 | 144 | putp(colour); |
Lippi | 0:862a4d510e20 | 145 | } |
Lippi | 0:862a4d510e20 | 146 | } |
Lippi | 0:862a4d510e20 | 147 | |
Lippi | 0:862a4d510e20 | 148 | void GraphicsDisplay::cls() { |
Lippi | 0:862a4d510e20 | 149 | fill(0, 0, width(), height(), _background); |
Lippi | 0:862a4d510e20 | 150 | } |
Lippi | 0:862a4d510e20 | 151 | |
Lippi | 0:862a4d510e20 | 152 | void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { |
Lippi | 0:862a4d510e20 | 153 | window(x, y, w, h); |
Lippi | 0:862a4d510e20 | 154 | for(int i=0; i<w*h; i++) { |
Lippi | 0:862a4d510e20 | 155 | putp(colour[i]); |
Lippi | 0:862a4d510e20 | 156 | } |
Lippi | 0:862a4d510e20 | 157 | } |
Lippi | 0:862a4d510e20 | 158 | |
Lippi | 0:862a4d510e20 | 159 | void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) { |
Lippi | 0:862a4d510e20 | 160 | window(x, y, w, h); |
Lippi | 0:862a4d510e20 | 161 | for(int i = 0; i < w*h; i++) { |
Lippi | 0:862a4d510e20 | 162 | char byte = colour[i >> 3]; |
Lippi | 0:862a4d510e20 | 163 | int offset = i & 0x7; |
Lippi | 0:862a4d510e20 | 164 | int c = ((byte << offset) & 0x80) ? _foreground : _background; |
Lippi | 0:862a4d510e20 | 165 | putp(c); |
Lippi | 0:862a4d510e20 | 166 | } |
Lippi | 0:862a4d510e20 | 167 | } |
Lippi | 0:862a4d510e20 | 168 | |
Lippi | 0:862a4d510e20 | 169 | int GraphicsDisplay::columns() { |
Lippi | 0:862a4d510e20 | 170 | return width() / 8; |
Lippi | 0:862a4d510e20 | 171 | } |
Lippi | 0:862a4d510e20 | 172 | |
Lippi | 0:862a4d510e20 | 173 | int GraphicsDisplay::rows() { |
Lippi | 0:862a4d510e20 | 174 | return height() / 8; |
Lippi | 0:862a4d510e20 | 175 | } |
Lippi | 0:862a4d510e20 | 176 |