text: #include "SSVPCH.h"
  
  #include "SyntaxTreeView.h"
  
  #include "SyntaxVisualizer.h"
  
  #include "Client/Core/FileSystem.h"
  #include "Client/Core/Application.h"
  
  #include "Client/UI/TextLabel.h"
  
  namespace SSV::Client::Visualizer
  {
  	SyntaxTreeView::SyntaxTreeView(const std::string& name, const int32_t zIndex)
  		: UI::View(name, zIndex)
  	{
  		// Test data
  		// 
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[TP [NP [N' [N John]]] [T' [T PAST] [VP [V' [V expect] [CP [C' [C (X)] [TP [NP John's brother] [T' [T to] [VP [V' [V come]]]]]]]]]]]");
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[CP [C' [C (x)] [TP [NP [N' [N John]]] [T' [T PRES.] [VP [V' [V be] [NP [DET a] [N' [N student]]]]]]]]]");
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[TP [NP [N' [N John]]] [T' [T Past] [VP [V' [V expect] [CP [C' [C (X)] [TP [NP [DET the] [N' [N student] [PP [P' [P of] [NP [N' [N physics]]]]]]] [T' [T to] [VP [V' [V come]]]]]]]]]]]");
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[NP [N' [N John's mother]]]");
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[TP [NP [DET the] [N' [N student] [PP [P' [P of] [NP [N' [N physics]]]]]]] [T' [T to] [VP [V' [V come]]]]]");
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[TP [NP [N Mary]] [T' [T PRES] [VP [V' [V hit] [NP [DET the] [N' [N student] [PP [P' [P of] [NP [N' [N physics]]]]]]]]]]]");
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[TP [NP [N' [N John]]] [T' [T PAST] [VP [V' [V gave] [NP [N' [N her]]] [NP [DET a] [N' [N book]]]]]]]");
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[VP [V' [V play] [NP [DET an ] [N' [AdjP [Adj' [Adj important]]] [NP [N' [N role]]]]]]]");
  		// SVOO //m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[TP [NP [N' [N Mary]]] [T' [T PAST] [VP [V' [V play] [NP [DET the] [N' [N THIS S]]]]]]]");
  		//m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[TP [NP [N' [N Mary]]] [T' [T PRES.] [VP plays the piano every weekend]]]");
  		// Pretty long input //m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(L"[CP [C' [C (X)] [TP [NP [DET the] [N' [N' [AdjP [AdvP [Adv' [Adv very]]] [Adj' [Adj tall]]] [N' [N' [N student] [PP [P' [P of] [N' [N physics]]]]]]] [PP [P' [P with] [NP long blonde hair]]  ]]] [T' [T [NP [DET the] [N' [N' [AdjP [AdvP [Adv' [Adv very]]] [Adj' [Adj tall]]] [N' [N' [N student] [PP [P' [P of] [N' [N physics]]]]]]] [PP [P' [P with] [NP long blonde hair]]  ]]]] [VP [V' [V come] [CP [C' [C (X)] [TP [NP [N' [N John]]] [T' [T PAST] [VP [V' [V gave] [NP [N' [N her]]] [NP [DET a] [N' [N book]]]]]]]]]]]] [C' [C (X)] [TP [NP John's mother] [T' [T PRES.] [VP [V' [V expect] [CP [C' [C that] [TP [NP [N' [N John]]] [T' [T Past] [VP [V' [V expect] [CP [C' [C (X)] [TP [NP [DET the] [N' [AdjP [Adj' [Adj tall]]] [N' [N' [N student] [PP [P' [P of] [N' [N physics]]]]]] [PP [P' [P with] [NP long blonde hair] ]  ]]] [T' [T to] [VP [V' [V come] [CP [C' [C (X)] [TP [NP [N' [N John]]] [T' [T PAST] [VP [V' [V gave] [NP [N' [N her]]] [NP [DET a] [N' [N book]]]]]]]]]]]]]]]]]]]]]]]]]]]]]");
  	}
  
  	void SyntaxTreeView::CreateWidgets()
  	{
  		m_SyntaxVisualizer = CreateWidget<SyntaxVisualizer>("SyntaxVisualizer", 0);
  		m_SyntaxVisualizer->m_View = this;
  
  		m_VisualizerScaleIndicator = CreateWidget<UI::TextLabel>("VisualizerScaleIndicator", 1, L"Scale: 100%", L"UI-Regular", 12.f);
  		m_VisualizerScaleIndicator->AllowRespondingToHit(false);
  		m_VisualizerScaleIndicator->SetEnabled(false);
  
  		m_SyntaxVisualizer->SetOnScaleChangedDelegate([&](const float newVisualizerScale)
  			{
  				m_VisualizerScaleIndicator->SetEnabled(true);
  				m_VisualizerScaleIndicator->SetText(L"Scale: " + std::to_wstring(static_cast<int32_t>(std::floor(newVisualizerScale * 100.f))) + L"%", L"UI-Regular", 12.f);
  
  				Core::Application::GetInstance().CreateTimer(20, 5000, [&]()
  					{
  						m_VisualizerScaleIndicator->SetEnabled(false);
  						Core::Application::GetInstance().Render();
  					});
  			});
  	}
  
  	void SyntaxTreeView::CalculateWidgetLayout(const D2D1_POINT_2L newViewLocation, const D2D1_SIZE_U newViewSize)
  	{
  		m_SyntaxVisualizer->SetLocation({ 0, 0 });
  		m_SyntaxVisualizer->SetSize(newViewSize);
  
  		m_VisualizerScaleIndicator->SetLocation({ 60, static_cast<long>(newViewSize.height) - 150});
  		m_VisualizerScaleIndicator->SetSize({ 100, 100 });
  	}
  
  	void SyntaxTreeView::OnMouseLButtonDownOnView(const UI::Widget* hitWidget)
  	{
  		Core::Application::GetInstance().GetViewManager().SetKeyboardFocus(nullptr);
  
  		MarkViewAsDirty();
  	}
  	
  	void SyntaxTreeView::UpdateSourceSentence(const std::wstring& sentence)
  	{
  		m_SourceSyntaxTree = m_SyntaxParser.ParseAndConstruct(sentence);
  	}
  
  	
  }