void HierarchyTreeController::SelectControl(HierarchyTreeControlNode* control) { if (activeControlNodes.find(control) != activeControlNodes.end()) return; //add selection activeControlNodes.insert(control); UIControl* uiControl = control->GetUIObject(); if (uiControl) { uiControl->SetDebugDraw(true); uiControl->SetDebugDrawColor(Color(1.f, 0, 0, 1.f)); //YZ draw parent rect UIControl* parentUiControl = uiControl->GetParent(); if (parentUiControl) { parentUiControl->SetDebugDrawColor(Color(0.55f, 0.55f, 0.55f, 1.f)); parentUiControl->SetDebugDraw(true); } } emit AddSelectedControl(control); emit SelectedControlNodesChanged(activeControlNodes); UpdateSelection(control); }
void HierarchyTreeController::UnselectControl(HierarchyTreeControlNode* control, bool emitSelectedControlNodesChanged) { if (activeControlNodes.find(control) == activeControlNodes.end()) return; //remove selection activeControlNodes.erase(control); UIControl* uiControl = control->GetUIObject(); if (uiControl) { uiControl->SetDebugDraw(false); //YZ draw parent rect UIControl* parentToRemove = uiControl->GetParent(); if (parentToRemove) { bool removeParentDraw = true; for (SELECTEDCONTROLNODES::iterator iter = activeControlNodes.begin(); iter != activeControlNodes.end(); ++iter) { HierarchyTreeControlNode* control = (*iter); UIControl* uiControl = control->GetUIObject(); if (uiControl) { UIControl* parentUiControl = uiControl->GetParent(); if (parentToRemove == uiControl || parentToRemove == parentUiControl) { removeParentDraw = false; break; } } } if (removeParentDraw) parentToRemove->SetDebugDraw(false); } } emit RemoveSelectedControl(control); if (emitSelectedControlNodesChanged) emit SelectedControlNodesChanged(activeControlNodes); }
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); }