void CAniVScroller::Paint (SAniPaintCtx &Ctx)

//	Paint
//
//	Paint the lines

{
    int i;

    //	Basic metrics

    Metric yScrollPos = m_Properties[INDEX_SCROLL_POS].GetMetric();
    Metric cyViewport = m_Properties[INDEX_VIEWPORT_HEIGHT].GetMetric();
    Metric cyFadeEdge = m_Properties[INDEX_FADE_EDGE_HEIGHT].GetMetric();
    DWORD dwBaseOpacity = m_Properties[INDEX_OPACITY].GetOpacity() * Ctx.dwOpacityToDest / 255;

    //	Transform

    CVector vPos = m_Properties[INDEX_POSITION].GetVector();
    CXForm LocalToDest = CXForm(xformTranslate, vPos - CVector(0.0, yScrollPos)) * Ctx.ToDest;

    //	Local paint ctx

    SAniPaintCtx LocalCtx(Ctx.Dest,
                          LocalToDest,
                          0,
                          Ctx.iFrame);

    //	Clip

    RECT rcSavedClip = Ctx.Dest.GetClipRect();

    RECT rcClip = rcSavedClip;
    rcClip.top = (int)vPos.GetY();
    rcClip.bottom = (int)(vPos.GetY() + cyViewport);
    Ctx.Dest.SetClipRect(rcClip);

    //	Loop over all lines

    for (i = 0; i < m_List.GetCount(); i++)
    {
        SLine *pList = &m_List[i];

        //	Are we in the viewport?

        RECT rcLine;
        pList->pAni->GetSpacingRect(&rcLine);
        Metric cyLine = (Metric)RectHeight(rcLine);

        Metric yLinePos = pList->pAni->GetPropertyVector(PROP_POSITION).GetY() - yScrollPos;
        if (yLinePos + cyLine < 0.0 || yLinePos >= cyViewport)
            continue;

        //	Fade edges

        if (cyFadeEdge > 0.0)
        {
            if (yLinePos < 0.0)
                LocalCtx.dwOpacityToDest = 0;
            else if (yLinePos < cyFadeEdge)
                LocalCtx.dwOpacityToDest = (DWORD)((Metric)dwBaseOpacity * (yLinePos / cyFadeEdge));
            else if (yLinePos + cyFadeEdge > cyViewport)
                LocalCtx.dwOpacityToDest = (DWORD)((Metric)dwBaseOpacity * (cyViewport - yLinePos) / cyFadeEdge);
            else
                LocalCtx.dwOpacityToDest = dwBaseOpacity;
        }
        else
            LocalCtx.dwOpacityToDest = dwBaseOpacity;

        //	Paint

        pList->pAni->Paint(LocalCtx);
    }

    Ctx.Dest.SetClipRect(rcSavedClip);
}
Example #2
0
void CGroupOfGenerators::AddItems (SItemAddCtx &Ctx)

//	AddItems
//
//	Add items

	{
	int i, j;

	//	If we need to adjust counts, then do a separate algorithm

	if (SetsAverageValue())
		{
		//	Get the count adjustment.

		Metric rCountAdj = GetCountAdj(Ctx.iLevel);
		Metric rLoops = floor(rCountAdj);
		Metric rLastLoopAdj = rCountAdj - rLoops;

		//	Loop if we have extra items

		int iFullLoops = (int)rLoops;
		for (i = 0; i < iFullLoops + 1; i++)
			{
			//	For a full loop we just add the items

			if (i < iFullLoops)
				AddItemsInt(Ctx);

			//	Otherwise we need to add partial items

			else
				{
				//	Add the items to a private list.

				CItemList LocalList;
				CItemListManipulator ItemList(LocalList);
				SItemAddCtx LocalCtx(ItemList);
				LocalCtx.iLevel = Ctx.iLevel;
				AddItemsInt(LocalCtx);

				//	Now loop over the items and adjust the count appropriately.

				for (j = 0; j < LocalList.GetCount(); j++)
					{
					const CItem &Item = LocalList.GetItem(j);
					int iOriginalCount = Item.GetCount();

					//	Adjust the count

					Metric rNewCount = iOriginalCount * rLastLoopAdj;
					Metric rNewCountInt = floor(rNewCount);
					int iNewCount = (int)rNewCountInt;

					Metric rExtra = rNewCount - rNewCountInt;
					int iExtraChance = (int)(100000.0 * rExtra);
					if (mathRandom(0, 100000) < iExtraChance)
						iNewCount++;

					//	Add the item with the new count

					if (iNewCount > 0)
						{
						if (iNewCount == iOriginalCount)
							Ctx.ItemList.AddItem(Item);
						else
							{
							CItem NewItem(Item);
							NewItem.SetCount(iNewCount);
							Ctx.ItemList.AddItem(NewItem);
							}
						}
					}
				}
			}
		}
	else
		AddItemsInt(Ctx);
	}