Beispiel #1
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();
}
Beispiel #2
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);
}
Beispiel #3
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);
}
Beispiel #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();
}
Beispiel #5
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);
}
Beispiel #6
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());
}
Beispiel #7
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;
}
Beispiel #8
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;
}
Beispiel #9
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();
}
Beispiel #10
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;
}
Beispiel #11
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);
}
Beispiel #12
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;
}
Beispiel #13
0
//*******************************************
//
// ORIENTATION HORIZONTAL
//
bool nuiSplitter::SetRectHorizontal(const nuiRect& rRect)
{
  nuiSize Height = rRect.GetHeight();
  nuiSize Width = rRect.GetWidth();
  nuiRect Rect;
  
  nuiWidgetList::iterator it;
  nuiWidgetList::iterator end = mpChildren.end();

  list<nuiRect>::iterator rit = mPositions.begin();
  Rect = (*rit);

  ++rit;


  // First Child:
  nuiWidgetPtr pItem;
  Height = 0;
  // We only care about the first two widgets!
  int i;
  it = mpChildren.begin();
  i = 0;
  nuiSize h;
  
  // don't process the splitter handle before the first child (we need the size of the first child)
  if (it != end)
  {
    pItem = (*it);
    if (pItem == mpHandle)
      ++it;
  }


  if (it != end)
  {
    pItem = (*it);

    //*****************************************************
    //
    // MASTERCHILD TRUE
    if (mMasterChild)
    {
      h = pItem->GetIdealRect().GetHeight();

      mHandlePos = h;
      if (mMode == eModePercentage) 
      {
        mHandlePos = (mHandlePos / (rRect.GetHeight() * (mHandlePosMax / 100.0f))) * 100.0f; 
        h = mHandlePos;
      }
      
      Rect.Set(0.f, Height, Width, h);
      Rect.RoundToBelow();
    }

    // MASTERCHILD FALSE
    else
    {
      h = mHandlePos;

      if (mMode == eModePercentage) 
        h = mRect.GetHeight() * (h / 100.0f);

      h = MAX(h, mFirstWidgetMinPixels);

      if (h + mSeconWidgetMinPixels > mRect.GetHeight())
      {
        h = mRect.GetHeight() - mSeconWidgetMinPixels;

        mHandlePos = h;
        if (mMode == eModePercentage)
          mHandlePos = ((h / mRect.GetHeight()) * 100.f); 
      }

      Rect.Set(0.f, Height, Width, h);
      Rect.RoundToBelow();
    }

    Height += h;
    pItem->SetLayout(Rect);
  }


  //******************************************
  //
  // handle
  nuiSize handleSize =0;
  if (mpHandle)
  {
    const nuiRect& handleRect = mpHandle->GetIdealRect();
    handleSize = handleRect.GetHeight();

    Rect.Set(0.0f, Height, rRect.GetWidth(), handleSize);
    Rect.RoundToBelow();
    mpHandle->SetLayout(Rect);
    Height += handleSize;
  }

  if (it != end)
  {
    ++it;
    i++;
    if (it != end)
    {
      pItem = (*it);
      if (pItem == mpHandle)
      {
        ++it;
        i++;
      }
    }
  }




  //*****************************************************
  //
  // Second child:
  if (it != end)
  {
    pItem = (*it);

    if (mMasterChild)
    {
      h = mRect.GetHeight() - h ;
      NGL_ASSERT(h >= mSeconWidgetMinPixels);

      Rect.Set(0.f, Height + handleSize, Width, h - handleSize);
      Rect.RoundToBelow();
    }
    else
    {
      if (mMode == eModePercentage)
      {
        h = mRect.GetHeight() - ((mHandlePos/100.0f) * mRect.GetHeight()) - handleSize;
      }
      else
      {
        h = mRect.GetHeight() - mHandlePos - handleSize;
      }


      h = MAX(h, mSeconWidgetMinPixels);

      if (h + mFirstWidgetMinPixels > mRect.GetHeight())
      {
        h = mRect.GetHeight() - mFirstWidgetMinPixels;

        mHandlePos = mRect.GetHeight() - h;

        if (mMode == eModePercentage)
          mHandlePos = (mHandlePos * 100.0f) / mRect.GetHeight();
      }

      Rect.Set(0.f, Height, Width, h);
      Rect.RoundToBelow();
    }

    pItem->SetLayout(Rect);
  }

  return true;
}
Beispiel #14
0
bool nuiZoomView::SetRect(const nuiRect& rRect)
{
  nuiWidget::SetRect(rRect);

  nuiSize XOffset = 0;
  nuiSize YOffset = 0;

  if (mpHorizontalScrollbar)
    XOffset = (nuiSize)ToNearest(mpHorizontalScrollbar->GetRange().GetValue());
  if (mpVerticalScrollbar)
    YOffset = (nuiSize)ToNearest(mpVerticalScrollbar->GetRange().GetValue());

  nuiSize HorizontalZoomLevel = mHorizontalZoomLevel; 
  nuiSize VerticalZoomLevel = mVerticalZoomLevel;

  if (mpVerticalSlider)
    VerticalZoomLevel = mpVerticalSlider->GetRange().GetValue();
  if (mpHorizontalSlider)
    HorizontalZoomLevel = mpHorizontalSlider->GetRange().GetValue();

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

  if (mCalcWidthFromIdealSize)
    x = GetIdealRect().GetWidth();
  else
    x = xx * HorizontalZoomLevel;
  if (mCalcHeightFromIdealSize)
    y = GetIdealRect().GetHeight();
  else
    y = yy * VerticalZoomLevel;

  bool needv = y > yy;
  bool needh = x > xx;
  
  if (mpHorizontalScrollbar)
  {
    nuiRange& hrange = mpHorizontalScrollbar->GetRange();
    hrange.SetRange(0,x);
    hrange.SetPageSize(MAX(0, xx));
    hrange.SetIncrement(16.0f);
    hrange.SetPageIncrement(MAX(0, xx - xx / 8.f)); // 1/8th of page skip overlaps with the next and previous
    hrange.EnableEvents(false); 
    hrange.SetValue(XOffset); 
    hrange.EnableEvents(true);
    XOffset = hrange.GetValue();
  }
  if (mpVerticalScrollbar)
  {
    nuiRange& vrange = mpVerticalScrollbar->GetRange();
    vrange.SetRange(0,y);
    vrange.SetPageSize(MAX(0, yy));
    vrange.SetIncrement(16.0f);
    vrange.SetPageIncrement(MAX(0, yy - yy / 8.f)); // 1/8th of page skip overlaps with the next and previous
    vrange.EnableEvents(false); 
    vrange.SetValue(YOffset); 
    vrange.EnableEvents(true);
    YOffset = vrange.GetValue();
  }

  if (x < xx)
    x = xx;
  if (y < yy)
    y = yy;

  IteratorPtr pIt;  
  for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
  {
    nuiWidgetPtr pItem = pIt->GetWidget();
    nuiRect rect(-XOffset, -YOffset, x, y);
    pItem->SetLayout(rect);
  }
  delete pIt;

  needv = needv | mAlwaysDisplayVScrollbar;
  needh = needh | mAlwaysDisplayHScrollbar;

  if (mpVerticalScrollbar)
    mpVerticalScrollbar->SetVisible(needv);
  if (mpHorizontalScrollbar)
    mpHorizontalScrollbar->SetVisible(needh);

  return true;
}
Beispiel #15
0
//*******************************************
//
// ORIENTATION VERTICAL
//  
bool nuiSplitter::SetRectVertical(const nuiRect& rRect)
{
  nuiSize Height = rRect.GetHeight();
//  nuiSize Width = rRect.GetWidth();
  nuiSize left;
  nuiRect Rect;
  
  nuiSize handleSize = 0;
  if (mpHandle)
  {
    const nuiRect& handleRect = mpHandle->GetIdealRect();
    handleSize = handleRect.GetWidth();
  }
  
  nuiWidgetPtr pItem = NULL;
  nuiWidgetList::iterator it;
  nuiWidgetList::iterator end = mpChildren.end();

  list<nuiRect>::iterator rit=mPositions.begin();
  Rect=(*rit);

  ++rit;

  left = 0;
  nuiSize w=0;
  int i;
  it=mpChildren.begin();
  i=0;
  
   // don't process the splitter handle before the first child (we need the size of the first child)
  if (it != end)
  {
    pItem = (*it);
    if (pItem == mpHandle)
    {
      ++it;
      i++;
    }
  }



  //******************************************
  //
  // First Child:

  if (it != end)
  {
    pItem = (*it);

    if (mMasterChild)
    {
      w = pItem->GetIdealRect().GetWidth();

      mHandlePos = (mMode == eModePercentage) ? ((w / rRect.GetWidth()) * 100.0f) : w;

      Rect.Set(left, 0.f, w, Height);
      Rect.RoundToBelow();
    }
    else
    {
      w = (mMode == eModePercentage) ? MAX((mRect.GetWidth() * (mHandlePos/100.0f)), mFirstWidgetMinPixels) : MAX(mHandlePos, mFirstWidgetMinPixels);
      
      if (w + mSeconWidgetMinPixels > mRect.GetWidth())
      {

        w = mRect.GetWidth() - mSeconWidgetMinPixels;
        mHandlePos = (mMode == eModePercentage) ? (w / mRect.GetWidth() * 100.0f) : w;
      }


      Rect.Set(left, 0.f, w, Height);
      Rect.RoundToBelow();
    }

    pItem->SetLayout(Rect);

    left += w;
  }
  // no child
  else
  {
    if (mMasterChild)
    {
      left = (mMode == eModePercentage) ? ((mHandlePos / rRect.GetWidth()) * 100.0f) : mHandlePos;
    }
    else
    {
      left = (mMode == eModePercentage) ? MAX((mRect.GetWidth() * (mHandlePos/100.0f)), mFirstWidgetMinPixels) : MAX(mHandlePos, mFirstWidgetMinPixels);
    }
  }





  //******************************************
  //
  // handle
  if (mpHandle)
  {
    Rect.Set(left, 0.0f, handleSize, rRect.GetHeight());
    Rect.RoundToBelow();
    mpHandle->SetLayout(Rect);
    left += handleSize;
  }

  if (it != end)
  {
    ++it;
    i++;
    if (it != end)
    {
      pItem = (*it);
      if (pItem == mpHandle)
      {
        ++it;
        i++;
      }
    }
  }


  //******************************************
  //
  // second child
  if (it !=end)
  {
    w = mRect.GetWidth() - left;
    pItem = (*it);
    if (mMasterChild)
    {
      if (w < 0)
        w = 0;

      Rect.Set(left, 0.f, w, Height);
      Rect.RoundToBelow();
    }
    else
    {
      if (w + mFirstWidgetMinPixels > mRect.GetWidth())
      {
        w = mRect.GetWidth() - mFirstWidgetMinPixels;
        mHandlePos = (mMode == eModePercentage) ? (100.0f - (w / mRect.GetWidth()) * 100.0f) : (mRect.GetWidth() - w);
      }
      
      Rect.Set(left, 0.f, w, Height);
      Rect.RoundToBelow();
    }


    pItem->SetLayout(Rect);
  }
    


  return true;
}
Beispiel #16
0
bool nuiList::SetRect(const nuiRect& rRect)
{
  nuiWidget::SetRect(rRect);
  nuiSize Height = (nuiSize)rRect.GetHeight();
  nuiSize Width = (nuiSize)rRect.GetWidth();
  nuiSize pageincr = 0, value = 0;
  nuiRect Rect;
  nuiSize w,h;

  list<nuiRect>::iterator rit=mPositions.begin();

  Rect=(*rit);

  ++rit;
  if (mOrientation == nuiVertical)
  {
    pageincr = rRect.GetHeight() - 2.0f;

    Height = (nuiSize)-value;

    IteratorPtr pIt;
    for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
    {
      nuiWidgetPtr pItem = pIt->GetWidget();
      Rect=(*rit);
      if (mFixedAspectRatio)
      {
        nuiSize rratio,rw,rh;
        rratio = (nuiSize)Rect.GetWidth() / (nuiSize)Rect.GetHeight();

        rw = (nuiSize)Width;
        rh = rw / rratio;

        h=rh;

      }
      else
      {
        h=(nuiSize)Rect.GetHeight();
      }
      
      Rect.Set(mBorderSize, Height, Width - 2 * mBorderSize, h);
      Rect.RoundToAbove();

      Height += h + mBorderSize;
      Height = (nuiSize)ToAbove(Height);
      pItem->SetLayout(Rect);
      mRects[pItem] = Rect;

      ++rit;
    }
    delete pIt;
  }
  else
  {
    pageincr = rRect.GetWidth() - 2.0f;

    Width = (nuiSize) -value;
    IteratorPtr pIt;
    for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
    {
      nuiWidgetPtr pItem = pIt->GetWidget();
      Rect=(*rit);
      if (mFixedAspectRatio)
      {
        nuiSize rratio,rw,rh;
        rratio = (nuiSize)Rect.GetWidth() / (nuiSize)Rect.GetHeight();

        rh = (nuiSize)Height;
        rw = rh * rratio;
        
        w=rw;
      }
      else
      {
        w=(nuiSize)(int)((nuiSize)Rect.GetWidth());
      }
      
      Rect.Set(Width, mBorderSize, w, Height - 2 * mBorderSize);
      Rect.RoundToAbove();
      Width += w + mBorderSize;
      Width = (nuiSize)ToAbove(Width);
      pItem->SetLayout(Rect);
      mRects[pItem] = Rect;
      ++rit;
    }
    delete pIt;
  }

  return true;
}
//virtual
void nuiGradientDecoration::Draw(nuiDrawContext* pContext, nuiWidget* pWidget, const nuiRect& rDestRect)
{
  nuiColor c1 = mColor1;
  nuiColor c2 = mColor2;
  nuiColor c3 = mColor3;
  nuiColor c4 = mColor4;
  nuiColor s = mStrokeColor;
  pContext->PushState();
  pContext->ResetState();
  
  pContext->EnableAntialiasing(false);
  pContext->EnableBlending(true);
  pContext->SetBlendFunc(nuiBlendTransp);
  pContext->EnableTexturing(false);

  
  if (mUseWidgetAlpha && pWidget)
  {
    float widgetAlpha = pWidget->GetMixedAlpha();
    c1.Multiply(widgetAlpha);
    c2.Multiply(widgetAlpha);
    s.Multiply(widgetAlpha);
  }
  
  pContext->SetFillColor(nuiColor(1, 1, 1, 1));
  pContext->SetStrokeColor(s);

  nuiGradient gradient;
  if (!mUserOffsets)
    InitOffsets();
  gradient.AddStop(c1, mOffset1);
  gradient.AddStop(c2, mOffset2);
  if (mGradientType == nuiGradient4Colors)
  {
    if (mUseWidgetAlpha && pWidget)
    {
      float widgetAlpha = pWidget->GetMixedAlpha();
      c3.Multiply(widgetAlpha);
      c4.Multiply(widgetAlpha);
    }

    gradient.AddStop(c3, mOffset3);
    gradient.AddStop(c4, mOffset4);
  }

  if (mOrientation == nuiVertical)
    pContext->DrawGradient(gradient, rDestRect, 0, rDestRect.Top(), 0, rDestRect.Bottom());
  else
  {
    pContext->DrawGradient(gradient, rDestRect, 0, rDestRect.Top(), rDestRect.Right(), rDestRect.Top());
  }
  
  if (((mShapeMode == eStrokeShape) || (mShapeMode == eStrokeAndFillShape)) && mStrokeSize)
  {
    pContext->SetFillColor(s);
    
    nuiRect rect(rDestRect.Left(), rDestRect.Top(), rDestRect.GetWidth(), mStrokeSize);
    pContext->DrawRect(rect, eFillShape);
    
    rect = nuiRect(rDestRect.Left(), rDestRect.Bottom()-mStrokeSize, rDestRect.GetWidth(), mStrokeSize);
    pContext->DrawRect(rect, eFillShape);
    
    rect = nuiRect(rDestRect.Left(), rDestRect.Top(), mStrokeSize, rDestRect.GetHeight());
    pContext->DrawRect(rect, eFillShape);
    
    rect = nuiRect(rDestRect.Right()-mStrokeSize, rDestRect.Top(), mStrokeSize, rDestRect.GetHeight());
    pContext->DrawRect(rect, eFillShape);
    
  }

  pContext->PopState();
}
Beispiel #18
0
void nuiSoftwarePainter::Display(nglWindow* pWindow, const nuiRect& rRect)
{
  if (!pWindow)
    return;
  const nglWindow::OSInfo* pInfo = pWindow->GetOSInfo();
  
  NGL_ASSERT(pInfo);

  if (!pInfo)
    return;

  //TestAgg((char*)&mBuffer[0], mWidth, mHeight);
  
  int32 x, y, w, h;
  x = ToBelow(rRect.Left());
  y = ToBelow(rRect.Top());
  w = ToBelow(rRect.GetWidth());
  h = ToBelow(rRect.GetHeight());
  int32 offset = (x + mWidth * y);
  
#ifdef _WIN32_
  HDC hdc = GetDC(pInfo->GLWindowHandle);

  BITMAPV5HEADER bminfo;

  // BITMAPV5HEADER
  bminfo.bV5Size = sizeof(BITMAPV5HEADER);
  bminfo.bV5Width = (LONG)mWidth;
  bminfo.bV5Height = -(LONG)mHeight;
  bminfo.bV5Planes = 1;
  bminfo.bV5BitCount = 32;
  bminfo.bV5Compression = BI_RGB;
  bminfo.bV5SizeImage = 0;
  bminfo.bV5XPelsPerMeter = 0;
  bminfo.bV5YPelsPerMeter = 0;
  bminfo.bV5ClrUsed = 0;
  bminfo.bV5ClrImportant =0;

  bminfo.bV5RedMask = 0;
  bminfo.bV5GreenMask = 0;
  bminfo.bV5BlueMask = 0;
  bminfo.bV5AlphaMask = 0;

  bminfo.bV5CSType = LCS_WINDOWS_COLOR_SPACE;
  bminfo.bV5Endpoints.ciexyzRed.ciexyzX = 0;
  bminfo.bV5Endpoints.ciexyzRed.ciexyzY = 0;
  bminfo.bV5Endpoints.ciexyzRed.ciexyzZ = 0;
  bminfo.bV5Endpoints.ciexyzGreen.ciexyzX = 0;
  bminfo.bV5Endpoints.ciexyzGreen.ciexyzY = 0;
  bminfo.bV5Endpoints.ciexyzGreen.ciexyzZ = 0;
  bminfo.bV5Endpoints.ciexyzBlue.ciexyzX = 0;
  bminfo.bV5Endpoints.ciexyzBlue.ciexyzY = 0;
  bminfo.bV5Endpoints.ciexyzBlue.ciexyzZ = 0;
  bminfo.bV5GammaRed = 0;
  bminfo.bV5GammaGreen = 0;
  bminfo.bV5GammaBlue = 0;
  bminfo.bV5Intent = LCS_GM_IMAGES;
  bminfo.bV5ProfileData = 0;
  bminfo.bV5ProfileSize = 0;

  bminfo.bV5Reserved = 0;

  RECT r;
  GetClientRect(pInfo->GLWindowHandle, &r);

  r.right = (LONG)mWidth;
  r.bottom = (LONG)mHeight;

  uint32* pBuffer = mpRasterizer->GetBuffer();
/*
  for (uint32 i = 0; i < mWidth * mHeight; i++)
    pBuffer[i] = rand();
*/

  SetDIBitsToDevice(
    hdc,              // handle to DC
    x,                // x-coord of destination upper-left corner
    y,                // y-coord of destination upper-left corner
    w,          // width of destination rectangle
    h,         // height of destination rectangle
    x,                // x-coord of source upper-left corner
    mHeight - h - y,                // y-coord of source upper-left corner

    0,                // first scan line
    (LONG)mHeight,    // number of scan lines

    pBuffer,          // bitmap bits
    (const BITMAPINFO*)&bminfo,          // bitmap data
    DIB_RGB_COLORS    // usage options
    );

  ReleaseDC(pInfo->GLWindowHandle, hdc);

#elif (defined _CARBON_)

  WindowRef win = pInfo->WindowHandle;
  if (!win)
    win = pInfo->Parent;
  
  //CGContextRef myMemoryContext;
  CGColorSpaceRef cspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
  CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, mpRasterizer->GetBuffer() + offset, mWidth * h * 4, NULL);
  
  CGImageRef img = CGImageCreate(
                                 w,
                                 h,
                                 8,
                                 32,
                                 mWidth * 4,
                                 cspace,
                                 kCGBitmapByteOrder32Host | kCGImageAlphaNoneSkipFirst,
                                 provider,
                                 NULL,
                                 0,
                                 kCGRenderingIntentDefault
                                 );
  
  CGContextRef myContext;
  
  SetPortWindowPort (win);// 1
  QDBeginCGContext (GetWindowPort (win), &myContext);

  CGRect rect = CGRectMake(x, mHeight - h - y, w, h);
  CGContextDrawImage(myContext, rect, img);
  
  QDEndCGContext (GetWindowPort(win), &myContext);  
          
#endif
}
Beispiel #19
0
void nuiMainWindow::SetWindowRect(nuiRect rect)
{
    SetSize(rect.GetWidth(), rect.GetHeight());
    SetPos(rect.Left(), rect.Top());
}