void CaPieInfoData::AddPie2 (LPCTSTR lpszPie, double dPercentage, double dValue) { // // You must set the total capacity. ASSERT (m_dCapacity > 0.0); int r, g, b; r = lRandom() % 255; g = lRandom() % 255; b = lRandom() % 255; double start = 0.0; CaLegendData* pData = new CaLegendData(lpszPie, dPercentage, RGB (r, g, b)); POSITION pos = m_listPie.GetTailPosition (); if (pos != NULL) { CaLegendData* pLegend = m_listPie.GetPrev (pos); start = pLegend->m_dDegEnd; } pData->SetSector (start, start + dPercentage * 3.6); m_listPie.AddTail (pData); // // Add Legend. AddLegend (lpszPie, RGB (r, g, b)); pos = m_listLegend.GetTailPosition(); pData = m_listLegend.GetAt (pos); if (pData) { pData->m_dPercentage = dPercentage; pData->m_dValue = dValue; } }
VOID PolyInitPoints(HWND hWnd) { //PPOLYDATA ppd; //LPBEZBUFFER lpBez; int idx; RECT rect; //if(ppd = (PPOLYDATA)LockWindowInfo(hWnd)) //{ // if(lpBez = (LPBEZBUFFER)GlobalLock(ppd->hBezBuffer)) // { GetClientRect(hWnd,&rect); for(idx=0; idx < BEZ_PTS-1; idx++) { lpBez->pPts[idx].x = lRandom() % rect.right; lpBez->pPts[idx].y = lRandom() % rect.bottom; ppd->pVel[idx].x = PolyNewVel(idx); ppd->pVel[idx].y = PolyNewVel(idx); // } // GlobalUnlock(ppd->hBezBuffer); //} //UnlockWindowInfo(hWnd); } return; }
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M Method: COBall::CImpIBall::Reset Summary: The Reset member method of the IBall interface implementation. Called by outside clients of a COBall object to reset the virtual ball. It is restored to the upper left corner. Args: RECT* pNewRect, Pointer to a RECT structure. Tells the COBall the bounding rectangle within which the ball can move. short nBallSize, The size of the ball in pixels. nBallSize == Width == Height meaning that a circle is assumed. Modifies: ... Returns: void M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/ STDMETHODIMP COBall::CImpIBall::Reset( RECT* pNewRect, short nBallSize) { HRESULT hr = E_FAIL; int nDim, xDirection, yDirection; if (OwnThis()) { // Find the thread who is executing this and remember its color. FindThread(); m_xSkew = m_ySkew = BALL_MOVE_SKEW; m_WinRect.left = pNewRect->left; m_WinRect.top = pNewRect->top; m_WinRect.right = pNewRect->right; m_WinRect.bottom = pNewRect->bottom; nDim = nBallSize ? nBallSize : max(5, m_WinRect.right / 13); SetDimensions(nDim, nDim); SetPosition(0, 0); xDirection = ((lRandom() % m_xSkew) + m_xSkew); yDirection = ((lRandom() % m_ySkew) + m_ySkew); SetDirection(xDirection, yDirection); hr = NOERROR; UnOwnThis(); } return hr; }
void CaBarInfoData::AddBar (LPCTSTR lpszBar) { int r, g, b; r = lRandom() % 255; g = lRandom() % 255; b = lRandom() % 255; m_listBar.AddTail (new CaBarPieItem(lpszBar, RGB (r, g, b))); }
int PolyNewVel(int i) { int nRet; if ((i == 1) || (i == 2)) nRet = (int)((lRandom() % VELMAX) / 3) + VELMIN; else nRet = (int)(lRandom() % VELMAX) + VELMIN; return((nRet < 0) ? -nRet : nRet); }
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M Method: COBall::CImpIBall::CheckBounce Summary: Internal utility method to check the current ball position, dimension, and direction data and determine if the ball has hit the internal WinRect bounding rectangle. If it has then the ball data is recalculated to achieve a "bounce" effect for the ball as it moves. Args: void Modifies: ... Returns: void M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/ void COBall::CImpIBall::CheckBounce(void) { POINT Pos, Dir, Dim; int xNewPos, yNewPos, xNewDir, yNewDir; GetPosition(&Pos); GetDirection(&Dir); GetDimensions(&Dim); // Check each edge of the client rectangle. If the ball goes past the // boundries, reset its position and direction to give it a "bounce" // effect the next time it is displayed. xNewDir = Dir.x; yNewDir = Dir.y; xNewPos = Pos.x + Dir.x; yNewPos = Pos.y + Dir.y; if(xNewPos < m_WinRect.left) { xNewDir = ((lRandom() % m_xSkew) + m_xSkew); SetPosition(m_WinRect.left, Pos.y); } if((xNewPos + Dim.x) > m_WinRect.right) { xNewDir = -(((int)lRandom() % m_xSkew) + m_xSkew); SetPosition(m_WinRect.right - Dim.x, Pos.y); } if(yNewPos < m_WinRect.top) { yNewDir = ((lRandom() % m_ySkew) + m_ySkew); SetPosition(Pos.x, m_WinRect.top); } if((yNewPos + Dim.y) > m_WinRect.bottom) { yNewDir = -(((int)lRandom() % m_ySkew) + m_ySkew); SetPosition(Pos.x, m_WinRect.bottom - Dim.y); } SetDirection(xNewDir, yNewDir); return; }
void CaPieInfoData::AddLegend (LPCTSTR lpszLegend, double dPercentage, double dValue) { int r, g, b; CaLegendData* pData = NULL; POSITION pos = m_listLegend.GetHeadPosition(); while (pos != NULL) { pData = (CaLegendData*)m_listLegend.GetNext (pos); if (pData->m_strName.CompareNoCase (lpszLegend) == 0) return; } r = lRandom() % 255; g = lRandom() % 255; b = lRandom() % 255; pData = new CaLegendData(lpszLegend, RGB (r, g, b)); if (pData) { pData->m_dPercentage = dPercentage; pData->m_dValue = dValue; m_listLegend.AddTail (pData); } }
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M Method: COBall::CImpIBall::CImpIBall Summary: Constructor for the CImpIBall interface instantiation. Args: COBall* pBackObj, Back pointer to the parent outer object. IUnknown* pUnkOuter Pointer to the outer Unknown. For delegation. Modifies: m_pBackObj, m_pUnkOuter. Returns: void M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/ COBall::CImpIBall::CImpIBall( COBall* pBackObj, IUnknown* pUnkOuter) { size_t i; BYTE r=128, g=128, b=128; // Init the Back Object Pointer to point to the parent object. m_pBackObj = pBackObj; // Init the CImpIBall interface's delegating Unknown pointer. We use // the Back Object pointer for IUnknown delegation here if we are not // being aggregated. If we are being aggregated we use the supplied // pUnkOuter for IUnknown delegation. In either case the pointer // assignment requires no AddRef because the CImpIBall lifetime is // quaranteed by the lifetime of the parent object in which // CImpIBall is nested. if (NULL == pUnkOuter) m_pUnkOuter = pBackObj; else m_pUnkOuter = pUnkOuter; // Now initialize the Ball application entity data. m_bAlive = TRUE; m_xDirection = 0; m_yDirection = 0; m_bNewPosition = FALSE; m_xPosition = 0; m_yPosition = 0; m_nWidth = 30; m_nHeight = 30; m_xSkew = BALL_MOVE_SKEW; m_ySkew = BALL_MOVE_SKEW; m_crColor = RGB(0,0,0); // Clear point transformation array. m_XForm.Clear(); // Init BallThread array--init colors and clear thread Ids. // The BallThreads are the threads that contend to move and/or // paint the ball object. for (i = 0; i < MAX_BALLTHREADS; i++) m_aBallThreads[i].Id = 0; m_aBallThreads[0].Color = RGB(0 , 0,255); // Blue m_aBallThreads[1].Color = RGB(255, 0, 0); // Red m_aBallThreads[2].Color = RGB(0 ,255, 0); // Green m_aBallThreads[3].Color = RGB(0 , 0, 0); // Black m_aBallThreads[4].Color = RGB(255, 0,255); // Purple m_aBallThreads[5].Color = RGB(0 ,255,255); // Aqua m_aBallThreads[6].Color = RGB(255,255, 0); // Brown int mBalls = MAX_BALLTHREADS; if ( mBalls > 8) for (i=7; i<MAX_BALLTHREADS; i++) { // Fill the remainder with some random colors. m_aBallThreads[i].Color = RGB(r,g,b); r = (BYTE) lRandom() % 255; g = (BYTE) lRandom() % 255; b = (BYTE) lRandom() % 255; } return; }