move / resize bug in Relative mode

Use this forum for:
- Discussion regarding unofficial CEGUI related tools, scripts and utilities.
- User to user help for the obsoleted CELayoutEditor and CEImagesetEditor tools.

Moderators: CEGUI MVP, CEGUI Team

User avatar
Sinjaph
Just popping in
Just popping in
Posts: 1
Joined: Tue Jul 26, 2005 13:29

move / resize bug in Relative mode

Postby Sinjaph » Tue Jul 26, 2005 13:55

I dont know if this has already been fixed ( I dont have access to CVS now) but child windows move / resize is not correct if the window is at relative mode. Here is a fix for this bug:

Code: Select all

void CCELayoutEditorDoc::mouseMoved (int iMouseX, int iMouseY)
{
  CSelection::WindowIterator windowIt ;
  CSelection::ResizerIterator resizerIt ;

  char p_chStatusInfo [100];
  bool bChanges = true ;
   float pixelDiffX, pixelDiffY ;
  float relativeDiffX, relativeDiffY ;
  float pixelMinimumW, pixelMinimumH ;
  float relativeMinimumW, relativeMinimumH ;
  float diffX, diffY ;

  // Copy parameters into members
   m_iMouseX = iMouseX ;
   m_iMouseY = iMouseY ;

  // Minimum status bar text
  sprintf (p_chStatusInfo, "[%d, %d][%3.2f, %3.2f]", iMouseX, iMouseY, (double) iMouseX / m_iWidth, (double) iMouseY / m_iHeight) ;

  // Only proceed when the mouse is pressed
  if (m_bMousePressed)
  {
    // Calculate both value-type, so the code below can choose,
    // based on the metric modes of the elements.

    // Calculate pixel differences with the previous mouse position.
    pixelDiffX = (float)(m_iMouseX - m_iPreviousMouseX) ;
    pixelDiffY = (float)(m_iMouseY - m_iPreviousMouseY) ;
    pixelMinimumW = 1 ; // pixel
    pixelMinimumH = 1 ; // pixel
 
    // Calculate relative differences with the previous mouse position.
    relativeDiffX = pixelDiffX / (float) m_iWidth ;
    relativeDiffY = pixelDiffY / (float) m_iHeight ;
    relativeMinimumW = pixelMinimumW / (float) m_iWidth ;
    relativeMinimumH = pixelMinimumH / (float) m_iHeight ;

    if (m_iHoveredResizePoint != RESIZE_POINT_NONE)
    {     
      // We need to resize of reposition
      for (windowIt = m_selection.getSelectedWindows().begin();
        windowIt != m_selection.getSelectedWindows().end(); ++windowIt)
      {
        // Handy pointer
        Window* pWindow = (*windowIt);
       
        // Calculate the differences according to the metrics mode of the window. This way we will modify
        // values within the same measurement.
        float minimumW, minimumH ;
        if (pWindow->getMetricsMode () == CEGUI::Absolute)
        {
          diffX = pixelDiffX ;
          diffY = pixelDiffY ;
          minimumW = pixelMinimumW ;
          minimumH = pixelMinimumH ;
        }
        else if (pWindow->getMetricsMode () == CEGUI::Relative)
        {
         [color=FF0000]if (pWindow->getParent())
         {
            diffX = pixelDiffX / (float)pWindow->getParent()->getAbsoluteWidth();
            diffY = pixelDiffY  / (float)pWindow->getParent()->getAbsoluteHeight();
         }
         else
         {
            diffX = relativeDiffX;
            diffY = relativeDiffY;
         }[/color]
         minimumW = relativeMinimumW ;
         minimumH = relativeMinimumH ;
        }
        else
        {
          // unsupported
          continue ;
        }
       
        // Avoid negative widths and heights
        if (pWindow->getXPosition () + pWindow->getWidth () + diffX < pWindow->getXPosition () + minimumW ||
          pWindow->getYPosition () + pWindow->getHeight () + diffY < pWindow->getYPosition () + minimumH)
        {
          // Don't allow update (for all elements at the moment).
          continue ;
        }
       
        // Type of movement depends on the selected resize part.
        switch (m_iHoveredResizePoint)
        {
          case RESIZE_POINT_WN:
            pWindow->setXPosition (pWindow->getXPosition () + diffX) ;
            pWindow->setWidth (pWindow->getWidth () - diffX) ;
            pWindow->setYPosition (pWindow->getYPosition () + diffY) ;
            pWindow->setHeight (pWindow->getHeight () - diffY) ;
            break;

          case RESIZE_POINT_N:
            pWindow->setYPosition (pWindow->getYPosition () + diffY) ;
            pWindow->setHeight (pWindow->getHeight () - diffY) ;
            break;

          case RESIZE_POINT_NE:
            pWindow->setYPosition (pWindow->getYPosition () + diffY) ;
            pWindow->setHeight (pWindow->getHeight () - diffY) ;
            pWindow->setWidth (pWindow->getWidth () + diffX) ;
            break;
       
          case RESIZE_POINT_E:
            pWindow->setWidth (pWindow->getWidth () + diffX) ;
            break;

          case RESIZE_POINT_ES:       
            pWindow->setWidth (pWindow->getWidth () + diffX) ;
            pWindow->setHeight (pWindow->getHeight () + diffY) ;
            break;
       
          case RESIZE_POINT_S:
            pWindow->setHeight (pWindow->getHeight () + diffY) ;
            break;

          case RESIZE_POINT_SW:
            pWindow->setXPosition (pWindow->getXPosition () + diffX) ;
            pWindow->setWidth (pWindow->getWidth () - diffX) ;
            pWindow->setHeight (pWindow->getHeight () + diffY) ;
            break;

          case RESIZE_POINT_W:
            pWindow->setXPosition (pWindow->getXPosition () + diffX) ;
            pWindow->setWidth (pWindow->getWidth () - diffX) ;
            break;
          default:
            break;
        }
     
        bChanges = true ;
       }
    }

    else if (m_pHoveredWindow)
    {
      // Drag selection
      for (windowIt = m_selection.getSelectedWindows().begin();
        windowIt != m_selection.getSelectedWindows().end(); ++windowIt)
      {
        // Handy pointer
        Window* pWindow = (*windowIt);
       
        // Just use the methods here, not the 'get' and 'set' param stuff
        // Choose metrics mode
        if (pWindow->getMetricsMode () == CEGUI::Absolute)
        {
          diffX = pixelDiffX ;
          diffY = pixelDiffY ;
        }
        else if (pWindow->getMetricsMode () == CEGUI::Relative)
        {
         [color=FF0000]if (pWindow->getParent())
         {
            diffX = pixelDiffX / (float)pWindow->getParent()->getAbsoluteWidth();
            diffY = pixelDiffY  / (float)pWindow->getParent()->getAbsoluteHeight();
         }
         else
         {
            diffX = relativeDiffX;
            diffY = relativeDiffY;
         }[/color]
        }
        pWindow->setXPosition (pWindow->getXPosition () + diffX) ;
        pWindow->setYPosition (pWindow->getYPosition () + diffY) ;
      } 
      bChanges = true ;
    }

    if (bChanges)
    {
      // Update the resizers position or size
      for (resizerIt = m_selection.getResizersBegin(); resizerIt != m_selection.getResizersEnd(); ++resizerIt)
      {       
        (*resizerIt)->reset();
      }

      onModify();
    }
  }

  else
  {
    // Mouse not pressed:
    // Find hovered resize point or window
    if (m_pActiveLayout != NULL)
    {
      for (resizerIt = m_selection.getResizersBegin(); resizerIt != m_selection.getResizersEnd(); ++resizerIt)
      {       
        m_iHoveredResizePoint = (*resizerIt)->getPointAtPosition (Point ((float)m_iMouseX, (float)m_iMouseY)) ;
        if (m_iHoveredResizePoint != RESIZE_POINT_NONE)
        {
          //HCURSOR hCursor; 
          // Load the predefined Windows "up arrow" cursor.
          //hCursor = AfxGetApp()->LoadStandardCursor(IDC_UPARROW);
          break;
        }
      }

      if (m_iHoveredResizePoint == RESIZE_POINT_NONE)
      {
        // Didn't find resize point, try window
        m_pHoveredWindow = m_pActiveLayout->getChildAtPosition(Point((float)m_iMouseX, (float)m_iMouseY)) ;
      }
    }
  }

  if (m_iHoveredResizePoint != RESIZE_POINT_NONE)
  {
    m_pHoveredWindow = NULL;
    sprintf (p_chStatusInfo, "%s ResizePoint: %d", p_chStatusInfo, m_iHoveredResizePoint);
  }
  else if (m_pHoveredWindow != NULL)
  {
    m_iHoveredResizePoint = RESIZE_POINT_NONE;
    sprintf (p_chStatusInfo, "%s Window: %s", p_chStatusInfo, m_pHoveredWindow->getName().c_str());
    // Selectable?
    if (m_pHoveredWindow->getName().find((utf8*)"__auto_") != CEGUI::String::npos || m_pHoveredWindow->getName().find((utf8*)"__TabPane__") != CEGUI::String::npos)
    {
      // No, add to status info
      sprintf (p_chStatusInfo, "%s (not selectable)", p_chStatusInfo);
    }
  }

  updateStatusBar (p_chStatusInfo);


  // Reset previous values
   m_iPreviousMouseX = m_iMouseX ;
  m_iPreviousMouseY = m_iMouseY ;
}

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Re: move / resize bug in Relative mode

Postby scriptkid » Tue Jul 26, 2005 18:34

Hi,

thanks for the post! :-) I will add it to the new (ported) version!

Kind regards.


Return to “Unofficial CEGUI-Related Tools”

Who is online

Users browsing this forum: No registered users and 5 guests