fixing bugs + InnerOnKeyPress added

This commit is contained in:
Vladislav Khorev 2013-11-11 22:12:29 +00:00
parent ec2e6830aa
commit 94e073eaaa
5 changed files with 67 additions and 9 deletions

View File

@ -38,6 +38,8 @@ public:
//To do on mouse wheel move //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 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"); bool CreateEngine(int width, int height, int x = 0, int y = 0, std::string windowName = "Salmon Engine App", std::string logFileName = "log.txt");

View File

@ -29,6 +29,21 @@ public:
} }
}; };
template <typename TVALUE>
TVALUE GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path)
{
return subTree.second.get<TVALUE>(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 <typename TKEY, typename TVALUE> template <typename TKEY, typename TVALUE>
@ -43,7 +58,7 @@ public:
BOOST_FOREACH(boost::property_tree::ptree::value_type& subTree, propertyTree) BOOST_FOREACH(boost::property_tree::ptree::value_type& subTree, propertyTree)
{ {
TKEY key = subTree.second.get<TKEY>("<xmlattr>.key"); TKEY key = subTree.second.get<TKEY>("<xmlattr>.key");
TVALUE value = subTree.second.get<TVALUE>("<xmlattr>.value"); TVALUE value = GetValueFromSubtree<TVALUE>(subTree, "<xmlattr>.value");
Map[key] = value; Map[key] = value;
} }

View File

@ -133,6 +133,8 @@ void TApplication::OnKeyPress(cardinal key)
{ {
ResourceManager->GUIManager.KeyPressedSignal(static_cast<int>(key)); ResourceManager->GUIManager.KeyPressedSignal(static_cast<int>(key));
} }
App->InnerOnKeyPress(key);
} }
} }
@ -221,10 +223,14 @@ case WM_MOUSEMOVE:
if (MouseButtonPressed) if (MouseButtonPressed)
{ {
vec2 currentMousePos(static_cast<float>(mouseState.X), static_cast<float>(Renderer->GetScreenHeight() - mouseState.Y)); vec2 currentMousePos(static_cast<float>(mouseState.X), static_cast<float>(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); vec2 shift = (MouseButtonPos - currentMousePos);
//shift.v[1] = - shift.v[1];
App->OuterOnMove(shift); App->OuterOnMove(shift, 0);
//App->OuterOnMove(currentMousePos - MouseButtonPos);
MouseButtonPos = currentMousePos; MouseButtonPos = currentMousePos;
MouseTotalShift += shift; MouseTotalShift += shift;
@ -247,9 +253,12 @@ case WM_MOUSEMOVE:
MouseButtonPos = vec2(static_cast<float>(mouseState.X), static_cast<float>(Renderer->GetScreenHeight() - mouseState.Y)); MouseButtonPos = vec2(static_cast<float>(mouseState.X), static_cast<float>(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) 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_MBUTTON);
mouseState.MiddleButtonPressed = (wParam & MK_RBUTTON); mouseState.MiddleButtonPressed = (wParam & MK_RBUTTON);
MouseButtonPos = vec2(static_cast<float>(mouseState.X), static_cast<float>(Renderer->GetScreenHeight() - mouseState.Y));
MouseButtonPos.v[0] *= SE::Renderer->GetMatrixWidth() / SE::Renderer->GetScreenWidth();
MouseButtonPos.v[1] *= SE::Renderer->GetMatrixHeight() / SE::Renderer->GetScreenHeight();
if (MouseMoved) if (MouseMoved)
{ {
App->OuterOnTapUpAfterMove(vec2(static_cast<float>(mouseState.X), static_cast<float>(Renderer->GetScreenHeight() - mouseState.Y))); App->OuterOnTapUpAfterMove(MouseButtonPos, 0);
} }
else else
{ {
App->OuterOnTapUp(vec2(static_cast<float>(mouseState.X), static_cast<float>(Renderer->GetScreenHeight() - mouseState.Y))); App->OuterOnTapUp(MouseButtonPos, 0);
} }
MouseButtonPressed = false; MouseButtonPressed = false;

View File

@ -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]; 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; 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[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]; 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; return 0;
} }

View File

@ -7,6 +7,29 @@
namespace SE namespace SE
{ {
template <>
vec2 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path)
{
return StringToVec2(subTree.second.get<std::string>(path));
}
template <>
vec3 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path)
{
return StringToVec3(subTree.second.get<std::string>(path));
}
template <>
vec4 GetValueFromSubtree(const boost::property_tree::ptree::value_type& subTree, const std::string& path)
{
return StringToVec4(subTree.second.get<std::string>(path));
}
void ReplaceText(boost::property_tree::ptree& propertyTree, std::map<std::string, std::string>& replaceMap) void ReplaceText(boost::property_tree::ptree& propertyTree, std::map<std::string, std::string>& replaceMap)
{ {
for (boost::property_tree::ptree::iterator i = propertyTree.begin(); i != propertyTree.end(); ) for (boost::property_tree::ptree::iterator i = propertyTree.begin(); i != propertyTree.end(); )