| 20 | constexpr char kRawBlack = 'X'; |
| 21 | |
| 22 | constexpr static CursorData cursorFromBitMap(int x, int y, std::string_view bitmap) |
| 23 | { |
| 24 | assert(bitmap.length() == kRawCursorSize); |
| 25 | |
| 26 | CursorData newCursor{}; |
| 27 | newCursor.HotSpot.X = x; |
| 28 | newCursor.HotSpot.Y = y; |
| 29 | |
| 30 | uint8_t curBit{}; |
| 31 | uint16_t curPixel{}; |
| 32 | uint8_t dataByte{}, maskByte{}; |
| 33 | for (char rawPixel : bitmap) |
| 34 | { |
| 35 | uint8_t dataBit{}, maskBit{}; |
| 36 | switch (rawPixel) |
| 37 | { |
| 38 | case kRawBlack: |
| 39 | dataBit = 1; |
| 40 | maskBit = 1; |
| 41 | break; |
| 42 | case kRawWhite: |
| 43 | dataBit = 0; |
| 44 | maskBit = 1; |
| 45 | break; |
| 46 | case kRawTransparent: |
| 47 | dataBit = 0; |
| 48 | maskBit = 0; |
| 49 | break; |
| 50 | default: |
| 51 | assert("Invalid character in cursor bitmap!"); |
| 52 | } |
| 53 | |
| 54 | dataByte |= (dataBit << (7 - curBit)); |
| 55 | maskByte |= (maskBit << (7 - curBit)); |
| 56 | |
| 57 | // Save dataBit once 8 chars have been processed. |
| 58 | curBit = (curBit + 1) % 8; |
| 59 | if (curBit == 0) |
| 60 | { |
| 61 | newCursor.Data[curPixel] = dataByte; |
| 62 | newCursor.Mask[curPixel] = maskByte; |
| 63 | |
| 64 | dataByte = 0; |
| 65 | maskByte = 0; |
| 66 | curPixel++; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return newCursor; |
| 71 | } |
| 72 | |
| 73 | static constexpr CursorData kBlankCursorData = { { 0, 0 }, { 0 }, { 0 } }; |
| 74 | |