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.

olcPGE_Sprite.h 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef OLC_PGE_SPRITE
  2. #define OLC_PGE_SPRITE
  3. #ifdef _WIN32
  4. // Link to libraries
  5. #ifndef __MINGW32__
  6. #pragma comment(lib, "user32.lib") // Visual Studio Only
  7. #pragma comment(lib, "gdi32.lib") // For other Windows Compilers please add
  8. #pragma comment(lib, "gdiplus.lib") // these libs to your linker input
  9. #else
  10. // In Code::Blocks, Select C++14 in your build options, and add the
  11. // following libs to your linker: user32 gdi32 opengl32 gdiplus
  12. #if !defined _WIN32_WINNT
  13. #ifdef HAVE_MSMF
  14. #define _WIN32_WINNT 0x0600 // Windows Vista
  15. #else
  16. #define _WIN32_WINNT 0x0500 // Windows 2000
  17. #endif
  18. #endif
  19. #endif
  20. // Include WinAPI
  21. #include <windows.h>
  22. #include <gdiplus.h>
  23. #else
  24. #include <png.h>
  25. #endif
  26. #include <cstdint>
  27. #include <cmath>
  28. #include <string>
  29. #include <map>
  30. #include <vector>
  31. #include <streambuf>
  32. #include <iostream>
  33. #include <fstream>
  34. #include "olcPGE_Common.h"
  35. #include "olcPGE_Pixel.h"
  36. #include "olcPGE_ResourcePack.h"
  37. namespace olc {
  38. // A bitmap-like structure that stores a 2D array of Pixels
  39. class Sprite
  40. {
  41. public:
  42. Sprite();
  43. Sprite(std::string sImageFile);
  44. Sprite(std::string sImageFile, olc::ResourcePack *pack);
  45. Sprite(int32_t w, int32_t h);
  46. ~Sprite();
  47. public:
  48. olc::rcode LoadFromFile(std::string sImageFile, olc::ResourcePack *pack = nullptr);
  49. olc::rcode LoadFromPGESprFile(std::string sImageFile, olc::ResourcePack *pack = nullptr);
  50. olc::rcode SaveToPGESprFile(std::string sImageFile);
  51. public:
  52. int32_t width = 0;
  53. int32_t height = 0;
  54. enum Mode { NORMAL, PERIODIC };
  55. public:
  56. void SetSampleMode(olc::Sprite::Mode mode = olc::Sprite::Mode::NORMAL);
  57. Pixel GetPixel(int32_t x, int32_t y);
  58. bool SetPixel(int32_t x, int32_t y, Pixel p);
  59. Pixel Sample(float x, float y);
  60. Pixel SampleBL(float u, float v);
  61. Pixel* GetData();
  62. private:
  63. Pixel *pColData = nullptr;
  64. Mode modeSample = Mode::NORMAL;
  65. #ifdef OLC_DBG_OVERDRAW
  66. public:
  67. static int nOverdrawCount;
  68. #endif
  69. };
  70. }
  71. #endif