diff options
author | chai <chaifix@163.com> | 2018-11-15 19:29:27 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-11-15 19:29:27 +0800 |
commit | 7e51ff3bfae0becc260452a427a1fc1232a4b348 (patch) | |
tree | e2c4cddcd5ed719a611be4c92edf1991a63203c5 /src/libjin/Graphics/je_bitmap.cpp | |
parent | a6f2d5fff89b7322009c46a9272668ca4c32ce64 (diff) |
*修改代码结构
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) |