Example #1
0
//-----------------------------------------------------------------------------
// Does:   Open a Resource And Load It Into IPicture (Interface)
// ~~~~    (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
//
// Note:   When Adding a Bitmap Resource It Would Automatically Show On "Bitmap"
// ~~~~    This NOT Good Coz We Need To Load It From a Custom Resource "BMP"
//         To Add a Custom Rresource: Import Resource -> Open As -> Custom
//         (Both .BMP And .DIB Should Be Found Under "BMP")
//
// InPut:  ResourceName - As a UINT Defined (Example: IDR_PICTURE_RESOURCE)
// ~~~~~   ResourceType - Type Name (Example: "JPG")
//
// OutPut: TRUE If Succeeded...
// ~~~~~~
//-----------------------------------------------------------------------------
BOOL CPicture_Ex::Load(HINSTANCE hInstance,LPCTSTR lpszResourceName, LPCSTR ResourceType)
//=============================================================================
{
 HGLOBAL  hGlobal = NULL;
 HRSRC  hSource = NULL;
 LPVOID  lpVoid  = NULL;
 int   nSize   = 0;
 BOOL  bResult=FALSE;
 if(m_pPict != NULL) UnloadPicture(); // Important - Avoid Leaks...



 hSource = FindResource(hInstance, lpszResourceName, ResourceType);



 if(hSource == NULL)
  {
  HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
  MessageBoxEx(hWnd, "FindResource() Failed\t", "ERROR"/*ERROR_TITLE*/, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
  return(FALSE);
  }



 hGlobal = LoadResource(hInstance, hSource);
 if(hGlobal == NULL)
  {
  HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
  MessageBoxEx(hWnd, "LoadResource() Failed\t", "ERROR"/*ERROR_TITLE*/, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
  return(FALSE);
  }



 lpVoid = LockResource(hGlobal);
 if(lpVoid == NULL)
  {
  HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
  MessageBoxEx(hWnd, "LockResource() Failed\t", "ERROR"/*ERROR_TITLE*/, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
  return(FALSE);
  }



 nSize = (UINT)SizeofResource(hInstance, hSource);
 if(LoadPictureData((BYTE*)hGlobal, nSize)) bResult = TRUE;



 UnlockResource(hGlobal); // 16Bit Windows Needs This
 FreeResource(hGlobal); // 16Bit Windows Needs This (32Bit - Automatic Release)
 return(bResult);
}
Example #2
0
//-----------------------------------------------------------------------------
// Does:   Open a File And Load It Into IPicture (Interface)
// ~~~~    (.BMP .DIB .EMF .GIF .ICO .JPG .WMF)
//
// InPut:  sFilePathName - Path And FileName Target To Save
// ~~~~~   
//
// OutPut: TRUE If Succeeded...
// ~~~~~~
//-----------------------------------------------------------------------------
BOOL CPicture_Ex::Load(CString sFilePathName)
//=============================================================================
{
 //if(!PathFileExists(sFilePathName))return FALSE;
/*
			CFile file;
			if (!file.Open(sFilePathName, CFile::modeRead/ *|CFile::shareDenyWrite* /))
				return FALSE;*/
		
		
 BOOL bResult = FALSE;
 CFile PictureFile;
 CFileException e;
 int nSize = 0;



 if(m_pPict != NULL) UnloadPicture(); // Important - Avoid Leaks...



 if(PictureFile.Open(sFilePathName, CFile::modeRead | CFile::typeBinary, &e))
  {
  nSize = PictureFile.GetLength();
  BYTE* pBuffer = new BYTE[nSize];
 
  if(PictureFile.Read(pBuffer, nSize) > 0)
   {
   if(LoadPictureData(pBuffer, nSize)) bResult = TRUE;
   }



  PictureFile.Close();
  delete [] pBuffer;
  }
 else // Open Failed...
  {
  TCHAR szCause[255];
  e.GetErrorMessage(szCause, 255, NULL);
  HWND hWnd = AfxGetApp()->GetMainWnd()->m_hWnd;
  MessageBoxEx(hWnd, szCause, "ERROR"/*ERROR_TITLE*/, MB_OK | MB_ICONSTOP, LANG_ENGLISH);
  bResult = FALSE;
  }
 return(bResult);
}
Example #3
0
/// @brief Closes the renderer used by the editor
/// @return 0 on failure, non-0 for success
/// @note Tested
int CloseGraphics (void)
{
	Graphics::Main & g = Graphics::Main::Get();

	// Unload all pictures; doing so unloads images, as well.
	while (!g.mPictures.empty())
	{
		UnloadPicture(*g.mPictures.begin());
	}

	// Unload all text images and fonts.
	while (!g.mTextImages.empty())
	{
		UnloadTextImage(*g.mTextImages.begin());
	}

	while (!g.mFaces.empty())
	{
		Graphics::Face * pFace = g.mFaces.begin()->second;

		while (!pFace->mSizes.empty())
		{
			UnloadFont(pFace->mSizes.begin()->second);
		}
	}

	// Close TrueType font support.
	FT_Done_FreeType(g.mFreeType);

	// Close the video subsystem.
	if (SDL_WasInit(SDL_INIT_VIDEO)) SDL_QuitSubSystem(SDL_INIT_VIDEO);

	// Flag the termination
	g.mInit = false;

	return 1;
}
Example #4
0
static int UnloadPicture (lua_State * L)
{
	UnloadPicture(lua_touserdata(L, 1));

	return 0;
}