Update EApp
This commit is contained in:
parent
5b3e83cb6b
commit
36a714ee9b
|
|
@ -1,140 +1,193 @@
|
||||||
#include "..\easy2d.h"
|
#include "..\easy2d.h"
|
||||||
#include "..\Win\winbase.h"
|
#include "..\Win\winbase.h"
|
||||||
#include "..\EasyX\easyx.h"
|
|
||||||
#include <time.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <imm.h>
|
|
||||||
#pragma comment(lib, "imm32.lib")
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
using namespace std::this_thread;
|
||||||
|
|
||||||
// App 的唯一实例
|
|
||||||
static App * s_pInstance = nullptr;
|
|
||||||
// 场景栈
|
|
||||||
static std::stack<Scene*> s_SceneStack;
|
|
||||||
|
|
||||||
App::App() :
|
#ifndef HINST_THISCOMPONENT
|
||||||
m_pCurrentScene(nullptr),
|
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
|
||||||
m_pNextScene(nullptr),
|
#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
|
||||||
m_pLoadingScene(nullptr),
|
#endif
|
||||||
m_bRunning(false),
|
|
||||||
m_nWindowMode(0),
|
|
||||||
m_bSaveScene(true)
|
EApp * s_pInstance = nullptr;
|
||||||
|
std::stack<Scene*> s_SceneStack;
|
||||||
|
|
||||||
|
e2d::EApp::EApp()
|
||||||
|
: m_bRunning(false)
|
||||||
|
, m_ClearColor(EColor::White)
|
||||||
|
, m_bSaveScene(true)
|
||||||
|
, m_pCurrentScene(nullptr)
|
||||||
|
, m_pNextScene(nullptr)
|
||||||
|
, m_pLoadingScene(nullptr)
|
||||||
{
|
{
|
||||||
assert(!s_pInstance); // 不能同时存在两个 App 实例
|
|
||||||
s_pInstance = this; // 保存实例对象
|
s_pInstance = this; // 保存实例对象
|
||||||
}
|
}
|
||||||
|
|
||||||
App::~App()
|
e2d::EApp::~EApp()
|
||||||
{
|
{
|
||||||
|
SafeReleaseInterface(&GetFactory());
|
||||||
|
SafeReleaseInterface(&GetRenderTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
App * App::get()
|
EApp * e2d::EApp::get()
|
||||||
{
|
{
|
||||||
assert(s_pInstance); // 断言实例存在
|
Assert(s_pInstance); // 断言实例存在
|
||||||
return s_pInstance; // 获取 App 的唯一实例
|
return s_pInstance; // 获取 EApp 的唯一实例
|
||||||
}
|
}
|
||||||
|
|
||||||
int App::run()
|
bool e2d::EApp::init(EString title, ESize size, bool bShowConsole /* = false */)
|
||||||
{
|
{
|
||||||
// 开启批量绘图
|
return init(title, size.width, size.height, bShowConsole);
|
||||||
BeginBatchDraw();
|
}
|
||||||
// 记录当前时间
|
|
||||||
steady_clock::time_point nLast = steady_clock::now();
|
|
||||||
// 帧间隔
|
|
||||||
LONGLONG nAnimationInterval = 17LL;
|
|
||||||
// 时间间隔
|
|
||||||
LONGLONG nInterval = 0LL;
|
|
||||||
// 挂起时长
|
|
||||||
LONGLONG nWaitMS = 0L;
|
|
||||||
|
|
||||||
// 将隐藏的窗口显示
|
bool e2d::EApp::init(EString title, UINT32 width, UINT32 height, bool bShowConsole /* = false */)
|
||||||
ShowWindow(GetHWnd(), SW_NORMAL);
|
{
|
||||||
// 运行游戏
|
m_sTitle = title;
|
||||||
m_bRunning = true;
|
|
||||||
|
|
||||||
// 启动多线程
|
HRESULT hr;
|
||||||
//std::thread t(std::bind(&App::_mainLoop, this));
|
hr = CoInitialize(NULL);
|
||||||
//t.join();
|
|
||||||
|
|
||||||
// 进入主循环
|
if (SUCCEEDED(hr))
|
||||||
while (m_bRunning)
|
|
||||||
{
|
{
|
||||||
// 刷新计时
|
// 关闭控制台.
|
||||||
::FlushSteadyClock();
|
if (bShowConsole)
|
||||||
// 计算时间间隔
|
|
||||||
nInterval = duration_cast<milliseconds>(GetNow() - nLast).count();
|
|
||||||
// 判断间隔时间是否足够
|
|
||||||
if (nInterval >= nAnimationInterval)
|
|
||||||
{
|
{
|
||||||
// 记录当前时间
|
HWND hwnd = FindWindow(L"ConsoleWindowClass", NULL);
|
||||||
nLast = GetNow();
|
|
||||||
// 刷新游戏画面
|
if (hwnd)
|
||||||
_draw();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 计算挂起时长
|
|
||||||
nWaitMS = nAnimationInterval - nInterval - 1;
|
|
||||||
// 挂起线程,释放 CPU 占用
|
|
||||||
if (nWaitMS > 1LL)
|
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(milliseconds(nWaitMS));
|
hr = ShowWindow(hwnd, SW_HIDE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 停止批量绘图
|
|
||||||
EndBatchDraw();
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
// 初始化 device-indpendent 资源
|
||||||
|
// 比如 Direct2D factory.
|
||||||
|
hr = CreateDeviceIndependentResources();
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
// 注册窗口类
|
||||||
|
WNDCLASSEX wcex = { sizeof(WNDCLASSEX) };
|
||||||
|
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
|
wcex.lpfnWndProc = EApp::WndProc;
|
||||||
|
wcex.cbClsExtra = 0;
|
||||||
|
wcex.cbWndExtra = sizeof(LONG_PTR);
|
||||||
|
wcex.hInstance = HINST_THISCOMPONENT;
|
||||||
|
wcex.hbrBackground = NULL;
|
||||||
|
wcex.lpszMenuName = NULL;
|
||||||
|
wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION);
|
||||||
|
wcex.lpszClassName = L"E2DApp";
|
||||||
|
|
||||||
|
RegisterClassEx(&wcex);
|
||||||
|
|
||||||
|
|
||||||
|
// Because the CreateWindow function takes its size in pixels,
|
||||||
|
// obtain the system DPI and use it to scale the window size.
|
||||||
|
FLOAT dpiX, dpiY;
|
||||||
|
|
||||||
|
// The factory returns the current system DPI. This is also the value it will use
|
||||||
|
// to create its own windows.
|
||||||
|
GetFactory()->GetDesktopDpi(&dpiX, &dpiY);
|
||||||
|
|
||||||
|
|
||||||
|
// Create the window.
|
||||||
|
GetHWnd() = CreateWindow(
|
||||||
|
L"E2DApp",
|
||||||
|
m_sTitle.c_str(),
|
||||||
|
WS_OVERLAPPEDWINDOW,
|
||||||
|
CW_USEDEFAULT,
|
||||||
|
CW_USEDEFAULT,
|
||||||
|
static_cast<UINT>(ceil(width * dpiX / 96.f)),
|
||||||
|
static_cast<UINT>(ceil(height * dpiY / 96.f)),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
HINST_THISCOMPONENT,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
hr = GetHWnd() ? S_OK : E_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCEEDED(hr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 运行游戏
|
||||||
|
void e2d::EApp::run()
|
||||||
|
{
|
||||||
|
// 显示窗口
|
||||||
|
ShowWindow(GetHWnd(), SW_SHOWNORMAL);
|
||||||
|
UpdateWindow(GetHWnd());
|
||||||
|
// 运行游戏
|
||||||
|
m_bRunning = true;
|
||||||
|
|
||||||
|
MSG msg;
|
||||||
|
|
||||||
|
while (m_bRunning)
|
||||||
|
{
|
||||||
|
// 处理窗口消息
|
||||||
|
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
|
||||||
|
{
|
||||||
|
if (msg.message == WM_QUIT)
|
||||||
|
{
|
||||||
|
m_bRunning = false;
|
||||||
|
}
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
// 执行主循环
|
||||||
|
_mainLoop();
|
||||||
|
}
|
||||||
// 关闭窗口
|
// 关闭窗口
|
||||||
close();
|
close();
|
||||||
// 释放所有内存占用
|
// 释放所有内存占用
|
||||||
free();
|
free();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::_initGraph()
|
void e2d::EApp::_mainLoop()
|
||||||
{
|
{
|
||||||
// 创建绘图环境
|
static steady_clock::time_point nNow;
|
||||||
initgraph(m_Size.cx, m_Size.cy, m_nWindowMode);
|
static steady_clock::time_point nLast = steady_clock::now();
|
||||||
// 隐藏当前窗口(防止在加载阶段显示黑窗口)
|
// 帧间隔
|
||||||
ShowWindow(GetHWnd(), SW_HIDE);
|
static LONGLONG nAnimationInterval = 17LL;
|
||||||
// 获取屏幕分辨率
|
// 时间间隔
|
||||||
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
static LONGLONG nInterval = 0LL;
|
||||||
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
// 挂起时长
|
||||||
// 获取窗口大小
|
static LONGLONG nWaitMS = 0L;
|
||||||
CRect rcWindow;
|
|
||||||
GetWindowRect(GetHWnd(), &rcWindow);
|
// 刷新计时
|
||||||
// 设置窗口在屏幕居中
|
nNow = steady_clock::now();
|
||||||
SetWindowPos(GetHWnd(), HWND_TOP,
|
// 计算时间间隔
|
||||||
(screenWidth - rcWindow.Size().cx) / 2,
|
nInterval = duration_cast<milliseconds>(nNow - nLast).count();
|
||||||
(screenHeight - rcWindow.Size().cy) / 2,
|
// 判断间隔时间是否足够
|
||||||
rcWindow.Size().cx,
|
if (nInterval >= nAnimationInterval)
|
||||||
rcWindow.Size().cy,
|
|
||||||
SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOSIZE);
|
|
||||||
// 禁用输入法
|
|
||||||
ImmAssociateContext(GetHWnd(), NULL);
|
|
||||||
// 重置绘图环境
|
|
||||||
reset();
|
|
||||||
// 设置窗口标题
|
|
||||||
if (m_sTitle.empty())
|
|
||||||
{
|
{
|
||||||
// 保存当前标题
|
// 记录当前时间
|
||||||
TCHAR title[31];
|
nLast = nNow;
|
||||||
GetWindowText(GetHWnd(), title, 30);
|
//
|
||||||
m_sTitle = title;
|
_onControl();
|
||||||
if (m_sAppName.empty()) m_sAppName = title;
|
// 刷新游戏画面
|
||||||
|
_onRender();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
setWindowTitle(m_sTitle);
|
// 计算挂起时长
|
||||||
|
nWaitMS = nAnimationInterval - nInterval - 1;
|
||||||
|
// 挂起线程,释放 CPU 占用
|
||||||
|
if (nWaitMS > 1LL)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(milliseconds(nWaitMS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::_draw()
|
void e2d::EApp::_onControl()
|
||||||
{
|
{
|
||||||
// 下一场景指针不为空时,切换场景
|
// 下一场景指针不为空时,切换场景
|
||||||
if (m_pNextScene)
|
if (m_pNextScene)
|
||||||
|
|
@ -143,164 +196,196 @@ void App::_draw()
|
||||||
_enterNextScene();
|
_enterNextScene();
|
||||||
}
|
}
|
||||||
// 断言当前场景非空
|
// 断言当前场景非空
|
||||||
assert(m_pCurrentScene);
|
Assert(m_pCurrentScene);
|
||||||
|
|
||||||
cleardevice(); // 清空画面
|
//MouseMsg::__exec(); // 鼠标检测
|
||||||
m_pCurrentScene->_onDraw(); // 绘制当前场景
|
//KeyMsg::__exec(); // 键盘按键检测
|
||||||
FlushBatchDraw(); // 刷新画面
|
//Timer::__exec(); // 定时器执行程序
|
||||||
|
//ActionManager::__exec(); // 动作管理器执行程序
|
||||||
MouseMsg::__exec(); // 鼠标检测
|
//FreePool::__flush(); // 刷新内存池
|
||||||
KeyMsg::__exec(); // 键盘按键检测
|
|
||||||
Timer::__exec(); // 定时器执行程序
|
|
||||||
ActionManager::__exec(); // 动作管理器执行程序
|
|
||||||
FreePool::__flush(); // 刷新内存池
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::_mainLoop()
|
// This method discards device-specific
|
||||||
|
// resources if the Direct3D device dissapears during execution and
|
||||||
|
// recreates the resources the next time it's invoked.
|
||||||
|
bool e2d::EApp::_onRender()
|
||||||
{
|
{
|
||||||
while (true)
|
HRESULT hr = S_OK;
|
||||||
|
|
||||||
|
hr = CreateDeviceResources();
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
if (m_bRunning)
|
GetRenderTarget()->BeginDraw();
|
||||||
{
|
|
||||||
MouseMsg::__exec(); // 鼠标检测
|
GetRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||||
KeyMsg::__exec(); // 键盘按键检测
|
|
||||||
Timer::__exec(); // 定时器执行程序
|
GetRenderTarget()->Clear(D2D1::ColorF(m_ClearColor));
|
||||||
ActionManager::__exec(); // 动作管理器执行程序
|
|
||||||
FreePool::__flush(); // 刷新内存池
|
m_pCurrentScene->_onDraw(); // 绘制当前场景
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(milliseconds(10));
|
hr = GetRenderTarget()->EndDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hr == D2DERR_RECREATE_TARGET)
|
||||||
|
{
|
||||||
|
hr = S_OK;
|
||||||
|
DiscardDeviceResources();
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCEEDED(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::createWindow(int width, int height, int mode)
|
void e2d::EApp::setWindowSize(int width, int height)
|
||||||
{
|
{
|
||||||
// 保存窗口信息
|
|
||||||
m_Size.cx = width;
|
|
||||||
m_Size.cy = height;
|
|
||||||
m_nWindowMode = mode;
|
|
||||||
// 创建窗口
|
|
||||||
_initGraph();
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::createWindow(CSize size, int mode)
|
|
||||||
{
|
|
||||||
createWindow(size.cx, size.cy, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::createWindow(TString title, int width, int height, int mode)
|
|
||||||
{
|
|
||||||
// 保存窗口信息
|
|
||||||
m_Size.cx = width;
|
|
||||||
m_Size.cy = height;
|
|
||||||
m_nWindowMode = mode;
|
|
||||||
m_sTitle = title;
|
|
||||||
if (m_sAppName.empty()) m_sAppName = title;
|
|
||||||
// 创建窗口
|
|
||||||
_initGraph();
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::createWindow(TString title, CSize size, int mode)
|
|
||||||
{
|
|
||||||
createWindow(title, size.cx, size.cy, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::setWindowSize(int width, int height)
|
|
||||||
{
|
|
||||||
// 游戏正在运行时才允许修改窗口大小
|
|
||||||
assert(s_pInstance->m_bRunning);
|
|
||||||
|
|
||||||
// 获取屏幕分辨率
|
// 获取屏幕分辨率
|
||||||
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||||
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||||
// 获取窗口大小(包含菜单栏)
|
// 获取窗口大小(包含菜单栏)
|
||||||
CRect rcWindow;
|
tagRECT rcWindow;
|
||||||
GetWindowRect(GetHWnd(), &rcWindow);
|
GetWindowRect(GetHWnd(), &rcWindow);
|
||||||
// 获取客户区大小
|
// 获取客户区大小
|
||||||
CRect rcClient;
|
tagRECT rcClient;
|
||||||
GetClientRect(GetHWnd(), &rcClient);
|
GetClientRect(GetHWnd(), &rcClient);
|
||||||
// 计算边框大小
|
// 计算边框大小
|
||||||
width += (rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left);
|
width += (rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left);
|
||||||
height += (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top);
|
height += (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top);
|
||||||
// 销毁当前窗口
|
// 销毁当前窗口
|
||||||
// DestroyWindow(GetHWnd());/* 无法操作多线程导致失效 */
|
// DestroyWindow(m_);
|
||||||
// 修改窗口大小,并设置窗口在屏幕居中
|
// 修改窗口大小,并设置窗口在屏幕居中
|
||||||
SetWindowPos(GetHWnd(), HWND_TOP,
|
SetWindowPos(
|
||||||
|
GetHWnd(),
|
||||||
|
HWND_TOP,
|
||||||
(screenWidth - width) / 2,
|
(screenWidth - width) / 2,
|
||||||
(screenHeight - height) / 2,
|
(screenHeight - height) / 2,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
SWP_SHOWWINDOW);
|
SWP_SHOWWINDOW
|
||||||
// 重置窗口属性
|
);
|
||||||
reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::setWindowSize(CSize size)
|
void e2d::EApp::setWindowSize(ESize size)
|
||||||
{
|
{
|
||||||
setWindowSize(size.cx, size.cy);
|
setWindowSize(size.width, size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::setWindowTitle(TString title)
|
void e2d::EApp::setWindowTitle(EString title)
|
||||||
{
|
{
|
||||||
// 设置窗口标题
|
// 设置窗口标题
|
||||||
SetWindowText(GetHWnd(), title.c_str());
|
SetWindowText(GetHWnd(), title.c_str());
|
||||||
// 保存当前标题,用于修改窗口大小时恢复标题
|
// 保存当前标题,用于修改窗口大小时恢复标题
|
||||||
s_pInstance->m_sTitle = title;
|
m_sTitle = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
TString App::getWindowTitle()
|
EString e2d::EApp::getTitle()
|
||||||
{
|
{
|
||||||
return s_pInstance->m_sTitle;
|
return m_sTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::close()
|
int e2d::EApp::getWidth()
|
||||||
{
|
{
|
||||||
closegraph(); // 关闭绘图环境
|
return GetRenderTarget()->GetPixelSize().width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::enterScene(Scene * scene, bool save)
|
int e2d::EApp::getHeight()
|
||||||
|
{
|
||||||
|
return GetRenderTarget()->GetPixelSize().height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EApp::enterScene(Scene * scene, bool save /* = true */)
|
||||||
{
|
{
|
||||||
// 保存下一场景的指针
|
// 保存下一场景的指针
|
||||||
s_pInstance->m_pNextScene = scene;
|
m_pNextScene = scene;
|
||||||
// 切换场景时,是否保存当前场景
|
// 切换场景时,是否保存当前场景
|
||||||
s_pInstance->m_bSaveScene = save;
|
m_bSaveScene = save;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::backScene()
|
void e2d::EApp::backScene()
|
||||||
{
|
{
|
||||||
// 从栈顶取出场景指针,作为下一场景
|
// 从栈顶取出场景指针,作为下一场景
|
||||||
s_pInstance->m_pNextScene = s_SceneStack.top();
|
m_pNextScene = s_SceneStack.top();
|
||||||
// 不保存当前场景
|
// 不保存当前场景
|
||||||
s_pInstance->m_bSaveScene = false;
|
m_bSaveScene = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::clearScene()
|
void e2d::EApp::clearScene()
|
||||||
{
|
{
|
||||||
// 清空场景栈
|
// 清空场景栈
|
||||||
while (s_SceneStack.size())
|
while (s_SceneStack.size())
|
||||||
{
|
{
|
||||||
auto temp = s_SceneStack.top();
|
auto temp = s_SceneStack.top();
|
||||||
SafeDelete(temp);
|
SafeDelete(&temp);
|
||||||
s_SceneStack.pop();
|
s_SceneStack.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::setAppName(TString appname)
|
Scene * e2d::EApp::getCurrentScene()
|
||||||
|
{
|
||||||
|
return m_pCurrentScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene * e2d::EApp::getLoadingScene()
|
||||||
|
{
|
||||||
|
return m_pLoadingScene;
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EApp::setAppName(EString appname)
|
||||||
{
|
{
|
||||||
s_pInstance->m_sAppName = appname;
|
s_pInstance->m_sAppName = appname;
|
||||||
}
|
}
|
||||||
|
|
||||||
TString App::getAppName()
|
EString e2d::EApp::getAppName()
|
||||||
{
|
{
|
||||||
return s_pInstance->m_sAppName;
|
return s_pInstance->m_sAppName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::setBkColor(COLORREF color)
|
void EApp::setBkColor(EColor::Enum color)
|
||||||
{
|
{
|
||||||
setbkcolor(color);
|
m_ClearColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::_enterNextScene()
|
void e2d::EApp::close()
|
||||||
|
{
|
||||||
|
ShowWindow(GetHWnd(), SW_HIDE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EApp::show()
|
||||||
|
{
|
||||||
|
ShowWindow(GetHWnd(), SW_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EApp::free()
|
||||||
|
{
|
||||||
|
// 释放场景内存
|
||||||
|
SafeDelete(&m_pCurrentScene);
|
||||||
|
SafeDelete(&m_pNextScene);
|
||||||
|
// 清空场景栈
|
||||||
|
while (s_SceneStack.size())
|
||||||
|
{
|
||||||
|
auto temp = s_SceneStack.top();
|
||||||
|
SafeDelete(&temp);
|
||||||
|
s_SceneStack.pop();
|
||||||
|
}
|
||||||
|
// 删除所有定时器
|
||||||
|
//Timer::clearAllTimers();
|
||||||
|
//MouseMsg::clearAllListeners();
|
||||||
|
//KeyMsg::clearAllListeners();
|
||||||
|
//ActionManager::clearAllActions();
|
||||||
|
// 删除所有对象
|
||||||
|
//FreePool::__clearAllObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EApp::quit()
|
||||||
|
{
|
||||||
|
m_bRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EApp::end()
|
||||||
|
{
|
||||||
|
m_bRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EApp::_enterNextScene()
|
||||||
{
|
{
|
||||||
bool bBackScene = false;
|
bool bBackScene = false;
|
||||||
|
|
||||||
|
|
@ -321,19 +406,19 @@ void App::_enterNextScene()
|
||||||
// 若要保存当前场景,把它放入栈中
|
// 若要保存当前场景,把它放入栈中
|
||||||
s_SceneStack.push(m_pCurrentScene);
|
s_SceneStack.push(m_pCurrentScene);
|
||||||
// 暂停当前场景上运行的所有定时器
|
// 暂停当前场景上运行的所有定时器
|
||||||
Timer::waitAllSceneTimers(m_pCurrentScene);
|
//Timer::waitAllSceneTimers(m_pCurrentScene);
|
||||||
MouseMsg::waitAllSceneListeners(m_pCurrentScene);
|
//MouseMsg::waitAllSceneListeners(m_pCurrentScene);
|
||||||
KeyMsg::waitAllSceneListeners(m_pCurrentScene);
|
//KeyMsg::waitAllSceneListeners(m_pCurrentScene);
|
||||||
ActionManager::waitAllSceneActions(m_pCurrentScene);
|
//ActionManager::waitAllSceneActions(m_pCurrentScene);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 不保存场景时,停止当前场景上运行的所有定时器,并删除当前场景
|
// 不保存场景时,停止当前场景上运行的所有定时器,并删除当前场景
|
||||||
Timer::clearAllSceneTimers(m_pCurrentScene);
|
//Timer::clearAllSceneTimers(m_pCurrentScene);
|
||||||
MouseMsg::clearAllSceneListeners(m_pCurrentScene);
|
//MouseMsg::clearAllSceneListeners(m_pCurrentScene);
|
||||||
KeyMsg::clearAllSceneListeners(m_pCurrentScene);
|
//KeyMsg::clearAllSceneListeners(m_pCurrentScene);
|
||||||
ActionManager::stopAllSceneActions(m_pCurrentScene);
|
//ActionManager::stopAllSceneActions(m_pCurrentScene);
|
||||||
SafeDelete(m_pCurrentScene);
|
SafeDelete(&m_pCurrentScene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -343,10 +428,10 @@ void App::_enterNextScene()
|
||||||
if (bBackScene)
|
if (bBackScene)
|
||||||
{
|
{
|
||||||
// 返回上一场景时,恢复场景上的定时器
|
// 返回上一场景时,恢复场景上的定时器
|
||||||
Timer::notifyAllSceneTimers(m_pCurrentScene);
|
//Timer::notifyAllSceneTimers(m_pCurrentScene);
|
||||||
MouseMsg::notifyAllSceneListeners(m_pCurrentScene);
|
//MouseMsg::notifyAllSceneListeners(m_pCurrentScene);
|
||||||
KeyMsg::notifyAllSceneListeners(m_pCurrentScene);
|
//KeyMsg::notifyAllSceneListeners(m_pCurrentScene);
|
||||||
ActionManager::notifyAllSceneActions(m_pCurrentScene);
|
//ActionManager::notifyAllSceneActions(m_pCurrentScene);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -356,62 +441,144 @@ void App::_enterNextScene()
|
||||||
m_pCurrentScene->onEnter(); // 执行下一场景的 onEnter 函数
|
m_pCurrentScene->onEnter(); // 执行下一场景的 onEnter 函数
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::quit()
|
// Creates resources that are not bound to a particular device.
|
||||||
|
// Their lifetime effectively extends for the duration of the
|
||||||
|
// application.
|
||||||
|
HRESULT e2d::EApp::CreateDeviceIndependentResources()
|
||||||
{
|
{
|
||||||
s_pInstance->m_bRunning = false;
|
HRESULT hr = S_OK;
|
||||||
|
|
||||||
|
// Create a Direct2D factory.
|
||||||
|
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &GetFactory());
|
||||||
|
|
||||||
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::end()
|
// Creates resources that are bound to a particular
|
||||||
|
// Direct3D device. These resources need to be recreated
|
||||||
|
// if the Direct3D device dissapears, such as when the display
|
||||||
|
// changes, the window is remoted, etc.
|
||||||
|
HRESULT e2d::EApp::CreateDeviceResources()
|
||||||
{
|
{
|
||||||
s_pInstance->m_bRunning = false;
|
HRESULT hr = S_OK;
|
||||||
}
|
|
||||||
|
|
||||||
void App::reset()
|
if (!GetRenderTarget())
|
||||||
{
|
|
||||||
// 重置绘图环境
|
|
||||||
graphdefaults();
|
|
||||||
setbkmode(TRANSPARENT);
|
|
||||||
setbkcolor(Color::black);
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene * App::getCurrentScene()
|
|
||||||
{
|
|
||||||
// 获取当前场景的指针
|
|
||||||
return s_pInstance->m_pCurrentScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene * App::getLoadingScene()
|
|
||||||
{
|
|
||||||
return s_pInstance->m_pLoadingScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
int App::getWidth()
|
|
||||||
{
|
|
||||||
return s_pInstance->m_Size.cx;
|
|
||||||
}
|
|
||||||
|
|
||||||
int App::getHeight()
|
|
||||||
{
|
|
||||||
return s_pInstance->m_Size.cy;
|
|
||||||
}
|
|
||||||
|
|
||||||
void App::free()
|
|
||||||
{
|
|
||||||
// 释放场景内存
|
|
||||||
SafeDelete(m_pCurrentScene);
|
|
||||||
SafeDelete(m_pNextScene);
|
|
||||||
// 清空场景栈
|
|
||||||
while (s_SceneStack.size())
|
|
||||||
{
|
{
|
||||||
auto temp = s_SceneStack.top();
|
RECT rc;
|
||||||
SafeDelete(temp);
|
GetClientRect(GetHWnd(), &rc);
|
||||||
s_SceneStack.pop();
|
|
||||||
|
D2D1_SIZE_U size = D2D1::SizeU(
|
||||||
|
rc.right - rc.left,
|
||||||
|
rc.bottom - rc.top
|
||||||
|
);
|
||||||
|
|
||||||
|
// Create a Direct2D render target.
|
||||||
|
hr = GetFactory()->CreateHwndRenderTarget(
|
||||||
|
D2D1::RenderTargetProperties(),
|
||||||
|
D2D1::HwndRenderTargetProperties(GetHWnd(), size),
|
||||||
|
&GetRenderTarget()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// 删除所有定时器
|
|
||||||
Timer::clearAllTimers();
|
return hr;
|
||||||
MouseMsg::clearAllListeners();
|
|
||||||
KeyMsg::clearAllListeners();
|
|
||||||
ActionManager::clearAllActions();
|
|
||||||
// 删除所有对象
|
|
||||||
FreePool::__clearAllObjects();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Discards device-dependent resources. These resources must be
|
||||||
|
// recreated when the Direct3D device is lost.
|
||||||
|
void e2d::EApp::DiscardDeviceResources()
|
||||||
|
{
|
||||||
|
SafeReleaseInterface(&GetRenderTarget());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the application receives a WM_SIZE message, this method
|
||||||
|
// resizes the render target appropriately.
|
||||||
|
void e2d::EApp::_onResize(UINT width, UINT height)
|
||||||
|
{
|
||||||
|
if (GetRenderTarget())
|
||||||
|
{
|
||||||
|
// Note: This method can fail, but it's okay to ignore the
|
||||||
|
// error here, because the error will be returned again
|
||||||
|
// the next time EndDraw is called.
|
||||||
|
GetRenderTarget()->Resize(D2D1::SizeU(width, height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handles window messages.
|
||||||
|
LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
LRESULT result = 0;
|
||||||
|
|
||||||
|
if (message == WM_CREATE)
|
||||||
|
{
|
||||||
|
LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
|
||||||
|
EApp *pEApp = (EApp *)pcs->lpCreateParams;
|
||||||
|
|
||||||
|
::SetWindowLongPtrW(
|
||||||
|
GetHWnd(),
|
||||||
|
GWLP_USERDATA,
|
||||||
|
PtrToUlong(pEApp)
|
||||||
|
);
|
||||||
|
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EApp *pEApp = reinterpret_cast<EApp *>(static_cast<LONG_PTR>(
|
||||||
|
::GetWindowLongPtrW(
|
||||||
|
GetHWnd(),
|
||||||
|
GWLP_USERDATA
|
||||||
|
)));
|
||||||
|
|
||||||
|
bool wasHandled = false;
|
||||||
|
|
||||||
|
if (pEApp)
|
||||||
|
{
|
||||||
|
switch (message)
|
||||||
|
{
|
||||||
|
case WM_SIZE:
|
||||||
|
{
|
||||||
|
UINT width = LOWORD(lParam);
|
||||||
|
UINT height = HIWORD(lParam);
|
||||||
|
pEApp->_onResize(width, height);
|
||||||
|
}
|
||||||
|
result = 0;
|
||||||
|
wasHandled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_DISPLAYCHANGE:
|
||||||
|
{
|
||||||
|
InvalidateRect(GetHWnd(), NULL, FALSE);
|
||||||
|
}
|
||||||
|
result = 0;
|
||||||
|
wasHandled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_PAINT:
|
||||||
|
{
|
||||||
|
pEApp->_onRender();
|
||||||
|
ValidateRect(GetHWnd(), NULL);
|
||||||
|
}
|
||||||
|
result = 0;
|
||||||
|
wasHandled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_DESTROY:
|
||||||
|
{
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
|
result = 1;
|
||||||
|
wasHandled = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wasHandled)
|
||||||
|
{
|
||||||
|
result = DefWindowProc(GetHWnd(), message, wParam, lParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
Scene::Scene()
|
Scene::Scene()
|
||||||
{
|
{
|
||||||
App::get()->m_pLoadingScene = this;
|
EApp::get()->m_pLoadingScene = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scene::~Scene()
|
Scene::~Scene()
|
||||||
|
|
|
||||||
|
|
@ -190,8 +190,10 @@
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalDependencies>EasyXa.lib;GdiPlus.lib</AdditionalDependencies>
|
<AdditionalDependencies>
|
||||||
<AdditionalLibraryDirectories>EasyX\x86</AdditionalLibraryDirectories>
|
</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>
|
||||||
|
</AdditionalLibraryDirectories>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugW|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugW|Win32'">
|
||||||
|
|
@ -209,10 +211,12 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalDependencies>EasyXw.lib;GdiPlus.lib</AdditionalDependencies>
|
<AdditionalDependencies>
|
||||||
|
</AdditionalDependencies>
|
||||||
<IgnoreAllDefaultLibraries>
|
<IgnoreAllDefaultLibraries>
|
||||||
</IgnoreAllDefaultLibraries>
|
</IgnoreAllDefaultLibraries>
|
||||||
<AdditionalLibraryDirectories>EasyX\x86</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>
|
||||||
|
</AdditionalLibraryDirectories>
|
||||||
</Lib>
|
</Lib>
|
||||||
<ProjectReference>
|
<ProjectReference>
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
||||||
|
|
@ -233,8 +237,10 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>EasyX\x64</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>EasyXa.lib;GdiPlus.lib</AdditionalDependencies>
|
</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>
|
||||||
|
</AdditionalDependencies>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugW|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugW|x64'">
|
||||||
|
|
@ -252,8 +258,10 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalDependencies>EasyXw.lib;GdiPlus.lib</AdditionalDependencies>
|
<AdditionalDependencies>
|
||||||
<AdditionalLibraryDirectories>EasyX\x64</AdditionalLibraryDirectories>
|
</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>
|
||||||
|
</AdditionalLibraryDirectories>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
|
@ -274,8 +282,10 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>EasyX\x86</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>EasyXa.lib;GdiPlus.lib</AdditionalDependencies>
|
</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>
|
||||||
|
</AdditionalDependencies>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseW|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseW|Win32'">
|
||||||
|
|
@ -296,8 +306,10 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalDependencies>EasyXw.lib;GdiPlus.lib</AdditionalDependencies>
|
<AdditionalDependencies>
|
||||||
<AdditionalLibraryDirectories>EasyX\x86</AdditionalLibraryDirectories>
|
</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>
|
||||||
|
</AdditionalLibraryDirectories>
|
||||||
<IgnoreSpecificDefaultLibraries>
|
<IgnoreSpecificDefaultLibraries>
|
||||||
</IgnoreSpecificDefaultLibraries>
|
</IgnoreSpecificDefaultLibraries>
|
||||||
</Lib>
|
</Lib>
|
||||||
|
|
@ -320,8 +332,10 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalLibraryDirectories>EasyX\x64</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>EasyXa.lib;GdiPlus.lib</AdditionalDependencies>
|
</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>
|
||||||
|
</AdditionalDependencies>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseW|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseW|x64'">
|
||||||
|
|
@ -342,59 +356,22 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Lib>
|
<Lib>
|
||||||
<AdditionalDependencies>EasyXw.lib;GdiPlus.lib</AdditionalDependencies>
|
<AdditionalDependencies>
|
||||||
<AdditionalLibraryDirectories>EasyX\x64</AdditionalLibraryDirectories>
|
</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>
|
||||||
|
</AdditionalLibraryDirectories>
|
||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Action\Action.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionCallback.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionDelay.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionFrames.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionMoveTo.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionMoveBy.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionNeverStop.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionOpacityTo.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionOpacityBy.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionScaleBy.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionScaleTo.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionSequence.cpp" />
|
|
||||||
<ClCompile Include="Action\ActionTwo.cpp" />
|
|
||||||
<ClCompile Include="Action\Animation.cpp" />
|
|
||||||
<ClCompile Include="Base\App.cpp" />
|
<ClCompile Include="Base\App.cpp" />
|
||||||
<ClCompile Include="Base\FreePool.cpp" />
|
<ClCompile Include="Base\FreePool.cpp" />
|
||||||
<ClCompile Include="Base\Scene.cpp" />
|
<ClCompile Include="Base\Scene.cpp" />
|
||||||
<ClCompile Include="Msg\KeyMsg.cpp" />
|
|
||||||
<ClCompile Include="Msg\MouseMsg.cpp" />
|
|
||||||
<ClCompile Include="Object\BatchNode.cpp" />
|
|
||||||
<ClCompile Include="Object\BatchSprite.cpp" />
|
|
||||||
<ClCompile Include="Object\Button\Button.cpp" />
|
|
||||||
<ClCompile Include="Object\Button\ImageButton.cpp" />
|
|
||||||
<ClCompile Include="Object\Button\TextButton.cpp" />
|
|
||||||
<ClCompile Include="Object\Image.cpp" />
|
|
||||||
<ClCompile Include="Object\Layer.cpp" />
|
|
||||||
<ClCompile Include="Object\MouseNode.cpp" />
|
|
||||||
<ClCompile Include="Object\Node.cpp" />
|
|
||||||
<ClCompile Include="Object\RectNode.cpp" />
|
|
||||||
<ClCompile Include="Object\Shape\Circle.cpp" />
|
|
||||||
<ClCompile Include="Object\Shape\Rectangle.cpp" />
|
|
||||||
<ClCompile Include="Object\Shape\Shape.cpp" />
|
|
||||||
<ClCompile Include="Object\Sprite.cpp" />
|
|
||||||
<ClCompile Include="Object\Text.cpp" />
|
|
||||||
<ClCompile Include="Object\Object.cpp" />
|
|
||||||
<ClCompile Include="Style\Color.cpp" />
|
|
||||||
<ClCompile Include="Style\FillStyle.cpp" />
|
|
||||||
<ClCompile Include="Style\FontStyle.cpp" />
|
|
||||||
<ClCompile Include="Style\LineStyle.cpp" />
|
|
||||||
<ClCompile Include="Tool\ActionManager.cpp" />
|
|
||||||
<ClCompile Include="Tool\FileUtils.cpp" />
|
|
||||||
<ClCompile Include="Tool\Math.cpp" />
|
|
||||||
<ClCompile Include="Tool\MusicUtils.cpp" />
|
|
||||||
<ClCompile Include="Tool\Timer.cpp" />
|
|
||||||
<ClCompile Include="Win\winbase.cpp" />
|
<ClCompile Include="Win\winbase.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="easy2d.h" />
|
<ClInclude Include="easy2d.h" />
|
||||||
|
<ClInclude Include="ecommon.h" />
|
||||||
|
<ClInclude Include="emacros.h" />
|
||||||
<ClInclude Include="Win\winbase.h" />
|
<ClInclude Include="Win\winbase.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|
|
||||||
|
|
@ -13,104 +13,14 @@
|
||||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="源文件\Style">
|
|
||||||
<UniqueIdentifier>{18e7fd5c-0935-47bb-9a2e-38da40377f7d}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="源文件\Tool">
|
|
||||||
<UniqueIdentifier>{682a1a3c-39d8-4ac9-ba03-fa90c089c9ab}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="源文件\Object">
|
|
||||||
<UniqueIdentifier>{d6778635-8947-4f9b-9388-dd088642b5b2}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="源文件\Object\Shape">
|
|
||||||
<UniqueIdentifier>{065a3244-7169-4a45-bc9f-f2a80d8a9759}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="源文件\Msg">
|
|
||||||
<UniqueIdentifier>{72dbabab-8278-4ee4-917f-bfffb474a51b}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="源文件\Object\Button">
|
|
||||||
<UniqueIdentifier>{bdcd902b-b53d-4537-9632-76ea14c141a0}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="源文件\Action">
|
|
||||||
<UniqueIdentifier>{e1501580-8f69-4ad6-a9f1-76d825572c3d}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
<Filter Include="源文件\Base">
|
<Filter Include="源文件\Base">
|
||||||
<UniqueIdentifier>{261633d3-3814-40c7-bd6d-201ede6c6ade}</UniqueIdentifier>
|
<UniqueIdentifier>{261633d3-3814-40c7-bd6d-201ede6c6ade}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="源文件\Win">
|
<Filter Include="源文件\Win">
|
||||||
<UniqueIdentifier>{37b7730c-acb0-4b57-b1f8-01680951611c}</UniqueIdentifier>
|
<UniqueIdentifier>{2f0f3d30-bfc2-4aea-a170-258bbaacaa79}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Style\Color.cpp">
|
|
||||||
<Filter>源文件\Style</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Tool\Timer.cpp">
|
|
||||||
<Filter>源文件\Tool</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Tool\MusicUtils.cpp">
|
|
||||||
<Filter>源文件\Tool</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Tool\FileUtils.cpp">
|
|
||||||
<Filter>源文件\Tool</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Style\FontStyle.cpp">
|
|
||||||
<Filter>源文件\Style</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\BatchNode.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Image.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Node.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Text.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Shape\Circle.cpp">
|
|
||||||
<Filter>源文件\Object\Shape</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Shape\Rectangle.cpp">
|
|
||||||
<Filter>源文件\Object\Shape</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Shape\Shape.cpp">
|
|
||||||
<Filter>源文件\Object\Shape</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\MouseNode.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Style\LineStyle.cpp">
|
|
||||||
<Filter>源文件\Style</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Object.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Style\FillStyle.cpp">
|
|
||||||
<Filter>源文件\Style</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Msg\MouseMsg.cpp">
|
|
||||||
<Filter>源文件\Msg</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Msg\KeyMsg.cpp">
|
|
||||||
<Filter>源文件\Msg</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Button\Button.cpp">
|
|
||||||
<Filter>源文件\Object\Button</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Button\ImageButton.cpp">
|
|
||||||
<Filter>源文件\Object\Button</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Button\TextButton.cpp">
|
|
||||||
<Filter>源文件\Object\Button</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Layer.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\Action.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Base\App.cpp">
|
<ClCompile Include="Base\App.cpp">
|
||||||
<Filter>源文件\Base</Filter>
|
<Filter>源文件\Base</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -120,60 +30,6 @@
|
||||||
<ClCompile Include="Base\Scene.cpp">
|
<ClCompile Include="Base\Scene.cpp">
|
||||||
<Filter>源文件\Base</Filter>
|
<Filter>源文件\Base</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Action\ActionMoveBy.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionMoveTo.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionTwo.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionNeverStop.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\Sprite.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionCallback.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionDelay.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Tool\ActionManager.cpp">
|
|
||||||
<Filter>源文件\Tool</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionSequence.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionFrames.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionScaleBy.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionScaleTo.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\Animation.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionOpacityTo.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Action\ActionOpacityBy.cpp">
|
|
||||||
<Filter>源文件\Action</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\BatchSprite.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Object\RectNode.cpp">
|
|
||||||
<Filter>源文件\Object</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Tool\Math.cpp">
|
|
||||||
<Filter>源文件\Tool</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Win\winbase.cpp">
|
<ClCompile Include="Win\winbase.cpp">
|
||||||
<Filter>源文件\Win</Filter>
|
<Filter>源文件\Win</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|
@ -182,6 +38,12 @@
|
||||||
<ClInclude Include="easy2d.h">
|
<ClInclude Include="easy2d.h">
|
||||||
<Filter>头文件</Filter>
|
<Filter>头文件</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="ecommon.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="emacros.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="Win\winbase.h">
|
<ClInclude Include="Win\winbase.h">
|
||||||
<Filter>源文件\Win</Filter>
|
<Filter>源文件\Win</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ void KeyMsg::addListener(TString name, const KEY_CALLBACK & callback)
|
||||||
// 创建新的监听对象
|
// 创建新的监听对象
|
||||||
auto listener = new KeyMsg(name, callback);
|
auto listener = new KeyMsg(name, callback);
|
||||||
// 绑定在场景上
|
// 绑定在场景上
|
||||||
listener->m_pParentScene = App::getLoadingScene();
|
listener->m_pParentScene = EApp::getLoadingScene();
|
||||||
// 添加新的按键回调函数
|
// 添加新的按键回调函数
|
||||||
s_vListeners.push_back(listener);
|
s_vListeners.push_back(listener);
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +149,7 @@ void KeyMsg::startListener(TString name)
|
||||||
// 查找名称相同的监听器
|
// 查找名称相同的监听器
|
||||||
for (auto l : s_vListeners)
|
for (auto l : s_vListeners)
|
||||||
{
|
{
|
||||||
if (l->m_sName == name && l->m_pParentScene == App::getCurrentScene())
|
if (l->m_sName == name && l->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
l->start();
|
l->start();
|
||||||
}
|
}
|
||||||
|
|
@ -161,7 +161,7 @@ void KeyMsg::stopListener(TString name)
|
||||||
// 查找名称相同的监听器
|
// 查找名称相同的监听器
|
||||||
for (auto l : s_vListeners)
|
for (auto l : s_vListeners)
|
||||||
{
|
{
|
||||||
if (l->m_sName == name && l->m_pParentScene == App::getCurrentScene())
|
if (l->m_sName == name && l->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
l->stop();
|
l->stop();
|
||||||
}
|
}
|
||||||
|
|
@ -176,7 +176,7 @@ void KeyMsg::delListener(TString name)
|
||||||
for (iter = s_vListeners.begin(); iter != s_vListeners.end();)
|
for (iter = s_vListeners.begin(); iter != s_vListeners.end();)
|
||||||
{
|
{
|
||||||
// 查找相同名称的监听器
|
// 查找相同名称的监听器
|
||||||
if ((*iter)->m_sName == name && (*iter)->m_pParentScene == App::getCurrentScene())
|
if ((*iter)->m_sName == name && (*iter)->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
// 删除该定时器
|
// 删除该定时器
|
||||||
delete (*iter);
|
delete (*iter);
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ void MouseMsg::__exec()
|
||||||
// 获取鼠标消息
|
// 获取鼠标消息
|
||||||
s_mouseMsg = GetMouseMsg();
|
s_mouseMsg = GetMouseMsg();
|
||||||
// 执行场景程序
|
// 执行场景程序
|
||||||
App::get()->getCurrentScene()->_exec();
|
EApp::get()->getCurrentScene()->_exec();
|
||||||
// 执行鼠标监听回调函数
|
// 执行鼠标监听回调函数
|
||||||
for (auto l : s_vListeners) // 循环遍历所有的鼠标监听
|
for (auto l : s_vListeners) // 循环遍历所有的鼠标监听
|
||||||
{
|
{
|
||||||
|
|
@ -58,7 +58,7 @@ void MouseMsg::addListener(TString name, const MOUSE_CALLBACK & callback)
|
||||||
// 创建新的监听对象
|
// 创建新的监听对象
|
||||||
auto listener = new MouseMsg(name, callback);
|
auto listener = new MouseMsg(name, callback);
|
||||||
// 绑定在场景上
|
// 绑定在场景上
|
||||||
listener->m_pParentScene = App::getLoadingScene();
|
listener->m_pParentScene = EApp::getLoadingScene();
|
||||||
// 添加新的按键回调函数
|
// 添加新的按键回调函数
|
||||||
s_vListeners.push_back(listener);
|
s_vListeners.push_back(listener);
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +68,7 @@ void MouseMsg::startListener(TString name)
|
||||||
// 查找名称相同的监听器
|
// 查找名称相同的监听器
|
||||||
for (auto l : s_vListeners)
|
for (auto l : s_vListeners)
|
||||||
{
|
{
|
||||||
if (l->m_sName == name && l->m_pParentScene == App::getCurrentScene())
|
if (l->m_sName == name && l->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
l->start();
|
l->start();
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +80,7 @@ void MouseMsg::stopListener(TString name)
|
||||||
// 查找名称相同的监听器
|
// 查找名称相同的监听器
|
||||||
for (auto l : s_vListeners)
|
for (auto l : s_vListeners)
|
||||||
{
|
{
|
||||||
if (l->m_sName == name && l->m_pParentScene == App::getCurrentScene())
|
if (l->m_sName == name && l->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
l->stop();
|
l->stop();
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +95,7 @@ void MouseMsg::delListener(TString name)
|
||||||
for (iter = s_vListeners.begin(); iter != s_vListeners.end();)
|
for (iter = s_vListeners.begin(); iter != s_vListeners.end();)
|
||||||
{
|
{
|
||||||
// 查找相同名称的监听器
|
// 查找相同名称的监听器
|
||||||
if ((*iter)->m_sName == name && (*iter)->m_pParentScene == App::getCurrentScene())
|
if ((*iter)->m_sName == name && (*iter)->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
// 删除该定时器
|
// 删除该定时器
|
||||||
delete (*iter);
|
delete (*iter);
|
||||||
|
|
|
||||||
|
|
@ -216,7 +216,7 @@ void Image::saveScreenshot()
|
||||||
{
|
{
|
||||||
// ±£´æ´°¿Ú½ØÍ¼
|
// ±£´æ´°¿Ú½ØÍ¼
|
||||||
IMAGE image;
|
IMAGE image;
|
||||||
getimage(&image, 0, 0, App::getWidth(), App::getHeight());
|
getimage(&image, 0, 0, EApp::getWidth(), EApp::getHeight());
|
||||||
saveimage(savePath.c_str(), &image);
|
saveimage(savePath.c_str(), &image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@ bool RectNode::isPointIn(CPoint p) const
|
||||||
|
|
||||||
void RectNode::setWindowCenterX()
|
void RectNode::setWindowCenterX()
|
||||||
{
|
{
|
||||||
setX((App::getWidth() - getWidth()) / 2);
|
setX((EApp::getWidth() - getWidth()) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectNode::setWindowCenterY()
|
void RectNode::setWindowCenterY()
|
||||||
{
|
{
|
||||||
setY((App::getHeight() - getHeight()) / 2);
|
setY((EApp::getHeight() - getHeight()) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RectNode::setWindowCenter()
|
void RectNode::setWindowCenter()
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ void ActionManager::addAction(Action * action)
|
||||||
assert(a != action);
|
assert(a != action);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
action->m_pParentScene = App::getLoadingScene();
|
action->m_pParentScene = EApp::getLoadingScene();
|
||||||
s_vActions.push_back(action);
|
s_vActions.push_back(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ TString FileUtils::getDefaultSavePath()
|
||||||
|
|
||||||
TString path = m_lpszDefaultDir;
|
TString path = m_lpszDefaultDir;
|
||||||
path.append(_T("\\"));
|
path.append(_T("\\"));
|
||||||
path.append(App::getAppName());
|
path.append(EApp::getAppName());
|
||||||
|
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
if (_waccess(path.c_str(), 0) == -1)
|
if (_waccess(path.c_str(), 0) == -1)
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ void Timer::addTimer(Timer * timer)
|
||||||
// 启动定时器
|
// 启动定时器
|
||||||
timer->start();
|
timer->start();
|
||||||
// 绑定在场景上
|
// 绑定在场景上
|
||||||
timer->m_pParentScene = App::getLoadingScene();
|
timer->m_pParentScene = EApp::getLoadingScene();
|
||||||
// 将该定时器放入容器
|
// 将该定时器放入容器
|
||||||
s_vTimers.push_back(timer);
|
s_vTimers.push_back(timer);
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +126,7 @@ void Timer::startTimer(TString name)
|
||||||
// 查找名称相同的定时器
|
// 查找名称相同的定时器
|
||||||
for (auto timer : s_vTimers)
|
for (auto timer : s_vTimers)
|
||||||
{
|
{
|
||||||
if (timer->m_sName == name && timer->m_pParentScene == App::getCurrentScene())
|
if (timer->m_sName == name && timer->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
// 启动定时器
|
// 启动定时器
|
||||||
timer->start();
|
timer->start();
|
||||||
|
|
@ -139,7 +139,7 @@ void Timer::stopTimer(TString name)
|
||||||
// 查找名称相同的定时器
|
// 查找名称相同的定时器
|
||||||
for (auto timer : s_vTimers)
|
for (auto timer : s_vTimers)
|
||||||
{
|
{
|
||||||
if (timer->m_sName == name && timer->m_pParentScene == App::getCurrentScene())
|
if (timer->m_sName == name && timer->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
// 停止定时器
|
// 停止定时器
|
||||||
timer->stop();
|
timer->stop();
|
||||||
|
|
@ -155,7 +155,7 @@ void Timer::delTimer(TString name)
|
||||||
for (iter = s_vTimers.begin(); iter != s_vTimers.end();)
|
for (iter = s_vTimers.begin(); iter != s_vTimers.end();)
|
||||||
{
|
{
|
||||||
// 查找相同名称的定时器
|
// 查找相同名称的定时器
|
||||||
if ((*iter)->m_sName == name && (*iter)->m_pParentScene == App::getCurrentScene())
|
if ((*iter)->m_sName == name && (*iter)->m_pParentScene == EApp::getCurrentScene())
|
||||||
{
|
{
|
||||||
// 删除该定时器
|
// 删除该定时器
|
||||||
delete (*iter);
|
delete (*iter);
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,24 @@
|
||||||
#include "winbase.h"
|
#include "winbase.h"
|
||||||
#include <Windows.h>
|
#include "..\emacros.h"
|
||||||
#include <tchar.h>
|
|
||||||
#include <atltypes.h>
|
|
||||||
|
|
||||||
static steady_clock::time_point nNow;
|
HWND m_hwnd = nullptr;
|
||||||
|
ID2D1Factory * m_pDirect2dFactory = nullptr;
|
||||||
|
ID2D1HwndRenderTarget * m_pRenderTarget = nullptr;
|
||||||
|
|
||||||
steady_clock::time_point GetNow()
|
|
||||||
|
HWND &GetHWnd()
|
||||||
{
|
{
|
||||||
return nNow;
|
return m_hwnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlushSteadyClock()
|
ID2D1Factory * &GetFactory()
|
||||||
{
|
{
|
||||||
nNow = steady_clock::now(); // »ñÈ¡µ±Ç°Ê±¼ä
|
return m_pDirect2dFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
LONGLONG GetInterval(steady_clock::time_point nLast)
|
ID2D1HwndRenderTarget * &GetRenderTarget()
|
||||||
{
|
{
|
||||||
return duration_cast<milliseconds>(nNow - nLast).count();
|
return m_pRenderTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowCenter(HWND hWnd)
|
void WindowCenter(HWND hWnd)
|
||||||
|
|
@ -26,60 +27,16 @@ void WindowCenter(HWND hWnd)
|
||||||
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||||
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||||
// 获取窗口大小
|
// 获取窗口大小
|
||||||
CRect rcWindow;
|
tagRECT rcWindow;
|
||||||
GetWindowRect(hWnd, &rcWindow);
|
GetWindowRect(hWnd, &rcWindow);
|
||||||
// 设置窗口在屏幕居中
|
// 设置窗口在屏幕居中
|
||||||
SetWindowPos(hWnd, HWND_TOP,
|
SetWindowPos(
|
||||||
(screenWidth - rcWindow.Size().cx) / 2,
|
hWnd,
|
||||||
(screenHeight - rcWindow.Size().cy) / 2,
|
HWND_TOP,
|
||||||
rcWindow.Size().cx,
|
(screenWidth - (rcWindow.left - rcWindow.right)) / 2,
|
||||||
rcWindow.Size().cy,
|
(screenHeight - (rcWindow.top - rcWindow.bottom)) / 2,
|
||||||
SWP_SHOWWINDOW | SWP_NOSIZE);
|
(rcWindow.left - rcWindow.right),
|
||||||
|
(rcWindow.top - rcWindow.bottom),
|
||||||
|
SWP_SHOWWINDOW | SWP_NOSIZE
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateGameWindow()
|
|
||||||
{
|
|
||||||
HWND _wnd;
|
|
||||||
HINSTANCE s_hInstance;
|
|
||||||
if (!s_hInstance)
|
|
||||||
{
|
|
||||||
s_hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
|
|
||||||
|
|
||||||
WNDCLASS wc; // Windows Class Structure
|
|
||||||
|
|
||||||
// Redraw On Size, And Own DC For Window.
|
|
||||||
wc.style = 0;
|
|
||||||
wc.lpfnWndProc = _SoundPlayProc; // WndProc Handles Messages
|
|
||||||
wc.cbClsExtra = 0; // No Extra Window Data
|
|
||||||
wc.cbWndExtra = 0; // No Extra Window Data
|
|
||||||
wc.hInstance = s_hInstance; // Set The Instance
|
|
||||||
wc.hIcon = 0; // Load The Default Icon
|
|
||||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
|
|
||||||
wc.hbrBackground = NULL; // No Background Required For GL
|
|
||||||
wc.lpszMenuName = NULL; // We Don't Want A Menu
|
|
||||||
wc.lpszClassName = _T("Easy2dCallbackWnd"); // Set The Class Name
|
|
||||||
|
|
||||||
if (!RegisterClass(&wc) // Register Our Class
|
|
||||||
&& GetLastError() != 1410) // Class is Already Existent
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_wnd = CreateWindowEx(
|
|
||||||
WS_EX_APPWINDOW, // Extended Style For The Window
|
|
||||||
_T("Easy2dCallbackWnd"), // Class Name
|
|
||||||
NULL, // Window Title
|
|
||||||
WS_POPUPWINDOW, // Defined Window Style
|
|
||||||
0, 0, // Window Position
|
|
||||||
0, 0, // Window Width And Height
|
|
||||||
NULL, // No Parent Window
|
|
||||||
NULL, // No Menu
|
|
||||||
s_hInstance, // Instance
|
|
||||||
NULL); // No Param
|
|
||||||
|
|
||||||
if (_wnd)
|
|
||||||
{
|
|
||||||
//SetWindowLongPtr(_wnd, GWLP_USERDATA, (LONG_PTR)this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,27 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <chrono>
|
#include <d2d1.h>
|
||||||
using namespace std::chrono;
|
#include <d2d1helper.h>
|
||||||
|
#include <dwrite.h>
|
||||||
|
#include <wincodec.h>
|
||||||
|
|
||||||
steady_clock::time_point GetNow();
|
HWND &GetHWnd();
|
||||||
|
|
||||||
void FlushSteadyClock();
|
ID2D1Factory * &GetFactory();
|
||||||
|
|
||||||
|
ID2D1HwndRenderTarget * &GetRenderTarget();
|
||||||
|
|
||||||
|
void WindowCenter(HWND hWnd);
|
||||||
|
|
||||||
|
|
||||||
|
template<class Interface>
|
||||||
|
inline void SafeReleaseInterface(
|
||||||
|
Interface **ppInterfaceToRelease
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (*ppInterfaceToRelease != nullptr)
|
||||||
|
{
|
||||||
|
(*ppInterfaceToRelease)->Release();
|
||||||
|
|
||||||
|
(*ppInterfaceToRelease) = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
1716
Easy2D/easy2d.h
1716
Easy2D/easy2d.h
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,170 @@
|
||||||
|
#pragma once
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
typedef std::wstring EString;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
UINT32 width;
|
||||||
|
UINT32 height;
|
||||||
|
} ESize;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
FLOAT width;
|
||||||
|
FLOAT height;
|
||||||
|
} ESize_F;
|
||||||
|
|
||||||
|
|
||||||
|
class EColor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum Enum
|
||||||
|
{
|
||||||
|
AliceBlue = 0xF0F8FF,
|
||||||
|
AntiqueWhite = 0xFAEBD7,
|
||||||
|
Aqua = 0x00FFFF,
|
||||||
|
Aquamarine = 0x7FFFD4,
|
||||||
|
Azure = 0xF0FFFF,
|
||||||
|
Beige = 0xF5F5DC,
|
||||||
|
Bisque = 0xFFE4C4,
|
||||||
|
Black = 0x000000,
|
||||||
|
BlanchedAlmond = 0xFFEBCD,
|
||||||
|
Blue = 0x0000FF,
|
||||||
|
BlueViolet = 0x8A2BE2,
|
||||||
|
Brown = 0xA52A2A,
|
||||||
|
BurlyWood = 0xDEB887,
|
||||||
|
CadetBlue = 0x5F9EA0,
|
||||||
|
Chartreuse = 0x7FFF00,
|
||||||
|
Chocolate = 0xD2691E,
|
||||||
|
Coral = 0xFF7F50,
|
||||||
|
CornflowerBlue = 0x6495ED,
|
||||||
|
Cornsilk = 0xFFF8DC,
|
||||||
|
Crimson = 0xDC143C,
|
||||||
|
Cyan = 0x00FFFF,
|
||||||
|
DarkBlue = 0x00008B,
|
||||||
|
DarkCyan = 0x008B8B,
|
||||||
|
DarkGoldenrod = 0xB8860B,
|
||||||
|
DarkGray = 0xA9A9A9,
|
||||||
|
DarkGreen = 0x006400,
|
||||||
|
DarkKhaki = 0xBDB76B,
|
||||||
|
DarkMagenta = 0x8B008B,
|
||||||
|
DarkOliveGreen = 0x556B2F,
|
||||||
|
DarkOrange = 0xFF8C00,
|
||||||
|
DarkOrchid = 0x9932CC,
|
||||||
|
DarkRed = 0x8B0000,
|
||||||
|
DarkSalmon = 0xE9967A,
|
||||||
|
DarkSeaGreen = 0x8FBC8F,
|
||||||
|
DarkSlateBlue = 0x483D8B,
|
||||||
|
DarkSlateGray = 0x2F4F4F,
|
||||||
|
DarkTurquoise = 0x00CED1,
|
||||||
|
DarkViolet = 0x9400D3,
|
||||||
|
DeepPink = 0xFF1493,
|
||||||
|
DeepSkyBlue = 0x00BFFF,
|
||||||
|
DimGray = 0x696969,
|
||||||
|
DodgerBlue = 0x1E90FF,
|
||||||
|
Firebrick = 0xB22222,
|
||||||
|
FloralWhite = 0xFFFAF0,
|
||||||
|
ForestGreen = 0x228B22,
|
||||||
|
Fuchsia = 0xFF00FF,
|
||||||
|
Gainsboro = 0xDCDCDC,
|
||||||
|
GhostWhite = 0xF8F8FF,
|
||||||
|
Gold = 0xFFD700,
|
||||||
|
Goldenrod = 0xDAA520,
|
||||||
|
Gray = 0x808080,
|
||||||
|
Green = 0x008000,
|
||||||
|
GreenYellow = 0xADFF2F,
|
||||||
|
Honeydew = 0xF0FFF0,
|
||||||
|
HotPink = 0xFF69B4,
|
||||||
|
IndianRed = 0xCD5C5C,
|
||||||
|
Indigo = 0x4B0082,
|
||||||
|
Ivory = 0xFFFFF0,
|
||||||
|
Khaki = 0xF0E68C,
|
||||||
|
Lavender = 0xE6E6FA,
|
||||||
|
LavenderBlush = 0xFFF0F5,
|
||||||
|
LawnGreen = 0x7CFC00,
|
||||||
|
LemonChiffon = 0xFFFACD,
|
||||||
|
LightBlue = 0xADD8E6,
|
||||||
|
LightCoral = 0xF08080,
|
||||||
|
LightCyan = 0xE0FFFF,
|
||||||
|
LightGoldenrodYellow = 0xFAFAD2,
|
||||||
|
LightGreen = 0x90EE90,
|
||||||
|
LightGray = 0xD3D3D3,
|
||||||
|
LightPink = 0xFFB6C1,
|
||||||
|
LightSalmon = 0xFFA07A,
|
||||||
|
LightSeaGreen = 0x20B2AA,
|
||||||
|
LightSkyBlue = 0x87CEFA,
|
||||||
|
LightSlateGray = 0x778899,
|
||||||
|
LightSteelBlue = 0xB0C4DE,
|
||||||
|
LightYellow = 0xFFFFE0,
|
||||||
|
Lime = 0x00FF00,
|
||||||
|
LimeGreen = 0x32CD32,
|
||||||
|
Linen = 0xFAF0E6,
|
||||||
|
Magenta = 0xFF00FF,
|
||||||
|
Maroon = 0x800000,
|
||||||
|
MediumAquamarine = 0x66CDAA,
|
||||||
|
MediumBlue = 0x0000CD,
|
||||||
|
MediumOrchid = 0xBA55D3,
|
||||||
|
MediumPurple = 0x9370DB,
|
||||||
|
MediumSeaGreen = 0x3CB371,
|
||||||
|
MediumSlateBlue = 0x7B68EE,
|
||||||
|
MediumSpringGreen = 0x00FA9A,
|
||||||
|
MediumTurquoise = 0x48D1CC,
|
||||||
|
MediumVioletRed = 0xC71585,
|
||||||
|
MidnightBlue = 0x191970,
|
||||||
|
MintCream = 0xF5FFFA,
|
||||||
|
MistyRose = 0xFFE4E1,
|
||||||
|
Moccasin = 0xFFE4B5,
|
||||||
|
NavajoWhite = 0xFFDEAD,
|
||||||
|
Navy = 0x000080,
|
||||||
|
OldLace = 0xFDF5E6,
|
||||||
|
Olive = 0x808000,
|
||||||
|
OliveDrab = 0x6B8E23,
|
||||||
|
Orange = 0xFFA500,
|
||||||
|
OrangeRed = 0xFF4500,
|
||||||
|
Orchid = 0xDA70D6,
|
||||||
|
PaleGoldenrod = 0xEEE8AA,
|
||||||
|
PaleGreen = 0x98FB98,
|
||||||
|
PaleTurquoise = 0xAFEEEE,
|
||||||
|
PaleVioletRed = 0xDB7093,
|
||||||
|
PapayaWhip = 0xFFEFD5,
|
||||||
|
PeachPuff = 0xFFDAB9,
|
||||||
|
Peru = 0xCD853F,
|
||||||
|
Pink = 0xFFC0CB,
|
||||||
|
Plum = 0xDDA0DD,
|
||||||
|
PowderBlue = 0xB0E0E6,
|
||||||
|
Purple = 0x800080,
|
||||||
|
Red = 0xFF0000,
|
||||||
|
RosyBrown = 0xBC8F8F,
|
||||||
|
RoyalBlue = 0x4169E1,
|
||||||
|
SaddleBrown = 0x8B4513,
|
||||||
|
Salmon = 0xFA8072,
|
||||||
|
SandyBrown = 0xF4A460,
|
||||||
|
SeaGreen = 0x2E8B57,
|
||||||
|
SeaShell = 0xFFF5EE,
|
||||||
|
Sienna = 0xA0522D,
|
||||||
|
Silver = 0xC0C0C0,
|
||||||
|
SkyBlue = 0x87CEEB,
|
||||||
|
SlateBlue = 0x6A5ACD,
|
||||||
|
SlateGray = 0x708090,
|
||||||
|
Snow = 0xFFFAFA,
|
||||||
|
SpringGreen = 0x00FF7F,
|
||||||
|
SteelBlue = 0x4682B4,
|
||||||
|
Tan = 0xD2B48C,
|
||||||
|
Teal = 0x008080,
|
||||||
|
Thistle = 0xD8BFD8,
|
||||||
|
Tomato = 0xFF6347,
|
||||||
|
Turquoise = 0x40E0D0,
|
||||||
|
Violet = 0xEE82EE,
|
||||||
|
Wheat = 0xF5DEB3,
|
||||||
|
White = 0xFFFFFF,
|
||||||
|
WhiteSmoke = 0xF5F5F5,
|
||||||
|
Yellow = 0xFFFF00,
|
||||||
|
YellowGreen = 0x9ACD32,
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef Assert
|
||||||
|
|
||||||
|
#if defined( DEBUG ) || defined( _DEBUG )
|
||||||
|
#define Assert(b) do {if (!(b)) {OutputDebugStringA("Assert: " #b "\n");}} while(0)
|
||||||
|
#else
|
||||||
|
#define Assert(b)
|
||||||
|
#endif //DEBUG || _DEBUG
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline void SafeDelete(T** p) { if (*p) { delete *p; *p = nullptr; } }
|
||||||
Loading…
Reference in New Issue