void nuiPopupMenu::RemoveMenu() { if (mTrashRemoval) { Trash(); } }
nuiMessageBox::Button nuiMessageBox::QueryUser() { Button btn = ButtonCancel; DoModal(); btn = mClickedButton; Trash(); return btn; }
void nuiWindow::HandleCloseButtonPressed(const nuiEvent& rEvent) { // Destroy the window if there is no handler for the event... if (!CloseButtonPressed.GetTargetCount()) Trash(); else CloseButtonPressed(); }
void nuiDialogSelectDirectory::OnSelectorOK(const nuiEvent& rEvent) { mPath = mpSelector->GetPath(); // send event and close the dialog if the user answered true if (!DirectorySelected()) Trash(); }
void SObject::Engage() { if(target == NULL) return; Trash(destination); destination = target; depart_turn = cur_game->turn; arrive_turn = cur_game->turn + distance; if(arrive_turn == depart_turn) Arrive(); target = NULL; }
void nuiDialogSelectFile::OnSelectorOK(const nuiEvent& rEvent) { // nglString text = mpEditLine->GetText(); // text.Trim(); // if (text.IsNull()) // return false; mPath = mpSelector->GetPath(); mRootPath = mpSelector->GetRootPath(); // send event and close the dialog if the user answered true if (!FileSelected()) Trash(); }
bool nuiPopupMenu::KeyDown(const nglKeyEvent& rEvent) { mSelectionTimer.Stop(); nuiTreeNode* pNode = (mpNewSelectedNode ? mpNewSelectedNode : mpSelectedNode); if (pNode) { nuiRect WidgetRect = pNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[pNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); Invalidate(); //(r); } if (rEvent.mKey == NK_UP) { if (mpSelectedNode && !mpSelectedNode->IsOpened()) pNode = GetNextNode(GetParentNode(mpTree, mpSelectedNode), mpSelectedNode, -1); else { ///< find the first non disabled element node from end nuiTreeNode* pParent = mpSelectedNode ? mpSelectedNode : mpTree; uint32 count = pParent->GetChildrenCount(); for (int i = count - 1; i >= 0; i--) { pNode = dynamic_cast<nuiTreeNode*>(pParent->GetChild(i)); if (pNode->GetElement()->IsDisabled()) { pNode=NULL; continue; } else break; } pNode = pNode ? pNode : mpSelectedNode ? mpSelectedNode : NULL; } if (!pNode) return true; nuiRect WidgetRect = pNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[pNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); Invalidate(); //(r); if (mpSelectedNode && !mpSelectedNode->IsOpened()) { mpSelectedNode->Select(false); nuiRect WidgetRect = mpSelectedNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[mpSelectedNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); Invalidate(); //(r); } mpSelectedNode = pNode; pNode->Select(true); AdjustScrolling(pNode); FillSelectedNodes(); return true; } else if (rEvent.mKey == NK_DOWN) { if (mpSelectedNode && !mpSelectedNode->IsOpened()) pNode = GetNextNode(GetParentNode(mpTree, mpSelectedNode), mpSelectedNode, 1); else { ///< find the first non disabled element node from top nuiTreeNode* pParent = mpSelectedNode ? mpSelectedNode : mpTree; uint32 count = pParent->GetChildrenCount(); for (uint32 i = 0; i < count; i++) { pNode = dynamic_cast<nuiTreeNode*>(pParent->GetChild(i)); if (pNode->GetElement()->IsDisabled()) { pNode=NULL; continue; } else break; } pNode = pNode ? pNode : mpSelectedNode ? mpSelectedNode : NULL; } if (!pNode) return true; nuiRect WidgetRect = pNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[pNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); Invalidate(); //(r); if (mpSelectedNode && !mpSelectedNode->IsOpened()) { mpSelectedNode->Select(false); nuiRect WidgetRect = mpSelectedNode->GetElement()->GetRect(); nuiRect r = WidgetRect; nuiMenuRect* pRect= mRects[mpSelectedNode->GetDepth()-1]; /// get the current menuRect nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f; r.SetSize(WidgetRect.GetWidth()+TreeHandleSize, WidgetRect.GetHeight()); Invalidate(); //(r); } mpSelectedNode = pNode; pNode->Select(true); AdjustScrolling(pNode); FillSelectedNodes(); return true; } else if (rEvent.mKey == NK_LEFT) { if (mpSelectedNode) { if (mpSelectedNode->IsOpened()) { mpSelectedNode->Open(false); FillSelectedNodes(); InvalidateLayout(); Invalidate(); return true; } else if ((pNode = GetParentNode(mpTree, mpSelectedNode)) != mpTree) { mpSelectedNode->Select(false); mpSelectedNode = pNode; mpSelectedNode->Open(false); FillSelectedNodes(); InvalidateLayout(); Invalidate(); return true; } } Invalidate(); InvalidateLayout(); return false; } else if (rEvent.mKey == NK_RIGHT) { if (mpSelectedNode && !mpSelectedNode->IsEmpty()) { mpSelectedNode->Open(true); if (!mpSelectedNode->GetChildrenCount()) { mpSelectedNode->Open(false); return false; } ResetScrolling(mpSelectedNode->GetDepth()); mpSelectedNode = dynamic_cast<nuiTreeNode*>(mpSelectedNode->GetChild(0)); mpSelectedNode->Select(true); Invalidate(); InvalidateLayout(); FillSelectedNodes(); return true; } Invalidate(); InvalidateLayout(); return false; } else if (rEvent.mKey == NK_ENTER || rEvent.mKey == NK_PAD_ENTER || rEvent.mKey == NK_SPACE) { if (mpSelectedNode && !mpSelectedNode->IsEmpty()) // maybe open { mpSelectedNode->Open(true); if (!mpSelectedNode->GetChildrenCount()) { mpSelectedNode->Open(false); return false; } else { ResetScrolling(mpSelectedNode->GetDepth()); mpSelectedNode = dynamic_cast<nuiTreeNode*>(mpSelectedNode->GetChild(0)); mpSelectedNode->Select(true); Invalidate(); InvalidateLayout(); FillSelectedNodes(); return true; } } // selection done FillSelectedNodes(); if (mpSelectedNode) mpSelectedNode->Activated(); if (!MenuDone()) Trash(); else RemoveMenu(); return true; } else if (rEvent.mKey == NK_ESC) { mpTree->OpenAllChildren(false); mpTree->SelectAllChildren(false); mpSelectedNode = NULL; FillSelectedNodes(); if (!MenuDone()) Trash(); else RemoveMenu(); return true; } else if (rEvent.mChar) { int index = -1; nuiTreeNodePtr pParent = mpTree; if (mpSelectedNode) { pParent = (nuiTreeNodePtr)mpSelectedNode->GetParent(); uint count = pParent->GetChildrenCount(); for (uint i = 0; i < count && index == -1; i++) { if (mpSelectedNode == pParent->GetChild(i)) { index = i; } } } if (pParent) { index++; nuiTreeNodePtr pNode = NULL; uint count = pParent->GetChildrenCount(); NGL_OUT(_T("Start search\n")); for (uint i = 0; i < count && !pNode; i++) { nuiTreeNodePtr pN = (nuiTreeNodePtr)pParent->GetChild((i + index) % count); nuiWidget* pItem = pN->GetElement(); if (pItem->IsEnabled()) { if (mKey.IsEmpty()) { nuiLabel* pLabel = SearchLabel(pItem); if (pLabel) { const nglString& rKey = pLabel->GetText(); if (toupper(rKey[0]) == rEvent.mChar) { pNode = pN; } } } else { const nglString& rKey = pN->GetProperty(mKey); if (toupper(rKey[0]) == rEvent.mChar) { pNode = pN; } } } } if (pNode) { if (mpSelectedNode) { mpSelectedNode->Select(false); if (mpSelectedNode->IsOpened()) mpSelectedNode->Open(false); } mpSelectedNode = pNode; pNode->Select(true); AdjustScrolling(pNode); FillSelectedNodes(); } } return true; } return false; }
bool nuiPopupMenu::MouseClicked(nuiSize X, nuiSize Y, nglMouseInfo::Flags Button) { mSelectionTimer.Stop(); if (Button & nglMouseInfo::ButtonWheelUp) { IncrementScrollBar(false); mWheelMoved = true; return true; } else if (Button & nglMouseInfo::ButtonWheelDown) { IncrementScrollBar(true); mWheelMoved = true; return true; } bool IsInside; int cpt = SearchRectIndex(X,Y); IsInside = cpt >= 0 ? true : false; if (!IsInside) { // Out of bounds, had to close menu if (mpSelectedNode) { mpSelectedNode->Select(false); mpSelectedNode = NULL; } if (!MenuDone()) Trash(); else RemoveMenu(); return true; } else { // Search the clicked node nuiTreeNodePtr pNode = SearchNode(X,Y,cpt); if (pNode) { if (pNode->GetElement()->IsDisabled()) return true; if (mpSelectedNode && mpSelectedNode != pNode) mpSelectedNode->Select(false); nuiTreeNodePtr pParent = GetParentNode(mpTree, pNode); if (pParent) { pParent->OpenAllChildren(false); pParent->SelectAllChildren(false); } mpSelectedNode = mpNewSelectedNode = pNode; pNode->Select(true); if (!pNode->IsEmpty()) { pNode->Open(true); if (!pNode->GetChildrenCount()) pNode->Open(false); else { ResetScrolling(pNode->GetDepth()); FillSelectedNodes(); } } Invalidate(); InvalidateLayout(); return true; } } return true; }
bool nuiPopupMenu::MouseUnclicked(nuiSize X, nuiSize Y, nglMouseInfo::Flags Button) { if (mWheelMoved) { mWheelMoved = false; return true; } if (nglTime() - mStartTime < mDelayTime) { return true; } bool IsInside; int cpt = SearchRectIndex(X,Y); IsInside = cpt >= 0 ? true : false; if (!IsInside) { // Out of bounds, had to close menu mpTree->OpenAllChildren(false); mpTree->SelectAllChildren(false); mpSelectedNode = NULL; FillSelectedNodes(); if (!MenuDone()) Trash(); else RemoveMenu(); return true; } else { nuiTreeNodePtr pNode = SearchNode(X,Y,cpt); if (pNode) { if (!pNode->IsSelectionEnabled() || pNode->GetElement()->IsDisabled()) return true; if (mpSelectedNode) { mpSelectedNode->Select(false); } nuiTreeNodePtr pParent = GetParentNode(mpTree, pNode); if (pParent) { pParent->OpenAllChildren(false); pParent->SelectAllChildren(false); } mpSelectedNode = mpNewSelectedNode = pNode; pNode->Select(true); if (!pNode->IsEmpty()) { pNode->Open(true); if (!pNode->GetChildrenCount()) pNode->Open(false); else { ResetScrolling(pNode->GetDepth()); FillSelectedNodes(); } } else { FillSelectedNodes(); if (mpSelectedNode) mpSelectedNode->Activated(); if (!MenuDone()) Trash(); else RemoveMenu(); } Invalidate(); InvalidateLayout(); } return true; } return false; }
void SObject::Arrive() { SObject *truedest = destination->Represents(); if(!truedest) { system = destination->Sys(); orbit = destination->OrbitDist(); period = destination->Period(); startpos = destination->OrbitPhase(); arrive_turn = destination->ArriveTurn(); depart_turn = destination->DepartTurn(); Trash(location); location = destination->Location(); Trash(destination); destination = destination->Destination(); Trash(target); target = NULL; distance = 0; } else if(truedest->SType() == SOBJECT_PLANET) { system = destination->system; orbit = destination->orbit; period = destination->period; startpos = destination->startpos; Trash(location); location = destination; truedest->See(Owner()); truedest->Know(Owner()); destination = NULL; } else if(truedest->SType() == SOBJECT_SYSTEM) { orbit = 6600; period = int(sqrt(double(orbit)*double(orbit)*double(orbit))); int xp = system->gxpos - destination->system->gxpos; int yp = system->gypos - destination->system->gypos; double tang = double(cur_game->turn) * double(256*256*256) / double(period); double nang = double(65536) * atan2(double(yp), double(xp)) / 2.0 / M_PIl; startpos = int(nang - tang); system->FleetLeaves((Fleet*)this); system = destination->system; system->FleetArrives((Fleet*)this); Trash(location); location = NULL; truedest->Know(Owner()); Trash(destination); destination = NULL; } else if(truedest->SType() == SOBJECT_FLEET && SType() == SOBJECT_FLEET && Owner() == truedest->Owner()) { Fleet *flt = (Fleet *)this; for(int shp=0; shp < flt->NumShips(); ++shp) ((Fleet*)truedest)->AddShip(flt->GetShip(shp)); if(cur_object == this) cur_object = truedest; panel_draw(); RemapPositions(flt, truedest); flt->RemoveShips(0); } else if(truedest->SType() == SOBJECT_FLEET && SType() == SOBJECT_FLEET) { Fleet *flt = (Fleet*)this; flt->Attack((Fleet*)truedest); system = destination->system; orbit = destination->orbit; period = destination->period; startpos = destination->startpos; Trash(location); location = destination->location; Trash(destination); destination = destination->destination; //FIXME! Two attacking each other! } else if(truedest->SType() == SOBJECT_FLEET) { system = destination->system; orbit = destination->orbit; period = destination->period; startpos = destination->startpos; Trash(location); location = destination->location; Trash(destination); destination = destination->destination; } }