diff options
Diffstat (limited to 'src/libjin/Graphics')
-rw-r--r-- | src/libjin/Graphics/je_bitmap.cpp | 20 | ||||
-rw-r--r-- | src/libjin/Graphics/je_bitmap.h | 2 | ||||
-rw-r--r-- | src/libjin/Graphics/je_sprite.h | 2 |
3 files changed, 20 insertions, 4 deletions
diff --git a/src/libjin/Graphics/je_bitmap.cpp b/src/libjin/Graphics/je_bitmap.cpp index 711b8b5..cdab46d 100644 --- a/src/libjin/Graphics/je_bitmap.cpp +++ b/src/libjin/Graphics/je_bitmap.cpp @@ -56,6 +56,20 @@ namespace JinEngine return bitmap; } + /*static*/ Bitmap* Bitmap::createBitmap(int width, int height, std::function<Color(int, int, int, int)> drawer) + { + Bitmap* bitmap = new Bitmap(width, height); + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + Color c = drawer(width, height, x, y); + bitmap->setPixel(c, x, y); + } + } + return bitmap; + } + /*static */ Bitmap* Bitmap::clone(const Bitmap* bitmap) { Bitmap* b = new Bitmap(); @@ -78,7 +92,7 @@ namespace JinEngine height = h; pixels = new Color[w*h]; if (pixels == nullptr) - throw Exception("Not enough memory."); + throw Exception("No enough memory."); } Bitmap::~Bitmap() @@ -110,8 +124,8 @@ namespace JinEngine void Bitmap::setPixel(const Color& c, int x, int y) { - if (pixels == nullptr) - return; + if (pixels == nullptr) + throw Exception("Bitmap don't have pixel space."); if (without<int>(x, 0, width - 1) || without<int>(y, 0, height - 1)) return; if (x + y * width >= width * height) diff --git a/src/libjin/Graphics/je_bitmap.h b/src/libjin/Graphics/je_bitmap.h index c3041f8..5ab11ca 100644 --- a/src/libjin/Graphics/je_bitmap.h +++ b/src/libjin/Graphics/je_bitmap.h @@ -67,7 +67,7 @@ namespace JinEngine /// /// Create bitmap and set bitmap pixels with given drawer. /// - static Bitmap* createBitmap(int width, int height, std::function<Color(int, int)> drawer); + static Bitmap* createBitmap(int width, int height, std::function<Color(int, int, int, int)> drawer); /// /// Create bitmap with another one. diff --git a/src/libjin/Graphics/je_sprite.h b/src/libjin/Graphics/je_sprite.h index d48fbbc..65e00eb 100644 --- a/src/libjin/Graphics/je_sprite.h +++ b/src/libjin/Graphics/je_sprite.h @@ -55,6 +55,8 @@ namespace JinEngine const Math::Vector2<int>& getOrigin() { return mOrigin; } const Math::Vector2<float>& getScale() { return mScale; } const Color& getColor() { return mColor; } + const Graphic* getGraphic() { return mGraphic; } + const Shaders::Shader* getShader() { return mShader; } /// /// Render callback. |