No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

color.h 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* The MIT License
  2. *
  3. * Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #ifndef COLOR_H
  24. #define COLOR_H
  25. #include "prerequisites.h"
  26. typedef uint32 RGBA;
  27. class Color
  28. {
  29. public:
  30. Color() : color(0) { }
  31. Color(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) : color(((r & 0xff)<<24) | ((g & 0xff)<<16) | ((b & 0xff)<<8) | (a & 0xff)) { }
  32. Color(const Color& other) : color(other.color) { }
  33. Color(RGBA rgba) : color(rgba) { }
  34. uint8 red() const { return (color >> 24) & 0xFF; }
  35. uint8 green() const { return (color >> 16) & 0xFF; }
  36. uint8 blue() const { return (color >> 8) & 0xFF; }
  37. uint8 alpha() const { return color & 0xFF; }
  38. RGBA rgba() const { return color; }
  39. const uint8* rgbaPtr() const { return (const uint8*)&color; }
  40. void setRed(uint8 r) { color = ((r & 0xff)<<24) | (color & 0x00ffffff); }
  41. void setGreen(uint8 g) { color = ((g & 0xff)<<16) | (color & 0xff00ffff); }
  42. void setBlue(uint8 b) { color = ((b & 0xff)<<8) | (color & 0xffff00ff); }
  43. void setAlpha(uint8 a) { color = (a & 0xff) | (color & 0xffffff00); }
  44. void setRGBA(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) { color = ((r & 0xff)<<24) | ((g & 0xff)<<16) | ((b & 0xff)<<8) | (a & 0xff); }
  45. void setRGBA(uint32 rgba) { color = rgba; }
  46. Color& operator=(const Color& other) { color = other.color; return *this; }
  47. bool operator==(const Color& other) const { return other.color == color; }
  48. bool operator!=(const Color& other) const { return other.color != color; }
  49. private:
  50. RGBA color;
  51. };
  52. #endif // COLOR_H