Пример #1
0
	void CollisionSystem::Update()
	{

#ifdef ENGINE_DEBUG
		// Start the process time
		StartProcessTime();

		// Collisions/Check init
		m_Collisions = 0;
		m_CollisionCheck = 0;
#endif

		for (uint_32 _Itr = 0; _Itr < m_Components.size(); _Itr++)
		{
			m_CollisionTree->AddElement(m_Components[_Itr]);
		}
		// Change the world surface tree
		m_CollisionTree->SetBounds(Game::GetInstance().GetWorld().GetBounds());

		// Process collision and message send
		m_CollisionTree->ComputeCollisions(m_CollisionCheck, m_Collisions, GetDebug());

#ifdef ENGINE_DEBUG
		// End process time
		EndProcessTime();

		// Draw process time of the game (Drawcall and drawtime)
		DrawDebug::DrawDebugText(sf::Vector2f(50.f, 80.f),
			TEXT_STREAM("Collision : " << GetProcessTime() << " ms"));

		// Compute collisions
		m_CollisionTree->ComputeCollisions(m_CollisionCheck, m_Collisions, GetDebug());

		// Draw debug
		if (GetDebug())
		{
			// Debug draw specs
			DrawDebug::DrawDebugText(sf::Vector2f(50.f, 300.f),
				TEXT_STREAM("Colliders : " << m_Components.size()));
			DrawDebug::DrawDebugText(sf::Vector2f(60.f, 315.f),
				TEXT_STREAM("- Dynamic : " << m_Components.size()));
			DrawDebug::DrawDebugText(sf::Vector2f(60.f, 330.f),
				TEXT_STREAM("- Static : " << 0));
			DrawDebug::DrawDebugText(sf::Vector2f(50.f, 345.f),
				TEXT_STREAM("Collisions : " << m_Collisions));
			DrawDebug::DrawDebugText(sf::Vector2f(50.f, 360.f),
				TEXT_STREAM("Check : " << m_CollisionCheck));
			DrawDebug::DrawDebugText(sf::Vector2f(50.f, 375.f),
				TEXT_STREAM("Brute Force : " << m_Components.size() * m_Components.size()));
		}
#endif

		m_CollisionTree->Clear();
	}
Пример #2
0
bool nuiScrollView::Draw(nuiDrawContext* pContext)
{
  nuiSize scrollv = (mpVertical->IsVisible() && !mForceNoVertical && !mVerticalIsExternal)?mBarSize:0;
  nuiSize scrollh = (mpHorizontal->IsVisible() && !mForceNoHorizontal && !mHorizontalIsExternal)?mBarSize:0;
  nuiRect rect(0.0f,0.0f,mRect.GetWidth()-scrollv, mRect.GetHeight()-scrollh);

  IteratorPtr pIt;
  for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
  {
    nuiWidgetPtr pItem = pIt->GetWidget();
    nuiRect intersect;
    if (intersect.Intersect(rect, pItem->GetOverDrawRect(true, true)))
    {
      DrawChild(pContext, pItem);
    }
  }

  delete pIt;

  if (GetDebug())
  {
    pContext->SetStrokeColor(nuiColor("red"));
    pContext->DrawRect(GetRect().Size(), eStrokeShape);
    pContext->SetStrokeColor(nuiColor("blue"));
    pContext->DrawRect(GetIdealRect().Size(), eStrokeShape);
    pContext->SetStrokeColor("yellow");
    float h = GetRect().GetHeight() - scrollh - 1;
    pContext->DrawLine(0, h, GetRect().GetWidth(), h);
  }
  return true;
}
Пример #3
0
nuiRect nuiFlowView::CalcIdealSize()
{
  if (mCurrentIdealWidth == 0)
  {
    if (GetObjectName() == "Grid")
    {
      NGL_OUT("Flow Layout %p '%s'\n", this, GetObjectName().GetChars());
    }
  }
  if (mIdealWidth > 0)
  {
    mCurrentIdealWidth = mIdealWidth;
  }
  else if (mRect.GetWidth() > 0)
  {
    mCurrentIdealWidth = mRect.GetWidth();
  }
  nuiRect idealsize = Layout(false, mCurrentIdealWidth);

  if (GetDebug())
  {
    NGL_OUT(_T("nuiFlowView::CalcIdealSize[%f]: %s\n"), mCurrentIdealWidth, idealsize.GetValue().GetChars());
  }

  return idealsize;
}
Пример #4
0
int main(int argc, char* argv[])
{
	int argPos = 0, argNum = argc, ncid;
	char *fname = (char *) NULL, *tname = "time";
	FILE *output = stdout;
	NCtable_t *tbl = (NCtable_t *) NULL;

	initMemInfo();
	for(argPos = 1; argPos < argNum;) {
		if (CMargTest(argv[argPos],"-d","--debug"))
                    {
                    SetDebug();
                    CMargShiftLeft(argPos,argv,argc);
                    argNum--;
                    continue;
                    }
		if (CMargTest(argv[argPos],"-h","--help")) {
			if((argPos + 1 < argNum) && (argv[argPos+1][0] == 'e')) doHelp (CMprgName(argv[0]),true);
			else doHelp (CMprgName (argv[0]),false);
			cleanup(NCsucceeded);
		}
		if (CMargTest(argv[argPos],"-t","--table"))
		{
			CMargShiftLeft(argPos,argv,argc); argNum--;
			tname = argv[argPos];
			CMargShiftLeft(argPos,argv,argc); argNum--;
			continue;
		}
		if (CMargTest(argv[argPos],"-f","--file"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError,"Missing file!");  return (CMfailed); }
			fname = argv[argPos];
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if (CMargTest(argv[argPos],"-o","--output"))
		{
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos)
                            { CMmsgPrint (CMmsgUsrError,"Missing output!");  return (CMfailed); }
			if(output != stdout) { CMmsgPrint (CMmsgUsrError, "Output file defined twice!"); cleanup(NCfailed); }
			if((output = fopen(argv[argPos],"w")) == (FILE *) NULL)
				{ CMmsgPrint (CMmsgUsrError, "Cannot open for writing: %s",argv[argPos]); cleanup(NCfailed); }
			if ((argNum = CMargShiftLeft(argPos,argv,argc)) <= argPos) break;
			continue;
		}
		if ((argv[argPos][0] == '-') && (strlen (argv[argPos]) > 1))
			{ CMmsgPrint (CMmsgUsrError, "Unknown option: %s!",argv[argPos]); cleanup(NCfailed); }
		argPos++;
	}
	if(fname == (char *) NULL) { doHelp(argv[0],false); CMmsgPrint (CMmsgUsrError, "No file specified!"); cleanup(NCfailed); }
	if(nc_open(fname,NC_NOWRITE,&ncid) != NC_NOERR) { CMmsgPrint (CMmsgUsrError, "Error opening file!"); cleanup(NCfailed); }
	if((tbl = NCtableOpen(ncid,tname)) == (NCtable_t *) NULL) { CMmsgPrint (CMmsgUsrError, "Error opening table!"); cleanup(NCfailed); }
	if(GetDebug()) CMmsgPrint (CMmsgUsrError, "Loaded file!");
	NCtableExportAscii(tbl,output);
	cleanup(NCsucceeded);
}
Пример #5
0
bool nuiSimpleContainer::DelChild(nuiWidgetPtr pChild)
{
  CheckValid();
  NGL_ASSERT(pChild->GetParent() == this)


  if (GetDebug())
  {
    NGL_OUT(_T("[%s] Del Child 0x%x <--- 0x%x (%s)\n"), GetObjectClass().GetChars(), this, pChild);
  }
  
  nuiWidgetList::iterator it  = mpChildren.begin();
  nuiWidgetList::iterator end = mpChildren.end();
  for ( ; it != end; ++it)
  {
    if (*it == pChild)
    {
      mpChildren.erase(it);
      if (!pChild->IsTrashed())
      {
        nuiTopLevel* pRoot = GetTopLevel();
        Trashed();
        Invalidate();
        
        if (pRoot)
          pRoot->AdviseObjectDeath(pChild);
        pChild->SetParent(NULL);
      }
      ChildDeleted(this, pChild);
      Invalidate();
      InvalidateLayout();
      DebugRefreshInfo();
      pChild->Release();
      return true;
    }
  }
  DebugRefreshInfo();
  return false;
}
Пример #6
0
nuiRect nuiScrollView::CalcIdealSize()
{
  nuiRect rect;

  IteratorPtr pIt;
  for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt))
  {
    nuiWidgetPtr pItem = pIt->GetWidget();
    if (pItem != mpHorizontal && pItem != mpVertical)
    {
      pItem->SetLayoutConstraint(mConstraint);
      rect.Union(rect, pItem->GetIdealRect()); 
    }
    else if (pItem)
    {
      pItem->GetIdealRect(); // Dummy get ideal rect for the scroll bars
    }
  }
  delete pIt;

  rect.mLeft = 0;
  rect.mTop = 0;

  mChildrenUnionRect = rect;
  ///< take scrollbars in IdealRect calculation if necessary
  rect.SetSize(rect.GetWidth() + (mpHorizontal && !mHorizontalIsExternal && !mForceNoHorizontal && !mHideScrollBars ? mBarSize : 0),
               rect.GetHeight() + (mpVertical && !mVerticalIsExternal && !mForceNoVertical && !mHideScrollBars ? mBarSize : 0));
  mIdealRect = rect;

  #ifdef _DEBUG_LAYOUT
  if (GetDebug())
  {
    NGL_OUT(_T("nuiScrollView::CalcIdealSize: %s\n"), mIdealRect.GetValue().GetChars());
  }
  #endif
  
  return mIdealRect;
}
Пример #7
0
bool nuiSimpleContainer::AddChild(nuiWidgetPtr pChild)
{
  CheckValid();
  if (GetDebug())
  {
    NGL_OUT(_T("[%s] Add Child 0x%x <--- 0x%x\n"), GetObjectClass().GetChars(), this, pChild);
  }
  pChild->Acquire();
  nuiContainer* pParent = pChild->GetParent();
  NGL_ASSERT(pParent != this);
  
  uint32 capacity = mpChildren.capacity();
  uint32 size = mpChildren.size();
  if (size == capacity)
  {
    if (size < 128)
    {
      mpChildren.reserve(size * 2);
    }
    else
    {
      mpChildren.reserve(size + 128);
    }
  }
  
  mpChildren.push_back(pChild);
  if (pParent)
    pParent->DelChild(pChild); // Remove from previous parent...
  
  pChild->SetParent(this);
  ChildAdded(this, pChild);
  Invalidate();
  InvalidateLayout();
  
  DebugRefreshInfo();
  return true;
}
Пример #8
0
NCtable_t *NCtableOpen(int ncid, char *tablename)
{
	int status, *dimids, dimid, i = 0, j = 0;
	int ndims, nvars;
	size_t nrecords;
	size_t len;
	char varname [NC_MAX_NAME];
	nc_type type;
	NCfield_t *field = (NCfield_t *) NULL;
	NCtable_t *tbl   = (NCtable_t *) NULL;

	if((status = nc_inq_dimid  (ncid,tablename,&dimid)) != NC_NOERR)
	{ NCprintNCError (status,"NCtableOpen"); return ((NCtable_t *) NULL); }
	if((status = nc_inq_dimlen (ncid,dimid,&nrecords))  != NC_NOERR)
	{ NCprintNCError (status,"NCtableOpen"); return ((NCtable_t *) NULL); }
	if((status = nc_inq_nvars  (ncid,&nvars))           != NC_NOERR)
	{ NCprintNCError (status,"NCtableOpen"); return ((NCtable_t *) NULL); }
	if(nc_inq_ndims(ncid,&ndims) != NC_NOERR)
	{ NCprintNCError (status,"NCtableOpen"); return ((NCtable_t *) NULL); }
	if ((dimids = (int *) malloc(sizeof(int) * ndims)) == (int *) NULL)
	{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return (NCtable_t *) NULL; }

	if ((tbl = (NCtable_t *) malloc(sizeof(NCtable_t))) == (NCtable_t *) NULL)
	{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); free (dimids); return ((NCtable_t *) NULL); }
	if ((tbl->Name = (char *) malloc (strlen(tablename) + 1)) == (char *) NULL)
	{ CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); free (dimids); free (tbl); return ((NCtable_t *) NULL); }
	strcpy(tbl->Name,tablename);
	tbl->NFields  = 0;
	tbl->Fields   = (NCfield_t *) NULL;

	for(i = 0; i < nvars; i++)
	{
		if ((status = nc_inq_vartype(ncid,i,&type)) != NC_NOERR)
		{ NCprintNCError (status,"NCtableOpen"); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
		if ((len = _NCtableVarLen(ncid,i,dimid,dimids)) == NCfailed) continue;
		if ((type != NC_CHAR) && (len > 1)) continue;

		if((status = nc_inq_varname(ncid,i,varname)) != NC_NOERR)
		{ NCprintNCError (status,"NCtableOpen"); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }

		if ((tbl->Fields = (NCfield_t *) realloc (tbl->Fields, sizeof (NCfield_t) * (tbl->NFields + 1))) == (NCfield_t *) NULL)
		{ CMmsgPrint (CMmsgSysError, "Error allocating memory in: %s %d",__FILE__,__LINE__); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
		field = tbl->Fields + tbl->NFields;
		tbl->NFields += 1;
		field->NRecords = nrecords;
		field->Data = (void *) NULL;
		field->Name = (char *) NULL;
		field->Type = type;
		field->Len  = len;

		if ((field->Name = malloc (strlen (varname) + 1)) == (char *) NULL)
		{ CMmsgPrint (CMmsgSysError, "Error allocating memory in: %s %d",__FILE__,__LINE__); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
		strcpy (field->Name,varname);

		if (nc_get_att_double (ncid,i,NCnameVAScaleFactor,&field->Scale)      != NC_NOERR) field->Scale      = 1.0;
		if (nc_get_att_double (ncid,i,NCnameVAAddOffset,  &field->Offset)     != NC_NOERR) field->Offset     = 0.0;

		switch(field->Type)
		{
			case NC_CHAR:
				if ((field->Data = (void *) malloc(field->NRecords * field->Len * sizeof (char)))   == (void *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Error allocating memory in: %s %d",__FILE__,__LINE__); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
				if((status = nc_get_var_text(ncid,i,(char *) (field->Data))) != NC_NOERR)
				{ NCprintNCError (status,"NCtableOpen"); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
				break;
			case NC_BYTE:
			case NC_SHORT:
			case NC_INT:
				if ((field->Data = (void *) malloc(field->NRecords * field->Len * sizeof (int)))   == (void *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Error allocating memory in: %s %d",__FILE__,__LINE__); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
				if((status = nc_get_var_int(ncid,i,(int *) (field->Data))) != NC_NOERR)
				{ NCprintNCError (status,"NCtableOpen"); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
				if (nc_get_att_int    (ncid,i,NCnameVAFillValue,  &field->FillValue.Int)  != NC_NOERR) field->FillValue.Int  = INT_NOVALUE;
				if (nc_get_att_double (ncid,i,NCnameVAMissingVal, &field->MissingVal)     != NC_NOERR) field->MissingVal     = FLOAT_NOVALUE;
				break;
			case NC_FLOAT:
			case NC_DOUBLE:
				if ((field->Data = (void *) malloc(field->NRecords * field->Len * sizeof (double))) == (void *) NULL)
				{ CMmsgPrint (CMmsgSysError, "Error allocating memory in: %s %d",__FILE__,__LINE__); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
				if((status = nc_get_var_double(ncid,i,(double *) (field->Data))) != NC_NOERR)
				{ NCprintNCError (status,"NCtableOpen"); free (dimids); NCtableClose (tbl); return ((NCtable_t *) NULL); }
				if (nc_get_att_double (ncid,i,NCnameVAFillValue,  &field->FillValue.Float)  != NC_NOERR) field->FillValue.Float = FLOAT_NOVALUE;
				if (nc_get_att_double (ncid,i,NCnameVAMissingVal, &field->MissingVal)       != NC_NOERR) field->MissingVal      = FLOAT_NOVALUE;
				break;
			default:        field->Data = (void *) NULL; break;
		}
		if(GetDebug()) CMmsgPrint (CMmsgUsrError, "Loaded: %s(dimid: %d)\n",field->Name,dimid);
	}

	if(GetDebug())
	{
		CMmsgPrint (CMmsgUsrError, "Dim: %d Name: %s Cols: %d Rows: %d\n",dimid,tbl->Name,tbl->NFields,field->NRecords);
		for(i = 0; i < tbl->NFields; i++)
		{
			field = tbl->Fields + i;
			CMmsgPrint (CMmsgUsrError, "\tField: %d Name: %s ",i,field->Name);
			switch(field->Type)
			{
				case NC_CHAR:
					if(field->Len == 1)
					{
						CMmsgPrint (CMmsgUsrError, "Type: char\n");
						for(j = 0; j < 5; j++) CMmsgPrint (CMmsgUsrError, "\t\t%d %c\n",j,((char *) (field->Data)) [j]);
					}
					else
					{
						CMmsgPrint (CMmsgUsrError, "Type: string\n");
						for(j = 0; j < 5; j++) CMmsgPrint (CMmsgUsrError, "\t\t%d %s\n",j,((char *) (field->Data)) + j * field->Len);
					}
					break;
				case NC_BYTE:
				case NC_SHORT:
				case NC_INT:
					CMmsgPrint (CMmsgUsrError, "Type: int\n");
					for(j = 0; j < 5; j++) CMmsgPrint (CMmsgUsrError, "\t\t%d %i\n",j,((int *)    (field->Data)) [j]);
					break;
				case NC_FLOAT:
				case NC_DOUBLE:
					CMmsgPrint (CMmsgUsrError, "Type: double\n");
					for(j = 0; j < 5; j++) CMmsgPrint (CMmsgUsrError, "\t\t%d %f\n",j,((double *) (field->Data)) [j]);
					break;
				default: break;
			}
		}
	}
	return (tbl);
}
Пример #9
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;
}
Пример #10
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;
}
Пример #11
0
bool nuiLabel::Draw(nuiDrawContext* pContext)
{
  if (GetDebug())
    NGL_OUT(_T("Draw 0x%x (%s)\n"), this, mText.GetChars());
  nuiColor Color = GetTextColor();
  nuiColor ColorBg = GetBackgroundColor();

  CalcLayout();

  pContext->SetFont(mpFont);

  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 + 1;
  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;
}