示例#1
0
void nuiDecoration::GlobalToClientRect(nuiRect& rRect, const nuiWidget* pWidget) const
{
    nuiRect clientRect = GetIdealClientRect(pWidget);
//  nuiSize bordertop = GetBorder(nuiTop, pWidget);
//  nuiSize borderleft = GetBorder(nuiLeft, pWidget);
    nuiSize borderright = GetBorder(nuiRight, pWidget);
    nuiSize borderbottom = GetBorder(nuiBottom, pWidget);


    float X1 = (float)clientRect.Left();
    float X2 = (float)clientRect.Right();
    float X3 = (float)clientRect.Right()+borderright;

    float Y1 = (float)clientRect.Top();
    float Y2 = (float)clientRect.Bottom();
    float Y3 = (float)clientRect.Bottom()+borderbottom;

    const float x0 = (float)rRect.Left();
    const float x1 = x0 + X1;
    const float x3 = (float)rRect.Right();
    const float x2 = x3 - (X3 - X2);

    const float y0 = (float)rRect.Top();
    const float y1 = y0 + Y1;
    const float y3 = (float)rRect.Bottom();
    const float y2 = y3 - (Y3 - Y2);

    rRect.Set(x1, y1, x2, y2, false);
}
示例#2
0
bool nuiWindowManager::ValidateWindowRect(nuiRect& rRect) const
{
  bool res = true;
  
  if (rRect.mTop > (mRect.GetHeight() - 10))
  {
    rRect.Move(0, mRect.GetHeight() - 10 - rRect.mTop);
    res = false;
  }
  if (rRect.mTop < 0)
  {
    rRect.Move(0, - rRect.mTop);
    res = false;
  }
  
  if (rRect.mLeft > (mRect.GetWidth() - 10))
  {
    rRect.Move(mRect.GetWidth() - 10 - rRect.mLeft, 0);
    res = false;
  }
  if (rRect.mRight < 10)
  {
    rRect.Move(10 - rRect.mRight, 0);
    res = false;
  }
  return res;
}
示例#3
0
void nuiGLDrawContext::BlurRect(const nuiRect& rRect, uint Strength)
{
  nuiRect Rect = rRect;
  if (mClippingRect.mEnabled)
    Rect.Intersect(mClippingRect,rRect);
  nuiRect size = Rect.Size();

  nuiTexture* pScratchPad = GetScratchPad(ToZero(size.GetWidth()), ToZero(size.GetHeight()));

  if (!pScratchPad)
    return;

  SetTexture(pScratchPad);

  glPushMatrix();
  glLoadIdentity();

  EnableBlending(true);
  EnableTexture2D(true);
  SetBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  do
  {
    glCopyTexSubImage2D(
      GL_TEXTURE_2D, 0, 
      0, 0, 
      ToZero(rRect.mLeft), ToZero(mHeight) - 1 - ToZero(rRect.mTop) - ToZero(rRect.GetHeight()), 
      ToZero(rRect.GetWidth()), ToZero(rRect.GetHeight())
      );

    SetFillColor(nuiColor(1,1,1,.15f));
    nuiRect rect = Rect;

    rect.Move(-1,-1);
    DrawImage(rect,size);
    rect.Move(1,0);
    DrawImage(rect,size);
    rect.Move(1,0);
    DrawImage(rect,size);

    rect.Move(-2,1);
    DrawImage(rect,size);
    rect.Move(1,0);
    DrawImage(rect,size);
    rect.Move(1,0);
    DrawImage(rect,size);

    rect.Move(-2,1);
    DrawImage(rect,size);
    rect.Move(0,1);
    DrawImage(rect,size);
    rect.Move(0,1);
    DrawImage(rect,size);
  } while ((long)(Strength--) > 0);

  EnableBlending(false);
  EnableTexture2D(false);

  glPopMatrix();
}
示例#4
0
nuiSoftwarePainter::nuiSoftwarePainter(const nuiRect& rRect, nglContext* pContext)
: nuiPainter(rRect, pContext)
{
  mWidth = ToNearest(rRect.GetWidth());
  mHeight = ToNearest(rRect.GetHeight());
  mpRasterizer = new nuiRasterizer(mWidth, mHeight);
  AddNeedTextureBackingStore();
}
示例#5
0
void nuiDrawContext::Set2DProjectionMatrix(const nuiRect& rRect)
{
  //printf("Set2DProjectionMatrix: %s\n", rRect.GetValue().GetChars());
  nuiMatrix m;
  m.Translate(-1.0f, 1.0f, 0.0f);
  m.Scale(2.0f/rRect.GetWidth(), -2.0f/rRect.GetHeight(), 1.0f);
  LoadProjectionMatrix(rRect, m);
}
示例#6
0
nuiSize nuiPopupMenu::AdjustRectsPos(nuiSize& rX, nuiSize& rY, uint depth, nuiRect CurRect)
{
  nuiTopLevel* pRoot = GetTopLevel();
  NGL_ASSERT(pRoot);
  NGL_ASSERT(depth+1 < mRects.size());
  nuiRect MainRect = pRoot->GetRect();
  nuiRect& prevRect(mRects[depth]->mRect); // prevRect is the previous rect in the hierarchy (NOT the previous rect of this sub menu)
  depth++;

  nuiMenuRect* pMenuRect = mRects[depth];
  nuiRect& rRect(pMenuRect->mRect);

  nuiSize x, y;
  x = rX + (mXdir * rRect.GetWidth()) - (mXdir < 0 ? prevRect.GetWidth() : 0); // Compute X so that the rect doesn't get out of the main container
  y = rY + (mYdir * rRect.GetHeight()) + (mYdir < 0 ? CurRect.GetHeight() : 0); // Compute Y so that the rect doesn't get out of the main container
  if (x > MainRect.GetWidth() || x < 0) // Should we change the current x direction?
    mXdir *= -1;
  if (y > MainRect.GetHeight() || y < 0)  // Should we change the current y direction?
    mYdir *= -1;

  rX = rX - ((mXdir < 0) ? rRect.GetWidth()  + prevRect.GetWidth() : 0);
  rY = rY - ((mYdir < 0) ? rRect.GetHeight() - CurRect.GetHeight() : 0);

  if (rY < 0)
    rY = 0;
  if ( 
    ( (mYdir > 0) && (MainRect.GetHeight() < (rY + rRect.GetHeight()) ) ) ||
    ( (mYdir < 0) && (0 > (rY - rRect.GetHeight()) ) )
    )
  {
    nuiSize heightDiff = MainRect.GetHeight() - rRect.GetHeight();
    if (heightDiff > 0)
    {
      rY = heightDiff;
    }
    else
    {
      nuiRect r( ToNearest(rX + rRect.GetWidth() - SB_WIDTH), 0, ToNearest(SB_WIDTH), ToNearest(MainRect.GetHeight()));
      pMenuRect->mpSBar->GetRange().SetRange(0.f, rRect.GetHeight());
      pMenuRect->mpSBar->GetRange().SetPageSize(MainRect.GetHeight());
      pMenuRect->mpSBar->GetRange().SetIncrement(10.f);

      pMenuRect->mpSBar->SetLayout(r);
      pMenuRect->mpSBar->SetVisible(true);
      pMenuRect->mpSBar->SetSelected(false);
      pMenuRect->mpSBar->SetEnabled(true);
      rY = -pMenuRect->mpSBar->GetRange().GetValue();
      return (SB_WIDTH);
    }
  }
  if (pMenuRect->mpSBar)
  {
    pMenuRect->mpSBar->SetVisible(false);
    pMenuRect->mpSBar->SetEnabled(false);
  }
  return (0.f);
}
示例#7
0
void nuiPopupMenu::CalcTreeSize(nuiRect& rRect, nuiTreeNode* pTree, uint32& cpt)
{
  NGL_ASSERT(pTree); // no chance to happen
  cpt++;
  nuiRect rect(0,0,0,0);
  nuiWidgetPtr pWidget;
  nuiRect WidgetRect;

  uint32 depth = cpt;

  uint32 count = pTree->GetChildrenCount();
  if (count <= 0)
    return;

  bool HasNonEmpty = false;

  for (uint32 i = 0; i < count; i++)
  {
    nuiTreeNode* pNode = dynamic_cast<nuiTreeNode*>(pTree->GetChild(i));
    NGL_ASSERT(pNode);
    pWidget = pNode->GetElement();
    NGL_ASSERT(pWidget);
    WidgetRect = pWidget->GetIdealRect();
    rect.SetSize(MAX(rect.GetWidth(), WidgetRect.GetWidth()), rect.GetHeight() + WidgetRect.GetHeight());
    if (!pNode->IsEmpty())
    {
      HasNonEmpty = true;
    }
    if (pNode->IsOpened())
    {
      if (mRects.size() <= depth + 1) // ensure that there is a rect for the next node
      {
        nuiMenuRect* pMenuRect = new nuiMenuRect(this, cpt+1);
        mRects.push_back(pMenuRect);
        mPopupTreeSink.Connect(pMenuRect->mpSBar->ValueChanged, &nuiPopupMenu::OnScrollBarChange, pMenuRect);
      }
      mRects[depth+1]->mpFromNode = pNode;
      CalcTreeSize(rRect, pNode, cpt);
    }
  }
  if (HasNonEmpty)
  {
    mRects[depth]->mHasNonEmpty = true;
    rect.SetSize(rect.GetWidth() + NUI_POPUP_TREE_HANDLE_SIZE * 2, rect.GetHeight());
  }
  else
  {
    mRects[depth]->mHasNonEmpty = false;
  }

  mRects[depth]->mRect = rect;
  NGL_ASSERT(mRects.size() >= depth+1);
  rRect.SetSize(rect.GetWidth()+rRect.GetWidth(), rect.GetHeight()+rRect.GetHeight());
}
示例#8
0
void nuiMetaPainter::LoadProjectionMatrix(const nuiRect& rViewport, const nuiMatrix& rMatrix)
{
  StoreOpCode(eLoadProjectionMatrix);
  StoreFloat(rViewport.Left());
  StoreFloat(rViewport.Top());
  StoreFloat(rViewport.GetWidth());
  StoreFloat(rViewport.GetHeight());
  StoreBuffer(rMatrix.Array, sizeof(nuiSize), 16);  
  
  nuiPainter::LoadProjectionMatrix(rViewport, rMatrix);
}
示例#9
0
void nuiPainter::LoadProjectionMatrix(const nuiRect& rViewport, const nuiMatrix& rMatrix)
{
  NGL_ASSERT(!mProjectionMatrixStack.empty());
  mProjectionMatrixStack.top() = rMatrix;

  nuiMatrix LocalMatrix(mMatrixStack.top());
  nuiVector vec1(rViewport.Left(), rViewport.Top(), 0.0f);
  nuiVector vec2(rViewport.Right(), rViewport.Bottom(), 0.0f);
  vec1 = LocalMatrix * vec1;
  vec2 = LocalMatrix * vec2;
  mProjectionViewportStack.top().Set(vec1[0], vec1[1], vec2[0], vec2[1], false);
}
示例#10
0
void nuiTexture::TextureToImageCoord(nuiRect& rRect) const
{
  nuiSize x, y, xx, yy;
  x = rRect.Left();
  y = rRect.Top();
  xx = rRect.Right();
  yy = rRect.Bottom();
  TextureToImageCoord(x, y);
  TextureToImageCoord(xx, yy);
  
  rRect.Set(x, y, xx, yy, false);
}
示例#11
0
void nuiDecoration::ClientToGlobalRect(nuiRect& rRect, const nuiWidget* pWidget) const
{
    nuiSize bordertop = GetBorder(nuiTop, pWidget);
    nuiSize borderleft = GetBorder(nuiLeft, pWidget);
    nuiSize borderright = GetBorder(nuiRight, pWidget);
    nuiSize borderbottom = GetBorder(nuiBottom, pWidget);

    rRect.Set(rRect.Left() - borderleft,
              rRect.Top() - bordertop,
              rRect.Right() + borderright,
              rRect.Bottom() + borderbottom,
              false);


}
示例#12
0
///////////////////////////////////
// nuiPainter implementation:
nuiPainter::nuiPainter(const nuiRect& rRect, nglContext* pContext) 
{
  ResetStats();
  mWidth = ToNearest(rRect.GetWidth());
  mHeight = ToNearest(rRect.GetHeight());
  mMatrixStack.push(nuiMatrix());
  mProjectionMatrixStack.push(nuiMatrix());
  mProjectionViewportStack.push(nuiRect());
  
  mDummyMode = false;
  mpSurface = NULL;

  mAngle=0;

  mEnableDrawArray = true;
}
示例#13
0
/****************************************************************************
 *
 * Constructor / Destructor
 *
 ****************************************************************************/
nuiDrawContext::nuiDrawContext(const nuiRect& rRect)
{
  mWidth = rRect.GetWidth();
  mHeight = rRect.GetHeight();

  mClipOffsetX = mClipOffsetY = 0;

  mPermitAntialising = true;

  mpPainter = NULL;
  mpMainPainter = NULL;
  mpSavedPainter = NULL;
  mpAATexture = nuiTexture::GetAATexture();
  
  mStateChanges = 1;
}
示例#14
0
bool nuiStateDummy::SetRect(const nuiRect& rRect)
{
  nuiWidget::SetRect(rRect);
  nuiWidgetPtr pWidget = mpState[(IsEnabled(mCombined)?1:0) + (IsSelected(mCombined)?2:0)];
  if (pWidget)
    pWidget->SetLayout(rRect.Size());
  return true;
}
示例#15
0
bool nuiLabel::SetRect(const nuiRect& rRect)
{
  bool needRecalcLayout = false;

  if (mUseEllipsis || mWrapping)
    needRecalcLayout = (rRect.GetWidth() != mRect.GetWidth());
    
  nuiWidget::SetRect(rRect);

  nuiRect ideal(mIdealLayoutRect);


  if (needRecalcLayout || ideal.GetWidth() > mRect.GetWidth())
  {
    if (mUseEllipsis)
    {
      CalcLayout();
      nuiSize diff = ideal.GetWidth() - mRect.GetWidth();
      int NbLetterToRemove = ToNearest(diff / (ideal.GetWidth() / mText.GetLength())) + 3;
      nglString text = mText;
      if (NbLetterToRemove > 0)
      {
        int len = text.GetLength();
        text.DeleteRight(MIN(NbLetterToRemove, len));
        text.Append(_T("..."));
      }
      delete mpLayout;
      mpLayout = new nuiTextLayout(mpFont);
      mpLayout->SetWrapX(0);
      mpLayout->Layout(text);
      GetLayoutRect();
    }
    else if (mWrapping)
    {
      CalcLayout();
      delete mpLayout;
      mpLayout = new nuiTextLayout(mpFont);
      delete mpIdealLayout;
      mpIdealLayout = new nuiTextLayout(mpFont);
      mpLayout->SetWrapX(mRect.GetWidth() - mBorderLeft - mBorderRight);
      mpIdealLayout->SetWrapX(mRect.GetWidth() - mBorderLeft - mBorderRight);
      mpLayout->Layout(mText);
      mpIdealLayout->Layout(mText);
      GetLayoutRect();
    }

    SetToolTip(mText);
  }
  else
  {
    if (GetToolTip() == mText)
      SetToolTip(nglString::Empty);
  }

  return true;
}
示例#16
0
void nuiImageDecoration::Draw(nuiDrawContext* pContext, nuiWidget* pWidget, const nuiRect& rDestRect)
{
  if (!mpTexture || !mpTexture->GetImage() || !mpTexture->GetImage()->GetPixelSize())
    return;
  
  pContext->PushState();
  pContext->ResetState();
  
  nuiRect rect = mClientRect;
  rect.SetPosition(mPosition, rDestRect);
  rect.RoundToBelow();
  
  pContext->EnableTexturing(true);
  pContext->EnableBlending(true);
  pContext->SetBlendFunc(nuiBlendTransp);
  pContext->SetTexture(mpTexture);
  nuiColor col(mColor);
  if (mUseWidgetAlpha && pWidget)
    col.Multiply(pWidget->GetMixedAlpha());
  
  pContext->SetFillColor(col);
  
  nuiRect srcrect(mClientRect);
  if (mRepeatX)
  {
    srcrect.SetWidth(rDestRect.GetWidth());
    srcrect.MoveTo(0, srcrect.Top());
  }

  if (mRepeatY)
  {
    srcrect.SetHeight(rDestRect.GetHeight());
    srcrect.MoveTo(srcrect.Left(), 0);
  }

  if (mRepeatX || mRepeatY)
    rect = rDestRect;
  
  
  pContext->DrawImage(rect, srcrect);
  //pContext->DrawRect(rDestRect, eStrokeShape);
  pContext->PopState();
}
示例#17
0
bool nuiPositioner::SetRect(const nuiRect& rRect)
{
    nuiWidget::SetRect(rRect);

    //NGL_OUT(_T("nuiPositioner::SetRect: %d x %d\n"),(int)rRect.GetWidth(),(int)rRect.GetHeight());

    nuiWidget::LayoutConstraint contraint;
    contraint.mMaxWidth = rRect.GetWidth();
    contraint.mMaxHeight = rRect.GetHeight();

    IteratorPtr pIt;
    for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
    {
        nuiWidgetPtr pItem = pIt->GetWidget();
        pItem->SetLayoutConstraint(contraint);
    }
    delete pIt;

    mIdealRect = CalcIdealSize();

    nuiRect mainrect(rRect.Size());

    pIt = NULL;
    for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
    {
        nuiWidgetPtr pItem = pIt->GetWidget();
        nuiRect rect = pItem->GetIdealRect().Size();
        if (mExpandWidth)
            rect.SetSize(mainrect.GetWidth(), rect.GetHeight());
        if (mExpandHeight)
            rect.SetSize(rect.GetWidth(), mainrect.GetHeight());

        rect.SetPosition(mPPosition, mainrect);
        if (mLimitBounds)
            rect.Intersect(rect, mainrect);
        rect.RoundToBiggest();
        pItem->SetLayout(rect);
    }
    delete pIt;

    return true;
}
示例#18
0
bool nuiLayout::SetRect(const nuiRect& rRect)
{
  nuiWidget::SetRect(rRect);

  //NGL_OUT("nuiLayout::SetRect(%s)\n", rRect.GetValue().GetChars());
  
  nuiRect r(rRect.Size());
  DoLayout(r);
  
  return true;
}
示例#19
0
static void nuiDrawRect(const nuiRect& out, nuiRenderArray& rArray)
{
  rArray.SetMode(GL_TRIANGLE_STRIP);
  rArray.Reserve(8);
  nuiRect in(out);
  in.Grow(-nuiGetInvScaleFactor(), -nuiGetInvScaleFactor());
  
  rArray.SetVertex(out.Left(), out.Top()); rArray.PushVertex();
  rArray.SetVertex(in.Left(), in.Top()); rArray.PushVertex();

  rArray.SetVertex(out.Right(), out.Top()); rArray.PushVertex();
  rArray.SetVertex(in.Right(), in.Top()); rArray.PushVertex();
  
  rArray.SetVertex(out.Right(), out.Bottom()); rArray.PushVertex();
  rArray.SetVertex(in.Right(), in.Bottom()); rArray.PushVertex();
  
  rArray.SetVertex(out.Left(), out.Bottom()); rArray.PushVertex();
  rArray.SetVertex(in.Left(), in.Bottom()); rArray.PushVertex();

  rArray.SetVertex(out.Left(), out.Top()); rArray.PushVertex();
  rArray.SetVertex(in.Left(), in.Top()); rArray.PushVertex();
}
示例#20
0
bool nuiButton::SetRect(const nuiRect& rRect)
{
  nuiWidget::SetRect(rRect);
  nuiRect Rect = rRect.Size();

  IteratorPtr pIt;
  for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
  {
    nuiWidgetPtr pItem = pIt->GetWidget();
    if (pItem)
      pItem->SetLayout(Rect);
  }
  delete pIt;
  return true;
}
示例#21
0
bool nuiTabBar::SetRect(const nuiRect& rRect)
{
  nuiSize width = 0;
  nuiWidget::SetRect(rRect);

  IteratorPtr pIt;  
  for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
  {
    nuiWidgetPtr pItem = pIt->GetWidget();
    const nuiRect  &childIdealRect = pItem->GetIdealRect();
    nuiRect rect(width, rRect.Top(), childIdealRect.GetWidth(), childIdealRect.GetHeight());
    width += childIdealRect.GetWidth();
    pItem->SetLayout(rect);
  }
  delete pIt;

  return true;
}
示例#22
0
bool nuiWindow::SetRect(const nuiRect& rRect)
{
  //NGL_OUT(_T("nuiWindow::SetRect\n"));
  nuiWidget::SetRect(rRect);

  nuiRect Rect = GetRectFromFlags(rRect.Size(), GetFlags(), false);

  LayoutConstraint  constraint;
  constraint.mMaxWidth = Rect.GetWidth();
  constraint.mMaxHeight = Rect.GetHeight();

  nuiWidgetList::iterator it;
  nuiWidgetList::iterator end = mpChildren.end();

  for (it=mpChildren.begin(); it != end; ++it)
  {
    nuiWidgetPtr pItem = *it;
    
    if (pItem != mpCloseButton)
    {
      if (mStaticChildren)
      {
        // Children are static, honor their size and position requests.
        pItem->SetLayout(pItem->GetIdealRect());
      }
      else
      {
        // Children are not static, let's ignore their request...
        pItem->SetLayoutConstraint(constraint);
        pItem->GetIdealRect();
        pItem->SetLayout(Rect);
      }
    }
    else
    {
      nuiRect r(Rect);
      r.Move(Rect.GetWidth() - 18, -21);
      r.SetSize((long)12,(long)15);
      pItem->SetLayout(r);
    }
  }

  return true;
}
示例#23
0
bool nuiContainer::SetRect(const nuiRect& rRect)
{
  CheckValid();
  nuiWidget::SetRect(rRect);

  nuiRect rect(rRect.Size());
  IteratorPtr pIt;
  for (pIt = GetFirstChild(false); pIt && pIt->IsValid(); GetNextChild(pIt))
  {
    nuiWidgetPtr pItem = pIt->GetWidget();
    if (mCanRespectConstraint)
      pItem->SetLayoutConstraint(mConstraint);
    pItem->GetIdealRect();
    pItem->SetLayout(rect);
  }
  delete pIt;

  DebugRefreshInfo();
  return true;
}
示例#24
0
bool nuiToggleButton::SetRect(const nuiRect& rRect)
{
  if (mDisplayAsFrameBox)
  {
    nuiWidget::SetRect(rRect);
    nuiRect rect(rRect.Size());
    //rect.Grow(-2,-2);

    IteratorPtr pIt;
    for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
    {
      nuiWidgetPtr pItem = pIt->GetWidget();
      if (mCanRespectConstraint)
        pItem->SetLayoutConstraint(mConstraint);
      pItem->GetIdealRect();
      pItem->SetLayout(rect);
    }
    delete pIt;
    return true;
  }
  return nuiButton::SetRect(rRect);
}
示例#25
0
bool nuiFrameView::SetRect(const nuiRect& rRect)
{
  nuiRect r(rRect.Size());
  if (mpFrame)
    mpFrame->GlobalToClientRect(r, this);
  nuiWidget::SetRect(rRect);
  
  IteratorPtr pIt;
  for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
  {
    nuiWidgetPtr pItem = pIt->GetWidget();
    if (mCanRespectConstraint)
      pItem->SetLayoutConstraint(mConstraint);
    pItem->GetIdealRect();
    r.RoundToSmallest();
    pItem->SetLayout(r);
  }
  delete pIt;
  
  DebugRefreshInfo();  
  return true;
}
示例#26
0
bool nuiPainter::GetClipRect(nuiRect& rRect, bool LocalRect) const
{
  if (mClip.mEnabled)
  {
    rRect = mClip;
  }
  else
  {
    rRect.Set(0, 0, mWidth, mHeight);
  }
  
  if (LocalRect)
  {
    // Transform the rect with the inverse of the current matrix
    nglMatrixf m(GetMatrix());
    m.InvertHomogenous();
    nglVectorf v1(rRect.Left(), rRect.Top(), 0, 1);
    nglVectorf v2(rRect.Right(), rRect.Bottom(), 0, 1);
    v1 = m * v1;
    v2 = m * v2;
    rRect.Set(v1[0], v1[1], v2[0], v2[1], false);
  }
  return mClip.mEnabled;
}
示例#27
0
void nuiContainer::InternalSetLayout(const nuiRect& rect, bool PositionChanged, bool SizeChanged)
{
  CheckValid();
  if (mNeedSelfLayout || SizeChanged)
  {
    mInSetRect = true;
    SetRect(rect);
    mInSetRect = false;
    Invalidate();
  }
  else
  {
    // Is this case the widget have just been moved inside its parent. No need to re layout it, only change the rect...
    mRect = rect;
    
    if (mNeedLayout)
    {
      // The children need to be re layed out (at least one of them!).
      nuiContainer::IteratorPtr pIt = GetFirstChild(false);
      do
      {
        nuiWidgetPtr pItem = pIt->GetWidget();
        if (pItem)
        {
          // The rect of each child doesn't change BUT we still ask for its ideal rect.
          nuiRect rect(pItem->GetBorderedRect());
          nuiRect ideal(pItem->GetIdealRect());
          
          if (pItem->HasUserPos()) 	 
          { 	 
            rect = ideal; 	 
          } 	 
          else if (pItem->HasUserSize())
          {
            rect.SetSize(ideal.GetWidth(), ideal.GetHeight());
          }
          else
          {
            // Set the widget to the size of the parent
          }
          
          pItem->SetLayout(rect);
        }
      } while (GetNextChild(pIt));
      delete pIt;
      
    }
  }
  
  //#TEST:
#ifdef NUI_CHECK_LAYOUTS
  IteratorPtr pIt;
  for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
  {
    nuiWidgetPtr pItem = pIt->GetWidget();
    if (pItem->IsVisible())
    {
      NGL_ASSERT(!pItem->GetNeedLayout());
    }
  }
  delete pIt;
  //#TEST end
#endif
}
示例#28
0
void nuiGLDrawContext::DrawGradient(const nuiGradient& rGradient, const nuiRect& rEnclosingRect, nuiSize x1, nuiSize y1, nuiSize x2, nuiSize y2)
{
  nglVector2f vec(x2 - x1, y2 - y1);
  nglVector2f para(-vec[1], vec[0]);
  nglVector2f vec1(vec);
  nglVector2f para1(para);
  vec1.Normalize();
  para1.Normalize();

  // What Quadrant are we in?:
  //         |
  //     a   |   b
  //         |
  //  ----------------
  //         |
  //     c   |   d
  //         |
  float xa, xb, xc, xd;
  float ya, yb, yc, yd;
  float x, y;
  float xp, yp;
  float xx, yy;
  float xxp, yyp;

  xa = xc = rEnclosingRect.Left();
  xb = xd = rEnclosingRect.Right();
  ya = yb = rEnclosingRect.Top();
  yc = yd = rEnclosingRect.Bottom();

  if (x1 < x2)
  {
    // Go from a to d or c to b
    if (y1 == y2)
    {
      x  = xa; y  = ya;
      xp = xc; yp = yc;
      xx = xd; yy = yd;
      xxp= xb; yyp= yb;
    }
    else if (y1 < y2)
    {
      // a to d
      IntersectLines(xa,ya, para1[0], para1[1], xb, yb, vec1[0], vec1[1], x, y);
      IntersectLines(xa,ya, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xp, yp);
      IntersectLines(xd,yd, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xx, yy);
      IntersectLines(xd,yd, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xxp, yyp);
    }
    else
    {
      // c to d
      IntersectLines(xc,yc, para1[0], para1[1], xa, ya, vec1[0], vec1[1], x, y);
      IntersectLines(xc,yc, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xp, yp);
      IntersectLines(xb,yb, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xx, yy);
      IntersectLines(xb,yb, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xxp, yyp);
    }
  }
  else
  {
    if (y1 == y2)
    {
      x  = xd; y  = yd;
      xp = xb; yp = yb;
      xx = xa; yy = ya;
      xxp= xc; yyp= yc;
    }
    else if (y1 < y2)
    {
      // b to c
      IntersectLines(xb,yb, para1[0], para1[1], xd, yd, vec1[0], vec1[1], x, y);
      IntersectLines(xb,yb, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xp, yp);
      IntersectLines(xc,yc, para1[0], para1[1], xa, ya, vec1[0], vec1[1], xx, yy);
      IntersectLines(xc,yc, para1[0], para1[1], xd, yd, vec1[0], vec1[1], xxp, yyp);
    }
    else
    {
      // d to a
      IntersectLines(xd,yd, para1[0], para1[1], xc, yc, vec1[0], vec1[1], x, y);
      IntersectLines(xd,yd, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xp, yp);
      IntersectLines(xa,ya, para1[0], para1[1], xb, yb, vec1[0], vec1[1], xx, yy);
      IntersectLines(xa,ya, para1[0], para1[1], xc, yc, vec1[0], vec1[1], xxp, yyp);
    }
  }

  float startx,starty;
  float startxp,startyp;
  float stopx,stopy;
  float stopxp,stopyp;

  if (y1 != y2)
  {
    IntersectLines(x1, y1, para1[0], para1[1], x,  y,  vec1[0], vec1[1], startx,  starty);
    IntersectLines(x1, y1, para1[0], para1[1], xp, yp, vec1[0], vec1[1], startxp, startyp);
    IntersectLines(x2, y2, para1[0], para1[1], x,  y,  vec1[0], vec1[1], stopx,   stopy);
    IntersectLines(x2, y2, para1[0], para1[1], xp, yp, vec1[0], vec1[1], stopxp,  stopyp);
  }
  else
  {
    startx  = x1; starty  = y;
    startxp = x1; startyp = yp;
    stopx   = x2; stopy   = y;
    stopxp  = x2; stopyp  = yp;
  }

  nuiGradientStopList::const_iterator it = rGradient.GetStopList().begin();
  nuiGradientStopList::const_iterator end = rGradient.GetStopList().end();

  float px1, py1;
  float px2, py2;

  PushClipping();
  nuiRect r = rEnclosingRect;
  nglMatrixf m(GetMatrix());
  nglVectorf v1(r.Left(), r.Top(), 0);
  v1 = m * v1;
  nglVectorf v2 = nglVectorf(r.Right(), r.Bottom(), 0);
  v2 = m * v2;
  r.Set(v1[0], v1[1], v2[0], v2[1], false);

  Clip(r);
  SetClipping(true);

  std::vector<nuiShape::CacheElement::Vertex> vertices;

  nuiColor col = it->second;
  vertices.push_back(nuiShape::CacheElement::Vertex(x, y, col));
  vertices.push_back(nuiShape::CacheElement::Vertex(xp, yp, col));

  for ( ; it != end; ++it)
  {
    float r = it->first;
    float rm = 1.0f - r;
    px1 = startx * rm + stopx * r;
    py1 = starty * rm + stopy * r;
    px2 = startxp * rm + stopxp * r;
    py2 = startyp * rm + stopyp * r;

    col = it->second;
    vertices.push_back(nuiShape::CacheElement::Vertex(px1, py1, col));
    vertices.push_back(nuiShape::CacheElement::Vertex(px2, py2, col));
  }

  vertices.push_back(nuiShape::CacheElement::Vertex(xxp, yyp, col));
  vertices.push_back(nuiShape::CacheElement::Vertex(xx, yy, col));

  glEnableClientState(GL_COLOR_ARRAY);
  glEnableClientState(GL_VERTEX_ARRAY);
  glColorPointer(4,  GL_FLOAT, sizeof(nuiShape::CacheElement::Vertex), vertices[0].mColor);
  glVertexPointer(3, GL_FLOAT, sizeof(nuiShape::CacheElement::Vertex), vertices[0].mCoord);

  glDrawArrays(GL_QUAD_STRIP, 0, vertices.size());

  glDisableClientState(GL_COLOR_ARRAY);
  glDisableClientState(GL_VERTEX_ARRAY);

  PopClipping();
}
示例#29
0
bool nuiScrollView::SetRect(const nuiRect& rRect)
{
  #ifdef _DEBUG_LAYOUT
  if (GetDebug())
  {
    NGL_OUT(_T("nuiScrollView::SetRect: %s\n"), rRect.GetValue().GetChars());
  }
  #endif
      
  nuiWidget::SetRect(rRect);

  if (!mpHorizontal || !mpVertical)
    return false;

  nuiSize XOffset = mpHorizontal->GetRange().GetValue();
  nuiSize YOffset = mpVertical->GetRange().GetValue();

  if (mSmoothScrolling)
  {
    if (!mHThumbPressed)
      XOffset = mXOffset;
    if (!mVThumbPressed)
      YOffset = mYOffset;
  }

  mXOffset = XOffset;
  mYOffset = YOffset;

  XOffset = (nuiSize)ToNearest(XOffset);
  YOffset = (nuiSize)ToNearest(YOffset);

  GetIdealRect();
  nuiRect rIdealRect(mChildrenUnionRect); ///< needed because GetIdealRect may return a UserRect
  
  if (mMinimalResize)
  {
    rIdealRect.Right() = MAX(rIdealRect.Right(), mOldIdealRect.Right());
    rIdealRect.Bottom() = MAX(rIdealRect.Bottom(), mOldIdealRect.Bottom());
    mOldIdealRect = rIdealRect;
  }

  nuiSize x = rIdealRect.GetWidth();
  nuiSize y = rIdealRect.GetHeight();
  
  nuiRange& hrange = mpHorizontal->GetRange();
  nuiRange& vrange = mpVertical->GetRange();

  if (mMinimalResize)
  {
    if( (hrange.GetValue() + hrange.GetPageSize()) < hrange.GetMaximum() )
    {
      x = mChildrenUnionRect.GetWidth();
      mOldIdealRect = mChildrenUnionRect;
    }
    if( (vrange.GetValue() + vrange.GetPageSize()) < vrange.GetMaximum() )
    {
      y = mChildrenUnionRect.GetHeight();
      mOldIdealRect = mChildrenUnionRect;
    }
  }

  nuiSize xx = rRect.GetWidth();
  nuiSize yy = rRect.GetHeight();

  bool needv = y > yy;
  bool needh = x > xx;

  needh = needh && !mForceNoHorizontal;
  needv = needv && !mForceNoVertical;

  nuiSize scrollh = (needh && !mHorizontalIsExternal) ? mBarSize:0;
  nuiSize scrollv = (needv && !mVerticalIsExternal)   ? mBarSize:0;

  for (int i = 0; i<2; i++)
  {
    if (needv && !mForceNoHorizontal)
    {
      needh = x > (xx - scrollv);
      if (!mVerticalIsExternal)
        scrollv = needv?mBarSize:0;
    }
    
    if (needh && !mForceNoVertical)
    {
      needv = y > (yy - scrollh);
      if (!mHorizontalIsExternal)
        scrollh = needh?mBarSize:0;
    }
  }

  if (needh)
  {
    double pagesize = xx - scrollv;
    if (mHideScrollBars)
      pagesize = xx;
    hrange.SetRange(0, x);
    hrange.SetPageSize(MAX(0, pagesize));
    hrange.SetPageIncrement(MAX(0, pagesize));
    hrange.SetIncrement(mHIncrement);
    hrange.EnableEvents(false); 
    nuiSize oldv = hrange.GetValue();
    hrange.SetValue(hrange.GetValue()); 
    if (hrange.GetValue() != oldv)
    {
      mXOffset = hrange.GetValue();  
    }
    hrange.EnableEvents(true);
  }
  else
  {
    double pagesize = x;
    hrange.SetRange(0, x);
    hrange.SetPageSize(MAX(0, pagesize));
    hrange.SetPageIncrement(MAX(0, pagesize));
    hrange.SetIncrement(mHIncrement);
    mXOffset = XOffset= 0.f;  
    hrange.EnableEvents(false); 
    hrange.SetValue(XOffset); 
    hrange.EnableEvents(true);
  }
  
  if (needv)
  {
    double pagesize = yy - scrollh;
    if (mHideScrollBars)
      pagesize = yy;
    vrange.SetRange(0, y);
    vrange.SetPageSize(MAX(0, pagesize));
    vrange.SetPageIncrement(MAX(0, pagesize));
    vrange.SetIncrement(mVIncrement);
    vrange.EnableEvents(false); 
    nuiSize oldv = vrange.GetValue();
    vrange.SetValue(vrange.GetValue()); 
    if (vrange.GetValue() != oldv)
    {
      mYOffset = vrange.GetValue();  
    }
    vrange.EnableEvents(true);
  }
  else
  {
    double pagesize = y;
    vrange.SetRange(0, y);
    vrange.SetPageSize(MAX(0, pagesize));
    vrange.SetPageIncrement(MAX(0, pagesize));
    vrange.SetIncrement(mVIncrement);
    mYOffset = YOffset = 0.f;
    vrange.EnableEvents(false); 
    vrange.SetValue(YOffset); 
    vrange.EnableEvents(true);
  }
  OffsetsChanged();

  nuiSize scrollbarH = scrollh;
  nuiSize scrollbarV = scrollv;
  if (mHideScrollBars)
  {
    scrollbarH = 0;
    scrollbarV = 0;
  }
  SetChildrenRect(x, y, xx, yy, scrollbarV, scrollbarH);

  if (!mHorizontalIsExternal)
  {
    mpHorizontal->SetVisible(needh);
    mpHorizontal->SetLayout(nuiRect(0.0f, yy-scrollh, xx - scrollv, scrollh));
  }
  if (!mVerticalIsExternal)
  {
    mpVertical->SetVisible(needv);
    mpVertical->SetLayout(nuiRect(xx - scrollv, 0.0f, scrollv, yy-scrollh));
  }

  return true;
}
示例#30
0
void nuiRect::SetPosition(nuiPosition Position, const nuiRect& Inside)
{
  nuiSize x,y,w,h;
  nuiSize rx,ry,rw,rh;
  rx = Inside.mLeft;
  ry = Inside.mTop;
  rw = Inside.GetWidth();
  rh = Inside.GetHeight();
  w = GetWidth();
  h = GetHeight();
  x = (rw - w) / 2.f;
  y = (rh - h) / 2.f;

  switch (Position)
  {
  case nuiCenter:
    mLeft = x;
    mRight = x+w;
    mTop = y;
    mBottom = y+h;
    break;
  case nuiFill:
    mLeft=0;
    mRight=rw;
    mTop=0;
    mBottom=rh;
    break;
  case nuiFillHorizontal:
    mLeft=0;
    mRight=rw;
    mTop=y;
    mBottom=y+h;
    break;
  case nuiFillVertical:
    mLeft=x;
    mRight=x+w;
    mTop=0;
    mBottom=rh;
    break;
  case nuiFillLeft:
    mLeft=0;
    mRight=w;
    mTop=0;
    mBottom=rh;
    break;
  case nuiFillRight:
    mLeft = rw-w;
    mRight = rw;
    mTop = 0;
    mBottom = rh;
    break;
  case nuiFillTop:
    mLeft = 0;
    mRight = rw;
    mTop = 0;
    mBottom = h;
    break;
  case nuiFillBottom:
    mLeft = 0;
    mRight = rw;
    mTop = rh - h;
    mBottom = rh;
    break;
  case nuiLeft:
    mLeft=0;
    mTop =y; 
    mRight=w;
    mBottom=y+h;
    break;
  case nuiRight:
    mLeft=rw-w;
    mTop =y; 
    mRight=rw;
    mBottom=y+h;
    break;
  case nuiTop:
    mLeft=x;
    mTop =0; 
    mRight=x+w;
    mBottom=h;
    break;
  case nuiBottom:
    mLeft=x;
    mTop =rh-h; 
    mRight=x+w;
    mBottom=rh;
    break;
  case nuiTopLeft:
    mLeft=0;
    mRight=w;
    mTop=0;
    mBottom=h;
    break;
  case nuiTopRight:
    mLeft=rw-w;
    mRight=rw;
    mTop=0;
    mBottom=h;
    break;
  case nuiBottomLeft:
    mLeft=0;
    mRight=w;
    mTop=rh-h;
    mBottom=rh;
    break;
  case nuiBottomRight:
    mLeft=rw-w;
    mRight=rw;
    mTop=rh-h;
    mBottom=rh;
    break;
  case nuiTile:
    mLeft = 0;
    mRight= w;
    mTop = 0;
    mBottom =h;
    break;
  case nuiNoPosition:
	break;
  }

  Move(rx, ry);
}