Пример #1
0
int LuaAnimationCreateFrames(lua_State* _State) {
	int _Width = luaL_checkinteger(_State, 1);
	int _Height = luaL_checkinteger(_State, 2);
	int _FrameCt = luaL_checkinteger(_State, 3);
	const char* _KeyName = luaL_checkstring(_State, 4);
	struct AnimationLoading* _Data = NULL;
	struct Resource* _Image = NULL;

	lua_pushvalue(_State, LUA_REGISTRYINDEX);
	lua_pushstring(_State, ANIM_LUASTR);
	lua_rawget(_State, -2);
	_Data = lua_touserdata(_State, -1);
	if(_Data->ImageName == NULL)
		return luaL_error(_State, "Animation has no image loaded.");
	_Image = ResourceGet(_Data->ImageName);
	if(SDL_QueryTexture(ResourceGetData(_Image), NULL, NULL, &_Data->Dims.x, &_Data->Dims.y) != 0) {
		luaL_error(_State, SDL_GetError());
		DestroyResource(_Image);
		return 0;
	}
	DestroyResource(_Image);
	if(_FrameCt * _Width > _Data->Dims.x || _FrameCt * _Height > _Data->Dims.y)
		return luaL_error(_State, "Frame exceeds dimensions.");
	for(int i = _Data->FrameSz; i < _FrameCt && i < ANIM_MAXFRAMES; ++i) {
		_Data->Frames[i + _Data->FrameSz].Speed = _Data->DefaultSpeed;
		_Data->Frames[i + _Data->FrameSz].Rect.x = i * _Width;
		_Data->Frames[i + _Data->FrameSz].Rect.y = i * _Height;
		_Data->Frames[i + _Data->FrameSz].Rect.w = _Width;
		_Data->Frames[i + _Data->FrameSz].Rect.h = _Height;
		++_Data->FrameSz;
	}
	_Data->y = _Data->y + _Height;
	_Data->Keys[_Data->KeySz].Name = calloc(strlen(_KeyName) + 1, sizeof(char));
	strcpy((char*)_Data->Keys[_Data->KeySz].Name, _KeyName);
	++_Data->KeySz;
	return 0;
}
    ResourceWeakPtr IResourceManager::LoadResource(xst_castring& strResName, xst_castring& strResGroupName, xst_castring &strFileName, xst_castring &strFileGroupName, bool bFullLoad)
    {
        xst_assert( m_pResFileMgr, "(IResourceManager::LoadResource) File manager not created" );
        
        ResourceHandle ResHandle = CalcHandle( strResName.c_str(), strResName.length() );
        GroupHandle GrHandle = CalcHandle( strResGroupName.c_str(), strResName.length() );
        ResourceWeakPtr pRes = GetResource( ResHandle, GrHandle );
        if( pRes.IsValid() )
        {
            return pRes;
        }

        pRes = CreateResource( strResName, strResGroupName );
        if( XST_FAILED( LoadResource( &pRes, strFileName, strFileGroupName, bFullLoad ) ) )
        {
            DestroyResource( pRes );
            pRes = XSE_NULLRES;
        }
        return pRes;
    }
Пример #3
0
	bool painter<Derived>::WindowProc(Derived &, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT &r)
	{
		switch(msg){
		case WM_CREATE:
			{
				/*if(::IsWindowsVersionOrGreater(6, 2, 0)){
					HINSTANCE module = ::LoadLibrary(L"user32.dll");

					if(module == nullptr)
						break;

					using lpfnSetWindowCompositionAttribute = BOOL(WINAPI *)(HWND, detail::WINDOWCOMPOSITIONATTRIBUTEDATA*);
					auto SetWindowCompositionAttribute = (lpfnSetWindowCompositionAttribute)::GetProcAddress(module, "SetWindowCompositionAttribute");

					if(SetWindowCompositionAttribute == nullptr){
						::FreeLibrary(module);
						break;
					}

					detail::ACCENTPOLICY policy = {3, 0, 0, 0};
					detail::WINDOWCOMPOSITIONATTRIBUTEDATA data = {19, &policy, sizeof(policy)};

					SetWindowCompositionAttribute(hwnd, &data);

					::FreeLibrary(module);
				}else{
					DWM_BLURBEHIND bb = {};
					bb.dwFlags = DWM_BB_ENABLE;
					bb.fEnable = TRUE;
					::DwmEnableBlurBehindWindow(
						get_hwnd(),
						&bb);
					htheme = ::OpenThemeData(hwnd, VSCLASS_WINDOW);

					BOOL b;
					::DwmIsCompositionEnabled(&b);
					aero_glass = b != FALSE;
				}*/
			}
			break;
		case WM_DESTROY:
			::CloseThemeData(htheme);
			DestroyResource();
			break;
		case WM_PAINT:
			if(CreateResource()){
				mutex.lock();

				paint_params pp = {
					target
				};

				HWND hwnd = get_hwnd();
				RECT rc;
				::GetClientRect(hwnd, &rc);

				PAINTSTRUCT ps;
				::BeginPaint(hwnd, &ps);

				target->BindDC(ps.hdc, &rc);
				target->BeginDraw();

				if(!aero_glass)
					target->Clear(color(255, 255, 255, 255));

				static_cast<Derived*>(this)->draw(pp);

				if(target->EndDraw() == D2DERR_RECREATE_TARGET){
					DestroyResource();
					repaint();
				}

				::EndPaint(hwnd, &ps);

				mutex.unlock();
			}else{
				throw std::runtime_error("an error occurred when creating Direct2D resources.");
			}
			break;
		case WM_SIZE:
			::InvalidateRect(hwnd, nullptr, FALSE);
			break;
		case WM_DWMCOMPOSITIONCHANGED:
			{
				BOOL b;
				::DwmIsCompositionEnabled(&b);
				aero_glass = b != FALSE;
			}
			break;
		}
		return true;
	}
Пример #4
0
//加载资源
bool CTableResource::LoadFromFiles(LPCTSTR pszGameName)
{
	try
	{
		//加载资源
		CFile ResourceFile;
		TCHAR szResourcePath[MAX_PATH];
		_snprintf(szResourcePath,sizeof(szResourcePath),TEXT("%s%s\\TableFrame.DAT"),g_GlobalUnits.GetWorkDirectory(),pszGameName);
		if (ResourceFile.Open(szResourcePath,CFile::modeRead,NULL)==FALSE) throw 0;

		//读取配置
		tagTableConfigFile TableConfig;
		ULONGLONG uLong=ResourceFile.GetLength();
		switch (uLong)
		{
		case sizeof(tagTableConfigFile):
			{
				UINT uReadCount=ResourceFile.Read(&TableConfig,sizeof(TableConfig));
				if (uReadCount!=sizeof(TableConfig)) throw 0;
				if (TableConfig.wFileSize!=sizeof(tagTableConfigFile)) throw 0;
				break;
			}
		case sizeof(tagTableConfigFile_Normal):
			{
				tagTableConfigFile_Normal TableConfig_Normal;
				UINT uReadCount=ResourceFile.Read(&TableConfig_Normal,sizeof(TableConfig_Normal));
				if (uReadCount!=sizeof(TableConfig_Normal)) throw 0;
				if (TableConfig_Normal.wFileSize!=sizeof(TableConfig_Normal)) throw 0;
				if (TableConfig_Normal.wStructVer!=1) throw 0;

				TableConfig.TableResourceInfo.crName=TableConfig_Normal.TableResourceInfo.crName;
				TableConfig.TableResourceInfo.crNote=TableConfig_Normal.TableResourceInfo.crNote;
				TableConfig.TableResourceInfo.crTableID=TableConfig_Normal.TableResourceInfo.crTableID;
				TableConfig.TableResourceInfo.ptLock=TableConfig_Normal.TableResourceInfo.ptLock;
				TableConfig.TableResourceInfo.rcNote=TableConfig_Normal.TableResourceInfo.rcNote;
				TableConfig.TableResourceInfo.rcTableID=TableConfig_Normal.TableResourceInfo.rcTableID;
				for (int i=0;i<8;i++)
				{
					TableConfig.TableResourceInfo.rcName[i]=TableConfig_Normal.TableResourceInfo.rcName[i];
					TableConfig.TableResourceInfo.rcChair[i]=TableConfig_Normal.TableResourceInfo.rcChair[i];
					TableConfig.TableResourceInfo.ptReady[i]=TableConfig_Normal.TableResourceInfo.ptReady[i];
					TableConfig.TableResourceInfo.nDrawStyle[i]=TableConfig_Normal.TableResourceInfo.nDrawStyle[i];
				}
				break;
			}
		default: throw 0;
		}

		//德州扑克
		if (lstrcmp(pszGameName,TEXT("DZShowHand"))==0)
		{
			m_bDZShowHand=true;
			_snprintf(szResourcePath,sizeof(szResourcePath),TEXT("%s%s\\Player.BMP"),g_GlobalUnits.GetWorkDirectory(),pszGameName);
			m_ImagePeople.Load(szResourcePath);
			if (m_ImagePeople.IsNull()) throw 0;
		}

		//加载锁位图
		_snprintf(szResourcePath,sizeof(szResourcePath),TEXT("%s%s\\Locker.BMP"),g_GlobalUnits.GetWorkDirectory(),pszGameName);
		m_ImageLock.Load(szResourcePath);
		if (m_ImageLock.IsNull()) 
		{
			m_ImageLock.LoadFromResource(AfxGetInstanceHandle(),IDB_TABLE_LOCK);
			if (m_ImageLock.IsNull()) throw 0;
		}

		//加载准备标志
		_snprintf(szResourcePath,sizeof(szResourcePath),TEXT("%s%s\\UserReady.BMP"),g_GlobalUnits.GetWorkDirectory(),pszGameName);
		m_ImageReady.Load(szResourcePath);
		if (m_ImageReady.IsNull()) 
		{
			m_ImageReady.LoadFromResource(AfxGetInstanceHandle(),IDB_TABLE_READY);
			if (m_ImageReady.IsNull()) throw 0;
			throw 0;
		}

		//加载开始标志
		_snprintf(szResourcePath,sizeof(szResourcePath),TEXT("%s%s\\TablePlaying.BMP"),g_GlobalUnits.GetWorkDirectory(),pszGameName);
		m_ImagePlay.Load(szResourcePath);
		if (m_ImagePlay.IsNull()) throw 0;

		//加载桌子位图
		_snprintf(szResourcePath,sizeof(szResourcePath),TEXT("%s%s\\TableNormal.BMP"),g_GlobalUnits.GetWorkDirectory(),pszGameName);
		m_ImageTable.Load(szResourcePath);
		if (m_ImageTable.IsNull()) throw 0;

		//读取参数
		m_wWidth=m_ImageTable.GetWidth();
		m_wHeight=m_ImageTable.GetHeight();
		m_crBackGround=m_ImageTable.GetPixel(0,0);

		//设置参数
		tagTableResourceInfo * pResourceInfo=&TableConfig.TableResourceInfo;
		m_ptLock=pResourceInfo->ptLock;
		m_rcNote=pResourceInfo->rcNote;
		m_crName=pResourceInfo->crName;
		m_crNote=pResourceInfo->crNote;
		m_crTableID=pResourceInfo->crTableID;
		m_rcTableID=pResourceInfo->rcTableID;
		for (WORD i=0;i<MAX_CHAIR;i++)
		{
			m_ptReady[i]=pResourceInfo->ptReady[i];
			m_rcName[i]=pResourceInfo->rcName[i];
			m_rcChair[i]=pResourceInfo->rcChair[i];
			m_nDrawStyle[i]=pResourceInfo->nDrawStyle[i];
		}

		return true;
	}
	catch (...) { DestroyResource(); }

	return false;
}
Пример #5
0
//析构函数
CTableResource::~CTableResource()
{
	DestroyResource();
	return;
}
Пример #6
0
void DestroySprite(struct Sprite* _Sprite) {
	DestroyResource(_Sprite->Image);
	free(_Sprite);
}