//-----------------------------------------------------------------------------
//
// Look for vgui screens, returns true if it found one ...
//
//-----------------------------------------------------------------------------
C_BaseEntity *FindNearbyVguiScreen( const Vector &viewPosition, const QAngle &viewAngle, int nTeam )
{
	if ( IsX360() )
	{
		// X360TBD: Turn this on if feature actually used
		return NULL;
	}

	C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();

	Assert( pLocalPlayer );

	if ( !pLocalPlayer )
		return NULL;

	// Get the view direction...
	Vector lookDir;
	AngleVectors( viewAngle, &lookDir );

	// Create a ray used for raytracing 
	Vector lookEnd;
	VectorMA( viewPosition, 2.0f * VGUI_SCREEN_MODE_RADIUS, lookDir, lookEnd );

	Ray_t lookRay;
	lookRay.Init( viewPosition, lookEnd );

#ifndef C17
	// Look for vgui screens that are close to the player
	CVGuiScreenEnumerator localScreens;
	partition->EnumerateElementsInSphere( PARTITION_CLIENT_NON_STATIC_EDICTS, viewPosition, VGUI_SCREEN_MODE_RADIUS, false, &localScreens );
#endif

	Vector vecOut, vecViewDelta;

	float flBestDist = 2.0f;
	C_VGuiScreen *pBestScreen = NULL;
#ifdef C17
	for (int i = 0; i < g_pVGUIScreens.Count(); i++)
	{
		if (g_pVGUIScreens.IsValidIndex(i))
		{
			C_VGuiScreen *pScreen = g_pVGUIScreens[i];
#else
	for (int i = localScreens.GetScreenCount(); --i >= 0; )
	{
		C_VGuiScreen *pScreen = localScreens.GetVGuiScreen(i);
#endif

		if (pScreen->IsAttachedToViewModel())
			continue;

		// Don't bother with screens I'm behind...
		// Hax - don't cancel backfacing with viewmodel attached screens.
		// we can get prediction bugs that make us backfacing for one frame and
		// it resets the mouse position if we lose focus.
		if (pScreen->IsBackfacing(viewPosition))
			continue;

		// Don't bother with screens that are turned off
		if (!pScreen->IsActive())
			continue;

		// FIXME: Should this maybe go into a derived class of some sort?
		// Don't bother with screens on the wrong team
		if (!pScreen->IsVisibleToTeam(nTeam))
			continue;

		if (!pScreen->AcceptsInput())
			continue;

		if (pScreen->IsInputOnlyToOwner() && pScreen->GetPlayerOwner() != pLocalPlayer)
			continue;

		// Test perpendicular distance from the screen...
		pScreen->GetVectors(NULL, NULL, &vecOut);
		VectorSubtract(viewPosition, pScreen->GetAbsOrigin(), vecViewDelta);
		float flPerpDist = DotProduct(vecViewDelta, vecOut);
		if ((flPerpDist < 0) || (flPerpDist > VGUI_SCREEN_MODE_RADIUS))
			continue;

		// Perform a raycast to see where in barycentric coordinates the ray hits
		// the viewscreen; if it doesn't hit it, you're not in the mode
		float u, v, t;
		if (!pScreen->IntersectWithRay(lookRay, &u, &v, &t))
			continue;

		// Barycentric test
		if ((u < 0) || (v < 0) || (u > 1) || (v > 1))
			continue;

		if (t < flBestDist)
		{
			flBestDist = t;
			pBestScreen = pScreen;
		}
		}
#ifdef C17
	}
#endif
	
	return pBestScreen;
}

void ActivateVguiScreen( C_BaseEntity *pVguiScreenEnt )
{
	if (pVguiScreenEnt)
	{
		Assert( dynamic_cast<C_VGuiScreen*>(pVguiScreenEnt) );
		C_VGuiScreen *pVguiScreen = static_cast<C_VGuiScreen*>(pVguiScreenEnt);
		pVguiScreen->GainFocus( );
	}
}

void SetVGuiScreenButtonState( C_BaseEntity *pVguiScreenEnt, int nButtonState )
{
	if (pVguiScreenEnt)
	{
		Assert( dynamic_cast<C_VGuiScreen*>(pVguiScreenEnt) );
		C_VGuiScreen *pVguiScreen = static_cast<C_VGuiScreen*>(pVguiScreenEnt);
		pVguiScreen->SetButtonState( nButtonState );
	}
}

void DeactivateVguiScreen( C_BaseEntity *pVguiScreenEnt )
{
	if (pVguiScreenEnt)
	{
		Assert( dynamic_cast<C_VGuiScreen*>(pVguiScreenEnt) );
		C_VGuiScreen *pVguiScreen = static_cast<C_VGuiScreen*>(pVguiScreenEnt);
		pVguiScreen->LoseFocus( );
	}
}

CVGuiScreenPanel::CVGuiScreenPanel( vgui::Panel *parent, const char *panelName )
	: BaseClass( parent, panelName )
{
	m_hEntity = NULL;
}

CVGuiScreenPanel::CVGuiScreenPanel( vgui::Panel *parent, const char *panelName, vgui::HScheme hScheme )
	: BaseClass( parent, panelName, hScheme )
{
	m_hEntity = NULL;
}


bool CVGuiScreenPanel::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
{
	const char *pResFile = pKeyValues->GetString( "resfile" );
	if (pResFile[0] != 0)
	{
		KeyValues *pCachedKeyValues = CacheKeyValuesForFile( pResFile );
		LoadControlSettings( pResFile, NULL, pCachedKeyValues );
	}

	// Dimensions in pixels
	int nWidth, nHeight;
	nWidth = pKeyValues->GetInt( "pixelswide", 240 );
	nHeight = pKeyValues->GetInt( "pixelshigh", 160 );
	if ((nWidth <= 0) || (nHeight <= 0))
		return false;

	// If init data isn't specified, then we're just precaching.
	if ( pInitData )
	{
		m_hEntity.Set( pInitData->m_pEntity );

		C_VGuiScreen *screen = dynamic_cast< C_VGuiScreen * >( pInitData->m_pEntity );
		if ( screen )
		{
			bool acceptsInput = pKeyValues->GetInt( "acceptsinput", 1 ) ? true : false;
			screen->SetAcceptsInput( acceptsInput );
		}
	}

	SetBounds( 0, 0, nWidth, nHeight );

	return true;
}

vgui::Panel *CVGuiScreenPanel::CreateControlByName(const char *controlName)
{
	// Check the panel metaclass manager to make these controls...
	if (!Q_strncmp(controlName, "MaterialImage", 20))
	{
		return new CBitmapPanel(NULL, "BitmapPanel");
	}

	if (!Q_strncmp(controlName, "MaterialButton", 20))
	{
		return new CBitmapButton(NULL, "BitmapButton", "");
	}

	// Didn't find it? Just use the default stuff
	return BaseClass::CreateControlByName( controlName );
}

//-----------------------------------------------------------------------------
// Purpose: Called when the user presses a button
//-----------------------------------------------------------------------------
void CVGuiScreenPanel::OnCommand( const char *command)
{
	if ( Q_stricmp( command, "vguicancel" ) )
	{
		engine->ClientCmd( const_cast<char *>( command ) );
	}

	BaseClass::OnCommand(command);
}

DECLARE_VGUI_SCREEN_FACTORY( CVGuiScreenPanel, "vgui_screen_panel" );
예제 #2
0
View& View::SetBounds(Attach bottom, Attach top,  Attach left, Attach right, double aspect)
{
    this->aspect = aspect;
    SetBounds(top,bottom,left,right);
    return *this;
}
예제 #3
0
	void CCircleCollider::CalculateBounds()
	{
		SetBounds(sf::FloatRect(GetPosition().x, GetPosition().y, (m_Radius * 2.f), (m_Radius * 2.f)));
	}
예제 #4
0
void AccessibilityTreeNode::Merge(AccessibilityTreeNode* node)
{
	int i = 0, j = 0;
	AccessibilityTreeNode* my_child = m_children.Get(i);
	AccessibilityTreeNode* your_child = node->m_children.Get(j);
	while (my_child || your_child)
	{
		if (my_child && !your_child)
		{
			OP_DELETE(my_child);
			my_child = m_children.Get(i);
		}
		else if (your_child && !my_child)
		{
			your_child->Reparent(this);
			your_child = node->m_children.Get(j);
		}
		else
		{
			if (my_child->Compare(your_child))
			{
				my_child->Merge(your_child);
				i++;
				j++;
			}
			else
			{
				int j2 = j+1;
				your_child = node->m_children.Get(j2);
				while (your_child)
				{
					if (my_child->Compare(your_child))
					{
						int diff = j2 - j;
						my_child->Merge(your_child);
						for (int k = 0; k < diff; k++)
							node->m_children.Remove(j)->Reparent(this, i + k);
						j++;
						i+= 1+diff;
						break;
					}
					j2++;
					your_child = node->m_children.Get(j2);
				}
				if (!your_child)
				{
					OP_DELETE(my_child);
				}
			}
			my_child = m_children.Get(i);
			your_child = node->m_children.Get(j);
		}
	}
	OpRect bounds;
	node->GetBounds(bounds);
	if (!m_bounds.Equals(bounds))
	{
		BOOL moved = (bounds.x != m_bounds.x) || (bounds.y != m_bounds.y);
		BOOL resized = (bounds.width != m_bounds.width) || (bounds.height != m_bounds.height);
		SetBounds(bounds);
		BoundsChanged(moved, resized);
	}
}
예제 #5
0
View& View::SetBounds(Attach bottom, Attach top,  Attach left, Attach right, bool keep_aspect)
{
    aspect = keep_aspect ? v.aspect() : 0;
    SetBounds(top,bottom,left,right);
    return *this;
}
예제 #6
0
파일: camera.cpp 프로젝트: kanc/UTAD
Camera::Camera() {
	SetBounds(-1, -1, -1, -1);
	SetPosition(0, 0);
	followingSprite = NULL;
}
예제 #7
0
HRESULT ui::UIListBox::Initialize(graphics::D3DInteropHelper *pD3DInteropHelper) {
#ifdef DEBUG_UILISTBOX
  LOG_ENTER(SEVERITY_LEVEL_DEBUG);
#endif
  assert(GetWidth() > 0.0f);
  assert(GetHeight() > 0.0f);

  ui::UIListBoxItem::LAYOUT_DIRECTION layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_VERTICAL;

  switch (m_scrollDirection) {
  case ui::UIListBox::SCROLL_DIRECTION_HORIZONTAL:
    layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_VERTICAL;
    m_itemHeight = GetHeight();
    if (m_preferredTextAreaSize.height == 0.0f) {
      m_preferredTextAreaSize.height = GetHeight() - m_preferredBitmapSize.height - m_marginBetweenBitmapAndText;
    }
    if (m_preferredTextAreaSize.width == 0.0f) {
      m_preferredTextAreaSize.width = m_preferredBitmapSize.width * 3.0f;
    }
    m_itemWidth = m_preferredTextAreaSize.width;
    break;
  case ui::UIListBox::SCROLL_DIRECTION_VERTICAL:
    layoutDirection = ui::UIListBoxItem::LAYOUT_DIRECTION_HORIZONTAL;
    m_itemWidth = GetWidth();
    if (m_preferredTextAreaSize.width == 0.0f) {
      m_preferredTextAreaSize.width = GetWidth() - m_preferredBitmapSize.width - m_marginBetweenBitmapAndText;
    }
    if (m_preferredTextAreaSize.height == 0.0f) {
      m_preferredTextAreaSize.height = m_preferredBitmapSize.height;
    }
    m_itemHeight = m_preferredTextAreaSize.height;
    break;
  }
  for (size_t i = 0; i < GetNumberOfElements(); ++i) {
    auto element = GetElement(i);
    auto listBoxItem = std::dynamic_pointer_cast<UIListBoxItem>(element);
    if (listBoxItem.get() != nullptr) {
      listBoxItem->SetLayoutDirection(layoutDirection);
      listBoxItem->SetPreferredBitmapSize(m_preferredBitmapSize);
      listBoxItem->SetPreferredTextAreaSize(m_preferredTextAreaSize);
      listBoxItem->SetBounds(0.0f, 0.0f, m_itemWidth, m_itemHeight);
    }
  }
  CHK_WARN_HRESULT(UIContainer::Initialize(pD3DInteropHelper));

  auto frameDecorator = std::make_shared<graphics::decorator::FrameDecorator>();
  frameDecorator->SetColorSet(m_colorSet);
  for (size_t i = 0; i < m_colorSet->GetNumberOfColors(); ++i) {
    frameDecorator->AddFrame(graphics::decorator::Frame(i));
  }
  m_rectFigure->AddDecorator(frameDecorator);

  m_rectFigure->SetX(0.0f);
  m_rectFigure->SetY(0.0f);
  m_rectFigure->SetWidth(GetWidth());
  m_rectFigure->SetHeight(GetHeight());
  m_rectFigure->SetColor(graphics::color::ColorValue(graphics::color::ColorValue::COLOR_TYPE_RGBA, 0x222222, 1.0f),
                         graphics::color::COLOR_PATTERN_FLAT);
  CHK_WARN_HRESULT(m_rectFigure->Initialize(pD3DInteropHelper));

  m_scrollBar->SetParentContainer(shared_from_this());
  m_scrollBar->SetMinValue(0.0f);
  m_scrollBar->SetMaxValue(GetNumberOfElements() - 1.0f);
  m_scrollBar->SetPageSize(1.0f);
  if (m_scrollBar->GetCurrentValue() < m_scrollBar->GetMinValue()
      || m_scrollBar->GetCurrentValue() > m_scrollBar->GetMaxValue() - m_scrollBar->GetPageSize()) {
    m_scrollBar->SetCurrentValue(0.0f);
  }
  FLOAT frameThick = static_cast<FLOAT>(m_colorSet->GetNumberOfColors());
  if (m_scrollDirection == ui::UIListBox::SCROLL_DIRECTION_HORIZONTAL) {
    m_scrollBar->SetDirection(ui::UIScrollBar::SCROLLBAR_DIRECTION_HORIZONTAL);
    m_scrollBar->SetBounds(frameThick + m_scrollBarMarginFromSide,
                           GetHeight() - m_scrollBarThick - frameThick - m_scrollBarMarginFromSide,
                           GetWidth() - (frameThick + m_scrollBarMarginFromSide) * 2, m_scrollBarThick);
  } else {
    m_scrollBar->SetDirection(ui::UIScrollBar::SCROLLBAR_DIRECTION_VERTICAL);
    m_scrollBar->SetBounds(GetWidth() - m_scrollBarThick - frameThick - m_scrollBarMarginFromSide,
                           frameThick + m_scrollBarMarginFromSide, m_scrollBarThick,
                           GetHeight() - (frameThick + m_scrollBarMarginFromSide) * 2);
  }
  m_scrollBar->AddPositionChangedCallback([&](FLOAT position) { NotifyScrollPositionChanged(position); });
  CHK_FATAL_HRESULT(m_scrollBar->Initialize(pD3DInteropHelper));

#ifdef DEBUG_UILISTBOX
  LOG_LEAVE(SEVERITY_LEVEL_DEBUG);
#endif
  return S_OK;
}
예제 #8
0
void gxViewElement::SetSize( const gxPix aNewSize, bool aOnMajorAxis )
{
    gxRect iBounds = GetBounds();
    iBounds.SetSize( aNewSize, aOnMajorAxis );
    SetBounds( iBounds );
}
예제 #9
0
int GraphPaper(vector<T_Point> &points, 
               int nRows, int nCols,
               FlatMatrix2D<int> &bins,
               FlatMatrix2D<int> &scoreMat,
               FlatMatrix2D<Arrow> &pathMat,
               vector<bool> &onOptPath) {

  bins.Resize(nRows, nCols);
	bins.Fill(0);
  scoreMat.Resize(nRows+1, nCols+1);
  pathMat.Resize(nRows+1, nCols+1);
  scoreMat.Fill(0);
  pathMat.Fill(NoArrow);
  onOptPath.resize(points.size());
  fill(onOptPath.begin(), onOptPath.end(), false);

  DNALength xMin, xMax, yMin, yMax;
  SetBounds(points, xMin, xMax, 0); 
  xMax++; // make half-open interval.
  SetBounds(points, yMin, yMax, 1); 
  yMax++; // ditto.
  
  //
  // First set up the grid to optimize over.
  //
  int i;
  for (i = 0; i < points.size(); i++) {
    int rowIndex = GetIndex(points[i].GetX(), xMin, xMax, nRows);
    int colIndex = GetIndex(points[i].GetY(), yMin, yMax, nCols);
    bins[rowIndex][colIndex]+= points[i].length;
  }
	
  //
  // Now optimize using DP.
  //

  // First handle boundary strips
  int r, c;
  for (r = 1; r < nRows+1; r++) {
    scoreMat[r][0] = 0;
    pathMat[r][0]  = Up;
  }
  for (c = 1; c < nCols+1; c++) {
    scoreMat[0][c] = 0;
    pathMat[0][c]  = Left;
  }
  scoreMat[0][0] = 0;
  for (r = 1; r < nRows + 1; r++) {
    for (c = 1; c < nCols + 1; c++) {
      int diagScore, leftScore, upScore;
      diagScore = scoreMat[r-1][c-1];
      leftScore = scoreMat[r][c-1];
      upScore   = scoreMat[r-1][c];
      
      int optScore;
      Arrow optDir;
      if (diagScore >= leftScore and
          diagScore >= upScore) {
        optScore = diagScore;
        optDir   = Diagonal;
      }
      else if (leftScore >= diagScore and 
               leftScore >= upScore) {
        optScore = leftScore;
        optDir   = Left;
      }
      else {
        optScore = upScore;
        optDir   = Up;
      }
      
      scoreMat[r][c] = optScore + bins[r-1][c-1];
      pathMat[r][c]   = optDir;
    }
  }

  r = nRows; c = nCols;
  while (r > 0 or c > 0) {
    Arrow dir = pathMat[r][c];
    pathMat[r][c] = Star;
    if (dir == Diagonal) { r--; c--; }
    else if (dir == Left) { c--; }
    else if (dir == Up) { r--; }
    if (r == 0 and c == 0) { break; }
  }

  //
  // Now mark inclusion/exclusion from matrix.
  //
  int nOpt = 0;
  for (i = 0; i < points.size(); i++) {
    int rowIndex = GetIndex(points[i].GetX(), xMin, xMax, nRows);
    int colIndex = GetIndex(points[i].GetY(), yMin, yMax, nCols);
    if (pathMat[rowIndex+1][colIndex+1] == Star) {
      onOptPath[i] = true;
    }
    else if (pathMat[rowIndex][colIndex+1] == Star) {
      onOptPath[i] = true;
    }
    else if (rowIndex + 2 < nRows and pathMat[rowIndex+2][colIndex+1] == Star) {
      onOptPath[i] = true;
    }
    else if (pathMat[rowIndex+1][colIndex] == Star) {
      onOptPath[i] = true;
    }
    else if (colIndex < nCols + 2  and pathMat[rowIndex+1][colIndex+2] == Star) {
      onOptPath[i] = true;
    }
    if (onOptPath[i]) {
      ++nOpt;
    }
  }
  return nOpt;
}
예제 #10
0
void gxViewElement::SetPosition( const gxPix aNewPosition, bool aOnMajorAxis )
{
    gxRect iBounds = GetBounds();
    iBounds.SetPosition( aNewPosition, aOnMajorAxis );
    SetBounds( iBounds );
}
예제 #11
0
void gxViewElement::SetSize( const gxSize& aNewSize )
{
    gxRect iBounds = GetBounds();
    iBounds.SetSize( aNewSize );
    SetBounds( iBounds );
}
예제 #12
0
void gxViewElement::SetPosition( const gxPoint& aNewPosition )
{
    gxRect iBounds = GetBounds();
    iBounds.SetPosition( aNewPosition );
    SetBounds( iBounds );
}
예제 #13
0
PLAYER::PLAYER()
{
  SetBounds(sf::FloatRect(2,0,28,32));
}
예제 #14
0
STATICOBJECT::STATICOBJECT() 
{
  SetBounds(sf::FloatRect(0,0,32,32));
}
예제 #15
0
파일: render.cpp 프로젝트: yxrkt/DigiPen
////////////////////////////////////////////////////////////////////////
// Procedure DrawScene is called whenever the scene needs to be drawn.
void DrawScene(Scene& scene, int width, int height)
{
	// Choose OpenGL or student rendering here.  The decision can be
	// based on useOpenGLRendering, useFastRendering, or both:

	// if (useOpenGLRendering || useFastRendering)
	if (scene.UseOpenGLRendering)
  {
		DrawSceneWithOpenGL(scene, width, height);
    return;
  }

  // ---------------------------------------------------------------------------
	// Student rendering code goes here
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glBegin(GL_POINTS);

  w = width;
  h = height;
  unsigned nLength = (unsigned) (width * height);

  zBuf = new float[nLength];

  for (unsigned i = 0; i < nLength; ++i)
    zBuf[i] = 1.f;

    // for each object
  size_t nObjects = scene.objects.size();
  for (size_t i = 0; i < nObjects; ++i)
  {
    Object &obj = scene.objects[i];

      // for each polygon
    size_t nPolys = obj.polygons.size();
    for (size_t j = 0; j < nPolys; ++j)
    {
      EdgeTable.clear();
      APolygon &poly = obj.polygons[j];
      std::vector<Vector3D> vVertices;

        // Set polygon color
      float rgba[4];
      Vector3D v3Light = bybyte_cast<Vector3D>(scene.lights[0].position);
      v3Light.normalize();
      SetColor(v3Light, poly[0].N, obj.Kd, rgba);

        // make the A object blue both sides
      if (i == 2)
      {
        for (int c = 0; c < 3; ++c)
          rgba[c] = abs(rgba[c]);
      }

        // Get pixel coords for polygon & push edges
      size_t nVerts = poly.size();
      for (size_t k = 0; k < nVerts; ++k)
      {
          // current vertex
        Vector4D v4T = scene.viewing.Transform(poly[k].V);
        Vector3D v3S = bybyte_cast<Vector3D>(scene.projection.Transform(v4T).Hdiv());
        v3S[0] = (float) FloatToInt((v3S[0] + 1.f) * width / 2.f);
        v3S[1] = (float) FloatToInt((v3S[1] + 1.f) * height / 2.f);

        vVertices.push_back(v3S);
      }

        // put vertices in correct order
      for (size_t k = 0; k < nVerts; ++k)
      {
        unsigned nNext = poly[k].prevIndex;

          // skip horizontal edges
        if ((int) vVertices[k][1] == (int) vVertices[nNext][1])
          continue;

        if (vVertices[k][1] < vVertices[nNext][1])
        {
          Edge e(vVertices[k], vVertices[nNext]);
          EdgeTable.push_back(e);
        }

        else
        {
          Edge e(vVertices[nNext], vVertices[k]);
          EdgeTable.push_back(e);
        }
      }

      ActiveEdgeList.clear();
      EdgeListIt ETIt, AELIt;
      size_t nEdges = EdgeTable.size();

        // Cull / clip edges
      ETIt = EdgeTable.begin();
      while (ETIt != EdgeTable.end())
      {
          // y culling
        if (ETIt->v1[1] < 0.f || ETIt->v0[1] >= height)
          EdgeTable.erase(ETIt++);
        else
        {
            // y clipping
          if (ETIt->v0[1] < 0)
          {
            ETIt->x += (-ETIt->v0[1] * ETIt->dx);
            ETIt->z += (-ETIt->v0[1] * ETIt->dz);
          }
          else if (ETIt->v1[1] > height)
          {
            float fYMax = (float) (height - 1);
            float fYDif = ETIt->v1[1] - fYMax;
            ETIt->v1[1]  = fYMax;
            ETIt->v1[0] -= (fYDif * ETIt->dx);
            ETIt->v1[2] -= (fYDif * ETIt->dz);
          }
          ++ETIt;
        }
      }

        // Set values for scanline 0
      ETIt = EdgeTable.begin();
      while (ETIt != EdgeTable.end())
      {
        if ((ETIt->v0[1] <= 0) && (ETIt->v0[1] != ETIt->v1[1]) && (ETIt->v1[1] != 0.f))
        {
          ActiveEdgeList.push_back(*ETIt);
          EdgeTable.erase(ETIt++);
        }
        else
          ++ETIt;
      }

      ActiveEdgeList.sort();

        // for each scanline
      for (int y = 0; y < height; ++y)
      {
          // draw by pair
        for (AELIt = ActiveEdgeList.begin(); AELIt != ActiveEdgeList.end(); ++AELIt)
        {
          EdgeListIt AELItPrev = AELIt++;
          float z              = AELItPrev->z;
          float dzdx           = (AELIt->z - AELItPrev->z) / (AELIt->x - AELItPrev->x);

          int x0 = FloatToInt(AELItPrev->x), x1 = FloatToInt(AELIt->x);
          SetBounds(x0, x1);
          for (int x = x0; x < x1; ++x)
          {
            if (z < ZBuf(x, y))
            {
              ZBuf(x, y) = z;
              glColor4fv(rgba);
              glVertex2i(x, y);
            }
            z += dzdx;
          }
        }

          // insert edges into AEL
        bool bSort = false;
        ETIt = EdgeTable.begin();
        while (ETIt != EdgeTable.end())
        {
          if (IsInRange((float) y, ETIt->v0[1], ETIt->v1[1]))
          {
            ActiveEdgeList.push_back(*ETIt);
            EdgeTable.erase(ETIt++);
            bSort = true;
          }
          else
            ++ETIt;
        }

          // increment edges on AEL & remove passed edges
        AELIt = ActiveEdgeList.begin();
        while (AELIt != ActiveEdgeList.end())
        {
          AELIt->Inc();

          if (!IsInRange((float) y, AELIt->v0[1], AELIt->v1[1]))
            ActiveEdgeList.erase(AELIt++);
          else
            ++AELIt;
        }

          // sort the AEL
        if (bSort) ActiveEdgeList.sort();

      } // [END] for each scanline
    } // [END] for each polygon
  } // [END] for each object

  delete [] zBuf;

  glEnd();
}
예제 #16
0
NS_IMETHODIMP
nsLeafBoxFrame::Reflow(nsPresContext*   aPresContext,
                     nsHTMLReflowMetrics&     aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus&          aStatus)
{
  // This is mostly a copy of nsBoxFrame::Reflow().
  // We aren't able to share an implementation because of the frame
  // class hierarchy.  If you make changes here, please keep
  // nsBoxFrame::Reflow in sync.

  DO_GLOBAL_REFLOW_COUNT("nsLeafBoxFrame");
  DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);

  NS_ASSERTION(aReflowState.ComputedWidth() >=0 &&
               aReflowState.ComputedHeight() >= 0, "Computed Size < 0");

#ifdef DO_NOISY_REFLOW
  printf("\n-------------Starting LeafBoxFrame Reflow ----------------------------\n");
  printf("%p ** nsLBF::Reflow %d R: ", this, myCounter++);
  switch (aReflowState.reason) {
    case eReflowReason_Initial:
      printf("Ini");break;
    case eReflowReason_Incremental:
      printf("Inc");break;
    case eReflowReason_Resize:
      printf("Rsz");break;
    case eReflowReason_StyleChange:
      printf("Sty");break;
    case eReflowReason_Dirty:
      printf("Drt ");
      break;
    default:printf("<unknown>%d", aReflowState.reason);break;
  }
  
  printSize("AW", aReflowState.availableWidth);
  printSize("AH", aReflowState.availableHeight);
  printSize("CW", aReflowState.ComputedWidth());
  printSize("CH", aReflowState.ComputedHeight());

  printf(" *\n");

#endif

  aStatus = NS_FRAME_COMPLETE;

  // create the layout state
  nsBoxLayoutState state(aPresContext, aReflowState.rendContext);

  nsSize computedSize(aReflowState.ComputedWidth(),aReflowState.ComputedHeight());

  nsMargin m;
  m = aReflowState.mComputedBorderPadding;

  //GetBorderAndPadding(m);

  // this happens sometimes. So lets handle it gracefully.
  if (aReflowState.ComputedHeight() == 0) {
    nsSize minSize = GetMinSize(state);
    computedSize.height = minSize.height - m.top - m.bottom;
  }

  nsSize prefSize(0,0);

  // if we are told to layout intrinic then get our preferred size.
  if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) {
     prefSize = GetPrefSize(state);
     nsSize minSize = GetMinSize(state);
     nsSize maxSize = GetMaxSize(state);
     prefSize = BoundsCheck(minSize, prefSize, maxSize);
  }

  // get our desiredSize
  if (aReflowState.ComputedWidth() == NS_INTRINSICSIZE) {
    computedSize.width = prefSize.width;
  } else {
    computedSize.width += m.left + m.right;
  }

  if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) {
    computedSize.height = prefSize.height;
  } else {
    computedSize.height += m.top + m.bottom;
  }

  // handle reflow state min and max sizes
  // XXXbz the width handling here seems to be wrong, since
  // mComputedMin/MaxWidth is a content-box size, whole
  // computedSize.width is a border-box size...
  if (computedSize.width > aReflowState.mComputedMaxWidth)
    computedSize.width = aReflowState.mComputedMaxWidth;

  if (computedSize.width < aReflowState.mComputedMinWidth)
    computedSize.width = aReflowState.mComputedMinWidth;

  // Now adjust computedSize.height for our min and max computed
  // height.  The only problem is that those are content-box sizes,
  // while computedSize.height is a border-box size.  So subtract off
  // m.TopBottom() before adjusting, then readd it.
  computedSize.height = std::max(0, computedSize.height - m.TopBottom());
  computedSize.height = NS_CSS_MINMAX(computedSize.height,
                                      aReflowState.mComputedMinHeight,
                                      aReflowState.mComputedMaxHeight);
  computedSize.height += m.TopBottom();

  nsRect r(mRect.x, mRect.y, computedSize.width, computedSize.height);

  SetBounds(state, r);
 
  // layout our children
  Layout(state);
  
  // ok our child could have gotten bigger. So lets get its bounds
  aDesiredSize.width  = mRect.width;
  aDesiredSize.height = mRect.height;
  aDesiredSize.ascent = GetBoxAscent(state);

  // the overflow rect is set in SetBounds() above
  aDesiredSize.mOverflowAreas = GetOverflowAreas();

#ifdef DO_NOISY_REFLOW
  {
    printf("%p ** nsLBF(done) W:%d H:%d  ", this, aDesiredSize.width, aDesiredSize.height);

    if (maxElementWidth) {
      printf("MW:%d\n", *maxElementWidth); 
    } else {
      printf("MW:?\n"); 
    }

  }
#endif

  return NS_OK;
}
예제 #17
0
NS_IMETHODIMP
nsLeafBoxFrame::Reflow(nsPresContext*   aPresContext,
                     nsHTMLReflowMetrics&     aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus&          aStatus)
{
  // This is mostly a copy of nsBoxFrame::Reflow().
  // We aren't able to share an implementation because of the frame
  // class hierarchy.  If you make changes here, please keep
  // nsBoxFrame::Reflow in sync.

  DO_GLOBAL_REFLOW_COUNT("nsLeafBoxFrame", aReflowState.reason);
  DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);

  NS_ASSERTION(aReflowState.mComputedWidth >=0 && aReflowState.mComputedHeight >= 0, "Computed Size < 0");

#ifdef DO_NOISY_REFLOW
  printf("\n-------------Starting LeafBoxFrame Reflow ----------------------------\n");
  printf("%p ** nsLBF::Reflow %d R: ", this, myCounter++);
  switch (aReflowState.reason) {
    case eReflowReason_Initial:
      printf("Ini");break;
    case eReflowReason_Incremental:
      printf("Inc");break;
    case eReflowReason_Resize:
      printf("Rsz");break;
    case eReflowReason_StyleChange:
      printf("Sty");break;
    case eReflowReason_Dirty:
      printf("Drt ");
      break;
    default:printf("<unknown>%d", aReflowState.reason);break;
  }
  
  printSize("AW", aReflowState.availableWidth);
  printSize("AH", aReflowState.availableHeight);
  printSize("CW", aReflowState.mComputedWidth);
  printSize("CH", aReflowState.mComputedHeight);

  printf(" *\n");

#endif

  aStatus = NS_FRAME_COMPLETE;

  // create the layout state
  nsBoxLayoutState state(aPresContext, aReflowState, aDesiredSize);

  // coelesce reflows if we are root.
  state.HandleReflow(this);
  
  nsSize computedSize(aReflowState.mComputedWidth,aReflowState.mComputedHeight);

  nsMargin m;
  m = aReflowState.mComputedBorderPadding;

  //GetBorderAndPadding(m);

  // this happens sometimes. So lets handle it gracefully.
  if (aReflowState.mComputedHeight == 0) {
    nsSize minSize(0,0);
    GetMinSize(state, minSize);
    computedSize.height = minSize.height - m.top - m.bottom;
  }

  nsSize prefSize(0,0);

  // if we are told to layout intrinic then get our preferred size.
  if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) {
     nsSize minSize(0,0);
     nsSize maxSize(0,0);
     GetPrefSize(state, prefSize);
     GetMinSize(state,  minSize);
     GetMaxSize(state,  maxSize);
     BoundsCheck(minSize, prefSize, maxSize);
  }

  // get our desiredSize
  if (aReflowState.mComputedWidth == NS_INTRINSICSIZE) {
    computedSize.width = prefSize.width;
  } else {
    computedSize.width += m.left + m.right;
  }

  if (aReflowState.mComputedHeight == NS_INTRINSICSIZE) {
    computedSize.height = prefSize.height;
  } else {
    computedSize.height += m.top + m.bottom;
  }

  // handle reflow state min and max sizes

  if (computedSize.width > aReflowState.mComputedMaxWidth)
    computedSize.width = aReflowState.mComputedMaxWidth;

  if (computedSize.height > aReflowState.mComputedMaxHeight)
    computedSize.height = aReflowState.mComputedMaxHeight;

  if (computedSize.width < aReflowState.mComputedMinWidth)
    computedSize.width = aReflowState.mComputedMinWidth;

  if (computedSize.height < aReflowState.mComputedMinHeight)
    computedSize.height = aReflowState.mComputedMinHeight;

  nsRect r(mRect.x, mRect.y, computedSize.width, computedSize.height);

  SetBounds(state, r);
 
  // layout our children
  Layout(state);
  
  // ok our child could have gotten bigger. So lets get its bounds
  
  // get the ascent
  nscoord ascent = mRect.height;

  // Only call GetAscent when not doing Initial reflow while in PP
  // or when it is Initial reflow while in PP and a chrome doc
  // If called again with initial reflow it crashes because the 
  // frames are fully constructed (I think).
  PRBool isChrome;
  PRBool isInitialPP = nsBoxFrame::IsInitialReflowForPrintPreview(state, isChrome);
  if (!isInitialPP || (isInitialPP && isChrome)) {
    GetAscent(state, ascent);
  }

  aDesiredSize.width  = mRect.width;
  aDesiredSize.height = mRect.height;
  aDesiredSize.ascent = ascent;
  aDesiredSize.descent = 0;

  // NS_FRAME_OUTSIDE_CHILDREN is set in SetBounds() above
  if (mState & NS_FRAME_OUTSIDE_CHILDREN) {
    nsRect* overflowArea = GetOverflowAreaProperty();
    NS_ASSERTION(overflowArea, "Failed to set overflow area property");
    aDesiredSize.mOverflowArea = *overflowArea;
  }

  // max sure the max element size reflects
  // our min width
  nscoord* maxElementWidth = state.GetMaxElementWidth();
  if (maxElementWidth)
  {
     nsSize minSize(0,0);
     GetMinSize(state,  minSize);

     if (mRect.width > minSize.width) {
       if (aReflowState.mComputedWidth == NS_INTRINSICSIZE) {
         *maxElementWidth = minSize.width;
       } else {
         *maxElementWidth = mRect.width;
       }
     } else {
        *maxElementWidth = mRect.width;
     }
  }
#ifdef DO_NOISY_REFLOW
  {
    printf("%p ** nsLBF(done) W:%d H:%d  ", this, aDesiredSize.width, aDesiredSize.height);

    if (maxElementWidth) {
      printf("MW:%d\n", *maxElementWidth); 
    } else {
      printf("MW:?\n"); 
    }

  }
#endif

  return NS_OK;
}
예제 #18
0
void BrowserBubble::MoveTo(int x, int y)
{
    SetBounds(x, y, bounds_.width(), bounds_.height());
}
예제 #19
0
void MainMenu::OnThink()
{
	BaseClass::OnThink();

	SetBounds(0, 0, GameUI2().GetViewport().x, GameUI2().GetViewport().y);
}
예제 #20
0
void CMissile::OnUpdate (Metric rSecondsPerTick)

//	OnUpdate
//
//	Update the beam

	{
	//	If we're already destroyed, then just update the timer until the
	//	vapor trail fades out

	if (m_fDestroyed)
		{
		//	Update the painter

		if (m_pPainter)
			{
			m_pPainter->OnUpdate();

			RECT rcRect;
			m_pPainter->GetRect(&rcRect);
			SetBounds(rcRect);
			}

		//	Done?

		if (--m_iLifeLeft <= 0)
			{
			Destroy(removedFromSystem, NULL);
			return;
			}
		}

	//	Otherwise, update

	else
		{
		int i;
		CSystem *pSystem = GetSystem();
		int iTick = m_iTick + GetDestiny();
		bool bDestroy = false;

		//	Accelerate, if necessary

		if (m_pDesc->m_iAccelerationFactor > 0 
				&& (iTick % 10 ) == 0)
			{
			if (m_pDesc->m_iAccelerationFactor < 100
					|| GetVel().Length() < m_pDesc->m_rMaxMissileSpeed)
				SetVel(GetVel() * (Metric)(m_pDesc->m_iAccelerationFactor / 100.0));
			}

		//	If we can choose new targets, see if we need one now

		if (m_pDesc->CanAutoTarget() && m_pTarget == NULL)
			m_pTarget = GetNearestEnemy(MAX_TARGET_RANGE, false);

		//	If this is a tracking missile, change direction to face the target

		if ((m_pDesc->m_iManeuverability > 0)
				&& m_pTarget 
				&& ((iTick % m_pDesc->m_iManeuverability) == 0))
			{
			//	Get the position and velocity of the target

			CVector vTarget = m_pTarget->GetPos() - GetPos();
			CVector vTargetVel = m_pTarget->GetVel() - GetVel();

			//	Figure out which direction to move in

			Metric rCurrentSpeed = GetVel().Length();
			Metric rTimeToIntercept = CalcInterceptTime(vTarget, vTargetVel, rCurrentSpeed);
			if (rTimeToIntercept > 0.0)
				{
				CVector vInterceptPoint = vTarget + vTargetVel * rTimeToIntercept;
				int iFireAngle = VectorToPolar(vInterceptPoint, NULL);

				//	If we are directional, then we are constrained to specific angles

				if (m_pDesc->m_bDirectional)
					{
					if (!AreAnglesAligned(iFireAngle, m_iRotation, g_RotationAngle / 2))
						{
						int iTurn = (iFireAngle + 360 - m_iRotation) % 360;

						if (iTurn >= 180)
							m_iRotation = (m_iRotation + 360 - g_RotationAngle) % 360;
						else
							m_iRotation = (m_iRotation + g_RotationAngle) % 360;

						}
					}
				else
					{
					if (!AreAnglesAligned(iFireAngle, m_iRotation, 1))
						{
						int iTurn = (iFireAngle + 360 - m_iRotation) % 360;

						if (iTurn >= 180)
							{
							int iTurnAngle = Min((360 - iTurn), g_RotationAngle);
							m_iRotation = (m_iRotation + 360 - iTurnAngle) % 360;
							}
						else
							{
							int iTurnAngle = Min(iTurn, g_RotationAngle);
							m_iRotation = (m_iRotation + iTurnAngle) % 360;
							}

						SetVel(PolarToVector(m_iRotation, rCurrentSpeed));
						}
					}

				SetVel(PolarToVector(m_iRotation, rCurrentSpeed));
				}
			}

		//	Update exhaust

		if (m_pExhaust)
			{
			if (iTick % m_pDesc->m_iExhaustRate)
				{
				if (m_pExhaust->GetCount() == m_pExhaust->GetMaxCount())
					m_pExhaust->Dequeue();

				SExhaustParticle &New = m_pExhaust->GetAt(m_pExhaust->Queue());
				New.vPos = GetPos();
				New.vVel = GetVel();
				}

			for (int i = 0; i < m_pExhaust->GetCount(); i++)
				{
				SExhaustParticle &Particle = m_pExhaust->GetAt(i);
				Particle.vVel = m_pDesc->m_rExhaustDrag * Particle.vVel;
				Particle.vPos = Particle.vPos + Particle.vVel * g_SecondsPerUpdate;
				}
			}

		//	Update the painter

		if (m_pPainter)
			{
			m_pPainter->OnUpdate();

			RECT rcRect;
			m_pPainter->GetRect(&rcRect);
			SetBounds(rcRect);
			}

		//	If we have a vapor trail and need to save rotation, do it

		if (m_pDesc->m_iVaporTrailLength 
				&& m_pDesc->m_iManeuverability)
			{
			//	Compute the current rotation

			int iDirection;
			if (m_pDesc->m_bDirectional)
				iDirection = (AlignToRotationAngle(m_iRotation) + 180) % 360;
			else
				iDirection = (m_iRotation + 180) % 360;

			//	Add the current rotation to the list of saved rotations

			if (m_pSavedRotations == NULL)
				{
				m_pSavedRotations = new int [m_pDesc->m_iVaporTrailLength];
				m_iSavedRotationsCount = 0;
				}

			int iStart = Min(m_iSavedRotationsCount, m_pDesc->m_iVaporTrailLength - 1);
			for (i = iStart; i > 0; i--)
				m_pSavedRotations[i] = m_pSavedRotations[i - 1];

			m_pSavedRotations[0] = iDirection;
			if (m_iSavedRotationsCount < m_pDesc->m_iVaporTrailLength)
				m_iSavedRotationsCount++;
			}

		//	See if the missile hit anything

		if (m_fDetonate && m_pDesc->HasFragments())
			{
			CreateFragments(GetPos());
			CreateHitEffect(GetPos());
			bDestroy = true;
			}
		else if (m_pHit)
			{
			//	If we have fragments, then explode now

			if (m_iHitDir == -1
					&& m_pDesc->HasFragments()
					&& m_iTick >= m_pDesc->m_iProximityFailsafe)
				{
				CreateFragments(m_vHitPos);
				CreateHitEffect(m_vHitPos);
				bDestroy = true;
				}

			//	Otherwise, if this was a direct hit, then we do damage

			else if (m_iHitDir != -1)
				{
				DamageResults result;
				DamageDesc Damage = m_pDesc->m_Damage;
				Damage.AddBonus(m_iBonus);
				Damage.SetCause(m_iCause);
				if (IsAutomatedWeapon())
					Damage.SetAutomatedWeapon();

				result = m_pHit->Damage(this,
						m_vHitPos,
						(m_iHitDir + 360 + mathRandom(0, 30) - 15) % 360,
						Damage);

				//	If we hit another missile (or some small object) there is a chance
				//	that we continue

				if (result == damagePassthrough)
					{
					m_iHitPoints = m_iHitPoints / 2;
					bDestroy = (m_iHitPoints == 0);
					}

				//	Set the missile to destroy itself after a hit

				else if (m_pDesc->m_iPassthrough == 0
						|| result == damageNoDamage 
						|| result == damageAbsorbedByShields
						|| mathRandom(1, 100) > m_pDesc->m_iPassthrough)
					bDestroy = true;

				CreateHitEffect(m_vHitPos);
				}
			}

		//	See if the missile has faded out

		if (bDestroy || --m_iLifeLeft <= 0)
			{
			//	If this is a fragmentation weapon, then we explode at the end of life

			if (!bDestroy && m_pDesc->HasFragments())
				{
				CreateFragments(GetPos());
				CreateHitEffect(GetPos());
				}

			//	If we've got a vapor trail effect, then keep the missile object alive
			//	but mark it destroyed

			int iFadeLife;
			if (m_pDesc->m_iVaporTrailLength)
				{
				m_fDestroyed = true;
				m_iLifeLeft = m_pDesc->m_iVaporTrailLength;
				}

			//	If we've got an effect that needs time to fade out, then keep
			//	the missile object alive

			else if (m_pPainter && (iFadeLife = m_pPainter->GetFadeLifetime()))
				{
				m_pPainter->OnBeginFade();

				m_fDestroyed = true;
				m_iLifeLeft = iFadeLife;
				}

			//	Otherwise, destroy the missile

			else
				{
				Destroy(removedFromSystem, NULL);
				return;
				}
			}
		}

	m_iTick++;
	}