Exemplo n.º 1
0
void OpenGLES30FormatTest::LoadResources()
{
	Font *font = FTFont::Create("~res:/Fonts/korinna.ttf");
    DVASSERT(font);
	font->SetSize(20);

	UIButton *testButton = new UIButton(Rect(0, 0, 300, 30));
	testButton->SetStateFont(0xFF, font);
	testButton->SetStateText(0xFF, L"Finish Test");
 	testButton->SetStateFontColor(0xFF, Color::White);
	testButton->SetDebugDraw(true);
	testButton->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &OpenGLES30FormatTest::ButtonPressed));
	AddControl(testButton);
    testButton->Release();

    formatName = new UIStaticText(Rect(0, 30, 300, 30));
    formatName->SetFont(font);
    formatName->SetTextColor(Color::White);
    AddControl(formatName);
    
    source = new UIControl(Rect(0, 60, 256, 256));
    AddControl(source);

    decodedSource = new UIControl(Rect(0, 330, 256, 256));
    AddControl(decodedSource);
    
    encodedSource = new UIControl(Rect(300, 330, 256, 256));
    AddControl(encodedSource);
    
    LoadFormat("RG11");
}
// Initialize the control(s) attached.
void UIButtonMetadata::InitializeControl(const String& controlName, const Vector2& position)
{
    BaseMetadata::InitializeControl(controlName, position);

    int paramsCount = this->GetParamsCount();
    for (BaseMetadataParams::METADATAPARAMID i = 0; i < paramsCount; i ++)
    {
        UIButton* button = dynamic_cast<UIButton*>(this->treeNodeParams[i].GetUIControl());

        WideString controlText = StringToWString(button->GetName());
        HierarchyTreeNode* activeNode = GetTreeNode(i);
    
        // Initialize the button for all states.
        int statesCount = UIControlStateHelper::GetUIControlStatesCount();
        for (int stateID = 0; stateID < statesCount; stateID ++)
        {
            UIControl::eControlState state = UIControlStateHelper::GetUIControlState(stateID);
            button->SetStateFont(state, EditorFontManager::Instance()->GetDefaultFont());
            button->SetStateText(state, controlText);

            // Button is state-aware.
            activeNode->GetExtraData().SetLocalizationKey(controlText, state);
        }
        
        // Define some properties for the reference state.
        button->SetStateDrawType(GetReferenceState(), UIControlBackground::DRAW_SCALE_TO_RECT);
    }
}
Exemplo n.º 3
0
DAVA::UIControl *UIControlFactory::CreateButton(DAVA::UIControl *prototype, UIStyle *style)
{
    UIButton *button = NULL;
    
    if (prototype)
        button = dynamic_cast<UIButton*>(prototype->Clone());
    
    if (!button)
        button = new UIButton();

    ApplyAttributes(button, style);
    
    const int32 states[] = {UIControl::STATE_NORMAL, UIControl::STATE_PRESSED_INSIDE, UIControl::STATE_PRESSED_OUTSIDE, UIControl::STATE_DISABLED, UIControl::STATE_SELECTED, UIControl::STATE_HOVER};
    const String stateNames[] = {"Normal", "PressedInside", "PressedOutside", "Disabled", "Selected", "Hover"};
    
    for (int i = 0; i < UIControl::STATE_COUNT; i++)
    {
        const UIStyle *stateStyle = style->GetSubstyle(stateNames[i]);
        if (stateStyle == NULL)
            stateStyle = style;
        
        const UIStyleAttribute *attr = NULL;
        if ((attr = stateStyle->GetAttribute("sprite", style)) != NULL)
            button->SetStateSprite(states[i], attr->AsString());
        if ((attr = stateStyle->GetAttribute("spriteFrame", style)) != NULL)
            button->SetStateFrame(states[i], attr->AsInt());
        if ((attr = stateStyle->GetAttribute("color", style)) != NULL)
            button->SetStateColor(states[i], attr->AsColor());
        if ((attr = stateStyle->GetAttribute("text", style)) != NULL)
            button->SetStateText(states[i], StringToWString(attr->AsString()));
        if ((attr = stateStyle->GetAttribute("font", style)) != NULL)
        {
            String fontName = attr->AsString();
            int fontSize = 20;
            if ((attr = stateStyle->GetAttribute("fontSize", style)) != NULL)
                fontSize = attr->AsInt();
            
            Font *font = FTFont::Create(fontName);
            font->SetSize(fontSize);
            button->SetStateFont(states[i], font);
            SafeRelease(font);
        }
    }
    
    return button;
}
Exemplo n.º 4
0
void UIScrollViewTest::LoadResources()
{
	Font *font = FTFont::Create("~res:/Fonts/korinna.ttf");
    DVASSERT(font);
	font->SetSize(14);
    font->SetColor(Color::White());

    UIYamlLoader::Load( this, "~res:/UI/Test/ScrollScreen.yaml" );
	scrollView = DynamicTypeCheck<UIScrollView *>( FindByName( "Scrollview" ) );
	
	UIControl* innerControl = FindByName("UIControl1");
	if (innerControl)
	{
		innerControl->SetSprite("~res:/Gfx/UI/HorizontalScroll", 0);
		innerControl->GetBackground()->SetDrawType(UIControlBackground::DRAW_SCALE_TO_RECT);
	}
	
    UIControl *control = FindByName("HorizontalScrollbar");
    if( control )
    {
        UIScrollBar *horizontalScrollbar = DynamicTypeCheck<UIScrollBar *>( control );
        horizontalScrollbar->GetSlider()->SetSprite("~res:/Gfx/UI/HorizontalScroll", 0);
        horizontalScrollbar->GetSlider()->GetBackground()->SetDrawType(UIControlBackground::DRAW_STRETCH_HORIZONTAL);
		horizontalScrollbar->GetSlider()->GetBackground()->SetLeftRightStretchCap(10);
        horizontalScrollbar->SetOrientation( UIScrollBar::ORIENTATION_HORIZONTAL );
        horizontalScrollbar->SetDelegate(scrollView);
    }
	
    control = FindByName("VerticalScrollbar");
    if( control )
    {
        UIScrollBar *verticalScrollbar = DynamicTypeCheck<UIScrollBar *>( control );
        verticalScrollbar->GetSlider()->SetSprite("~res:/Gfx/UI/VerticalScroll", 0);
        verticalScrollbar->GetSlider()->GetBackground()->SetDrawType(UIControlBackground::DRAW_STRETCH_VERTICAL);
        verticalScrollbar->GetSlider()->GetBackground()->SetTopBottomStretchCap(10);
        verticalScrollbar->SetOrientation( UIScrollBar::ORIENTATION_VERTICAL );
        verticalScrollbar->SetDelegate(scrollView);
    }
	
	UIControl *testControl4 = new UIControl(Rect(1200, 1400, 250, 250));
	testControl4->SetDebugDraw(true);
	testControl4->GetBackground()->SetColor(Color(0.3333, 0.3333, 0.5555, 1.0000));
	testControl4->GetBackground()->SetDrawType(UIControlBackground::DRAW_FILL);
	testControl4->SetName("CONTROL_4");
	testControl4->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &UIScrollViewTest::ButtonPressed));
	scrollView->AddControlToContainer(testControl4);

	UIControl *testControlChild = new UIControl(Rect(100, 100, 150, 150));
	testControlChild->SetDebugDraw(true);
	testControlChild->GetBackground()->SetColor(Color(0.3333, 0.3333, 0.5555, 1.0000));
	testControlChild->GetBackground()->SetDrawType(UIControlBackground::DRAW_FILL);
	testControlChild->SetName("CONTROL_3");
	testControlChild->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &UIScrollViewTest::ButtonPressed));
	
	UIControl *testControl = new UIControl(Rect(50, 0, 150, 150));
	testControl->SetDebugDraw(true);
	testControl->GetBackground()->SetColor(Color(0.3333, 0.6667, 0.4980, 1.0000));
	testControl->GetBackground()->SetDrawType(UIControlBackground::DRAW_FILL);
	testControl->SetName("CONTROL_2");
	testControl->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &UIScrollViewTest::ButtonPressed));
	testControl->AddControl(testControlChild);
	
	UIButton *testButton = new UIButton(Rect(10, 50, 250, 100));
	testButton->SetDebugDraw(true);
	testButton->SetStateFont(STATE_NORMAL, font);
	testButton->SetStateText(STATE_NORMAL, L"First button");
	testButton->GetBackground()->SetColor(Color(0.6667, 0.6667, 0.4980, 1.0000));
	testButton->GetBackground()->SetDrawType(UIControlBackground::DRAW_FILL);
	testButton->SetName("CONTROL_1");
	testButton->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &UIScrollViewTest::ButtonPressed));
	testButton->AddControl(testControl);
	
	scrollView->AddControlToContainer(testButton);
	
	testMessageText = new UIStaticText(Rect(10, 10, 300, 30));
	testMessageText->SetFont(font);
	testMessageText->SetTextColor(Color(0.0, 1.0, 0.0, 1.0));
	testMessageText->GetBackground()->SetColor(Color(0.5, 0.0, 0.25, 1.0));
	testMessageText->GetBackground()->SetDrawType(UIControlBackground::DRAW_FILL);
	AddControl(testMessageText);
	
	finishTestBtn = new UIButton(Rect(10, 310, 300, 30));
	finishTestBtn->SetStateFont(0xFF, font);
	finishTestBtn->SetStateFontColor(0xFF, Color(1.0, 0.0, 0.0, 0.75));
	finishTestBtn->SetStateText(0xFF, L"Finish test");

	finishTestBtn->SetDebugDraw(true);
	finishTestBtn->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &UIScrollViewTest::ButtonPressed));
	AddControl(finishTestBtn);
}