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.

101 lines
3.0 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: auxlib.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of AUXLIB.CPP
  13. //----------------------------------------------------------------------------
  14. #include "StdAfx.h"
  15. #include "AuxLib.h"
  16. #include "..\..\LgLib\Version.h"
  17. double CalcViewRectAndScale( CRect& mapRect, CRect *pViewRect )
  18. {
  19. double k = ((double)mapRect.Height()) / ((double)mapRect.Width());
  20. CRect rect;
  21. rect = *pViewRect;
  22. rect.right = (int)(((double)rect.left) + ((double)rect.Height()) / k );
  23. if( rect.Width() > pViewRect->Width() )
  24. {
  25. rect = *pViewRect;
  26. rect.bottom = (int)(((double)rect.top) + ((double)rect.Width()) * k );
  27. }
  28. *pViewRect = rect;
  29. return ((double)rect.Width()) / ((double)mapRect.Width());
  30. }
  31. CRect CalcDrawRect( CRect& viewRect, CSize& mapSize, SDPOINT& mapShift, double scale )
  32. {
  33. double cx = mapSize.cx * scale;
  34. double cy = mapSize.cy * scale;
  35. double x = mapShift.x * cx;
  36. double y = mapShift.y * cy;
  37. CRect rect;
  38. rect.left = (int)(viewRect.left - x);
  39. rect.top = (int)(viewRect.top - y);
  40. rect.right = (int)(rect.left + cx);
  41. rect.bottom = (int)(rect.top + cy);
  42. return rect;
  43. }
  44. /*
  45. CRect CalcDrawRectCentral( CRect& viewRect, CSize& mapSize, DPOINT& mapShift, double scale )
  46. {
  47. double cx = mapSize.cx * scale;
  48. double cy = mapSize.cy * scale;
  49. double x = mapShift.x * cx;
  50. double y = mapShift.y * cy;
  51. CRect rect;
  52. rect.left = (int)( 0.5 * (viewRect.left + viewRect.right) - x );
  53. rect.top = (int)( 0.5 * ( viewRect.top + viewRect.bottom) - y );
  54. rect.right = (int)(rect.left + cx);
  55. rect.bottom = (int)(rect.top + cy);
  56. return rect;
  57. }
  58. */
  59. CPoint CalcDrawPoint( CRect& viewRect, CSize& mapSize, SDPOINT& mapPoint, double scale )
  60. {
  61. double x = mapPoint.x * mapSize.cx * scale;
  62. double y = mapPoint.y * mapSize.cy * scale;
  63. return CPoint( (int)(viewRect.left + x), (int)(viewRect.top + y) );
  64. }
  65. SDPOINT CalcMapPoint( CPoint& viewPoint, CSize& mapSize, SDPOINT& mapShift, double scale )
  66. {
  67. SDPOINT point;
  68. point.x = ((double)(viewPoint.x + mapShift.x * mapSize.cx * scale)) / ((double)mapSize.cx * scale);
  69. point.y = ((double)(viewPoint.y + mapShift.y * mapSize.cy * scale)) / ((double)mapSize.cy * scale);
  70. return point;
  71. }
  72. SDPOINT CalcViewCenterShift( CRect& viewRect, CSize& mapSize, double scale )
  73. {
  74. double cx = mapSize.cx * scale;
  75. double cy = mapSize.cy * scale;
  76. double dx = 0.5 * (double)viewRect.Width();
  77. double dy = 0.5 * (double)viewRect.Height();
  78. return SDPOINT( dx / cx, dy / cy );
  79. }
  80. BOOL FindTag( FILE_TAG *pTag, int nTagCount, LPCTSTR pTagName, LPDWORD pFilePtr )
  81. {
  82. for( int i = 0; i < nTagCount; i++ )
  83. {
  84. if( !_strnicmp( pTag[i].pName, pTagName, strlen( pTagName ) ) )
  85. {
  86. *pFilePtr = pTag[i].iStart;
  87. return TRUE;
  88. }
  89. }
  90. return FALSE;
  91. }