Skip to content

Commit

Permalink
switched color back to using a hex string
Browse files Browse the repository at this point in the history
  • Loading branch information
benni-tec committed Dec 20, 2024
1 parent 4d3786c commit 82a2b34
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions packages/tiled/lib/src/common/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@ part of tiled;
class ColorData {
static int _sub(int hex, int index) => (hex >> index * 8) & 0x000000ff;

final int red;
final int green;
final int blue;
final int alpha;
final int _hex;

int get alpha => _sub(_hex, 3);

int get red => _sub(_hex, 2);

int get green => _sub(_hex, 1);

int get blue => _sub(_hex, 0);

/// Parses the Color from an int using the lower 32-bits and tiled's format: 0xaarrggbb
ColorData.hex(int hex)
: alpha = _sub(hex, 3),
red = _sub(hex, 2),
green = _sub(hex, 1),
blue = _sub(hex, 0);
const ColorData.hex(this._hex);

const ColorData.rgb(int red, int green, int blue, [int alpha = 255])
: assert(red >= 0 && red <= 255),
assert(green >= 0 && green <= 255),
assert(blue >= 0 && blue <= 255),
assert(alpha >= 0 && alpha <= 255),
_hex = (alpha << 3 * 8) + (red << 2 * 8) + (green << 1 * 8) +
(blue << 0 * 8);

const ColorData.rgb(this.red, this.green, this.blue, [this.alpha = 255])
const ColorData.argb(int alpha, int red, int green, int blue)
: assert(red >= 0 && red <= 255),
assert(green >= 0 && green <= 255),
assert(blue >= 0 && blue <= 255),
assert(alpha >= 0 && alpha <= 255);
assert(alpha >= 0 && alpha <= 255),
_hex = (alpha << 3 * 8) + (red << 2 * 8) + (green << 1 * 8) +
(blue << 0 * 8);
}

0 comments on commit 82a2b34

Please sign in to comment.