TEST
Dependencies: max32630fthr Adafruit_FeatherOLED USBDevice
Drivers/LS013B7DH03/GraphicsDisplay.cpp@4:291477e8690d, 2020-04-19 (annotated)
- Committer:
- wwwarunraj
- Date:
- Sun Apr 19 11:19:57 2020 +0000
- Revision:
- 4:291477e8690d
- Parent:
- 1:f60eafbf009a
19/04
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gmehmet | 1:f60eafbf009a | 1 | /* mbed GraphicsDisplay Display Library Base Class |
gmehmet | 1:f60eafbf009a | 2 | * Copyright (c) 2007-2009 sford |
gmehmet | 1:f60eafbf009a | 3 | * Released under the MIT License: http://mbed.org/license/mit |
gmehmet | 1:f60eafbf009a | 4 | */ |
gmehmet | 1:f60eafbf009a | 5 | |
gmehmet | 1:f60eafbf009a | 6 | #include "GraphicsDisplay.h" |
gmehmet | 1:f60eafbf009a | 7 | |
gmehmet | 1:f60eafbf009a | 8 | #define incx() x++, dxt += d2xt, t += dxt |
gmehmet | 1:f60eafbf009a | 9 | #define incy() y--, dyt += d2yt, t += dyt |
gmehmet | 1:f60eafbf009a | 10 | |
gmehmet | 1:f60eafbf009a | 11 | const unsigned char FONT8x8[97][8] = { |
gmehmet | 1:f60eafbf009a | 12 | {0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00}, // columns, rows, num_bytes_per_char |
gmehmet | 1:f60eafbf009a | 13 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // space 0x20 |
gmehmet | 1:f60eafbf009a | 14 | {0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00}, // ! |
gmehmet | 1:f60eafbf009a | 15 | {0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00}, // " |
gmehmet | 1:f60eafbf009a | 16 | {0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00}, // # |
gmehmet | 1:f60eafbf009a | 17 | {0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00}, // $ |
gmehmet | 1:f60eafbf009a | 18 | {0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00}, // % |
gmehmet | 1:f60eafbf009a | 19 | {0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00}, // & |
gmehmet | 1:f60eafbf009a | 20 | {0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00}, // ' |
gmehmet | 1:f60eafbf009a | 21 | {0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00}, // ( |
gmehmet | 1:f60eafbf009a | 22 | {0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00}, // ) |
gmehmet | 1:f60eafbf009a | 23 | {0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00}, // * |
gmehmet | 1:f60eafbf009a | 24 | {0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00}, // + |
gmehmet | 1:f60eafbf009a | 25 | {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30}, // , |
gmehmet | 1:f60eafbf009a | 26 | {0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00}, // - |
gmehmet | 1:f60eafbf009a | 27 | {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00}, // . |
gmehmet | 1:f60eafbf009a | 28 | {0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00}, // / (forward slash) |
gmehmet | 1:f60eafbf009a | 29 | {0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00}, // 0 0x30 |
gmehmet | 1:f60eafbf009a | 30 | {0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00}, // 1 |
gmehmet | 1:f60eafbf009a | 31 | {0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00}, // 2 |
gmehmet | 1:f60eafbf009a | 32 | {0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00}, // 3 |
gmehmet | 1:f60eafbf009a | 33 | {0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00}, // 4 |
gmehmet | 1:f60eafbf009a | 34 | {0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00}, // 5 |
gmehmet | 1:f60eafbf009a | 35 | {0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00}, // 6 |
gmehmet | 1:f60eafbf009a | 36 | {0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00}, // 7 |
gmehmet | 1:f60eafbf009a | 37 | {0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00}, // 8 |
gmehmet | 1:f60eafbf009a | 38 | {0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00}, // 9 |
gmehmet | 1:f60eafbf009a | 39 | {0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00}, // : |
gmehmet | 1:f60eafbf009a | 40 | {0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30}, // ; |
gmehmet | 1:f60eafbf009a | 41 | {0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00}, // < |
gmehmet | 1:f60eafbf009a | 42 | {0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00}, // = |
gmehmet | 1:f60eafbf009a | 43 | {0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00}, // > |
gmehmet | 1:f60eafbf009a | 44 | {0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00}, // ? |
gmehmet | 1:f60eafbf009a | 45 | {0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00}, // @ 0x40 |
gmehmet | 1:f60eafbf009a | 46 | {0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00}, // A |
gmehmet | 1:f60eafbf009a | 47 | {0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00}, // B |
gmehmet | 1:f60eafbf009a | 48 | {0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00}, // C |
gmehmet | 1:f60eafbf009a | 49 | {0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00}, // D |
gmehmet | 1:f60eafbf009a | 50 | {0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00}, // E |
gmehmet | 1:f60eafbf009a | 51 | {0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00}, // F |
gmehmet | 1:f60eafbf009a | 52 | {0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00}, // G |
gmehmet | 1:f60eafbf009a | 53 | {0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00}, // H |
gmehmet | 1:f60eafbf009a | 54 | {0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00}, // I |
gmehmet | 1:f60eafbf009a | 55 | {0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00}, // J |
gmehmet | 1:f60eafbf009a | 56 | {0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00}, // K |
gmehmet | 1:f60eafbf009a | 57 | {0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00}, // L |
gmehmet | 1:f60eafbf009a | 58 | {0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00}, // M |
gmehmet | 1:f60eafbf009a | 59 | {0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00}, // N |
gmehmet | 1:f60eafbf009a | 60 | {0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00}, // O |
gmehmet | 1:f60eafbf009a | 61 | {0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00}, // P 0x50 |
gmehmet | 1:f60eafbf009a | 62 | {0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00}, // Q |
gmehmet | 1:f60eafbf009a | 63 | {0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00}, // R |
gmehmet | 1:f60eafbf009a | 64 | {0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00}, // S |
gmehmet | 1:f60eafbf009a | 65 | {0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00}, // T |
gmehmet | 1:f60eafbf009a | 66 | {0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00}, // U |
gmehmet | 1:f60eafbf009a | 67 | {0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00}, // V |
gmehmet | 1:f60eafbf009a | 68 | {0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00}, // W |
gmehmet | 1:f60eafbf009a | 69 | {0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00}, // X |
gmehmet | 1:f60eafbf009a | 70 | {0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00}, // Y |
gmehmet | 1:f60eafbf009a | 71 | {0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00}, // Z |
gmehmet | 1:f60eafbf009a | 72 | {0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00}, // [ |
gmehmet | 1:f60eafbf009a | 73 | {0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00}, // \ (back slash) |
gmehmet | 1:f60eafbf009a | 74 | {0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00}, // ] |
gmehmet | 1:f60eafbf009a | 75 | {0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00}, // ^ |
gmehmet | 1:f60eafbf009a | 76 | {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF}, // _ |
gmehmet | 1:f60eafbf009a | 77 | {0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00}, // ` 0x60 |
gmehmet | 1:f60eafbf009a | 78 | {0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00}, // a |
gmehmet | 1:f60eafbf009a | 79 | {0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00}, // b |
gmehmet | 1:f60eafbf009a | 80 | {0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00}, // c |
gmehmet | 1:f60eafbf009a | 81 | {0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00}, // d |
gmehmet | 1:f60eafbf009a | 82 | {0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00}, // e |
gmehmet | 1:f60eafbf009a | 83 | {0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00}, // f |
gmehmet | 1:f60eafbf009a | 84 | {0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C}, // g |
gmehmet | 1:f60eafbf009a | 85 | {0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00}, // h |
gmehmet | 1:f60eafbf009a | 86 | {0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00}, // i |
gmehmet | 1:f60eafbf009a | 87 | {0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C}, // j |
gmehmet | 1:f60eafbf009a | 88 | {0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00}, // k |
gmehmet | 1:f60eafbf009a | 89 | {0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00}, // l |
gmehmet | 1:f60eafbf009a | 90 | {0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00}, // m |
gmehmet | 1:f60eafbf009a | 91 | {0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00}, // n |
gmehmet | 1:f60eafbf009a | 92 | {0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00}, // o |
gmehmet | 1:f60eafbf009a | 93 | {0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78}, // p |
gmehmet | 1:f60eafbf009a | 94 | {0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F}, // q |
gmehmet | 1:f60eafbf009a | 95 | {0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00}, // r |
gmehmet | 1:f60eafbf009a | 96 | {0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00}, // s |
gmehmet | 1:f60eafbf009a | 97 | {0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00}, // t |
gmehmet | 1:f60eafbf009a | 98 | {0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00}, // u |
gmehmet | 1:f60eafbf009a | 99 | {0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00}, // v |
gmehmet | 1:f60eafbf009a | 100 | {0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00}, // w |
gmehmet | 1:f60eafbf009a | 101 | {0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00}, // x |
gmehmet | 1:f60eafbf009a | 102 | {0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C}, // y |
gmehmet | 1:f60eafbf009a | 103 | {0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00}, // z |
gmehmet | 1:f60eafbf009a | 104 | {0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00}, // { |
gmehmet | 1:f60eafbf009a | 105 | {0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00}, // | |
gmehmet | 1:f60eafbf009a | 106 | {0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00}, // } |
gmehmet | 1:f60eafbf009a | 107 | {0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00}, // ~ |
gmehmet | 1:f60eafbf009a | 108 | {0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}}; // DEL |
gmehmet | 1:f60eafbf009a | 109 | |
gmehmet | 1:f60eafbf009a | 110 | GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) { |
gmehmet | 1:f60eafbf009a | 111 | foreground((uint16_t)Black); |
gmehmet | 1:f60eafbf009a | 112 | background((uint16_t)White); |
gmehmet | 1:f60eafbf009a | 113 | // current pixel location |
gmehmet | 1:f60eafbf009a | 114 | _x = 0; |
gmehmet | 1:f60eafbf009a | 115 | _y = 0; |
gmehmet | 1:f60eafbf009a | 116 | // window settings |
gmehmet | 1:f60eafbf009a | 117 | _x1 = 0; |
gmehmet | 1:f60eafbf009a | 118 | _x2 = 0; |
gmehmet | 1:f60eafbf009a | 119 | _y1 = 0; |
gmehmet | 1:f60eafbf009a | 120 | _y2 = 0; |
gmehmet | 1:f60eafbf009a | 121 | } |
gmehmet | 1:f60eafbf009a | 122 | |
gmehmet | 1:f60eafbf009a | 123 | void GraphicsDisplay::character(int column, int row, int value) { |
gmehmet | 1:f60eafbf009a | 124 | if(externalfont){ // send external font |
gmehmet | 1:f60eafbf009a | 125 | unsigned int hor,vert,offset,bpl,j,i,b; |
gmehmet | 1:f60eafbf009a | 126 | const unsigned char* sign; |
gmehmet | 1:f60eafbf009a | 127 | unsigned char z,w; |
gmehmet | 1:f60eafbf009a | 128 | if ((value < 31) || (value > 127)) return; // test char range |
gmehmet | 1:f60eafbf009a | 129 | // read font parameter from start of array |
gmehmet | 1:f60eafbf009a | 130 | offset = font[0]; // bytes / char |
gmehmet | 1:f60eafbf009a | 131 | hor = font[1]; // get hor size of font |
gmehmet | 1:f60eafbf009a | 132 | vert = font[2]; // get vert size of font |
gmehmet | 1:f60eafbf009a | 133 | bpl = font[3]; // bytes per line |
gmehmet | 1:f60eafbf009a | 134 | if (char_x + hor > width()) { |
gmehmet | 1:f60eafbf009a | 135 | char_x = 0; |
gmehmet | 1:f60eafbf009a | 136 | char_y = char_y + vert; |
gmehmet | 1:f60eafbf009a | 137 | if (char_y >= height() - font[2]) { |
gmehmet | 1:f60eafbf009a | 138 | char_y = 0; |
gmehmet | 1:f60eafbf009a | 139 | } |
gmehmet | 1:f60eafbf009a | 140 | } |
gmehmet | 1:f60eafbf009a | 141 | window(char_x, char_y,hor,vert); // char box |
gmehmet | 1:f60eafbf009a | 142 | sign = &font[((value -32) * offset) + 4]; // start of char bitmap |
gmehmet | 1:f60eafbf009a | 143 | w = sign[0]; // width of actual char |
gmehmet | 1:f60eafbf009a | 144 | for (j=0; j<vert; j++) { // vert line |
gmehmet | 1:f60eafbf009a | 145 | for (i=0; i<hor; i++) { // horz line |
gmehmet | 1:f60eafbf009a | 146 | z = sign[bpl * i + ((j & 0xF8) >> 3)+1]; |
gmehmet | 1:f60eafbf009a | 147 | b = 1 << (j & 0x07); |
gmehmet | 1:f60eafbf009a | 148 | if (( z & b ) == 0x00) { |
gmehmet | 1:f60eafbf009a | 149 | putp(_foreground); |
gmehmet | 1:f60eafbf009a | 150 | } |
gmehmet | 1:f60eafbf009a | 151 | else { |
gmehmet | 1:f60eafbf009a | 152 | putp(_background); |
gmehmet | 1:f60eafbf009a | 153 | } |
gmehmet | 1:f60eafbf009a | 154 | } |
gmehmet | 1:f60eafbf009a | 155 | } |
gmehmet | 1:f60eafbf009a | 156 | if ((w + 2) < hor) { // x offset to next char |
gmehmet | 1:f60eafbf009a | 157 | char_x += w + 2; |
gmehmet | 1:f60eafbf009a | 158 | } |
gmehmet | 1:f60eafbf009a | 159 | else char_x += hor; |
gmehmet | 1:f60eafbf009a | 160 | } |
gmehmet | 1:f60eafbf009a | 161 | // send default font |
gmehmet | 1:f60eafbf009a | 162 | else { |
gmehmet | 1:f60eafbf009a | 163 | blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0])); |
gmehmet | 1:f60eafbf009a | 164 | } |
gmehmet | 1:f60eafbf009a | 165 | } |
gmehmet | 1:f60eafbf009a | 166 | |
gmehmet | 1:f60eafbf009a | 167 | void GraphicsDisplay::window(int x, int y, int w, int h) { |
gmehmet | 1:f60eafbf009a | 168 | // current pixel location |
gmehmet | 1:f60eafbf009a | 169 | _x = x; |
gmehmet | 1:f60eafbf009a | 170 | _y = y; |
gmehmet | 1:f60eafbf009a | 171 | // window settings |
gmehmet | 1:f60eafbf009a | 172 | _x1 = x; |
gmehmet | 1:f60eafbf009a | 173 | _x2 = x + w - 1; |
gmehmet | 1:f60eafbf009a | 174 | _y1 = y; |
gmehmet | 1:f60eafbf009a | 175 | _y2 = y + h - 1; |
gmehmet | 1:f60eafbf009a | 176 | } |
gmehmet | 1:f60eafbf009a | 177 | |
gmehmet | 1:f60eafbf009a | 178 | void GraphicsDisplay::putp(int colour) { |
gmehmet | 1:f60eafbf009a | 179 | // put pixel at current pixel location |
gmehmet | 1:f60eafbf009a | 180 | pixel(_x, _y, colour); |
gmehmet | 1:f60eafbf009a | 181 | // update pixel location based on window settings |
gmehmet | 1:f60eafbf009a | 182 | _x++; |
gmehmet | 1:f60eafbf009a | 183 | if(_x > _x2) { |
gmehmet | 1:f60eafbf009a | 184 | _x = _x1; |
gmehmet | 1:f60eafbf009a | 185 | _y++; |
gmehmet | 1:f60eafbf009a | 186 | if(_y > _y2) { |
gmehmet | 1:f60eafbf009a | 187 | _y = _y1; |
gmehmet | 1:f60eafbf009a | 188 | } |
gmehmet | 1:f60eafbf009a | 189 | } |
gmehmet | 1:f60eafbf009a | 190 | } |
gmehmet | 1:f60eafbf009a | 191 | |
gmehmet | 1:f60eafbf009a | 192 | void GraphicsDisplay::rect(int x0, int y0, int x1, int y1, int color) { |
gmehmet | 1:f60eafbf009a | 193 | if (x1 > x0) hline(x0,x1,y0,color); |
gmehmet | 1:f60eafbf009a | 194 | else hline(x1,x0,y0,color); |
gmehmet | 1:f60eafbf009a | 195 | if (y1 > y0) vline(x0,y0,y1,color); |
gmehmet | 1:f60eafbf009a | 196 | else vline(x0,y1,y0,color); |
gmehmet | 1:f60eafbf009a | 197 | if (x1 > x0) hline(x0,x1,y1,color); |
gmehmet | 1:f60eafbf009a | 198 | else hline(x1,x0,y1,color); |
gmehmet | 1:f60eafbf009a | 199 | if (y1 > y0) vline(x1,y0,y1,color); |
gmehmet | 1:f60eafbf009a | 200 | else vline(x1,y1,y0,color); |
gmehmet | 1:f60eafbf009a | 201 | return; |
gmehmet | 1:f60eafbf009a | 202 | } |
gmehmet | 1:f60eafbf009a | 203 | |
gmehmet | 1:f60eafbf009a | 204 | void GraphicsDisplay::fillrect(int x0, int y0, int w, int h, int colour) { |
gmehmet | 1:f60eafbf009a | 205 | unsigned long int index=0; |
gmehmet | 1:f60eafbf009a | 206 | if (w < 0) { |
gmehmet | 1:f60eafbf009a | 207 | x0 = x0 + w; |
gmehmet | 1:f60eafbf009a | 208 | w = -w; |
gmehmet | 1:f60eafbf009a | 209 | } |
gmehmet | 1:f60eafbf009a | 210 | if (h < 0) { |
gmehmet | 1:f60eafbf009a | 211 | y0 = y0 + h; |
gmehmet | 1:f60eafbf009a | 212 | h = -h; |
gmehmet | 1:f60eafbf009a | 213 | } |
gmehmet | 1:f60eafbf009a | 214 | window(x0,y0,w,h); |
gmehmet | 1:f60eafbf009a | 215 | int num = h*w; |
gmehmet | 1:f60eafbf009a | 216 | for( index = 0; index<num; index++ ) { |
gmehmet | 1:f60eafbf009a | 217 | putp(colour); |
gmehmet | 1:f60eafbf009a | 218 | } |
gmehmet | 1:f60eafbf009a | 219 | return; |
gmehmet | 1:f60eafbf009a | 220 | } |
gmehmet | 1:f60eafbf009a | 221 | |
gmehmet | 1:f60eafbf009a | 222 | void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { |
gmehmet | 1:f60eafbf009a | 223 | fillrect(x, y, w, h, colour); |
gmehmet | 1:f60eafbf009a | 224 | } |
gmehmet | 1:f60eafbf009a | 225 | |
gmehmet | 1:f60eafbf009a | 226 | void GraphicsDisplay::circle(int x, int y, int r,int colour){ |
gmehmet | 1:f60eafbf009a | 227 | int ce = -r; |
gmehmet | 1:f60eafbf009a | 228 | int cx = r; |
gmehmet | 1:f60eafbf009a | 229 | int cy = 0; |
gmehmet | 1:f60eafbf009a | 230 | while(cx >= cy){ |
gmehmet | 1:f60eafbf009a | 231 | pixel(x+cx,y+cy,colour); |
gmehmet | 1:f60eafbf009a | 232 | pixel(x-cx,y-cy,colour); |
gmehmet | 1:f60eafbf009a | 233 | pixel(x-cx,y+cy,colour); |
gmehmet | 1:f60eafbf009a | 234 | pixel(x+cx,y-cy,colour); |
gmehmet | 1:f60eafbf009a | 235 | pixel(x+cy,y+cx,colour); |
gmehmet | 1:f60eafbf009a | 236 | pixel(x-cy,y+cx,colour); |
gmehmet | 1:f60eafbf009a | 237 | pixel(x-cy,y-cx,colour); |
gmehmet | 1:f60eafbf009a | 238 | pixel(x+cy,y-cx,colour); |
gmehmet | 1:f60eafbf009a | 239 | ce += 2*cy++ + 1; |
gmehmet | 1:f60eafbf009a | 240 | if(ce >= 0){ |
gmehmet | 1:f60eafbf009a | 241 | ce -= 2*cx---1; |
gmehmet | 1:f60eafbf009a | 242 | } |
gmehmet | 1:f60eafbf009a | 243 | |
gmehmet | 1:f60eafbf009a | 244 | } |
gmehmet | 1:f60eafbf009a | 245 | |
gmehmet | 1:f60eafbf009a | 246 | } |
gmehmet | 1:f60eafbf009a | 247 | |
gmehmet | 1:f60eafbf009a | 248 | // To draw circle set a and b to the same values |
gmehmet | 1:f60eafbf009a | 249 | void GraphicsDisplay::ellipse(int xc, int yc, int a, int b, unsigned int colour) |
gmehmet | 1:f60eafbf009a | 250 | { |
gmehmet | 1:f60eafbf009a | 251 | /* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */ |
gmehmet | 1:f60eafbf009a | 252 | int x = 0, y = b; |
gmehmet | 1:f60eafbf009a | 253 | long a2 = (long)a*a, b2 = (long)b*b; |
gmehmet | 1:f60eafbf009a | 254 | long crit1 = -(a2/4 + a%2 + b2); |
gmehmet | 1:f60eafbf009a | 255 | long crit2 = -(b2/4 + b%2 + a2); |
gmehmet | 1:f60eafbf009a | 256 | long crit3 = -(b2/4 + b%2); |
gmehmet | 1:f60eafbf009a | 257 | long t = -a2*y; // e(x+1/2,y-1/2) - (a^2+b^2)/4 |
gmehmet | 1:f60eafbf009a | 258 | long dxt = 2*b2*x, dyt = -2*a2*y; |
gmehmet | 1:f60eafbf009a | 259 | long d2xt = 2*b2, d2yt = 2*a2; |
gmehmet | 1:f60eafbf009a | 260 | |
gmehmet | 1:f60eafbf009a | 261 | while (y>=0 && x<=a) { |
gmehmet | 1:f60eafbf009a | 262 | pixel(xc+x, yc+y, colour); |
gmehmet | 1:f60eafbf009a | 263 | if (x!=0 || y!=0) |
gmehmet | 1:f60eafbf009a | 264 | pixel(xc-x, yc-y, colour); |
gmehmet | 1:f60eafbf009a | 265 | if (x!=0 && y!=0) { |
gmehmet | 1:f60eafbf009a | 266 | pixel(xc+x, yc-y, colour); |
gmehmet | 1:f60eafbf009a | 267 | pixel(xc-x, yc+y, colour); |
gmehmet | 1:f60eafbf009a | 268 | } |
gmehmet | 1:f60eafbf009a | 269 | if (t + b2*x <= crit1 || // e(x+1,y-1/2) <= 0 |
gmehmet | 1:f60eafbf009a | 270 | t + a2*y <= crit3) // e(x+1/2,y) <= 0 |
gmehmet | 1:f60eafbf009a | 271 | incx(); |
gmehmet | 1:f60eafbf009a | 272 | else if (t - a2*y > crit2) // e(x+1/2,y-1) > 0 |
gmehmet | 1:f60eafbf009a | 273 | incy(); |
gmehmet | 1:f60eafbf009a | 274 | else { |
gmehmet | 1:f60eafbf009a | 275 | incx(); |
gmehmet | 1:f60eafbf009a | 276 | incy(); |
gmehmet | 1:f60eafbf009a | 277 | } |
gmehmet | 1:f60eafbf009a | 278 | } |
gmehmet | 1:f60eafbf009a | 279 | } |
gmehmet | 1:f60eafbf009a | 280 | // To draw circle set a and b to the same values |
gmehmet | 1:f60eafbf009a | 281 | void GraphicsDisplay::fillellipse(int xc, int yc, int a, int b, unsigned int colour) |
gmehmet | 1:f60eafbf009a | 282 | { |
gmehmet | 1:f60eafbf009a | 283 | /* e(x,y) = b^2*x^2 + a^2*y^2 - a^2*b^2 */ |
gmehmet | 1:f60eafbf009a | 284 | int x = 0, y = b; |
gmehmet | 1:f60eafbf009a | 285 | int rx = x, ry = y; |
gmehmet | 1:f60eafbf009a | 286 | unsigned int width = 1; |
gmehmet | 1:f60eafbf009a | 287 | unsigned int height = 1; |
gmehmet | 1:f60eafbf009a | 288 | long a2 = (long)a*a, b2 = (long)b*b; |
gmehmet | 1:f60eafbf009a | 289 | long crit1 = -(a2/4 + a%2 + b2); |
gmehmet | 1:f60eafbf009a | 290 | long crit2 = -(b2/4 + b%2 + a2); |
gmehmet | 1:f60eafbf009a | 291 | long crit3 = -(b2/4 + b%2); |
gmehmet | 1:f60eafbf009a | 292 | long t = -a2*y; // e(x+1/2,y-1/2) - (a^2+b^2)/4 |
gmehmet | 1:f60eafbf009a | 293 | long dxt = 2*b2*x, dyt = -2*a2*y; |
gmehmet | 1:f60eafbf009a | 294 | long d2xt = 2*b2, d2yt = 2*a2; |
gmehmet | 1:f60eafbf009a | 295 | if (b == 0) { |
gmehmet | 1:f60eafbf009a | 296 | fillrect(xc-a, yc, 2*a+1, 1, colour); |
gmehmet | 1:f60eafbf009a | 297 | return; |
gmehmet | 1:f60eafbf009a | 298 | } |
gmehmet | 1:f60eafbf009a | 299 | while (y>=0 && x<=a) { |
gmehmet | 1:f60eafbf009a | 300 | if (t + b2*x <= crit1 || // e(x+1,y-1/2) <= 0 |
gmehmet | 1:f60eafbf009a | 301 | t + a2*y <= crit3) { // e(x+1/2,y) <= 0 |
gmehmet | 1:f60eafbf009a | 302 | if (height == 1) |
gmehmet | 1:f60eafbf009a | 303 | ; // draw nothing |
gmehmet | 1:f60eafbf009a | 304 | else if (ry*2+1 > (height-1)*2) { |
gmehmet | 1:f60eafbf009a | 305 | fillrect(xc-rx, yc-ry, width, height-1, colour); |
gmehmet | 1:f60eafbf009a | 306 | fillrect(xc-rx, yc+ry+1, width, 1-height, colour); |
gmehmet | 1:f60eafbf009a | 307 | ry -= height-1; |
gmehmet | 1:f60eafbf009a | 308 | height = 1; |
gmehmet | 1:f60eafbf009a | 309 | } else { |
gmehmet | 1:f60eafbf009a | 310 | fillrect(xc-rx, yc-ry, width, ry*2+1, colour); |
gmehmet | 1:f60eafbf009a | 311 | ry -= ry; |
gmehmet | 1:f60eafbf009a | 312 | height = 1; |
gmehmet | 1:f60eafbf009a | 313 | } |
gmehmet | 1:f60eafbf009a | 314 | incx(); |
gmehmet | 1:f60eafbf009a | 315 | rx++; |
gmehmet | 1:f60eafbf009a | 316 | width += 2; |
gmehmet | 1:f60eafbf009a | 317 | } else if (t - a2*y > crit2) { // e(x+1/2,y-1) > 0 |
gmehmet | 1:f60eafbf009a | 318 | incy(); |
gmehmet | 1:f60eafbf009a | 319 | height++; |
gmehmet | 1:f60eafbf009a | 320 | } else { |
gmehmet | 1:f60eafbf009a | 321 | if (ry*2+1 > height*2) { |
gmehmet | 1:f60eafbf009a | 322 | fillrect(xc-rx, yc-ry, width, height, colour); |
gmehmet | 1:f60eafbf009a | 323 | fillrect(xc-rx, yc+ry+1, width, -height, colour); |
gmehmet | 1:f60eafbf009a | 324 | } else { |
gmehmet | 1:f60eafbf009a | 325 | fillrect(xc-rx, yc-ry, width, ry*2+1, colour); |
gmehmet | 1:f60eafbf009a | 326 | } |
gmehmet | 1:f60eafbf009a | 327 | incx(); |
gmehmet | 1:f60eafbf009a | 328 | incy(); |
gmehmet | 1:f60eafbf009a | 329 | rx++; |
gmehmet | 1:f60eafbf009a | 330 | width += 2; |
gmehmet | 1:f60eafbf009a | 331 | ry -= height; |
gmehmet | 1:f60eafbf009a | 332 | height = 1; |
gmehmet | 1:f60eafbf009a | 333 | } |
gmehmet | 1:f60eafbf009a | 334 | } |
gmehmet | 1:f60eafbf009a | 335 | if (ry > height) { |
gmehmet | 1:f60eafbf009a | 336 | fillrect(xc-rx, yc-ry, width, height, colour); |
gmehmet | 1:f60eafbf009a | 337 | fillrect(xc-rx, yc+ry+1, width, -height, colour); |
gmehmet | 1:f60eafbf009a | 338 | } else { |
gmehmet | 1:f60eafbf009a | 339 | fillrect(xc-rx, yc-ry, width, ry*2+1, colour); |
gmehmet | 1:f60eafbf009a | 340 | } |
gmehmet | 1:f60eafbf009a | 341 | } |
gmehmet | 1:f60eafbf009a | 342 | |
gmehmet | 1:f60eafbf009a | 343 | |
gmehmet | 1:f60eafbf009a | 344 | void GraphicsDisplay::line(int x0, int y0, int x1, int y1, int colour) { |
gmehmet | 1:f60eafbf009a | 345 | //window(x0, y, w, h); |
gmehmet | 1:f60eafbf009a | 346 | int dx = 0, dy = 0; |
gmehmet | 1:f60eafbf009a | 347 | int dx_sym = 0, dy_sym = 0; |
gmehmet | 1:f60eafbf009a | 348 | int dx_x2 = 0, dy_x2 = 0; |
gmehmet | 1:f60eafbf009a | 349 | int di = 0; |
gmehmet | 1:f60eafbf009a | 350 | dx = x1-x0; |
gmehmet | 1:f60eafbf009a | 351 | dy = y1-y0; |
gmehmet | 1:f60eafbf009a | 352 | |
gmehmet | 1:f60eafbf009a | 353 | if (dx == 0) { /* vertical line */ |
gmehmet | 1:f60eafbf009a | 354 | if (y1 > y0) vline(x0,y0,y1,colour); |
gmehmet | 1:f60eafbf009a | 355 | else vline(x0,y1,y0,colour); |
gmehmet | 1:f60eafbf009a | 356 | return; |
gmehmet | 1:f60eafbf009a | 357 | } |
gmehmet | 1:f60eafbf009a | 358 | if (dx > 0) { |
gmehmet | 1:f60eafbf009a | 359 | dx_sym = 1; |
gmehmet | 1:f60eafbf009a | 360 | } else { |
gmehmet | 1:f60eafbf009a | 361 | dx_sym = -1; |
gmehmet | 1:f60eafbf009a | 362 | } |
gmehmet | 1:f60eafbf009a | 363 | if (dy == 0) { /* horizontal line */ |
gmehmet | 1:f60eafbf009a | 364 | if (x1 > x0) hline(x0,x1,y0,colour); |
gmehmet | 1:f60eafbf009a | 365 | else hline(x1,x0,y0,colour); |
gmehmet | 1:f60eafbf009a | 366 | return; |
gmehmet | 1:f60eafbf009a | 367 | } |
gmehmet | 1:f60eafbf009a | 368 | if (dy > 0) { |
gmehmet | 1:f60eafbf009a | 369 | dy_sym = 1; |
gmehmet | 1:f60eafbf009a | 370 | } else { |
gmehmet | 1:f60eafbf009a | 371 | dy_sym = -1; |
gmehmet | 1:f60eafbf009a | 372 | } |
gmehmet | 1:f60eafbf009a | 373 | dx = dx_sym*dx; |
gmehmet | 1:f60eafbf009a | 374 | dy = dy_sym*dy; |
gmehmet | 1:f60eafbf009a | 375 | dx_x2 = dx*2; |
gmehmet | 1:f60eafbf009a | 376 | dy_x2 = dy*2; |
gmehmet | 1:f60eafbf009a | 377 | if (dx >= dy) { |
gmehmet | 1:f60eafbf009a | 378 | di = dy_x2 - dx; |
gmehmet | 1:f60eafbf009a | 379 | while (x0 != x1) { |
gmehmet | 1:f60eafbf009a | 380 | |
gmehmet | 1:f60eafbf009a | 381 | pixel(x0, y0, colour); |
gmehmet | 1:f60eafbf009a | 382 | x0 += dx_sym; |
gmehmet | 1:f60eafbf009a | 383 | if (di<0) { |
gmehmet | 1:f60eafbf009a | 384 | di += dy_x2; |
gmehmet | 1:f60eafbf009a | 385 | } else { |
gmehmet | 1:f60eafbf009a | 386 | di += dy_x2 - dx_x2; |
gmehmet | 1:f60eafbf009a | 387 | y0 += dy_sym; |
gmehmet | 1:f60eafbf009a | 388 | } |
gmehmet | 1:f60eafbf009a | 389 | } |
gmehmet | 1:f60eafbf009a | 390 | pixel(x0, y0, colour); |
gmehmet | 1:f60eafbf009a | 391 | } else { |
gmehmet | 1:f60eafbf009a | 392 | di = dx_x2 - dy; |
gmehmet | 1:f60eafbf009a | 393 | while (y0 != y1) { |
gmehmet | 1:f60eafbf009a | 394 | pixel(x0, y0, colour); |
gmehmet | 1:f60eafbf009a | 395 | y0 += dy_sym; |
gmehmet | 1:f60eafbf009a | 396 | if (di < 0) { |
gmehmet | 1:f60eafbf009a | 397 | di += dx_x2; |
gmehmet | 1:f60eafbf009a | 398 | } else { |
gmehmet | 1:f60eafbf009a | 399 | di += dx_x2 - dy_x2; |
gmehmet | 1:f60eafbf009a | 400 | x0 += dx_sym; |
gmehmet | 1:f60eafbf009a | 401 | } |
gmehmet | 1:f60eafbf009a | 402 | } |
gmehmet | 1:f60eafbf009a | 403 | pixel(x0, y0, colour); |
gmehmet | 1:f60eafbf009a | 404 | } |
gmehmet | 1:f60eafbf009a | 405 | return; |
gmehmet | 1:f60eafbf009a | 406 | } |
gmehmet | 1:f60eafbf009a | 407 | |
gmehmet | 1:f60eafbf009a | 408 | void GraphicsDisplay::hline(int x0, int x1, int y, int colour) { |
gmehmet | 1:f60eafbf009a | 409 | int w; |
gmehmet | 1:f60eafbf009a | 410 | w = x1 - x0 + 1; |
gmehmet | 1:f60eafbf009a | 411 | window(x0,y,w,1); |
gmehmet | 1:f60eafbf009a | 412 | for (int x=0; x<w; x++) { |
gmehmet | 1:f60eafbf009a | 413 | putp(colour); |
gmehmet | 1:f60eafbf009a | 414 | } |
gmehmet | 1:f60eafbf009a | 415 | return; |
gmehmet | 1:f60eafbf009a | 416 | } |
gmehmet | 1:f60eafbf009a | 417 | |
gmehmet | 1:f60eafbf009a | 418 | void GraphicsDisplay::vline(int x, int y0, int y1, int colour) { |
gmehmet | 1:f60eafbf009a | 419 | int h; |
gmehmet | 1:f60eafbf009a | 420 | h = y1 - y0 + 1; |
gmehmet | 1:f60eafbf009a | 421 | window(x,y0,1,h); |
gmehmet | 1:f60eafbf009a | 422 | for (int y=0; y<h; y++) { |
gmehmet | 1:f60eafbf009a | 423 | putp(colour); |
gmehmet | 1:f60eafbf009a | 424 | } |
gmehmet | 1:f60eafbf009a | 425 | return; |
gmehmet | 1:f60eafbf009a | 426 | } |
gmehmet | 1:f60eafbf009a | 427 | |
gmehmet | 1:f60eafbf009a | 428 | void GraphicsDisplay::cls() { |
gmehmet | 1:f60eafbf009a | 429 | fill(0, 0, width(), height(), _background); |
gmehmet | 1:f60eafbf009a | 430 | } |
gmehmet | 1:f60eafbf009a | 431 | |
gmehmet | 1:f60eafbf009a | 432 | void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { |
gmehmet | 1:f60eafbf009a | 433 | window(x, y, w, h); |
gmehmet | 1:f60eafbf009a | 434 | for(int i=0; i<w*h; i++) { |
gmehmet | 1:f60eafbf009a | 435 | putp(colour[i]); |
gmehmet | 1:f60eafbf009a | 436 | } |
gmehmet | 1:f60eafbf009a | 437 | } |
gmehmet | 1:f60eafbf009a | 438 | |
gmehmet | 1:f60eafbf009a | 439 | void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) { |
gmehmet | 1:f60eafbf009a | 440 | window(x, y, w, h); |
gmehmet | 1:f60eafbf009a | 441 | for(int i = 0; i < w*h; i++) { |
gmehmet | 1:f60eafbf009a | 442 | char byte = colour[i >> 3]; |
gmehmet | 1:f60eafbf009a | 443 | int offset = i & 0x7; |
gmehmet | 1:f60eafbf009a | 444 | int c = ((byte << (offset)) & 0x80) ? _foreground : _background; |
gmehmet | 1:f60eafbf009a | 445 | putp(c); |
gmehmet | 1:f60eafbf009a | 446 | } |
gmehmet | 1:f60eafbf009a | 447 | } |
gmehmet | 1:f60eafbf009a | 448 | |
gmehmet | 1:f60eafbf009a | 449 | int GraphicsDisplay::columns() { |
gmehmet | 1:f60eafbf009a | 450 | return width() / 8; |
gmehmet | 1:f60eafbf009a | 451 | } |
gmehmet | 1:f60eafbf009a | 452 | |
gmehmet | 1:f60eafbf009a | 453 | int GraphicsDisplay::rows() { |
gmehmet | 1:f60eafbf009a | 454 | return height() / 8; |
gmehmet | 1:f60eafbf009a | 455 | } |
gmehmet | 1:f60eafbf009a | 456 |