Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
3.8 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 08/10/2003
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: LgUIMapBackground.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of LgUIMapBackground.cpp
  13. //----------------------------------------------------------------------------
  14. #include "stdafx.h"
  15. #include "..\Version.h"
  16. #include "LgUIMapBackground.h"
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[]=__FILE__;
  20. #define new DEBUG_NEW
  21. #endif
  22. CLgUIMapBackground::CLgUIMapBackground()
  23. {
  24. m_Type = ET_GENERIC;
  25. m_Size = CSize( 1000, 1000 );
  26. m_VersionInfo.dwOSVersionInfoSize = sizeof( m_VersionInfo );
  27. ::GetVersionEx( &m_VersionInfo );
  28. ::InitializeCriticalSection( &m_CritSection );
  29. m_dMeterScale = 1.0;
  30. // log info
  31. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgUIMapBackground::CLgUIMapBackground" );
  32. }
  33. CLgUIMapBackground::~CLgUIMapBackground()
  34. {
  35. ::DeleteCriticalSection( &m_CritSection );
  36. // log info
  37. LGLOG( LOG_LEVEL_MEDIUM, LOG_TYPE_INFO, this, "CLgUIMapBackground::~CLgUIMapBackground" );
  38. }
  39. BOOL CLgUIMapBackground::Load( LPCTSTR pFileName, CLgFileGroup *pFileGroup, double dMeterScale )
  40. {
  41. m_dMeterScale = dMeterScale;
  42. m_Type = ET_GENERIC;
  43. HBITMAP hBitmap = NULL;
  44. if( pFileGroup )
  45. hBitmap = (HBITMAP)pFileGroup->LoadImage( pFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
  46. else
  47. hBitmap = (HBITMAP)::LoadImage( NULL, pFileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE );
  48. if( hBitmap )
  49. {
  50. if( m_MemoryDC.Create( hBitmap, FALSE ) )
  51. {
  52. m_Size = m_MemoryDC.GetSize();
  53. m_Type = ET_BITMAP;
  54. return TRUE;
  55. }
  56. }
  57. TCHAR pBuffer[MAX_PATH];
  58. BOOL bFromFileGroup = ( bFromFileGroup = pFileGroup && pFileGroup->GetTemp( pFileName, pBuffer, MAX_PATH ) );
  59. if( m_MetaFile.Load( bFromFileGroup ? pBuffer : pFileName ) )
  60. {
  61. m_Size = m_MetaFile.GetSize();
  62. m_Type = ET_METAFILE;
  63. if( bFromFileGroup )
  64. DeleteFile( pBuffer );
  65. return TRUE;
  66. }
  67. if( bFromFileGroup )
  68. DeleteFile( pBuffer );
  69. return FALSE;
  70. }
  71. BOOL CLgUIMapBackground::Load( E_Type eType, PVOID pImage, double dMeterScale )
  72. {
  73. CLgImageDIB dib;
  74. m_dMeterScale = dMeterScale;
  75. m_Type = eType;
  76. m_Size = CSize( 1000, 1000 );
  77. switch( eType )
  78. {
  79. case ET_GENERIC:
  80. return TRUE;
  81. case ET_BITMAP:
  82. if( dib.Create( reinterpret_cast<CLgImageJPEG*>(pImage) ) &&
  83. m_MemoryDC.Create( dib.CreateBitmap( NULL, NULL ), FALSE ) )
  84. {
  85. m_Size = m_MemoryDC.GetSize();
  86. return TRUE;
  87. }
  88. break;
  89. case ET_METAFILE:
  90. if( m_MetaFile = *reinterpret_cast<CLgImageEMF*>(pImage) )
  91. {
  92. m_Size = m_MetaFile.GetSize();
  93. return TRUE;
  94. }
  95. break;
  96. }
  97. return FALSE;
  98. }
  99. BOOL CLgUIMapBackground::Draw( CDC *pDC, CRect *pRect )
  100. {
  101. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgUIMapBackground::Draw"), _T("Started...") );
  102. ::EnterCriticalSection( &m_CritSection );
  103. int smode;
  104. bool bNT = ( m_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT );
  105. BOOL bSuccess;
  106. switch( m_Type )
  107. {
  108. case ET_BITMAP:
  109. smode = pDC->SetStretchBltMode( bNT ? HALFTONE : COLORONCOLOR );
  110. pDC->StretchBlt( pRect->left, pRect->top, pRect->Width(), pRect->Height(),
  111. &m_MemoryDC, 0, 0, m_Size.cx, m_Size.cy, SRCCOPY );
  112. pDC->SetStretchBltMode( smode );
  113. bSuccess = TRUE;
  114. break;
  115. case ET_METAFILE:
  116. pDC->PlayMetaFile( m_MetaFile, pRect );
  117. bSuccess = TRUE;
  118. break;
  119. default:
  120. pDC->FillSolidRect( pRect, RGB(0x7F,0,0) );
  121. bSuccess = FALSE;
  122. break;
  123. }
  124. ::LeaveCriticalSection( &m_CritSection );
  125. // log info
  126. LGLOG( LOG_LEVEL_HIGH, LOG_TYPE_INFO, this, _T("CLgUIMapBackground::Draw"), _T("Done") );
  127. return bSuccess;
  128. }