Exemplo n.º 1
0
void TBEditField::OnMessageReceived(TBMessage *msg)
{
	if (msg->message == TBIDC("blink"))
	{
		m_style_edit.caret.on = !m_style_edit.caret.on;
		m_style_edit.caret.Invalidate();

		// Post another blink message so we blink again.
		PostMessageDelayed(TBIDC("blink"), nullptr, CARET_BLINK_TIME);
	}
	else if (msg->message == TBIDC("selscroll") && captured_widget == this)
	{
		// Get scroll speed from where mouse is relative to the padding rect.
		TBRect padding_rect = GetVisibleRect().Shrink(2, 2);
		int dx = GetSelectionScrollSpeed(pointer_move_widget_x, padding_rect.x, padding_rect.x + padding_rect.w);
		int dy = GetSelectionScrollSpeed(pointer_move_widget_y, padding_rect.y, padding_rect.y + padding_rect.h);
		m_scrollbar_x.SetValue(m_scrollbar_x.GetValue() + dx);
		m_scrollbar_y.SetValue(m_scrollbar_y.GetValue() + dy);

		// Handle mouse move at the new scroll position, so selection is updated
		if (dx || dy)
			m_style_edit.MouseMove(TBPoint(pointer_move_widget_x, pointer_move_widget_y));

		// Post another setscroll message so we continue scrolling if we still should.
		if (m_style_edit.select_state)
			PostMessageDelayed(TBIDC("selscroll"), nullptr, SELECTION_SCROLL_DELAY);
	}
}
bool SceneView3D::MouseInView()
{
    Input* input = GetSubsystem<Input>();
    IntVector2 pos = input->GetMousePosition();

    TBRect rect = GetWidgetDelegate()->GetRect();
    GetWidgetDelegate()->ConvertToRoot(rect.x, rect.y);

    return rect.Contains(TBPoint(pos.x_, pos.y_));

}
Exemplo n.º 3
0
    // TBWidgetListener
    virtual bool OnWidgetInvokeEvent(TBWidget *widget, const TBWidgetEvent &ev)
    {
        // Skip these events for now
        if (ev.IsPointerEvent())
            return false;

        // Always ignore activity in this window (or we might get endless recursion)
        if (TBWindow *window = widget->GetParentWindow())
            if (TBSafeCast<DebugSettingsWindow>(window))
                return false;

        TBTempBuffer buf;
        buf.AppendString(GetEventTypeStr(ev.type));
        buf.AppendString(" (");
        buf.AppendString(widget->GetClassName());
        buf.AppendString(")");

        buf.AppendString(" id: ");
        buf.AppendString(GetIDString(ev.target->GetID()));

        if (ev.ref_id)
        {
            buf.AppendString(", ref_id: ");
            buf.AppendString(GetIDString(ev.ref_id));
        }

        if (ev.type == EVENT_TYPE_CHANGED)
        {
            TBStr extra, text;
            if (ev.target->GetText(text) && text.Length() > 24)
                sprintf(text.CStr() + 20, "...");
            extra.SetFormatted(", value: %.2f (\"%s\")", ev.target->GetValueDouble(), text.CStr());
            buf.AppendString(extra);
        }
        buf.AppendString("\n");

        // Append the line to the output textfield
        TBStyleEdit *se = output->GetStyleEdit();
        se->selection.SelectNothing();
        se->AppendText(buf.GetData(), TB_ALL_TO_TERMINATION, true);
        se->ScrollIfNeeded(false, true);

        // Remove lines from the top if we exceed the height limit.
        const int height_limit = 2000;
        int current_height = se->GetContentHeight();
        if (current_height > height_limit)
        {
            se->caret.Place(TBPoint(0, current_height - height_limit));
            se->selection.SelectToCaret(se->blocks.GetFirst(), 0);
            se->Delete();
        }
        return false;
    }
Exemplo n.º 4
0
bool ResourceEditWindow::OnEvent(const TBWidgetEvent &ev)
{
	if (ev.type == EVENT_TYPE_CHANGED && ev.target->GetID() == TBIDC("widget_list_search"))
	{
		m_widget_list->SetFilter(ev.target->GetText());
		return true;
	}
	else if (ev.type == EVENT_TYPE_CHANGED && ev.target == m_widget_list)
	{
		if (m_widget_list->GetValue() >= 0 && m_widget_list->GetValue() < m_widget_list_source.GetNumItems())
			if (ResourceItem *item = m_widget_list_source.GetItem(m_widget_list->GetValue()))
				SetSelectedWidget(item->GetWidget());
	}
	else if (ev.type == EVENT_TYPE_CHANGED && ev.target == m_source_edit)
	{
		RefreshFromSource();
		return true;
	}
	else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("test"))
	{
		// Create a window containing the current layout, resize and center it.
		if (TBWindow *win = new TBWindow())
		{
			win->SetText("Test window");
			g_widgets_reader->LoadData(win->GetContentRoot(), m_source_edit->GetText());
			win->ResizeToFitContent();
			win->SetPosition(TBPoint((GetParent()->GetRect().w - win->GetRect().w) / 2,
									(GetParent()->GetRect().h - win->GetRect().h) / 2));
			GetParent()->AddChild(win);
		}
		return true;
	}
	else if (ev.target->GetID() == TBIDC("constrained"))
	{
		m_scroll_container->SetAdaptContentSize(ev.target->GetValue() ? true : false);
	}
	return TBWindow::OnEvent(ev);
}
Exemplo n.º 5
0
bool TBEditField::OnEvent(const TBWidgetEvent &ev)
{
	if (ev.type == EVENT_TYPE_CHANGED && ev.target == &m_scrollbar_x)
	{
		m_style_edit.SetScrollPos(m_scrollbar_x.GetValue(), m_style_edit.scroll_y);
		OnScroll(m_scrollbar_x.GetValue(), m_style_edit.scroll_y);
		return true;
	}
	else if (ev.type == EVENT_TYPE_CHANGED && ev.target == &m_scrollbar_y)
	{
		m_style_edit.SetScrollPos(m_style_edit.scroll_x, m_scrollbar_y.GetValue());
		OnScroll(m_style_edit.scroll_x, m_scrollbar_y.GetValue());
		return true;
	}
	else if (ev.type == EVENT_TYPE_WHEEL && ev.modifierkeys == TB_MODIFIER_NONE)
	{
		int old_val = m_scrollbar_y.GetValue();
		m_scrollbar_y.SetValue(old_val + ev.delta_y * TBSystem::GetPixelsPerLine());
		return m_scrollbar_y.GetValue() != old_val;
	}
	else if (ev.type == EVENT_TYPE_POINTER_DOWN && ev.target == this)
	{
		TBRect padding_rect = GetPaddingRect();
		if (m_style_edit.MouseDown(
			TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y),
			1, ev.count, TB_MODIFIER_NONE, ev.touch))
		{
			// Post a message to start selection scroll
			PostMessageDelayed(TBIDC("selscroll"), nullptr, SELECTION_SCROLL_DELAY);
			return true;
		}
	}
	else if (ev.type == EVENT_TYPE_POINTER_MOVE && ev.target == this)
	{
		TBRect padding_rect = GetPaddingRect();
		return m_style_edit.MouseMove(TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y));
	}
	else if (ev.type == EVENT_TYPE_POINTER_UP && ev.target == this)
	{
		TBRect padding_rect = GetPaddingRect();
		return m_style_edit.MouseUp(TBPoint(ev.target_x - padding_rect.x, ev.target_y - padding_rect.y),
										1, TB_MODIFIER_NONE, ev.touch);
	}
	else if (ev.type == EVENT_TYPE_KEY_DOWN)
	{
		return m_style_edit.KeyDown(ev.key, ev.special_key, ev.modifierkeys);
	}
	else if (ev.type == EVENT_TYPE_KEY_UP)
	{
		return true;
	}
	else if ((ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("popupmenu")) ||
			(ev.type == EVENT_TYPE_SHORTCUT))
	{
		if (ev.ref_id == TBIDC("cut") && !m_style_edit.packed.read_only)
			m_style_edit.Cut();
		else if (ev.ref_id == TBIDC("copy"))
			m_style_edit.Copy();
		else if (ev.ref_id == TBIDC("paste") && !m_style_edit.packed.read_only)
			m_style_edit.Paste();
		else if (ev.ref_id == TBIDC("delete") && !m_style_edit.packed.read_only)
			m_style_edit.Delete();
		else if (ev.ref_id == TBIDC("undo") && !m_style_edit.packed.read_only)
			m_style_edit.Undo();
		else if (ev.ref_id == TBIDC("redo") && !m_style_edit.packed.read_only)
			m_style_edit.Redo();
		else if (ev.ref_id == TBIDC("selectall"))
			m_style_edit.selection.SelectAll();
		else
			return false;
		return true;
	}
	else if (ev.type == EVENT_TYPE_CONTEXT_MENU && ev.target == this)
	{
		TBPoint pos_in_root(ev.target_x, ev.target_y);
		ev.target->ConvertToRoot(pos_in_root.x, pos_in_root.y);

		if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("popupmenu")))
		{
			TBGenericStringItemSource *source = menu->GetList()->GetDefaultSource();
			source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("cut")), TBIDC("cut")));
			source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("copy")), TBIDC("copy")));
			source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("paste")), TBIDC("paste")));
			source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("delete")), TBIDC("delete")));
			source->AddItem(new TBGenericStringItem("-"));
			source->AddItem(new TBGenericStringItem(g_tb_lng->GetString(TBIDC("selectall")), TBIDC("selectall")));
			menu->Show(source, TBPopupAlignment(pos_in_root), -1);
		}
		return true;
	}
	return false;
}