diff options
Diffstat (limited to 'src/libjin/Graphics/je_bitmap.cpp')
-rw-r--r-- | src/libjin/Graphics/je_bitmap.cpp | 20 |
1 files changed, 17 insertions, 3 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) |