UIScrollBar* UIFactory::createScrollBar(vec2 pos, float rot, float width, float barLength, const char* filename, UIController* uiController){ UIScrollBar* scrollbar = new UIScrollBar(filename, uiController); //Creo un estado externo para el boton UIState* externalState = UIFactory::createState(pos, rot, vec2(1.0f), 1.0f, NULL); //Informo que debe destruirse el estado luego de efectuar una transicion externalState->setDestroyedAfterTransition(true); //Asigno el estado scrollbar->getExternalState()->makeStateTransition(externalState); //Pongo los largos y anchos correctos scrollbar->setWidth(width); scrollbar->setHeight(barLength); //Habemus boton return scrollbar; }
void UIScrollBarMetadata::InitializeControl(const String& controlName, const Vector2& position) { BaseMetadata::InitializeControl(controlName, position); int paramsCount = this->GetParamsCount(); for (BaseMetadataParams::METADATAPARAMID i = 0; i < paramsCount; i ++) { // Initialize UIScrollBar UIScrollBar* scroll = dynamic_cast<UIScrollBar*>(this->treeNodeParams[i].GetUIControl()); if (scroll) { scroll->GetBackground()->SetDrawType(UIControlBackground::DRAW_SCALE_TO_RECT); } } }
void ControlsFactory::SetScrollbar(DAVA::UIHierarchy *h) { Rect fr = h->GetRect(); Sprite *scrollSpr = Sprite::Create("~res:/Gfx/UI/scroll"); UIScrollBar *scrollBar = new UIScrollBar(Rect(fr.dx - scrollSpr->GetWidth(), 0, scrollSpr->GetWidth(), fr.dy), UIScrollBar::ORIENTATION_VERTICAL); scrollBar->GetSlider()->SetSprite(scrollSpr, 0); scrollBar->GetSlider()->GetBackground()->SetDrawType(UIControlBackground::DRAW_STRETCH_VERTICAL); scrollBar->GetSlider()->GetBackground()->SetTopBottomStretchCap(10); scrollBar->SetDelegate(h); scrollBar->SetInputEnabled(false); h->AddControl(scrollBar); SafeRelease(scrollSpr); SafeRelease(scrollBar); }
void ControlsFactory::SetScrollbar(DAVA::UIList *l) { UIControl *c = l->FindByName("ScrollBar"); if(c) return; Rect fr = l->GetRect(); Sprite *scrollSpr = Sprite::Create("~res:/Gfx/UI/scroll"); UIScrollBar *scrollBar = new UIScrollBar(Rect(fr.dx - scrollSpr->GetWidth(), 0, scrollSpr->GetWidth(), fr.dy), UIScrollBar::ORIENTATION_VERTICAL); scrollBar->SetName("ScrollBar"); scrollBar->GetSlider()->SetSprite(scrollSpr, 0); scrollBar->GetSlider()->GetBackground()->SetDrawType(UIControlBackground::DRAW_STRETCH_VERTICAL); scrollBar->GetSlider()->GetBackground()->SetTopBottomStretchCap(10); scrollBar->SetDelegate(l); scrollBar->SetInputEnabled(false); l->AddControl(scrollBar); SafeRelease(scrollSpr); SafeRelease(scrollBar); }
UIControl* UIScrollBar::Clone() { UIScrollBar *t = new UIScrollBar(GetRect()); t->CopyDataFrom(this); return t; }
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); }
UIWidget* UI::WrapWidget(tb::TBWidget* widget) { if (!widget) return NULL; if (widgetWrap_.Contains(widget)) return widgetWrap_[widget]; // switch this to use a factory? // this is order dependent as we're using IsOfType which also works if a base class if (widget->IsOfType<TBPopupWindow>()) { UIPopupWindow* popupWindow = new UIPopupWindow(context_, false); popupWindow->SetWidget(widget); WrapWidget(popupWindow, widget); return popupWindow; } if (widget->IsOfType<TBDimmer>()) { UIDimmer* dimmer = new UIDimmer(context_, false); dimmer->SetWidget(widget); WrapWidget(dimmer, widget); return dimmer; } if (widget->IsOfType<TBScrollContainer>()) { UIScrollContainer* container = new UIScrollContainer(context_, false); container->SetWidget(widget); WrapWidget(container, widget); return container; } if (widget->IsOfType<TBInlineSelect>()) { UIInlineSelect* select = new UIInlineSelect(context_, false); select->SetWidget(widget); WrapWidget(select, widget); return select; } if (widget->IsOfType<TBSlider>()) { UISlider* slider = new UISlider(context_, false); slider->SetWidget(widget); WrapWidget(slider, widget); return slider; } if (widget->IsOfType<TBScrollBar>()) { UIScrollBar* slider = new UIScrollBar(context_, false); slider->SetWidget(widget); WrapWidget(slider, widget); return slider; } if (widget->IsOfType<TBColorWidget>()) { UIColorWidget* colorWidget = new UIColorWidget(context_, false); colorWidget->SetWidget(widget); WrapWidget(colorWidget, widget); return colorWidget; } if (widget->IsOfType<TBColorWheel>()) { UIColorWheel* colorWheel = new UIColorWheel(context_, false); colorWheel->SetWidget(widget); WrapWidget(colorWheel, widget); return colorWheel; } if (widget->IsOfType<TBSection>()) { UISection* section = new UISection(context_, false); section->SetWidget(widget); WrapWidget(section, widget); return section; } if (widget->IsOfType<TBSeparator>()) { UISeparator* sep = new UISeparator(context_, false); sep->SetWidget(widget); WrapWidget(sep, widget); return sep; } if (widget->IsOfType<TBContainer>()) { UIContainer* container = new UIContainer(context_, false); container->SetWidget(widget); WrapWidget(container, widget); return container; } if (widget->IsOfType<TBSelectDropdown>()) { UISelectDropdown* select = new UISelectDropdown(context_, false); select->SetWidget(widget); WrapWidget(select, widget); return select; } if (widget->IsOfType<TBPulldownMenu>()) { UIPulldownMenu* select = new UIPulldownMenu(context_, false); select->SetWidget(widget); WrapWidget(select, widget); return select; } if (widget->IsOfType<TBButton>()) { // don't wrap the close button of a TBWindow.close if (widget->GetID() == TBIDC("TBWindow.close")) return 0; UIButton* button = new UIButton(context_, false); button->SetWidget(widget); WrapWidget(button, widget); return button; } if (widget->IsOfType<TBTextField>()) { UITextField* textfield = new UITextField(context_, false); textfield->SetWidget(widget); WrapWidget(textfield, widget); return textfield; } if (widget->IsOfType<TBEditField>()) { UIEditField* editfield = new UIEditField(context_, false); editfield->SetWidget(widget); WrapWidget(editfield, widget); return editfield; } if (widget->IsOfType<TBSkinImage>()) { UISkinImage* skinimage = new UISkinImage(context_, "", false); skinimage->SetWidget(widget); WrapWidget(skinimage, widget); return skinimage; } if (widget->IsOfType<TBImageWidget>()) { UIImageWidget* imagewidget = new UIImageWidget(context_, false); imagewidget->SetWidget(widget); WrapWidget(imagewidget, widget); return imagewidget; } if (widget->IsOfType<TBClickLabel>()) { UIClickLabel* nwidget = new UIClickLabel(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBCheckBox>()) { UICheckBox* nwidget = new UICheckBox(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBRadioButton>()) { UIRadioButton* nwidget = new UIRadioButton(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBBarGraph>()) { UIBargraph* nwidget = new UIBargraph(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBSelectList>()) { UISelectList* nwidget = new UISelectList(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBMessageWindow>()) { UIMessageWindow* nwidget = new UIMessageWindow(context_, NULL, "", false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBPromptWindow>()) { UIPromptWindow* nwidget = new UIPromptWindow(context_, NULL, "", false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBFinderWindow>()) { UIFinderWindow* nwidget = new UIFinderWindow(context_, NULL, "", false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBTabContainer>()) { UITabContainer* nwidget = new UITabContainer(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<SceneViewWidget>()) { UISceneView* nwidget = new UISceneView(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } if (widget->IsOfType<TBLayout>()) { UILayout* layout = new UILayout(context_, (UI_AXIS) widget->GetAxis(), false); layout->SetWidget(widget); WrapWidget(layout, widget); return layout; } if (widget->IsOfType<TBWidget>()) { UIWidget* nwidget = new UIWidget(context_, false); nwidget->SetWidget(widget); WrapWidget(nwidget, widget); return nwidget; } return 0; }