OSDN Git Service

Move bitmap helper functions from LocationView.cpp to new files (Common/Bitmap.h...
authorKimmo Varis <kimmov@gmail.com>
Fri, 11 Apr 2008 19:56:56 +0000 (19:56 +0000)
committerKimmo Varis <kimmov@gmail.com>
Fri, 11 Apr 2008 19:56:56 +0000 (19:56 +0000)
Src/Common/Bitmap.cpp [new file with mode: 0644]
Src/Common/Bitmap.h [new file with mode: 0644]
Src/LocationView.cpp
Src/Merge.dsp
Src/Merge.vcproj

diff --git a/Src/Common/Bitmap.cpp b/Src/Common/Bitmap.cpp
new file mode 100644 (file)
index 0000000..5d095cc
--- /dev/null
@@ -0,0 +1,133 @@
+/** 
+ * @file  Bitmap.cpp
+ *
+ * @brief Implementation file for Bitmap helper functions.
+ *
+ */
+// ID line follows -- this is updated by SVN
+// $Id$
+
+#include "stdafx.h"
+#include <math.h>
+#include "Bitmap.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+
+/**
+ * @brief Save an area as a bitmap
+ * @param pDC [in] The source device context
+ * @param rect [in] The rect to be copied
+ * @return The bitmap object
+ */
+CBitmap *CopyRectToBitmap(CDC *pDC, const CRect & rect)
+{
+       CRect rc = rect;
+       CDC dcMem;
+       dcMem.CreateCompatibleDC(pDC);
+       CBitmap *pBitmap = new CBitmap;
+       pBitmap->CreateCompatibleBitmap(pDC, rc.Width(), rc.Height());
+       CBitmap *pOldBitmap = dcMem.SelectObject(pBitmap);
+       dcMem.BitBlt(0, 0, rc.Width(), rc.Height(), pDC, rc.left, rc.top, SRCCOPY);
+       dcMem.SelectObject(pOldBitmap);
+       dcMem.DeleteDC();
+       return pBitmap;
+}
+
+/**
+ * @brief Draw a bitmap image
+ * @param pDC [in] The destination device context to draw to
+ * @param x [in] The x-coordinate of the upper-left corner of the bitmap
+ * @param y [in] The y-coordinate of the upper-left corner of the bitmap
+ * @param pBitmap [in] the bitmap to draw
+ */
+void DrawBitmap(CDC *pDC, int x, int y, CBitmap *pBitmap)
+{
+       CDC dcMem;
+       dcMem.CreateCompatibleDC(pDC);
+       BITMAP bm;
+       pBitmap->GetBitmap(&bm);
+       CBitmap *pOldBitmap = dcMem.SelectObject(pBitmap);
+       pDC->BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
+       dcMem.SelectObject(pOldBitmap);
+       dcMem.DeleteDC();
+}
+
+/**
+ * @brief Duplicate a bitmap and make it dark
+ * @param pDC [in] Device context
+ * @param pBitmap [in] the bitmap to darken
+ * @return The bitmap object
+ */
+CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap)
+{
+       CDC dcMem;
+       dcMem.CreateCompatibleDC(pDC);
+       BITMAP bm;
+       pBitmap->GetObject(sizeof(bm), &bm);
+       CBitmap *pBitmapDarkened = new CBitmap();
+       pBitmapDarkened->CreateCompatibleBitmap(pDC, bm.bmWidth, bm.bmHeight);
+       CBitmap *pOldBitmap = dcMem.SelectObject(pBitmapDarkened);
+       DrawBitmap(&dcMem, 0, 0, pBitmap);
+
+       BITMAPINFO bi;
+       bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
+       bi.bmiHeader.biWidth = bm.bmWidth;
+       bi.bmiHeader.biHeight = bm.bmHeight;
+       bi.bmiHeader.biPlanes = 1;
+       bi.bmiHeader.biBitCount = 32;
+       bi.bmiHeader.biCompression = 0;
+       bi.bmiHeader.biSizeImage = bm.bmWidth * 4 * bm.bmHeight;
+       bi.bmiHeader.biXPelsPerMeter = 0;
+       bi.bmiHeader.biYPelsPerMeter = 0;
+       bi.bmiHeader.biClrUsed = 0;
+       bi.bmiHeader.biClrImportant = 0;
+
+       BYTE *pbuf = new BYTE[bi.bmiHeader.biSizeImage];
+       GetDIBits(dcMem.m_hDC, (HBITMAP)*pBitmapDarkened, 0, bm.bmHeight, pbuf, &bi, DIB_RGB_COLORS);
+
+       int x;
+       for (x = 0; x < bm.bmWidth; x++)
+       {
+               double b = 0.70 + (0.20 * sin(acos((double)x/bm.bmWidth*2.0-1.0)));
+               for (int y = 1; y < bm.bmHeight-1; y++)
+               {
+                       int i = x * 4 + y * bm.bmWidth * 4;
+                       pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
+                       pbuf[i+1] = (BYTE)(pbuf[i+1] * b);
+                       pbuf[i+2] = (BYTE)(pbuf[i+2] * b);
+               }
+       }
+       for (x = 0; x < bm.bmWidth; x++)
+       {
+               int i = x * 4 + 0 * bm.bmWidth * 4;
+               pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
+               pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.7);
+               pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.7);
+               i = x * 4 + (bm.bmHeight-1) * bm.bmWidth * 4;
+               pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
+               pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.7);
+               pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.7);
+       }
+       for (int y = 0; y < bm.bmHeight; y++)
+       {
+               int i = 0 * 4 + y * bm.bmWidth * 4;
+               pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
+               pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.4);
+               pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.4);
+               i = (bm.bmWidth-1) * 4 + y * bm.bmWidth * 4;
+               pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
+               pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.4);
+               pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.4);
+       }
+
+       SetDIBits(dcMem.m_hDC, (HBITMAP)*pBitmapDarkened, 0, bm.bmHeight, pbuf, &bi, DIB_RGB_COLORS);
+       delete pbuf;
+       dcMem.SelectObject(pOldBitmap);
+       dcMem.DeleteDC();
+       return pBitmapDarkened;
+}
diff --git a/Src/Common/Bitmap.h b/Src/Common/Bitmap.h
new file mode 100644 (file)
index 0000000..ed25a12
--- /dev/null
@@ -0,0 +1,17 @@
+/** 
+ * @file  Bitmap.h
+ *
+ * @brief Declaration file for Bitmap helper functions.
+ *
+ */
+// ID line follows -- this is updated by SVN
+// $Id$
+
+#ifndef _BITMAP_H_
+#define _BITMAP_H_
+
+CBitmap *CopyRectToBitmap(CDC *pDC, const CRect & rect);
+void DrawBitmap(CDC *pDC, int x, int y, CBitmap *pBitmap);
+CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap);
+
+#endif // _BITMAP_H_
index 7a152c5..894a715 100644 (file)
@@ -26,7 +26,7 @@
  *
  */
 
-// RCS ID line follows -- this is updated by CVS
+// ID line follows -- this is updated by SVN
 // $Id$
 
 #include "stdafx.h"
@@ -38,7 +38,7 @@
 #include "BCMenu.h"
 #include "OptionsDef.h"
 #include "MergeLineFlags.h"
-#include <math.h>
+#include "Bitmap.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -77,119 +77,6 @@ enum LOCBAR_TYPE
 
 IMPLEMENT_DYNCREATE(CLocationView, CView)
 
-/**
- * @brief Save an area as a bitmap
- * @param pDC [in] The source device context
- * @param rect [in] The rect to be copied
- * @return The bitmap object
- */
-static CBitmap *CopyRectToBitmap(CDC *pDC, const CRect & rect)
-{
-       CRect rc = rect;
-       CDC dcMem;
-       dcMem.CreateCompatibleDC(pDC);
-       CBitmap *pBitmap = new CBitmap;
-       pBitmap->CreateCompatibleBitmap(pDC, rc.Width(), rc.Height());
-       CBitmap *pOldBitmap = dcMem.SelectObject(pBitmap);
-       dcMem.BitBlt(0, 0, rc.Width(), rc.Height(), pDC, rc.left, rc.top, SRCCOPY);
-       dcMem.SelectObject(pOldBitmap);
-       dcMem.DeleteDC();
-       return pBitmap;
-}
-
-/**
- * @brief Draw a bitmap image
- * @param pDC [in] The destination device context to draw to
- * @param x [in] The x-coordinate of the upper-left corner of the bitmap
- * @param y [in] The y-coordinate of the upper-left corner of the bitmap
- * @param pBitmap [in] the bitmap to draw
- */
-static void DrawBitmap(CDC *pDC, int x, int y, CBitmap *pBitmap)
-{
-       CDC dcMem;
-       dcMem.CreateCompatibleDC(pDC);
-       BITMAP bm;
-       pBitmap->GetBitmap(&bm);
-       CBitmap *pOldBitmap = dcMem.SelectObject(pBitmap);
-       pDC->BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
-       dcMem.SelectObject(pOldBitmap);
-       dcMem.DeleteDC();
-}
-
-/**
- * @brief Duplicate a bitmap and make it dark
- * @param pDC [in] Device context
- * @param pBitmap [in] the bitmap to darken
- * @return The bitmap object
- */
-static CBitmap *GetDarkenedBitmap(CDC *pDC, CBitmap *pBitmap)
-{
-       CDC dcMem;
-       dcMem.CreateCompatibleDC(pDC);
-       BITMAP bm;
-       pBitmap->GetObject(sizeof(bm), &bm);
-       CBitmap *pBitmapDarkened = new CBitmap();
-       pBitmapDarkened->CreateCompatibleBitmap(pDC, bm.bmWidth, bm.bmHeight);
-       CBitmap *pOldBitmap = dcMem.SelectObject(pBitmapDarkened);
-       DrawBitmap(&dcMem, 0, 0, pBitmap);
-
-       BITMAPINFO bi;
-       bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
-       bi.bmiHeader.biWidth = bm.bmWidth;
-       bi.bmiHeader.biHeight = bm.bmHeight;
-       bi.bmiHeader.biPlanes = 1;
-       bi.bmiHeader.biBitCount = 32;
-       bi.bmiHeader.biCompression = 0;
-       bi.bmiHeader.biSizeImage = bm.bmWidth * 4 * bm.bmHeight;
-       bi.bmiHeader.biXPelsPerMeter = 0;
-       bi.bmiHeader.biYPelsPerMeter = 0;
-       bi.bmiHeader.biClrUsed = 0;
-       bi.bmiHeader.biClrImportant = 0;
-
-       BYTE *pbuf = new BYTE[bi.bmiHeader.biSizeImage];
-       GetDIBits(dcMem.m_hDC, (HBITMAP)*pBitmapDarkened, 0, bm.bmHeight, pbuf, &bi, DIB_RGB_COLORS);
-
-       int x;
-       for (x = 0; x < bm.bmWidth; x++)
-       {
-               double b = 0.70 + (0.20 * sin(acos((double)x/bm.bmWidth*2.0-1.0)));
-               for (int y = 1; y < bm.bmHeight-1; y++)
-               {
-                       int i = x * 4 + y * bm.bmWidth * 4;
-                       pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
-                       pbuf[i+1] = (BYTE)(pbuf[i+1] * b);
-                       pbuf[i+2] = (BYTE)(pbuf[i+2] * b);
-               }
-       }
-       for (x = 0; x < bm.bmWidth; x++)
-       {
-               int i = x * 4 + 0 * bm.bmWidth * 4;
-               pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
-               pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.7);
-               pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.7);
-               i = x * 4 + (bm.bmHeight-1) * bm.bmWidth * 4;
-               pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
-               pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.7);
-               pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.7);
-       }
-       for (int y = 0; y < bm.bmHeight; y++)
-       {
-               int i = 0 * 4 + y * bm.bmWidth * 4;
-               pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
-               pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.4);
-               pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.4);
-               i = (bm.bmWidth-1) * 4 + y * bm.bmWidth * 4;
-               pbuf[i  ] = (BYTE)(pbuf[i] * 0.95);
-               pbuf[i+1] = (BYTE)(pbuf[i+1] * 0.4);
-               pbuf[i+2] = (BYTE)(pbuf[i+2] * 0.4);
-       }
-
-       SetDIBits(dcMem.m_hDC, (HBITMAP)*pBitmapDarkened, 0, bm.bmHeight, pbuf, &bi, DIB_RGB_COLORS);
-       delete pbuf;
-       dcMem.SelectObject(pOldBitmap);
-       dcMem.DeleteDC();
-       return pBitmapDarkened;
-}
 
 CLocationView::CLocationView()
        : m_visibleTop(-1)
index 426ef1f..2c8b62f 100644 (file)
@@ -195,6 +195,10 @@ SOURCE=.\BCMenu.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\Common\Bitmap.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\CCPrompt.cpp
 # End Source File
 # Begin Source File
@@ -1047,6 +1051,10 @@ SOURCE=.\BCMenu.h
 # End Source File
 # Begin Source File
 
+SOURCE=.\Common\Bitmap.h
+# End Source File
+# Begin Source File
+
 SOURCE=.\CCPrompt.h
 # End Source File
 # Begin Source File
index bab1c15..31bf194 100644 (file)
                                </FileConfiguration>
                        </File>
                        <File
+                               RelativePath=".\Common\Bitmap.cpp">
+                       </File>
+                       <File
                                RelativePath="CCPrompt.cpp">
                                <FileConfiguration
                                        Name="UnicodeRelease|Win32">
                                RelativePath="BCMenu.h">
                        </File>
                        <File
+                               RelativePath=".\Common\Bitmap.h">
+                       </File>
+                       <File
                                RelativePath="CCPrompt.h">
                        </File>
                        <File