v1.1.1
This commit is contained in:
parent
8590e385c2
commit
205b195df0
|
|
@ -380,12 +380,6 @@
|
|||
<ClCompile Include="Tool\Timer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="e2daction.h" />
|
||||
<ClInclude Include="e2dbase.h" />
|
||||
<ClInclude Include="e2dmsg.h" />
|
||||
<ClInclude Include="e2dobj.h" />
|
||||
<ClInclude Include="e2dstyle.h" />
|
||||
<ClInclude Include="e2dtool.h" />
|
||||
<ClInclude Include="easy2d.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
|||
|
|
@ -170,24 +170,6 @@
|
|||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="e2daction.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="e2dbase.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="e2dmsg.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="e2dobj.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="e2dstyle.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="e2dtool.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="easy2d.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include "..\easy2d.h"
|
||||
#include "..\EasyX\easyx.h"
|
||||
#include "..\e2dmsg.h"
|
||||
|
||||
// 鼠标监听回调函数的容器
|
||||
static std::vector<MouseMsg*> s_vMouseMsg;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include "..\..\easy2d.h"
|
||||
#include "..\..\EasyX\easyx.h"
|
||||
#include "..\..\e2dobj.h"
|
||||
|
||||
|
||||
Button::Button() :
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "..\easy2d.h"
|
||||
#include "..\e2dobj.h"
|
||||
|
||||
|
||||
MouseNode::MouseNode() :
|
||||
|
|
|
|||
|
|
@ -1,313 +0,0 @@
|
|||
#pragma once
|
||||
#include <e2dbase.h>
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
class Action :
|
||||
public Object
|
||||
{
|
||||
friend class Sprite;
|
||||
friend class ActionManager;
|
||||
friend class ActionTwo;
|
||||
friend class ActionNeverStop;
|
||||
friend class ActionSequence;
|
||||
public:
|
||||
Action();
|
||||
virtual ~Action();
|
||||
|
||||
bool isRunning();
|
||||
void start();
|
||||
void resume();
|
||||
void pause();
|
||||
void stop();
|
||||
void setInterval(UINT ms);
|
||||
virtual Action * copy() = 0;
|
||||
virtual Action * reverse() const;
|
||||
|
||||
protected:
|
||||
bool m_bRunning;
|
||||
bool m_bStop;
|
||||
Sprite * m_pParent;
|
||||
UINT m_nMilliSeconds;
|
||||
LARGE_INTEGER m_nLast;
|
||||
LARGE_INTEGER m_nAnimationInterval;
|
||||
|
||||
protected:
|
||||
virtual void _init() = 0;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) = 0;
|
||||
virtual void _reset() = 0;
|
||||
};
|
||||
|
||||
|
||||
class Animation :
|
||||
public Action
|
||||
{
|
||||
public:
|
||||
Animation(float duration);
|
||||
virtual ~Animation();
|
||||
|
||||
protected:
|
||||
UINT m_nDuration;
|
||||
UINT m_nTotalDuration;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionMoveBy :
|
||||
public Animation
|
||||
{
|
||||
public:
|
||||
ActionMoveBy(float duration, CVector vec);
|
||||
virtual ~ActionMoveBy();
|
||||
|
||||
virtual ActionMoveBy * copy() override;
|
||||
virtual ActionMoveBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
CPoint m_BeginPos;
|
||||
CVector m_MoveVector;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionMoveTo :
|
||||
public ActionMoveBy
|
||||
{
|
||||
public:
|
||||
ActionMoveTo(float duration, CPoint pos);
|
||||
virtual ~ActionMoveTo();
|
||||
|
||||
virtual ActionMoveTo * copy() override;
|
||||
|
||||
protected:
|
||||
CPoint m_EndPos;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionScaleBy :
|
||||
public Animation
|
||||
{
|
||||
public:
|
||||
ActionScaleBy(float duration, float scaleX, float scaleY);
|
||||
virtual ~ActionScaleBy();
|
||||
|
||||
virtual ActionScaleBy * copy() override;
|
||||
virtual ActionScaleBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
float m_nBeginScaleX;
|
||||
float m_nBeginScaleY;
|
||||
float m_nVariationX;
|
||||
float m_nVariationY;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionScaleTo :
|
||||
public ActionScaleBy
|
||||
{
|
||||
public:
|
||||
ActionScaleTo(float duration, float scaleX, float scaleY);
|
||||
virtual ~ActionScaleTo();
|
||||
|
||||
virtual ActionScaleTo * copy() override;
|
||||
|
||||
protected:
|
||||
float m_nEndScaleX;
|
||||
float m_nEndScaleY;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionOpacityBy :
|
||||
public Animation
|
||||
{
|
||||
public:
|
||||
ActionOpacityBy(float duration, float opacity);
|
||||
virtual ~ActionOpacityBy();
|
||||
|
||||
virtual ActionOpacityBy * copy() override;
|
||||
virtual ActionOpacityBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
float m_nBeginVal;
|
||||
float m_nVariation;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionOpacityTo :
|
||||
public ActionOpacityBy
|
||||
{
|
||||
public:
|
||||
ActionOpacityTo(float duration, float opacity);
|
||||
virtual ~ActionOpacityTo();
|
||||
|
||||
virtual ActionOpacityTo * copy() override;
|
||||
|
||||
protected:
|
||||
float m_nEndVal;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionFadeIn :
|
||||
public ActionOpacityTo
|
||||
{
|
||||
public:
|
||||
ActionFadeIn(float duration) : ActionOpacityTo(duration, 1) {}
|
||||
};
|
||||
|
||||
|
||||
class ActionFadeOut :
|
||||
public ActionOpacityTo
|
||||
{
|
||||
public:
|
||||
ActionFadeOut(float duration) : ActionOpacityTo(duration, 0) {}
|
||||
};
|
||||
|
||||
|
||||
class ActionTwo :
|
||||
public Action
|
||||
{
|
||||
public:
|
||||
ActionTwo(Action * actionFirst, Action * actionSecond);
|
||||
virtual ~ActionTwo();
|
||||
|
||||
virtual ActionTwo * copy() override;
|
||||
virtual ActionTwo * reverse() const override;
|
||||
|
||||
protected:
|
||||
Action * m_FirstAction;
|
||||
Action * m_SecondAction;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionSequence :
|
||||
public Action
|
||||
{
|
||||
public:
|
||||
ActionSequence(int number, Action * action1, ...);
|
||||
virtual ~ActionSequence();
|
||||
|
||||
virtual ActionSequence * copy() override;
|
||||
virtual ActionSequence * reverse() const override;
|
||||
|
||||
protected:
|
||||
UINT m_nActionIndex;
|
||||
std::vector<Action*> m_vActions;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionDelay :
|
||||
public Action
|
||||
{
|
||||
public:
|
||||
ActionDelay(float duration);
|
||||
virtual ~ActionDelay();
|
||||
|
||||
virtual ActionDelay * copy() override;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionNeverStop :
|
||||
public Action
|
||||
{
|
||||
public:
|
||||
ActionNeverStop(Action * action);
|
||||
virtual ~ActionNeverStop();
|
||||
|
||||
virtual ActionNeverStop * copy() override;
|
||||
|
||||
protected:
|
||||
Action * m_Action;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionFrames :
|
||||
public Action
|
||||
{
|
||||
public:
|
||||
ActionFrames();
|
||||
~ActionFrames();
|
||||
|
||||
void addFrame(Image * frame);
|
||||
virtual ActionFrames * copy() override;
|
||||
virtual ActionFrames * reverse() const override;
|
||||
|
||||
protected:
|
||||
UINT m_nFrameIndex;
|
||||
std::vector<Image*> m_vFrames;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionCallback :
|
||||
public Action
|
||||
{
|
||||
public:
|
||||
ActionCallback(const std::function<void()>& callback);
|
||||
~ActionCallback();
|
||||
|
||||
virtual ActionCallback * copy() override;
|
||||
|
||||
protected:
|
||||
std::function<void()> m_Callback;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual bool _exec(LARGE_INTEGER nNow) override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
} // End of easy2d namespace
|
||||
184
Easy2D/e2dbase.h
184
Easy2D/e2dbase.h
|
|
@ -1,184 +0,0 @@
|
|||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <tchar.h>
|
||||
#include <atltypes.h>
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
#include <functional>
|
||||
|
||||
// String macros
|
||||
|
||||
#ifdef UNICODE
|
||||
#define tstring std::wstring
|
||||
#else
|
||||
#define tstring std::string
|
||||
#endif
|
||||
|
||||
|
||||
// Safe macros
|
||||
|
||||
#define SAFE_DELETE(p) { delete (p); (p) = nullptr; }
|
||||
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = nullptr; } }
|
||||
#define SAFE_RELEASE(p) { if (p) p->release(); }
|
||||
|
||||
|
||||
// Type Declare
|
||||
|
||||
typedef CPoint CVector;
|
||||
typedef unsigned int VK_KEY;
|
||||
typedef std::function<void()> CLICK_CALLBACK;
|
||||
typedef std::function<void()> TIMER_CALLBACK;
|
||||
typedef std::function<void(VK_KEY)> KEY_CALLBACK;
|
||||
typedef std::function<void()> MOUSE_CALLBACK;
|
||||
|
||||
|
||||
// Classes Declare
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
class Scene;
|
||||
class Node;
|
||||
|
||||
class App
|
||||
{
|
||||
public:
|
||||
App();
|
||||
~App();
|
||||
|
||||
// 窗口可选模式
|
||||
enum MODE { SHOW_CONSOLE = 1, NO_CLOSE = 2, NO_MINI_MIZE = 4 };
|
||||
|
||||
// 定义绘图窗口
|
||||
void createWindow(int width, int height, int mode = 0);
|
||||
// 定义绘图窗口
|
||||
void createWindow(CSize size, int mode = 0);
|
||||
// 定义绘图窗口
|
||||
void createWindow(tstring title, int width, int height, int mode = 0);
|
||||
// 定义绘图窗口
|
||||
void createWindow(tstring title, CSize size, int mode = 0);
|
||||
// 启动程序
|
||||
int run();
|
||||
// 释放所有内存资源
|
||||
void free();
|
||||
// 销毁该对象
|
||||
void destory();
|
||||
|
||||
// 获取程序实例
|
||||
static App * get();
|
||||
// 设置坐标原点
|
||||
static void setOrigin(int originX, int originY);
|
||||
// 获取坐标原点的物理横坐标
|
||||
static int getOriginX();
|
||||
// 获取坐标原点的物理纵坐标
|
||||
static int getOriginY();
|
||||
// 终止程序
|
||||
static void quit();
|
||||
// 终止程序
|
||||
static void end();
|
||||
// 修改窗口大小
|
||||
static void setWindowSize(int width, int height);
|
||||
// 修改窗口大小
|
||||
static void setWindowSize(CSize size);
|
||||
// 关闭窗口
|
||||
static void close();
|
||||
// 设置窗口标题
|
||||
static void setWindowTitle(tstring title);
|
||||
// 获取窗口标题
|
||||
static tstring getWindowTitle();
|
||||
// 获取窗口宽度
|
||||
static int getWidth();
|
||||
// 获取窗口高度
|
||||
static int getHeight();
|
||||
// 切换场景
|
||||
static void enterScene(Scene *scene, bool save = true);
|
||||
// 返回上一场景
|
||||
static void backScene();
|
||||
// 清空之前保存的所有场景
|
||||
static void clearScene();
|
||||
// 设置 AppName
|
||||
static void setAppName(tstring appname);
|
||||
// 获取 AppName
|
||||
static tstring getAppName();
|
||||
// 修改窗口背景色
|
||||
static void setBkColor(COLORREF color);
|
||||
// 设置帧率
|
||||
static void setFPS(DWORD fps);
|
||||
// 重置绘图样式为默认值
|
||||
static void reset();
|
||||
// 获取当前场景
|
||||
static Scene * getCurrentScene();
|
||||
|
||||
protected:
|
||||
tstring m_sTitle;
|
||||
tstring m_sAppName;
|
||||
Scene* m_CurrentScene;
|
||||
Scene* m_NextScene;
|
||||
std::stack<Scene*> m_SceneStack;
|
||||
LARGE_INTEGER m_nAnimationInterval;
|
||||
CSize m_Size;
|
||||
int m_nWindowMode;
|
||||
bool m_bRunning;
|
||||
bool m_bSaveScene;
|
||||
|
||||
protected:
|
||||
void _initGraph();
|
||||
void _mainLoop();
|
||||
void _enterNextScene();
|
||||
};
|
||||
|
||||
class FreePool
|
||||
{
|
||||
friend class App;
|
||||
friend class Object;
|
||||
|
||||
private:
|
||||
// 刷新内存池
|
||||
static void __flush();
|
||||
// 将一个节点放入释放池
|
||||
static void __add(Object * nptr);
|
||||
};
|
||||
|
||||
class Scene
|
||||
{
|
||||
friend class App;
|
||||
friend class MouseMsg;
|
||||
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
|
||||
// 重写这个函数,它将在进入这个场景时自动执行
|
||||
virtual void onEnter();
|
||||
// 重写这个函数,它将在离开这个场景时自动执行
|
||||
virtual void onExit();
|
||||
// 添加子成员到场景
|
||||
void add(Node * child, int zOrder = 0);
|
||||
// 删除子成员
|
||||
bool del(Node * child);
|
||||
// 清空所有子成员
|
||||
void clearAllChildren();
|
||||
|
||||
protected:
|
||||
std::vector<Node*> m_vChildren;
|
||||
|
||||
protected:
|
||||
void _exec();
|
||||
void _onDraw();
|
||||
};
|
||||
|
||||
class Object
|
||||
{
|
||||
friend class FreePool;
|
||||
|
||||
public:
|
||||
Object();
|
||||
virtual ~Object();
|
||||
|
||||
void retain();
|
||||
void release();
|
||||
|
||||
protected:
|
||||
int m_nRef;
|
||||
};
|
||||
|
||||
} // End of easy2d namespace
|
||||
112
Easy2D/e2dmsg.h
112
Easy2D/e2dmsg.h
|
|
@ -1,112 +0,0 @@
|
|||
#pragma once
|
||||
#include <e2dbase.h>
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
class MouseMsg
|
||||
{
|
||||
friend class App;
|
||||
|
||||
public:
|
||||
MouseMsg();
|
||||
MouseMsg(tstring name, const MOUSE_CALLBACK& callback);
|
||||
~MouseMsg();
|
||||
|
||||
// 添加键盘监听
|
||||
static void addListener(tstring name, const MOUSE_CALLBACK& callback);
|
||||
// 删除键盘监听
|
||||
static bool delListener(tstring name);
|
||||
// 删除所有键盘监听
|
||||
static void clearAllListeners();
|
||||
// 左键是否按下
|
||||
static bool isLButtonDown();
|
||||
// 右键是否按下
|
||||
static bool isRButtonDown();
|
||||
// 中键是否按下
|
||||
static bool isMButtonDown();
|
||||
// 获取鼠标X坐标
|
||||
static int getX();
|
||||
// 获取鼠标Y坐标
|
||||
static int getY();
|
||||
// 获取鼠标坐标
|
||||
static CPoint getPos();
|
||||
// 获取鼠标滚轮值
|
||||
static int getWheel();
|
||||
// 鼠标移动消息
|
||||
static bool isOnMouseMoved();
|
||||
// 左键双击消息
|
||||
static bool isOnLButtonDBClicked();
|
||||
// 右键按下消息
|
||||
static bool isOnLButtonDown();
|
||||
// 左键弹起消息
|
||||
static bool isOnLButtonUp();
|
||||
// 右键双击消息
|
||||
static bool isOnRButtonDBClicked();
|
||||
// 右键按下消息
|
||||
static bool isOnRButtonDown();
|
||||
// 右键弹起消息
|
||||
static bool isOnRButtonUp();
|
||||
// 中键双击消息
|
||||
static bool isOnMButtonDBClicked();
|
||||
// 中键按下消息
|
||||
static bool isOnMButtonDown();
|
||||
// 中键弹起消息
|
||||
static bool isOnMButtonUp();
|
||||
// 鼠标滚轮拨动消息
|
||||
static bool isOnWheel();
|
||||
// 清空鼠标消息
|
||||
static void resetMouseMsg();
|
||||
|
||||
private:
|
||||
static void __exec();
|
||||
|
||||
protected:
|
||||
tstring m_sName;
|
||||
MOUSE_CALLBACK m_callback;
|
||||
|
||||
protected:
|
||||
// 执行回调函数
|
||||
void onMouseMsg();
|
||||
};
|
||||
|
||||
|
||||
class KeyMsg
|
||||
{
|
||||
friend class App;
|
||||
|
||||
public:
|
||||
KeyMsg(tstring name, const KEY_CALLBACK& callback);
|
||||
~KeyMsg();
|
||||
|
||||
// 执行回调函数
|
||||
void onKbHit(VK_KEY key);
|
||||
|
||||
// 添加键盘监听
|
||||
static void addListener(tstring name, const KEY_CALLBACK& callback);
|
||||
// 删除键盘监听
|
||||
static bool delListener(tstring name);
|
||||
// 删除所有键盘监听
|
||||
static void clearAllListeners();
|
||||
// 判断键是否被按下,按下返回true
|
||||
static bool isKeyDown(VK_KEY key);
|
||||
|
||||
public:
|
||||
// 字母键值
|
||||
static const VK_KEY A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
|
||||
// 数字键值
|
||||
static const VK_KEY NUM_1, NUM_2, NUM_3, NUM_4, NUM_5, NUM_6, NUM_7, NUM_8, NUM_9, NUM_0;
|
||||
// 小数字键盘值
|
||||
static const VK_KEY NUMPAD_1, NUMPAD_2, NUMPAD_3, NUMPAD_4, NUMPAD_5, NUMPAD_6, NUMPAD_7, NUMPAD_8, NUMPAD_9, NUMPAD_0;
|
||||
// 控制键值
|
||||
static const VK_KEY Enter, Space, Up, Down, Left, Right, Esc, Shift, LShift, RShift, Ctrl, LCtrl, RCtrl;
|
||||
// F 键值
|
||||
static const VK_KEY F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12;
|
||||
|
||||
private:
|
||||
static void __exec();
|
||||
|
||||
protected:
|
||||
tstring m_sName;
|
||||
KEY_CALLBACK m_callback;
|
||||
};
|
||||
} // End of easy2d namespace
|
||||
589
Easy2D/e2dobj.h
589
Easy2D/e2dobj.h
|
|
@ -1,589 +0,0 @@
|
|||
#pragma once
|
||||
#include <e2dbase.h>
|
||||
#include <atlimage.h>
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
class FontStyle;
|
||||
class Color;
|
||||
class Action;
|
||||
|
||||
class Node :
|
||||
public Object
|
||||
{
|
||||
friend class Scene;
|
||||
friend class BatchNode;
|
||||
|
||||
public:
|
||||
Node();
|
||||
Node(CPoint p);
|
||||
Node(int x, int y);
|
||||
virtual ~Node();
|
||||
|
||||
// 获取节点横坐标
|
||||
virtual int getX() const;
|
||||
// 获取节点纵坐标
|
||||
virtual int getY() const;
|
||||
// 获取节点坐标
|
||||
virtual CPoint getPos() const;
|
||||
// 设置节点横坐标
|
||||
virtual void setX(int x);
|
||||
// 设置节点纵坐标
|
||||
virtual void setY(int y);
|
||||
// 设置节点横纵坐标
|
||||
virtual void setPos(int x, int y);
|
||||
// 设置节点横纵坐标
|
||||
virtual void setPos(CPoint p);
|
||||
// 移动节点
|
||||
virtual void move(int x, int y);
|
||||
// 设置节点横纵坐标
|
||||
virtual void move(CVector v);
|
||||
// 节点是否显示
|
||||
virtual bool display() const;
|
||||
// 设置节点是否显示
|
||||
virtual void setDisplay(bool value);
|
||||
// 获取节点绘图顺序
|
||||
virtual int getZOrder() const;
|
||||
// 设置节点绘图顺序(0为最先绘制,显示在最底层)
|
||||
virtual void setZOrder(int z);
|
||||
// 获取节点所在场景
|
||||
Scene * getParentScene();
|
||||
|
||||
protected:
|
||||
int m_nZOrder;
|
||||
bool m_bDisplay;
|
||||
Scene* m_pScene;
|
||||
CPoint m_Pos;
|
||||
|
||||
protected:
|
||||
virtual bool _exec(bool active);
|
||||
virtual void _onDraw() = 0;
|
||||
void setParentScene(Scene * scene);
|
||||
};
|
||||
|
||||
|
||||
class BatchNode :
|
||||
public Node
|
||||
{
|
||||
public:
|
||||
BatchNode();
|
||||
virtual ~BatchNode();
|
||||
|
||||
// 添加子节点
|
||||
void add(Node *child, int z_Order = 0);
|
||||
// 删除子节点
|
||||
bool del(Node * child);
|
||||
// 清空所有子节点
|
||||
void clearAllChildren();
|
||||
|
||||
protected:
|
||||
std::vector<Node*> m_vChildren;
|
||||
|
||||
protected:
|
||||
virtual bool _exec(bool active) override;
|
||||
virtual void _onDraw() override;
|
||||
};
|
||||
|
||||
|
||||
class Layer :
|
||||
public BatchNode
|
||||
{
|
||||
public:
|
||||
Layer();
|
||||
virtual ~Layer();
|
||||
|
||||
// 图层是否阻塞消息
|
||||
int getBlock() const;
|
||||
// 设置图层是否阻塞消息
|
||||
void setBlock(bool block);
|
||||
|
||||
protected:
|
||||
bool m_bBlock;
|
||||
|
||||
protected:
|
||||
virtual bool _exec(bool active) override;
|
||||
};
|
||||
|
||||
|
||||
class RectNode :
|
||||
public Node
|
||||
{
|
||||
public:
|
||||
RectNode();
|
||||
~RectNode();
|
||||
|
||||
virtual bool isCollisionWith(RectNode * rectNode) const;
|
||||
virtual bool isPointIn(CPoint p) const;
|
||||
|
||||
virtual void setWindowCenterX();
|
||||
virtual void setWindowCenterY();
|
||||
virtual void setWindowCenter();
|
||||
|
||||
virtual int getX() const override;
|
||||
virtual int getY() const override;
|
||||
virtual CPoint getPos() const override;
|
||||
virtual int getWidth() const;
|
||||
virtual int getHeight() const;
|
||||
virtual CSize getSize() const;
|
||||
virtual CRect getRect() const;
|
||||
|
||||
virtual void setX(int x) override;
|
||||
virtual void setY(int y) override;
|
||||
virtual void setPos(int x, int y) override;
|
||||
virtual void setPos(CPoint p) override;
|
||||
virtual void move(int x, int y) override;
|
||||
virtual void move(CVector v) override;
|
||||
virtual void setWidth(int width);
|
||||
virtual void setHeight(int height);
|
||||
virtual void setSize(int width, int height);
|
||||
virtual void setSize(CSize size);
|
||||
virtual void setRect(int x1, int y1, int x2, int y2);
|
||||
virtual void setRect(CPoint leftTop, CPoint rightBottom);
|
||||
virtual void setRect(CRect rect);
|
||||
|
||||
protected:
|
||||
CRect m_Rect;
|
||||
};
|
||||
|
||||
|
||||
class Text :
|
||||
public RectNode
|
||||
{
|
||||
friend class TextButton;
|
||||
|
||||
public:
|
||||
Text();
|
||||
// 根据字符串、颜色和字体创建文字
|
||||
Text(tstring text, COLORREF color = Color::white, FontStyle * font = FontStyle::getDefault());
|
||||
// 根据横纵坐标、字符串、颜色和字体创建文字
|
||||
Text(int x, int y, tstring text, COLORREF color = Color::white, FontStyle * font = FontStyle::getDefault());
|
||||
virtual ~Text();
|
||||
|
||||
// 获取当前颜色
|
||||
COLORREF getColor() const;
|
||||
// 获取当前文字
|
||||
tstring getText() const;
|
||||
// 获取当前字体
|
||||
FontStyle * getFontStyle();
|
||||
// 文本是否为空
|
||||
bool isEmpty() const;
|
||||
|
||||
// 设置文字
|
||||
void setText(tstring text);
|
||||
// 设置文字颜色
|
||||
void setColor(COLORREF color);
|
||||
// 设置字体
|
||||
void setFontStyle(FontStyle * style);
|
||||
|
||||
protected:
|
||||
tstring m_sText;
|
||||
COLORREF m_color;
|
||||
FontStyle * m_pFontStyle;
|
||||
|
||||
protected:
|
||||
virtual void _onDraw() override;
|
||||
};
|
||||
|
||||
|
||||
class Image :
|
||||
public RectNode
|
||||
{
|
||||
friend class Sprite;
|
||||
friend class ImageButton;
|
||||
public:
|
||||
Image();
|
||||
// 从图片文件获取图像
|
||||
Image(LPCTSTR ImageFile);
|
||||
/**
|
||||
* 从图片文件获取图像
|
||||
* 参数:图片文件名,图片裁剪坐标,图片裁剪宽度和高度
|
||||
*/
|
||||
Image(LPCTSTR ImageFile, int x, int y, int width, int height);
|
||||
virtual ~Image();
|
||||
|
||||
// 获取横向拉伸比例
|
||||
float getScaleX() const;
|
||||
// 获取纵向拉伸比例
|
||||
float getScaleY() const;
|
||||
// 获取透明度
|
||||
float getOpacity() const;
|
||||
|
||||
/**
|
||||
* 从图片文件获取图像
|
||||
* 返回值:图片加载是否成功
|
||||
*/
|
||||
bool setImage(LPCTSTR ImageFile);
|
||||
/**
|
||||
* 从图片文件获取图像
|
||||
* 参数:图片文件名,图片裁剪起始坐标,图片裁剪宽度和高度
|
||||
* 返回值:图片加载是否成功
|
||||
*/
|
||||
bool setImage(LPCTSTR ImageFile, int x, int y, int width, int height);
|
||||
/**
|
||||
* 从资源文件获取图像,不支持 png
|
||||
* 返回值:图片加载是否成功
|
||||
*/
|
||||
bool setImageFromRes(LPCTSTR pResName);
|
||||
/**
|
||||
* 从资源文件获取图像,不支持 png
|
||||
* 参数:资源名称,图片裁剪坐标,图片裁剪宽度和高度
|
||||
* 返回值:图片加载是否成功
|
||||
*/
|
||||
bool setImageFromRes(LPCTSTR pResName, int x, int y, int width, int height);
|
||||
// 裁剪图片(裁剪后会恢复 stretch 拉伸)
|
||||
void crop(int x, int y, int width, int height);
|
||||
// 将图片拉伸到固定宽高
|
||||
void stretch(int width, int height);
|
||||
// 按比例拉伸图片
|
||||
void setScale(float scaleX, float scaleY);
|
||||
// 设置透明度,范围 0~1.0f(只对 png 图片生效)
|
||||
void setOpacity(float value);
|
||||
// 设置透明色
|
||||
void setTransparentColor(COLORREF value);
|
||||
// 重置图片属性
|
||||
void reset();
|
||||
// 保存游戏截图
|
||||
static void saveScreenshot();
|
||||
|
||||
protected:
|
||||
CImage m_Image;
|
||||
CRect m_SrcRect;
|
||||
BYTE m_nAlpha;
|
||||
float m_fScaleX;
|
||||
float m_fScaleY;
|
||||
|
||||
protected:
|
||||
virtual void _onDraw() override;
|
||||
};
|
||||
|
||||
|
||||
class Sprite :
|
||||
public RectNode
|
||||
{
|
||||
friend class BatchSprite;
|
||||
public:
|
||||
Sprite();
|
||||
Sprite(Image * image);
|
||||
Sprite(LPCTSTR imageFileName);
|
||||
virtual ~Sprite();
|
||||
|
||||
// 判断是否和另一个精灵碰撞
|
||||
bool isCollisionWith(Sprite * sprite);
|
||||
// 修改精灵图片
|
||||
virtual void setImage(Image * image);
|
||||
// 添加动作
|
||||
virtual void addAction(Action * action);
|
||||
// 暂停所有动作
|
||||
virtual void pauseAllAction();
|
||||
// 继续所有动作
|
||||
virtual void resumeAllAction();
|
||||
// 停止所有动作
|
||||
virtual void stopAllAction();
|
||||
|
||||
virtual float getScaleX() const;
|
||||
virtual float getScaleY() const;
|
||||
virtual float getOpacity() const;
|
||||
|
||||
virtual void setScale(float scaleX, float scaleY);
|
||||
virtual void setOpacity(float opacity);
|
||||
|
||||
protected:
|
||||
float m_fScaleX;
|
||||
float m_fScaleY;
|
||||
BYTE m_nAlpha;
|
||||
Image * m_pImage;
|
||||
|
||||
protected:
|
||||
bool _exec(bool active) override;
|
||||
void _onDraw() override;
|
||||
};
|
||||
|
||||
|
||||
class BatchSprite :
|
||||
public Node
|
||||
{
|
||||
public:
|
||||
BatchSprite();
|
||||
virtual ~BatchSprite();
|
||||
|
||||
// 添加精灵
|
||||
void addSprite(Sprite * sprite, int z_Order = 0);
|
||||
// 删除精灵
|
||||
bool delSprite(Sprite * child);
|
||||
// 删除所有精灵
|
||||
void clearAllSprites();
|
||||
// 判断是否有精灵产生碰撞
|
||||
// 返回值:若有碰撞,返回第一个产生碰撞的精灵,否则返回空指针
|
||||
Sprite * isCollisionWith(Sprite * sprite);
|
||||
// 判断点是否在精灵内部
|
||||
// 返回值:若这个点在任意一个精灵内部,返回这个精灵,否则返回空指针
|
||||
Sprite * isPointIn(CPoint point);
|
||||
// 同时修改所有精灵的图片
|
||||
virtual void setImage(Image * image);
|
||||
|
||||
virtual float getScaleX() const;
|
||||
virtual float getScaleY() const;
|
||||
virtual float getOpacity() const;
|
||||
|
||||
virtual void setScale(float scaleX, float scaleY);
|
||||
virtual void setOpacity(float opacity);
|
||||
|
||||
protected:
|
||||
std::vector<Sprite*> m_vSprites;
|
||||
float m_fScaleX;
|
||||
float m_fScaleY;
|
||||
BYTE m_nAlpha;
|
||||
|
||||
protected:
|
||||
bool _exec(bool active) override;
|
||||
void _onDraw() override;
|
||||
};
|
||||
|
||||
|
||||
class MouseNode :
|
||||
public RectNode
|
||||
{
|
||||
public:
|
||||
MouseNode();
|
||||
virtual ~MouseNode();
|
||||
|
||||
// 鼠标是否移入
|
||||
virtual bool isMouseIn();
|
||||
// 鼠标是否选中
|
||||
virtual bool isSelected();
|
||||
// 设置回调函数
|
||||
virtual void setClickedCallback(const CLICK_CALLBACK & callback);
|
||||
// 设置回调函数
|
||||
virtual void setMouseInCallback(const CLICK_CALLBACK & callback);
|
||||
// 设置回调函数
|
||||
virtual void setMouseOutCallback(const CLICK_CALLBACK & callback);
|
||||
// 设置回调函数
|
||||
virtual void setSelectCallback(const CLICK_CALLBACK & callback);
|
||||
// 设置回调函数
|
||||
virtual void setUnselectCallback(const CLICK_CALLBACK & callback);
|
||||
// 重置状态
|
||||
virtual void reset();
|
||||
// 设置节点是否阻塞鼠标消息
|
||||
void setBlock(bool block);
|
||||
|
||||
protected:
|
||||
bool m_bTarget;
|
||||
bool m_bBlock;
|
||||
enum Status { NORMAL, MOUSEIN, SELECTED } m_eStatus;
|
||||
CLICK_CALLBACK m_OnMouseInCallback;
|
||||
CLICK_CALLBACK m_OnMouseOutCallback;
|
||||
CLICK_CALLBACK m_OnSelectCallback;
|
||||
CLICK_CALLBACK m_OnUnselectCallback;
|
||||
CLICK_CALLBACK m_ClickCallback;
|
||||
|
||||
protected:
|
||||
virtual bool _exec(bool active) override;
|
||||
virtual void _onDraw() override;
|
||||
|
||||
// 重写这个方法可以自定义按钮的判断方法
|
||||
virtual bool _isMouseIn();
|
||||
// 切换状态
|
||||
virtual void _setStatus(Status status);
|
||||
// 正常状态
|
||||
virtual void _onNormal() = 0;
|
||||
// 鼠标移入时
|
||||
virtual void _onMouseIn() = 0;
|
||||
// 鼠标选中时
|
||||
virtual void _onSelected() = 0;
|
||||
};
|
||||
|
||||
|
||||
class Button :
|
||||
public MouseNode
|
||||
{
|
||||
public:
|
||||
Button();
|
||||
virtual ~Button();
|
||||
|
||||
// 按钮是否启用
|
||||
virtual bool isEnable();
|
||||
// 设置是否启用
|
||||
virtual void setEnable(bool enable);
|
||||
|
||||
// 设置按钮横坐标
|
||||
virtual void setX(int x) override;
|
||||
// 设置按钮纵坐标
|
||||
virtual void setY(int y) override;
|
||||
// 设置按钮坐标
|
||||
virtual void setPos(int x, int y) override;
|
||||
// 设置按钮坐标
|
||||
virtual void setPos(CPoint p) override;
|
||||
// 移动按钮
|
||||
virtual void move(int x, int y) override;
|
||||
// 移动按钮
|
||||
virtual void move(CVector v) override;
|
||||
|
||||
protected:
|
||||
bool m_bEnable;
|
||||
|
||||
protected:
|
||||
virtual bool _exec(bool active) override;
|
||||
virtual void _onDraw() override;
|
||||
virtual void _resetPosition() = 0;
|
||||
|
||||
virtual void _onNormal() = 0;
|
||||
virtual void _onMouseIn() = 0;
|
||||
virtual void _onSelected() = 0;
|
||||
virtual void _onDisable() = 0;
|
||||
};
|
||||
|
||||
|
||||
class TextButton :
|
||||
public Button
|
||||
{
|
||||
public:
|
||||
TextButton();
|
||||
TextButton(tstring text);
|
||||
TextButton(Text * text);
|
||||
virtual ~TextButton();
|
||||
|
||||
// 设置按钮文字
|
||||
void setNormal(Text * text);
|
||||
// 设置鼠标移入时的按钮文字
|
||||
void setMouseIn(Text * text);
|
||||
// 设置鼠标选中时的按钮文字
|
||||
void setSelected(Text * text);
|
||||
// 设置按钮禁用时的按钮文字
|
||||
void setUnable(Text * text);
|
||||
|
||||
protected:
|
||||
Text * m_pNormalText;
|
||||
Text * m_pMouseInText;
|
||||
Text * m_pSelectedText;
|
||||
Text * m_pUnableText;
|
||||
|
||||
protected:
|
||||
virtual void _resetPosition() override;
|
||||
|
||||
virtual void _setStatus(Status status) override;
|
||||
virtual void _onNormal() override;
|
||||
virtual void _onMouseIn() override;
|
||||
virtual void _onSelected() override;
|
||||
virtual void _onDisable() override;
|
||||
};
|
||||
|
||||
|
||||
class ImageButton :
|
||||
public Button
|
||||
{
|
||||
public:
|
||||
ImageButton();
|
||||
ImageButton(LPCTSTR image);
|
||||
ImageButton(Image * image);
|
||||
virtual ~ImageButton();
|
||||
|
||||
// 设置按钮图片
|
||||
void setNormal(Image * image);
|
||||
// 设置鼠标移入时的按钮图片
|
||||
void setMouseIn(Image * image);
|
||||
// 设置鼠标选中时的按钮图片
|
||||
void setSelected(Image * image);
|
||||
// 设置按钮禁用时的按钮图片
|
||||
void setUnable(Image * image);
|
||||
|
||||
protected:
|
||||
Image * m_pNormalImage;
|
||||
Image * m_pMouseInImage;
|
||||
Image * m_pSelectedImage;
|
||||
Image * m_pUnableImage;
|
||||
|
||||
protected:
|
||||
virtual void _resetPosition() override;
|
||||
virtual void _setStatus(Status status) override;
|
||||
virtual void _onNormal() override;
|
||||
virtual void _onMouseIn() override;
|
||||
virtual void _onSelected() override;
|
||||
virtual void _onDisable() override;
|
||||
};
|
||||
|
||||
|
||||
class Shape :
|
||||
public Node
|
||||
{
|
||||
public:
|
||||
Shape();
|
||||
virtual ~Shape();
|
||||
|
||||
// 形状填充样式
|
||||
enum STYLE { ROUND, SOLID, FILL } m_eStyle;
|
||||
|
||||
// 获取形状的填充颜色
|
||||
COLORREF getFillColor() const;
|
||||
// 获取形状的线条颜色
|
||||
COLORREF getLineColor() const;
|
||||
// 设置填充颜色
|
||||
void setFillColor(COLORREF color);
|
||||
// 设置线条颜色
|
||||
void setLineColor(COLORREF color);
|
||||
// 设置填充样式
|
||||
void setStyle(STYLE style);
|
||||
|
||||
protected:
|
||||
COLORREF fillColor;
|
||||
COLORREF lineColor;
|
||||
|
||||
protected:
|
||||
virtual void _onDraw() override;
|
||||
virtual void solidShape() = 0;
|
||||
virtual void fillShape() = 0;
|
||||
virtual void roundShape() = 0;
|
||||
};
|
||||
|
||||
|
||||
class Rect :
|
||||
public Shape
|
||||
{
|
||||
public:
|
||||
Rect();
|
||||
Rect(int x, int y, int width, int height);
|
||||
virtual ~Rect();
|
||||
|
||||
// 获取矩形宽度
|
||||
int getWidth() const;
|
||||
// 获取矩形高度
|
||||
int getHeight() const;
|
||||
// 设置矩形宽度
|
||||
void setWidth(int width);
|
||||
// 设置矩形高度
|
||||
void setHeight(int height);
|
||||
// 设置矩形大小
|
||||
void setSize(int width, int height);
|
||||
|
||||
protected:
|
||||
CSize m_Size;
|
||||
|
||||
protected:
|
||||
virtual void solidShape() override;
|
||||
virtual void fillShape() override;
|
||||
virtual void roundShape() override;
|
||||
};
|
||||
|
||||
|
||||
class Circle :
|
||||
public Shape
|
||||
{
|
||||
public:
|
||||
Circle();
|
||||
Circle(int x, int y, int radius);
|
||||
virtual ~Circle();
|
||||
|
||||
// 获取圆形半径
|
||||
int getRadius() const;
|
||||
// 设置圆形半径
|
||||
void setRadius(int m_nRadius);
|
||||
|
||||
protected:
|
||||
int m_nRadius;
|
||||
|
||||
protected:
|
||||
virtual void solidShape() override;
|
||||
virtual void fillShape() override;
|
||||
virtual void roundShape() override;
|
||||
};
|
||||
|
||||
} // End of easy2d namespace
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
#pragma once
|
||||
#include <e2dbase.h>
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
class FontStyle :
|
||||
public Object
|
||||
{
|
||||
friend class Text;
|
||||
|
||||
public:
|
||||
FontStyle();
|
||||
/**
|
||||
* 使用 [字体名称、字号、粗细、字宽、斜体、下划线、删除线、字符串书写角度、
|
||||
* 每个字符书写角度、抗锯齿] 属性创建字体样式
|
||||
*/
|
||||
FontStyle(LPCTSTR fontfamily, LONG height = 18, LONG weight = 0, LONG width = 0,
|
||||
bool italic = 0, bool underline = 0, bool strikeout = 0, LONG escapement = 0,
|
||||
LONG orientation = 0, bool quality = true);
|
||||
virtual ~FontStyle();
|
||||
|
||||
// 获取默认字体
|
||||
static FontStyle * getDefault();
|
||||
// 设置字符平均高度
|
||||
void setHeight(LONG value);
|
||||
// 设置字符平均宽度(0表示自适应)
|
||||
void setWidth(LONG value);
|
||||
// 设置字体
|
||||
void setFontFamily(LPCTSTR value);
|
||||
// 设置字符笔画粗细,范围0~1000,默认为0
|
||||
void setWeight(LONG value);
|
||||
// 设置斜体
|
||||
void setItalic(bool value);
|
||||
// 设置下划线
|
||||
void setUnderline(bool value);
|
||||
// 设置删除线
|
||||
void setStrikeOut(bool value);
|
||||
// 设置字符串的书写角度,单位0.1度,默认为0
|
||||
void setEscapement(LONG value);
|
||||
// 设置每个字符的书写角度,单位0.1度,默认为0
|
||||
void setOrientation(LONG value);
|
||||
// 设置字体抗锯齿,默认为true
|
||||
void setQuality(bool value);
|
||||
|
||||
protected:
|
||||
LOGFONT m_font;
|
||||
};
|
||||
|
||||
|
||||
class FontWeight
|
||||
{
|
||||
public:
|
||||
static const LONG dontcare; // 粗细值 0
|
||||
static const LONG thin; // 粗细值 100
|
||||
static const LONG extraLight; // 粗细值 200
|
||||
static const LONG light; // 粗细值 300
|
||||
static const LONG normal; // 粗细值 400
|
||||
static const LONG regular; // 粗细值 400
|
||||
static const LONG medium; // 粗细值 500
|
||||
static const LONG demiBlod; // 粗细值 600
|
||||
static const LONG blod; // 粗细值 700
|
||||
static const LONG extraBold; // 粗细值 800
|
||||
static const LONG black; // 粗细值 900
|
||||
static const LONG heavy; // 粗细值 900
|
||||
};
|
||||
|
||||
class Color
|
||||
{
|
||||
public:
|
||||
static const COLORREF black; // 黑色
|
||||
static const COLORREF blue; // 蓝色
|
||||
static const COLORREF green; // 绿色
|
||||
static const COLORREF cyan; // 青色
|
||||
static const COLORREF red; // 红色
|
||||
static const COLORREF magenta; // 紫色
|
||||
static const COLORREF brown; // 棕色
|
||||
static const COLORREF lightgray; // 亮灰色
|
||||
static const COLORREF darkgray; // 深灰色
|
||||
static const COLORREF lightblue; // 亮蓝色
|
||||
static const COLORREF lightgreen; // 亮绿色
|
||||
static const COLORREF lightcyan; // 亮青色
|
||||
static const COLORREF lightred; // 亮红色
|
||||
static const COLORREF lightmagenta; // 亮紫色
|
||||
static const COLORREF yellow; // 亮黄色
|
||||
static const COLORREF white; // 白色
|
||||
|
||||
// 通过红、绿、蓝颜色分量合成颜色
|
||||
static COLORREF getFromRGB(BYTE r, BYTE g, BYTE b);
|
||||
// 通过色相、饱和度、亮度合成颜色
|
||||
static COLORREF getFromHSL(float H, float S, float L);
|
||||
// 通过色相、饱和度、明度合成颜色
|
||||
static COLORREF getFromHSV(float H, float S, float V);
|
||||
|
||||
// 返回指定颜色中的红色值
|
||||
static BYTE getRValue(COLORREF color);
|
||||
// 返回指定颜色中的绿色值
|
||||
static BYTE getGValue(COLORREF color);
|
||||
// 返回指定颜色中的蓝色值
|
||||
static BYTE getBValue(COLORREF color);
|
||||
// 返回与指定颜色对应的灰度值颜色
|
||||
static COLORREF getGray(COLORREF color);
|
||||
};
|
||||
|
||||
} // End of easy2d namespace
|
||||
174
Easy2D/e2dtool.h
174
Easy2D/e2dtool.h
|
|
@ -1,174 +0,0 @@
|
|||
#pragma once
|
||||
#include <e2dbase.h>
|
||||
|
||||
namespace easy2d
|
||||
{
|
||||
class Action;
|
||||
|
||||
class FileUtils
|
||||
{
|
||||
public:
|
||||
// 获取系统的 AppData\Local 路径
|
||||
static tstring getLocalAppDataPath();
|
||||
// 获取默认的保存路径
|
||||
static tstring getDefaultSavePath();
|
||||
// 保存 int 型的值
|
||||
static void saveInt(LPCTSTR key, int value);
|
||||
// 保存 double 型的值
|
||||
static void saveDouble(LPCTSTR key, double value);
|
||||
// 保存 字符串 型的值(不要在 Unicode 字符集下保存中文字符)
|
||||
static void saveString(LPCTSTR key, tstring value);
|
||||
// 获取 int 型的值(若不存在则返回 default 参数的值)
|
||||
static int getInt(LPCTSTR key, int default);
|
||||
// 获取 double 型的值(若不存在则返回 default 参数的值)
|
||||
static double getDouble(LPCTSTR key, double default);
|
||||
// 获取 字符串 型的值(若不存在则返回 default 参数的值)
|
||||
static tstring getString(LPCTSTR key, tstring default);
|
||||
// 得到文件扩展名(小写)
|
||||
static tstring getFileExtension(const tstring& filePath);
|
||||
/**
|
||||
* 打开保存文件对话框,得到有效保存路径返回 true
|
||||
* 参数:返回文件路径的字符串,窗口标题,设置扩展名过滤,设置默认扩展名
|
||||
*/
|
||||
static bool getSaveFilePath(tstring& path, LPCTSTR title = _T("保存到"), LPCTSTR defExt = NULL);
|
||||
};
|
||||
|
||||
|
||||
class MusicUtils
|
||||
{
|
||||
public:
|
||||
// 播放背景音乐
|
||||
static void playBackgroundMusic(tstring pszFilePath, bool bLoop = true);
|
||||
// 停止背景音乐
|
||||
static void stopBackgroundMusic(bool bReleaseData = false);
|
||||
// 暂停背景音乐
|
||||
static void pauseBackgroundMusic();
|
||||
// 继续播放背景音乐
|
||||
static void resumeBackgroundMusic();
|
||||
// 从头播放背景音乐
|
||||
static void rewindBackgroundMusic();
|
||||
// 背景音乐是否正在播放
|
||||
static bool isBackgroundMusicPlaying();
|
||||
// 设置背景音乐音量,0 ~ 1.0f
|
||||
static void setBackgroundMusicVolume(float volume);
|
||||
|
||||
// 播放音效
|
||||
static unsigned int playMusic(tstring pszFilePath, bool loop = false);
|
||||
// 停止音效
|
||||
static void stopMusic(unsigned int nSoundId);
|
||||
// 预加载音效
|
||||
static void preloadMusic(tstring pszFilePath);
|
||||
// 暂停音效
|
||||
static void pauseMusic(unsigned int nSoundId);
|
||||
// 继续播放音效
|
||||
static void resumeMusic(unsigned int nSoundId);
|
||||
// 卸载音效
|
||||
static void unloadMusic(LPCTSTR pszFilePath);
|
||||
// 设置特定音乐的音量,0 ~ 1.0f
|
||||
static void setVolume(tstring pszFilePath, float volume);
|
||||
|
||||
// 暂停所有音乐
|
||||
static void pauseAllMusics();
|
||||
// 继续播放所有音乐
|
||||
static void resumeAllMusics();
|
||||
// 停止所有音乐
|
||||
static void stopAllMusics();
|
||||
// 停止所有音乐,并释放内存
|
||||
static void end();
|
||||
// 设置总音量,0 ~ 1.0f
|
||||
static void setVolume(float volume);
|
||||
};
|
||||
|
||||
|
||||
class Timer
|
||||
{
|
||||
friend class App;
|
||||
|
||||
public:
|
||||
Timer(tstring name, UINT ms, const TIMER_CALLBACK & callback);
|
||||
~Timer();
|
||||
|
||||
// 启动定时器
|
||||
void start();
|
||||
// 停止定时器
|
||||
void stop();
|
||||
// 定时器是否正在运行
|
||||
bool isRunning();
|
||||
// 设置间隔时间
|
||||
void setInterval(UINT ms);
|
||||
// 设置回调函数
|
||||
void setCallback(const TIMER_CALLBACK& callback);
|
||||
// 设置定时器名称
|
||||
void setName(tstring name);
|
||||
// 获取定时器间隔时间
|
||||
UINT getInterval() const;
|
||||
// 获取定时器名称
|
||||
tstring getName() const;
|
||||
|
||||
// 添加定时器
|
||||
static void addTimer(Timer * timer);
|
||||
// 添加定时器
|
||||
static void addTimer(tstring name, UINT ms, const TIMER_CALLBACK & callback);
|
||||
// 根据名称获取定时器
|
||||
static Timer * getTimer(tstring name);
|
||||
// 启动特定定时器
|
||||
static bool startTimer(tstring name);
|
||||
// 停止特定定时器
|
||||
static bool stopTimer(tstring name);
|
||||
// 删除特定定时器
|
||||
static bool delTimer(tstring name);
|
||||
// 删除所有定时器
|
||||
static void clearAllTimers();
|
||||
|
||||
protected:
|
||||
bool m_bRunning;
|
||||
tstring m_sName;
|
||||
TIMER_CALLBACK m_callback;
|
||||
LARGE_INTEGER m_nLast;
|
||||
LARGE_INTEGER m_nAnimationInterval;
|
||||
UINT m_nMilliSeconds;
|
||||
|
||||
private:
|
||||
static void __exec();
|
||||
};
|
||||
|
||||
|
||||
class ActionManager
|
||||
{
|
||||
friend class App;
|
||||
friend class Sprite;
|
||||
public:
|
||||
// 继续一个特定的动作
|
||||
static void startAction(Action * action);
|
||||
// 继续一个特定的动作
|
||||
static void resumeAction(Action * action);
|
||||
// 暂停一个特定的动作
|
||||
static void pauseAction(Action * action);
|
||||
// 停止一个特定的动作
|
||||
static void stopAction(Action * action);
|
||||
|
||||
// 继续一个 Sprite 的所有动作
|
||||
static void startSpriteAllActions(Sprite * sprite);
|
||||
// 继续一个 Sprite 的所有动作
|
||||
static void resumeSpriteAllActions(Sprite * sprite);
|
||||
// 暂停一个 Sprite 的所有动作
|
||||
static void pauseSpriteAllActions(Sprite * sprite);
|
||||
// 停止一个 Sprite 的所有动作
|
||||
static void stopSpriteAllActions(Sprite * sprite);
|
||||
|
||||
// 继续当前存在的所有动作
|
||||
static void startAllActions();
|
||||
// 继续当前存在的所有动作
|
||||
static void resumeAllActions();
|
||||
// 暂停当前存在的所有动作
|
||||
static void pauseAllActions();
|
||||
// 停止当前存在的所有动作
|
||||
static void stopAllActions();
|
||||
|
||||
private:
|
||||
static void __exec();
|
||||
// 将一个动作添加进动作管理器
|
||||
static void addAction(Action * action);
|
||||
};
|
||||
|
||||
} // End of easy2d namespace
|
||||
1462
Easy2D/easy2d.h
1462
Easy2D/easy2d.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue