diff options
Diffstat (limited to 'src/T2DLL/T2DlgItemMovie.cpp')
-rw-r--r-- | src/T2DLL/T2DlgItemMovie.cpp | 196 |
1 files changed, 189 insertions, 7 deletions
diff --git a/src/T2DLL/T2DlgItemMovie.cpp b/src/T2DLL/T2DlgItemMovie.cpp index 4644fe2..2a66e80 100644 --- a/src/T2DLL/T2DlgItemMovie.cpp +++ b/src/T2DLL/T2DlgItemMovie.cpp @@ -1,30 +1,212 @@ +#include "GlobalFunc.h" +#include "T2BitImage.h" #include "T2DlgItemMovie.h" +#include "T2ImageObj.h" -T2DlgItemMovie::T2DlgItemMovie(T2TowerDoc*, T2ImageObj*, CPalette*) { +// love how this is obviously based off player/playfile/playfile.cpp +// from the DirectX SDK + +#define WM_GRAPHNOTIFY WM_USER+13 +#define HELPER_RELEASE(x) { if (x) x->Release(); x = NULL; } + +T2DlgItemMovie::T2DlgItemMovie(T2TowerDoc* inDoc, T2ImageObj* inImageObj, CPalette* inPalette) + : T2DlgItem(inDoc, inImageObj, inPalette) +{ + mImage = NULL; + mImageObj = NULL; + mPlaying = false; + + mUnusedInterface = NULL; + mGraph = NULL; + mMediaControl = NULL; + mMediaEvent = NULL; + mVideoWindow = NULL; + mMediaPosition = NULL; } /*virtual*/ T2DlgItemMovie::~T2DlgItemMovie() { + if (mImage) + delete mImage; + if (mImageObj) + delete mImageObj; } -/*virtual*/ int T2DlgItemMovie::OnT2DlgItemCreate(CREATESTRUCTA*) { +/*virtual*/ int T2DlgItemMovie::OnT2DlgItemCreate(CREATESTRUCT* cs) { + return T2DlgItem::OnT2DlgItemCreate(cs); } -/*virtual*/ int T2DlgItemMovie::OnT2DlgItemEraseBkgnd(CDC*) { +/*virtual*/ BOOL T2DlgItemMovie::OnT2DlgItemEraseBkgnd(CDC* pDC) { + CRect rect; + GetClientRect(rect); + + int save = pDC->SaveDC(); + pDC->SelectPalette(mPalette, false); + pDC->RealizePalette(); + + if (mImageObj) { + int objectID = mImageObj->FindObject("STIL"); + mImageObj->DrawObject(pDC, objectID, rect); + } + + pDC->RestoreDC(save); + return true; } -void T2DlgItemMovie::SetStillScreenID(const char*, int) { +void T2DlgItemMovie::SetStillScreenID(const char* inName, int inResID) { + if (mPlaying) + CloseMovie(); + mPlaying = false; + + if (mImage) + delete mImage; + if (mImageObj) + delete mImageObj; + + InvalidateRect(NULL); + +#line 76 + mImage = DEBUG_NEW T2BitImage(inName, inResID, true); + mImageObj = DEBUG_NEW T2ImageObj; + mImageObj->AddObject("STIL", -1, *mImage, NULL, false, false); } -void T2DlgItemMovie::SetQTMovieName(CString&) { +void T2DlgItemMovie::SetQTMovieName(CString& inName) { + CString dirName = "MOVIE"; + + if (inName.GetLength()) { + CString str = ""; + + if (str == "") { +#pragma var_order(path, ofStruct, towerDir) + char towerDir[512]; + GetTowerDirectory(towerDir); + + CString path = towerDir; + path = path + dirName + "\\" + inName; + OFSTRUCT ofStruct; + if (OpenFile(path, &ofStruct, OF_EXIST) != HFILE_ERROR) + str = path; + } + + if (str == "") { +#pragma var_order(volName, root, fsFlags) + CString root = GetInstallSourceDrive(); + root += ":\\"; + + char volName[256]; + volName[0] = 0; + DWORD fsFlags; + GetVolumeInformation(root, volName, 256, NULL, 0, &fsFlags, NULL, 0); + + if (!strcmp(volName, "TheTower2")) { + CString path = root + dirName + "\\" + inName; + OFSTRUCT ofStruct; + if (OpenFile(path, &ofStruct, OF_EXIST) != HFILE_ERROR) + str = path; + } + } + + if (str != "") + PlayMovie(str); + } } -void T2DlgItemMovie::PlayMovie(const char*) { +void T2DlgItemMovie::PlayMovie(const char* inName) { + if (mPlaying) + CloseMovie(); + + WCHAR *wFile = (WCHAR *) malloc(1024); + // bug: this passes 1024 and not 512 as cchWideChar + MultiByteToWideChar(CP_ACP, 0, inName, -1, wFile, 1024); + + HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **) &mGraph); + if (SUCCEEDED(hr)) { + mGraph->QueryInterface(IID_IMediaControl, (void **) &mMediaControl); + mGraph->QueryInterface(IID_IMediaEventEx, (void **) &mMediaEvent); + mGraph->QueryInterface(IID_IVideoWindow, (void **) &mVideoWindow); + mGraph->QueryInterface(IID_IMediaPosition, (void **) &mMediaPosition); + + hr = mGraph->RenderFile(wFile, NULL); + mVideoWindow->put_Owner((OAHWND) m_hWnd); + mVideoWindow->put_WindowStyle(WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD); + mMediaEvent->SetNotifyWindow((OAHWND) m_hWnd, WM_GRAPHNOTIFY, 0); + mVideoWindow->put_BackgroundPalette(-1); + + CRect videoRect; + mVideoWindow->GetWindowPosition(&videoRect.left, &videoRect.top, &videoRect.right, &videoRect.bottom); + videoRect.left = 0; + videoRect.top = 0; + + CRect clientRect; + GetClientRect(clientRect); + + SIZE sz; + + sz.cy = videoRect.Height(); + videoRect.top = (clientRect.Height() - sz.cy) / 2; + videoRect.bottom = videoRect.top + sz.cy; + + sz.cx = videoRect.Width(); + videoRect.left = (clientRect.Width() - sz.cx) / 2; + videoRect.right = videoRect.left + sz.cx; + + mVideoWindow->SetWindowPosition(videoRect.left, videoRect.top, videoRect.Width(), videoRect.Height()); + + if (SUCCEEDED(hr)) { + mMediaControl->Run(); + mPlaying = true; + } + } + + if (FAILED(hr)) { + // "Active Movieの初期化に失敗しました。" - Failed to initialize Active Movie. + MessageBox( + "Active Movie\x82\xCC\x8F\x89\x8A\xFA\x89\xBB\x82\xC9\x8E\xB8\x94\x73\x82\xB5\x82\xDC\x82\xB5\x82\xBD\x81\x42"); + } + + free(wFile); } void T2DlgItemMovie::CloseMovie() { + if (mMediaControl) + mMediaControl->Stop(); + + if (mVideoWindow) { + mVideoWindow->put_Visible(0); + mVideoWindow->put_Owner(NULL); + HELPER_RELEASE(mVideoWindow); + } + + HELPER_RELEASE(mUnusedInterface); + HELPER_RELEASE(mGraph); + HELPER_RELEASE(mMediaControl); + HELPER_RELEASE(mMediaEvent); + HELPER_RELEASE(mMediaPosition); } -/*virtual*/ long T2DlgItemMovie::WindowProc(unsigned int, unsigned int, long) { +/*virtual*/ LRESULT T2DlgItemMovie::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { + switch (message) { + case WM_GRAPHNOTIFY: + { + HRESULT hr; + LONG evCode; + LONG evParam1; + LONG evParam2; + while (SUCCEEDED(mMediaEvent->GetEvent(&evCode, &evParam1, &evParam2, 0))) { + hr = mMediaEvent->FreeEventParams(evCode, evParam1, evParam2); + if (evCode == EC_COMPLETE && mVideoWindow) { + mMediaPosition->put_CurrentPosition(0); + mMediaControl->Run(); + } + } + break; + } + case WM_DESTROY: + CloseMovie(); + break; + } + + return CWnd::WindowProc(message, wParam, lParam); } /*virtual*/ void T2DlgItemMovie::OnT2Close() { |