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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_ACTION_H__
#define __E2D_ACTION_H__
#include "e2dutil.h" #include "e2dutil.h"
#include "e2dobject.h" #include "e2dobject.h"
namespace easy2d namespace easy2d
{ {
class Node; class Node;
class Loop; class Loop;
class Sequence; class Sequence;
class Spawn; class Spawn;
class ActionManager;
// »ù´¡¶¯×÷ // »ù´¡¶¯×÷
class Action class Action
: public Ref : public Ref
{ {
friend class ActionManager;
friend class Loop; friend class Loop;
friend class Sequence; friend class Sequence;
friend class Spawn; friend class Spawn;
@ -818,5 +818,7 @@ namespace easy2d
Animation * animation_; 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_COMPONENT_H__
#define __E2D_COMPONENT_H__
#include "e2dobject.h" #include "e2dobject.h"
namespace easy2d namespace easy2d
{ {
class Button class Button
: public Node : public Node
{ {
@ -175,5 +177,7 @@ namespace easy2d
std::vector<Button*> buttons_; 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_EVENT_H__
#define __E2D_EVENT_H__
#include "e2dutil.h" #include "e2dutil.h"
namespace easy2d namespace easy2d
{ {
// °´¼üÏûÏ¢ // °´¼üÏûÏ¢
class KeyEvent class KeyEvent
{ {
@ -121,4 +122,7 @@ namespace easy2d
LPARAM l_param_; 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_IMPL_H__
#define __E2D_IMPL_H__
#include "e2dutil.h" #include "e2dutil.h"
namespace easy2d namespace easy2d
{ {
// 文字渲染器 // 文字渲染器
class TextRenderer class TextRenderer
: public IDWriteTextRenderer : public IDWriteTextRenderer
@ -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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_MACROS_H__
#define __E2D_MACROS_H__
#ifndef WINVER #ifndef WINVER
# define WINVER 0x0700 // Allow use of features specific to Windows 7 or later # define WINVER 0x0700 // Allow use of features specific to Windows 7 or later
@ -137,48 +139,20 @@
#ifndef E2D_WARNING #ifndef E2D_WARNING
# if defined( DEBUG ) || defined( _DEBUG ) # 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 # else
# define E2D_WARNING(msg, ...) ((void)0) # define E2D_WARNING(msg) ((void)0)
# endif # endif
#endif #endif
#ifndef E2D_WARNING_IF #ifndef E2D_WARNING_IF
# if defined( DEBUG ) || defined( _DEBUG ) # 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 # else
# define E2D_WARNING_IF(exp, msg, ...) ((void)0) # define E2D_WARNING_IF(exp, msg) ((void)0)
# endif # endif
#endif #endif
void OutputDebugStringExW(LPCWSTR pszOutput, ...) #endif // __E2D_MACROS_H__
{
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;
}

View File

@ -18,7 +18,10 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_MODULE_H__
#define __E2D_MODULE_H__
#include "e2dimpl.h" #include "e2dimpl.h"
#include "e2dobject.h" #include "e2dobject.h"
#include "e2dtransition.h" #include "e2dtransition.h"
@ -321,4 +324,7 @@ namespace easy2d
Transition* transition_; 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_OBJECT_H__
#define __E2D_OBJECT_H__
#include "e2dutil.h" #include "e2dutil.h"
#include "e2devent.h" #include "e2devent.h"
@ -26,7 +29,6 @@
namespace easy2d namespace easy2d
{ {
// ͼƬ // ͼƬ
class Image class Image
: public Ref : public Ref
@ -1092,4 +1094,7 @@ namespace easy2d
ID2D1StrokeStyle * stroke_style_; 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_TOOL_H__
#define __E2D_TOOL_H__
#include "e2dutil.h" #include "e2dutil.h"
#include "e2dimpl.h" #include "e2dimpl.h"
@ -374,4 +377,7 @@ namespace easy2d
static const String& GetExeFilePath(); 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_TRANSITION_H__
#define __E2D_TRANSITION_H__
#include "e2dutil.h" #include "e2dutil.h"
namespace easy2d namespace easy2d
{ {
class Game; class Game;
class Scene; class Scene;
@ -193,4 +195,7 @@ namespace easy2d
float rotation_; 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 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#pragma once #ifndef __E2D_UTIL_H__
#define __E2D_UTIL_H__
#include "e2dmacros.h" #include "e2dmacros.h"
namespace easy2d namespace easy2d
{ {
// ·½Ïò // ·½Ïò
enum class Direction : int enum class Direction : int
{ {
@ -676,5 +678,7 @@ namespace easy2d
} }
} }
} // end of easy2d namespace
}
#endif // __E2D_UTIL_H__

View File

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

View File

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

View File

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

View File

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