SDL_Extensions.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SDL_Extensions.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../../lib/Rect.h"
  12. #include "../../lib/Color.h"
  13. struct SDL_Rect;
  14. struct SDL_Surface;
  15. struct SDL_Color;
  16. namespace CSDL_Ext
  17. {
  18. /// creates Rect using provided rect
  19. Rect fromSDL(const SDL_Rect & rect);
  20. /// creates SDL_Rect using provided rect
  21. SDL_Rect toSDL(const Rect & rect);
  22. /// creates Color using provided SDL_Color
  23. ColorRGBA fromSDL(const SDL_Color & color);
  24. /// creates SDL_Color using provided Color
  25. SDL_Color toSDL(const ColorRGBA & color);
  26. void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst);
  27. void blitAt(SDL_Surface * src, const Rect & pos, SDL_Surface * dst);
  28. void setClipRect(SDL_Surface * src, const Rect & other);
  29. void getClipRect(SDL_Surface * src, Rect & other);
  30. void blitSurface(SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dest);
  31. void blitSurface(SDL_Surface * src, SDL_Surface * dst, const Point & dest);
  32. void fillSurface(SDL_Surface * dst, const SDL_Color & color);
  33. void fillRect(SDL_Surface * dst, const Rect & dstrect, const SDL_Color & color);
  34. void fillRectBlended(SDL_Surface * dst, const Rect & dstrect, const SDL_Color & color);
  35. void putPixelWithoutRefresh(SDL_Surface * ekran, const int & x, const int & y, const uint8_t & R, const uint8_t & G, const uint8_t & B, uint8_t A = 255);
  36. void putPixelWithoutRefreshIfInSurf(SDL_Surface *ekran, const int & x, const int & y, const uint8_t & R, const uint8_t & G, const uint8_t & B, uint8_t A = 255);
  37. SDL_Surface * verticalFlip(SDL_Surface * toRot); //vertical flip
  38. SDL_Surface * horizontalFlip(SDL_Surface * toRot); //horizontal flip
  39. uint32_t getPixel(SDL_Surface * surface, const int & x, const int & y, bool colorByte = false);
  40. uint8_t * getPxPtr(const SDL_Surface * const & srf, const int x, const int y);
  41. template<int bpp, bool useAlpha>
  42. int blit8bppAlphaTo24bppT(const SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dstPoint, uint8_t alpha); //blits 8 bpp surface with alpha channel to 24 bpp surface
  43. int blit8bppAlphaTo24bpp(const SDL_Surface * src, const Rect & srcRect, SDL_Surface * dst, const Point & dstPoint, uint8_t alpha); //blits 8 bpp surface with alpha channel to 24 bpp surface
  44. uint32_t colorTouint32_t(const SDL_Color * color); //little endian only
  45. void drawLine(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color1, const SDL_Color & color2, int width);
  46. void drawLineDashed(SDL_Surface * sur, const Point & from, const Point & dest, const SDL_Color & color);
  47. void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const SDL_Color & color, int depth = 1);
  48. void drawBorder(SDL_Surface * sur, const Rect & r, const SDL_Color & color, int depth = 1);
  49. SDL_Surface * newSurface(const Point & dimensions, SDL_Surface * mod); //creates new surface, with flags/format same as in surface given
  50. SDL_Surface * newSurface(const Point & dimensions); //creates new surface, with flags/format same as in screen surface
  51. void convertToGrayscale(SDL_Surface * surf, const Rect & rect);
  52. void convertToH2Scheme(SDL_Surface * surf, const Rect & rect);
  53. void setColorKey(SDL_Surface * surface, SDL_Color color);
  54. ///set key-color to 0,255,255
  55. void setDefaultColorKey(SDL_Surface * surface);
  56. ///set key-color to 0,255,255 only if it exactly mapped
  57. void setDefaultColorKeyPresize(SDL_Surface * surface);
  58. SDL_Surface * drawOutline(SDL_Surface * source, const SDL_Color & color, int thickness);
  59. SDL_Surface * drawShadow(SDL_Surface * source, bool doSheer);
  60. }