Пример #1
0
void UI::HandleUpdate(StringHash eventType, VariantMap& eventData)
{
    if (exitRequested_) {
        SendEvent(E_EXITREQUESTED);
        exitRequested_ = false;
        return;
    }
    
    tooltipHoverTime_ += eventData[Update::P_TIMESTEP].GetFloat();

    if (tooltipHoverTime_ >= 0.5f)
    {
        UIWidget* hoveredWidget = GetHoveredWidget();
        if (hoveredWidget && !tooltip_ && (hoveredWidget->GetShortened() || hoveredWidget->GetTooltip().Length() > 0))
        {
            tooltip_ = new UIPopupWindow(context_, true, hoveredWidget, "tooltip");
            UILayout* tooltipLayout = new UILayout(context_, UI_AXIS_Y, true);
            if (hoveredWidget->GetShortened())
            {
                UITextField* fullTextField = new UITextField(context_, true);
                fullTextField->SetText(hoveredWidget->GetText());
                tooltipLayout->AddChild(fullTextField);
            }
            if (hoveredWidget->GetTooltip().Length() > 0)
            {
                UITextField* tooltipTextField = new UITextField(context_, true);
                tooltipTextField->SetText(hoveredWidget->GetTooltip());
                tooltipLayout->AddChild(tooltipTextField);
            }
            Input* input = GetSubsystem<Input>();
            IntVector2 mousePosition = input->GetMousePosition();
            tooltip_->AddChild(tooltipLayout);
            tooltip_->Show(mousePosition.x_ + 8, mousePosition.y_ + 8);
        }
    }
    else 
    {
        if (tooltip_) tooltip_->Close();
    }

    SendEvent(E_UIUPDATE);
    TBMessageHandler::ProcessMessages();
}
Пример #2
0
SampleSelector::SampleSelector(Context* context) :
    Object(context)
{
    UIView* view = FeatureExamples::GetUIView();

    UILayout* rootLayout = new UILayout(context_);
    rootLayout->SetAxis(UI_AXIS_Y);
    rootLayout->SetRect(view->GetRect());
    view->AddChild(rootLayout);

    const char* examples[] = {
        "Hello World",
        "Hello GUI",
        "Render to Texture",
        "2D Sprite",
        "2D Physics",
        "2D Constraints",
        "2D Rope",
        "2D Spriter Animation",
        "3D Static Scene",
        "3D Animating Scene",
        "3D Light Animation",
        "3D Billboards",
        "3D Particles",
        "3D Physics",
        "3D Skeletal Animation",
        "3D Decals",
        "3D Character",
        "3D Dynamic Geometry",
        "3D Ragdolls",
        "3D Vehicle Demo",
        "3D Crowd Navigation",
        "3D Water",
        "3D Multiple Viewports"
    };

    for (size_t i = 0; i < sizeof(examples) / sizeof(examples[0]); i++)
    {
        UIButton* button = new UIButton(context_);
        button->SetLayoutMinWidth(128);
        button->SetText(examples[i]);
        button->SetId(examples[i]);
        button->SubscribeToEvent(button, E_WIDGETEVENT, ATOMIC_HANDLER(SampleSelector, HandleWidgetEvent));
        rootLayout->AddChild(button);
    }

    Input* input = GetSubsystem<Input>();
    input->SetMouseVisible(true);
    input->SetMouseMode(MM_FREE);

    // Subscribe key up event
    SubscribeToEvent(E_KEYUP, ATOMIC_HANDLER(SampleSelector, HandleKeyUp));

    context->RegisterSubsystem(this);
}