From 91e589d1678a8187c307e09b98b67ec4133092ff Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 19 Jan 2019 01:44:05 +0800 Subject: =?UTF-8?q?*=E6=B8=B8=E6=88=8F=E6=A1=86=E6=9E=B6=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Asura.Engine/Graphics/Image.h | 119 +++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Source/Asura.Engine/Graphics/Image.h (limited to 'Source/Asura.Engine/Graphics/Image.h') diff --git a/Source/Asura.Engine/Graphics/Image.h b/Source/Asura.Engine/Graphics/Image.h new file mode 100644 index 0000000..5b27079 --- /dev/null +++ b/Source/Asura.Engine/Graphics/Image.h @@ -0,0 +1,119 @@ +#ifndef __AE_IMAGE_H__ +#define __AE_IMAGE_H__ + +#include "Math/Vector2.h" +#include "Manager.hpp" +#include "Texture.h" +#include "Color.h" +#include "Factory.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageFactory; + + /// + /// Image是图片从内存中载入后,读取进游戏后保存的结果。一个Image在内存、显存中只会保存一份,不会产生副本。需要特征 + /// 化的区别image,如锚点位置,缩放和旋转角度,使用sprite。基本是一个只读类。 + /// + class Image final : public Texture, public Filesystem::Asset + { + public: + + uint GetWidth(); + uint GetHeight(); + + /// + /// 获得某一个位置的像素 + /// + Color GetPixel(uint x, uint y); + + private: + + friend class ImageFactory; + + Image(Color* pixels, int width, int height); + ~Image(); + + /// + /// 大小(以像素为单位) + /// + uint mWidth, mHeight; + Color* mPixels; + + /// + /// ID + /// + uint mID; + + }; + + /// + /// + /// + class ImageManager : public Manager + { + public: + + /// + /// 通过ID获取路径,如果是程序创建的图片,返回String::Null + /// + Containers::String GetImagePath(uint ID); + + /// + /// 通过ID路径获取ID,如果没找到,返回0 + /// + uint GetImageID(const Containers::String& path); + + Image* GetImage(const Containers::String& path); + + Image* GetImage(const Containers::String& ID); + + uint AddImage(const Containers::String& path, Image* image); + + uint AddImage(Image* image); + + bool RemoveImage(uint ID); + + bool RemoveImage(Image* image); + + private: + + /// + /// 所有的image + /// + Containers::Map mImages; + + /// + /// image,路径和ID的映射。针对从.asr导入的image,通过路径可以拿到image。所以并不是所有的image都在此map中。 + /// 由程序创建的image只能通过ID来获取,所以程序中需要保留ID。 + /// + Containers::StringMap mImageIDs; + + }; + + /// + /// + /// + class ImageFactory : public Factory + { + public: + + /// + /// 从image pixel数据中构建image + /// + Image* ReadBuffer(Color* pixels, int width, int height); + + /// + /// 从image extern数据并返回 + /// + Image* Decode(); + + }; + + } +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0