fix: minor fixes

This commit is contained in:
Nomango 2018-10-17 00:16:26 +08:00
parent 75440b15a2
commit db5446bb78
14 changed files with 136 additions and 91 deletions

View File

@ -18,26 +18,26 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_ACTION_H__
#define __E2D_ACTION_H__
#include "e2dutil.h"
#include "e2dobject.h"
namespace easy2d
{
class Node;
class Loop;
class Sequence;
class Spawn;
class ActionManager;
// »ù´¡¶¯×÷
class Action
: public Ref
{
friend class ActionManager;
friend class Loop;
friend class Sequence;
friend class Spawn;
@ -818,5 +818,7 @@ namespace easy2d
Animation * animation_;
};
} // end of easy2d namespace
}
#endif // __E2D_ACTION_H__

View File

@ -18,13 +18,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_COMPONENT_H__
#define __E2D_COMPONENT_H__
#include "e2dobject.h"
namespace easy2d
{
class Button
: public Node
{
@ -175,5 +177,7 @@ namespace easy2d
std::vector<Button*> buttons_;
};
} // end of easy2d namespace
}
#endif // !__E2D_COMPONENT_H__

View File

@ -18,13 +18,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_EVENT_H__
#define __E2D_EVENT_H__
#include "e2dutil.h"
namespace easy2d
{
// °´¼üÏûÏ¢
class KeyEvent
{
@ -121,4 +122,7 @@ namespace easy2d
LPARAM l_param_;
};
}
} // end of easy2d namespace
#endif // __E2D_EVENT_H__

View File

@ -18,11 +18,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_IMPL_H__
#define __E2D_IMPL_H__
#include "e2dutil.h"
namespace easy2d
{
// ÎÄ×ÖäÖȾÆ÷
class TextRenderer
: public IDWriteTextRenderer
@ -77,7 +81,7 @@ namespace easy2d
BOOL IsSideways,
BOOL IsRightToLeft,
IUnknown* clientDrawingEffect
);
);
STDMETHOD(IsPixelSnappingDisabled)(
__maybenull void* clientDrawingContext,
@ -150,4 +154,7 @@ namespace easy2d
}
}
}
} // end of easy2d namespace
#endif // __E2D_IMPL_H__

View File

@ -18,7 +18,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_MACROS_H__
#define __E2D_MACROS_H__
#ifndef WINVER
# define WINVER 0x0700 // Allow use of features specific to Windows 7 or later
@ -137,48 +139,20 @@
#ifndef E2D_WARNING
# if defined( DEBUG ) || defined( _DEBUG )
# define E2D_WARNING(msg, ...) do { OutputDebugStringExW(L"Warning: " _CRT_WIDE(#msg) L"\n", __VA_ARGS__); } while(0)
# define E2D_WARNING(msg) do { ::OutputDebugStringW(L"Warning: " _CRT_WIDE(msg) L"\r\n"); } while(0)
# else
# define E2D_WARNING(msg, ...) ((void)0)
# define E2D_WARNING(msg) ((void)0)
# endif
#endif
#ifndef E2D_WARNING_IF
# if defined( DEBUG ) || defined( _DEBUG )
# define E2D_WARNING_IF(exp, msg, ...) do { if (exp) { OutputDebugStringExW(L"Warning: " _CRT_WIDE(#msg) L"\n", __VA_ARGS__); } } while(0)
# define E2D_WARNING_IF(exp, msg) do { if (exp) { ::OutputDebugStringW(L"Warning: " _CRT_WIDE(msg) L"\r\n"); } } while(0)
# else
# define E2D_WARNING_IF(exp, msg, ...) ((void)0)
# define E2D_WARNING_IF(exp, msg) ((void)0)
# endif
#endif
void OutputDebugStringExW(LPCWSTR pszOutput, ...)
{
va_list args = NULL;
va_start(args, pszOutput);
size_t nLen = _vscwprintf(pszOutput, args) + 1;
const wchar_t* psBuffer = new wchar_t[nLen];
_vsnwprintf_s(psBuffer, nLen, nLen, pszOutput, args);
va_end(args);
OutputDebugStringW(psBuffer);
delete [] psBuffer;
}
void OutputDebugStringExA(LPCSTR pszOutput, ...)
{
va_list args = NULL;
va_start(args, pszOutput);
size_t nLen = _vscprintf(pszOutput, args) + 1;
const char* psBuffer = new char[nLen];
_vsnprintf_s(psBuffer, nLen, nLen, pszOutput, args);
va_end(args);
OutputDebugStringA(psBuffer);
delete [] psBuffer;
}
#endif // __E2D_MACROS_H__

View File

@ -18,7 +18,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_MODULE_H__
#define __E2D_MODULE_H__
#include "e2dimpl.h"
#include "e2dobject.h"
#include "e2dtransition.h"
@ -321,4 +324,7 @@ namespace easy2d
Transition* transition_;
};
}
} // end of easy2d namespace
#endif // __E2D_MODULE_H__

View File

@ -18,7 +18,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_OBJECT_H__
#define __E2D_OBJECT_H__
#include "e2dutil.h"
#include "e2devent.h"
@ -26,7 +29,6 @@
namespace easy2d
{
// ͼƬ
class Image
: public Ref
@ -1092,4 +1094,7 @@ namespace easy2d
ID2D1StrokeStyle * stroke_style_;
};
}
} // end of easy2d namespace
#endif // __E2D_OBJECT_H__

View File

@ -18,7 +18,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_TOOL_H__
#define __E2D_TOOL_H__
#include "e2dutil.h"
#include "e2dimpl.h"
@ -374,4 +377,7 @@ namespace easy2d
static const String& GetExeFilePath();
};
}
} // end of easy2d namespace
#endif // __E2D_TOOL_H__

View File

@ -18,13 +18,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_TRANSITION_H__
#define __E2D_TRANSITION_H__
#include "e2dutil.h"
namespace easy2d
{
class Game;
class Scene;
@ -193,4 +195,7 @@ namespace easy2d
float rotation_;
};
}
} // end of easy2d namespace
#endif // __E2D_TRANSITION_H__

View File

@ -18,13 +18,15 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#ifndef __E2D_UTIL_H__
#define __E2D_UTIL_H__
#include "e2dmacros.h"
namespace easy2d
{
// ·½Ïò
enum class Direction : int
{
@ -676,5 +678,7 @@ namespace easy2d
}
}
} // end of easy2d namespace
}
#endif // __E2D_UTIL_H__

View File

@ -314,8 +314,12 @@ ID2D1StrokeStyle * easy2d::Graphics::GetRoundStrokeStyle()
float easy2d::Graphics::GetDpi()
{
HDC hdc = ::GetDC(0);
int dpi = ::GetDeviceCaps(hdc, LOGPIXELSX);
::ReleaseDC(0, hdc);
return static_cast<float>(dpi);
static float dpi = -1;
if (dpi < 0)
{
HDC hdc = ::GetDC(0);
dpi = static_cast<float>(::GetDeviceCaps(hdc, LOGPIXELSX));
::ReleaseDC(0, hdc);
}
return dpi;
}

View File

@ -120,11 +120,11 @@ easy2d::File easy2d::File::Extract(const Resource& res, const String& dest_file_
return std::move(file);
// 查找资源文件中、加载资源到内存、得到资源大小
HRSRC res = ::FindResource(NULL, MAKEINTRESOURCE(res.id), static_cast<LPCWSTR>(res.type));
HGLOBAL res_data = ::LoadResource(NULL, res);
DWORD res_size = ::SizeofResource(NULL, res);
HRSRC res_info = ::FindResource(NULL, MAKEINTRESOURCE(res.id), static_cast<LPCWSTR>(res.type));
HGLOBAL res_data = ::LoadResource(NULL, res_info);
DWORD res_size = ::SizeofResource(NULL, res_info);
if (res && res_data && res_size)
if (res_info && res_data && res_size)
{
// 写入文件
DWORD written_bytes = 0;

View File

@ -22,16 +22,32 @@
#include "..\e2dmodule.h"
inline bool TraceError(wchar_t* prompt)
namespace
{
E2D_WARNING("Music error: %s failed!", prompt);
return false;
}
void OutputDebugStringExW(LPCWSTR pszOutput, ...)
{
va_list args = NULL;
va_start(args, pszOutput);
inline bool TraceError(wchar_t* prompt, HRESULT hr)
{
E2D_WARNING("Music error: %s (%#X)", prompt, hr);
return false;
size_t nLen = _vscwprintf(pszOutput, args) + 1;
wchar_t* psBuffer = new wchar_t[nLen];
_vsnwprintf_s(psBuffer, nLen, nLen, pszOutput, args);
va_end(args);
::OutputDebugStringW(psBuffer);
delete[] psBuffer;
}
inline void TraceError(LPCWSTR output)
{
OutputDebugStringExW(L"Music error: %s failed!\r\n", output);
}
inline void TraceError(LPCWSTR output, HRESULT hr)
{
OutputDebugStringExW(L"Music error: %s (%#X)\r\n", output, hr);
}
}
@ -99,35 +115,40 @@ namespace easy2d
res_info = FindResourceW(HINST_THISCOMPONENT, res_name, res_type);
if (res_info == nullptr)
{
return TraceError(L"FindResource");
TraceError(L"FindResource");
return false;
}
res_data = LoadResource(HINST_THISCOMPONENT, res_info);
if (res_data == nullptr)
{
return TraceError(L"LoadResource");
TraceError(L"LoadResource");
return false;
}
res_size = SizeofResource(HINST_THISCOMPONENT, res_info);
if (res_size == 0)
{
return TraceError(L"SizeofResource");
TraceError(L"SizeofResource");
return false;
}
res = LockResource(res_data);
if (res == nullptr)
{
return TraceError(L"LockResource");
TraceError(L"LockResource");
return false;
}
stream = ::SHCreateMemStream(
stream = SHCreateMemStream(
static_cast<const BYTE*>(res),
static_cast<UINT>(res_size)
);
if (stream == nullptr)
{
return TraceError(L"SHCreateMemStream");
TraceError(L"SHCreateMemStream");
return false;
}
if (SUCCEEDED(hr))
@ -359,7 +380,7 @@ bool easy2d::Music::Load(const easy2d::String & file_path)
File music_file;
if (!music_file.Open(file_path))
{
E2D_WARNING("Music::Load error: File not found.");
E2D_WARNING("Media file not found.");
return false;
}
@ -381,7 +402,8 @@ bool easy2d::Music::Load(const easy2d::String & file_path)
delete[] wave_data_;
wave_data_ = nullptr;
}
return TraceError(L"Create source voice error", hr);
TraceError(L"Create source voice error", hr);
return false;
}
opened_ = true;
@ -409,7 +431,8 @@ bool easy2d::Music::Load(const Resource& res)
delete[] wave_data_;
wave_data_ = nullptr;
}
return TraceError(L"Create source voice error", hr);
TraceError(L"Create source voice error", hr);
return false;
}
opened_ = true;
@ -420,13 +443,13 @@ bool easy2d::Music::Play(int loop_count)
{
if (!opened_)
{
E2D_WARNING("Music::Play Failed: Music must be opened first!");
E2D_WARNING("Music must be opened first!");
return false;
}
if (voice_ == nullptr)
{
E2D_WARNING("Music::Play Failed: IXAudio2SourceVoice Null pointer exception!");
E2D_WARNING("IXAudio2SourceVoice Null pointer exception!");
return false;
}
@ -456,7 +479,8 @@ bool easy2d::Music::Play(int loop_count)
HRESULT hr;
if (FAILED(hr = voice_->SubmitSourceBuffer(&buffer)))
{
return TraceError(L"Submitting source buffer error", hr);
TraceError(L"Submitting source buffer error", hr);
return false;
}
hr = voice_->Start(0);

View File

@ -101,7 +101,7 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<DebugInformationFormat>None</DebugInformationFormat>
<MinimalRebuild>false</MinimalRebuild>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>