整体优化
This commit is contained in:
parent
a789c037c3
commit
3747c4d0de
|
|
@ -0,0 +1,156 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{70931955-FE2D-4A50-93C6-6955A730B0FE}</ProjectGuid>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<RootNamespace>ConsoleDemo</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
<LibraryPath>$(MSBuildProjectDirectory)\..\Win32;$(LibraryPath)</LibraryPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>
|
||||||
|
</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>
|
||||||
|
</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>Disabled</Optimization>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>
|
||||||
|
</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<PrecompiledHeader>
|
||||||
|
</PrecompiledHeader>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<Optimization>MaxSpeed</Optimization>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="main.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="源文件">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="头文件">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="资源文件">
|
||||||
|
<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>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="main.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
#include "..\Easy2D\easy2d.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
EApp app;
|
||||||
|
|
||||||
|
if (app.init(L"Easy2D Demo", 640, 480, true))
|
||||||
|
{
|
||||||
|
auto scene = new EScene();
|
||||||
|
|
||||||
|
auto node = new ENode();
|
||||||
|
node->setPos(50, 80);
|
||||||
|
node->setSize(30, 180);
|
||||||
|
scene->add(node);
|
||||||
|
|
||||||
|
/*auto listener = new EMouseListener([=] {
|
||||||
|
if (!EMouseMsg::isLButtonDown())
|
||||||
|
{
|
||||||
|
if (EMouseMsg::getMsg() == EMouseMsg::MOVE)
|
||||||
|
{
|
||||||
|
node->setPos(EMouseMsg::getPos());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
|
||||||
|
auto listener = new EKeyPressListener([=] {
|
||||||
|
if (EKeyMsg::isCapitalLockOn())
|
||||||
|
{
|
||||||
|
if (EKeyMsg::getVal() == EKeyMsg::KEY::LEFT)
|
||||||
|
{
|
||||||
|
node->move(-3, 0);
|
||||||
|
}
|
||||||
|
if (EKeyMsg::getVal() == EKeyMsg::KEY::RIGHT)
|
||||||
|
{
|
||||||
|
node->move(3, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
listener->bindWithNode(node);
|
||||||
|
|
||||||
|
EMsgManager::bindListenerWithScene(listener, scene);
|
||||||
|
|
||||||
|
app.enterScene(scene);
|
||||||
|
|
||||||
|
app.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -23,13 +23,13 @@
|
||||||
<ProjectGuid>{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}</ProjectGuid>
|
<ProjectGuid>{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>Demo</RootNamespace>
|
<RootNamespace>Demo</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
#include "..\Easy2D\easy2d.h"
|
#include "..\Easy2D\easy2d.h"
|
||||||
#pragma comment(lib, "d2d1.lib")
|
|
||||||
|
|
||||||
|
|
||||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
int WINAPI WinMain(
|
||||||
|
HINSTANCE hInstance,
|
||||||
|
HINSTANCE hPrevInstance,
|
||||||
|
LPSTR lpCmdLine,
|
||||||
|
int nCmdShow
|
||||||
|
)
|
||||||
{
|
{
|
||||||
EApp app;
|
EApp app;
|
||||||
|
|
||||||
if (app.init(L"Easy2D Demo", 640, 480))
|
if (app.init(L"Easy2D Demo", 640, 480, true))
|
||||||
{
|
{
|
||||||
auto scene = new EScene();
|
auto scene = new EScene();
|
||||||
|
|
||||||
|
|
@ -37,9 +41,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
node->move(3, 0);
|
node->move(3, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
EApp::setWindowSize(500, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
EMsgManager::addListener(listener);
|
listener->bindWithNode(node);
|
||||||
|
|
||||||
|
EMsgManager::bindListenerWithScene(listener, scene);
|
||||||
|
|
||||||
app.enterScene(scene);
|
app.enterScene(scene);
|
||||||
|
|
||||||
|
|
|
||||||
12
Easy2D.sln
12
Easy2D.sln
|
|
@ -1,12 +1,14 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.26730.16
|
VisualStudioVersion = 15.0.26730.12
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D\Easy2D.vcxproj", "{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D\Easy2D.vcxproj", "{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo\Demo.vcxproj", "{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo\Demo.vcxproj", "{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleDemo", "ConsoleDemo\ConsoleDemo.vcxproj", "{70931955-FE2D-4A50-93C6-6955A730B0FE}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x64 = Debug|x64
|
Debug|x64 = Debug|x64
|
||||||
|
|
@ -33,6 +35,14 @@ Global
|
||||||
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x64.Build.0 = Release|x64
|
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x64.Build.0 = Release|x64
|
||||||
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x86.ActiveCfg = Release|Win32
|
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x86.ActiveCfg = Release|Win32
|
||||||
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x86.Build.0 = Release|Win32
|
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x86.Build.0 = Release|Win32
|
||||||
|
{70931955-FE2D-4A50-93C6-6955A730B0FE}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{70931955-FE2D-4A50-93C6-6955A730B0FE}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{70931955-FE2D-4A50-93C6-6955A730B0FE}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{70931955-FE2D-4A50-93C6-6955A730B0FE}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{70931955-FE2D-4A50-93C6-6955A730B0FE}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{70931955-FE2D-4A50-93C6-6955A730B0FE}.Release|x64.Build.0 = Release|x64
|
||||||
|
{70931955-FE2D-4A50-93C6-6955A730B0FE}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{70931955-FE2D-4A50-93C6-6955A730B0FE}.Release|x86.Build.0 = Release|Win32
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ e2d::EApp::EApp()
|
||||||
, m_bSaveScene(true)
|
, m_bSaveScene(true)
|
||||||
, m_pCurrentScene(nullptr)
|
, m_pCurrentScene(nullptr)
|
||||||
, m_pNextScene(nullptr)
|
, m_pNextScene(nullptr)
|
||||||
, m_pLoadingScene(nullptr)
|
|
||||||
{
|
{
|
||||||
s_pInstance = this; // 保存实例对象
|
s_pInstance = this; // 保存实例对象
|
||||||
}
|
}
|
||||||
|
|
@ -37,7 +36,7 @@ e2d::EApp::~EApp()
|
||||||
|
|
||||||
e2d::EApp * e2d::EApp::get()
|
e2d::EApp * e2d::EApp::get()
|
||||||
{
|
{
|
||||||
ASSERT(s_pInstance != nullptr);
|
ASSERT(s_pInstance != nullptr, "Nonexistent EApp instance.");
|
||||||
return s_pInstance; // 获取 EApp 的唯一实例
|
return s_pInstance; // 获取 EApp 的唯一实例
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,7 +44,7 @@ bool e2d::EApp::init(e2d::EString title, e2d::ESize size, bool bShowConsole /* =
|
||||||
{
|
{
|
||||||
return init(title, size.cx, size.cy, bShowConsole);
|
return init(title, size.cx, size.cy, bShowConsole);
|
||||||
}
|
}
|
||||||
|
#include <iostream>
|
||||||
bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShowConsole /* = false */)
|
bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShowConsole /* = false */)
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
|
@ -54,14 +53,28 @@ bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShow
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
// 关闭控制台
|
// 关闭控制台
|
||||||
if (!bShowConsole)
|
if (bShowConsole)
|
||||||
{
|
{
|
||||||
HWND consoleHWnd = FindWindow(L"ConsoleWindowClass", NULL);
|
// 查找是否已经存在控制台
|
||||||
|
if (!GetConsoleWindow())
|
||||||
if (consoleHWnd)
|
|
||||||
{
|
{
|
||||||
ShowWindow(consoleHWnd, SW_HIDE);
|
// 显示一个新控制台
|
||||||
|
if (AllocConsole())
|
||||||
|
{
|
||||||
|
FILE *stream;
|
||||||
|
freopen_s(&stream, "CONOUT$", "w+t", stdout);
|
||||||
|
freopen_s(&stream, "CONOUT$", "w+t", stderr);
|
||||||
|
freopen_s(&stream, "CONIN$", "r+t", stdin);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox(nullptr, L"Alloc Console Failed!", L"Error", MB_OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FreeConsole();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化 device-indpendent 资源
|
// 初始化 device-indpendent 资源
|
||||||
|
|
@ -117,6 +130,24 @@ bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShow
|
||||||
UnregisterClass(L"E2DApp", HINST_THISCOMPONENT);
|
UnregisterClass(L"E2DApp", HINST_THISCOMPONENT);
|
||||||
MessageBox(nullptr, L"Create Window Failed!", L"Error", MB_OK);
|
MessageBox(nullptr, L"Create Window Failed!", L"Error", MB_OK);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 获取屏幕分辨率
|
||||||
|
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||||
|
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||||
|
// 获取窗口大小(包含菜单栏)
|
||||||
|
tagRECT rcWindow;
|
||||||
|
GetWindowRect(GetHWnd(), &rcWindow);
|
||||||
|
// 修改窗口大小,并设置窗口在屏幕居中
|
||||||
|
MoveWindow(
|
||||||
|
GetHWnd(),
|
||||||
|
(screenWidth - (rcWindow.right - rcWindow.left)) / 2,
|
||||||
|
(screenHeight - (rcWindow.bottom - rcWindow.top)) / 2,
|
||||||
|
(rcWindow.right - rcWindow.left),
|
||||||
|
(rcWindow.bottom - rcWindow.top),
|
||||||
|
FALSE
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAILED(hr))
|
if (FAILED(hr))
|
||||||
|
|
@ -130,7 +161,7 @@ bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShow
|
||||||
// 运行游戏
|
// 运行游戏
|
||||||
void e2d::EApp::run()
|
void e2d::EApp::run()
|
||||||
{
|
{
|
||||||
ASSERT(m_pNextScene != nullptr);
|
ASSERT(m_pNextScene != nullptr, "Next scene NULL pointer exception.");
|
||||||
// 进入第一个场景
|
// 进入第一个场景
|
||||||
_enterNextScene();
|
_enterNextScene();
|
||||||
// 显示窗口
|
// 显示窗口
|
||||||
|
|
@ -161,9 +192,7 @@ void e2d::EApp::run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 游戏结束后再执行一次循环
|
// 游戏结束后再执行一次循环
|
||||||
_mainLoop();
|
_onControl();
|
||||||
// 关闭窗口
|
|
||||||
close();
|
|
||||||
// 释放所有内存占用
|
// 释放所有内存占用
|
||||||
free();
|
free();
|
||||||
}
|
}
|
||||||
|
|
@ -214,10 +243,8 @@ void e2d::EApp::_onControl()
|
||||||
_enterNextScene();
|
_enterNextScene();
|
||||||
}
|
}
|
||||||
// 断言当前场景非空
|
// 断言当前场景非空
|
||||||
ASSERT(m_pCurrentScene != nullptr);
|
ASSERT(m_pCurrentScene != nullptr, "Current scene NULL pointer exception.");
|
||||||
|
|
||||||
//MouseMsg::__exec(); // 鼠标检测
|
|
||||||
//KeyMsg::__exec(); // 键盘按键检测
|
|
||||||
//Timer::__exec(); // 定时器执行程序
|
//Timer::__exec(); // 定时器执行程序
|
||||||
//ActionManager::__exec(); // 动作管理器执行程序
|
//ActionManager::__exec(); // 动作管理器执行程序
|
||||||
EObjectManager::__flush(); // 刷新内存池
|
EObjectManager::__flush(); // 刷新内存池
|
||||||
|
|
@ -226,7 +253,7 @@ void e2d::EApp::_onControl()
|
||||||
// This method discards device-specific
|
// This method discards device-specific
|
||||||
// resources if the Direct3D device dissapears during execution and
|
// resources if the Direct3D device dissapears during execution and
|
||||||
// recreates the resources the next time it's invoked.
|
// recreates the resources the next time it's invoked.
|
||||||
bool e2d::EApp::_onRender()
|
void e2d::EApp::_onRender()
|
||||||
{
|
{
|
||||||
HRESULT hr = S_OK;
|
HRESULT hr = S_OK;
|
||||||
|
|
||||||
|
|
@ -251,7 +278,10 @@ bool e2d::EApp::_onRender()
|
||||||
_discardDeviceResources();
|
_discardDeviceResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCEEDED(hr);
|
if (FAILED(hr))
|
||||||
|
{
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::setWindowSize(int width, int height)
|
void e2d::EApp::setWindowSize(int width, int height)
|
||||||
|
|
@ -268,18 +298,8 @@ void e2d::EApp::setWindowSize(int width, int height)
|
||||||
// 计算边框大小
|
// 计算边框大小
|
||||||
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(m_);
|
|
||||||
// 修改窗口大小,并设置窗口在屏幕居中
|
// 修改窗口大小,并设置窗口在屏幕居中
|
||||||
SetWindowPos(
|
MoveWindow(GetHWnd(), (screenWidth - width) / 2, (screenHeight - height) / 2, width, height, TRUE);
|
||||||
GetHWnd(),
|
|
||||||
HWND_TOP,
|
|
||||||
(screenWidth - width) / 2,
|
|
||||||
(screenHeight - height) / 2,
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
SWP_SHOWWINDOW
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::setWindowSize(e2d::ESize size)
|
void e2d::EApp::setWindowSize(e2d::ESize size)
|
||||||
|
|
@ -292,12 +312,12 @@ void e2d::EApp::setWindowTitle(e2d::EString title)
|
||||||
// 设置窗口标题
|
// 设置窗口标题
|
||||||
SetWindowText(GetHWnd(), title.c_str());
|
SetWindowText(GetHWnd(), title.c_str());
|
||||||
// 保存当前标题,用于修改窗口大小时恢复标题
|
// 保存当前标题,用于修改窗口大小时恢复标题
|
||||||
m_sTitle = title;
|
get()->m_sTitle = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::EString e2d::EApp::getTitle()
|
e2d::EString e2d::EApp::getTitle()
|
||||||
{
|
{
|
||||||
return m_sTitle;
|
return get()->m_sTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::ESize e2d::EApp::getSize()
|
e2d::ESize e2d::EApp::getSize()
|
||||||
|
|
@ -318,17 +338,17 @@ UINT32 e2d::EApp::getHeight()
|
||||||
void e2d::EApp::enterScene(EScene * scene, bool save /* = true */)
|
void e2d::EApp::enterScene(EScene * scene, bool save /* = true */)
|
||||||
{
|
{
|
||||||
// 保存下一场景的指针
|
// 保存下一场景的指针
|
||||||
m_pNextScene = scene;
|
get()->m_pNextScene = scene;
|
||||||
// 切换场景时,是否保存当前场景
|
// 切换场景时,是否保存当前场景
|
||||||
m_bSaveScene = save;
|
get()->m_bSaveScene = save;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::backScene()
|
void e2d::EApp::backScene()
|
||||||
{
|
{
|
||||||
// 从栈顶取出场景指针,作为下一场景
|
// 从栈顶取出场景指针,作为下一场景
|
||||||
m_pNextScene = s_SceneStack.top();
|
get()->m_pNextScene = s_SceneStack.top();
|
||||||
// 不保存当前场景
|
// 不保存当前场景
|
||||||
m_bSaveScene = false;
|
get()->m_bSaveScene = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::clearScene()
|
void e2d::EApp::clearScene()
|
||||||
|
|
@ -344,17 +364,7 @@ void e2d::EApp::clearScene()
|
||||||
|
|
||||||
e2d::EScene * e2d::EApp::getCurrentScene()
|
e2d::EScene * e2d::EApp::getCurrentScene()
|
||||||
{
|
{
|
||||||
return m_pCurrentScene;
|
return get()->m_pCurrentScene;
|
||||||
}
|
|
||||||
|
|
||||||
e2d::EScene * e2d::EApp::getLoadingScene()
|
|
||||||
{
|
|
||||||
return m_pLoadingScene;
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::EApp::setLoadingScene(EScene * scene)
|
|
||||||
{
|
|
||||||
m_pLoadingScene = scene;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::setAppName(e2d::EString appname)
|
void e2d::EApp::setAppName(e2d::EString appname)
|
||||||
|
|
@ -369,7 +379,7 @@ e2d::EString e2d::EApp::getAppName()
|
||||||
|
|
||||||
void e2d::EApp::setBkColor(EColor::Enum color)
|
void e2d::EApp::setBkColor(EColor::Enum color)
|
||||||
{
|
{
|
||||||
m_ClearColor = color;
|
get()->m_ClearColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::close()
|
void e2d::EApp::close()
|
||||||
|
|
@ -385,8 +395,8 @@ void e2d::EApp::show()
|
||||||
void e2d::EApp::free()
|
void e2d::EApp::free()
|
||||||
{
|
{
|
||||||
// 释放场景内存
|
// 释放场景内存
|
||||||
SafeDelete(&m_pCurrentScene);
|
SafeDelete(&get()->m_pCurrentScene);
|
||||||
SafeDelete(&m_pNextScene);
|
SafeDelete(&get()->m_pNextScene);
|
||||||
// 清空场景栈
|
// 清空场景栈
|
||||||
while (s_SceneStack.size())
|
while (s_SceneStack.size())
|
||||||
{
|
{
|
||||||
|
|
@ -394,33 +404,34 @@ void e2d::EApp::free()
|
||||||
SafeDelete(&temp);
|
SafeDelete(&temp);
|
||||||
s_SceneStack.pop();
|
s_SceneStack.pop();
|
||||||
}
|
}
|
||||||
// 删除所有定时器
|
// 删除所有定时器、监听器
|
||||||
//Timer::clearAllTimers();
|
//Timer::clearAllTimers();
|
||||||
//MouseMsg::clearAllListeners();
|
EMsgManager::clearAllKeyboardListeners();
|
||||||
//KeyMsg::clearAllListeners();
|
EMsgManager::clearAllMouseListeners();
|
||||||
//ActionManager::clearAllActions();
|
//ActionManager::clearAllActions();
|
||||||
// 删除所有对象
|
// 删除所有对象
|
||||||
//EObjectManager::__clearAllObjects();
|
EObjectManager::clearAllObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::quit()
|
void e2d::EApp::quit()
|
||||||
{
|
{
|
||||||
m_bRunning = false;
|
get()->m_bRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::end()
|
void e2d::EApp::end()
|
||||||
{
|
{
|
||||||
m_bRunning = false;
|
get()->m_bRunning = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EApp::_enterNextScene()
|
void e2d::EApp::_enterNextScene()
|
||||||
{
|
{
|
||||||
bool bBackScene = false;
|
|
||||||
|
|
||||||
// 若下一场景处于栈顶,说明正在返回上一场景
|
// 若下一场景处于栈顶,说明正在返回上一场景
|
||||||
if (s_SceneStack.size() && m_pNextScene == s_SceneStack.top())
|
if (s_SceneStack.size() && m_pNextScene == s_SceneStack.top())
|
||||||
{
|
{
|
||||||
bBackScene = true;
|
// 返回上一场景时,恢复场景上的定时器
|
||||||
|
//Timer::notifyAllSceneTimers(m_pNextScene);
|
||||||
|
EMsgManager::notifyAllListenersBindWithScene(m_pNextScene);
|
||||||
|
//ActionManager::notifyAllSceneActions(m_pNextScene);
|
||||||
// 删除栈顶场景
|
// 删除栈顶场景
|
||||||
s_SceneStack.pop();
|
s_SceneStack.pop();
|
||||||
}
|
}
|
||||||
|
|
@ -435,37 +446,23 @@ void e2d::EApp::_enterNextScene()
|
||||||
s_SceneStack.push(m_pCurrentScene);
|
s_SceneStack.push(m_pCurrentScene);
|
||||||
// 暂停当前场景上运行的所有定时器
|
// 暂停当前场景上运行的所有定时器
|
||||||
//Timer::waitAllSceneTimers(m_pCurrentScene);
|
//Timer::waitAllSceneTimers(m_pCurrentScene);
|
||||||
//MouseMsg::waitAllSceneListeners(m_pCurrentScene);
|
EMsgManager::waitAllListenersBindWithScene(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);
|
EMsgManager::clearAllListenersBindWithScene(m_pCurrentScene);
|
||||||
//KeyMsg::clearAllSceneListeners(m_pCurrentScene);
|
|
||||||
//ActionManager::stopAllSceneActions(m_pCurrentScene);
|
//ActionManager::stopAllSceneActions(m_pCurrentScene);
|
||||||
SafeDelete(&m_pCurrentScene);
|
SafeDelete(&m_pCurrentScene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_pNextScene->onEnter(); // 执行下一场景的 onEnter 函数
|
||||||
|
|
||||||
m_pCurrentScene = m_pNextScene; // 切换场景
|
m_pCurrentScene = m_pNextScene; // 切换场景
|
||||||
m_pNextScene = nullptr; // 下一场景置空
|
m_pNextScene = nullptr; // 下一场景置空
|
||||||
|
|
||||||
if (bBackScene)
|
|
||||||
{
|
|
||||||
// 返回上一场景时,恢复场景上的定时器
|
|
||||||
//Timer::notifyAllSceneTimers(m_pCurrentScene);
|
|
||||||
EMsgManager::notifyAllListenersOnScene(m_pCurrentScene);
|
|
||||||
//ActionManager::notifyAllSceneActions(m_pCurrentScene);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_pCurrentScene->init(); // 进入一个新场景时,执行它的 init 函数
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pCurrentScene->onEnter(); // 执行下一场景的 onEnter 函数
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates resources that are not bound to a particular device.
|
// Creates resources that are not bound to a particular device.
|
||||||
|
|
@ -602,7 +599,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
|
|
||||||
case WM_KEYDOWN:
|
case WM_KEYDOWN:
|
||||||
case WM_KEYUP:
|
case WM_KEYUP:
|
||||||
case WM_CHAR:
|
|
||||||
{
|
{
|
||||||
EMsgManager::KeyboardProc(message, wParam, lParam);
|
EMsgManager::KeyboardProc(message, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
@ -638,6 +634,10 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
|
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
{
|
{
|
||||||
|
if (GetConsoleWindow())
|
||||||
|
{
|
||||||
|
FreeConsole();
|
||||||
|
}
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
result = 1;
|
result = 1;
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,6 @@ void e2d::EObject::release()
|
||||||
void e2d::EObject::autoRelease()
|
void e2d::EObject::autoRelease()
|
||||||
{
|
{
|
||||||
m_bAutoRelease = true;
|
m_bAutoRelease = true;
|
||||||
|
// 通知对象管理池刷新
|
||||||
|
EObjectManager::notifyFlush();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
#include "..\ebase.h"
|
#include "..\ebase.h"
|
||||||
#include "..\enodes.h"
|
#include "..\enodes.h"
|
||||||
|
#include "..\emsg.h"
|
||||||
|
|
||||||
e2d::EScene::EScene()
|
|
||||||
{
|
|
||||||
EApp::get()->setLoadingScene(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
e2d::EScene::~EScene()
|
e2d::EScene::~EScene()
|
||||||
{
|
{
|
||||||
clearAllChildren();
|
clearAllChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EScene::_exec()
|
/*void e2d::EScene::_exec()
|
||||||
{
|
{
|
||||||
// active 标志画面是否取得焦点
|
// active 标志画面是否取得焦点
|
||||||
bool active = true;
|
bool active = true;
|
||||||
|
|
@ -23,7 +20,7 @@ void e2d::EScene::_exec()
|
||||||
active = false; // 若子节点取得焦点,将标志置 false
|
active = false; // 若子节点取得焦点,将标志置 false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void e2d::EScene::_onRender()
|
void e2d::EScene::_onRender()
|
||||||
{
|
{
|
||||||
|
|
@ -34,10 +31,6 @@ void e2d::EScene::_onRender()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EScene::init()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void e2d::EScene::onEnter()
|
void e2d::EScene::onEnter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -49,11 +42,11 @@ void e2d::EScene::onExit()
|
||||||
void e2d::EScene::add(ENode * child, int zOrder /* = 0 */)
|
void e2d::EScene::add(ENode * child, int zOrder /* = 0 */)
|
||||||
{
|
{
|
||||||
// 断言添加的节点非空
|
// 断言添加的节点非空
|
||||||
ASSERT(child != nullptr);
|
ASSERT(child != nullptr, "Scene::add NULL pointer exception.");
|
||||||
// 忽略空指针
|
// 忽略空指针
|
||||||
if (child == nullptr) return;
|
if (child == nullptr) return;
|
||||||
// 设置节点的父场景
|
// 设置节点的父场景
|
||||||
child->setParentScene(this);
|
child->bindWithScene(this);
|
||||||
// 设置 z 轴顺序
|
// 设置 z 轴顺序
|
||||||
child->setZOrder(zOrder);
|
child->setZOrder(zOrder);
|
||||||
// 对象的引用计数加一
|
// 对象的引用计数加一
|
||||||
|
|
@ -119,3 +112,13 @@ void e2d::EScene::clearAllChildren()
|
||||||
// 清空储存节点的容器
|
// 清空储存节点的容器
|
||||||
m_vChildren.clear();
|
m_vChildren.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void e2d::EScene::bindListener(EMouseListener * listener)
|
||||||
|
{
|
||||||
|
EMsgManager::bindListenerWithScene(listener, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EScene::bindListener(EKeyboardListener * listener)
|
||||||
|
{
|
||||||
|
EMsgManager::bindListenerWithScene(listener, this);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@
|
||||||
<ProjectGuid>{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}</ProjectGuid>
|
<ProjectGuid>{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>Easy2D</RootNamespace>
|
<RootNamespace>Easy2D</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v140</PlatformToolset>
|
<PlatformToolset>v141</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
|
@ -204,6 +204,7 @@
|
||||||
<ClCompile Include="Msg\Listener\EMouseListener.cpp" />
|
<ClCompile Include="Msg\Listener\EMouseListener.cpp" />
|
||||||
<ClCompile Include="Node\ENode.cpp" />
|
<ClCompile Include="Node\ENode.cpp" />
|
||||||
<ClCompile Include="Tool\EObjectManager.cpp" />
|
<ClCompile Include="Tool\EObjectManager.cpp" />
|
||||||
|
<ClCompile Include="Tool\ETimerManager.cpp" />
|
||||||
<ClCompile Include="Win\winbase.cpp" />
|
<ClCompile Include="Win\winbase.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,9 @@
|
||||||
<ClCompile Include="Msg\Listener\EKeyPressListener.cpp">
|
<ClCompile Include="Msg\Listener\EKeyPressListener.cpp">
|
||||||
<Filter>Msg\Listener</Filter>
|
<Filter>Msg\Listener</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Tool\ETimerManager.cpp">
|
||||||
|
<Filter>Tool</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Win\winbase.h">
|
<ClInclude Include="Win\winbase.h">
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ e2d::EMouseMsg mouseMsg;
|
||||||
// 按键消息
|
// 按键消息
|
||||||
e2d::EKeyMsg keyMsg;
|
e2d::EKeyMsg keyMsg;
|
||||||
// 鼠标消息监听器
|
// 鼠标消息监听器
|
||||||
std::vector<e2d::EMouseListener*> m_vMouseListeners;
|
std::vector<e2d::EMouseListener*> s_vMouseListeners;
|
||||||
// 按键消息监听器
|
// 按键消息监听器
|
||||||
std::vector<e2d::EKeyListener*> m_vKeyListeners;
|
std::vector<e2d::EKeyboardListener*> s_vKeyListeners;
|
||||||
|
|
||||||
|
|
||||||
DWORD e2d::EMouseMsg::getX()
|
DWORD e2d::EMouseMsg::getX()
|
||||||
|
|
@ -125,7 +125,7 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
mouseMsg.m_wParam = wParam;
|
mouseMsg.m_wParam = wParam;
|
||||||
mouseMsg.m_lParam = lParam;
|
mouseMsg.m_lParam = lParam;
|
||||||
// 执行鼠标消息监听函数
|
// 执行鼠标消息监听函数
|
||||||
for (auto mlistener : m_vMouseListeners)
|
for (auto mlistener : s_vMouseListeners)
|
||||||
{
|
{
|
||||||
if (mlistener->isRunning())
|
if (mlistener->isRunning())
|
||||||
{
|
{
|
||||||
|
|
@ -141,7 +141,7 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
keyMsg.m_wParam = wParam;
|
keyMsg.m_wParam = wParam;
|
||||||
keyMsg.m_lParam = lParam;
|
keyMsg.m_lParam = lParam;
|
||||||
// 执行按键消息监听函数
|
// 执行按键消息监听函数
|
||||||
for (auto klistener : m_vKeyListeners)
|
for (auto klistener : s_vKeyListeners)
|
||||||
{
|
{
|
||||||
if (klistener->isRunning())
|
if (klistener->isRunning())
|
||||||
{
|
{
|
||||||
|
|
@ -150,38 +150,38 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EMsgManager::addListener(e2d::EMouseListener * listener, EScene * pParentScene)
|
void e2d::EMsgManager::bindListenerWithScene(e2d::EMouseListener * listener, EScene * pParentScene)
|
||||||
{
|
{
|
||||||
WARN_IF(listener == nullptr, "Add NULL EMouseListener!");
|
WARN_IF(listener == nullptr, "EMouseListener NULL pointer exception!");
|
||||||
WARN_IF(pParentScene == nullptr, "Bind EMouseListener on a NULL Scene!");
|
WARN_IF(pParentScene == nullptr, "Bind EMouseListener with a NULL EScene pointer!");
|
||||||
|
|
||||||
if (listener && pParentScene)
|
if (listener && pParentScene)
|
||||||
{
|
{
|
||||||
listener->start();
|
listener->start();
|
||||||
listener->retain();
|
listener->retain();
|
||||||
listener->setParentScene(pParentScene);
|
listener->bindWithScene(pParentScene);
|
||||||
m_vMouseListeners.push_back(listener);
|
s_vMouseListeners.push_back(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EMsgManager::addListener(e2d::EKeyListener * listener, EScene * pParentScene)
|
void e2d::EMsgManager::bindListenerWithScene(e2d::EKeyboardListener * listener, EScene * pParentScene)
|
||||||
{
|
{
|
||||||
WARN_IF(listener == nullptr, "Add NULL EKeyListener!");
|
WARN_IF(listener == nullptr, "EKeyboardListener NULL pointer exception!");
|
||||||
WARN_IF(pParentScene == nullptr, "Bind EKeyListener on a NULL Scene!");
|
WARN_IF(pParentScene == nullptr, "Bind EKeyboardListener with a NULL EScene pointer!");
|
||||||
|
|
||||||
if (listener && pParentScene)
|
if (listener && pParentScene)
|
||||||
{
|
{
|
||||||
listener->start();
|
listener->start();
|
||||||
listener->retain();
|
listener->retain();
|
||||||
listener->setParentScene(pParentScene);
|
listener->bindWithScene(pParentScene);
|
||||||
m_vKeyListeners.push_back(listener);
|
s_vKeyListeners.push_back(listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EMsgManager::startListener(EString name)
|
void e2d::EMsgManager::startListener(EString name)
|
||||||
{
|
{
|
||||||
// 启动鼠标消息监听器
|
// 启动鼠标消息监听器
|
||||||
for (auto l : m_vMouseListeners)
|
for (auto l : s_vMouseListeners)
|
||||||
{
|
{
|
||||||
if (l->getName() == name)
|
if (l->getName() == name)
|
||||||
{
|
{
|
||||||
|
|
@ -189,7 +189,7 @@ void e2d::EMsgManager::startListener(EString name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 启动按键消息监听器
|
// 启动按键消息监听器
|
||||||
for (auto l : m_vKeyListeners)
|
for (auto l : s_vKeyListeners)
|
||||||
{
|
{
|
||||||
if (l->getName() == name)
|
if (l->getName() == name)
|
||||||
{
|
{
|
||||||
|
|
@ -201,7 +201,7 @@ void e2d::EMsgManager::startListener(EString name)
|
||||||
void e2d::EMsgManager::stopListener(EString name)
|
void e2d::EMsgManager::stopListener(EString name)
|
||||||
{
|
{
|
||||||
// 停止鼠标消息监听器
|
// 停止鼠标消息监听器
|
||||||
for (auto l : m_vMouseListeners)
|
for (auto l : s_vMouseListeners)
|
||||||
{
|
{
|
||||||
if (l->getName() == name)
|
if (l->getName() == name)
|
||||||
{
|
{
|
||||||
|
|
@ -209,7 +209,7 @@ void e2d::EMsgManager::stopListener(EString name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 停止按键消息监听器
|
// 停止按键消息监听器
|
||||||
for (auto l : m_vKeyListeners)
|
for (auto l : s_vKeyListeners)
|
||||||
{
|
{
|
||||||
if (l->getName() == name)
|
if (l->getName() == name)
|
||||||
{
|
{
|
||||||
|
|
@ -221,41 +221,153 @@ void e2d::EMsgManager::stopListener(EString name)
|
||||||
void e2d::EMsgManager::delListener(EString name)
|
void e2d::EMsgManager::delListener(EString name)
|
||||||
{
|
{
|
||||||
// 删除鼠标消息监听器
|
// 删除鼠标消息监听器
|
||||||
for (std::vector<EMouseListener*>::iterator iter = m_vMouseListeners.begin(); iter != m_vMouseListeners.end();)
|
std::vector<EMouseListener*>::iterator mIter;
|
||||||
|
for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();)
|
||||||
{
|
{
|
||||||
if ((*iter)->getName() == name)
|
if ((*mIter)->getName() == name)
|
||||||
{
|
{
|
||||||
(*iter)->autoRelease();
|
(*mIter)->autoRelease();
|
||||||
(*iter)->release();
|
(*mIter)->release();
|
||||||
delete (*iter);
|
mIter = s_vMouseListeners.erase(mIter);
|
||||||
iter = m_vMouseListeners.erase(iter);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iter++;
|
mIter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 删除按键消息监听器
|
// 删除按键消息监听器
|
||||||
for (std::vector<EKeyListener*>::iterator iter = m_vKeyListeners.begin(); iter != m_vKeyListeners.end();)
|
std::vector<EKeyboardListener*>::iterator kIter;
|
||||||
|
for (kIter = s_vKeyListeners.begin(); kIter != s_vKeyListeners.end();)
|
||||||
{
|
{
|
||||||
if ((*iter)->getName() == name)
|
if ((*kIter)->getName() == name)
|
||||||
{
|
{
|
||||||
(*iter)->autoRelease();
|
(*kIter)->autoRelease();
|
||||||
(*iter)->release();
|
(*kIter)->release();
|
||||||
delete (*iter);
|
kIter = s_vKeyListeners.erase(kIter);
|
||||||
iter = m_vKeyListeners.erase(iter);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iter++;
|
kIter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EMsgManager::waitAllListenersOnScene(EScene * scene)
|
void e2d::EMsgManager::startAllMouseListener()
|
||||||
|
{
|
||||||
|
for (auto l : s_vMouseListeners)
|
||||||
|
{
|
||||||
|
if (!l->isWaiting())
|
||||||
|
{
|
||||||
|
l->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::stopAllMouseListener()
|
||||||
|
{
|
||||||
|
for (auto l : s_vMouseListeners)
|
||||||
|
{
|
||||||
|
if (!l->isWaiting())
|
||||||
|
{
|
||||||
|
l->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::clearAllMouseListeners()
|
||||||
|
{
|
||||||
|
for (auto l : s_vMouseListeners)
|
||||||
|
{
|
||||||
|
l->autoRelease();
|
||||||
|
l->release();
|
||||||
|
}
|
||||||
|
s_vMouseListeners.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::startAllKeyboardListener()
|
||||||
|
{
|
||||||
|
for (auto l : s_vKeyListeners)
|
||||||
|
{
|
||||||
|
if (!l->isWaiting())
|
||||||
|
{
|
||||||
|
l->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::stopAllKeyboardListener()
|
||||||
|
{
|
||||||
|
for (auto l : s_vKeyListeners)
|
||||||
|
{
|
||||||
|
if (!l->isWaiting())
|
||||||
|
{
|
||||||
|
l->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::clearAllKeyboardListeners()
|
||||||
|
{
|
||||||
|
for (auto l : s_vKeyListeners)
|
||||||
|
{
|
||||||
|
l->autoRelease();
|
||||||
|
l->release();
|
||||||
|
}
|
||||||
|
s_vKeyListeners.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::startAllMouseListenersBindWithScene(EScene * pParentScene)
|
||||||
|
{
|
||||||
|
// 启动鼠标消息监听器
|
||||||
|
for (auto l : s_vMouseListeners)
|
||||||
|
{
|
||||||
|
if (l->getParentScene() == pParentScene)
|
||||||
|
{
|
||||||
|
l->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::stopAllMouseListenersBindWithScene(EScene * pParentScene)
|
||||||
|
{
|
||||||
|
// 停止鼠标消息监听器
|
||||||
|
for (auto l : s_vMouseListeners)
|
||||||
|
{
|
||||||
|
if (l->getParentScene() == pParentScene)
|
||||||
|
{
|
||||||
|
l->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::startAllKeyboardListenersBindWithScene(EScene * pParentScene)
|
||||||
|
{
|
||||||
|
// 启动按键消息监听器
|
||||||
|
for (auto l : s_vKeyListeners)
|
||||||
|
{
|
||||||
|
if (l->getParentScene() == pParentScene)
|
||||||
|
{
|
||||||
|
l->start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::stopAllKeyboardListenersBindWithScene(EScene * pParentScene)
|
||||||
|
{
|
||||||
|
// 停止按键消息监听器
|
||||||
|
for (auto l : s_vKeyListeners)
|
||||||
|
{
|
||||||
|
if (l->getParentScene() == pParentScene)
|
||||||
|
{
|
||||||
|
l->stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::waitAllListenersBindWithScene(EScene * scene)
|
||||||
{
|
{
|
||||||
// 挂起鼠标消息监听器
|
// 挂起鼠标消息监听器
|
||||||
for (auto l : m_vMouseListeners)
|
for (auto l : s_vMouseListeners)
|
||||||
{
|
{
|
||||||
if (l->getParentScene() == scene)
|
if (l->getParentScene() == scene)
|
||||||
{
|
{
|
||||||
|
|
@ -263,7 +375,7 @@ void e2d::EMsgManager::waitAllListenersOnScene(EScene * scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 挂起按键消息监听器
|
// 挂起按键消息监听器
|
||||||
for (auto l : m_vKeyListeners)
|
for (auto l : s_vKeyListeners)
|
||||||
{
|
{
|
||||||
if (l->getParentScene() == scene)
|
if (l->getParentScene() == scene)
|
||||||
{
|
{
|
||||||
|
|
@ -272,10 +384,10 @@ void e2d::EMsgManager::waitAllListenersOnScene(EScene * scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EMsgManager::notifyAllListenersOnScene(EScene * scene)
|
void e2d::EMsgManager::notifyAllListenersBindWithScene(EScene * scene)
|
||||||
{
|
{
|
||||||
// 重启鼠标消息监听器
|
// 重启鼠标消息监听器
|
||||||
for (auto l : m_vMouseListeners)
|
for (auto l : s_vMouseListeners)
|
||||||
{
|
{
|
||||||
if (l->getParentScene() == scene)
|
if (l->getParentScene() == scene)
|
||||||
{
|
{
|
||||||
|
|
@ -283,7 +395,7 @@ void e2d::EMsgManager::notifyAllListenersOnScene(EScene * scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 重启按键消息监听器
|
// 重启按键消息监听器
|
||||||
for (auto l : m_vKeyListeners)
|
for (auto l : s_vKeyListeners)
|
||||||
{
|
{
|
||||||
if (l->getParentScene() == scene)
|
if (l->getParentScene() == scene)
|
||||||
{
|
{
|
||||||
|
|
@ -292,3 +404,107 @@ void e2d::EMsgManager::notifyAllListenersOnScene(EScene * scene)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::clearAllListenersBindWithScene(EScene * scene)
|
||||||
|
{
|
||||||
|
std::vector<EMouseListener*>::iterator mIter;
|
||||||
|
for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();)
|
||||||
|
{
|
||||||
|
if ((*mIter)->getParentScene() == scene)
|
||||||
|
{
|
||||||
|
(*mIter)->autoRelease();
|
||||||
|
(*mIter)->release();
|
||||||
|
mIter = s_vMouseListeners.erase(mIter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mIter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::vector<EKeyboardListener*>::iterator kIter;
|
||||||
|
for (kIter = s_vKeyListeners.begin(); kIter != s_vKeyListeners.end();)
|
||||||
|
{
|
||||||
|
if ((*kIter)->getParentScene() == scene)
|
||||||
|
{
|
||||||
|
(*kIter)->autoRelease();
|
||||||
|
(*kIter)->release();
|
||||||
|
kIter = s_vKeyListeners.erase(kIter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
kIter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::waitAllListenersBindWithNode(ENode * pParentNode)
|
||||||
|
{
|
||||||
|
// 挂起鼠标消息监听器
|
||||||
|
for (auto l : s_vMouseListeners)
|
||||||
|
{
|
||||||
|
if (l->getParentNode() == pParentNode)
|
||||||
|
{
|
||||||
|
l->wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 挂起按键消息监听器
|
||||||
|
for (auto l : s_vKeyListeners)
|
||||||
|
{
|
||||||
|
if (l->getParentNode() == pParentNode)
|
||||||
|
{
|
||||||
|
l->wait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::notifyAllListenersBindWithNode(ENode * pParentNode)
|
||||||
|
{
|
||||||
|
// 重启鼠标消息监听器
|
||||||
|
for (auto l : s_vMouseListeners)
|
||||||
|
{
|
||||||
|
if (l->getParentNode() == pParentNode)
|
||||||
|
{
|
||||||
|
l->notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 重启按键消息监听器
|
||||||
|
for (auto l : s_vKeyListeners)
|
||||||
|
{
|
||||||
|
if (l->getParentNode() == pParentNode)
|
||||||
|
{
|
||||||
|
l->notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EMsgManager::clearAllListenersBindWithNode(ENode * pParentNode)
|
||||||
|
{
|
||||||
|
std::vector<EMouseListener*>::iterator mIter;
|
||||||
|
for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();)
|
||||||
|
{
|
||||||
|
if ((*mIter)->getParentNode() == pParentNode)
|
||||||
|
{
|
||||||
|
(*mIter)->autoRelease();
|
||||||
|
(*mIter)->release();
|
||||||
|
mIter = s_vMouseListeners.erase(mIter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mIter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::vector<EKeyboardListener*>::iterator kIter;
|
||||||
|
for (kIter = s_vKeyListeners.begin(); kIter != s_vKeyListeners.end();)
|
||||||
|
{
|
||||||
|
if ((*kIter)->getParentNode() == pParentNode)
|
||||||
|
{
|
||||||
|
(*kIter)->autoRelease();
|
||||||
|
(*kIter)->release();
|
||||||
|
kIter = s_vKeyListeners.erase(kIter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
kIter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,33 @@
|
||||||
#include "..\..\emsg.h"
|
#include "..\..\emsg.h"
|
||||||
|
|
||||||
e2d::EKeyListener::EKeyListener()
|
e2d::EKeyboardListener::EKeyboardListener()
|
||||||
: EListener()
|
: EListener()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::EKeyListener::EKeyListener(EString name)
|
e2d::EKeyboardListener::EKeyboardListener(EString name)
|
||||||
: EListener(name)
|
: EListener(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::EKeyListener::EKeyListener(const KEY_LISTENER_CALLBACK & callback)
|
e2d::EKeyboardListener::EKeyboardListener(const KEY_LISTENER_CALLBACK & callback)
|
||||||
: EListener()
|
: EListener()
|
||||||
{
|
{
|
||||||
m_callback = callback;
|
m_callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::EKeyListener::EKeyListener(EString name, const KEY_LISTENER_CALLBACK & callback)
|
e2d::EKeyboardListener::EKeyboardListener(EString name, const KEY_LISTENER_CALLBACK & callback)
|
||||||
: EListener(name)
|
: EListener(name)
|
||||||
{
|
{
|
||||||
m_callback = callback;
|
m_callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EKeyListener::runCallback()
|
void e2d::EKeyboardListener::runCallback()
|
||||||
{
|
{
|
||||||
m_callback();
|
m_callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EKeyListener::setCallback(const KEY_LISTENER_CALLBACK & callback)
|
void e2d::EKeyboardListener::setCallback(const KEY_LISTENER_CALLBACK & callback)
|
||||||
{
|
{
|
||||||
m_callback = callback;
|
m_callback = callback;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,22 @@
|
||||||
#include "..\..\emsg.h"
|
#include "..\..\emsg.h"
|
||||||
|
|
||||||
e2d::EKeyPressListener::EKeyPressListener()
|
e2d::EKeyPressListener::EKeyPressListener()
|
||||||
: EKeyListener()
|
: EKeyboardListener()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::EKeyPressListener::EKeyPressListener(EString name)
|
e2d::EKeyPressListener::EKeyPressListener(EString name)
|
||||||
: EKeyListener(name)
|
: EKeyboardListener(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::EKeyPressListener::EKeyPressListener(const KEY_LISTENER_CALLBACK & callback)
|
e2d::EKeyPressListener::EKeyPressListener(const KEY_LISTENER_CALLBACK & callback)
|
||||||
: EKeyListener(callback)
|
: EKeyboardListener(callback)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::EKeyPressListener::EKeyPressListener(EString name, const KEY_LISTENER_CALLBACK & callback)
|
e2d::EKeyPressListener::EKeyPressListener(EString name, const KEY_LISTENER_CALLBACK & callback)
|
||||||
: EKeyListener(name, callback)
|
: EKeyboardListener(name, callback)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ e2d::EListener::EListener()
|
||||||
, m_bWaiting(false)
|
, m_bWaiting(false)
|
||||||
, m_sName(L"")
|
, m_sName(L"")
|
||||||
, m_pParentScene(nullptr)
|
, m_pParentScene(nullptr)
|
||||||
|
, m_pParentNode(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,6 +20,11 @@ bool e2d::EListener::isRunning() const
|
||||||
return m_bRunning && !m_bWaiting;
|
return m_bRunning && !m_bWaiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool e2d::EListener::isWaiting() const
|
||||||
|
{
|
||||||
|
return m_bWaiting;
|
||||||
|
}
|
||||||
|
|
||||||
void e2d::EListener::start()
|
void e2d::EListener::start()
|
||||||
{
|
{
|
||||||
m_bRunning = true;
|
m_bRunning = true;
|
||||||
|
|
@ -39,6 +45,11 @@ void e2d::EListener::notify()
|
||||||
m_bWaiting = false;
|
m_bWaiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e2d::EListener * e2d::EListener::clone()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
e2d::EString e2d::EListener::getName() const
|
e2d::EString e2d::EListener::getName() const
|
||||||
{
|
{
|
||||||
return m_sName;
|
return m_sName;
|
||||||
|
|
@ -49,12 +60,32 @@ e2d::EScene * e2d::EListener::getParentScene() const
|
||||||
return m_pParentScene;
|
return m_pParentScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e2d::ENode * e2d::EListener::getParentNode() const
|
||||||
|
{
|
||||||
|
return m_pParentNode;
|
||||||
|
}
|
||||||
|
|
||||||
void e2d::EListener::setName(EString name)
|
void e2d::EListener::setName(EString name)
|
||||||
{
|
{
|
||||||
m_sName = name;
|
m_sName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EListener::setParentScene(EScene * scene)
|
void e2d::EListener::bindWithScene(EScene * scene)
|
||||||
{
|
{
|
||||||
if (scene != nullptr) m_pParentScene = scene;
|
WARN_IF(m_pParentNode != nullptr, "EListener bind with Scene Failed! Please use its clone.");
|
||||||
|
|
||||||
|
if (scene != nullptr && m_pParentNode == nullptr)
|
||||||
|
{
|
||||||
|
m_pParentScene = scene;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::EListener::bindWithNode(ENode * pParentNode)
|
||||||
|
{
|
||||||
|
WARN_IF(m_pParentScene != nullptr, "EListener bind with Node Failed! Please use its clone.");
|
||||||
|
|
||||||
|
if (pParentNode != nullptr && m_pParentScene == nullptr)
|
||||||
|
{
|
||||||
|
m_pParentNode = pParentNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ e2d::EScene * &e2d::ENode::getParentScene()
|
||||||
return m_pParentScene;
|
return m_pParentScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::ENode::setParentScene(EScene * scene)
|
void e2d::ENode::bindWithScene(EScene * scene)
|
||||||
{
|
{
|
||||||
m_pParentScene = scene;
|
m_pParentScene = scene;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,14 @@
|
||||||
|
|
||||||
// 释放池容器
|
// 释放池容器
|
||||||
static std::vector<e2d::EObject*> s_vPool;
|
static std::vector<e2d::EObject*> s_vPool;
|
||||||
|
// 标志释放池执行状态
|
||||||
|
static bool s_bNotifyed = false;
|
||||||
|
|
||||||
void e2d::EObjectManager::__flush()
|
void e2d::EObjectManager::__flush()
|
||||||
{
|
{
|
||||||
|
if (!s_bNotifyed) return;
|
||||||
|
|
||||||
|
s_bNotifyed = false;
|
||||||
// 创建迭代器
|
// 创建迭代器
|
||||||
static std::vector<e2d::EObject*>::iterator iter;
|
static std::vector<e2d::EObject*>::iterator iter;
|
||||||
// 循环遍历容器中的所有对象
|
// 循环遍历容器中的所有对象
|
||||||
|
|
@ -49,3 +54,8 @@ void e2d::EObjectManager::clearAllObjects()
|
||||||
}
|
}
|
||||||
s_vPool.clear();
|
s_vPool.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void e2d::EObjectManager::notifyFlush()
|
||||||
|
{
|
||||||
|
s_bNotifyed = true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
#include "..\etools.h"
|
||||||
|
|
@ -21,22 +21,3 @@ ID2D1HwndRenderTarget * &GetRenderTarget()
|
||||||
return pRenderTarget;
|
return pRenderTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowCenter(HWND hWnd)
|
|
||||||
{
|
|
||||||
// 获取屏幕分辨率
|
|
||||||
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
|
||||||
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
|
||||||
// 获取窗口大小
|
|
||||||
tagRECT rcWindow;
|
|
||||||
GetWindowRect(hWnd, &rcWindow);
|
|
||||||
// 设置窗口在屏幕居中
|
|
||||||
SetWindowPos(
|
|
||||||
hWnd,
|
|
||||||
HWND_TOP,
|
|
||||||
(screenWidth - (rcWindow.left - rcWindow.right)) / 2,
|
|
||||||
(screenHeight - (rcWindow.top - rcWindow.bottom)) / 2,
|
|
||||||
(rcWindow.left - rcWindow.right),
|
|
||||||
(rcWindow.top - rcWindow.bottom),
|
|
||||||
SWP_SHOWWINDOW | SWP_NOSIZE
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include <d2d1helper.h>
|
#include <d2d1helper.h>
|
||||||
#include <dwrite.h>
|
#include <dwrite.h>
|
||||||
#include <wincodec.h>
|
#include <wincodec.h>
|
||||||
|
#pragma comment(lib, "d2d1.lib")
|
||||||
|
|
||||||
HWND &GetHWnd();
|
HWND &GetHWnd();
|
||||||
|
|
||||||
|
|
@ -11,8 +12,6 @@ ID2D1Factory * &GetFactory();
|
||||||
|
|
||||||
ID2D1HwndRenderTarget * &GetRenderTarget();
|
ID2D1HwndRenderTarget * &GetRenderTarget();
|
||||||
|
|
||||||
void WindowCenter(HWND hWnd);
|
|
||||||
|
|
||||||
|
|
||||||
template<class Interface>
|
template<class Interface>
|
||||||
inline void SafeReleaseInterface(
|
inline void SafeReleaseInterface(
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
#include "emacros.h"
|
#include "emacros.h"
|
||||||
#include "ecommon.h"
|
#include "ecommon.h"
|
||||||
#include "ebase.h"
|
#include "ebase.h"
|
||||||
#include "emsg.h"
|
|
||||||
#include "enodes.h"
|
#include "enodes.h"
|
||||||
|
#include "emsg.h"
|
||||||
#include "etools.h"
|
#include "etools.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ namespace e2d
|
||||||
class EScene;
|
class EScene;
|
||||||
class ENode;
|
class ENode;
|
||||||
class EObjectManager;
|
class EObjectManager;
|
||||||
|
class EMouseListener;
|
||||||
|
class EKeyboardListener;
|
||||||
|
|
||||||
class EApp
|
class EApp
|
||||||
{
|
{
|
||||||
|
|
@ -42,81 +44,75 @@ public:
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
// 修改窗口大小
|
// 修改窗口大小
|
||||||
void setWindowSize(
|
static void setWindowSize(
|
||||||
int width,
|
int width,
|
||||||
int height
|
int height
|
||||||
);
|
);
|
||||||
|
|
||||||
// 修改窗口大小
|
// 修改窗口大小
|
||||||
void setWindowSize(
|
static void setWindowSize(
|
||||||
e2d::ESize size
|
e2d::ESize size
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置窗口标题
|
// 设置窗口标题
|
||||||
void setWindowTitle(
|
static void setWindowTitle(
|
||||||
e2d::EString title
|
e2d::EString title
|
||||||
);
|
);
|
||||||
|
|
||||||
// 获取窗口标题
|
// 获取窗口标题
|
||||||
e2d::EString getTitle();
|
static e2d::EString getTitle();
|
||||||
|
|
||||||
// 获取窗口大小
|
// 获取窗口大小
|
||||||
e2d::ESize getSize();
|
static e2d::ESize getSize();
|
||||||
|
|
||||||
// 获取窗口宽度
|
// 获取窗口宽度
|
||||||
UINT32 getWidth();
|
static UINT32 getWidth();
|
||||||
|
|
||||||
// 获取窗口高度
|
// 获取窗口高度
|
||||||
UINT32 getHeight();
|
static UINT32 getHeight();
|
||||||
|
|
||||||
// 切换场景
|
// 切换场景
|
||||||
void enterScene(
|
static void enterScene(
|
||||||
EScene * scene,
|
EScene * scene,
|
||||||
bool save = true
|
bool save = true
|
||||||
);
|
);
|
||||||
|
|
||||||
// 返回上一场景
|
// 返回上一场景
|
||||||
void backScene();
|
static void backScene();
|
||||||
|
|
||||||
// 清空保存的所有场景
|
// 清空保存的所有场景
|
||||||
void clearScene();
|
static void clearScene();
|
||||||
|
|
||||||
// 获取当前场景
|
// 获取当前场景
|
||||||
EScene * getCurrentScene();
|
static EScene * getCurrentScene();
|
||||||
|
|
||||||
// 获取正处于加载中的场景
|
|
||||||
EScene * getLoadingScene();
|
|
||||||
|
|
||||||
// 设置正处于加载中的场景
|
|
||||||
void setLoadingScene(EScene * scene);
|
|
||||||
|
|
||||||
// 获取 AppName
|
// 获取 AppName
|
||||||
e2d::EString getAppName();
|
static e2d::EString getAppName();
|
||||||
|
|
||||||
// 设置 AppName
|
// 设置 AppName
|
||||||
void setAppName(
|
static void setAppName(
|
||||||
e2d::EString appname
|
e2d::EString appname
|
||||||
);
|
);
|
||||||
|
|
||||||
// 修改窗口背景色
|
// 修改窗口背景色
|
||||||
void setBkColor(
|
static void setBkColor(
|
||||||
EColor::Enum color
|
EColor::Enum color
|
||||||
);
|
);
|
||||||
|
|
||||||
// 释放所有内存资源
|
// 释放所有内存资源
|
||||||
void free();
|
static void free();
|
||||||
|
|
||||||
// 关闭窗口
|
// 关闭窗口
|
||||||
void close();
|
static void close();
|
||||||
|
|
||||||
// 显示窗口
|
// 显示窗口
|
||||||
void show();
|
static void show();
|
||||||
|
|
||||||
// 终止程序
|
// 终止程序
|
||||||
void quit();
|
static void quit();
|
||||||
|
|
||||||
// 终止程序
|
// 终止程序
|
||||||
void end();
|
static void end();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Initialize device-independent resources.
|
// Initialize device-independent resources.
|
||||||
|
|
@ -133,7 +129,7 @@ protected:
|
||||||
void _onControl();
|
void _onControl();
|
||||||
|
|
||||||
// Draw content.
|
// Draw content.
|
||||||
bool _onRender();
|
void _onRender();
|
||||||
|
|
||||||
void _enterNextScene();
|
void _enterNextScene();
|
||||||
|
|
||||||
|
|
@ -160,7 +156,6 @@ protected:
|
||||||
|
|
||||||
EScene * m_pCurrentScene;
|
EScene * m_pCurrentScene;
|
||||||
EScene * m_pNextScene;
|
EScene * m_pNextScene;
|
||||||
EScene * m_pLoadingScene;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -169,13 +164,10 @@ class EScene
|
||||||
friend EApp;
|
friend EApp;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EScene();
|
EScene() = default;
|
||||||
|
|
||||||
~EScene();
|
~EScene();
|
||||||
|
|
||||||
// 重写这个函数,初始化这个场景
|
|
||||||
virtual void init();
|
|
||||||
|
|
||||||
// 重写这个函数,它将在进入这个场景时自动执行
|
// 重写这个函数,它将在进入这个场景时自动执行
|
||||||
virtual void onEnter();
|
virtual void onEnter();
|
||||||
|
|
||||||
|
|
@ -200,14 +192,18 @@ public:
|
||||||
// 清空所有子成员
|
// 清空所有子成员
|
||||||
void clearAllChildren();
|
void clearAllChildren();
|
||||||
|
|
||||||
|
// 绑定鼠标消息监听器
|
||||||
|
void bindListener(EMouseListener * listener);
|
||||||
|
|
||||||
|
// 绑定按键消息监听器
|
||||||
|
void bindListener(EKeyboardListener * listener);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// 渲染场景画面
|
||||||
|
void _onRender();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<e2d::ENode*> m_vChildren;
|
std::vector<e2d::ENode*> m_vChildren;
|
||||||
|
|
||||||
protected:
|
|
||||||
// 场景
|
|
||||||
void _exec();
|
|
||||||
|
|
||||||
void _onRender();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,18 @@
|
||||||
|
|
||||||
#ifndef ASSERT_IF
|
#ifndef ASSERT_IF
|
||||||
#if defined( DEBUG ) || defined( _DEBUG )
|
#if defined( DEBUG ) || defined( _DEBUG )
|
||||||
#define ASSERT(b) do {if (!(b)) { OutputDebugStringA("Assert: " #b "\n"); }} while(0)
|
#define ASSERT(b, m) do {if (!(b)) { fprintf(stderr, "Assert: " #m "\n"); abort(); }} while(0)
|
||||||
#else
|
#else
|
||||||
#define ASSERT(b)
|
#define ASSERT(b, m) ((void)0)
|
||||||
#endif //DEBUG || _DEBUG
|
#endif //DEBUG || _DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WARN_IF
|
#ifndef WARN_IF
|
||||||
#define WARN_IF(b, m) do {if (b) { fprintf(stderr, "Warning: " #m "/n"); }} while(0)
|
#if defined( DEBUG ) || defined( _DEBUG )
|
||||||
|
#define WARN_IF(b, m) do {if (b) { fprintf(stderr, "Warning: " #m "\n"); }} while(0)
|
||||||
|
#else
|
||||||
|
#define WARN_IF(b, m) ((void)0)
|
||||||
|
#endif //DEBUG || _DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
257
Easy2D/emsg.h
257
Easy2D/emsg.h
|
|
@ -4,9 +4,9 @@
|
||||||
namespace e2d
|
namespace e2d
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class ENode;
|
||||||
class EMsgManager;
|
class EMsgManager;
|
||||||
|
|
||||||
|
|
||||||
// 鼠标消息
|
// 鼠标消息
|
||||||
class EMouseMsg
|
class EMouseMsg
|
||||||
{
|
{
|
||||||
|
|
@ -66,6 +66,77 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 按键消息
|
||||||
|
class EKeyMsg
|
||||||
|
{
|
||||||
|
friend EMsgManager;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// 按键消息类型集合
|
||||||
|
enum class KEYBOARD_MSG
|
||||||
|
{
|
||||||
|
KEY_DOWN = 0x0100, // 按下
|
||||||
|
KEY_UP // 抬起
|
||||||
|
};
|
||||||
|
|
||||||
|
// 按键键值集合
|
||||||
|
enum class KEY
|
||||||
|
{
|
||||||
|
A = '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, // 字母键值
|
||||||
|
NUM0 = '0', NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, // 数字键值
|
||||||
|
NUMPAD0 = 0x60, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, // 数字小键盘键值
|
||||||
|
F1 = 0x70, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, // F键键值
|
||||||
|
MULTIPLY, // 乘号键键值
|
||||||
|
ADD, // 加号键键值
|
||||||
|
SEPARATOR, // 分割键键值
|
||||||
|
SUBTRACT, // 减号键键值
|
||||||
|
DECIMAL, // 小数点键键值
|
||||||
|
DIVIDE, // 除号键键值
|
||||||
|
TAB = 0x09, // TAB 键键值
|
||||||
|
ENTER = 0x0D, // 回车键键值
|
||||||
|
SHIFT, CTRL, // SHIFT 键键值
|
||||||
|
ESC = 0x1B, // ESCAPE 键键值
|
||||||
|
SPACE = 0x20, // 空格键键值
|
||||||
|
PAGE_UP, // PageUp 键键值
|
||||||
|
PAGE_DOWN, // PageDown 键键值
|
||||||
|
END, // End 键键值
|
||||||
|
HOME, // Home 键键值
|
||||||
|
LEFT, // 左键键值
|
||||||
|
UP, // 上键键值
|
||||||
|
RIGHT, // 右键键值
|
||||||
|
DOWN // 下键键值
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取按键消息类型
|
||||||
|
static KEYBOARD_MSG getMsg();
|
||||||
|
|
||||||
|
// 获取键值
|
||||||
|
static KEY getVal();
|
||||||
|
|
||||||
|
// 获取按键消息的计数
|
||||||
|
static DWORD getCount();
|
||||||
|
|
||||||
|
// 获取特定按键的状态
|
||||||
|
static bool isKeyDown(
|
||||||
|
KEY key
|
||||||
|
);
|
||||||
|
|
||||||
|
// 获取大小写锁定状态
|
||||||
|
static bool isCapitalLockOn();
|
||||||
|
|
||||||
|
// 获取数字小键盘锁定状态
|
||||||
|
static bool isNumpadLockOn();
|
||||||
|
|
||||||
|
// 获取滑动锁定状态
|
||||||
|
static bool isScrollLockOn();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UINT m_nMsg = 0;
|
||||||
|
WPARAM m_wParam = 0;
|
||||||
|
LPARAM m_lParam = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// 监听器
|
// 监听器
|
||||||
class EListener :
|
class EListener :
|
||||||
public EObject
|
public EObject
|
||||||
|
|
@ -80,6 +151,9 @@ public:
|
||||||
// 获取监听器状态
|
// 获取监听器状态
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
|
// 获取监听器挂起状态
|
||||||
|
bool isWaiting() const;
|
||||||
|
|
||||||
// 启动监听
|
// 启动监听
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
|
|
@ -92,20 +166,31 @@ public:
|
||||||
// 唤醒
|
// 唤醒
|
||||||
void notify();
|
void notify();
|
||||||
|
|
||||||
|
// 克隆一个相同的监听器
|
||||||
|
virtual EListener * clone();
|
||||||
|
|
||||||
// 获取监听器名称
|
// 获取监听器名称
|
||||||
EString getName() const;
|
EString getName() const;
|
||||||
|
|
||||||
// 获取监听器所在场景
|
// 获取监听器所在场景
|
||||||
EScene * getParentScene() const;
|
EScene * getParentScene() const;
|
||||||
|
|
||||||
|
// 获取监听器所在节点
|
||||||
|
ENode * getParentNode() const;
|
||||||
|
|
||||||
// 设置监听器名称
|
// 设置监听器名称
|
||||||
void setName(
|
void setName(
|
||||||
EString name
|
EString name
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置监听器所在场景
|
// 绑定监听器到场景
|
||||||
void setParentScene(
|
void bindWithScene(
|
||||||
EScene * scene
|
EScene * pParentScene
|
||||||
|
);
|
||||||
|
|
||||||
|
// 绑定监听器到节点
|
||||||
|
void bindWithNode(
|
||||||
|
ENode * pParentNode
|
||||||
);
|
);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -113,6 +198,7 @@ protected:
|
||||||
bool m_bRunning;
|
bool m_bRunning;
|
||||||
bool m_bWaiting;
|
bool m_bWaiting;
|
||||||
EScene * m_pParentScene;
|
EScene * m_pParentScene;
|
||||||
|
ENode * m_pParentNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -217,93 +303,22 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// 按键消息
|
|
||||||
class EKeyMsg
|
|
||||||
{
|
|
||||||
friend EMsgManager;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// 按键消息类型集合
|
|
||||||
enum class KEYBOARD_MSG
|
|
||||||
{
|
|
||||||
KEY_DOWN = 0x0100, // 按下
|
|
||||||
KEY_UP // 抬起
|
|
||||||
};
|
|
||||||
|
|
||||||
// 按键键值集合
|
|
||||||
enum class KEY
|
|
||||||
{
|
|
||||||
A = '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, // 字母键值
|
|
||||||
NUM0 = '0', NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, // 数字键值
|
|
||||||
NUMPAD0 = 0x60, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, // 数字小键盘键值
|
|
||||||
F1 = 0x70, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, // F键键值
|
|
||||||
MULTIPLY, // 乘号键键值
|
|
||||||
ADD, // 加号键键值
|
|
||||||
SEPARATOR, // 分割键键值
|
|
||||||
SUBTRACT, // 减号键键值
|
|
||||||
DECIMAL, // 小数点键键值
|
|
||||||
DIVIDE, // 除号键键值
|
|
||||||
TAB = 0x09, // TAB 键键值
|
|
||||||
ENTER = 0x0D, // 回车键键值
|
|
||||||
SHIFT, CTRL, // SHIFT 键键值
|
|
||||||
ESC = 0x1B, // ESCAPE 键键值
|
|
||||||
SPACE = 0x20, // 空格键键值
|
|
||||||
PAGE_UP, // PageUp 键键值
|
|
||||||
PAGE_DOWN, // PageDown 键键值
|
|
||||||
END, // End 键键值
|
|
||||||
HOME, // Home 键键值
|
|
||||||
LEFT, // 左键键值
|
|
||||||
UP, // 上键键值
|
|
||||||
RIGHT, // 右键键值
|
|
||||||
DOWN // 下键键值
|
|
||||||
};
|
|
||||||
|
|
||||||
// 获取按键消息类型
|
|
||||||
static KEYBOARD_MSG getMsg();
|
|
||||||
|
|
||||||
// 获取键值
|
|
||||||
static KEY getVal();
|
|
||||||
|
|
||||||
// 获取按键消息的计数
|
|
||||||
static DWORD getCount();
|
|
||||||
|
|
||||||
// 获取特定按键的状态
|
|
||||||
static bool isKeyDown(
|
|
||||||
KEY key
|
|
||||||
);
|
|
||||||
|
|
||||||
// 获取大小写锁定状态
|
|
||||||
static bool isCapitalLockOn();
|
|
||||||
|
|
||||||
// 获取数字小键盘锁定状态
|
|
||||||
static bool isNumpadLockOn();
|
|
||||||
|
|
||||||
// 获取滑动锁定状态
|
|
||||||
static bool isScrollLockOn();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
UINT m_nMsg = 0;
|
|
||||||
WPARAM m_wParam = 0;
|
|
||||||
LPARAM m_lParam = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// 按键消息监听器
|
// 按键消息监听器
|
||||||
class EKeyListener :
|
class EKeyboardListener :
|
||||||
public EListener
|
public EListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EKeyListener();
|
EKeyboardListener();
|
||||||
|
|
||||||
EKeyListener(
|
EKeyboardListener(
|
||||||
EString name
|
EString name
|
||||||
);
|
);
|
||||||
|
|
||||||
EKeyListener(
|
EKeyboardListener(
|
||||||
const KEY_LISTENER_CALLBACK &callback
|
const KEY_LISTENER_CALLBACK &callback
|
||||||
);
|
);
|
||||||
|
|
||||||
EKeyListener(
|
EKeyboardListener(
|
||||||
EString name,
|
EString name,
|
||||||
const KEY_LISTENER_CALLBACK &callback
|
const KEY_LISTENER_CALLBACK &callback
|
||||||
);
|
);
|
||||||
|
|
@ -323,7 +338,7 @@ protected:
|
||||||
|
|
||||||
// 按键按下消息监听
|
// 按键按下消息监听
|
||||||
class EKeyPressListener :
|
class EKeyPressListener :
|
||||||
public EKeyListener
|
public EKeyboardListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EKeyPressListener();
|
EKeyPressListener();
|
||||||
|
|
@ -352,15 +367,15 @@ class EMsgManager
|
||||||
friend EApp;
|
friend EApp;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 添加鼠标消息监听器
|
// 绑定鼠标消息监听器到场景
|
||||||
static void addListener(
|
static void bindListenerWithScene(
|
||||||
EMouseListener * listener,
|
EMouseListener * listener,
|
||||||
EScene * pParentScene
|
EScene * pParentScene
|
||||||
);
|
);
|
||||||
|
|
||||||
// 添加按键消息监听器
|
// 绑定按键消息监听器到场景
|
||||||
static void addListener(
|
static void bindListenerWithScene(
|
||||||
EKeyListener * listener,
|
EKeyboardListener * listener,
|
||||||
EScene * pParentScene
|
EScene * pParentScene
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -379,14 +394,72 @@ public:
|
||||||
EString name
|
EString name
|
||||||
);
|
);
|
||||||
|
|
||||||
// 挂起场景上的所有监听器
|
// 启动所有鼠标消息监听器
|
||||||
static void waitAllListenersOnScene(
|
static void startAllMouseListener();
|
||||||
EScene * scene
|
|
||||||
|
// 停止所有鼠标消息监听器
|
||||||
|
static void stopAllMouseListener();
|
||||||
|
|
||||||
|
// 清除所有鼠标消息监听器
|
||||||
|
static void clearAllMouseListeners();
|
||||||
|
|
||||||
|
// 启动所有按键消息监听器
|
||||||
|
static void startAllKeyboardListener();
|
||||||
|
|
||||||
|
// 停止所有按键消息监听器
|
||||||
|
static void stopAllKeyboardListener();
|
||||||
|
|
||||||
|
// 清除所有按键消息监听器
|
||||||
|
static void clearAllKeyboardListeners();
|
||||||
|
|
||||||
|
// 启动绑定在场景上的所有鼠标消息监听器
|
||||||
|
static void startAllMouseListenersBindWithScene(
|
||||||
|
EScene * pParentScene
|
||||||
);
|
);
|
||||||
|
|
||||||
// 重启场景上的所有监听器
|
// 重启绑定在场景上的所有鼠标消息监听器
|
||||||
static void notifyAllListenersOnScene(
|
static void stopAllMouseListenersBindWithScene(
|
||||||
EScene * scene
|
EScene * pParentScene
|
||||||
|
);
|
||||||
|
|
||||||
|
// 启动绑定在场景上的所有按键消息监听器
|
||||||
|
static void startAllKeyboardListenersBindWithScene(
|
||||||
|
EScene * pParentScene
|
||||||
|
);
|
||||||
|
|
||||||
|
// 重启绑定在场景上的所有按键消息监听器
|
||||||
|
static void stopAllKeyboardListenersBindWithScene(
|
||||||
|
EScene * pParentScene
|
||||||
|
);
|
||||||
|
|
||||||
|
// 挂起绑定在场景上的所有监听器
|
||||||
|
static void waitAllListenersBindWithScene(
|
||||||
|
EScene * pParentScene
|
||||||
|
);
|
||||||
|
|
||||||
|
// 重启绑定在场景上的所有监听器
|
||||||
|
static void notifyAllListenersBindWithScene(
|
||||||
|
EScene * pParentScene
|
||||||
|
);
|
||||||
|
|
||||||
|
// 清空绑定在场景上的所有监听器
|
||||||
|
static void clearAllListenersBindWithScene(
|
||||||
|
EScene * pParentScene
|
||||||
|
);
|
||||||
|
|
||||||
|
// 挂起绑定在节点上的所有监听器
|
||||||
|
static void waitAllListenersBindWithNode(
|
||||||
|
ENode * pParentNode
|
||||||
|
);
|
||||||
|
|
||||||
|
// 重启绑定在节点上的所有监听器
|
||||||
|
static void notifyAllListenersBindWithNode(
|
||||||
|
ENode * pParentNode
|
||||||
|
);
|
||||||
|
|
||||||
|
// 清空绑定在节点上的所有监听器
|
||||||
|
static void clearAllListenersBindWithNode(
|
||||||
|
ENode * pParentNode
|
||||||
);
|
);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@
|
||||||
namespace e2d
|
namespace e2d
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class EScene;
|
||||||
|
class EObject;
|
||||||
|
|
||||||
class ENode :
|
class ENode :
|
||||||
public EObject
|
public EObject
|
||||||
{
|
{
|
||||||
|
|
@ -144,7 +147,7 @@ public:
|
||||||
);
|
);
|
||||||
|
|
||||||
// 设置节点所在场景
|
// 设置节点所在场景
|
||||||
void setParentScene(
|
void bindWithScene(
|
||||||
EScene * scene
|
EScene * scene
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class EObjectManager
|
||||||
friend EApp;
|
friend EApp;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 将一个节点放入释放池
|
// 将一个节点放入内存池
|
||||||
static void add(
|
static void add(
|
||||||
e2d::EObject * nptr
|
e2d::EObject * nptr
|
||||||
);
|
);
|
||||||
|
|
@ -18,9 +18,19 @@ public:
|
||||||
// 删除所有节点
|
// 删除所有节点
|
||||||
static void clearAllObjects();
|
static void clearAllObjects();
|
||||||
|
|
||||||
|
// 通知内存池刷新
|
||||||
|
static void notifyFlush();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 刷新内存池
|
// 刷新内存池
|
||||||
static void __flush();
|
static void __flush();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 定时器管理器
|
||||||
|
class ETimerManager
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue