Example #1
0
 virtual void RecreateWidget() {
     CreateCheckbox();
 }
Example #2
0
void Typography::Start()
{
    // Execute base class startup
    Sample::Start();

    // Enable OS cursor
    GetSubsystem<Input>()->SetMouseVisible(true);

    // Load XML file containing default UI style sheet
    auto* cache = GetSubsystem<ResourceCache>();
    auto* style = cache->GetResource<XMLFile>("UI/DefaultStyle.xml");

    // Set the loaded style as default style
    auto* ui = GetSubsystem<UI>();
    UIElement* root = ui->GetRoot();
    root->SetDefaultStyle(style);

    // Create a UIElement to hold all our content
    // (Don't modify the root directly, as the base Sample class uses it)
    uielement_ = new UIElement(context_);
    uielement_->SetAlignment(HA_CENTER, VA_CENTER);
    uielement_->SetLayout(LM_VERTICAL, 10, IntRect(20, 40, 20, 40));
    root->AddChild(uielement_);

    // Add some sample text.
    CreateText();

    // Add a checkbox to toggle the background color.
    CreateCheckbox("White background", URHO3D_HANDLER(Typography, HandleWhiteBackground))
        ->SetChecked(false);

    // Add a checkbox to toggle SRGB output conversion (if available).
    // This will give more correct text output for FreeType fonts, as the FreeType rasterizer
    // outputs linear coverage values rather than SRGB values. However, this feature isn't
    // available on all platforms.
    CreateCheckbox("Graphics::SetSRGB", URHO3D_HANDLER(Typography, HandleSRGB))
        ->SetChecked(GetSubsystem<Graphics>()->GetSRGB());

    // Add a checkbox for the global ForceAutoHint setting. This affects character spacing.
    CreateCheckbox("UI::SetForceAutoHint", URHO3D_HANDLER(Typography, HandleForceAutoHint))
        ->SetChecked(ui->GetForceAutoHint());

    // Add a drop-down menu to control the font hinting level.
    const char* levels[] = {
        "FONT_HINT_LEVEL_NONE",
        "FONT_HINT_LEVEL_LIGHT",
        "FONT_HINT_LEVEL_NORMAL",
        nullptr
    };
    CreateMenu("UI::SetFontHintLevel", levels, URHO3D_HANDLER(Typography, HandleFontHintLevel))
        ->SetSelection(ui->GetFontHintLevel());

    // Add a drop-down menu to control the subpixel threshold.
    const char* thresholds[] = {
        "0",
        "3",
        "6",
        "9",
        "12",
        "15",
        "18",
        "21",
        nullptr
    };
    CreateMenu("UI::SetFontSubpixelThreshold", thresholds, URHO3D_HANDLER(Typography, HandleFontSubpixel))
        ->SetSelection(ui->GetFontSubpixelThreshold() / 3);

    // Add a drop-down menu to control oversampling.
    const char* limits[] = {
        "1",
        "2",
        "3",
        "4",
        "5",
        "6",
        "7",
        "8",
        nullptr
    };
    CreateMenu("UI::SetFontOversampling", limits, URHO3D_HANDLER(Typography, HandleFontOversampling))
        ->SetSelection(ui->GetFontOversampling() - 1);

    // Set the mouse mode to use in the sample
    Sample::InitMouseMode(MM_FREE);
}