コード例 #1
0
ファイル: FunctionWidget.cpp プロジェクト: hoffoo/Conception
void FunctionWidget::Render()
{
    Color BackgroundColor(1.0, 1.0, 1.0);
    Color BorderColor(0.3, 0.3, 0.3);

    /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager))
    {
    }
    else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager)))
    {
    	BorderColor[0] = 0.898;
    	BorderColor[1] = 0.765;
    	BorderColor[2] = 0.396;
    }
    else
    {
    }*/
    //if (CheckHover())
    // HACK
    if (HasTypingFocus())
    {
        BorderColor[0] = 0.898;
        BorderColor[1] = 0.765;
        BorderColor[2] = 0.396;
    }

    DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor);

    glColor3d(0, 0, 0);
    OglUtilsPrint(GetPosition().X(), GetPosition().Y() - lineHeight, 0, LEFT, "Global Function");

    OpenGLStream OpenGLStream(GetPosition());
    OpenGLStream << m_Function;
}
コード例 #2
0
void ConceptStringBoxWidget::UpdateGestureRecognizer()
{
	//ModifyGestureRecognizer().m_RecognizeTap = true;

	// HACK: Recognize only taps when unselected; but this needs to be automated
	ModifyGestureRecognizer().m_RecognizeTap = !HasTypingFocus();
}
コード例 #3
0
ファイル: ListWidget.hpp プロジェクト: prinsmike/Conception
template <typename T> void ListWidget<T>::ProcessManipulationUpdated(const PointerState & PointerState)
{
	if (!HasTypingFocus())
	{
		auto ParentLocalPosition = GlobalToParent(Vector2n(PointerState.GetAxisState(0).GetPosition(), PointerState.GetAxisState(1).GetPosition()));
		
		ModifyPosition() = GetGestureRecognizer().m_ManipulationOffset + ParentLocalPosition;
	}
}
コード例 #4
0
void TextFieldWidget::ProcessManipulationStarted(const PointerState & PointerState)
{
	if (!HasTypingFocus())
	{
		auto ParentLocalPosition = GlobalToParent(Vector2n(PointerState.GetAxisState(0).GetPosition(), PointerState.GetAxisState(1).GetPosition()));

		ModifyGestureRecognizer().m_ManipulationOffset = GetPosition() - ParentLocalPosition;
	}
}
コード例 #5
0
void ConceptStringBoxWidget::Render()
{
	Color BackgroundColor(1.0, 1.0, 1.0);
	Color BorderColor(0.3, 0.3, 0.3);

	/*if (CheckHover(WidgetManager) && CheckActive(WidgetManager))
	{
	}
	else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager)))
	{
		BorderColor[0] = 0.898;
		BorderColor[1] = 0.765;
		BorderColor[2] = 0.396;
	}
	else
	{
	}*/
	//if (CheckHover())
	// HACK
	if (HasTypingFocus())
	{
		BorderColor[0] = 0.898;
		BorderColor[1] = 0.765;
		BorderColor[2] = 0.396;
	}

	/*glBegin(GL_QUADS);
		glVertex2d(m_Position.X(), m_Position.Y());
		glVertex2d(m_Position.X(), m_Position.Y() + 30);
		glVertex2d(m_Position.X() + 30, m_Position.Y() + 30);
		glVertex2d(m_Position.X() + 30, m_Position.Y());
	glEnd();*/
	DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor);

	glColor3d(0, 0, 0);
	OpenGLStream OpenGLStream(GetPosition());
	//OpenGLStream << m_Content.substr(0, m_CaretPosition);
	// TODO: Optimize this somehow?
	OpenGLStream << decltype(m_Content)(m_Content.begin(), m_Content.begin() + m_CaretPosition);

	// TEST
	if (!m_TypingModule.GetString().empty())
	{
		for (auto & Pointer : GetGestureRecognizer().GetConnected())
		{
			if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory())
			{
				//Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition());
				//Vector2n LocalPosition(GlobalToLocal(GlobalPosition));

				//auto ConceptId = FindOrCreateConcept(Entry);

				OpenGLStream << m_TypingModule.GetString();
			}
		}
	}

	Vector2n CaretPosition = OpenGLStream.GetCaretPosition();

	//OpenGLStream << m_Content.substr(m_CaretPosition);
	// TODO: Optimize this somehow?
	OpenGLStream << decltype(m_Content)(m_Content.begin() + m_CaretPosition, m_Content.end());

	//if (CheckHover())
	// HACK
	if (HasTypingFocus())
	{
		// Draw caret
		//if (static_cast<int>(glfwGetTime() * 2) % 2)
		{
			glPushMatrix();
			glTranslated(CaretPosition.X(), CaretPosition.Y(), 0);
			glColor3d(0, 0, 0);
			glBegin(GL_QUADS);
				glVertex2d(-1, 0);
				glVertex2d(-1, lineHeight);
				glVertex2d(+1, lineHeight);
				glVertex2d(+1, 0);
			glEnd();
			glPopMatrix();
		}
	}
}
コード例 #6
0
void ConceptStringBoxWidget::ProcessEvent(InputEvent & InputEvent)
{
	if (InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT))
	{
		auto ButtonId = InputEvent.m_InputId;
		bool Pressed = InputEvent.m_Buttons[0];		// TODO: Check if there are >1 buttons

		if (Pointer::VirtualCategory::TYPING == InputEvent.m_Pointer->GetVirtualCategory())
		{
			if (Pressed)
			{
				bool HandledEvent = true;		// Assume true at first

				switch (ButtonId)
				{
				case GLFW_KEY_BACKSPACE:
					/*{
						// Erase the last concept
						if (false == m_Content.empty())
						{
							m_Content.pop_back();
						}

						InputEvent.m_Handled = true;
					}*/
					break;
				case GLFW_KEY_ENTER:
					{
					}
					break;
				case GLFW_KEY_TAB:
					{
					}
					break;
				case GLFW_KEY_LEFT:
					{
						MoveCaretTry(-1, true);
					}
					break;
				case GLFW_KEY_RIGHT:
					{
						MoveCaretTry(+1, true);
					}
					break;
				default:
					HandledEvent = false;
					break;
				}

				if (HandledEvent)
				{
					InputEvent.m_Handled = true;
				}
			}
		}
		else if (Pointer::VirtualCategory::POINTING == InputEvent.m_Pointer->GetVirtualCategory())
		{
			if (HasTypingFocus())
			{
				if (Pressed)
				{
					bool HandledEvent = true;		// Assume true at first

					switch (ButtonId)
					{
					case 0:
						{
							auto Entry = m_TypingModule.TakeString();

							if (!Entry.empty())
							{
								auto ConceptId = FindOrCreateConcept(Entry);

								m_Content.push_back(ConceptId);
							}
							else
							{
								if (!m_Content.empty())
								{
									if (m_CaretPosition >= m_Content.size())
									{
										MoveCaretTry(-1, true);
									}

									m_TypingModule.SetString(GetConcept(m_Content.back()).GetContent());
									m_Content.pop_back();
								}
							}
						}
						break;
					default:
						HandledEvent = false;
						break;
					}

					if (HandledEvent)
					{
						InputEvent.m_Handled = true;
					}
				}
			}
		}
	}
}
コード例 #7
0
ファイル: MenuWidget.hpp プロジェクト: shurcooL/Conception
template <typename T> void MenuWidget<T>::Render()
{
    Color BackgroundColor(1.0, 1.0, 1.0);
    Color BorderColor(0.3, 0.3, 0.3);

    /*if (CheckHover(WidgetManager) && CheckActive(WidgetManager))
    {
    }
    else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager)))
    {
    	BorderColor[0] = 0.898;
    	BorderColor[1] = 0.765;
    	BorderColor[2] = 0.396;
    }
    else
    {
    }*/
    // HACK, TODO: Make this a single DRY const
    if (HasTypingFocus())
    {
        BorderColor[0] = 0.898;
        BorderColor[1] = 0.765;
        BorderColor[2] = 0.396;
    }

    // TODO: Think if I should outsource the entire rendering code for more generality
    // Draw list
    {
        UpdateDimensions();		// LATER: Optimize by not repeating this calculation each time, only when something changes?

        if (m_Entries.empty())
        {
            BackgroundColor[0] = 234 / 255.0;
            BackgroundColor[1] = 233 / 255.0;
            BackgroundColor[2] = 190 / 255.0;
        }

        DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor);

        // TEST
        auto Spot = m_Entries.end();
        if (   nullptr != m_TypingModule
                && !m_TypingModule->GetString().empty())
        {
            for (auto & Pointer : GetGestureRecognizer().GetConnected())
            {
                if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory())
                {
                    Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition());
                    Vector2n LocalPosition(GlobalToLocal(GlobalPosition));

                    Spot = m_Entries.begin() + (LocalPosition.Y() / lineHeight);
                }
            }
        }

        OpenGLStream OpenGLStream(GetPosition());
        //for (auto & Entry : m_Entries)
        for (auto Entry = m_Entries.begin(); m_Entries.end() != Entry; ++Entry)
        {
            if (Entry == Spot)
                OpenGLStream << endl;

            if (Entry - m_Entries.begin() == m_SelectedEntryId)
            {
                if (HasTypingFocus())
                    DrawBox(GetPosition() + Vector2n(0, static_cast<sint32>((Entry - m_Entries.begin() + (Entry >= Spot)) * lineHeight)), Vector2n(GetDimensions().X(), lineHeight), m_SelectedColor, m_SelectedColor);
                else
                    DrawBox(GetPosition() + Vector2n(0, static_cast<sint32>((Entry - m_Entries.begin() + (Entry >= Spot)) * lineHeight)), Vector2n(GetDimensions().X(), lineHeight), m_UnfocusedSelectedColor, m_UnfocusedSelectedColor);
            }

            OpenGLStream << *Entry << endl;
        }
    }
}
コード例 #8
0
ファイル: MenuWidget.hpp プロジェクト: shurcooL/Conception
template <typename T> void MenuWidget<T>::ProcessEvent(InputEvent & InputEvent)
{
    if (InputEvent.HasType(InputEvent::EventType::BUTTON_EVENT))
    {
        auto ButtonId = InputEvent.m_InputId;
        bool Pressed = InputEvent.m_Buttons[0];		// TODO: Check if there are >1 buttons

        if (Pointer::VirtualCategory::TYPING == InputEvent.m_Pointer->GetVirtualCategory())
        {
            if (Pressed)
            {
                const auto ControlActive = (   InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LCTRL)
                                               || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RCTRL));
                const auto ShiftActive = (   InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LSHIFT)
                                             || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RSHIFT));
                const auto SuperActive = (   InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LSUPER)
                                             || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RSUPER));
                const auto AltActive = (   InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_LALT)
                                           || InputEvent.m_Pointer->GetPointerState().GetButtonState(GLFW_KEY_RALT));

                bool HandledEvent = true;		// Assume true at first

                switch (ButtonId)
                {
                case GLFW_KEY_UP:
                {
                    if (!SuperActive) {
                        if (m_SelectedEntryId > 0)
                            SetSelectedEntryId(m_SelectedEntryId - 1);
                    } else {
                        SetSelectedEntryId(0);
                    }
                }
                break;
                case GLFW_KEY_DOWN:
                {
                    if (!SuperActive) {
                        if (m_SelectedEntryId < m_Entries.size() - 1)
                            SetSelectedEntryId(m_SelectedEntryId + 1);
                    } else {
                        SetSelectedEntryId(m_Entries.size() - 1);
                    }
                }
                break;
                default:
                    HandledEvent = false;
                    break;
                }

                if (HandledEvent)
                {
                    InputEvent.m_Handled = true;
                }
            }
        }
    }

    if (HasTypingFocus())
    {
        if (   InputEvent.HasType(InputEvent::EventType::AXIS_EVENT)
                || InputEvent.HasType(InputEvent::EventType::CANVAS_MOVED_TEST))
        {
            if (Pointer::VirtualCategory::POINTING == InputEvent.m_Pointer->GetVirtualCategory())
            {
                if (true == InputEvent.m_Pointer->GetPointerState().GetButtonState(0))
                {
                    if (!(   nullptr != m_TypingModule
                             && !m_TypingModule->GetString().empty()))
                    {
                        Vector2n GlobalPosition(InputEvent.m_Pointer->GetPointerState().GetAxisState(0).GetPosition(), InputEvent.m_Pointer->GetPointerState().GetAxisState(1).GetPosition());
                        Vector2n LocalPosition = GlobalToLocal(GlobalPosition);

                        SetSelectedEntryId(LocalPosition);
                    }
                }
            }
        }
    }
}
コード例 #9
0
void TextFieldWidget::Render()
{
	//Color BackgroundColor(1.0, 1.0, 1.0);
	Color BackgroundColor = m_BackgroundColor;
	Color BorderColor(0.3, 0.3, 0.3);

	/*if (CheckHover(WidgetManager) && CheckActive(WidgetManager))
	{
	}
	else if ((CheckHover(WidgetManager) && !CheckAnyActive(WidgetManager)) || (!CheckHover(WidgetManager) && CheckActive(WidgetManager)))
	{
		BorderColor[0] = 0.898;
		BorderColor[1] = 0.765;
		BorderColor[2] = 0.396;
	}
	else
	{
	}*/
	//if (CheckHover())
	// HACK
	if (HasTypingFocus())
	{
		BorderColor[0] = 0.898;
		BorderColor[1] = 0.765;
		BorderColor[2] = 0.396;
	}

	/*glBegin(GL_QUADS);
		glVertex2d(m_Position.X(), m_Position.Y());
		glVertex2d(m_Position.X(), m_Position.Y() + 30);
		glVertex2d(m_Position.X() + 30, m_Position.Y() + 30);
		glVertex2d(m_Position.X() + 30, m_Position.Y());
	glEnd();*/
	DrawAroundBox(GetPosition(), GetDimensions(), BackgroundColor, BorderColor);

	// TEST
	auto ContentWithInsertion = m_Content;
	if (!m_TypingModule.GetString().empty())
	{
		for (auto & Pointer : GetGestureRecognizer().GetConnected())
		{
			if (Pointer::VirtualCategory::POINTING == Pointer->GetVirtualCategory())
			{
				Vector2n GlobalPosition(Pointer->GetPointerState().GetAxisState(0).GetPosition(), Pointer->GetPointerState().GetAxisState(1).GetPosition());
				Vector2n LocalPosition(GlobalToLocal(GlobalPosition));
				LocalPosition = m_TypingModule.GetInsertionPosition(LocalPosition);

				auto InsertionPosition = GetNearestCaretPosition(LocalPosition);
				ContentWithInsertion.insert(InsertionPosition, m_TypingModule.GetString());
			}
		}
	}

	glColor3d(0, 0, 0);
	OpenGLStream OpenGLStream(GetPosition());
	OpenGLStream << ContentWithInsertion.substr(0, std::min(m_CaretPosition, m_SelectionPosition));

	Vector2n CaretPosition;

	// Remember caret position at selection front
	if (std::min(m_CaretPosition, m_SelectionPosition) == m_CaretPosition)
	{
		CaretPosition = OpenGLStream.GetCaretPosition();
	}

	// Draw selected text as highlighted
	if (HasTypingFocus())
	{
		OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(195), 212, 242));
	}
	else
	{
		OpenGLStream.SetBackgroundColor(Color(static_cast<uint8>(212), 212, 212));
	}
	auto SelectionLength = std::max(m_CaretPosition, m_SelectionPosition) - std::min(m_CaretPosition, m_SelectionPosition);
	OpenGLStream << ContentWithInsertion.substr(std::min(m_CaretPosition, m_SelectionPosition), SelectionLength);
	OpenGLStream.SetBackgroundColor(Color(1.0, 1.0, 1.0));

	// Remember caret position at selection back
	if (std::max(m_CaretPosition, m_SelectionPosition) == m_CaretPosition)
	{
		CaretPosition = OpenGLStream.GetCaretPosition();
	}

	OpenGLStream << ContentWithInsertion.substr(std::max(m_CaretPosition, m_SelectionPosition));

	//if (CheckHover())
	// HACK
	if (HasTypingFocus())
	{
		// Draw caret
		//if (static_cast<int>(glfwGetTime() * 2) % 2)
		{
			glPushMatrix();
			glTranslated(CaretPosition.X(), CaretPosition.Y(), 0);
			glColor3d(0, 0, 0);
			glBegin(GL_QUADS);
				glVertex2d(-1, 0);
				glVertex2d(-1, lineHeight);
				glVertex2d(+1, lineHeight);
				glVertex2d(+1, 0);
			glEnd();
			glPopMatrix();
		}
	}
}