📄 chanim.cpp
字号:
/*----------------------------------------------------------------------------
_ _ _
/\ | | | (_)
/ \ _ __ __| |_ __ ___ _ __ ___ ___ __| |_ __ _
/ /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
/ ____ \| | | | (_| | | | (_) | | | | | | __/ (_| | | (_| |
/_/ \_\_| |_|\__,_|_| \___/|_| |_| |_|\___|\__,_|_|\__,_|
The contents of this file are subject to the Andromedia Public
License Version 1.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.andromedia.com/APL/
Software distributed under the License is distributed on an
"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is Pueblo client code, released November 4, 1998.
The Initial Developer of the Original Code is Andromedia Incorporated.
Portions created by Andromedia are Copyright (C) 1998 Andromedia
Incorporated. All Rights Reserved.
Andromedia Incorporated 415.365.6700
818 Mission Street - 2nd Floor 415.365.6701 fax
San Francisco, CA 94103
Contributor(s):
--------------------------------------------------------------------------
Chaco team: Dan Greening, Glenn Crocker, Jim Doubek,
Coyote Lussier, Pritham Shetty.
Wrote and designed original codebase.
------------------------------------------------------------------------------
Implementation for the ChGraphic class, which is used to display
graphics, & accept selection of hot spots and sprites.
----------------------------------------------------------------------------*/
// $Header: /home/cvs/chaco/modules/client/msw/ChGraphx/ChAnim.cpp,v 2.18 1996/09/12 19:09:41 pritham Exp $
#include "grheader.h"
#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN ) && !defined( CH_PUEBLO_PLUGIN )
#include "resource.h"
#else
#include "vwrres.h"
#endif
#include <ChCore.h>
#include "ChGrMod.h"
#include "ChAniPrs.h"
#include <fstream.h>
#include <ChDibImage.h>
#include <ChGIFDecoder.h>
#include <ChJPEGDecoder.h>
#include <ChUtil.h>
#include <ChImgUtil.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define NOT_IMPLEMENTED TRACE2("Function not implemented, file %s: line %s.", __FILE__, __LINE__)
// Either of the following dummy declarations cause the compiler
// to fully define the ChPtrList<ChAnimAnchor> class, preventing
// a warning when deleting m_pCastAnchors;
//ChPtrList<ChAnimAnchor> m_dummy;
class dummyAnchorPtrList:ChPtrList<ChAnimAnchor>
{
public:
};
typedef struct tagChAnimStringTable
{
char * strStr;
chint32 key;
} ChAnimStringTable;
static ChAnimStringTable aChAnimPointerNames[] =
{
"Pointer", CH_CURSOR_STD_PTR,
"Crosshairs", CH_CURSOR_HAIRS,
"Wait", CH_CURSOR_WAIT,
"Picker", CH_CURSOR_PICK,
"Finger", CH_CURSOR_PICK,
"IBeam", CH_CURSOR_IBEAM,
"Edit", CH_CURSOR_IBEAM,
"No", CH_CURSOR_NO,
"Forbidden", CH_CURSOR_NO,
"", 0
};
/*
Class ChAnimView
*/
//IMPLEMENT_DYNCREATE( ChAnimView, ChGraphicView )
BEGIN_MESSAGE_MAP(ChAnimView, ChGraphicView)
//{{AFX_MSG_MAP(ChAnimView)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
ChAnimView::ChAnimView( ChGraphicMainInfo *pInfo ) :
ChGraphicView( pInfo ),
m_uiTimer(0),
m_cursorId(CH_CURSOR_STD_PTR),
m_anchorId(0),
m_pCastAnchors(0),
m_pDibBkgnd(0),
m_boolBackgroundDirty(false),
m_boolCenterIt(true)
{
m_pDIB = NULL;
m_pPal = NULL;
m_pOneToOneClrTab = NULL;
m_bUseCreateDIBSection = false;
m_hbmSection = NULL;
// See if we are on Win32s which exports CreateDIBSection but
// does not support it
DWORD dwVer = GetVersion();
if ((dwVer & 0x800000FF) != 0x080000003) {
// Not on Win32s so try to get the CreateDIBSection procedure address.
HANDLE hMod = ::GetModuleHandle("gdi32");
if (hMod) {
m_pCDSProc = (CDSPROC*) GetProcAddress((HMODULE) hMod, "CreateDIBSection");
if (m_pCDSProc) {
m_bUseCreateDIBSection = true;
}
}
}
// Cursors need to get moved to grview ??????????????
for (int j=0; j<MAX_CURSOR_COUNT; j++)
{
m_cursors[j] = LoadCursor( 0, IDC_ARROW );
}
m_cursors[CH_CURSOR_STD_PTR] = ::LoadCursor( 0, IDC_ARROW );
m_cursors[CH_CURSOR_HAIRS] = ::LoadCursor( 0, IDC_CROSS );
m_cursors[CH_CURSOR_WAIT] = ::LoadCursor( 0, IDC_WAIT );
m_cursors[CH_CURSOR_NO] = ::LoadCursor( 0, IDC_NO );
m_cursors[CH_CURSOR_IBEAM] = ::LoadCursor( 0, IDC_IBEAM );
if ( ChUtil::GetSystemType() == CH_SYS_WIN32S ||
ChUtil::GetSystemType() == CH_SYS_WIN3X )
{
m_cursors[CH_CURSOR_PICK] = ::LoadCursor( ChGraphicsDLL.hModule,
MAKEINTRESOURCE( IDC_HANDMONO ));
}
else
{
m_cursors[CH_CURSOR_PICK] = ::LoadCursor( ChGraphicsDLL.hModule,
MAKEINTRESOURCE( IDC_PICKER ));
}
m_pDibBkgnd = new ChDibBmp;
}
ChAnimView::~ChAnimView()
{
// Delete characters
while (!m_characters.IsEmpty())
{
ChAnimCastMember *pCast = m_characters.RemoveHead();
delete pCast;
}
// Note: Installed anchors are deleted when splay tree is zapped
// We need to explicitly zap list of pending anchors, if any
if (m_pCastAnchors && !m_pCastAnchors->IsEmpty())
{
ChAnimAnchor *pAnchor = m_pCastAnchors->RemoveHead();
delete pAnchor;
}
delete m_pCastAnchors;
if (m_pDIB) { delete m_pDIB; m_pDIB = 0;}
if (m_pPal) { delete m_pPal; m_pPal = 0;}
if (m_pOneToOneClrTab) {free(m_pOneToOneClrTab); m_pOneToOneClrTab = 0;}
if (m_hbmSection) {::DeleteObject(m_hbmSection); m_hbmSection = 0;}
EmptyDirtyList();
delete m_pDibBkgnd;
m_pDibBkgnd = 0;
}
// Create a Window
bool ChAnimView::Create( const CRect& rtView, CWnd* pParent, DWORD dwStyle,
UINT uiID )
{
bool boolSuccess = ChGraphicView::Create( rtView, pParent, dwStyle, uiID );
return boolSuccess;
}
BOOL ChAnimView::PreCreateWindow( CREATESTRUCT& cs )
{
HCURSOR hCursor;
if (!ChGraphicView::PreCreateWindow( cs ))
{
return false;
}
hCursor = AfxGetApp()->LoadStandardCursor( IDC_ARROW );
cs.lpszClass = AfxRegisterWndClass( CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, hCursor,
(HBRUSH)(COLOR_WINDOW + 1) );
return true;
//return ChGraphicView::PreCreateWindow(cs);
}
// Create a new buffer, tables and palette to match a supplied DIB.
BOOL ChAnimView::Create(ChDibBmp *pDIB)
{
// Create the 1-to-1 palette index table.
if (m_pOneToOneClrTab) free(m_pOneToOneClrTab);
m_pOneToOneClrTab =
(LPBITMAPINFO) malloc(sizeof(BITMAPINFOHEADER)
+ 256 * sizeof(WORD));
if (!m_pOneToOneClrTab) {
TRACE("Failed to create color table");
return false;
}
// Set up the table header to match the DIB
// by copying the header and then constructing the 1-to-1
// index translation table.
memcpy(m_pOneToOneClrTab,
pDIB->GetBitmapInfoAddress(),
sizeof(BITMAPINFOHEADER));
// make sure the length of the table is set to 256 not to
// the number of colors in the DIB which is irrelevant
m_pOneToOneClrTab->bmiHeader.biClrUsed = 0; // default (256)
WORD* pIndex;
pIndex = (LPWORD)((LPBYTE)m_pOneToOneClrTab + sizeof(BITMAPINFOHEADER));
for (int i = 0; i < 256; i++) {
*pIndex++ = (WORD) i;
}
// Create a palette from the DIB so that we can use it to do
// screen drawing.
if (m_pPal) delete m_pPal;
m_pPal = new ChDibPal;
ASSERT(m_pPal);
if (!m_pPal->Create(pDIB)) {
TRACE("Failed to create palette");
delete m_pPal;
m_pPal = NULL;
return false;
} else {
// Map the colors so that we get an identity palette.
m_pPal->SetSysPalColors();
}
// Delete any existing DIB and create a new one.
if (m_pDIB) delete m_pDIB;
m_pDIB = new ChDibBmp;
BOOL bResult = false;
if (m_bUseCreateDIBSection) {
if (m_hbmSection) ::DeleteObject(m_hbmSection);
ASSERT(m_pCDSProc);
CDC* pDC = GetDC();
CPalette* pPalOld = pDC->SelectPalette(m_pPal, false);
pDC->RealizePalette();
BYTE* pBits = NULL;
m_hbmSection = (*m_pCDSProc)(pDC->GetSafeHdc(),
m_pOneToOneClrTab,
DIB_PAL_COLORS,
(VOID **) &pBits,
NULL,
0);
pDC->SelectPalette(pPalOld, false);
ASSERT(m_hbmSection);
ASSERT(pBits);
ReleaseDC(pDC);
bResult = m_pDIB->Create(pDIB->GetBitmapInfoAddress(), pBits);
} else {
bResult = m_pDIB->Create(pDIB->GetWidth(), pDIB->GetHeight());
}
if (!bResult) {
TRACE("Failed to create off-screen DIB");
delete m_pDIB;
m_pDIB = NULL;
return false;
}
CSize sizeTotal;
sizeTotal.cx = m_pDIB->GetWidth();
sizeTotal.cy = m_pDIB->GetHeight();
//SetScrollSizes(MM_TEXT, sizeTotal);
SetScrollSizes(sizeTotal);
return true;
}
void ChAnimView::OnInitialUpdate()
{
CSize sizeTotal;
if (m_pDIB) {
sizeTotal.cx = m_pDIB->GetWidth();
sizeTotal.cy = m_pDIB->GetHeight();
} else {
sizeTotal.cx = 640;
sizeTotal.cy = 480;
}
SetScrollSizes(sizeTotal);
}
bool ChAnimView::LoadBackground( const string & strURL )
{
delete m_pDibBkgnd;
m_pDibBkgnd = new ChDibBmp;
if (!m_pDibBkgnd->Load( (char *)(LPCTSTR( strURL )) ))
{
return false;
}
// Create a new buffer
// and palette
m_spriteList.m_NotifyObj.SetView(this);
NewBackground(m_pDibBkgnd);
return true;
}
bool ChAnimView::LoadBackgroundJPEG( const string & strURL )
{
delete m_pDibBkgnd;
m_pDibBkgnd = new ChDibBmp;
ChDib dibImage;
ChJPEG jpegDecoder( &dibImage );
if (!jpegDecoder.Load( strURL ) )//, ChDib::load8Bit ))
{
return false;
}
// convert dib to dibbmp
m_pDibBkgnd->Create( dibImage.GetBitmapInfoAddress(),
(BYTE*)dibImage.GetBitsAddress(), true );
// Create a new buffer
// and palette
m_spriteList.m_NotifyObj.SetView(this);
NewBackground(m_pDibBkgnd);
return true;
}
bool ChAnimView::LoadBackgroundGIF( const string & strURL )
{
delete m_pDibBkgnd;
m_pDibBkgnd = new ChDibBmp;
ChDib dibImage;
ChGifDecoder gifDecoder( &dibImage );
if (!gifDecoder.Load( strURL )) //, ChDib::load8Bit ) )
{
return false;
}
// convert dib to dibbmp
m_pDibBkgnd->Create( dibImage.GetBitmapInfoAddress(),
(BYTE*)dibImage.GetBitsAddress(), true );
// Create a new buffer
// and palette
m_spriteList.m_NotifyObj.SetView(this);
NewBackground(m_pDibBkgnd);
return true;
}
bool ChAnimView::LoadBackground( chuint16 suResId )
{
delete m_pDibBkgnd;
m_pDibBkgnd = new ChDibBmp;
if (!m_pDibBkgnd->Load( suResId, ChGraphicsDLL.hModule ))
{
return false;
}
// Create a new buffer and palette
m_spriteList.m_NotifyObj.SetView( this );
NewBackground( m_pDibBkgnd );
return true;
}
// Create a new buffer and palette to match a new
// background DIB
bool ChAnimView::NewBackground(ChDibBmp* pDIB)
{
int iColors = ChImgUtil::MaxDeviceColors();
if ( (iColors > 256 || iColors < 0) &&
pDIB->GetBitmapInfoAddress()->bmiHeader.biBitCount <= 8 )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -