/** Mouse Over Event */
void WorldMapControl::OnMouseOver(unsigned short x, unsigned short y)
{
	WorldMap* worldmap = core->GetWorldMap();
	lastCursor = IE_CURSOR_GRAB;

	if (MouseIsDown) {
		AdjustScrolling(lastMouseX-x, lastMouseY-y);
	}

	lastMouseX = x;
	lastMouseY = y;

	if (Value!=(ieDword) -1) {
		x =(ieWord) (x + ScrollX);
		y =(ieWord) (y + ScrollY);

		WMPAreaEntry *oldArea = Area;
		Area = NULL;

		unsigned int i;
		unsigned int ec = worldmap->GetEntryCount();
		for (i=0;i<ec;i++) {
			WMPAreaEntry *ae = worldmap->GetEntry(i);

			if ( (ae->GetAreaStatus() & WMP_ENTRY_WALKABLE)!=WMP_ENTRY_WALKABLE) {
				continue; //invisible or inaccessible
			}

			Sprite2D *icon=ae->GetMapIcon(worldmap->bam);
			int h=0, w=0, iconx=0, icony=0;
			if (icon) {
				h=icon->Height;
				w=icon->Width;
				iconx = icon->XPos;
				icony = icon->YPos;
				core->GetVideoDriver()->FreeSprite( icon );
			}
			if (ftext && ae->GetCaption()) {
				int tw = ftext->CalcStringWidth( (unsigned char*)ae->GetCaption() ) + 5;
				int th = ftext->maxHeight;
				if(h<th)
					h=th;
				if(w<tw)
					w=tw;
			}
			if (ae->X - iconx > x) continue;
			if (ae->X - iconx + w < x) continue;
			if (ae->Y - icony > y) continue;
			if (ae->Y - icony + h < y) continue;
			lastCursor = IE_CURSOR_NORMAL;
			Area=ae;
			if(oldArea!=ae) {
				RunEventHandler(WorldMapControlOnEnter);
			}
			break;
		}
	}

	Owner->Cursor = lastCursor;
}
Exemple #2
0
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;
}