// 处理窗口的鼠标消息 void UIWindow::HandleMouseMessage(UINT message, WPARAM wParam, LPARAM lParam) { if (WM_MOUSELEAVE == message) { // 鼠标离开 SetCurrentMouseControl(NULL); mb_mouse_in = FALSE; return; } if (WM_MOUSEMOVE == message) { // 鼠标移动 if (! mb_mouse_in) { TRACKMOUSEEVENT track_mouse_event; track_mouse_event.cbSize = sizeof(TRACKMOUSEEVENT); track_mouse_event.dwFlags = TME_LEAVE; track_mouse_event.hwndTrack = GetHWND(); mb_mouse_in = ::TrackMouseEvent(&track_mouse_event); } } if (WM_LBUTTONDOWN == message) { ::SetFocus(hwnd_); } // 如果鼠标左键按下,设置此窗口活动 // 关键之处,如果根控件存在,则由根控件来寻找目前鼠标在哪个控件上,在由找到的控件处理此消息 if (mp_root_control) { UIPoint pt((short)LOWORD(lParam), (short)HIWORD(lParam)); UIControl *pMouseControl = mp_root_control->LookupMouseFocusedControl(pt); if (WM_MOUSEMOVE == message) { SetCurrentMouseControl(pMouseControl); } pMouseControl->DispatchMouseMessage(message, wParam, lParam); } }
UIControl * ControlsFactory::CreateLine(const Rect & rect, Color color) { UIControl * lineControl = new UIControl(rect); lineControl->GetBackground()->color = color; lineControl->GetBackground()->SetDrawType(UIControlBackground::DRAW_FILL); return lineControl; }
void DataGraph::FillCell(UIHierarchyCell *cell, void *node) { //Temporary fix for loading of UI Interface to avoid reloading of texrures to different formates. // 1. Reset default format before loading of UI // 2. Restore default format after loading of UI from stored settings. Texture::SetDefaultGPU(GPU_UNKNOWN); DataNode *n = (DataNode *)node; UIStaticText *text = (UIStaticText *)cell->FindByName("_Text_"); text->SetText(StringToWString(n->GetName())); UIControl *icon = cell->FindByName("_Icon_"); icon->SetSprite("~res:/Gfx/UI/SceneNode/datanode", 0); UIControl *marker = cell->FindByName("_Marker_"); marker->SetVisible(false); if(n == workingNode) { cell->SetSelected(true, false); } else { cell->SetSelected(false, false); } Texture::SetDefaultGPU(EditorSettings::Instance()->GetTextureViewGPU()); }
void EditorListDelegate::UpdateCellSize(UIList *forList) { if (isElementsCountNeedUpdate && forList) { isElementsCountNeedUpdate = false; // Change cell size only if aggregator control is available UIControl *aggregatorControl = GetCurrentAggregatorControl(); if (aggregatorControl) { Vector2 aggregatorSize = aggregatorControl->GetSize(); SetCellSize(aggregatorSize); } Vector2 listSize = forList->GetSize(); if(forList->GetOrientation() == UIList::ORIENTATION_HORIZONTAL) { DVASSERT(cellSize.x > 0); cellsCount = ceilf( listSize.x / cellSize.x ); } else { DVASSERT(cellSize.y > 0); cellsCount = ceilf( listSize.y / cellSize.y ); } } }
void ControlsFactory::CustomizeButtonExpandable(UIButton *btn) { UIControl *expandable = new UIControl(Rect(btn->GetSize().dx - btn->GetSize().dy, 0, btn->GetSize().dy, btn->GetSize().dy)); expandable->SetInputEnabled(false); expandable->SetSprite("~res:/Gfx/UI/arrowdown", 0); btn->AddControl(expandable); SafeRelease(expandable); }
bool UIControlTab::SetParameter(const wstring& _key, const ParamValue& _value) { if (L"addpage" == _key) { const ParamUIHandle& param = dynamic_cast<const ParamUIHandle&>(_value); UIControl* page = new UIControlTabPage(this->m_ui, this->m_ui.NewHandle(), NULL); if (false != this->SetParameter(L"addchild", ParamControlPtr(page))) { if (UIControl* control = this->m_ui.GetControl(param.Get())) { wstring name; ParamWString nameparam(name); if ((false != (control->GetParameter(L"name", nameparam))) && (false != (page->SetParameter(L"name", nameparam))) && (false != page->SetParameter(L"addchild", ParamControlPtr(control))) && (false != control->SetParameter(L"parent", ParamControlPtr(page)))) { this->m_pages.push_back(page); return true; } } } delete page; return false; } else if (L"headerlocation" == _key) { const ParamWString& param = dynamic_cast<const ParamWString&>(_value); const wstring headerlocation = param.Get(); if (L"left" == headerlocation) { this->m_headerlocation = HL_LEFT; return true; } else if (L"right" == headerlocation) { this->m_headerlocation = HL_RIGHT; return true; } else if (L"top" == headerlocation) { this->m_headerlocation = HL_TOP; return true; } else if (L"bottom" == headerlocation) { this->m_headerlocation = HL_BOTTOM; return true; } return false; } return UIControl::SetParameter(_key, _value); }
void UIAggregatorMetadata::InitializeControl(const String& controlName, const Vector2& position) { int paramsCount = this->GetParamsCount(); for (BaseMetadataParams::METADATAPARAMID i = 0; i < paramsCount; i ++) { UIControl* control = this->treeNodeParams[i].GetUIControl(); control->SetName(controlName); control->SetPosition(position); control->GetBackground()->SetDrawType(UIControlBackground::DRAW_ALIGNED); } }
// Initialize the control(s) attached. void BaseMetadata::InitializeControl(const String& controlName, const Vector2& position) { int paramsCount = this->GetParamsCount(); for (BaseMetadataParams::METADATAPARAMID i = 0; i < paramsCount; i ++) { UIControl* control = this->treeNodeParams[i].GetUIControl(); control->SetName(controlName); control->SetSize(INITIAL_CONTROL_SIZE); control->SetPosition(position); control->GetBackground()->SetDrawType(UIControlBackground::DRAW_FILL); } }
ControlsPositionData BaseAlignHandler::AlignRightBottom(const List<UIControl*>& controlsList, bool isRight) { ControlsPositionData resultData; // Find the bottom/right position. All the alignment is to be done in absolute coords. float32 referencePos = FLT_MIN; for (List<UIControl*>::const_iterator iter = controlsList.begin(); iter != controlsList.end(); iter ++) { UIControl* uiControl = *iter; if (!uiControl) { continue; } resultData.AddControl(uiControl); Rect absoluteRect = uiControl->GetRect(true); float32 controlSize = isRight ? (absoluteRect.x + absoluteRect.dx) : (absoluteRect.y + absoluteRect.dy); if (controlSize > referencePos) { referencePos = controlSize; } } // Second pass - update. for (List<UIControl*>::const_iterator iter = controlsList.begin(); iter != controlsList.end(); iter ++) { UIControl* uiControl = *iter; if (!uiControl) { continue; } Rect absoluteRect = uiControl->GetRect(true); if (isRight) { float32 offsetX = referencePos - (absoluteRect.x + absoluteRect.dx); absoluteRect.x += offsetX; } else { float32 offsetY = referencePos - (absoluteRect.y + absoluteRect.dy); absoluteRect.y += offsetY; } uiControl->SetRect(absoluteRect, true); } return resultData; }
ControlsPositionData BaseAlignHandler::AlignLeftTop(const List<UIControl*>& controlsList, bool isLeft) { ControlsPositionData resultData; // Find the reference position. All the alignment is to be done in absolute coords. float32 referencePos = FLT_MAX; for (List<UIControl*>::const_iterator iter = controlsList.begin(); iter != controlsList.end(); iter ++) { UIControl* uiControl = *iter; if (!uiControl) { continue; } resultData.AddControl(uiControl); Rect absoluteRect = uiControl->GetRect(true); float32 currentPos = isLeft ? absoluteRect.x : absoluteRect.y; if (currentPos < referencePos) { referencePos = currentPos; } } // Second pass - update. for (List<UIControl*>::const_iterator iter = controlsList.begin(); iter != controlsList.end(); iter ++) { UIControl* uiControl = *iter; if (!uiControl) { continue; } Rect absoluteRect = uiControl->GetRect(true); if (isLeft) { float32 offsetX = absoluteRect.x - referencePos; absoluteRect.x -= offsetX; } else { float32 offsetY = absoluteRect.y - referencePos; absoluteRect.y -= offsetY; } uiControl->SetRect(absoluteRect, true); } return resultData; }
void ControlsAdjustSizeCommand::UndoAdjustedSize(const ControlsPositionData& sizeData) { for (Map<UIControl*, Rect>::const_iterator iter = sizeData.GetControlPositions().begin(); iter != sizeData.GetControlPositions().end(); iter ++) { UIControl* control = iter->first; Rect rect = iter->second; if (control) { control->SetRect(rect); } } }
void UIControlTab::Update() { if (false != this->m_visible) { this->UpdateDirty(); this->UpdateHeaders(); if (this->m_currentpageindex < this->m_pages.size()) { UIControl* page = this->m_pages[this->m_currentpageindex]; page->SetParameter(L"position", ParamPoint(D2D1::Point2F(this->m_startingpagepos.m_x, this->m_startingpagepos.m_y))); page->SetParameter(L"size", ParamSize(D2D1::SizeF(this->m_pagesize.m_width, this->m_pagesize.m_height))); page->Update(); } } }
void UIControlTab::Render() { if (false != this->m_visible) { if (false == this->RenderUserDraw()) { this->RenderHeaders(); if (this->m_currentpageindex < this->m_pages.size()) { UIControl* page = this->m_pages[this->m_currentpageindex]; page->Render(); } } } }
HierarchyTreeControlNode::~HierarchyTreeControlNode() { Cleanup(); UIControl* parent = uiObject->GetParent(); if (parent) parent->RemoveControl(uiObject); else SafeRelease(uiObject); if (needReleaseUIObjects) { SafeRelease(uiObject); SafeRelease(parentUIObject); } }
void HierarchyTreeControlNode::SetParent(HierarchyTreeNode* node, HierarchyTreeNode* insertAfter) { if (this == insertAfter) return; if (parent) parent->RemoveTreeNode(this, false, false); HierarchyTreeControlNode* newParentControl = dynamic_cast<HierarchyTreeControlNode* >(node); HierarchyTreeScreenNode* newParentScreen = dynamic_cast<HierarchyTreeScreenNode* >(node); DVASSERT(newParentControl || newParentScreen); if (!newParentControl && !newParentScreen) return; UIControl* afterControl = NULL; HierarchyTreeControlNode* insertAfterControl = dynamic_cast<HierarchyTreeControlNode* >(insertAfter); if (insertAfterControl) afterControl = insertAfterControl->GetUIObject(); UIControl* newParentUI = NULL; if (newParentControl) newParentUI = newParentControl->GetUIObject(); else if (newParentScreen) newParentUI = newParentScreen->GetScreen(); node->AddTreeNode(this, insertAfter); if (newParentUI && uiObject) { if (insertAfter != node) { newParentUI->InsertChildAbove(uiObject, afterControl); } else { UIControl* belowControl = NULL; const List<UIControl*> & controls = newParentUI->GetChildren(); if (controls.size()) { belowControl = *controls.begin(); } newParentUI->InsertChildBelow(uiObject, belowControl); } } parent = node; }
bool HierarchyTreeWidget::IsDeleteNodeAllowed(HierarchyTreeControlNode* selectedControlNode) { if (!selectedControlNode) { return true; } // Check whether selected control is Subcontrol of its parent. UIControl* uiControl = selectedControlNode->GetUIObject(); if (!uiControl) { return true; } // Subcontrols cannot be deleted. return !uiControl->IsSubcontrol(); }
BaseMetadata* MetadataFactory::GetMetadataForTreeNodesList(const HierarchyTreeController::SELECTEDCONTROLNODES& nodesList) const { if (nodesList.empty()) { Logger::Error("MetadataFactory::GetMetadataForTreeNodesList - Nodes List is empty!"); return NULL; } // Simplified logic for now. If all the UI Controls attached to the node have the same type, return it. // Otherwise return common UIControlMetadata. bool allNodesHaveSameUIObjectType = true; const char* firstUIControlType = NULL; for (HierarchyTreeController::SELECTEDCONTROLNODES::const_iterator iter = nodesList.begin(); iter != nodesList.end(); iter ++) { UIControl* attachedControl = (*iter)->GetUIObject(); if (firstUIControlType == NULL) { // Remember the first node type. firstUIControlType = typeid(*attachedControl).name(); continue; } // Compare the current control type with the first one. if (strcmp(firstUIControlType, typeid(*attachedControl).name()) != 0) { allNodesHaveSameUIObjectType = false; break; } } if (allNodesHaveSameUIObjectType) { // Since all the nodes have the same UI Object type attached, use the first one. return GetMetadataForUIControl((*nodesList.begin())->GetUIObject()); } else { // Return the metadata for common UIControl. UIControl* uiControl = new UIControl(); BaseMetadata* resultMetadata = GetMetadataForUIControl(uiControl); uiControl->Release(); return resultMetadata; } }
UIHierarchyCell * UIHierarchy::FindVisibleCellForPoint(Vector2 &point) { UIHierarchyCell *cell = NULL; List<UIControl*> cellsToFind = GetVisibleCells(); for(List<UIControl*>::const_iterator it = cellsToFind.begin(); it != cellsToFind.end(); ++it) { UIControl *c = *it; if(c->IsPointInside(point)) { cell = (UIHierarchyCell *)c; break; } } return cell; }
void TextureConverterDialog::OnCellSelected(UIList *forList, UIListCell *selectedCell) { selectedItem = selectedCell->GetIndex(); SetupTexturePreview(); //set selections List<UIControl*> children = forList->GetVisibleCells(); List<UIControl*>::iterator endIt = children.end(); for(List<UIControl*>::iterator it = children.begin(); it != endIt; ++it) { UIControl *ctrl = (*it); ctrl->SetSelected(false, false); } selectedCell->SetSelected(true, false); }
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 GraphBase::OnCellSelected(UIHierarchy *forHierarchy, UIHierarchyCell *selectedCell) { DVASSERT(delegate); if(!delegate->LandscapeEditorActive()) { SelectHierarchyNode(selectedCell->GetNode()); //select List<UIControl*> children = forHierarchy->GetVisibleCells(); for(List<UIControl*>::iterator it = children.begin(); it != children.end(); ++it) { UIControl *ctrl = (*it); ctrl->SetSelected(false, false); } selectedCell->SetSelected(true, false); } }
void UIScrollViewTest::ButtonPressed(BaseObject *obj, void *data, void *callerData) { UIControl *control = dynamic_cast<UIControl*>(obj); if (control) { String msg = Format("Tap on control - %s", control->GetName().c_str()); testMessageText->SetText(StringToWString(msg)); } else { testMessageText->SetText(L""); } if (obj == finishTestBtn) { testFinished = true; } }
void HintManager::OnAlphaAnimationDone(BaseObject * owner, void * userData, void * callerData) { UIControl *hintControl = (UIControl *)userData; for(Vector<HintControl*>::iterator it = hints.begin(); it != hints.end(); ++it) { if((*it) == hintControl && hintControl) { if(hintControl->GetParent()) { hintControl->GetParent()->RemoveControl(hintControl); } SafeRelease(hintControl); hints.erase(it); break; } } }
ControlsPositionData BaseAlignHandler::AlignCenter(const List<UIControl*>& controlsList, bool isHorizontal) { ControlsPositionData resultData; for (List<UIControl*>::const_iterator iter = controlsList.begin(); iter != controlsList.end(); iter ++) { UIControl* uiControl = *iter; if (!uiControl) { continue; } resultData.AddControl(uiControl); } // Perform the alignment on the first or last control, depending on the flag. UIControl* referenceControl = GetReferenceControl(controlsList); Vector2 referenceCenter = referenceControl->GetRect(true).GetCenter(); // Second pass - update. for (List<UIControl*>::const_iterator iter = controlsList.begin(); iter != controlsList.end(); iter ++) { UIControl* uiControl = *iter; if (!uiControl) { continue; } Rect absoluteRect = uiControl->GetRect(true); Vector2 currentCenter = absoluteRect.GetCenter(); if (isHorizontal) { absoluteRect.x -= (currentCenter.x - referenceCenter.x); } else { absoluteRect.y -= (currentCenter.y - referenceCenter.y); } uiControl->SetRect(absoluteRect, true); } return resultData; }
void HierarchyTreeAggregatorNode::UpdateChilds() { for (CHILDS::iterator iter = childs.begin(); iter != childs.end(); ++iter) { HierarchyTreeControlNode* controlNode = (*iter); UIAggregatorControl* aggregatorControl = dynamic_cast<UIAggregatorControl*>(controlNode->GetUIObject()); DVASSERT(aggregatorControl); if (!aggregatorControl) continue; // Remove any child controls of UIControl to prevent appearance of deleted // child in case when screen child is aggregator. /*List<UIControl*> aggregatorChilds = aggregatorControl->GetChildren(); int size = GetScreen()->GetChildren().size(); for (List<UIControl*>::iterator iter = aggregatorChilds.begin(); iter != aggregatorChilds.end();) { if (--size < 0) break; UIControl* child = (*iter); ++iter; aggregatorControl->RemoveControl(child); }*/ aggregatorControl->RemoveAllControls(); const List<UIControl*> & childsList = screen->GetChildren(); UIControl* belowControl = NULL; List<UIControl*>::const_iterator belowIter = aggregatorControl->GetChildren().begin(); if (belowIter != aggregatorControl->GetChildren().end()) belowControl = (*belowIter); for (List<UIControl*>::const_iterator iter = childsList.begin(); iter != childsList.end(); ++iter) { UIControl* control = (*iter); UIControl* newControl = control->Clone(); aggregatorControl->InsertChildBelow(newControl, belowControl); aggregatorControl->AddAggregatorChild(newControl); } //aggregatorControl->SetSize(screen->GetSize()); TODO:// update child size aggregatorControl->SetRect(aggregatorControl->GetRect()); //update childs size and position } }
void HierarchyTreeScreenNode::BuildHierarchyTree(HierarchyTreeNode* parent, List<UIControl*> child) { for (List<UIControl*>::const_iterator iter = child.begin(); iter != child.end(); ++iter) { UIControl* uiControl = (*iter); HierarchyTreeControlNode* node = NULL; if (dynamic_cast<UIAggregatorControl*>(uiControl)) node = new HierarchyTreeAggregatorControlNode(NULL, parent, uiControl, QString::fromStdString(uiControl->GetName())); else node = new HierarchyTreeControlNode(parent, uiControl, QString::fromStdString(uiControl->GetName())); // Build hierarchy tree for all control's children. Subcontrols are loaded separately InitializeControlBeforeAddingToTree(uiControl); BuildHierarchyTree(node, uiControl->GetRealChildren()); parent->AddTreeNode(node); } }
UIHierarchyCell * GraphBase::CellForNode(UIHierarchy *forHierarchy, void *node) { UIHierarchyCell *c= forHierarchy->GetReusableCell("Graph cell"); //try to get cell from the reusable cells store if(!c) { //if cell of requested type isn't find in the store create new cell int32 leftSideWidth = EditorSettings::Instance()->GetLeftPanelWidth(); c = new UIHierarchyCell(Rect(0, 0, leftSideWidth, ControlsFactory::CELL_HEIGHT), "Graph cell"); UIControl *icon = new UIControl(Rect(0, 0, ControlsFactory::CELL_HEIGHT, ControlsFactory::CELL_HEIGHT)); icon->SetName("_Icon_"); icon->GetBackground()->SetDrawType(UIControlBackground::DRAW_SCALE_PROPORTIONAL); c->text->AddControl(icon); UIControl *marker = new UIControl(Rect(0, 0, ControlsFactory::CELL_HEIGHT, ControlsFactory::CELL_HEIGHT)); marker->SetName("_Marker_"); marker->GetBackground()->SetDrawType(UIControlBackground::DRAW_SCALE_PROPORTIONAL); c->text->AddControl(marker); UIStaticText *text = new UIStaticText(Rect(ControlsFactory::CELL_HEIGHT, 0, leftSideWidth - ControlsFactory::CELL_HEIGHT, ControlsFactory::CELL_HEIGHT)); Font *font = ControlsFactory::GetFont12(); text->SetFont(font); text->SetAlign(ALIGN_LEFT|ALIGN_VCENTER); text->SetName("_Text_"); text->SetTextColor(ControlsFactory::GetColorDark()); c->text->AddControl(text); } FillCell(c, node); ControlsFactory::CustomizeExpandButton(c->openButton); ControlsFactory::CustomizeSceneGraphCell(c); return c; }
ControlsPositionData ControlsAdjustSizeCommand::ApplyAjustedSize(HierarchyTreeController::SELECTEDCONTROLNODES& controls) { ControlsPositionData resultData; for (HierarchyTreeController::SELECTEDCONTROLNODES::iterator iter = controls.begin(); iter != controls.end(); ++iter) { HierarchyTreeControlNode* control = (*iter); UIControl* uiControl = control->GetUIObject(); int32 nodeId = control->GetId(); if (uiControl) { // Get sprite Sprite* sprite = uiControl->GetSprite(); Rect prevRect = uiControl->GetRect(); Rect updatedRect = prevRect; if (sprite) { // Save control size data for undo resultData.AddControl(uiControl); // Set new size of updated rect updatedRect.dx = sprite->GetWidth(); updatedRect.dy = sprite->GetHeight(); BaseMetadata* baseMetadata = GetMetadataForTreeNode(nodeId); // This command is NOT state-aware and contains one and only param. baseMetadata->SetActiveParamID(0); baseMetadata->ApplyResize(prevRect, updatedRect); SAFE_DELETE(baseMetadata); } } } return resultData; }
void HierarchyTreeControlNode::AddControlToParent() { if (!parent) return; DVASSERT(uiObject); HierarchyTreeScreenNode* screenNode = dynamic_cast<HierarchyTreeScreenNode*>(parent); if (screenNode) { screenNode->GetScreen()->AddControl(this->uiObject); } else { //HierarchyTreeControlNode* controlNode = GetControlNode(); HierarchyTreeControlNode* controlNode = dynamic_cast<HierarchyTreeControlNode*>(parent); if (controlNode) { UIControl* control = controlNode->GetUIObject(); if (control) control->AddControl(this->uiObject); } } }
void ComboBox::Update(float32 timeElapsed) { UIScreen *scr = UIScreenManager::Instance()->GetScreen(); if (list->GetParent() == scr) { UIControl *f = UIControlSystem::Instance()->GetFocusedControl(); bool isFocused = false; if (f == comboButton || f == list) { isFocused = true; } else { if (f && f->GetParent() && f->GetParent()->GetParent() == list) { isFocused = true; } } if (!isFocused) { Cancel(); } } }