📄 browsebar.cpp
字号:
// BrowseBar1.cpp : implementation file
//
#include "stdafx.h"
#include "RSImageStar.h"
#include "BrowseBar.h"
#include "RSImageStarDoc.h"
#include "RSImageStarView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBrowseBar dialog
extern HCURSOR hHandGrabed;
extern HCURSOR hHandWantGrab;
extern HCURSOR hHandpoint;
CBrowseBar::CBrowseBar(CWnd* pParent /*=NULL*/)
{
//{{AFX_DATA_INIT(CBrowseBar)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
ratio=float(1.0);
IsOpenImage = false;
CursorInRedRect = CursorInImage = CursorGrab = LButtonDown = false;
RedPen.CreatePen(PS_SOLID, 2, RGB(255, 0, 0));
}
void CBrowseBar::DoDataExchange(CDataExchange* pDX)
{
CDialogBar::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBrowseBar)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBrowseBar, CDialogBar)
//{{AFX_MSG_MAP(CBrowseBar)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBrowseBar message handlers
void CBrowseBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
DrawMiniImage();
// Do not call CDialogBar::OnPaint() for painting messages
}
void CBrowseBar::DrawMiniImage()
{
// TODO: Add your message handler code here
if( !IsWindowVisible() )
{
TRACE("The window is not visible , so I return !!!\n");
return;
}
CFrameWnd* lpFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
if( lpFrameWnd == NULL ) return;
CRSImageStarView* lpView = (CRSImageStarView*)lpFrameWnd->GetActiveFrame()->GetActiveView();
CStatic* pic = (CStatic*)GetDlgItem( IDC_MINIIMAGE );
CClientDC dc(pic);
GetClientRect( PicCRect );
int ClientW = PicCRect.Width();
int ClientH = PicCRect.Height();
if( lpView == NULL )
{
IsOpenImage = false;
/* dc.SetBkMode( TRANSPARENT );
dc.SetTextColor( RGB(255, 0, 0) );
PicCRect.top += 30;
dc.DrawText("鸟瞰", PicCRect, DT_CENTER);
*/ }
else
{
CRSImageStarDoc *m_pDoc = lpView->m_pDoc;
if(m_pDoc->m_Dib!=NULL)
{
IsOpenImage=true;
if((m_pDoc->m_Dib->MicW/float(PicCRect.Width()))>(m_pDoc->m_Dib->MicH/float(PicCRect.Height())))
{
float scale=(PicCRect.Width()-10)/float(m_pDoc->m_Dib->MicW);
ImageRect.left=PicCRect.left+5;
ImageRect.right=PicCRect.right-5;
ImageRect.top=(PicCRect.Height()-int(m_pDoc->m_Dib->MicH*scale))/2;
ImageRect.bottom=(PicCRect.Height()+int(m_pDoc->m_Dib->MicH*scale))/2;
}
else
{
float scale=(PicCRect.Height()-10)/float(m_pDoc->m_Dib->MicH);
ImageRect.top=PicCRect.top+5;
ImageRect.bottom=PicCRect.bottom-5;
ImageRect.left=(PicCRect.Width()-int(m_pDoc->m_Dib->MicW*scale))/2;
ImageRect.right=(PicCRect.Width()+int(m_pDoc->m_Dib->MicW*scale))/2;
}
CClientDC dc(this);
if(m_pDoc->m_Dib->lpMicImg!=NULL)
::StretchDIBits(dc.m_hDC, // hDC
ImageRect.left, // DestX
ImageRect.top, // DestY
ImageRect.Width(), // nDestWidth
ImageRect.Height(), // nDestHeight
0, // SrcX
0, // SrcY
m_pDoc->m_Dib->MicW, // wSrcWidth
m_pDoc->m_Dib->MicH, // wSrcHeight
m_pDoc->m_Dib->lpMicImg, // lpBits
m_pDoc->m_Dib->lpMicBMI, // lpBitsInfo
DIB_RGB_COLORS, // wUsage
SRCCOPY);
DrawRedRect();
}
else
{
IsOpenImage = false;
/* dc.SetBkMode( TRANSPARENT );
dc.SetTextColor( RGB(255, 0, 0) );
PicCRect.top += 30;
dc.DrawText("鸟瞰区域", PicCRect, DT_CENTER);
*/ }
}
}
void CBrowseBar::DrawRedRect()
{
CFrameWnd* lpFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
if( lpFrameWnd == NULL ) return;
CRSImageStarView* lpView = (CRSImageStarView*)lpFrameWnd->GetActiveFrame()->GetActiveView();
if(lpView)
{
CClientDC dc(this);
if(lpView->m_pDoc->m_Dib!=NULL)
{
CRSImageStarDoc *m_pDoc=lpView->m_pDoc;
CRect rect;
lpView->GetClientRect(&rect);
CSize size=lpView->GetTotalSize();
ratio=size.cx/float(ImageRect.Width());
int width=size.cx;
int height=size.cy;
CPoint pos;
pos=lpView->GetScrollPosition();
float ratiox,ratioy;
if((rect.Width()<width)&&(rect.Height()<height))
{
ratiox=rect.Width()/float(width);
ratioy=rect.Height()/float(height);
ImgW=ImageRect.Width();
ImgH=ImageRect.Height();
RedRect.left=ImageRect.left+int(pos.x*ImgW/width+1.0);
RedRect.top=ImageRect.top+int(pos.y*ImgH/height+1.0);
RedRect.right=RedRect.left+int(ratiox*ImgW);
RedRect.bottom=RedRect.top+int(ratioy*ImgH);
}
else if((rect.Width()>width)&&(rect.Height()>height))
{
RedRect.left=ImageRect.left+1;
RedRect.top=ImageRect.top+1;
RedRect.right=ImageRect.right;
RedRect.bottom=ImageRect.bottom;
}
else if((rect.Width()<=width)&&(rect.Height()>=height))
{
ratiox=rect.Width()/float(width);
ImgW=ImageRect.Width();
RedRect.top=ImageRect.top+1;
RedRect.bottom=ImageRect.bottom;
RedRect.left=ImageRect.left+int(pos.x*ImgW/width+1.0);
RedRect.right=RedRect.left+int(ratiox*ImgW);
}
else
{
ratioy=rect.Height()/float(height);
ImgH=ImageRect.Height();
RedRect.left=ImageRect.left+1;
RedRect.right=ImageRect.right;
RedRect.top=ImageRect.top+int(pos.y*ImgH/height+1.0);
RedRect.bottom=RedRect.top+int(ratioy*ImgH);
}
pOldPen = dc.SelectObject( &RedPen );
dc.SelectStockObject( NULL_BRUSH );
dc.Rectangle(RedRect);
dc.SelectObject( pOldPen );
}
}
}
void CBrowseBar::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
pMain->ShowControlBar(&pMain->m_wndBrowseBar, true, FALSE);
LButtonDown = true;
if( IsOpenImage && PicCRect.PtInRect( point ) )
{
if( RedRect.PtInRect( point ) )
{
CursorInRedRect = true;
SetCapture();
SetCursor( hHandGrabed );
StartPt = point;
}
else
{
CursorInRedRect = false;
if(ImageRect.PtInRect(point))
{
SetCursor( hHandpoint);
CursorInImage = true;
}
else
CursorInImage = false;
}
if( CursorInImage &&! CursorInRedRect )
{
int dx = point.x - (RedRect.left + RedRect.right) / 2;
int dy = point.y - (RedRect.top + RedRect.bottom) / 2;
RedRect.OffsetRect(dx, dy);
CFrameWnd* lpFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
if( lpFrameWnd == NULL ) return;
CRSImageStarView* lpView = (CRSImageStarView*)lpFrameWnd->GetActiveFrame()->GetActiveView();
if(lpView)
{
CSize size=lpView->GetScrollPosition();
size.cx+=int(dx*ratio);
size.cy+=int(dy*ratio);
CRect rect;
lpView->GetClientRect(&rect);
CSize totalsize=lpView->GetTotalSize();
if((size.cx+rect.Width())>totalsize.cx)
size.cx=totalsize.cx-rect.Width();
if((size.cy+rect.Height())>totalsize.cy)
size.cy=totalsize.cy-rect.Height();
lpView->ScrollToPosition(CPoint(size.cx,size.cy));
DrawRedRect();
}
}
}
else
CDialogBar::OnLButtonDown(nFlags, point);
}
void CBrowseBar::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(CursorInRedRect)
ReleaseCapture();
if(RedRect.PtInRect( point ))
SetCursor( hHandGrabed );
else if(ImageRect.PtInRect(point))
SetCursor( hHandpoint);
LButtonDown = false;
CursorInRedRect=false;
CursorInImage=false;
CDialogBar::OnLButtonUp(nFlags, point);
}
void CBrowseBar::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if( IsOpenImage)
{
if( CursorInRedRect && LButtonDown )// 开始拖动红框
{
int dx = point.x - StartPt.x;
int dy = point.y - StartPt.y;
if((dx+RedRect.left)<0)
dx=-RedRect.left;
if((dx+RedRect.right)>ImageRect.right)
dx=ImageRect.right-RedRect.right;
if((dy+RedRect.top)<0)
dy=-RedRect.top;
if((dy+RedRect.bottom)>ImageRect.bottom)
dy=ImageRect.bottom-RedRect.bottom;
RedRect.OffsetRect(dx, dy);
CFrameWnd* lpFrameWnd = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
if( lpFrameWnd == NULL ) return;
CRSImageStarView* lpView = (CRSImageStarView*)lpFrameWnd->GetActiveFrame()->GetActiveView();
if(lpView)
{
CSize size=lpView->GetScrollPosition();
size.cx+=int(dx*ratio);
size.cy+=int(dy*ratio);
CRect rect;
lpView->GetClientRect(&rect);
CSize totalsize=lpView->GetTotalSize();
if((size.cx+rect.Width())>totalsize.cx)
size.cx=totalsize.cx-rect.Width();
if((size.cy+rect.Height())>totalsize.cy)
size.cy=totalsize.cy-rect.Height();
lpView->ScrollToPosition(CPoint(size.cx,size.cy));
DrawRedRect();
}
StartPt = point;
}
else
{
if( RedRect.PtInRect( point ))
SetCursor( hHandGrabed );
else if(ImageRect.PtInRect(point))
SetCursor( hHandpoint);
}
}
else
CDialogBar::OnMouseMove(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -