Beispiel #1
0
void nuiRect::RoundToNearest()
{
  mLeft   = (nuiSize)ToNearest(mLeft  );
  mRight  = (nuiSize)ToNearest(mRight );
  mTop    = (nuiSize)ToNearest(mTop   );
  mBottom = (nuiSize)ToNearest(mBottom);
}
Beispiel #2
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 #3
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 #4
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 #5
0
nuiSize nuiPopupMenu::AdjustPosToSize(nuiMenuRect* rPosRect)
{
  nuiTopLevel* pRoot = GetTopLevel();
  NGL_ASSERT(pRoot);
  nuiRect MainRect = pRoot->GetRect();

  // adjust horizontally
  if (rPosRect->mRect.Right() > MainRect.GetWidth())
  {
    rPosRect->mRect.Set(rPosRect->mRect.Left() - (rPosRect->mRect.Right() - MainRect.GetWidth()), 
      rPosRect->mRect.Top(), rPosRect->mRect.GetWidth(), rPosRect->mRect.GetHeight());  
  }
  // adjust vertically
  if (rPosRect->mRect.Bottom() > MainRect.GetHeight())
  {
    rPosRect->mRect.Set(rPosRect->mRect.Left(), rPosRect->mRect.Top() - (rPosRect->mRect.Bottom() - MainRect.GetHeight()) - NUI_POPUP_MARGIN,
      rPosRect->mRect.GetWidth(), rPosRect->mRect.GetHeight());
  }
  // check for scrollbar
  if (rPosRect->mRect.GetHeight() > MainRect.GetHeight())
  {
    nuiRect r( ToNearest(rPosRect->mRect.Right() - SB_WIDTH), 0, ToNearest(SB_WIDTH), ToNearest(MainRect.GetHeight()));
    rPosRect->mpSBar->GetRange().EnableEvents(false);
    rPosRect->mpSBar->GetRange().SetRange(0.f, rPosRect->mRect.GetHeight());
    rPosRect->mpSBar->GetRange().SetPageSize(MainRect.GetHeight());
    rPosRect->mpSBar->GetRange().SetIncrement(10.f);
    rPosRect->mpSBar->GetRange().EnableEvents(true);

    rPosRect->mpSBar->SetLayout(r);
    rPosRect->mpSBar->SetVisible(true);
    rPosRect->mpSBar->SetEnabled(true);

    nuiSize decal = rPosRect->mpSBar->GetRange().GetValue();
    rPosRect->mRect.Set(rPosRect->mRect.Left(), 0.f,
      rPosRect->mRect.GetWidth(), rPosRect->mRect.GetHeight());
    return (decal);
  }
  else if (rPosRect->mpSBar)
  {
    rPosRect->mpSBar->SetVisible(false);
    rPosRect->mpSBar->SetEnabled(false);
  }

  return -1.f;
}
Beispiel #6
0
void nuiRange::SetValue(double Value)
{
#ifdef DEBUG
  if (IsValid())
  {
    NGL_ASSERT(finite(Value));
  }
#endif
  
  double OldValue = mValue;

  mValue = Value;

  if (mDiscreetStepSize)
  {
    double diff = mValue - OldValue;
    if (fabsf(diff) >= mIncrement / 2.f)
    {
      if (mIncrement > 0)
      {
        mValue = (double)((double)OldValue + (ToNearest((double)diff / (double)mIncrement) * (double)mIncrement));
      }
    }
    else
    {
      mValue = OldValue;
    }
  }

  if (mMinimum <= mMaximum)
  {
    if (mValue < mMinimum)
      mValue = mMinimum;
    else if (mValue + mPageSize > mMaximum)
      mValue = mMaximum - mPageSize;
    if (mValue < mMinimum)
      mValue = mMinimum;
  }
  else
  {
    if (mValue > mMinimum)
      mValue = mMinimum;
    else if (mValue - mPageSize < mMaximum)
      mValue = mMaximum + mPageSize;
    if (mValue > mMinimum)
      mValue = mMinimum;
  }

  if (OldValue == mValue)
    return;

  if (mEvents)
  {
    ValueChanged();
    Changed();
  }
}
Beispiel #7
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;
}
Beispiel #8
0
void nuiSoftwarePainter::SetState(const nuiRenderState& rState, bool ForceApply)
{
  mState = rState;

  int32 x = MIN(ToNearest(mClip.Left()), (int32)mWidth);
  int32 y = MIN(ToNearest(mClip.Top()), (int32)mHeight);
  int32 xt = MIN(ToNearest(mClip.Right()), (int32)mWidth);
  int32 yt = MIN(ToNearest(mClip.Bottom()), (int32)mHeight);
  
  x = MAX(0, x);
  y = MAX(0, y);
  xt = MAX(0, xt);
  yt = MAX(0, yt);
  
  if (mClip.mEnabled)
    mpRasterizer->SetClipRect(x, y, xt, yt);
  else
    mpRasterizer->SetClipRect(0,0, mWidth, mHeight);  
}
Beispiel #9
0
void nuiPopupMenu::SetTreeRect(uint depth, nuiSize X, nuiSize Y, nuiTreeNode* pTree)
{
  NGL_ASSERT(pTree);
  NGL_ASSERT(depth < mRects.size());

  nuiWidgetPtr  pWidget;
  nuiRect       WidgetRect;
  nuiSize       SbWidth = 0.f;

  X += mRects[depth]->mRect.GetWidth();
  SbWidth = AdjustRectsPos(X, Y, depth, (pTree->GetElement())->GetRect());

  depth++;
  nuiMenuRect*  pRect= mRects[depth]; /// get the current menuRect

  pRect->mRect.Set(X, Y, pRect->mRect.GetWidth(), pRect->mRect.GetHeight());
  nuiRect PopupRect(pRect->mRect);

  nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f;

  uint32 count = pTree->GetChildrenCount();
  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();
    WidgetRect.Set(ToNearest(X), ToNearest(Y), ToNearest(PopupRect.GetWidth() - SbWidth - TreeHandleSize), ToNearest(WidgetRect.GetHeight()));
    pWidget->SetLayout(WidgetRect);
    if (pNode->IsOpened())
    {
      SetTreeRect(depth, X, Y, pNode);
    }
    Y += WidgetRect.GetHeight();
  }
}
Beispiel #10
0
long double SigDig(long double x, size_t n)
{
    long double shift, result;

    if ((n == 0u) || (n > LDBL_DIG))
        result = x;
    else
    {
        --n;
        
#if defined(__DJGPP__) | defined(_MSC_VER)
        shift = pow(10.0L,(double)n - floor(log10(fabs(x))));
#else
        shift = powl(10.0L,(double)n - floorl(log10l(fabsl(x))));
#endif

        result = ToNearest(x * shift) / shift;
    }

    return result;
}
Beispiel #11
0
double SigDig(double x, size_t n)
{
    double s, result;

    if (fabs(x) < 1.0E-300)
        result = 0.0;
    else
    {
        if ((n == 0U) || (n > DBL_DIG))
            result = x;
        else
        {
            #ifdef __BORLANDC__
                s = pow10((int)n - 1 - (int)floor(log10(fabs(x))));
            #else
                s = pow(10.0,double((int)n - 1 - (int)floor(log10(fabs(x)))));
            #endif
            result = ToNearest(x * s) / s;
        }
    }

    return result;
}
bool nuiAudioDevice_DirectSound::Open(std::vector<uint32>& rInputChannels, std::vector<uint32>& rOutputChannels, double SampleRate, uint32 BufferSize, nuiAudioProcessFn pProcessFunction)
{
  if (!mpDirectSound)
    return false;
  
  HRESULT hr = S_OK;
  mAudioProcessFn = pProcessFunction;

  mBufferSize = BufferSize;

  hr = mpDirectSound->SetCooperativeLevel(GetDesktopWindow(), DSSCL_EXCLUSIVE);

  mHasInput = (rInputChannels.size() > 0) && (mInputChannels.size() > 0);
  mHasOutput = (rOutputChannels.size() > 0) && (mOutputChannels.size() > 0);


  mpInputBuffer = NULL;
  mpOutputBuffer = NULL;

  if (!mHasInput && !mHasOutput)
    return false;

  // init ringbuffer
  mpRingBuffer = new nglRingBuffer(BufferSize*4, sizeof(float), rOutputChannels.size());
  mpRingBuffer->AdvanceWriteIndex(BufferSize);

  // init input buffers
  if (mHasInput)
  {
    {
      mActiveInputChannels = rInputChannels;
    }

    WAVEFORMATEX IFormat;
    IFormat.wFormatTag = WAVE_FORMAT_PCM;
    IFormat.nChannels = (WORD)mInputChannels.size();
    IFormat.nSamplesPerSec = ToNearest(SampleRate);
    IFormat.wBitsPerSample = 16;
    IFormat.nAvgBytesPerSec = IFormat.nChannels * IFormat.nSamplesPerSec * (IFormat.wBitsPerSample / 8);
    IFormat.nBlockAlign = IFormat.nChannels * (IFormat.wBitsPerSample / 8);
    IFormat.cbSize = 0;

    DSCBUFFERDESC IBufferDesc;
    memset(&IBufferDesc, 0, sizeof(IBufferDesc));
    IBufferDesc.dwSize = sizeof(DSCBUFFERDESC);
    IBufferDesc.dwFlags = DSCBCAPS_WAVEMAPPED;
    IBufferDesc.dwBufferBytes = (IFormat.wBitsPerSample / 8) * IFormat.nChannels * BufferSize * 2;
    IBufferDesc.dwReserved = 0;
    IBufferDesc.lpwfxFormat = &IFormat;
    IBufferDesc.dwFXCount = 0;
    IBufferDesc.lpDSCFXDesc = NULL;

    NGL_ASSERT(mpDirectSoundCapture);
    hr = mpDirectSoundCapture->CreateCaptureBuffer(&IBufferDesc, &mpInputBuffer, NULL);
  }


  // init output buffers
  if (mHasOutput)
  {
    {
      mActiveOutputChannels = rOutputChannels;
    }

    WAVEFORMATEX OFormat;
    OFormat.wFormatTag = WAVE_FORMAT_PCM;
    OFormat.nChannels = (WORD)mOutputChannels.size();
    OFormat.nSamplesPerSec = ToNearest(SampleRate);
    OFormat.wBitsPerSample = 16;
    OFormat.nAvgBytesPerSec = OFormat.nChannels * OFormat.nSamplesPerSec * (OFormat.wBitsPerSample / 8);
    OFormat.nBlockAlign = OFormat.nChannels * OFormat.wBitsPerSample / 8;
    OFormat.cbSize = 0;

    DSBUFFERDESC  OBufferDesc;
    memset(&OBufferDesc, 0, sizeof(OBufferDesc));
    OBufferDesc.dwSize = sizeof(OBufferDesc);
    OBufferDesc.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY;
    OBufferDesc.dwBufferBytes = (OFormat.wBitsPerSample / 8) * OFormat.nChannels * BufferSize * 2;
    OBufferDesc.dwReserved = 0;
    OBufferDesc.lpwfxFormat = &OFormat;

    hr = mpDirectSound->CreateSoundBuffer(&OBufferDesc, &mpOutputBuffer, NULL);
  }


  // create event for notifications
  mNotifInputEvent[0] = CreateEvent(NULL, FALSE, FALSE, _T("NUI_DSoundInputEvent0"));
  mNotifInputEvent[1] = CreateEvent(NULL, FALSE, FALSE, _T("NUI_DSoundInputEvent1"));
  mNotifOutputEvent[0] = CreateEvent(NULL, FALSE, FALSE, _T("NUI_DSoundOutputEvent0"));
  mNotifOutputEvent[1] = CreateEvent(NULL, FALSE, FALSE, _T("NUI_DSoundOutputEvent1"));




  // set the notification for the input buffer
  if (mHasInput)
  {
    // Setup the notification positions
    ZeroMemory( &mInputPosNotify, sizeof(DSBPOSITIONNOTIFY) * 2);
    mInputPosNotify[0].dwOffset = BufferSize * sizeof(int16) * mInputChannels.size() - 1;
    mInputPosNotify[0].hEventNotify = mNotifInputEvent[0];             
    mInputPosNotify[1].dwOffset = BufferSize * sizeof(int16) * mInputChannels.size() * 2 - 1;
    mInputPosNotify[1].hEventNotify = mNotifInputEvent[1];           

    LPDIRECTSOUNDNOTIFY pInputNotify = NULL;
    if( FAILED( hr = mpInputBuffer->QueryInterface( IID_IDirectSoundNotify, (VOID**)&pInputNotify ) ) )
    {
      NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_ERROR, _T("Open ERROR : failed in querying interface for input notifications.\n"));
      return false;
    }


    // Tell DirectSound when to notify us. the notification will come in the from 
    // of signaled events that are handled in WinMain()
    if( FAILED( hr = pInputNotify->SetNotificationPositions( 2, mInputPosNotify ) ) )
    {
      NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_ERROR, _T("Open ERROR : failed in setting notifications for input\n"));
      return false;
    }

    pInputNotify->Release();
  }



  // set the notification events for the output buffer
  if (mHasOutput)
  {
    // Setup the notification positions
    ZeroMemory( &mOutputPosNotify, sizeof(DSBPOSITIONNOTIFY) * 2);
    mOutputPosNotify[0].dwOffset = BufferSize * sizeof(int16) * mOutputChannels.size() - 1;
    mOutputPosNotify[0].hEventNotify = mNotifOutputEvent[0];             
    mOutputPosNotify[1].dwOffset = BufferSize * sizeof(int16) * mOutputChannels.size() * 2 - 1;
    mOutputPosNotify[1].hEventNotify = mNotifOutputEvent[1];    

    LPDIRECTSOUNDNOTIFY pOutputNotify = NULL;
    if( FAILED( hr = mpOutputBuffer->QueryInterface( IID_IDirectSoundNotify, (VOID**)&pOutputNotify ) ) )
    {
      NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_ERROR, _T("Open ERROR : failed in querying interface for output notifications.\n"));
      return false;
    }

    // Tell DirectSound when to notify us. the notification will come in the from 
    // of signaled events that are handled in WinMain()
    if( FAILED( hr = pOutputNotify->SetNotificationPositions( 2, mOutputPosNotify ) ) )
    {
      NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_ERROR, _T("Open ERROR : failed in setting notifications for output\n"));
      return false;
    }

    pOutputNotify->Release();
  }


  // start input processing thread
  mpProcessingTh = new nuiAudioDevice_DS_ProcessingTh(this, mNotifInputEvent[0], mNotifInputEvent[1], mAudioProcessFn);
  mpProcessingTh->Start();



  // start output thread
  if (mHasOutput)
  {
    mpOutputTh = new nuiAudioDevice_DS_OutputTh(this, mNotifInputEvent[0], mNotifInputEvent[1], mNotifOutputEvent[0], mNotifOutputEvent[1]);
    mpOutputTh->Start();
    hr = mpOutputBuffer->Play(0,0,DSCBSTART_LOOPING);
    if (FAILED(hr))
      NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_ERROR, _T("OutputBuffer->Play ERROR!\n"));
  }

  // start input capture
  if (mHasInput)
  {
    hr = mpInputBuffer->Start(DSCBSTART_LOOPING);
    if (FAILED(hr))
      NGL_LOG(_T("nuiAudioDevice_DirectSound"), NGL_LOG_ERROR, _T("InputBuffer->Start ERROR!\n"));    
  }





  return true;
}
Beispiel #13
0
void nuiRange::SetValueAndSize(double Value, double PageSize)
{
  
  //Value
  double OldValue = mValue;
  mValue = Value;
  
  //Size
  double OldPageSize = mPageSize;
  mPageSize = PageSize;
  
  
  if (mMinimum < mMaximum)
  {
    if (mPageSize > mMaximum - mMinimum)
      mPageSize = mMaximum - mMinimum;
  }
  else
  {
    if (mPageSize > mMinimum - mMaximum)
      mPageSize = mMinimum - mMaximum;
  }
  
  if (mDiscreetStepSize)
  {
    double diff = mValue - OldValue;
    if (fabsf(diff) >= mIncrement / 2.f)
    {
      if (mIncrement > 0)
      {
        mValue = (double)((double)OldValue + (ToNearest((double)diff / (double)mIncrement) * (double)mIncrement));
      }
    }
    else
    {
      mValue = OldValue;
    }
  }
  
  if (mMinimum <= mMaximum)
  {
    if (mValue < mMinimum)
      mValue = mMinimum;
    else if (mValue + mPageSize > mMaximum)
      mValue = mMaximum - mPageSize;
    if (mValue < mMinimum)
      mValue = mMinimum;
  }
  else
  {
    if (mValue > mMinimum)
      mValue = mMinimum;
    else if (mValue - mPageSize < mMaximum)
      mValue = mMaximum + mPageSize;
    if (mValue > mMinimum)
      mValue = mMinimum;
  }

  if ((OldPageSize == mPageSize) && (OldValue == mValue))
    return;
  
  //Events
  if (mEvents)
  {
    ValueChanged();
    Changed();
  }
  
}
Beispiel #14
0
bool nuiLabel::Draw(nuiDrawContext* pContext)
{
//  NGL_OUT(_T("Draw 0x%x\n"), this);
  nuiColor Color = GetTextColor();
  nuiColor ColorBg = GetBackgroundColor();

  CalcLayout();

  pContext->SetFont(mpFont);
  
  if (mIgnoreState)
  {
    if (!mBackColorSet)
      ColorBg = GetColor(eNormalTextBg);
    if (!mTextColorSet)
      Color = GetColor(eNormalTextFg);
  }
  else
  {
    if (IsEnabled())
    {
      if (IsSelected())
      {
        if (!mBackColorSet)
          ColorBg = GetColor(eSelectedTextBg);
        if (!mTextColorSet)
          Color = GetColor(eSelectedTextFg);
      }
      else
      {
        if (!mBackColorSet)
          ColorBg = GetColor(eNormalTextBg);
        if (!mTextColorSet)
          Color = GetColor(eNormalTextFg);
      }
    }
    else
    {
      if (IsSelected())
      {
        if (!mBackColorSet)
          ColorBg = GetColor(eSelectedTextBg);
        if (!mTextColorSet)
          Color = GetColor(eDisabledTextFg);
      }
      else
      {
        if (!mBackColorSet)
          ColorBg = GetColor(eDisabledTextBg);
        if (!mTextColorSet)
          Color = GetColor(eDisabledTextFg);
      }
    }
  }

  nuiGlyphInfo GlyphInfo;
  mpLayout->GetMetrics(GlyphInfo);

  nuiFontInfo info;
  mpFont->GetInfo(info);
  //info.Dump(0);

  float alpha = GetMixedAlpha();
  Color.Multiply(alpha);
  ColorBg.Multiply(alpha);
  
  nuiRect rect = mpLayout->GetRect();

  rect.SetPosition(mTextPosition, mRect.Size());
  //pContext->DrawRect(rect, eStrokeShape);
  
  rect.mTop += (nuiSize)ToNearest(info.Ascender) + mVMargin;
  rect.mLeft +=  mHMargin;

  if (mClearBg)
  {
    if (ColorBg.Alpha() < 1.0)
    {
      pContext->SetBlendFunc(nuiBlendTransp);
      pContext->EnableBlending(true);
    }
    pContext->SetFillColor(ColorBg);   
    pContext->DrawRect(mRect.Size(),eFillShape);
    if (ColorBg.Alpha() < 1.0)
    {
      pContext->SetBlendFunc(nuiBlendSource);
      pContext->EnableBlending(false);
    }
  }

  if (mpLayout)
  {
    /* currently disabled as it doesn't look that good in many cases
    if (GetState() == nuiDisabled && !mIgnoreState)
    {
      nuiColor c = Color;
      c.Red()   *= 2;
      c.Green() *= 2;
      c.Blue()  *= 2;
      pContext->SetTextColor(c);
      pContext->DrawText((nuiSize)ToNearest(rect.mLeft+1), (nuiSize)ToNearest(rect.mTop+1), *mpLayout);
    }
    */
    pContext->SetTextColor(Color);

    pContext->DrawText((nuiSize)ToNearest(rect.mLeft), (nuiSize)ToNearest(rect.mTop), *mpLayout);
  }
  else
  {
//    NGL_OUT(_T("F**K 0x%x!"), this);
  }
  return true;
}
Beispiel #15
0
bool nuiScrollView::SetChildrenRect(nuiSize x, nuiSize y, nuiSize xx, nuiSize yy, nuiSize scrollv, nuiSize scrollh)
{  
  #ifdef _DEBUG_LAYOUT
  if (GetDebug())
  {
    NGL_OUT(_T("\tnuiScrollView::SetChildrenRect: (%f, %f) (%f, %f) - (%f, %f)\n"), x, y, xx, yy, scrollv, scrollh);
  }
  #endif
  
  nuiRect VisibleRect = GetRect().Size();
  VisibleRect.Right() -= scrollv;
  VisibleRect.Bottom() -= scrollh;
  
  nuiRange& hrange = mpHorizontal->GetRange();
  nuiRange& vrange = mpVertical->GetRange();
  nuiSize XOffset = hrange.GetValue();
  nuiSize YOffset = vrange.GetValue();

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

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

  if (!mFillChildren)
  {
    IteratorPtr pIt;  
    for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
    {
      nuiWidgetPtr pItem = pIt->GetWidget();
      if (pItem != mpVertical && pItem != mpHorizontal)
      {
        nuiRect rect = pItem->GetIdealRect();
        rect.Move(-XOffset, -YOffset);

        float w = rect.GetWidth();
        float h = rect.GetHeight();
        
        if (mForceNoHorizontal)
          w = xx;
        if (mForceNoVertical)
          h = yy;
        
        rect.SetSize(w, h);

        #ifdef _DEBUG_LAYOUT
        if (GetDebug())
        {
          NGL_OUT(_T("\tnuiScrollView::SetChildrenRect: SetLayout(%s)\n"), rect.GetValue().GetChars());
        }
        #endif

        pItem->SetLayout(rect);
        rect = VisibleRect;
        LocalToLocal(pItem, rect);
        //pItem->SetVisibleRect(rect);
      }
    }
    delete pIt;
  }
  else
  {
    if (x < xx - scrollv)
      x = xx - scrollv;
    if (y < yy - scrollh)
      y = yy - scrollh;

    IteratorPtr pIt;  
    for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
    {
      nuiWidgetPtr pItem = pIt->GetWidget();
      if (pItem != mpVertical && pItem != mpHorizontal)
      {
        float w = x, h = y;

        if (mForceNoHorizontal)
				{
          w = xx - scrollv;
				}
        if (mForceNoVertical)
				{
          h = yy - scrollh;
				}
        
        nuiRect rect(-XOffset, -YOffset, w, h);
          
        #ifdef _DEBUG_LAYOUT
        if (GetDebug())
        {
          NGL_OUT(_T("\tnuiScrollView::SetChildrenRect: SetLayout(%s)\n"), rect.GetValue().GetChars());
        }
        #endif
        
        pItem->SetLayout(rect);

        rect = VisibleRect;
        LocalToLocal(pItem, rect);
        pItem->SetVisibleRect(rect);
      }
    }
    delete pIt;
  }

  return true;
}
Beispiel #16
0
bool nuiWaveWriter::WriteInfo(const nuiSampleInfo& rInfos)
{
  if ( true == mIsInfosWritten )
    return false;
  
  mrSampleInfo = rInfos;
  mrSampleInfo.SetSampleFrames(0);
  
  if (32 == rInfos.GetBitsPerSample())
  {
    mrSampleInfo.SetFormatTag(eWaveFormatIEEEfloat);
  }
  else // if (16 == rInfos.GetBitsPerSample())
  {
    mrSampleInfo.SetFormatTag(eWaveFormatPcm);
  }
  
  
  int32 Data32;
  int16 Data16;
  
  //Write first chunk ID : "RIFF" (0x52494646)
  if ( 4 != mrStream.WriteUInt8((uint8*)"RIFF",4))
    return false;

  //we can't write file size!!! : write an uint32 to move 4 bytes forward
  uint32 fake = 1;
  if ( 1 != mrStream.WriteUInt32(&fake,1))
    return false;
  //mrStream.SetPos(4, eStreamForward);
  
  //Write RIFF type : "WAVE" (0x57415645)
  if ( 4 != mrStream.WriteUInt8((uint8*)"WAVE",4))
    return false;
  
  //Write second chunk : "fmt " (0x666D7420)
  if ( 4 != mrStream.WriteUInt8((uint8*)"fmt ",4))
    return false;
  
  
  //Write "fmt " chunk size : 16 if format code = PCM
  //                          18 if format code = IEEE Float
  
  switch(mrSampleInfo.GetFormatTag())
  {
    case eWaveFormatPcm :
    {
      Data32 = FMT_CHUNK_DATA_SIZE_PCM;
      if ( 1 != mrStream.WriteInt32(&Data32,1))
        return false;
    }
      break;
      
    case eWaveFormatIEEEfloat :
    {
      Data32 = FMT_CHUNK_DATA_SIZE_IEEE_FLOAT;
      if ( 1 != mrStream.WriteInt32(&Data32,1))
        return false;
    }
      break;
        
    default :
      return false;
      break;
  }
    /*
  Data32 = 16;
  if ( 1 != mrStream.WriteInt32(&Data32,1))
    return false;
  */
  
  //Write Compression code 
  Data16 = mrSampleInfo.GetFormatTag();
  if ( 1 != mrStream.WriteInt16(&Data16,1))
    return false;
  
  //Write Numbers of channels
  Data16 = rInfos.GetChannels();
  if ( 1 != mrStream.WriteInt16(&Data16,1))
    return false;
  
  //Write Sample Rate
  Data32 = ToNearest(rInfos.GetSampleRate());
  if ( 1 != mrStream.WriteInt32(&Data32,1))
    return false;
  
  //Write Average bytes per second
  Data32 = ToNearest(rInfos.GetSampleRate()) * rInfos.GetBitsPerSample() / 8 * rInfos.GetChannels();
  if ( 1 != mrStream.WriteInt32(&Data32,1))
    return false;
  
  //Write BlockAlign
  Data16 = rInfos.GetBitsPerSample() / 8 * rInfos.GetChannels();
  if ( 1 != mrStream.WriteInt16(&Data16,1))
    return false;
  
  //Write Bits per Sample
  Data16 = rInfos.GetBitsPerSample();
  if ( 1 != mrStream.WriteInt16(&Data16,1))
    return false;
  
  //
  if (eWaveFormatPcm != mrSampleInfo.GetFormatTag())
  {
    Data16 = 0; //Size of the extension : 0
    if ( 1 != mrStream.WriteInt16(&Data16,1))
      return false;
    
    //Write "fact" Chunk
    /////////////////////////////////
    //Write "data" chunk ID
    if ( 4 != mrStream.WriteUInt8((uint8*)"fact",4))
      return false;
    
    //Write "fact" chunk size
    Data32 = FACT_CHUNK_DATA_SIZE;
    if ( 1 != mrStream.WriteInt32(&Data32,1))
      return false;
    
    //We can't write Number of Channels * Number of Frames
    //Go Position + 4 : write an uint32 to move 4 bytes forward
    if ( 1 != mrStream.WriteUInt32(&fake,1))
      return false;
  }
  
  //Write "data" chunk ID
  if ( 4 != mrStream.WriteUInt8((uint8*)"data",4))
    return false;
  
  ////we can't write "data" chunk size!!! : write an uint32 to move 4 bytes forward
  if ( 1 != mrStream.WriteUInt32(&fake,1))
    return false;
  
  return true;
}
Beispiel #17
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 #18
0
void nuiTextLayout::Print(nuiDrawContext* pContext, float X, float Y, bool AlignGlyphPixels) const
{
  bool blendsaved = pContext->GetState().mBlending;
  bool texturesaved = pContext->GetState().mTexturing;
  
  pContext->EnableBlending(true);
  pContext->EnableTexturing(true);
  
  nuiColor SavedColor = pContext->GetFillColor();
  nuiColor oldcolor(pContext->GetStrokeColor());
  pContext->SetStrokeColor(pContext->GetTextColor());
  pContext->SetFillColor(pContext->GetTextColor());
  pContext->SetBlendFunc(nuiBlendTransp);
  
  std::map<nuiTexture*, std::vector<nuiTextGlyph*> > Glyphs;
  
  float x = X;
  float y = Y;
  
  // Iterate runs:
  for (int32 p = 0; p < GetParagraphCount(); p++)
  {
    for (int32 l = 0; l < GetLineCount(p); l++)
    {
      x = X;
      nuiTextLine* pLine = GetLine(p, l);
      for (int32 r = 0; r < pLine->GetRunCount(); r++)
      {
        nuiTextRun* pRun = pLine->GetRun(r);
        std::vector<nuiTextGlyph>& rGlyphs(pRun->GetGlyphs());
        nuiFontBase* pFont = pRun->GetFont();
        
        for (int32 g = 0; g < rGlyphs.size(); g++)
        {
          nuiTextGlyph& rGlyph(rGlyphs.at(g));
          Glyphs[rGlyph.mpTexture].push_back(&rGlyph);
        }
        
        // Draw underlines and strike through if needed
        if (pRun->GetUnderline() || pRun->GetStrikeThrough())
        {
          nuiFontInfo info;
          pFont->GetInfo(info);
          float thickness = ToNearest(info.UnderlineThick);
          pContext->SetLineWidth(thickness);
          
          const float x1 = x;
          const float x2 = x + pRun->GetAdvanceX();
          
          if (pRun->GetUnderline())
          {
            const float pos = -info.UnderlinePos;
            const float _y = ToNearest(y + pos);
            if (x1 != x2)
              pContext->DrawLine(x1, _y, x2, _y);
          }
          
          if (pRun->GetStrikeThrough())
          {
            const float pos = -info.Ascender * .4f;
            const float _y = ToNearest(y + pos);
            if (x1 != x2)
              pContext->DrawLine(x1, _y, x2, _y);
          }
        }
        
        //x += pRun->GetAdvanceX();
      }
      //y += pLine->GetAdvanceY();
    }
  }
  
  PrintGlyphs(pContext, X, Y, Glyphs, AlignGlyphPixels);
  
  
  pContext->EnableBlending(blendsaved);
  pContext->EnableTexturing(texturesaved);
  
  pContext->SetFillColor(SavedColor);
  pContext->SetStrokeColor(oldcolor);
}
Beispiel #19
0
bool nuiTextLayout::PrintGlyphs(nuiDrawContext *pContext, float X, float Y, const std::map<nuiTexture*, std::vector<nuiTextGlyph*> >& rGlyphs, bool AlignGlyphPixels) const
{
  std::map<nuiTexture*, std::vector<nuiTextGlyph*> >::const_iterator it = rGlyphs.begin();
  std::map<nuiTexture*, std::vector<nuiTextGlyph*> >::const_iterator end = rGlyphs.end();
  
  bool texturing = pContext->GetState().mTexturing;
  nuiTexture* pOldTexture = pContext->GetTexture();
  if (pOldTexture)
    pOldTexture->Acquire();
  
  pContext->EnableTexturing(true);

  const float f = nuiGetScaleFactor();
  const float i_f = nuiGetInvScaleFactor();
  
  while (it != end)
  {
    nuiTexture* pTexture = it->first;
    pContext->SetTexture(pTexture);
    int size = (int)it->second.size();
    int i;
    
    nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLES);
    pArray->EnableArray(nuiRenderArray::eVertex);
    pArray->EnableArray(nuiRenderArray::eTexCoord);
    pArray->EnableArray(nuiRenderArray::eColor);
    pArray->Reserve(6 * size);

    nuiColor textcolor = pContext->GetTextColor();
    
    for (i = 0; i < size; i++)
    {
      auto& run = *it;
      auto& glyph = *run.second[i];
      const nuiRect& rDest = glyph.mDestRect;
      const nuiRect& rSource = glyph.mSourceRect;

      if (glyph.mUseColor)
        pArray->SetColor(glyph.mColor);
      else
        pArray->SetColor(textcolor);

      nuiSize x1,y1,x2,y2;
      nuiSize tx,ty,tw,th;
      
      x1 = rDest.mLeft + X;
      y1 = rDest.mTop + Y;
      x2 = rDest.mRight + X;
      y2 = rDest.mBottom + Y;

      if (AlignGlyphPixels)
      {
        x1 = ToNearest(x1 * f) * i_f;
        y1 = ToNearest(y1 * f) * i_f;
        x2 = ToNearest(x2 * f) * i_f;
        y2 = ToNearest(y2 * f) * i_f;
      }
      
      tx = rSource.mLeft;
      ty = rSource.mTop;
      tw = rSource.mRight;
      th = rSource.mBottom;
      
      pTexture->ImageToTextureCoord(tx, ty);
      pTexture->ImageToTextureCoord(tw,th);
      
      ///////////////////////////////////////////
      pArray->SetVertex(x1, y1);
      pArray->SetTexCoords(tx, ty);
      pArray->PushVertex();
      
      pArray->SetVertex(x2, y1);
      pArray->SetTexCoords(tw, ty);
      pArray->PushVertex();
      
      pArray->SetVertex(x2, y2);
      pArray->SetTexCoords(tw, th);
      pArray->PushVertex();
      
      ///////////////////////////////////////////
      pArray->SetVertex(x1, y1);
      pArray->SetTexCoords(tx, ty);
      pArray->PushVertex();
      
      pArray->SetVertex(x2, y2);
      pArray->SetTexCoords(tw, th);
      pArray->PushVertex();
      
      pArray->SetVertex(x1, y2);
      pArray->SetTexCoords(tx, th);
      pArray->PushVertex();
    }
    
    //nglString str = pArray->Dump();
    //NGL_OUT("%s", str.GetChars());
    pContext->DrawArray(pArray);
    
    ++it;
  }
  
  pContext->EnableTexturing(texturing);
  pContext->SetTexture(pOldTexture);
  if (pOldTexture)
    pOldTexture->Release();
  
  return true;
}
Beispiel #20
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 #21
0
bool nuiPopupMenu::SetRect(const nuiRect& rRect)
{
  nuiRect r = rRect;
  nuiWidget::SetRect(r);
  mXdir = 1;
  mYdir = 1;
  nuiSize X, Y;
  X = Y = 0;

  NGL_ASSERT(mpTree);

  NGL_ASSERT(!mRects.empty());
  nuiMenuRect* pRect = mRects[0];

  nuiWidgetPtr pWidget = mpTree->GetElement();
  NGL_ASSERT(pWidget);

  nuiRect WidgetRect = pWidget->GetIdealRect();

  nuiSize decal = AdjustPosToSize(pRect);
  nuiRect PopupRect(pRect->mRect);
  mInitialPos = pRect->mRect;

  WidgetRect.Set( ToNearest(pRect->mRect.Left()), 
    ToNearest(pRect->mRect.Top() - (decal >= 0.f ? decal : 0.f)), 
    ToNearest(pRect->mRect.GetWidth() - (decal >= 0.f ? SB_WIDTH : 0.f)),
    ToNearest(WidgetRect.GetHeight()));
  pWidget->SetLayout(WidgetRect);

  if (mShowFirstNode)
  {
    X = WidgetRect.Left();
    Y = WidgetRect.Bottom();
  }
  else
  {
    X = mInitialPos.Left();
    Y = mInitialPos.Top() - (decal >= 0.f ? decal : 0.f);
  }

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

  nuiSize TreeHandleSize = pRect->mHasNonEmpty ? NUI_POPUP_TREE_HANDLE_SIZE : 0.f;
  for (uint32 i = 0; i < count; i++)
  {
    nuiTreeNode* pNode = dynamic_cast<nuiTreeNode*>(mpTree->GetChild(i));
    NGL_ASSERT(pNode);
    pWidget = pNode->GetElement();
    NGL_ASSERT(pWidget)
      WidgetRect = pWidget->GetIdealRect();
    WidgetRect.Set(ToNearest(X), 
      ToNearest(Y), 
      ToNearest(PopupRect.GetWidth() - (decal >= 0.f ? SB_WIDTH : 0.f) - TreeHandleSize), 
      ToNearest(WidgetRect.GetHeight()));
    pWidget->SetLayout(WidgetRect);
    if (pNode->IsOpened())
      SetTreeRect(0, X, Y, pNode);
    Y += WidgetRect.GetHeight();
  }
  return true;
}