From 7e51ff3bfae0becc260452a427a1fc1232a4b348 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 15 Nov 2018 19:29:27 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/Graphics/je_bitmap.cpp | 20 +++++++++++++++++--- src/libjin/Graphics/je_bitmap.h | 2 +- src/libjin/Graphics/je_sprite.h | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src/libjin/Graphics') 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 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(x, 0, width - 1) || without(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 drawer); + static Bitmap* createBitmap(int width, int height, std::function 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& getOrigin() { return mOrigin; } const Math::Vector2& getScale() { return mScale; } const Color& getColor() { return mColor; } + const Graphic* getGraphic() { return mGraphic; } + const Shaders::Shader* getShader() { return mShader; } /// /// Render callback. -- cgit v1.1-26-g67d0