remove easy2d::String class & refactory easy2d::Resource class

refactoring: move Random class to utils.h
This commit is contained in:
Haibo 2018-10-28 23:24:01 +08:00 committed by Nomango
parent 301c99018b
commit 380bde7932
28 changed files with 462 additions and 1139 deletions

View File

@ -52,12 +52,12 @@ void easy2d::Action::Stop()
done_ = true; done_ = true;
} }
const easy2d::String& easy2d::Action::GetName() const const std::wstring& easy2d::Action::GetName() const
{ {
return name_; return name_;
} }
void easy2d::Action::SetName(const String& name) void easy2d::Action::SetName(const std::wstring& name)
{ {
name_ = name; name_ = name;
} }

View File

@ -60,11 +60,11 @@ namespace easy2d
virtual void Stop(); virtual void Stop();
// 获取动作名称 // 获取动作名称
virtual const String& GetName() const; virtual const std::wstring& GetName() const;
// 设置动作名称 // 设置动作名称
virtual void SetName( virtual void SetName(
const String& name const std::wstring& name
); );
// 获取动作的拷贝 // 获取动作的拷贝
@ -100,7 +100,7 @@ namespace easy2d
E2D_DISABLE_COPY(Action); E2D_DISABLE_COPY(Action);
protected: protected:
String name_; std::wstring name_;
bool running_; bool running_;
bool done_; bool done_;
bool initialized_; bool initialized_;

View File

@ -232,7 +232,7 @@ namespace easy2d
// ÉèÖô°Ìå±êÌâ // ÉèÖô°Ìå±êÌâ
void SetTitle( void SetTitle(
const String& title /* ´°Ìå±êÌâ */ const std::wstring& title /* ´°Ìå±êÌâ */
); );
// ÉèÖô°Ìåͼ±ê // ÉèÖô°Ìåͼ±ê
@ -246,7 +246,7 @@ namespace easy2d
); );
// »ñÈ¡´°Ìå±êÌâ // »ñÈ¡´°Ìå±êÌâ
const String& GetTitle() const; const std::wstring& GetTitle() const;
// »ñÈ¡´°Ìå¿í¶È // »ñÈ¡´°Ìå¿í¶È
int GetWidth() const; int GetWidth() const;
@ -310,7 +310,7 @@ namespace easy2d
private: private:
HWND hwnd_; HWND hwnd_;
String title_; std::wstring title_;
int width_; int width_;
int height_; int height_;
int icon_; int icon_;

View File

@ -37,20 +37,20 @@ namespace easy2d
Image(); Image();
explicit Image( explicit Image(
const Resource& res Resource& res
); );
explicit Image( explicit Image(
const Resource& res, Resource& res,
const Rect& crop_rect /* 裁剪矩形 */ const Rect& crop_rect /* 裁剪矩形 */
); );
explicit Image( explicit Image(
const String& file_name const std::wstring& file_name
); );
explicit Image( explicit Image(
const String& file_name, const std::wstring& file_name,
const Rect& crop_rect /* 裁剪矩形 */ const Rect& crop_rect /* 裁剪矩形 */
); );
@ -58,12 +58,12 @@ namespace easy2d
// 加载图片资源 // 加载图片资源
bool Load( bool Load(
const Resource& res Resource& res
); );
// 加载图片资源 // 加载图片资源
bool Load( bool Load(
const String& file_name const std::wstring& file_name
); );
// 将图片裁剪为矩形 // 将图片裁剪为矩形
@ -112,12 +112,12 @@ namespace easy2d
// 缓存 Bitmap 资源 // 缓存 Bitmap 资源
static bool CacheBitmap( static bool CacheBitmap(
const String& file_name const std::wstring& file_name
); );
// 缓存 Bitmap 资源 // 缓存 Bitmap 资源
static bool CacheBitmap( static bool CacheBitmap(
const Resource& res Resource& res
); );
// 设置 Bitmap // 设置 Bitmap
@ -204,14 +204,14 @@ namespace easy2d
public: public:
explicit Task( explicit Task(
const Function& func, /* 执行函数 */ const Function& func, /* 执行函数 */
const String& name = L"" /* ÈÎÎñÃû³Æ */ const std::wstring& name = L"" /* 任务名称 */
); );
explicit Task( explicit Task(
const Function& func, /* 执行函数 */ const Function& func, /* 执行函数 */
float delay, /* 时间间隔(秒) */ float delay, /* 时间间隔(秒) */
int times = -1, /* 执行次数(设 -1 为永久执行) */ int times = -1, /* 执行次数(设 -1 为永久执行) */
const String& name = L"" /* ÈÎÎñÃû³Æ */ const std::wstring& name = L"" /* 任务名称 */
); );
// 启动任务 // 启动任务
@ -224,7 +224,7 @@ namespace easy2d
bool IsRunning() const; bool IsRunning() const;
// 获取任务名称 // 获取任务名称
const String& GetName() const; const std::wstring& GetName() const;
// 任务是否就绪 // 任务是否就绪
bool IsReady() const; bool IsReady() const;
@ -240,7 +240,7 @@ namespace easy2d
bool stopped_; bool stopped_;
int run_times_; int run_times_;
int total_times_; int total_times_;
String name_; std::wstring name_;
Duration delay_; Duration delay_;
Time last_time_; Time last_time_;
Function callback_; Function callback_;
@ -294,7 +294,7 @@ namespace easy2d
bool IsVisible() const; bool IsVisible() const;
// 获取节点名称 // 获取节点名称
const String& GetName() const; const std::wstring& GetName() const;
// 获取节点名称的 Hash 值 // 获取节点名称的 Hash 值
size_t GetHashName() const; size_t GetHashName() const;
@ -366,7 +366,7 @@ namespace easy2d
// 设置节点名称 // 设置节点名称
void SetName( void SetName(
const String& name const std::wstring& name
); );
// 设置节点横坐标 // 设置节点横坐标
@ -542,12 +542,12 @@ namespace easy2d
// 获取所有名称相同的子节点 // 获取所有名称相同的子节点
Nodes GetChildren( Nodes GetChildren(
const String& name const std::wstring& name
) const; ) const;
// 获取名称相同的子节点 // 获取名称相同的子节点
Node* GetChild( Node* GetChild(
const String& name const std::wstring& name
) const; ) const;
// 获取所有子节点 // 获取所有子节点
@ -563,7 +563,7 @@ namespace easy2d
// 移除所有名称相同的子节点 // 移除所有名称相同的子节点
void RemoveChildren( void RemoveChildren(
const String& child_name const std::wstring& child_name
); );
// 移除所有节点 // 移除所有节点
@ -579,17 +579,17 @@ namespace easy2d
// 继续动作 // 继续动作
void ResumeAction( void ResumeAction(
const String& name const std::wstring& name
); );
// 暂停动作 // 暂停动作
void PauseAction( void PauseAction(
const String& name const std::wstring& name
); );
// 停止动作 // 停止动作
void StopAction( void StopAction(
const String& name const std::wstring& name
); );
// 继续所有暂停动作 // 继续所有暂停动作
@ -611,17 +611,17 @@ namespace easy2d
// 启动任务 // 启动任务
void StartTasks( void StartTasks(
const String& task_name const std::wstring& task_name
); );
// 停止任务 // 停止任务
void StopTasks( void StopTasks(
const String& task_name const std::wstring& task_name
); );
// 移除任务 // 移除任务
void RemoveTasks( void RemoveTasks(
const String& task_name const std::wstring& task_name
); );
// 启动所有任务 // 启动所有任务
@ -682,7 +682,7 @@ namespace easy2d
void UpdateTime(); void UpdateTime();
private: private:
String name_; std::wstring name_;
size_t hash_name_; size_t hash_name_;
Transform transform_; Transform transform_;
float display_opacity_; float display_opacity_;
@ -716,20 +716,20 @@ namespace easy2d
); );
explicit Sprite( explicit Sprite(
const Resource& res Resource& res
); );
explicit Sprite( explicit Sprite(
const Resource& res, Resource& res,
const Rect& crop_rect /* 裁剪矩形 */ const Rect& crop_rect /* 裁剪矩形 */
); );
explicit Sprite( explicit Sprite(
const String& file_name const std::wstring& file_name
); );
explicit Sprite( explicit Sprite(
const String& file_name, const std::wstring& file_name,
const Rect& crop_rect /* 裁剪矩形 */ const Rect& crop_rect /* 裁剪矩形 */
); );
@ -737,12 +737,12 @@ namespace easy2d
// 加载图片文件 // 加载图片文件
bool Load( bool Load(
const Resource& res Resource& res
); );
// 加载图片文件 // 加载图片文件
bool Load( bool Load(
const String& file_name const std::wstring& file_name
); );
// 加载图片 // 加载图片
@ -820,7 +820,7 @@ namespace easy2d
Text(); Text();
explicit Text( explicit Text(
const String& text, /* ÎÄ×ÖÄÚÈÝ */ const std::wstring& text, /* 文字内容 */
const Font& font = Font(), /* 字体 */ const Font& font = Font(), /* 字体 */
const Style& style = Style() /* 文本样式 */ const Style& style = Style() /* 文本样式 */
); );
@ -828,7 +828,7 @@ namespace easy2d
virtual ~Text(); virtual ~Text();
// 获取文本 // 获取文本
const String& GetText() const; const std::wstring& GetText() const;
// 获取字体 // 获取字体
const Font& GetFont() const; const Font& GetFont() const;
@ -837,7 +837,7 @@ namespace easy2d
const Style& GetStyle() const; const Style& GetStyle() const;
// 获取字体族 // 获取字体族
const String& GetFontFamily() const; const std::wstring& GetFontFamily() const;
// 获取当前字号 // 获取当前字号
float GetFontSize() const; float GetFontSize() const;
@ -874,7 +874,7 @@ namespace easy2d
// 设置文本 // 设置文本
void SetText( void SetText(
const String& text const std::wstring& text
); );
// 设置文本样式 // 设置文本样式
@ -889,7 +889,7 @@ namespace easy2d
// 设置字体族 // 设置字体族
void SetFontFamily( void SetFontFamily(
const String& family const std::wstring& family
); );
// 设置字号(默认值为 22 // 设置字号(默认值为 22
@ -978,7 +978,7 @@ namespace easy2d
void CreateLayout(); void CreateLayout();
private: private:
String text_; std::wstring text_;
Font font_; Font font_;
Style style_; Style style_;
IDWriteTextFormat* text_format_; IDWriteTextFormat* text_format_;

View File

@ -78,23 +78,23 @@ namespace easy2d
Music(); Music();
Music( Music(
const easy2d::String& file_path /* 音乐文件路径 */ const std::wstring& file_path /* 音乐文件路径 */
); );
Music( Music(
const Resource& res /* 音乐资源 */ Resource& res /* 音乐资源 */
); );
virtual ~Music(); virtual ~Music();
// 打开音乐文件 // 打开音乐文件
bool Load( bool Load(
const easy2d::String& file_path /* 音乐文件路径 */ const std::wstring& file_path /* 音乐文件路径 */
); );
// 打开音乐资源 // 打开音乐资源
bool Load( bool Load(
const Resource& res /* 音乐资源 */ Resource& res /* 音乐资源 */
); );
// 播放 // 播放
@ -150,64 +150,64 @@ namespace easy2d
// 预加载音乐资源 // 预加载音乐资源
bool Load( bool Load(
const String& file_path /* 音乐文件路径 */ const std::wstring& file_path /* 音乐文件路径 */
); );
// 播放音乐 // 播放音乐
bool Play( bool Play(
const String& file_path, /* 音乐文件路径 */ const std::wstring& file_path, /* 音乐文件路径 */
int loop_count = 0 /* 播放循环次数 (-1 为循环播放) */ int loop_count = 0 /* 播放循环次数 (-1 为循环播放) */
); );
// 暂停音乐 // 暂停音乐
void Pause( void Pause(
const String& file_path /* 音乐文件路径 */ const std::wstring& file_path /* 音乐文件路径 */
); );
// 继续播放音乐 // 继续播放音乐
void Resume( void Resume(
const String& file_path /* 音乐文件路径 */ const std::wstring& file_path /* 音乐文件路径 */
); );
// 停止音乐 // 停止音乐
void Stop( void Stop(
const String& file_path /* 音乐文件路径 */ const std::wstring& file_path /* 音乐文件路径 */
); );
// 获取音乐播放状态 // 获取音乐播放状态
bool IsPlaying( bool IsPlaying(
const String& file_path /* 音乐文件路径 */ const std::wstring& file_path /* 音乐文件路径 */
); );
// 预加载音乐资源 // 预加载音乐资源
bool Load( bool Load(
const Resource& res /* 音乐资源 */ Resource& res /* 音乐资源 */
); );
// 播放音乐 // 播放音乐
bool Play( bool Play(
const Resource& res, /* 音乐资源 */ Resource& res, /* 音乐资源 */
int loop_count = 0 /* 播放循环次数 (-1 为循环播放) */ int loop_count = 0 /* 播放循环次数 (-1 为循环播放) */
); );
// 暂停音乐 // 暂停音乐
void Pause( void Pause(
const Resource& res /* 音乐资源 */ Resource& res /* 音乐资源 */
); );
// 继续播放音乐 // 继续播放音乐
void Resume( void Resume(
const Resource& res /* 音乐资源 */ Resource& res /* 音乐资源 */
); );
// 停止音乐 // 停止音乐
void Stop( void Stop(
const Resource& res /* 音乐资源 */ Resource& res /* 音乐资源 */
); );
// 获取音乐播放状态 // 获取音乐播放状态
bool IsPlaying( bool IsPlaying(
const Resource& res /* 音乐资源 */ Resource& res /* 音乐资源 */
); );
// 获取音量 // 获取音量
@ -245,8 +245,8 @@ namespace easy2d
{ {
public: public:
Data( Data(
const String& key, /* 键值 */ const std::wstring& key, /* 键值 */
const String& field = L"Defalut" /* 字段名称 */ const std::wstring& field = L"Defalut" /* 字段名称 */
); );
// 该数据是否存在 // 该数据是否存在
@ -272,9 +272,9 @@ namespace easy2d
bool value bool value
); );
// 保存 String 类型的值 // 保存 std::wstring 类型的值
bool SaveString( bool SaveString(
const String& value const std::wstring& value
); );
// 获取 int 类型的值 // 获取 int 类型的值
@ -290,12 +290,12 @@ namespace easy2d
bool GetBool() const; bool GetBool() const;
// 获取 字符串 类型的值 // 获取 字符串 类型的值
String GetString(); std::wstring GetString();
protected: protected:
String key_; std::wstring key_;
String field_; std::wstring field_;
const String& data_path_; const std::wstring& data_path_;
}; };
@ -306,14 +306,14 @@ namespace easy2d
File(); File();
File( File(
const String& file_name const std::wstring& file_name
); );
virtual ~File(); virtual ~File();
// 打开文件 // 打开文件
bool Open( bool Open(
const String& file_name const std::wstring& file_name
); );
// 文件是否存在 // 文件是否存在
@ -323,39 +323,39 @@ namespace easy2d
bool Delete(); bool Delete();
// 获取文件路径 // 获取文件路径
const String& GetPath() const; const std::wstring& GetPath() const;
// 获取文件扩展名 // 获取文件扩展名
String GetExtension() const; std::wstring GetExtension() const;
// 释放资源到临时文件目录 // 释放资源到临时文件目录
static File Extract( static File Extract(
const Resource& res, /* 资源 */ Resource& res, /* 资源 */
const String& dest_file_name /* 目标文件名 */ const std::wstring& dest_file_name /* 目标文件名 */
); );
// 添加文件搜索路径 // 添加文件搜索路径
static void AddSearchPath( static void AddSearchPath(
const String& path const std::wstring& path
); );
// 弹出打开文件对话框 // 弹出打开文件对话框
static File ShowOpenDialog( static File ShowOpenDialog(
const String& title = L"打开", /* 对话框标题 */ const std::wstring& title = L"打开", /* 对话框标题 */
const String& filter = L"" /* 筛选扩展名,例如 "*.jpg;*.jpeg" */ const std::wstring& filter = L"" /* 筛选扩展名,例如 "*.jpg;*.jpeg" */
); );
// 弹出保存文件对话框 // 弹出保存文件对话框
static File ShowSaveDialog( static File ShowSaveDialog(
const String& title = L"保存", /* 对话框标题 */ const std::wstring& title = L"保存", /* 对话框标题 */
const String& def_file = L"", /* 默认保存的文件名 */ const std::wstring& def_file = L"", /* 默认保存的文件名 */
const String& def_ext = L"" /* 默认追加的扩展名,例如 "txt" */ const std::wstring& def_ext = L"" /* 默认追加的扩展名,例如 "txt" */
); );
protected: protected:
String file_path_; std::wstring file_path_;
static std::list<String> search_paths_; static std::list<std::wstring> search_paths_;
}; };
@ -364,16 +364,16 @@ namespace easy2d
{ {
public: public:
// 获取数据的默认保存路径 // 获取数据的默认保存路径
static const String& GetDataPath(); static const std::wstring& GetDataPath();
// 获取临时文件目录 // 获取临时文件目录
static const String& GetTemporaryPath(); static const std::wstring& GetTemporaryPath();
// 获取 LocalAppData 目录 // 获取 LocalAppData 目录
static const String& GetLocalAppDataPath(); static const std::wstring& GetLocalAppDataPath();
// 获取当前程序的运行路径 // 获取当前程序的运行路径
static const String& GetExeFilePath(); static const std::wstring& GetExeFilePath();
}; };
} // end of easy2d namespace } // end of easy2d namespace

View File

@ -137,171 +137,6 @@ namespace easy2d
}; };
// 字符串
class String
{
public:
String();
String(
const String &
);
String(
const char *
);
String(
const wchar_t *
);
String(
String &&
);
~String();
// 获取字符串长度
int Length() const;
// 获取该字符串的 Hash 值
size_t GetHash() const;
// 判断字符串是否为空
bool IsEmpty() const;
// 获取指定位置字符
const wchar_t& At(
size_t index
) const;
// 比较字符串
int Compare(
const String & str
) const;
// 截取字符串
String Subtract(
int offset, /* 偏移量 */
int count = -1 /* 截取字符数量 */
) const;
// 插入字符串
void Insert(
const String & str,
int pos
);
// 替换字符串中的指定内容
void Replace(
const String & from, /* 需替换内容 */
const String & to /* 替换成内容 */
);
// 删除字符串中的指定内容
void Erase(
int offset, /* 偏移量 */
int count /* 删除字符数量 */
);
// 搜索字符串
int Find(
const String & str, /* 查找内容 */
int offset = 0 /* 偏移量 */
) const;
// 清空字符串
void Clear();
// 获取大写字符串
String ToUpper() const;
// 获取小写字符串
String ToLower() const;
// 将字符串转化为 int 型
int ToInt() const;
// 将字符串转化为 float 型
float ToFloat() const;
// 将字符串转化为 double 型
double ToDouble() const;
// 将字符串转化为 bool 型
bool ToBool() const;
// 数字类型转字符串
static String Parse(int value);
static String Parse(unsigned int value);
static String Parse(unsigned long long value);
static String Parse(float value);
static String Parse(double value);
// 格式化字符串
static String Format(const char * format, ...);
static String Format(const wchar_t * format, ...);
// 赋值运算符
String& operator= (const String &);
String& operator= (const char *);
String& operator= (const wchar_t *);
// 运算符
String& operator+= (const String &);
String& operator+= (const char *);
String& operator+= (const wchar_t *);
String operator+ (const String &) const;
String operator+ (const char *) const;
String operator+ (const wchar_t *) const;
// 友元运算符
friend String operator+ (const char *, const String &);
friend String operator+ (const wchar_t*, const String &);
// 类型转换操作符
E2D_OP_EXPLICIT operator const wchar_t* () const;
E2D_OP_EXPLICIT operator wchar_t* () const;
E2D_OP_EXPLICIT operator std::wstring() const;
E2D_OP_EXPLICIT operator std::string() const;
// 比较运算符
bool operator== (const String &) const;
bool operator== (const char *) const;
bool operator== (const wchar_t *) const;
bool operator!= (const String &) const;
bool operator!= (const char *) const;
bool operator!= (const wchar_t *) const;
bool operator> (const String &) const;
bool operator>= (const String &) const;
bool operator< (const String &) const;
bool operator<= (const String &) const;
// << 运算符(后接字符串)
String& operator<< (const String &);
String& operator<< (const char *);
String& operator<< (char *);
String& operator<< (const wchar_t *);
String& operator<< (wchar_t *);
String& operator<< (int value);
String& operator<< (unsigned int value);
String& operator<< (float value);
String& operator<< (double value);
// 其他运算符
wchar_t& operator[] (size_t);
friend std::ostream& operator<< (std::ostream &, const String &);
friend std::wostream& operator<< (std::wostream &, const String &);
friend std::istream& operator>> (std::istream &, String &);
friend std::wistream& operator>> (std::wistream &, String &);
private:
std::wstring string_;
};
// 颜色 // 颜色
class Color class Color
{ {
@ -608,7 +443,7 @@ namespace easy2d
class Font class Font
{ {
public: public:
String family; // 字体族 std::wstring family; // ×ÖÌå×å
float size; // 字号 float size; // 字号
UINT weight; // 粗细值 UINT weight; // 粗细值
bool italic; // 是否斜体 bool italic; // 是否斜体
@ -629,10 +464,8 @@ namespace easy2d
}; };
public: public:
Font();
explicit Font( explicit Font(
const String& family, const std::wstring& family = L"",
float size = 22, float size = 22,
UINT weight = Font::Weight::Normal, UINT weight = Font::Weight::Normal,
bool italic = false bool italic = false
@ -645,13 +478,28 @@ namespace easy2d
{ {
public: public:
Resource( Resource(
int resource_id, /* 资源名称 */ LPCWSTR name, /* ×ÊÔ´Ãû³Æ */
const String& resource_type /* 资源类型 */ LPCWSTR type /* ×ÊÔ´ÀàÐÍ */
); );
public: bool Load();
int id;
String type; LPCWSTR GetName() const;
LPCWSTR GetType() const;
LPVOID GetData() const;
DWORD GetDataSize() const;
size_t GetHashCode() const;
private:
bool loaded_;
LPCWSTR name_;
LPCWSTR type_;
LPVOID data_;
DWORD data_size_;
}; };

View File

@ -302,7 +302,7 @@ void easy2d::Game::Init()
hwnd_ = ::CreateWindowEx( hwnd_ = ::CreateWindowEx(
NULL, NULL,
REGISTER_CLASS, REGISTER_CLASS,
(LPCTSTR)title_, title_.c_str(),
WINDOW_STYLE, WINDOW_STYLE,
int(client_rect.origin.x), int(client_rect.origin.x),
int(client_rect.origin.y), int(client_rect.origin.y),
@ -421,7 +421,7 @@ HWND easy2d::Game::GetHWnd() const
return hwnd_; return hwnd_;
} }
const easy2d::String& easy2d::Game::GetTitle() const const std::wstring& easy2d::Game::GetTitle() const
{ {
return title_; return title_;
} }
@ -448,13 +448,13 @@ void easy2d::Game::SetSize(int width, int height)
} }
} }
void easy2d::Game::SetTitle(const String& title) void easy2d::Game::SetTitle(const std::wstring& title)
{ {
title_ = title; title_ = title;
if (hwnd_) if (hwnd_)
{ {
::SetWindowText(hwnd_, (LPCWSTR)title); ::SetWindowText(hwnd_, title.c_str());
} }
} }

View File

@ -660,7 +660,9 @@ void easy2d::Graphics::DrawDebugInfo()
++render_times_; ++render_times_;
if (duration >= 100) if (duration >= 100)
{ {
String fps_text = String::Format(L"FPS: %.1f", (1000.f / duration * render_times_)); wchar_t fps_text[12] = {};
int len = swprintf_s(fps_text, L"FPS: %.1f", 1000.f / duration * render_times_);
last_render_time_ = Time::Now(); last_render_time_ = Time::Now();
render_times_ = 0; render_times_ = 0;
@ -668,8 +670,8 @@ void easy2d::Graphics::DrawDebugInfo()
ThrowIfFailed( ThrowIfFailed(
write_factory_->CreateTextLayout( write_factory_->CreateTextLayout(
(const wchar_t *)fps_text, fps_text,
(UINT32)fps_text.Length(), static_cast<UINT32>(len),
fps_text_format_, fps_text_format_,
0, 0,
0, 0,

View File

@ -30,14 +30,14 @@ easy2d::Image::Image()
{ {
} }
easy2d::Image::Image(const Resource& res) easy2d::Image::Image(Resource& res)
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
this->Load(res); this->Load(res);
} }
easy2d::Image::Image(const Resource& res, const Rect& crop_rect) easy2d::Image::Image(Resource& res, const Rect& crop_rect)
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
@ -45,14 +45,14 @@ easy2d::Image::Image(const Resource& res, const Rect& crop_rect)
this->Crop(crop_rect); this->Crop(crop_rect);
} }
easy2d::Image::Image(const String & file_name) easy2d::Image::Image(const std::wstring & file_name)
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
this->Load(file_name); this->Load(file_name);
} }
easy2d::Image::Image(const String & file_name, const Rect & crop_rect) easy2d::Image::Image(const std::wstring & file_name, const Rect & crop_rect)
: bitmap_(nullptr) : bitmap_(nullptr)
, crop_rect_() , crop_rect_()
{ {
@ -65,7 +65,7 @@ easy2d::Image::~Image()
SafeRelease(bitmap_); SafeRelease(bitmap_);
} }
bool easy2d::Image::Load(const Resource& res) bool easy2d::Image::Load(Resource& res)
{ {
if (!Image::CacheBitmap(res)) if (!Image::CacheBitmap(res))
{ {
@ -73,15 +73,15 @@ bool easy2d::Image::Load(const Resource& res)
return false; return false;
} }
this->SetBitmap(bitmap_cache_.at(res.id)); this->SetBitmap(bitmap_cache_.at(res.GetHashCode()));
return true; return true;
} }
bool easy2d::Image::Load(const String & file_name) bool easy2d::Image::Load(const std::wstring & file_name)
{ {
E2D_WARNING_IF(file_name.IsEmpty(), "Image Load failed! Invalid file name."); E2D_WARNING_IF(file_name.empty(), "Image Load failed! Invalid file name.");
if (file_name.IsEmpty()) if (file_name.empty())
return false; return false;
if (!Image::CacheBitmap(file_name)) if (!Image::CacheBitmap(file_name))
@ -90,7 +90,7 @@ bool easy2d::Image::Load(const String & file_name)
return false; return false;
} }
this->SetBitmap(bitmap_cache_.at(file_name.GetHash())); this->SetBitmap(bitmap_cache_.at(std::hash<std::wstring>{}(file_name)));
return true; return true;
} }
@ -182,9 +182,10 @@ ID2D1Bitmap * easy2d::Image::GetBitmap() const
return bitmap_; return bitmap_;
} }
bool easy2d::Image::CacheBitmap(const Resource& res) bool easy2d::Image::CacheBitmap(Resource& res)
{ {
if (bitmap_cache_.find(res.id) != bitmap_cache_.end()) size_t hash_code = res.GetHashCode();
if (bitmap_cache_.find(hash_code) != bitmap_cache_.end())
{ {
return true; return true;
} }
@ -199,43 +200,9 @@ bool easy2d::Image::CacheBitmap(const Resource& res)
IWICStream* stream = nullptr; IWICStream* stream = nullptr;
IWICFormatConverter* converter = nullptr; IWICFormatConverter* converter = nullptr;
ID2D1Bitmap* bitmap = nullptr; ID2D1Bitmap* bitmap = nullptr;
HRSRC res_handle = nullptr;
HGLOBAL res_data_handle = nullptr;
LPVOID image_file = nullptr;
DWORD image_file_size = 0;
// 定位资源
res_handle = ::FindResourceW(
hinstance,
MAKEINTRESOURCE(res.id),
(LPCWSTR)res.type
);
hr = res_handle ? S_OK : E_FAIL;
if (SUCCEEDED(hr))
{
// 加载资源 // 加载资源
res_data_handle = ::LoadResource(hinstance, res_handle); hr = res.Load() ? S_OK : E_FAIL;
hr = res_data_handle ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// 获取文件指针,并锁定资源
image_file = ::LockResource(res_data_handle);
hr = image_file ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr))
{
// 计算大小
image_file_size = ::SizeofResource(hinstance, res_handle);
hr = image_file_size ? S_OK : E_FAIL;
}
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
@ -247,8 +214,8 @@ bool easy2d::Image::CacheBitmap(const Resource& res)
{ {
// 初始化流 // 初始化流
hr = stream->InitializeFromMemory( hr = stream->InitializeFromMemory(
reinterpret_cast<BYTE*>(image_file), static_cast<WICInProcPointer>(res.GetData()),
image_file_size res.GetDataSize()
); );
} }
@ -300,7 +267,7 @@ bool easy2d::Image::CacheBitmap(const Resource& res)
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
bitmap_cache_.insert(std::make_pair(res.id, bitmap)); bitmap_cache_.insert(std::make_pair(hash_code, bitmap));
} }
// 释放相关资源 // 释放相关资源
@ -312,10 +279,10 @@ bool easy2d::Image::CacheBitmap(const Resource& res)
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }
bool easy2d::Image::CacheBitmap(const String & file_name) bool easy2d::Image::CacheBitmap(const std::wstring & file_name)
{ {
size_t hash = file_name.GetHash(); size_t hash_code = std::hash<std::wstring>{}(file_name);
if (bitmap_cache_.find(hash) != bitmap_cache_.end()) if (bitmap_cache_.find(hash_code) != bitmap_cache_.end())
return true; return true;
File image_file; File image_file;
@ -324,7 +291,7 @@ bool easy2d::Image::CacheBitmap(const String & file_name)
// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加 // 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径 // 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
String image_file_path = image_file.GetPath(); std::wstring image_file_path = image_file.GetPath();
Graphics* graphics_device = Device::GetGraphics(); Graphics* graphics_device = Device::GetGraphics();
IWICImagingFactory* imaging_factory = graphics_device->GetImagingFactory(); IWICImagingFactory* imaging_factory = graphics_device->GetImagingFactory();
@ -337,7 +304,7 @@ bool easy2d::Image::CacheBitmap(const String & file_name)
// 创建解码器 // 创建解码器
HRESULT hr = imaging_factory->CreateDecoderFromFilename( HRESULT hr = imaging_factory->CreateDecoderFromFilename(
(LPCWSTR)image_file_path, image_file_path.c_str(),
nullptr, nullptr,
GENERIC_READ, GENERIC_READ,
WICDecodeMetadataCacheOnLoad, WICDecodeMetadataCacheOnLoad,
@ -381,7 +348,7 @@ bool easy2d::Image::CacheBitmap(const String & file_name)
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
bitmap_cache_.insert(std::make_pair(hash, bitmap)); bitmap_cache_.insert(std::make_pair(hash_code, bitmap));
} }
// 释放相关资源 // 释放相关资源

View File

@ -326,7 +326,7 @@ bool easy2d::Node::IsVisible() const
return visible_; return visible_;
} }
const easy2d::String& easy2d::Node::GetName() const const std::wstring& easy2d::Node::GetName() const
{ {
return name_; return name_;
} }
@ -653,15 +653,15 @@ easy2d::Scene * easy2d::Node::GetParentScene() const
return parent_scene_; return parent_scene_;
} }
easy2d::Node::Nodes easy2d::Node::GetChildren(const String& name) const easy2d::Node::Nodes easy2d::Node::GetChildren(const std::wstring& name) const
{ {
Nodes children; Nodes children;
size_t hash = name.GetHash(); size_t hash_code = std::hash<std::wstring>{}(name);
for (const auto& child : children_) for (const auto& child : children_)
{ {
// 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度
if (child->hash_name_ == hash && child->name_ == name) if (child->hash_name_ == hash_code && child->name_ == name)
{ {
children.push_back(child); children.push_back(child);
} }
@ -669,14 +669,14 @@ easy2d::Node::Nodes easy2d::Node::GetChildren(const String& name) const
return std::move(children); return std::move(children);
} }
easy2d::Node * easy2d::Node::GetChild(const String& name) const easy2d::Node * easy2d::Node::GetChild(const std::wstring& name) const
{ {
size_t hash = name.GetHash(); size_t hash_code = std::hash<std::wstring>{}(name);
for (const auto& child : children_) for (const auto& child : children_)
{ {
// 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度 // 不同的名称可能会有相同的 Hash 值,但是先比较 Hash 可以提升搜索速度
if (child->hash_name_ == hash && child->name_ == name) if (child->hash_name_ == hash_code && child->name_ == name)
{ {
return child; return child;
} }
@ -731,17 +731,17 @@ bool easy2d::Node::RemoveChild(Node * child)
return false; return false;
} }
void easy2d::Node::RemoveChildren(const String& child_name) void easy2d::Node::RemoveChildren(const std::wstring& child_name)
{ {
if (children_.empty()) if (children_.empty())
{ {
return; return;
} }
size_t hash = child_name.GetHash(); size_t hash_code = std::hash<std::wstring>{}(child_name);
for (auto iter = children_.begin(); iter != children_.end();) for (auto iter = children_.begin(); iter != children_.end();)
{ {
if ((*iter)->hash_name_ == hash && (*iter)->name_ == child_name) if ((*iter)->hash_name_ == hash_code && (*iter)->name_ == child_name)
{ {
(*iter)->parent_ = nullptr; (*iter)->parent_ = nullptr;
if ((*iter)->parent_scene_) if ((*iter)->parent_scene_)
@ -792,7 +792,7 @@ void easy2d::Node::RunAction(Action * action)
} }
} }
void easy2d::Node::ResumeAction(const String& name) void easy2d::Node::ResumeAction(const std::wstring& name)
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -806,7 +806,7 @@ void easy2d::Node::ResumeAction(const String& name)
} }
} }
void easy2d::Node::PauseAction(const String& name) void easy2d::Node::PauseAction(const std::wstring& name)
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -820,7 +820,7 @@ void easy2d::Node::PauseAction(const String& name)
} }
} }
void easy2d::Node::StopAction(const String& name) void easy2d::Node::StopAction(const std::wstring& name)
{ {
if (actions_.empty()) if (actions_.empty())
return; return;
@ -926,7 +926,7 @@ void easy2d::Node::AddTask(Task * task)
} }
} }
void easy2d::Node::StopTasks(const String& name) void easy2d::Node::StopTasks(const std::wstring& name)
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -937,7 +937,7 @@ void easy2d::Node::StopTasks(const String& name)
} }
} }
void easy2d::Node::StartTasks(const String& name) void easy2d::Node::StartTasks(const std::wstring& name)
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -948,7 +948,7 @@ void easy2d::Node::StartTasks(const String& name)
} }
} }
void easy2d::Node::RemoveTasks(const String& name) void easy2d::Node::RemoveTasks(const std::wstring& name)
{ {
for (const auto& task : tasks_) for (const auto& task : tasks_)
{ {
@ -1044,16 +1044,14 @@ void easy2d::Node::SetVisible(bool value)
visible_ = value; visible_ = value;
} }
void easy2d::Node::SetName(const String& name) void easy2d::Node::SetName(const std::wstring& name)
{ {
E2D_WARNING_IF(name.IsEmpty(), "Invalid Node name."); if (name_ != name)
if (!name.IsEmpty() && name_ != name)
{ {
// 保存节点名 // 保存节点名
name_ = name; name_ = name;
// 保存节点 Hash 名 // 保存节点 Hash 名
hash_name_ = name.GetHash(); hash_name_ = std::hash<std::wstring>{}(name);
} }
} }

View File

@ -32,26 +32,26 @@ easy2d::Sprite::Sprite(Image * image)
Load(image); Load(image);
} }
easy2d::Sprite::Sprite(const Resource& res) easy2d::Sprite::Sprite(Resource& res)
: image_(nullptr) : image_(nullptr)
{ {
Load(res); Load(res);
} }
easy2d::Sprite::Sprite(const Resource& res, const Rect& crop_rect) easy2d::Sprite::Sprite(Resource& res, const Rect& crop_rect)
: image_(nullptr) : image_(nullptr)
{ {
Load(res); Load(res);
Crop(crop_rect); Crop(crop_rect);
} }
easy2d::Sprite::Sprite(const String & file_name) easy2d::Sprite::Sprite(const std::wstring & file_name)
: image_(nullptr) : image_(nullptr)
{ {
Load(file_name); Load(file_name);
} }
easy2d::Sprite::Sprite(const String & file_name, const Rect & crop_rect) easy2d::Sprite::Sprite(const std::wstring & file_name, const Rect & crop_rect)
: image_(nullptr) : image_(nullptr)
{ {
Load(file_name); Load(file_name);
@ -81,7 +81,7 @@ bool easy2d::Sprite::Load(Image * image)
return false; return false;
} }
bool easy2d::Sprite::Load(const Resource& res) bool easy2d::Sprite::Load(Resource& res)
{ {
if (!image_) if (!image_)
{ {
@ -97,7 +97,7 @@ bool easy2d::Sprite::Load(const Resource& res)
return false; return false;
} }
bool easy2d::Sprite::Load(const String & file_name) bool easy2d::Sprite::Load(const std::wstring & file_name)
{ {
if (!image_) if (!image_)
{ {

View File

@ -21,7 +21,7 @@
#include "..\e2dobject.h" #include "..\e2dobject.h"
easy2d::Task::Task(const Function & func, const String & name) easy2d::Task::Task(const Function & func, const std::wstring & name)
: running_(true) : running_(true)
, stopped_(false) , stopped_(false)
, run_times_(0) , run_times_(0)
@ -32,7 +32,7 @@ easy2d::Task::Task(const Function & func, const String & name)
{ {
} }
easy2d::Task::Task(const Function & func, float delay, int times, const String & name) easy2d::Task::Task(const Function & func, float delay, int times, const std::wstring & name)
: running_(true) : running_(true)
, stopped_(false) , stopped_(false)
, run_times_(0) , run_times_(0)
@ -103,7 +103,7 @@ bool easy2d::Task::IsRunning() const
return running_; return running_;
} }
const easy2d::String& easy2d::Task::GetName() const const std::wstring& easy2d::Task::GetName() const
{ {
return name_; return name_;
} }

View File

@ -79,7 +79,7 @@ easy2d::Text::Text()
{ {
} }
easy2d::Text::Text(const String & text, const Font & font, const Style & style) easy2d::Text::Text(const std::wstring & text, const Font & font, const Style & style)
: font_(font) : font_(font)
, style_(style) , style_(style)
, text_layout_(nullptr) , text_layout_(nullptr)
@ -95,7 +95,7 @@ easy2d::Text::~Text()
SafeRelease(text_layout_); SafeRelease(text_layout_);
} }
const easy2d::String& easy2d::Text::GetText() const const std::wstring& easy2d::Text::GetText() const
{ {
return text_; return text_;
} }
@ -110,7 +110,7 @@ const easy2d::Text::Style& easy2d::Text::GetStyle() const
return style_; return style_;
} }
const easy2d::String& easy2d::Text::GetFontFamily() const const std::wstring& easy2d::Text::GetFontFamily() const
{ {
return font_.family; return font_.family;
} }
@ -179,7 +179,7 @@ bool easy2d::Text::outline() const
return style_.outline; return style_.outline;
} }
void easy2d::Text::SetText(const String& text) void easy2d::Text::SetText(const std::wstring& text)
{ {
text_ = text; text_ = text;
Reset(); Reset();
@ -197,7 +197,7 @@ void easy2d::Text::SetFont(const Font & font)
Reset(); Reset();
} }
void easy2d::Text::SetFontFamily(const String& family) void easy2d::Text::SetFontFamily(const std::wstring& family)
{ {
font_.family = family; font_.family = family;
Reset(); Reset();
@ -344,7 +344,7 @@ void easy2d::Text::CreateFormat()
ThrowIfFailed( ThrowIfFailed(
Device::GetGraphics()->GetWriteFactory()->CreateTextFormat( Device::GetGraphics()->GetWriteFactory()->CreateTextFormat(
(const wchar_t *)font_.family, font_.family.c_str(),
nullptr, nullptr,
DWRITE_FONT_WEIGHT(font_.weight), DWRITE_FONT_WEIGHT(font_.weight),
font_.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, font_.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
@ -388,7 +388,7 @@ void easy2d::Text::CreateLayout()
SafeRelease(text_layout_); SafeRelease(text_layout_);
// 文本为空字符串时,重置属性 // 文本为空字符串时,重置属性
if (text_.IsEmpty()) if (text_.empty())
{ {
this->SetSize(0, 0); this->SetSize(0, 0);
return; return;
@ -400,7 +400,7 @@ void easy2d::Text::CreateLayout()
return; return;
} }
UINT32 length = (UINT32)text_.Length(); UINT32 length = static_cast<UINT32>(text_.size());
auto writeFactory = Device::GetGraphics()->GetWriteFactory(); auto writeFactory = Device::GetGraphics()->GetWriteFactory();
// 对文本自动换行情况下进行处理 // 对文本自动换行情况下进行处理
@ -408,7 +408,7 @@ void easy2d::Text::CreateLayout()
{ {
ThrowIfFailed( ThrowIfFailed(
writeFactory->CreateTextLayout( writeFactory->CreateTextLayout(
(const wchar_t *)text_, text_.c_str(),
length, length,
text_format_, text_format_,
style_.wrap_width, style_.wrap_width,
@ -427,7 +427,7 @@ void easy2d::Text::CreateLayout()
// 为防止文本对齐问题,根据先创建 layout 以获取宽度 // 为防止文本对齐问题,根据先创建 layout 以获取宽度
ThrowIfFailed( ThrowIfFailed(
writeFactory->CreateTextLayout( writeFactory->CreateTextLayout(
(const wchar_t *)text_, text_.c_str(),
length, length,
text_format_, text_format_,
0, 0,
@ -446,7 +446,7 @@ void easy2d::Text::CreateLayout()
SafeRelease(text_layout_); SafeRelease(text_layout_);
ThrowIfFailed( ThrowIfFailed(
writeFactory->CreateTextLayout( writeFactory->CreateTextLayout(
(const wchar_t *)text_, text_.c_str(),
length, length,
text_format_, text_format_,
GetTransform().size.width, GetTransform().size.width,

View File

@ -21,7 +21,7 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
easy2d::Data::Data(const String & key, const String & field) easy2d::Data::Data(const std::wstring & key, const std::wstring & field)
: key_(key) : key_(key)
, field_(field) , field_(field)
, data_path_(Path::GetDataPath()) , data_path_(Path::GetDataPath())
@ -32,12 +32,12 @@ bool easy2d::Data::Exists() const
{ {
wchar_t temp[256] = { 0 }; wchar_t temp[256] = { 0 };
::GetPrivateProfileStringW( ::GetPrivateProfileStringW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
L"", L"",
temp, temp,
255, 255,
(LPCWSTR)data_path_ data_path_.c_str()
); );
return temp[0] == L'\0'; return temp[0] == L'\0';
} }
@ -45,102 +45,102 @@ bool easy2d::Data::Exists() const
bool easy2d::Data::SaveInt(int value) bool easy2d::Data::SaveInt(int value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
(LPCWSTR)String::Parse(value), std::to_wstring(value).c_str(),
(LPCWSTR)data_path_ data_path_.c_str()
); );
return ret != 0; return ret == TRUE;
} }
bool easy2d::Data::SaveFloat(float value) bool easy2d::Data::SaveFloat(float value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
(LPCWSTR)String::Parse(value), std::to_wstring(value).c_str(),
(LPCWSTR)data_path_ data_path_.c_str()
); );
return ret != 0; return ret == TRUE;
} }
bool easy2d::Data::SaveDouble(double value) bool easy2d::Data::SaveDouble(double value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
(LPCWSTR)String::Parse(value), std::to_wstring(value).c_str(),
(LPCWSTR)data_path_ data_path_.c_str()
); );
return ret != 0; return ret == TRUE;
} }
bool easy2d::Data::SaveBool(bool value) bool easy2d::Data::SaveBool(bool value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
(value ? L"1" : L"0"), (value ? L"1" : L"0"),
(LPCWSTR)data_path_ data_path_.c_str()
); );
return ret != 0; return ret == TRUE;
} }
bool easy2d::Data::SaveString(const String& value) bool easy2d::Data::SaveString(const std::wstring& value)
{ {
BOOL ret = ::WritePrivateProfileStringW( BOOL ret = ::WritePrivateProfileStringW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
(LPCWSTR)value, value.c_str(),
(LPCWSTR)data_path_ data_path_.c_str()
); );
return ret != 0; return ret == TRUE;
} }
int easy2d::Data::GetInt() const int easy2d::Data::GetInt() const
{ {
return ::GetPrivateProfileIntW( return ::GetPrivateProfileIntW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
0, 0,
(LPCWSTR)data_path_ data_path_.c_str()
); );
} }
float easy2d::Data::GetFloat() const float easy2d::Data::GetFloat() const
{ {
wchar_t temp[32] = { 0 }; wchar_t temp[32] = { 0 };
::GetPrivateProfileStringW((LPCWSTR)field_, (LPCWSTR)key_, L"0.0", temp, 31, (LPCWSTR)data_path_); ::GetPrivateProfileStringW(field_.c_str(), key_.c_str(), L"0.0", temp, 31, data_path_.c_str());
return std::stof(temp); return std::stof(temp);
} }
double easy2d::Data::GetDouble() const double easy2d::Data::GetDouble() const
{ {
wchar_t temp[32] = { 0 }; wchar_t temp[32] = { 0 };
::GetPrivateProfileStringW((LPCWSTR)field_, (LPCWSTR)key_, L"0.0", temp, 31, (LPCWSTR)data_path_); ::GetPrivateProfileStringW(field_.c_str(), key_.c_str(), L"0.0", temp, 31, data_path_.c_str());
return std::stod(temp); return std::stod(temp);
} }
bool easy2d::Data::GetBool() const bool easy2d::Data::GetBool() const
{ {
int nValue = ::GetPrivateProfileIntW( int nValue = ::GetPrivateProfileIntW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
0, 0,
(LPCWSTR)data_path_); data_path_.c_str());
return nValue != 0; return nValue == TRUE;
} }
easy2d::String easy2d::Data::GetString() std::wstring easy2d::Data::GetString()
{ {
wchar_t temp[256] = { 0 }; wchar_t temp[256] = { 0 };
::GetPrivateProfileStringW( ::GetPrivateProfileStringW(
(LPCWSTR)field_, field_.c_str(),
(LPCWSTR)key_, key_.c_str(),
L"", L"",
temp, temp,
255, 255,
(LPCWSTR)data_path_ data_path_.c_str()
); );
return temp; return temp;
} }

View File

@ -20,16 +20,17 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
#include "..\e2dmodule.h" #include "..\e2dmodule.h"
#include <cwctype>
#include <shobjidl.h> #include <shobjidl.h>
std::list<easy2d::String> easy2d::File::search_paths_; std::list<std::wstring> easy2d::File::search_paths_;
easy2d::File::File() easy2d::File::File()
: file_path_() : file_path_()
{ {
} }
easy2d::File::File(const String & file_name) easy2d::File::File(const std::wstring & file_name)
: file_path_(file_name) : file_path_(file_name)
{ {
this->Open(file_name); this->Open(file_name);
@ -39,14 +40,14 @@ easy2d::File::~File()
{ {
} }
bool easy2d::File::Open(const String & file_name) bool easy2d::File::Open(const std::wstring & file_name)
{ {
if (file_name.IsEmpty()) if (file_name.empty())
return false; return false;
auto FindFile = [](const String & path) -> bool auto FindFile = [](const std::wstring & path) -> bool
{ {
if (::PathFileExists((const wchar_t*)path)) if (::PathFileExists(path.c_str()))
return true; return true;
return false; return false;
}; };
@ -70,44 +71,44 @@ bool easy2d::File::Open(const String & file_name)
bool easy2d::File::Exists() const bool easy2d::File::Exists() const
{ {
if (::PathFileExists(static_cast<LPCWSTR>(file_path_))) if (::PathFileExists(file_path_.c_str()))
return true; return true;
return false; return false;
} }
const easy2d::String& easy2d::File::GetPath() const const std::wstring& easy2d::File::GetPath() const
{ {
return file_path_; return file_path_;
} }
easy2d::String easy2d::File::GetExtension() const std::wstring easy2d::File::GetExtension() const
{ {
String file_ext; std::wstring file_ext;
// 找到文件名中的最后一个 '.' 的位置 // 找到文件名中的最后一个 '.' 的位置
size_t pos = file_path_.operator std::wstring().find_last_of(L'.'); size_t pos = file_path_.find_last_of(L'.');
// 判断 pos 是否是有效位置 // 判断 pos 是否是有效位置
if (pos != std::wstring::npos) if (pos != std::wstring::npos)
{ {
// 截取扩展名 // 截取扩展名
file_ext = file_path_.Subtract(static_cast<int>(pos)); file_ext = file_path_.substr(pos);
// 转换为小写字母 // 转换为小写字母
file_ext = file_ext.ToLower(); std::transform(file_ext.begin(), file_ext.end(), file_ext.begin(), std::towlower);
} }
return std::move(file_ext); return std::move(file_ext);
} }
bool easy2d::File::Delete() bool easy2d::File::Delete()
{ {
if (::DeleteFile(static_cast<LPCWSTR>(file_path_))) if (::DeleteFile(file_path_.c_str()))
return true; return true;
return false; return false;
} }
easy2d::File easy2d::File::Extract(const Resource& res, const String& dest_file_name) easy2d::File easy2d::File::Extract(Resource& res, const std::wstring& dest_file_name)
{ {
File file; File file;
HANDLE file_handle = ::CreateFile( HANDLE file_handle = ::CreateFile(
static_cast<LPCWSTR>(dest_file_name), dest_file_name.c_str(),
GENERIC_WRITE, GENERIC_WRITE,
NULL, NULL,
NULL, NULL,
@ -119,16 +120,11 @@ easy2d::File easy2d::File::Extract(const Resource& res, const String& dest_file_
if (file_handle == INVALID_HANDLE_VALUE) if (file_handle == INVALID_HANDLE_VALUE)
return std::move(file); return std::move(file);
// 查找资源文件中、加载资源到内存、得到资源大小 if (res.Load())
HRSRC res_info = ::FindResource(NULL, MAKEINTRESOURCE(res.id), static_cast<LPCWSTR>(res.type));
HGLOBAL res_data = ::LoadResource(NULL, res_info);
DWORD res_size = ::SizeofResource(NULL, res_info);
if (res_info && res_data && res_size)
{ {
// 写入文件 // 写入文件
DWORD written_bytes = 0; DWORD written_bytes = 0;
::WriteFile(file_handle, res_data, res_size, &written_bytes, NULL); ::WriteFile(file_handle, res.GetData(), res.GetDataSize(), &written_bytes, NULL);
::CloseHandle(file_handle); ::CloseHandle(file_handle);
file.Open(dest_file_name); file.Open(dest_file_name);
@ -136,20 +132,25 @@ easy2d::File easy2d::File::Extract(const Resource& res, const String& dest_file_
else else
{ {
::CloseHandle(file_handle); ::CloseHandle(file_handle);
::DeleteFile(static_cast<LPCWSTR>(dest_file_name)); ::DeleteFile(dest_file_name.c_str());
} }
::FreeResource(res_data);
return std::move(file); return std::move(file);
} }
void easy2d::File::AddSearchPath(const String & path) void easy2d::File::AddSearchPath(const std::wstring & path)
{ {
String tmp = path; std::wstring tmp = path;
tmp.Replace(L"/", L"\\"); size_t pos = 0;
if (tmp.At(tmp.Length() - 1) != L'\\') while ((pos = tmp.find(L"/", pos)) != std::wstring::npos)
{ {
tmp << L"\\"; tmp.replace(pos, 1, L"\\");
pos++;
}
if (tmp.at(tmp.length() - 1) != L'\\')
{
tmp.append(L"\\");
} }
auto iter = std::find(search_paths_.cbegin(), search_paths_.cend(), tmp); auto iter = std::find(search_paths_.cbegin(), search_paths_.cend(), tmp);
if (iter == search_paths_.cend()) if (iter == search_paths_.cend())
@ -158,9 +159,9 @@ void easy2d::File::AddSearchPath(const String & path)
} }
} }
easy2d::File easy2d::File::ShowOpenDialog(const String & title, const String & filter) easy2d::File easy2d::File::ShowOpenDialog(const std::wstring & title, const std::wstring & filter)
{ {
String file_path; std::wstring file_path;
HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -172,16 +173,16 @@ easy2d::File easy2d::File::ShowOpenDialog(const String & title, const String & f
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
if (!title.IsEmpty()) if (!title.empty())
{ {
file_open->SetTitle(LPCWSTR(title)); file_open->SetTitle(title.c_str());
} }
if (!filter.IsEmpty()) if (!filter.empty())
{ {
COMDLG_FILTERSPEC spec[] = COMDLG_FILTERSPEC spec[] =
{ {
{ L"", LPCWSTR(filter) } { L"", filter.c_str() }
}; };
file_open->SetFileTypes(1, spec); file_open->SetFileTypes(1, spec);
} }
@ -220,9 +221,9 @@ easy2d::File easy2d::File::ShowOpenDialog(const String & title, const String & f
return std::move(File(file_path)); return std::move(File(file_path));
} }
easy2d::File easy2d::File::ShowSaveDialog(const String & title, const String& def_file, const String & def_ext) easy2d::File easy2d::File::ShowSaveDialog(const std::wstring & title, const std::wstring& def_file, const std::wstring & def_ext)
{ {
String file_path; std::wstring file_path;
HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -234,24 +235,24 @@ easy2d::File easy2d::File::ShowSaveDialog(const String & title, const String& de
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
if (!title.IsEmpty()) if (!title.empty())
{ {
file_save->SetTitle(LPCWSTR(title)); file_save->SetTitle(title.c_str());
} }
if (!def_file.IsEmpty()) if (!def_file.empty())
{ {
file_save->SetFileName(LPCWSTR(def_file)); file_save->SetFileName(def_file.c_str());
} }
if (!def_ext.IsEmpty()) if (!def_ext.empty())
{ {
file_save->SetDefaultExtension(LPCWSTR(def_ext)); file_save->SetDefaultExtension(def_ext.c_str());
String ext = L"*." + def_ext; std::wstring ext = L"*." + def_ext;
COMDLG_FILTERSPEC spec[] = COMDLG_FILTERSPEC spec[] =
{ {
{ L"", LPCWSTR(ext) } { L"", ext.c_str() }
}; };
file_save->SetFileTypes(1, spec); file_save->SetFileTypes(1, spec);
} }

View File

@ -100,50 +100,20 @@ namespace easy2d
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }
bool LoadMediaResource(LPCWSTR res_name, LPCWSTR res_type, BYTE** wave_data, UINT32* wave_data_size) bool LoadMediaResource(Resource& res, BYTE** wave_data, UINT32* wave_data_size)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
HRSRC res_info;
HGLOBAL res_data;
DWORD res_size;
LPVOID res;
HINSTANCE hinstance = GetModuleHandle(nullptr); HINSTANCE hinstance = GetModuleHandle(nullptr);
IStream* stream = nullptr; IStream* stream = nullptr;
IMFByteStream* byte_stream = nullptr; IMFByteStream* byte_stream = nullptr;
IMFSourceReader* reader = nullptr; IMFSourceReader* reader = nullptr;
res_info = FindResourceW(hinstance, res_name, res_type); if (!res.Load()) { return false; }
if (res_info == nullptr)
{
TraceError(L"FindResource");
return false;
}
res_data = LoadResource(hinstance, res_info);
if (res_data == nullptr)
{
TraceError(L"LoadResource");
return false;
}
res_size = SizeofResource(hinstance, res_info);
if (res_size == 0)
{
TraceError(L"SizeofResource");
return false;
}
res = LockResource(res_data);
if (res == nullptr)
{
TraceError(L"LockResource");
return false;
}
stream = SHCreateMemStream( stream = SHCreateMemStream(
static_cast<const BYTE*>(res), static_cast<const BYTE*>(res.GetData()),
static_cast<UINT>(res_size) static_cast<UINT>(res.GetDataSize())
); );
if (stream == nullptr) if (stream == nullptr)
@ -346,7 +316,7 @@ easy2d::Music::Music()
{ {
} }
easy2d::Music::Music(const easy2d::String& file_path) easy2d::Music::Music(const std::wstring& file_path)
: opened_(false) : opened_(false)
, playing_(false) , playing_(false)
, wave_data_(nullptr) , wave_data_(nullptr)
@ -356,7 +326,7 @@ easy2d::Music::Music(const easy2d::String& file_path)
Load(file_path); Load(file_path);
} }
easy2d::Music::Music(const Resource& res) easy2d::Music::Music(Resource& res)
: opened_(false) : opened_(false)
, playing_(false) , playing_(false)
, wave_data_(nullptr) , wave_data_(nullptr)
@ -371,7 +341,7 @@ easy2d::Music::~Music()
Close(); Close();
} }
bool easy2d::Music::Load(const easy2d::String & file_path) bool easy2d::Music::Load(const std::wstring & file_path)
{ {
if (opened_) if (opened_)
{ {
@ -387,10 +357,10 @@ bool easy2d::Music::Load(const easy2d::String & file_path)
// 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加 // 用户输入的路径不一定是完整路径,因为用户可能通过 File::AddSearchPath 添加
// 默认搜索路径,所以需要通过 File::GetPath 获取完整路径 // 默认搜索路径,所以需要通过 File::GetPath 获取完整路径
String music_file_path = music_file.GetPath(); std::wstring music_file_path = music_file.GetPath();
Transcoder transcoder; Transcoder transcoder;
if (!transcoder.LoadMediaFile((LPCWSTR)music_file_path, &wave_data_, &size_)) if (!transcoder.LoadMediaFile(music_file_path.c_str(), &wave_data_, &size_))
{ {
return false; return false;
} }
@ -411,7 +381,7 @@ bool easy2d::Music::Load(const easy2d::String & file_path)
return true; return true;
} }
bool easy2d::Music::Load(const Resource& res) bool easy2d::Music::Load(Resource& res)
{ {
if (opened_) if (opened_)
{ {
@ -419,7 +389,7 @@ bool easy2d::Music::Load(const Resource& res)
} }
Transcoder transcoder; Transcoder transcoder;
if (!transcoder.LoadMediaResource(MAKEINTRESOURCE(res.id), (LPCWSTR)res.type, &wave_data_, &size_)) if (!transcoder.LoadMediaResource(res, &wave_data_, &size_))
{ {
return false; return false;
} }

View File

@ -26,17 +26,17 @@
namespace namespace
{ {
// 创建指定文件夹 // 创建指定文件夹
bool CreateFolder(const easy2d::String & dir_path) bool CreateFolder(const std::wstring & dir_path)
{ {
if (dir_path.IsEmpty() || dir_path.Length() >= MAX_PATH) if (dir_path.empty() || dir_path.size() >= MAX_PATH)
return false; return false;
wchar_t tmp_dir_path[MAX_PATH] = { 0 }; wchar_t tmp_dir_path[MAX_PATH] = { 0 };
int length = dir_path.Length(); size_t length = dir_path.length();
for (int i = 0; i < length; ++i) for (size_t i = 0; i < length; ++i)
{ {
tmp_dir_path[i] = dir_path.At(i); tmp_dir_path[i] = dir_path.at(i);
if (tmp_dir_path[i] == L'\\' || tmp_dir_path[i] == L'/' || i == (length - 1)) if (tmp_dir_path[i] == L'\\' || tmp_dir_path[i] == L'/' || i == (length - 1))
{ {
if (::_waccess(tmp_dir_path, 0) != 0) if (::_waccess(tmp_dir_path, 0) != 0)
@ -53,19 +53,22 @@ namespace
} }
const easy2d::String& easy2d::Path::GetDataPath() const std::wstring& easy2d::Path::GetDataPath()
{ {
static String data_path; static std::wstring data_path;
if (data_path.IsEmpty()) if (data_path.empty())
{ {
// 设置数据的保存路径 // 设置数据的保存路径
String local_app_data_path = Path::GetLocalAppDataPath(); std::wstring local_app_data_path = Path::GetLocalAppDataPath();
String title = Game::GetInstance()->GetTitle(); std::wstring title = Game::GetInstance()->GetTitle();
String folder_name = String::Parse(title.GetHash()); std::wstring folder_name = std::to_wstring(std::hash<std::wstring>{}(title));
if (!local_app_data_path.IsEmpty()) if (!local_app_data_path.empty())
{ {
data_path = local_app_data_path + L"\\Easy2DGameData\\" << folder_name << L"\\"; data_path.append(local_app_data_path)
.append(L"\\Easy2DGameData\\")
.append(folder_name)
.append(L"\\");
File file(data_path); File file(data_path);
if (!file.Exists() && !CreateFolder(data_path)) if (!file.Exists() && !CreateFolder(data_path))
@ -73,24 +76,27 @@ const easy2d::String& easy2d::Path::GetDataPath()
data_path = L""; data_path = L"";
} }
} }
data_path << L"Data.ini"; data_path.append(L"Data.ini");
} }
return data_path; return data_path;
} }
const easy2d::String& easy2d::Path::GetTemporaryPath() const std::wstring& easy2d::Path::GetTemporaryPath()
{ {
static String temp_path; static std::wstring temp_path;
if (temp_path.IsEmpty()) if (temp_path.empty())
{ {
// 设置临时文件保存路径 // 设置临时文件保存路径
wchar_t path[_MAX_PATH]; wchar_t path[_MAX_PATH];
String title = Game::GetInstance()->GetTitle(); std::wstring title = Game::GetInstance()->GetTitle();
String folder_name = String::Parse(title.GetHash()); std::wstring folder_name = std::to_wstring(std::hash<std::wstring>{}(title));
if (0 != ::GetTempPath(_MAX_PATH, path)) if (0 != ::GetTempPath(_MAX_PATH, path))
{ {
temp_path << path << L"\\Easy2DGameTemp\\" << folder_name << L"\\"; temp_path.append(path)
.append(L"\\Easy2DGameTemp\\")
.append(folder_name)
.append(L"\\");
File file(temp_path); File file(temp_path);
if (!file.Exists() && !CreateFolder(temp_path)) if (!file.Exists() && !CreateFolder(temp_path))
@ -102,10 +108,10 @@ const easy2d::String& easy2d::Path::GetTemporaryPath()
return temp_path; return temp_path;
} }
const easy2d::String& easy2d::Path::GetLocalAppDataPath() const std::wstring& easy2d::Path::GetLocalAppDataPath()
{ {
static String local_app_data_path; static std::wstring local_app_data_path;
if (local_app_data_path.IsEmpty()) if (local_app_data_path.empty())
{ {
// 获取 AppData/Local 文件夹的路径 // 获取 AppData/Local 文件夹的路径
wchar_t path[MAX_PATH] = { 0 }; wchar_t path[MAX_PATH] = { 0 };
@ -116,10 +122,10 @@ const easy2d::String& easy2d::Path::GetLocalAppDataPath()
return local_app_data_path; return local_app_data_path;
} }
const easy2d::String& easy2d::Path::GetExeFilePath() const std::wstring& easy2d::Path::GetExeFilePath()
{ {
static String exe_file_path; static std::wstring exe_file_path;
if (exe_file_path.IsEmpty()) if (exe_file_path.empty())
{ {
TCHAR path[_MAX_PATH] = { 0 }; TCHAR path[_MAX_PATH] = { 0 };
if (::GetModuleFileName(nullptr, path, _MAX_PATH) != 0) if (::GetModuleFileName(nullptr, path, _MAX_PATH) != 0)

View File

@ -12,9 +12,9 @@ easy2d::Player::~Player()
{ {
} }
bool easy2d::Player::Load(const String & file_path) bool easy2d::Player::Load(const std::wstring & file_path)
{ {
if (file_path.IsEmpty()) if (file_path.empty())
return false; return false;
Music * music = new (std::nothrow) Music(); Music * music = new (std::nothrow) Music();
@ -24,7 +24,9 @@ bool easy2d::Player::Load(const String & file_path)
if (music->Load(file_path)) if (music->Load(file_path))
{ {
music->SetVolume(volume_); music->SetVolume(volume_);
musics_.insert(std::make_pair(file_path.GetHash(), music));
size_t hash_code = std::hash<std::wstring>{}(file_path);
musics_.insert(std::make_pair(hash_code, music));
return true; return true;
} }
else else
@ -35,14 +37,14 @@ bool easy2d::Player::Load(const String & file_path)
return false; return false;
} }
bool easy2d::Player::Play(const String & file_path, int loop_count) bool easy2d::Player::Play(const std::wstring & file_path, int loop_count)
{ {
if (file_path.IsEmpty()) if (file_path.empty())
return false; return false;
if (Load(file_path)) if (Load(file_path))
{ {
auto music = musics_[file_path.GetHash()]; auto music = musics_[std::hash<std::wstring>{}(file_path)];
if (music->Play(loop_count)) if (music->Play(loop_count))
{ {
return true; return true;
@ -51,50 +53,51 @@ bool easy2d::Player::Play(const String & file_path, int loop_count)
return false; return false;
} }
void easy2d::Player::Pause(const String & file_path) void easy2d::Player::Pause(const std::wstring & file_path)
{ {
if (file_path.IsEmpty()) if (file_path.empty())
return; return;
size_t hash = file_path.GetHash(); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (musics_.end() != musics_.find(hash)) if (musics_.end() != musics_.find(hash_code))
musics_[hash]->Pause(); musics_[hash_code]->Pause();
} }
void easy2d::Player::Resume(const String & file_path) void easy2d::Player::Resume(const std::wstring & file_path)
{ {
if (file_path.IsEmpty()) if (file_path.empty())
return; return;
size_t hash = file_path.GetHash(); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (musics_.end() != musics_.find(hash)) if (musics_.end() != musics_.find(hash_code))
musics_[hash]->Resume(); musics_[hash_code]->Resume();
} }
void easy2d::Player::Stop(const String & file_path) void easy2d::Player::Stop(const std::wstring & file_path)
{ {
if (file_path.IsEmpty()) if (file_path.empty())
return; return;
size_t hash = file_path.GetHash(); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (musics_.end() != musics_.find(hash)) if (musics_.end() != musics_.find(hash_code))
musics_[hash]->Stop(); musics_[hash_code]->Stop();
} }
bool easy2d::Player::IsPlaying(const String & file_path) bool easy2d::Player::IsPlaying(const std::wstring & file_path)
{ {
if (file_path.IsEmpty()) if (file_path.empty())
return false; return false;
size_t hash = file_path.GetHash(); size_t hash_code = std::hash<std::wstring>{}(file_path);
if (musics_.end() != musics_.find(hash)) if (musics_.end() != musics_.find(hash_code))
return musics_[hash]->IsPlaying(); return musics_[hash_code]->IsPlaying();
return false; return false;
} }
bool easy2d::Player::Load(const Resource& res) bool easy2d::Player::Load(Resource& res)
{ {
if (musics_.end() != musics_.find(res.id)) size_t hash_code = res.GetHashCode();
if (musics_.end() != musics_.find(hash_code))
return true; return true;
Music * music = new (std::nothrow) Music(); Music * music = new (std::nothrow) Music();
@ -104,7 +107,7 @@ bool easy2d::Player::Load(const Resource& res)
if (music->Load(res)) if (music->Load(res))
{ {
music->SetVolume(volume_); music->SetVolume(volume_);
musics_.insert(std::make_pair(res.id, music)); musics_.insert(std::make_pair(hash_code, music));
return true; return true;
} }
else else
@ -115,11 +118,12 @@ bool easy2d::Player::Load(const Resource& res)
return false; return false;
} }
bool easy2d::Player::Play(const Resource& res, int loop_count) bool easy2d::Player::Play(Resource& res, int loop_count)
{ {
if (Load(res)) if (Load(res))
{ {
auto music = musics_[res.id]; size_t hash_code = res.GetHashCode();
auto music = musics_[hash_code];
if (music->Play(loop_count)) if (music->Play(loop_count))
{ {
return true; return true;
@ -128,28 +132,32 @@ bool easy2d::Player::Play(const Resource& res, int loop_count)
return false; return false;
} }
void easy2d::Player::Pause(const Resource& res) void easy2d::Player::Pause(Resource& res)
{ {
if (musics_.end() != musics_.find(res.id)) size_t hash_code = res.GetHashCode();
musics_[res.id]->Pause(); if (musics_.end() != musics_.find(hash_code))
musics_[hash_code]->Pause();
} }
void easy2d::Player::Resume(const Resource& res) void easy2d::Player::Resume(Resource& res)
{ {
if (musics_.end() != musics_.find(res.id)) size_t hash_code = res.GetHashCode();
musics_[res.id]->Resume(); if (musics_.end() != musics_.find(hash_code))
musics_[hash_code]->Resume();
} }
void easy2d::Player::Stop(const Resource& res) void easy2d::Player::Stop(Resource& res)
{ {
if (musics_.end() != musics_.find(res.id)) size_t hash_code = res.GetHashCode();
musics_[res.id]->Stop(); if (musics_.end() != musics_.find(hash_code))
musics_[hash_code]->Stop();
} }
bool easy2d::Player::IsPlaying(const Resource& res) bool easy2d::Player::IsPlaying(Resource& res)
{ {
if (musics_.end() != musics_.find(res.id)) size_t hash_code = res.GetHashCode();
return musics_[res.id]->IsPlaying(); if (musics_.end() != musics_.find(hash_code))
return musics_[hash_code]->IsPlaying();
return false; return false;
} }

View File

@ -20,15 +20,8 @@
#include "..\e2dutil.h" #include "..\e2dutil.h"
easy2d::Font::Font()
: family("")
, size(22)
, weight(Font::Weight::Normal)
, italic(false)
{
}
easy2d::Font::Font(const String & family, float size, UINT weight, bool italic) easy2d::Font::Font(const std::wstring & family, float size, UINT weight, bool italic)
: family(family) : family(family)
, size(size) , size(size)
, weight(weight) , weight(weight)

View File

@ -21,8 +21,77 @@
#include "..\e2dtool.h" #include "..\e2dtool.h"
easy2d::Resource::Resource(int resource_id, const String & resource_type) easy2d::Resource::Resource(LPCWSTR name, LPCWSTR type)
: id(resource_id) : name_(name)
, type(resource_type) , type_(type)
, data_(nullptr)
, data_size_(0)
, loaded_(false)
{ {
} }
LPCWSTR easy2d::Resource::GetName() const
{
return name_;
}
LPCWSTR easy2d::Resource::GetType() const
{
return type_;
}
LPVOID easy2d::Resource::GetData() const
{
return data_;
}
DWORD easy2d::Resource::GetDataSize() const
{
return data_size_;
}
size_t easy2d::Resource::GetHashCode() const
{
return std::hash<LPCWSTR>{}(name_);
}
bool easy2d::Resource::Load()
{
if (!loaded_)
{
HRSRC res_info;
HGLOBAL res_data;
HINSTANCE hinstance = GetModuleHandle(NULL);
res_info = FindResourceW(hinstance, name_, type_);
if (res_info == nullptr)
{
E2D_WARNING("FindResource");
return false;
}
res_data = LoadResource(hinstance, res_info);
if (res_data == nullptr)
{
E2D_WARNING("LoadResource");
return false;
}
data_size_ = SizeofResource(hinstance, res_info);
if (data_size_ == 0)
{
E2D_WARNING("SizeofResource");
return false;
}
data_ = LockResource(res_data);
if (data_ == nullptr)
{
E2D_WARNING("LockResource");
return false;
}
loaded_ = true;
}
return true;
}

View File

@ -1,527 +0,0 @@
// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "..\e2dutil.h"
#include <iomanip>
#include <cwctype>
#include <comutil.h>
#pragma comment(lib, "comsuppw.lib")
easy2d::String::String()
: string_(L"")
{
}
easy2d::String::String(const wchar_t *str)
: string_(str)
{
}
easy2d::String::String(const char *cstr)
: string_(static_cast<wchar_t*>(_bstr_t(cstr)))
{
}
easy2d::String::String(easy2d::String && str)
{
string_ = std::move(str.string_);
}
easy2d::String::String(const easy2d::String &str)
: string_(str.string_)
{
}
easy2d::String::~String()
{
string_.clear();
}
easy2d::String &easy2d::String::operator=(const wchar_t *str)
{
string_ = str;
return (*this);
}
easy2d::String & easy2d::String::operator=(const char *cstr)
{
string_ = static_cast<wchar_t*>(_bstr_t(cstr));
return (*this);
}
easy2d::String easy2d::String::Parse(int value)
{
String tmp;
tmp.string_ = std::to_wstring(value);
return std::move(tmp);
}
easy2d::String easy2d::String::Parse(unsigned int value)
{
String tmp;
tmp.string_ = std::to_wstring(value);
return std::move(tmp);
}
easy2d::String easy2d::String::Parse(unsigned long long value)
{
String tmp;
tmp.string_ = std::to_wstring(value);
return std::move(tmp);
}
easy2d::String easy2d::String::Parse(float value)
{
String tmp;
tmp.string_ = std::to_wstring(value);
return std::move(tmp);
}
easy2d::String easy2d::String::Parse(double value)
{
String tmp;
tmp.string_ = std::to_wstring(value);
return std::move(tmp);
}
easy2d::String easy2d::String::Format(const char * format, ...)
{
std::string tmp;
va_list marker;
va_start(marker, format);
size_t nu_of_chars = _vscprintf(format, marker);
if (nu_of_chars > tmp.capacity())
{
tmp.resize(nu_of_chars + 1);
}
vsprintf_s(const_cast<LPSTR>(tmp.data()), tmp.capacity(), format, marker);
va_end(marker);
String str = tmp.c_str();
return std::move(str);
}
easy2d::String easy2d::String::Format(const wchar_t * format, ...)
{
std::wstring tmp;
va_list marker;
va_start(marker, format);
size_t nu_of_chars = _vscwprintf(format, marker);
if (nu_of_chars > tmp.capacity())
{
tmp.resize(nu_of_chars + 1);
}
vswprintf_s(const_cast<LPWSTR>(tmp.data()), tmp.capacity(), format, marker);
va_end(marker);
String str = tmp.c_str();
return std::move(str);
}
easy2d::String & easy2d::String::operator=(const String &str)
{
string_ = str.string_;
return (*this);
}
bool easy2d::String::operator==(const wchar_t *str) const
{
if (str)
{
return (string_.compare(str) == 0);
}
else
{
return false;
}
}
bool easy2d::String::operator==(const char *str) const
{
if (str)
{
String temp(str);
return (string_ == temp.string_);
}
else
{
return false;
}
}
bool easy2d::String::operator ==(const easy2d::String &str) const
{
return string_ == str.string_;
}
bool easy2d::String::operator!=(const wchar_t *str) const
{
if (str)
{
return (string_.compare(str) != 0);
}
else
{
return true;
}
}
bool easy2d::String::operator!=(const char *str) const
{
if (str)
{
String temp(str);
return (string_ != temp.string_);
}
else
{
return true;
}
}
bool easy2d::String::operator!=(const easy2d::String &str) const
{
return string_ != str.string_;
}
wchar_t &easy2d::String::operator[](size_t index)
{
return string_[index];
}
easy2d::String easy2d::String::operator+(const wchar_t *str) const
{
String temp;
temp.string_ = string_ + str;
return std::move(temp);
}
easy2d::String easy2d::String::operator+(const char *str) const
{
String temp;
temp.string_ = string_ + static_cast<wchar_t*>(_bstr_t(str));
return std::move(temp);
}
easy2d::String easy2d::String::operator+(const easy2d::String &str) const
{
String temp;
temp.string_ = string_ + str.string_;
return std::move(temp);
}
easy2d::String easy2d::operator+(const wchar_t *str1, const easy2d::String &str2)
{
String temp;
temp.string_ = str1 + str2.string_;
return std::move(temp);
}
easy2d::String easy2d::operator+(const char *str1, const String &str2)
{
String temp;
temp.string_ = static_cast<wchar_t*>(_bstr_t(str1)) + str2.string_;
return std::move(temp);
}
easy2d::String & easy2d::String::operator+=(const wchar_t *str)
{
string_ += str;
return (*this);
}
easy2d::String & easy2d::String::operator+=(const char *str)
{
string_ += static_cast<wchar_t*>(_bstr_t(str));
return (*this);
}
easy2d::String & easy2d::String::operator+=(const String &str)
{
string_ += str.string_;
return (*this);
}
bool easy2d::String::operator>(const String &str) const
{
return string_ > str.string_;
}
bool easy2d::String::operator>=(const String &str) const
{
return string_ >= str.string_;
}
bool easy2d::String::operator<(const String &str) const
{
return string_ < str.string_;
}
bool easy2d::String::operator<=(const String &str) const
{
return string_ <= str.string_;
}
easy2d::String & easy2d::String::operator<<(const String &str)
{
string_ += str.string_;
return (*this);
}
easy2d::String & easy2d::String::operator<<(const wchar_t *str)
{
string_ += str;
return (*this);
}
easy2d::String & easy2d::String::operator<<(wchar_t *str)
{
string_ += str;
return (*this);
}
easy2d::String & easy2d::String::operator<<(const char * cstr)
{
string_ += static_cast<wchar_t*>(_bstr_t(cstr));
return (*this);
}
easy2d::String & easy2d::String::operator<<(char * cstr)
{
string_ += static_cast<wchar_t*>(_bstr_t(cstr));
return (*this);
}
easy2d::String & easy2d::String::operator<<(int value)
{
(*this) += String::Parse(value);
return (*this);
}
easy2d::String & easy2d::String::operator<<(unsigned int value)
{
(*this) += String::Parse(value);
return (*this);
}
easy2d::String & easy2d::String::operator<<(float value)
{
(*this) += String::Parse(value);
return (*this);
}
easy2d::String & easy2d::String::operator<<(double value)
{
(*this) += String::Parse(value);
return (*this);
}
easy2d::String::operator const wchar_t*() const
{
return string_.c_str();
}
easy2d::String::operator wchar_t*() const
{
return const_cast<wchar_t*>(string_.c_str());
}
easy2d::String::operator std::wstring() const
{
return string_;
}
easy2d::String::operator std::string() const
{
std::string str = static_cast<const char *>(_bstr_t(string_.c_str()));
return std::move(str);
}
bool easy2d::String::IsEmpty() const
{
return string_.empty();
}
int easy2d::String::Length() const
{
return static_cast<int>(string_.size());
}
size_t easy2d::String::GetHash() const
{
std::hash<std::wstring> hash;
return hash(string_);
}
const wchar_t& easy2d::String::At(size_t index) const
{
return string_.at(index);
}
int easy2d::String::Compare(const String & str) const
{
return string_.compare(str.string_);
}
easy2d::String easy2d::String::ToUpper() const
{
String str(*this);
std::transform(str.string_.begin(), str.string_.end(), str.string_.begin(), std::towupper);
return std::move(str);
}
easy2d::String easy2d::String::ToLower() const
{
easy2d::String str(*this);
std::transform(str.string_.begin(), str.string_.end(), str.string_.begin(), std::towlower);
return std::move(str);
}
int easy2d::String::ToInt() const
{
if (string_.empty())
{
return 0;
}
return std::stoi(string_, 0, 10);
}
float easy2d::String::ToFloat() const
{
if (string_.empty())
{
return 0.f;
}
return std::stof(string_, 0);
}
double easy2d::String::ToDouble() const
{
if (string_.empty())
{
return 0.0;
}
return std::stod(string_, 0);
}
bool easy2d::String::ToBool() const
{
if (string_.empty())
{
return false;
}
if (string_.compare(L"0") == 0 || string_.compare(L"false") == 0)
{
return false;
}
return true;
}
easy2d::String easy2d::String::Subtract(int offset, int count) const
{
String tmp;
int length = static_cast<int>(string_.size());
if (length == 0 || offset >= length)
return std::move(tmp);
offset = offset >= 0 ? offset : 0;
if (count < 0 || (offset + count) > length)
count = length - offset;
tmp.string_ = string_.substr(offset, count);
return std::move(tmp);
}
void easy2d::String::Insert(const String & str, int pos)
{
string_.insert(size_t(pos), str.string_);
}
void easy2d::String::Replace(const String & from, const String & to)
{
if (from.string_.empty())
return;
size_t start_pos = 0;
while ((start_pos = string_.find((const wchar_t *)from, start_pos)) != std::wstring::npos)
{
string_.replace(start_pos, from.string_.length(), (const wchar_t *)to);
start_pos += to.string_.length();
}
}
void easy2d::String::Erase(int offset, int count)
{
string_.erase(size_t(offset), size_t(count));
}
int easy2d::String::Find(const String & str, int offset) const
{
size_t index;
if ((index = string_.find(str.string_, size_t(offset))) == std::wstring::npos)
return -1;
return static_cast<int>(index);
}
void easy2d::String::Clear()
{
string_.clear();
}
std::wostream & easy2d::operator<<(std::wostream &cout, const String &str)
{
cout << str.string_;
return cout;
}
std::wistream & easy2d::operator>>(std::wistream &cin, String &str)
{
cin >> str.string_;
return cin;
}
std::ostream & easy2d::operator<<(std::ostream &cout, const String &str)
{
std::string cstr = static_cast<char*>(_bstr_t(str.string_.c_str()));
cout << cstr;
return cout;
}
std::istream & easy2d::operator>>(std::istream &cin, String &str)
{
std::string temp;
cin >> temp;
str.string_ = static_cast<wchar_t*>(_bstr_t(temp.c_str()));
return cin;
}

View File

@ -61,7 +61,6 @@
<ClCompile Include="..\..\core\tools\Music.cpp" /> <ClCompile Include="..\..\core\tools\Music.cpp" />
<ClCompile Include="..\..\core\tools\Path.cpp" /> <ClCompile Include="..\..\core\tools\Path.cpp" />
<ClCompile Include="..\..\core\tools\Player.cpp" /> <ClCompile Include="..\..\core\tools\Player.cpp" />
<ClCompile Include="..\..\core\tools\Random.cpp" />
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp" /> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp" />
<ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" />
<ClCompile Include="..\..\core\transitions\FadeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\FadeTransition.cpp" />
@ -73,11 +72,11 @@
<ClCompile Include="..\..\core\utils\Font.cpp" /> <ClCompile Include="..\..\core\utils\Font.cpp" />
<ClCompile Include="..\..\core\utils\Function.cpp" /> <ClCompile Include="..\..\core\utils\Function.cpp" />
<ClCompile Include="..\..\core\utils\Point.cpp" /> <ClCompile Include="..\..\core\utils\Point.cpp" />
<ClCompile Include="..\..\core\utils\Random.cpp" />
<ClCompile Include="..\..\core\utils\Rect.cpp" /> <ClCompile Include="..\..\core\utils\Rect.cpp" />
<ClCompile Include="..\..\core\utils\Ref.cpp" /> <ClCompile Include="..\..\core\utils\Ref.cpp" />
<ClCompile Include="..\..\core\utils\Resource.cpp" /> <ClCompile Include="..\..\core\utils\Resource.cpp" />
<ClCompile Include="..\..\core\utils\Size.cpp" /> <ClCompile Include="..\..\core\utils\Size.cpp" />
<ClCompile Include="..\..\core\utils\String.cpp" />
<ClCompile Include="..\..\core\utils\Time.cpp" /> <ClCompile Include="..\..\core\utils\Time.cpp" />
<ClCompile Include="..\..\core\utils\Transform.cpp" /> <ClCompile Include="..\..\core\utils\Transform.cpp" />
</ItemGroup> </ItemGroup>

View File

@ -123,9 +123,6 @@
<ClCompile Include="..\..\core\utils\Size.cpp"> <ClCompile Include="..\..\core\utils\Size.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\utils\String.cpp">
<Filter>utils</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\Time.cpp"> <ClCompile Include="..\..\core\utils\Time.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
@ -156,9 +153,6 @@
<ClCompile Include="..\..\core\tools\Player.cpp"> <ClCompile Include="..\..\core\tools\Player.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\tools\Random.cpp">
<Filter>tools</Filter>
</ClCompile>
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp"> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp">
<Filter>transitions</Filter> <Filter>transitions</Filter>
</ClCompile> </ClCompile>
@ -210,6 +204,9 @@
<ClCompile Include="..\..\core\modules\Device.cpp"> <ClCompile Include="..\..\core\modules\Device.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\utils\Random.cpp">
<Filter>utils</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />

View File

@ -205,7 +205,6 @@
<ClCompile Include="..\..\core\tools\Music.cpp" /> <ClCompile Include="..\..\core\tools\Music.cpp" />
<ClCompile Include="..\..\core\tools\Path.cpp" /> <ClCompile Include="..\..\core\tools\Path.cpp" />
<ClCompile Include="..\..\core\tools\Player.cpp" /> <ClCompile Include="..\..\core\tools\Player.cpp" />
<ClCompile Include="..\..\core\tools\Random.cpp" />
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp" /> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp" />
<ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" />
<ClCompile Include="..\..\core\transitions\FadeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\FadeTransition.cpp" />
@ -217,11 +216,11 @@
<ClCompile Include="..\..\core\utils\Font.cpp" /> <ClCompile Include="..\..\core\utils\Font.cpp" />
<ClCompile Include="..\..\core\utils\Function.cpp" /> <ClCompile Include="..\..\core\utils\Function.cpp" />
<ClCompile Include="..\..\core\utils\Point.cpp" /> <ClCompile Include="..\..\core\utils\Point.cpp" />
<ClCompile Include="..\..\core\utils\Random.cpp" />
<ClCompile Include="..\..\core\utils\Rect.cpp" /> <ClCompile Include="..\..\core\utils\Rect.cpp" />
<ClCompile Include="..\..\core\utils\Ref.cpp" /> <ClCompile Include="..\..\core\utils\Ref.cpp" />
<ClCompile Include="..\..\core\utils\Resource.cpp" /> <ClCompile Include="..\..\core\utils\Resource.cpp" />
<ClCompile Include="..\..\core\utils\Size.cpp" /> <ClCompile Include="..\..\core\utils\Size.cpp" />
<ClCompile Include="..\..\core\utils\String.cpp" />
<ClCompile Include="..\..\core\utils\Time.cpp" /> <ClCompile Include="..\..\core\utils\Time.cpp" />
<ClCompile Include="..\..\core\utils\Transform.cpp" /> <ClCompile Include="..\..\core\utils\Transform.cpp" />
</ItemGroup> </ItemGroup>

View File

@ -123,9 +123,6 @@
<ClCompile Include="..\..\core\utils\Size.cpp"> <ClCompile Include="..\..\core\utils\Size.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\utils\String.cpp">
<Filter>utils</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\Time.cpp"> <ClCompile Include="..\..\core\utils\Time.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
@ -156,9 +153,6 @@
<ClCompile Include="..\..\core\tools\Player.cpp"> <ClCompile Include="..\..\core\tools\Player.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\tools\Random.cpp">
<Filter>tools</Filter>
</ClCompile>
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp"> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp">
<Filter>transitions</Filter> <Filter>transitions</Filter>
</ClCompile> </ClCompile>
@ -210,6 +204,9 @@
<ClCompile Include="..\..\core\modules\Device.cpp"> <ClCompile Include="..\..\core\modules\Device.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\utils\Random.cpp">
<Filter>utils</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />

View File

@ -238,7 +238,6 @@
<ClCompile Include="..\..\core\tools\Music.cpp" /> <ClCompile Include="..\..\core\tools\Music.cpp" />
<ClCompile Include="..\..\core\tools\Path.cpp" /> <ClCompile Include="..\..\core\tools\Path.cpp" />
<ClCompile Include="..\..\core\tools\Player.cpp" /> <ClCompile Include="..\..\core\tools\Player.cpp" />
<ClCompile Include="..\..\core\tools\Random.cpp" />
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp" /> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp" />
<ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\EmergeTransition.cpp" />
<ClCompile Include="..\..\core\transitions\FadeTransition.cpp" /> <ClCompile Include="..\..\core\transitions\FadeTransition.cpp" />
@ -250,11 +249,11 @@
<ClCompile Include="..\..\core\utils\Font.cpp" /> <ClCompile Include="..\..\core\utils\Font.cpp" />
<ClCompile Include="..\..\core\utils\Function.cpp" /> <ClCompile Include="..\..\core\utils\Function.cpp" />
<ClCompile Include="..\..\core\utils\Point.cpp" /> <ClCompile Include="..\..\core\utils\Point.cpp" />
<ClCompile Include="..\..\core\utils\Random.cpp" />
<ClCompile Include="..\..\core\utils\Rect.cpp" /> <ClCompile Include="..\..\core\utils\Rect.cpp" />
<ClCompile Include="..\..\core\utils\Ref.cpp" /> <ClCompile Include="..\..\core\utils\Ref.cpp" />
<ClCompile Include="..\..\core\utils\Resource.cpp" /> <ClCompile Include="..\..\core\utils\Resource.cpp" />
<ClCompile Include="..\..\core\utils\Size.cpp" /> <ClCompile Include="..\..\core\utils\Size.cpp" />
<ClCompile Include="..\..\core\utils\String.cpp" />
<ClCompile Include="..\..\core\utils\Time.cpp" /> <ClCompile Include="..\..\core\utils\Time.cpp" />
<ClCompile Include="..\..\core\utils\Transform.cpp" /> <ClCompile Include="..\..\core\utils\Transform.cpp" />
</ItemGroup> </ItemGroup>

View File

@ -123,9 +123,6 @@
<ClCompile Include="..\..\core\utils\Size.cpp"> <ClCompile Include="..\..\core\utils\Size.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\utils\String.cpp">
<Filter>utils</Filter>
</ClCompile>
<ClCompile Include="..\..\core\utils\Time.cpp"> <ClCompile Include="..\..\core\utils\Time.cpp">
<Filter>utils</Filter> <Filter>utils</Filter>
</ClCompile> </ClCompile>
@ -156,9 +153,6 @@
<ClCompile Include="..\..\core\tools\Player.cpp"> <ClCompile Include="..\..\core\tools\Player.cpp">
<Filter>tools</Filter> <Filter>tools</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\tools\Random.cpp">
<Filter>tools</Filter>
</ClCompile>
<ClCompile Include="..\..\core\transitions\BoxTransition.cpp"> <ClCompile Include="..\..\core\transitions\BoxTransition.cpp">
<Filter>transitions</Filter> <Filter>transitions</Filter>
</ClCompile> </ClCompile>
@ -210,6 +204,9 @@
<ClCompile Include="..\..\core\modules\Device.cpp"> <ClCompile Include="..\..\core\modules\Device.cpp">
<Filter>modules</Filter> <Filter>modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\utils\Random.cpp">
<Filter>utils</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />