Counter Strike : Global Offensive Source Code
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.

153 lines
3.3 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "mxbitmaptools.h"
  8. #include <mxtk/mx.h>
  9. #include "hlfaceposer.h"
  10. #include "FileSystem.h"
  11. bool LoadBitmapFromFile( const char *relative, mxbitmapdata_t& bitmap )
  12. {
  13. bitmap.valid = false;
  14. bitmap.image = NULL;
  15. bitmap.width = -1;
  16. bitmap.height = -1;
  17. // Draw
  18. HDC dc = GetDC( NULL );
  19. if ( !dc )
  20. {
  21. return false;
  22. }
  23. int width, height;
  24. width = 100;
  25. height = 100;
  26. HBITMAP bmNewImage = (HBITMAP)0;
  27. HBITMAP bm, oldbm;
  28. bm = CreateCompatibleBitmap( dc, width, height );
  29. if ( bm )
  30. {
  31. oldbm = (HBITMAP)SelectObject( dc, bm );
  32. HDC memdc = CreateCompatibleDC( dc );
  33. if ( memdc )
  34. {
  35. char filename[ 512 ];
  36. filesystem->RelativePathToFullPath( relative, "MOD", filename, sizeof( filename ) );
  37. bmNewImage = (HBITMAP)LoadImage(
  38. (HINSTANCE) GetModuleHandle(0), filename,
  39. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE );
  40. if ( !bmNewImage )
  41. {
  42. filesystem->RelativePathToFullPath( relative, "GAME", filename, sizeof( filename ) );
  43. bmNewImage = (HBITMAP)LoadImage(
  44. (HINSTANCE) GetModuleHandle(0), filename,
  45. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE );
  46. }
  47. if ( bmNewImage )
  48. {
  49. HBITMAP oldmembm = (HBITMAP)SelectObject( memdc, bmNewImage );
  50. BITMAPINFO bmi;
  51. memset( &bmi, 0, sizeof( bmi ) );
  52. bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
  53. if ( GetDIBits( memdc, bmNewImage, 0, 0, NULL, &bmi, DIB_RGB_COLORS ) )
  54. {
  55. bitmap.width = bmi.bmiHeader.biWidth;
  56. bitmap.height = bmi.bmiHeader.biHeight;
  57. }
  58. SelectObject( memdc, oldmembm );
  59. }
  60. DeleteDC( memdc );
  61. }
  62. SelectObject( dc, oldbm );
  63. DeleteObject( bm );
  64. }
  65. ReleaseDC( NULL, dc );
  66. if ( bmNewImage &&
  67. bitmap.width != -1 &&
  68. bitmap.height != -1 )
  69. {
  70. bitmap.image = bmNewImage;
  71. bitmap.valid = true;
  72. }
  73. return bitmap.valid;
  74. }
  75. void DrawBitmapToWindow( mxWindow *wnd, int x, int y, int w, int h, mxbitmapdata_t& bitmap )
  76. {
  77. if ( !bitmap.valid )
  78. return;
  79. // Draw
  80. HDC dc = GetDC( (HWND) wnd->getHandle() );
  81. if ( !dc )
  82. return;
  83. HBITMAP bm, oldbm;
  84. bm = CreateCompatibleBitmap( dc, w, h );
  85. oldbm = (HBITMAP)SelectObject( dc, bm );
  86. HDC memdc = CreateCompatibleDC( dc );
  87. HBITMAP oldmembm = (HBITMAP)SelectObject( memdc, bitmap.image );
  88. int oldmode = SetStretchBltMode( dc, COLORONCOLOR );
  89. StretchBlt( dc, x, y, w, h, memdc, 0, 0, bitmap.width, bitmap.height, SRCCOPY );
  90. SetStretchBltMode( dc, oldmode );
  91. SelectObject( memdc, oldmembm );
  92. DeleteDC( memdc );
  93. SelectObject( dc, oldbm );
  94. DeleteObject( bm );
  95. ReleaseDC( (HWND) wnd->getHandle(), dc );
  96. RECT rc;
  97. rc.left = x;
  98. rc.right = x + w;
  99. rc.top = y;
  100. rc.bottom = y + h;
  101. ValidateRect( (HWND)wnd->getHandle(), &rc );
  102. }
  103. void DrawBitmapToDC( void *hdc, int x, int y, int w, int h, mxbitmapdata_t& bitmap )
  104. {
  105. if ( !bitmap.valid )
  106. return;
  107. HDC dc = (HDC)hdc;
  108. HDC memdc = CreateCompatibleDC( dc );
  109. HBITMAP oldmembm = (HBITMAP)SelectObject( memdc, bitmap.image );
  110. int oldmode = SetStretchBltMode( dc, COLORONCOLOR );
  111. StretchBlt( dc, x, y, w, h, memdc, 0, 0, bitmap.width, bitmap.height, SRCCOPY );
  112. SetStretchBltMode( dc, oldmode );
  113. SelectObject( memdc, oldmembm );
  114. DeleteDC( memdc );
  115. }