bool ResourceEditWindow::OnWidgetInvokeEvent(TBWidget *widget, const TBWidgetEvent &ev)
{
	// Intercept all events to widgets in the build container
	if (m_build_container->IsAncestorOf(ev.target))
	{
		// Let events through if alt is pressed so we can test some
		// functionality right in the editor (like toggle hidden UI).
		if (ev.modifierkeys & TB_ALT)
			return false;

		// Select widget when clicking
		if (ev.type == EVENT_TYPE_POINTER_DOWN)
			SetSelectedWidget(ev.target);
		return true;
	}
	return false;
}
Esempio n. 2
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());
			TBRect bounds(0, 0, GetParent()->GetRect().w, GetParent()->GetRect().h);
			win->SetRect(win->GetResizeToFitContentRect().CenterIn(bounds).MoveIn(bounds).Clip(bounds));
			GetParent()->AddChild(win);
		}
		return true;
	}
	else if (ev.target->GetID() == TBIDC("constrained"))
	{
		m_scroll_container->SetAdaptContentSize(ev.target->GetValue() ? true : false);
		return true;
	}
	else if (ev.type == EVENT_TYPE_FILE_DROP)
	{
		return OnDropFileEvent(ev);
	}
	return TBWindow::OnEvent(ev);
}