예제 #1
0
CBitmap* COrnament::GetImage(void)
{
	CDC *pDC = m_pContext->GetDC();
	ASSERT(pDC != NULL);

	// If the image bitmap is not valid give the current state, free the
	// current bitmap and build the new one.
			
	if (ImageNeeded())
	{
		m_bmImage.DeleteObject();
	}

	// Check if we need to build a new bitmap.		
		
	if (m_bmImage.GetSafeHandle() == NULL)
	{
		// Create the bitmap for the image.
			
		CRect crImage(0, 0, Max(CurrentState()->m_czExtent.cx, 1), Max(CurrentState()->m_czExtent.cy, 1));
		
		if (m_bmImage.CreateCompatibleBitmap(pDC, crImage.Width(), crImage.Height()))
		{
			// Create a memory compatible DC and select the new bitmap into it.
				
			CDC ImageDC;
				
			if (ImageDC.CreateCompatibleDC(pDC))
			{
				CBrush cbTransparent(RGB(0,0,0));
				
				int nContext;
							
				if ((nContext = ImageDC.SaveDC()) != 0)
				{
					ImageDC.SetMapMode(MM_TEXT);
						
					if (ImageDC.SelectObject(&m_bmImage) != NULL)
					{
						// Create the image. Pixels that are transparent should be set to sero (black).
							
						ImageDC.FillRect(&crImage, &cbTransparent);
						DrawImage(&ImageDC);
						ClearImageNeeded();
					}
						
					ImageDC.RestoreDC(nContext);
				}
			}
		}
	}
	
	m_pContext->ReleaseDC();

	ASSERT(m_bmImage.GetSafeHandle() != NULL);
	
	if (m_bmImage.GetSafeHandle() == NULL)
	{
		return NULL;
	}
	
	return &m_bmImage;
}
/** Displays the image view with its current image/ texts.
*/
void
CAImageSelector::display( bool active ) {
    CAImageView::display( active );

    CL_Rect crAll( 0,0, CA_APP->width, CA_APP->height );
    CL_Rect crImage( left,top, right, bottom );

    CA_APP->graphicContext->set_cliprect( crImage );

    // Animate:
    //
    float diff = (float)newImage - currentImage;
    float numImages2 = (float)numImages/2.0;
    bool forward = false;

    // Move forward or back?
    //
    if( (diff <  numImages2 && diff > 0.0) ||
            (diff < -numImages2) ) {
        forward = true;
    }

    // Correct frame difference:
    //
    if( diff < -numImages2 ) diff += numImages;
    if( diff >  numImages2 ) diff -= numImages;

    if( forward ) currentImage += fabs( diff ) / 6.0;
    else          currentImage -= fabs( diff ) / 6.0;

    if( currentImage< 0.0 )             currentImage+=(float)numImages;
    if( currentImage>(float)numImages ) currentImage-=(float)numImages;

    int image1 = (int)floor( currentImage );
    int image2 = (int)ceil( currentImage );
    if( image2>=numImages ) image2=0;
    float rest = currentImage-image1;
    int center;
    CL_SpriteDescription im1_desc = CL_SpriteDescription();
    CL_SpriteDescription im2_desc = CL_SpriteDescription();
    im1_desc.add_frame(image[image1].image);
    im2_desc.add_frame(image[image2].image);
    CL_Sprite im1(*CA_APP->graphicContext,im1_desc);
    CL_Sprite im2(*CA_APP->graphicContext,im2_desc);

    if( direction==Horizontal ) {
        center = (left+right)/2;
        int image1Pos = (int)(center - rest*width - image[image1].image.get_width()/2);
        im1.draw ( *CA_APP->graphicContext,image1Pos, top+barHeight);
        im2.draw ( *CA_APP->graphicContext,image1Pos + width, top+barHeight);
    } else {
        center = (top+bottom)/2;
        int image1Pos = (int)(center - rest*height - image[image1].image.get_height()/2);
        im1.draw ( *CA_APP->graphicContext,(left+right-image[image1].image.get_width())/2, image1Pos);
        im2.draw ( *CA_APP->graphicContext,(left+right-image[image1].image.get_width())/2, image1Pos + height);
    }

    displayArrows( active );

    CA_APP->graphicContext->set_cliprect( crAll );
}