From 94e073eaaaae03455e861fa4ba63aed5a0b5c612 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Mon, 11 Nov 2013 22:12:29 +0000 Subject: [PATCH] fixing bugs + InnerOnKeyPress added --- include/SalmonEngineWindows.h | 2 ++ .../SerializeInterface/SerializeInterface.h | 17 ++++++++++- src/SalmonEngineWindows.cpp | 28 +++++++++++++++---- src/Utils/DataTypes/DataTypes.cpp | 6 ++-- .../SerializeInterface/SerializeInterface.cpp | 23 +++++++++++++++ 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/include/SalmonEngineWindows.h b/include/SalmonEngineWindows.h index 6fb8032..8c52957 100644 --- a/include/SalmonEngineWindows.h +++ b/include/SalmonEngineWindows.h @@ -38,6 +38,8 @@ public: //To do on mouse wheel move virtual void OnKeyPress(cardinal key); //Try not to override this. But if you need to override, call ancestor! + + virtual void InnerOnKeyPress(cardinal key) { } }; bool CreateEngine(int width, int height, int x = 0, int y = 0, std::string windowName = "Salmon Engine App", std::string logFileName = "log.txt"); diff --git a/include/Utils/SerializeInterface/SerializeInterface.h b/include/Utils/SerializeInterface/SerializeInterface.h index 04b8910..63b09db 100644 --- a/include/Utils/SerializeInterface/SerializeInterface.h +++ b/include/Utils/SerializeInterface/SerializeInterface.h @@ -29,6 +29,21 @@ public: } }; + +template +TVALUE GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path) +{ + return subTree.second.get(path); +} + +template <> +vec2 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path); + +template <> +vec3 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path); + +template <> +vec4 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path); template @@ -43,7 +58,7 @@ public: BOOST_FOREACH(boost::property_tree::ptree::value_type& subTree, propertyTree) { TKEY key = subTree.second.get(".key"); - TVALUE value = subTree.second.get(".value"); + TVALUE value = GetValueFromSubtree(subTree, ".value"); Map[key] = value; } diff --git a/src/SalmonEngineWindows.cpp b/src/SalmonEngineWindows.cpp index 305054f..470052f 100644 --- a/src/SalmonEngineWindows.cpp +++ b/src/SalmonEngineWindows.cpp @@ -133,6 +133,8 @@ void TApplication::OnKeyPress(cardinal key) { ResourceManager->GUIManager.KeyPressedSignal(static_cast(key)); } + + App->InnerOnKeyPress(key); } } @@ -221,10 +223,14 @@ case WM_MOUSEMOVE: if (MouseButtonPressed) { vec2 currentMousePos(static_cast(mouseState.X), static_cast(Renderer->GetScreenHeight() - mouseState.Y)); + + currentMousePos.v[0] *= SE::Renderer->GetMatrixWidth() / SE::Renderer->GetScreenWidth(); + currentMousePos.v[1] *= SE::Renderer->GetMatrixHeight() / SE::Renderer->GetScreenHeight(); + vec2 shift = (MouseButtonPos - currentMousePos); - //shift.v[1] = - shift.v[1]; - App->OuterOnMove(shift); - //App->OuterOnMove(currentMousePos - MouseButtonPos); + + App->OuterOnMove(shift, 0); + MouseButtonPos = currentMousePos; MouseTotalShift += shift; @@ -247,9 +253,12 @@ case WM_MOUSEMOVE: MouseButtonPos = vec2(static_cast(mouseState.X), static_cast(Renderer->GetScreenHeight() - mouseState.Y)); + MouseButtonPos.v[0] *= SE::Renderer->GetMatrixWidth() / SE::Renderer->GetScreenWidth(); + MouseButtonPos.v[1] *= SE::Renderer->GetMatrixHeight() / SE::Renderer->GetScreenHeight(); + if (mouseState.LeftButtonPressed) { - App->OuterOnTapDown(MouseButtonPos); + App->OuterOnTapDown(MouseButtonPos, 0); } @@ -270,13 +279,20 @@ case WM_MOUSEMOVE: mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON); mouseState.MiddleButtonPressed = (wParam & MK_RBUTTON); + + MouseButtonPos = vec2(static_cast(mouseState.X), static_cast(Renderer->GetScreenHeight() - mouseState.Y)); + MouseButtonPos.v[0] *= SE::Renderer->GetMatrixWidth() / SE::Renderer->GetScreenWidth(); + MouseButtonPos.v[1] *= SE::Renderer->GetMatrixHeight() / SE::Renderer->GetScreenHeight(); + + + if (MouseMoved) { - App->OuterOnTapUpAfterMove(vec2(static_cast(mouseState.X), static_cast(Renderer->GetScreenHeight() - mouseState.Y))); + App->OuterOnTapUpAfterMove(MouseButtonPos, 0); } else { - App->OuterOnTapUp(vec2(static_cast(mouseState.X), static_cast(Renderer->GetScreenHeight() - mouseState.Y))); + App->OuterOnTapUp(MouseButtonPos, 0); } MouseButtonPressed = false; diff --git a/src/Utils/DataTypes/DataTypes.cpp b/src/Utils/DataTypes/DataTypes.cpp index 8d54e72..b54af0d 100644 --- a/src/Utils/DataTypes/DataTypes.cpp +++ b/src/Utils/DataTypes/DataTypes.cpp @@ -320,7 +320,7 @@ int LineCrossLine2d(const vec2& a1, const vec2& a2, const vec2& b1, const vec2& float detm = m.m[0] * m.m[3] - m.m[1] * m.m[2]; - if (fabs(detm) <= 0.00005f) + if (fabs(detm) <= 0.005f) { return -1; } @@ -345,7 +345,9 @@ int LineCrossLine2d(const vec2& a1, const vec2& a2, const vec2& b1, const vec2& t.v[0] = vx.v[0] * rev_m.m[0] + vx.v[1] * rev_m.m[1]; t.v[1] = vx.v[0] * rev_m.m[2] + vx.v[1] * rev_m.m[3]; - if (t.v[0] < 0 || t.v[0] > 1 || t.v[1] < 0 || t.v[1] > 1) + //if (t.v[0] < 0 || t.v[0] > 1 || t.v[1] < 0 || t.v[1] > 1) + //if (t.v[0] < 0.01f|| t.v[0] > 0.99f || t.v[1] < 0.01f || t.v[1] > 0.99f) + if (t.v[0] < -0.01f || t.v[0] > 1.01f || t.v[1] < -0.01f || t.v[1] > 1.01f) { return 0; } diff --git a/src/Utils/SerializeInterface/SerializeInterface.cpp b/src/Utils/SerializeInterface/SerializeInterface.cpp index 2786c44..921d9de 100644 --- a/src/Utils/SerializeInterface/SerializeInterface.cpp +++ b/src/Utils/SerializeInterface/SerializeInterface.cpp @@ -7,6 +7,29 @@ namespace SE { + + +template <> +vec2 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path) +{ + return StringToVec2(subTree.second.get(path)); +} + +template <> +vec3 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path) +{ + return StringToVec3(subTree.second.get(path)); +} + +template <> +vec4 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path) +{ + return StringToVec4(subTree.second.get(path)); +} + + + + void ReplaceText(boost::property_tree::ptree& propertyTree, std::map& replaceMap) { for (boost::property_tree::ptree::iterator i = propertyTree.begin(); i != propertyTree.end(); )