⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 creditstatic.cpp

📁 mod_RSsim
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// CreditStatic.cpp : implementation file
//

#include "stdafx.h"
#include "CreditStatic.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define  DISPLAY_TIMER_ID		150		// timer id
/////////////////////////////////////////////////////////////////////////////
// CCreditStatic

CCreditStatic::CCreditStatic()
{

	m_Colors[0] = RGB(0,0,0);       // Black
	m_Colors[1] = RGB(255,0,0);     // Red
	m_Colors[2] = RGB(255,255,0);   // Yellow
	m_Colors[3] = RGB(0,0,0);       // Black
	m_Colors[4] = RGB(0,0,0);       // Black

	m_TextHeights[TOP_LEVEL_TITLE] = TOP_LEVEL_TITLE_HEIGHT;
	m_TextHeights[TOP_LEVEL_GROUP] = TOP_LEVEL_GROUP_HEIGHT;
	m_TextHeights[GROUP_TITLE]     = GROUP_TITLE_HEIGHT;
	m_TextHeights[DISPLAY_BITMAP] = NORMAL_TEXT_HEIGHT;
	m_TextHeights[NORMAL_CENTER]  = NORMAL_TEXT_HEIGHT;
	m_TextHeights[LEFT_ALIGN1]    = NORMAL_TEXT_HEIGHT;
	m_TextHeights[LEFT_ALIGN2]    = NORMAL_TEXT_HEIGHT;
	m_nCurrentFontHeight = m_TextHeights[NORMAL_CENTER];


	m_Escapes[TOP_LEVEL_TITLE] = '\t';
	m_Escapes[TOP_LEVEL_GROUP] = '\n';
	m_Escapes[GROUP_TITLE]     = '\r';
	m_Escapes[DISPLAY_BITMAP]  = '^';
	m_Escapes[NORMAL_CENTER]   = '%';
	m_Escapes[LEFT_ALIGN1]     = '$';
	m_Escapes[LEFT_ALIGN2]     = '`';


	m_DisplaySpeed[0] = 70;
	m_DisplaySpeed[1] = 40;
	m_DisplaySpeed[2] = 10;

	m_CurrentSpeed = 1;
	m_ScrollAmount = -1;
	m_bProcessingBitmap = FALSE;

	m_ArrIndex = NULL;
	m_nCounter = 1;
	m_nClip = 0;

	m_bFirstTime = TRUE;
	m_bDrawText = FALSE;
	m_bFirstTurn = TRUE;
	m_Gradient = GRADIENT_NONE;
	m_bTransparent = FALSE;
	n_MaxWidth = 0;
	TimerOn = 0;
}

CCreditStatic::~CCreditStatic()
{
}


BEGIN_MESSAGE_MAP(CCreditStatic, CStatic)
	//{{AFX_MSG_MAP(CCreditStatic)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCreditStatic message handlers

BOOL CCreditStatic::StartScrolling()
{
	if(m_ArrCredit.IsEmpty())
		return FALSE;

	if(m_BmpMain.m_hObject != NULL) {
		m_BmpMain.DeleteObject();
		m_BmpMain.m_hObject = NULL;
	}
	
	TimerOn = SetTimer(DISPLAY_TIMER_ID,m_DisplaySpeed[m_CurrentSpeed],NULL);
    ASSERT(TimerOn != 0);

	m_ArrIndex = m_ArrCredit.GetHeadPosition();
	m_nCounter = 1;
	m_nClip = 0;

	m_bFirstTime = TRUE;
	m_bDrawText = FALSE;

	return TRUE;
}

void CCreditStatic::EndScrolling()
{
	KillTimer(DISPLAY_TIMER_ID);
	TimerOn = 0;

	if(m_BmpMain.m_hObject != NULL) {
		m_BmpMain.DeleteObject();
		m_BmpMain.m_hObject = NULL;
	}
}

void CCreditStatic::SetCredits(LPCTSTR credits,char delimiter)
{
	char *str,*ptr1,*ptr2;
    
	ASSERT(credits);

	if((str = strdup(credits)) == NULL)
		return;

	m_ArrCredit.RemoveAll();

	ptr1 = str;
	while((ptr2 = strchr(ptr1,delimiter)) != NULL) {
		*ptr2 = '\0';
		m_ArrCredit.AddTail(ptr1);
		ptr1 = ptr2+1;
	}
	m_ArrCredit.AddTail(ptr1);

	free(str);

	m_ArrIndex = m_ArrCredit.GetHeadPosition();
	m_nCounter = 1;
	m_nClip = 0;

	m_bFirstTime = TRUE;
	m_bDrawText = FALSE;
}

void CCreditStatic::SetCredits(UINT nID,char delimiter)
{
	CString credits;
	if(!credits.LoadString(nID))
		return;

	SetCredits((LPCTSTR)credits, delimiter);
}

void CCreditStatic::SetSpeed(UINT index, int speed)
{
	ASSERT(index <= DISPLAY_FAST);

	if(speed)
		m_DisplaySpeed[index] = speed;

	m_CurrentSpeed = index;
}

void CCreditStatic::SetColor(UINT index, COLORREF col)
{
	ASSERT(index <= NORMAL_TEXT_COLOR);

	m_Colors[index] = col;
}

void CCreditStatic::SetTextHeight(UINT index, int height)
{
	ASSERT(index < MAX_STYLES);

	m_TextHeights[index] = height;
}

void CCreditStatic::SetEscape(UINT index, char escape)
{
	ASSERT(index <= MAX_STYLES);

	m_Escapes[index] = escape;
}

void CCreditStatic::SetGradient(UINT value)
{
	ASSERT(value <= GRADIENT_LEFT_LIGHT);

	m_Gradient = value;
}

void CCreditStatic::SetTransparent(BOOL bTransparent)
{
	m_bTransparent = bTransparent;
}

void CCreditStatic::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	if(TimerOn) return;

	CDC memDC;
	memDC.CreateCompatibleDC(&dc);

	CBitmap *pOldMemDCBitmap = NULL;
	CRect m_ScrollRect;
	GetClientRect(&m_ScrollRect);

	if(m_BmpMain.m_hObject == NULL) 
   {

		CDC memDC2;
		CBitmap bitmap;
		memDC2.CreateCompatibleDC(&dc);
		bitmap.CreateCompatibleBitmap( &dc, m_ScrollRect.Width(), m_ScrollRect.Height() );
		CBitmap *pOldMemDC2Bitmap = (CBitmap*)memDC2.SelectObject(&bitmap);
		
		DrawCredit(&memDC2, m_ScrollRect);
		AddBackGround(&memDC2, m_ScrollRect, m_ScrollRect);

		pOldMemDCBitmap = (CBitmap*)memDC.SelectObject(&m_BmpMain);
        memDC.BitBlt( 0, 0, m_ScrollRect.Width(), m_ScrollRect.Height(), 
                                        &memDC2, 0, 0, SRCCOPY );
		memDC2.SelectObject(pOldMemDC2Bitmap);
	}
	else
		pOldMemDCBitmap = (CBitmap*)memDC.SelectObject(&m_BmpMain);
       
	dc.BitBlt( 0, 0, m_ScrollRect.Width(), m_ScrollRect.Height(), 
               &memDC, 0, 0, SRCCOPY );
}

BOOL CCreditStatic::OnEraseBkgnd(CDC* pDC) 
{
	return TRUE;
	
//	return CStatic::OnEraseBkgnd(pDC);
}

//************************************************************************
//	 OnTimer
//
//	 	On each of the display timers, scroll the window 1 unit. Each 20
//      units, fetch the next array element and load into work string. Call
//      Invalidate and UpdateWindow to invoke the OnPaint which will paint 
//      the contents of the newly updated work string.
//************************************************************************
void CCreditStatic::OnTimer(UINT nIDEvent) 
{
	if (nIDEvent != DISPLAY_TIMER_ID)
	{
		CStatic::OnTimer(nIDEvent);
		return;
	}

	BOOL bCheck = FALSE;

	if (!m_bProcessingBitmap) 
   {
		if (m_nCounter++ % m_nCurrentFontHeight == 0)	 // every x timer events, show new line
		{
			m_nCounter=1;
			m_szWork = m_ArrCredit.GetNext(m_ArrIndex);
			if(m_bFirstTurn)
				bCheck = TRUE;
			if(m_ArrIndex == NULL) {
				m_bFirstTurn = FALSE;
				m_ArrIndex = m_ArrCredit.GetHeadPosition();
			}
			m_nClip = 0;
			m_bDrawText=TRUE;
		}
	}
	
   CClientDC dc(this);
	CRect m_ScrollRect;
	GetClientRect(&m_ScrollRect);
 
	CRect m_ClientRect(m_ScrollRect);
	m_ClientRect.left = 0;//(m_ClientRect.Width()-n_MaxWidth)/2;
	m_ClientRect.right = m_ClientRect.left + m_ClientRect.Width();//n_MaxWidth;

	MoveCredit(&dc, m_ScrollRect, m_ClientRect, bCheck);

	AddBackGround(&dc, m_ScrollRect, m_ClientRect);

	CStatic::OnTimer(nIDEvent);
}

void CCreditStatic::AddBackGround(CDC* pDC, CRect& m_ScrollRect, CRect& m_ClientRect)
{
	CDC memDC;
	memDC.CreateCompatibleDC( pDC );

   if( m_bitmap.m_hObject == NULL )
	{
        CBitmap* pOldBitmap = memDC.SelectObject( &m_BmpMain );
        pDC->BitBlt( 0, 0, m_ScrollRect.Width(), m_ScrollRect.Height(), 
                                        &memDC, 0, 0, SRCCOPY );
		memDC.SelectObject(pOldBitmap);
		return;
	}

   // Draw bitmap in the background if one has been set
                // Now create a mask
	CBitmap bitmap;
	bitmap.CreateCompatibleBitmap( pDC, m_ClientRect.Width(), m_ClientRect.Height() );
	CBitmap* pOldMemDCBitmap = memDC.SelectObject( &bitmap );
		
	CDC tempDC;
	tempDC.CreateCompatibleDC(pDC);
	CBitmap* pOldTempDCBitmap = tempDC.SelectObject( &m_BmpMain );

	memDC.BitBlt( 0, 0, m_ClientRect.Width(), m_ClientRect.Height(), &tempDC, 
                      m_ClientRect.left, m_ClientRect.top, SRCCOPY );
	CDC maskDC;
	maskDC.CreateCompatibleDC(pDC);
	CBitmap maskBitmap;

	// Create monochrome bitmap for the mask
	maskBitmap.CreateBitmap( m_ClientRect.Width(), m_ClientRect.Height(), 1, 1, NULL );
	CBitmap* pOldMaskDCBitmap = maskDC.SelectObject( &maskBitmap );
    memDC.SetBkColor(m_bTransparent? RGB(192,192,192): m_Colors[BACKGROUND_COLOR]);

	// Create the mask from the memory DC
	maskDC.BitBlt( 0, 0, m_ClientRect.Width(), m_ClientRect.Height(), &memDC, 0, 0, SRCCOPY );

	tempDC.SelectObject(pOldTempDCBitmap);
	pOldTempDCBitmap = tempDC.SelectObject( &m_bitmap );

	CDC imageDC;
	CBitmap bmpImage;
	imageDC.CreateCompatibleDC( pDC );
	bmpImage.CreateCompatibleBitmap( pDC, m_ScrollRect.Width(), m_ScrollRect.Height() );
	CBitmap* pOldImageDCBitmap = imageDC.SelectObject( &bmpImage );

	if( pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE && m_pal.m_hObject != NULL )
	{
		pDC->SelectPalette( &m_pal, FALSE );
		pDC->RealizePalette();

		imageDC.SelectPalette( &m_pal, FALSE );
	}
	// Get x and y offset
	// Draw bitmap in tiled manner to imageDC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -