diff --git a/include/GUIManager/KeyboardWidget.h b/include/GUIManager/KeyboardWidget.h new file mode 100644 index 0000000..53ac49e --- /dev/null +++ b/include/GUIManager/KeyboardWidget.h @@ -0,0 +1,75 @@ +#ifndef KEYBOARD_WIDGET_H_INCLUDED +#define KEYBOARD_WIDGET_H_INCLUDED + +#include "include/Render/RenderMisc.h" +#include "include/Render/RenderParams.h" +#include "include/Utils/Utils.h" +#include "include/FontManager/FontManager.h" + +#include "include/GUIManager/ButtonWidget.h" + +namespace SE +{ + + struct TVisualKey + { + ivec2 Pos; + ivec2 WidthHeight; + + TVisualKey() + { + } + + TVisualKey(ivec2 pos, ivec2 widthHeight) + : Pos(pos) + , WidthHeight(widthHeight) + { + } + + bool CheckClicked(ivec2 p) + { + return (p.v[0] >= Pos.v[0] - WidthHeight.v[0]*0.5f && p.v[0] <= Pos.v[0] + WidthHeight.v[0]*0.5f) && + (p.v[1] >= Pos.v[1] - WidthHeight.v[1]*0.5f && p.v[1] <= Pos.v[1] + WidthHeight.v[1]*0.5f); + } + }; + + +struct TKeyboardWidget : public TInstancingWidgetAncestor +{ + +protected: + std::vector> VisualKeyArr; + + bool Shifted; + + +public: + + TKeyboardWidget(); + + virtual bool CheckClick(vec2 mousePos); + virtual void OnTapDown(vec2 pos); + virtual void OnTapUp(vec2 pos); + + /* + static TSquareStatic* CreateStatic(vec2 posFrom, vec2 posTo); + static TSquareStatic* CreateStaticWithFiller(vec2 posFrom, vec2 posTo, boost::function staticFillerFunc); + static TSquareStatic* CreateStaticWithFillers(vec2 posFrom, vec2 posTo, std::vector> staticFillerFuncArr); + + static void StaticTextureFiller(vec2 posFrom, vec2 posTo, const std::string& texName, TSquareStatic* staticToFill); + static void StaticTextFiller(vec2 posFrom, vec2 posTo, TTextParams buttonTextParams, TSquareStatic* staticToFill); + + static TSquareStatic* CreateStaticTexture(vec2 posFrom, vec2 posTo, const std::string& texName); + static TSquareStatic* CreateStaticText(vec2 posFrom, vec2 posTo, TTextParams buttonTextParams);*/ + +}; + + + +} + + + + + +#endif \ No newline at end of file diff --git a/src/GUIManager/KeyboardWidget.cpp b/src/GUIManager/KeyboardWidget.cpp new file mode 100644 index 0000000..2895eac --- /dev/null +++ b/src/GUIManager/KeyboardWidget.cpp @@ -0,0 +1,166 @@ +#include "include/Engine.h" + +namespace SE +{ + + + /* +struct TKeyboardWidget : public TInstancingWidgetAncestor +{ + + + TKeyboardWidget(); + + virtual bool CheckClick(vec2 mousePos); + virtual void OnTapDown(vec2 pos); + virtual void OnTapUp(vec2 pos); + +};*/ + + TKeyboardWidget::TKeyboardWidget() + : Shifted(false) + { + std::vector> LineChars; + + LineChars.push_back(std::pair(ivec2(16, 185), static_cast('q'))); + LineChars.push_back(std::pair(ivec2(48, 185), static_cast('w'))); + LineChars.push_back(std::pair(ivec2(80, 185), static_cast('e'))); + LineChars.push_back(std::pair(ivec2(112, 185), static_cast('r'))); + LineChars.push_back(std::pair(ivec2(144, 185), static_cast('t'))); + LineChars.push_back(std::pair(ivec2(176, 185), static_cast('y'))); + LineChars.push_back(std::pair(ivec2(208, 185), static_cast('u'))); + LineChars.push_back(std::pair(ivec2(240, 185), static_cast('i'))); + LineChars.push_back(std::pair(ivec2(272, 185), static_cast('o'))); + LineChars.push_back(std::pair(ivec2(304, 185), static_cast('p'))); + + + LineChars.push_back(std::pair(ivec2(32, 131), static_cast('a'))); + LineChars.push_back(std::pair(ivec2(64, 131), static_cast('s'))); + LineChars.push_back(std::pair(ivec2(96, 131), static_cast('d'))); + LineChars.push_back(std::pair(ivec2(128, 131), static_cast('f'))); + LineChars.push_back(std::pair(ivec2(160, 131), static_cast('g'))); + LineChars.push_back(std::pair(ivec2(192, 131), static_cast('h'))); + LineChars.push_back(std::pair(ivec2(224, 131), static_cast('j'))); + LineChars.push_back(std::pair(ivec2(256, 131), static_cast('k'))); + LineChars.push_back(std::pair(ivec2(288, 131), static_cast('l'))); + + + LineChars.push_back(std::pair(ivec2(62, 78), static_cast('z'))); + LineChars.push_back(std::pair(ivec2(94, 78), static_cast('x'))); + LineChars.push_back(std::pair(ivec2(126, 78), static_cast('c'))); + LineChars.push_back(std::pair(ivec2(158, 78), static_cast('v'))); + LineChars.push_back(std::pair(ivec2(190, 78), static_cast('b'))); + LineChars.push_back(std::pair(ivec2(222, 78), static_cast('n'))); + LineChars.push_back(std::pair(ivec2(254, 78), static_cast('m'))); + + + + VisualKeyArr.clear(); + + BOOST_FOREACH(auto& linePair, LineChars) + { + std::tuple line_tuple = std::tuple(TVisualKey(linePair.first, ivec2(26, 38)), linePair.second, linePair.second); + + VisualKeyArr.push_back(line_tuple); + } + + //Backspace + std::tuple backspace_tuple = std::tuple(TVisualKey(ivec2(299, 77), ivec2(36, 38)), 8, 8); + + VisualKeyArr.push_back(backspace_tuple); + + //Space + std::tuple space_tuple = std::tuple(TVisualKey(ivec2(160, 23), ivec2(154, 38)), static_cast(' '), static_cast(' ')); + + VisualKeyArr.push_back(space_tuple); + + + LeftBottomPos = vec2(0,0); + + TRenderParams renderParams; + + renderParams.SamplerMap[CONST_STRING_TEXTURE_UNIFORM] = "keyboard.png"; + + TTriangleList triangleList = MakeTriangleList(vec2(0,0), vec2(320.f, 216.f)); + + triangleList.RefreshBuffer(); + + TriangleListVector.push_back(TRenderPair(renderParams, triangleList)); + + //Button width and height = 26, 38 + //Button half-width and half-height = 13, 19 + + //Upper line: + //3, 204 q + //35, 204 w + //67, 204 e + //99, 204 r + //131, 204 t + //163, 204 y + //195, 204 u + //227, 204 i + //259, 204 o + //291, 204 p + + + //Middle line: + //19, 150 a + //51, 150 s + //83, 150 d + //115, 150, f + //147, 150, g + //179, 150, h + //211, 150, j + //243, 150, k + //275, 150, l + + //Lower line + //49, 97 z + //81, 97 x + //113, 97 c + //145, 97 v + //177, 97 b + //209, 97 n + //241, 97 m + + //All keyboard w=320 h=216 + //return w=74 h = 38 pos = 280 23 + //shift w=36 h = 38 pos = 21 77 + + //backspace w=36 h = 38 pos = 299 77 + + //x=83 y=174 w=154 h =38 + + //space w = 154 h = 38 x = 160 y = 23 + + //numbers x=20 y=23 w= 34 h=38 + + //lang x=26 y=23 w= 34 h=38 + + + + + } + + bool TKeyboardWidget::CheckClick(vec2 mousePos) + { + return (mousePos.v[0] >= 0.f && mousePos.v[1] >= 0.f && mousePos.v[0] <= 320.f && mousePos.v[1] <= 216.f); + } + + void TKeyboardWidget::OnTapDown(vec2 pos) + { + } + + void TKeyboardWidget::OnTapUp(vec2 pos) + { + BOOST_FOREACH(auto& visualKeyElement, VisualKeyArr) + { + if (std::get<0>(visualKeyElement).CheckClicked(ivec2(pos.v[0], pos.v[1]))) + { + ResourceManager->GUIManager.KeyPressedSignal(std::get<1>(visualKeyElement)); + } + } + } + + +} \ No newline at end of file