void TBProgressSpinner::OnMessageReceived(TBMessage *msg)
{
	m_frame++;
	Invalidate();
	// Keep animation running
	PostMessageDelayed(TBID(1), nullptr, spin_speed);
}
bool IssuesWidget::OnEvent(const TBWidgetEvent &ev)
{
    if (!ev.target)
        return false;

    TBID id = ev.target->GetID();

    if (ev.type == EVENT_TYPE_CLICK)
    {
        // we clicked the folder list
        if (ev.target->GetID() == TBID("issuelist"))
        {
            AEJavascript* aejs = GetSubsystem<AEJavascript>();
            const Vector<JSError>& errors = aejs->GetJSErrors();
            TBSelectList* list = (TBSelectList*) ev.target;
            TBID tbid = list->GetSelectedItemID();

            if (tbid < errors.Size())
            {
                const JSError& error = errors[tbid];
                // make sure we are editing it
                ResourceFrame* rframe = GetSubsystem<MainFrame>()->GetResourceFrame();
                rframe->EditResource(error.fullpath);
                rframe->NavigateToResource(error.fullpath, -1, error.tokenPos);
            }

        }
    }

    return false;
}
unsigned UIListView::AddRootItem(const String& text, const String& icon, const String& id)
{
    ListViewItem* item = new ListViewItem(text.CString(), TBID(id.CString()), icon.CString(), source_);
    source_->AddItem(item);

    itemLookup_[itemLookupId_++] = item;
    return itemLookupId_ - 1;
}
void TBProgressSpinner::SetValue(int value)
{
	assert(value >= 0); // If this happens, you probably have unballanced Begin/End calls.
	m_value = value;
	if (value > 0)
	{
		// Start animation
		if (!GetMessageByID(TBID(1)))
		{
			m_frame = 0;
			PostMessageDelayed(TBID(1), nullptr, spin_speed);
		}
	}
	else
	{
		// Stop animation
		if (TBMessage *msg = GetMessageByID(TBID(1)))
			DeleteMessage(msg);
	}
}
void UISelectItemSource::RemoveItemWithId(const String& id)
{
    tb::TBID test = TBID(id.CString());
    for (List<SharedPtr<UISelectItem> >::Iterator itr = items_.Begin(); itr != items_.End(); itr++)
    {
        if ((*itr)->GetID() == test) {
            items_.Erase(itr);
            break;
        }
    }
}
unsigned UIListView::AddChildItem(unsigned parentItemID, const String& text, const String& icon, const String& id)
{
    if (!itemLookup_.Contains(parentItemID))
        return -1;

    ListViewItem* item = itemLookup_[parentItemID];

    ListViewItem* child = item->AddChild(text.CString(), icon.CString(), TBID(id.CString()));

    itemLookup_[itemLookupId_++] = child;       

    return itemLookupId_ - 1;

}
 bool RequestClose()
 {
     if (editor_->HasUnsavedModifications())
     {
         TBMessageWindow *msg_win = new TBMessageWindow(this, TBIDC("unsaved_modifications_dialog"));
         TBMessageWindowSettings settings(TB_MSG_NONE, TBID(uint32(0)));
         settings.dimmer = true;
         settings.styling = true;
         String windowString = Atomic::ToString("%s has unsaved modifications.\nDo you wish to discard them and close?", GetFileNameAndExtension(editor_->GetFullPath()).CString());
         msg_win->Show("Unsaved Modifications",  windowString.CString(), &settings, 640, 360);
         msg_win->AddButtonLeft("dont_save", false);
         msg_win->AddButton("TBMessageWindow.cancel", false);
         msg_win->AddButton("save", true);
         return false;
     }
     else
     {
         editor_->Close(container_->GetNumPages()>1);
         return true;
     }
 }
void IssuesWidget::UpdateIssues()
{
    AEJavascript* aejs = GetSubsystem<AEJavascript>();
    const Vector<JSError>& errors = aejs->GetJSErrors();

    issueList_->DeleteAllItems();

    for (unsigned i = 0; i < errors.Size(); i++)
    {
        const JSError& error = errors[i];

        String errorString;
        String filename = GetFileNameAndExtension(error.fullpath);

        errorString.AppendWithFormat("%s - %s - Line: %i Column: %i",
                                     filename.CString(), error.message.CString(), error.line, error.column);

        issueList_->AddItem(errorString.CString(), NULL, TBID(i));
    }

}
bool TBWidgetSkinConditionContext::GetCondition(TBWidget *widget, const TBSkinCondition::CONDITION_INFO &info)
{
	switch (info.prop)
	{
	case TBSkinCondition::PROPERTY_SKIN:
		return widget->GetSkinBg() == info.value;
	case TBSkinCondition::PROPERTY_WINDOW_ACTIVE:
		if (TBWindow *window = widget->GetParentWindow())
			return window->IsActive();
		return false;
	case TBSkinCondition::PROPERTY_AXIS:
		return TBID(widget->GetAxis() == AXIS_X ? "x" : "y") == info.value;
	case TBSkinCondition::PROPERTY_ALIGN:
		if (TBTabContainer *tc = TBSafeCast<TBTabContainer>(widget))
		{
			TBID widget_align;
			if (tc->GetAlignment() == TB_ALIGN_LEFT)				widget_align = TBIDC("left");
			else if (tc->GetAlignment() == TB_ALIGN_TOP)			widget_align = TBIDC("top");
			else if (tc->GetAlignment() == TB_ALIGN_RIGHT)		widget_align = TBIDC("right");
			else if (tc->GetAlignment() == TB_ALIGN_BOTTOM)		widget_align = TBIDC("bottom");
			return widget_align == info.value;
		}
		return false;
	case TBSkinCondition::PROPERTY_ID:
		return widget->GetID() == info.value;
	case TBSkinCondition::PROPERTY_STATE:
		return !!(widget->GetAutoState() & info.value);
	case TBSkinCondition::PROPERTY_VALUE:
		return widget->GetValue() == info.value;
	case TBSkinCondition::PROPERTY_HOVER:
		return TBWidget::hovered_widget && widget->IsAncestorOf(TBWidget::hovered_widget);
	case TBSkinCondition::PROPERTY_CAPTURE:
		return TBWidget::captured_widget && widget->IsAncestorOf(TBWidget::captured_widget);
	case TBSkinCondition::PROPERTY_FOCUS:
		return TBWidget::focused_widget && widget->IsAncestorOf(TBWidget::focused_widget);
	case TBSkinCondition::PROPERTY_CUSTOM:
		return widget->GetCustomSkinCondition(info);
	}
	return false;
}
Esempio n. 10
0
bool TBLanguage::Load(const char *filename)
{
	// Read the file into a node tree (even though it's only a flat list)
	TBNode node;
	if (!node.ReadFile(filename))
		return false;

	// Go through all nodes and add to the strings hash table
	TBNode *n = node.GetFirstChild();
	while (n)
	{
		const char *str = n->GetValue().GetString();
		TBStr *new_str = new TBStr(str);
		if (!new_str || !strings.Add(TBID(n->GetName()), new_str))
		{
			delete new_str;
			return false;
		}
		n = n->GetNext();
	}
	return true;
}
Esempio n. 11
0
bool MainWindow::OnEvent(const TBWidgetEvent &ev)
{
	if (ev.type == EVENT_TYPE_CLICK)
	{
		if (ev.target->GetID() == TBIDC("new"))
		{
			new MainWindow();
			return true;
		}
		if (ev.target->GetID() == TBIDC("msg"))
		{
			PostMessage(TBIDC("instantmsg"), nullptr);
			return true;
		}
		else if (ev.target->GetID() == TBIDC("busymsg"))
		{
			if (ev.target->GetValue() == 1)
			{
				// Post the first "busy" message when we check the checkbox.
				assert(!GetMessageByID(TBIDC("busy")));
				if (!GetMessageByID(TBIDC("busy")))
				{
					PostMessage(TBIDC("busy"), nullptr);
					TBMessageWindow *msg_win = new TBMessageWindow(this, TBIDC("test_dialog"));
					msg_win->Show("Message window", "The message loop is now constantly busy with messages to process.\n\n"
								"The main thread should be working hard, but input & animations should still be running smoothly.");
				}
			}
			else
			{
				// Remove any pending "busy" message when we uncheck the checkbox.
				assert(GetMessageByID(TBIDC("busy")));
				if (TBMessage *busymsg = GetMessageByID(TBIDC("busy")))
					DeleteMessage(busymsg);
			}
			return true;
		}
		else if (ev.target->GetID() == TBIDC("delayedmsg"))
		{
			PostMessageDelayed(TBIDC("delayedmsg"), nullptr, 2000);
			return true;
		}
		else if (ev.target->GetID() == TBIDC("TBWindow.close"))
		{
			// Intercept the TBWindow.close message and stop it from bubbling
			// to TBWindow (prevent the window from closing)
			TBMessageWindow *msg_win = new TBMessageWindow(this, TBIDC("confirm_close_dialog"));
			TBMessageWindowSettings settings(TB_MSG_YES_NO, TBIDC("Icon48"));
			settings.dimmer = true;
			settings.styling = true;
			msg_win->Show("Are you sure?", "Really <color #0794f8>close</color> the window?", &settings);
			return true;
		}
		else if (ev.target->GetID() == TBIDC("confirm_close_dialog"))
		{
			if (ev.ref_id == TBIDC("TBMessageWindow.yes"))
				Close();
			return true;
		}
		else if (ev.target->GetID() == TBIDC("reload skin bitmaps"))
		{
			int reload_count = 10;
			double t1 = TBSystem::GetTimeMS();
			for (int i = 0; i < reload_count; i++)
				g_tb_skin->ReloadBitmaps();
			double t2 = TBSystem::GetTimeMS();

			TBStr message;
			message.SetFormatted("Reloading the skin graphics %d times took %dms", reload_count, (int)(t2 - t1));
			TBMessageWindow *msg_win = new TBMessageWindow(ev.target, TBID());
			msg_win->Show("GFX load performance", message);
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test context lost"))
		{
			g_renderer->InvokeContextLost();
			g_renderer->InvokeContextRestored();
			TBMessageWindow *msg_win = new TBMessageWindow(ev.target, TBID());
			msg_win->Show("Context lost & restore",
							"Called InvokeContextLost and InvokeContextRestored.\n\n"
							"Does everything look fine?");
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-layout"))
		{
			TBStr resource_file("Demo/demo01/ui_resources/");
			resource_file.Append(ev.target->data.GetString());
			new LayoutWindow(resource_file);
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-connections"))
		{
			new ConnectionWindow();
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-list"))
		{
			new AdvancedListWindow(&advanced_source);
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-image"))
		{
			new ImageWindow();
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-page"))
		{
			new PageWindow();
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-animations"))
		{
			new AnimationsWindow();
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-scroll-container"))
		{
			new ScrollContainerWindow();
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-skin-conditions"))
		{
			(new DemoWindow())->LoadResourceFile("Demo/demo01/ui_resources/test_skin_conditions01.tb.txt");
			(new DemoWindow())->LoadResourceFile("Demo/demo01/ui_resources/test_skin_conditions02.tb.txt");
			return true;
		}
		else if (ev.target->GetID() == TBIDC("test-resource-edit"))
		{
			ResourceEditWindow *res_edit_win = new ResourceEditWindow();
			res_edit_win->Load("Demo/demo01/ui_resources/resource_edit_test.tb.txt");
			GetParent()->AddChild(res_edit_win);
			return true;
		}
		else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("debug settings"))
		{
#ifdef TB_RUNTIME_DEBUG_INFO
			ShowDebugInfoSettingsWindow(GetParentRoot());
#else
			TBMessageWindow *msg_win = new TBMessageWindow(ev.target, TBID());
			msg_win->Show("Debug settings",
							"Debug settings is only available in builds "
							"compiled with TB_RUNTIME_DEBUG_INFO defined.\n\n"
							"Debug builds enable this by default.");
#endif
			return true;
		}
	}
	return DemoWindow::OnEvent(ev);
}
Esempio n. 12
0
TBID TBSelectDropdown::GetSelectedItemID()
{
    if (m_source && m_value >= 0 && m_value < m_source->GetNumItems())
        return m_source->GetItemID(m_value);
    return TBID();
}
Esempio n. 13
0
void UISelectItem::SetSkinImage(const String& skinImage)
{
    skinImage_ = TBID(skinImage.CString());
}
Esempio n. 14
0
void UISelectItem::SetID(const String& id)
{
    id_ = TBID(id.CString());
}