[GME-commit]
GMESRC/GME/Gme PannButton.h,1.1,1.2 PannButton.cpp,1.2,1.3
gme-commit at list.isis.vanderbilt.edu
gme-commit at list.isis.vanderbilt.edu
Wed May 5 14:33:36 CDT 2004
Update of /var/lib/gme/GMESRC/GME/Gme
In directory braindrain:/tmp/cvs-serv31508
Modified Files:
PannButton.h PannButton.cpp
Log Message:
Panning window's frame movable
CVS User: bogyom
Index: PannButton.h
===================================================================
RCS file: /var/lib/gme/GMESRC/GME/Gme/PannButton.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PannButton.h 25 Mar 2004 20:06:44 -0000 1.1
--- PannButton.h 5 May 2004 18:33:34 -0000 1.2
***************
*** 11,31 ****
// CPannButton window
! class CPannButton : public CButton
{
// Construction
public:
CPannButton();
void SetBitmapDC(CDC *bdc, CRect &ori, CRect &rect);
! void SetViewRect(CRect &vrect);
! void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
private:
CDC* m_bitmapDC;
! CRect m_bitmapS;
! CRect m_bitmapO;
! CRect m_viewRect;
! // Attributes
! public:
// Operations
--- 11,49 ----
// CPannButton window
! class CPannButton : public CWnd
{
// Construction
public:
CPannButton();
+ bool Create(CWnd *parent);
void SetBitmapDC(CDC *bdc, CRect &ori, CRect &rect);
! void SetViewRect(CRect vrect);
private:
+ HCURSOR m_arrowh;
+ HCURSOR m_sizeallh;
+
+ bool m_inMove;
+ CPoint m_moveStartPoint;
+ CRect m_moveStartRect;
+
+ CWnd* m_parent;
CDC* m_bitmapDC;
! CRect m_bitmapSizeOri;
! CRect m_bitmapSizeStored;
! CRect m_bitmapOnScreen;
! CRect m_viewRectOnStored;
!
! CRect m_viewRectOnScreen;
! CRect m_viewRectInMove;
!
! double m_storedToScreenRx;
! double m_storedToScreenRy;
! double m_oriToStoredRx;
! double m_oriToStoredRy;
!
! void bmpToScreen(CRect clientr);
! void viewRectToScreen(CRect &vRect);
// Operations
***************
*** 44,48 ****
protected:
//{{AFX_MSG(CPannButton)
! // NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
--- 62,69 ----
protected:
//{{AFX_MSG(CPannButton)
! afx_msg void OnPaint();
! afx_msg void OnMouseMove(UINT nFlags, CPoint point);
! afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
! afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//}}AFX_MSG
Index: PannButton.cpp
===================================================================
RCS file: /var/lib/gme/GMESRC/GME/Gme/PannButton.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PannButton.cpp 26 Apr 2004 09:16:12 -0000 1.2
--- PannButton.cpp 5 May 2004 18:33:34 -0000 1.3
***************
*** 17,24 ****
CPannButton::CPannButton()
{
! m_viewRect = CRect(0,0,0,0);
m_bitmapDC = NULL;
! m_bitmapS = CRect(0,0,0,0);
! m_bitmapO = CRect(0,0,0,0);
}
--- 17,34 ----
CPannButton::CPannButton()
{
! m_viewRectOnScreen = CRect(0,0,0,0);
! m_viewRectInMove = CRect(0,0,0,0);
! m_viewRectOnStored = CRect(0,0,0,0);
m_bitmapDC = NULL;
! m_bitmapSizeStored = CRect(0,0,0,0);
! m_bitmapSizeOri = CRect(0,0,0,0);
! m_parent = NULL;
! m_sizeallh = NULL;
! m_arrowh = NULL;
! m_inMove = false;
! m_storedToScreenRx = 0;
! m_storedToScreenRy = 0;
! m_oriToStoredRx = 0;
! m_oriToStoredRy = 0;
}
***************
*** 30,36 ****
! BEGIN_MESSAGE_MAP(CPannButton, CButton)
//{{AFX_MSG_MAP(CPannButton)
! // NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
--- 40,49 ----
! BEGIN_MESSAGE_MAP(CPannButton, CWnd)
//{{AFX_MSG_MAP(CPannButton)
! ON_WM_PAINT()
! ON_WM_MOUSEMOVE()
! ON_WM_LBUTTONDOWN()
! ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
***************
*** 39,42 ****
--- 52,62 ----
// CPannButton message handlers
+ bool CPannButton::Create(CWnd *parent)
+ {
+ m_parent = parent;
+ m_sizeallh = ::LoadCursor(NULL, IDC_SIZEALL);
+ m_arrowh = ::LoadCursor(NULL, IDC_ARROW);
+ return true;
+ }
void CPannButton::SetBitmapDC(CDC *bdc, CRect &orisize, CRect &actsize) // may be empty
***************
*** 45,114 ****
delete m_bitmapDC;
m_bitmapDC = bdc;
! m_bitmapO = orisize;
! m_bitmapS = actsize;
Invalidate();
UpdateWindow();
}
! void CPannButton::SetViewRect(CRect &vrect)
{
- // vrect is on the logical coordinate system
- double rx = (double)(m_bitmapS.Width())/ m_bitmapO.Width();
- double ry = (double)(m_bitmapS.Height())/ m_bitmapO.Height();
- m_viewRect.left = (int)(vrect.left * rx);
- m_viewRect.right = (int)(vrect.right * rx);
- m_viewRect.top = (int)(vrect.top * ry);
- m_viewRect.bottom = (int)(vrect.bottom * ry);
// the method can be called even if the panning window is not visible
! if (::IsWindow(GetSafeHwnd())) {
! Invalidate();
UpdateWindow();
}
}
! void CPannButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
if (!m_bitmapDC)
- {
return;
}
! if (lpDrawItemStruct->itemAction == ODA_DRAWENTIRE)
{
! CDC dc;
! dc.Attach(lpDrawItemStruct->hDC); // device context for painting
! CRect vrect;
! GetParent()->GetClientRect(&vrect);
! m_bitmapDC->SetMapMode(MM_TEXT);
! dc.SetMapMode(MM_TEXT);
! double dx = (double)(vrect.Width())/m_bitmapS.Width();
! double dy = (double)(vrect.Height())/m_bitmapS.Height();
! double dd = (dx <= dy)? dx: dy;
! dd = (dd < 1)? dd: 1;
! vrect.right = min(vrect.right, dd * m_bitmapS.Width());
! vrect.bottom = min(vrect.bottom, dd * m_bitmapS.Height());
! BOOL ret = dc.StretchBlt(0, 0, vrect.Width(), vrect.Height(), m_bitmapDC,
! 0, 0, m_bitmapS.Width(), m_bitmapS.Height(), SRCCOPY);
! if (!m_viewRect.IsRectEmpty())
{
! double rx = (double)(vrect.Width())/ m_bitmapS.Width();
! double ry = (double)(vrect.Height())/ m_bitmapS.Height();
! CRect vRect(0,0,0,0);
! vRect.left = m_viewRect.left * rx;
! vRect.right = m_viewRect.right * rx;
! vRect.top = m_viewRect.top * ry;
! vRect.bottom = m_viewRect.bottom * ry;
! vRect.right = min(vRect.right, vrect.right);
! vRect.bottom = min(vRect.bottom, vrect.bottom);
! CBrush brush;
! DWORD dw = GetSysColor(COLOR_WINDOWTEXT);
! BYTE r = GetRValue(dw);
! BYTE g = GetGValue(dw);
! BYTE b = GetBValue(dw);
! brush.CreateSolidBrush(RGB(r,g,b));
! dc.FrameRect(&vRect, &brush);
}
! dc.Detach();
}
}
--- 65,257 ----
delete m_bitmapDC;
m_bitmapDC = bdc;
! m_bitmapSizeOri = orisize;
! m_bitmapSizeStored = actsize;
Invalidate();
UpdateWindow();
}
! void CPannButton::SetViewRect(CRect irect)
{
// the method can be called even if the panning window is not visible
! if (m_bitmapSizeOri.IsRectEmpty() || m_bitmapSizeStored.IsRectEmpty())
! return;
!
! m_oriToStoredRx = (double)(m_bitmapSizeStored.Width())/ m_bitmapSizeOri.Width();
! m_oriToStoredRy = (double)(m_bitmapSizeStored.Height())/ m_bitmapSizeOri.Height();
! m_viewRectOnStored.left = (int)(irect.left * m_oriToStoredRx);
! m_viewRectOnStored.right = (int)(irect.right * m_oriToStoredRx);
! m_viewRectOnStored.top = (int)(irect.top * m_oriToStoredRy);
! m_viewRectOnStored.bottom = (int)(irect.bottom * m_oriToStoredRy);
! CRect vRect(0,0,0,0);
! CRect client;
! GetParent()->GetClientRect(&client);
!
! bmpToScreen(client);
! viewRectToScreen(vRect);
!
! if (::IsWindow(GetSafeHwnd()))
! {
! InvalidateRect(&m_viewRectOnScreen, FALSE);
! m_viewRectOnScreen = vRect;
! InvalidateRect(&vRect, FALSE);
UpdateWindow();
}
+ else
+ m_viewRectOnScreen = vRect;
}
! void CPannButton::bmpToScreen(CRect clientr)
! {
! double dx = (double)(clientr.Width())/m_bitmapSizeStored.Width();
! double dy = (double)(clientr.Height())/m_bitmapSizeStored.Height();
! double dd = (dx <= dy)? dx: dy;
! dd = (dd < 1)? dd: 1;
!
! clientr.right = min(clientr.right, dd * m_bitmapSizeStored.Width());
! clientr.bottom = min(clientr.bottom, dd * m_bitmapSizeStored.Height());
! m_bitmapOnScreen = clientr;
! }
!
! void CPannButton::viewRectToScreen(CRect &vRect)
! {
! m_storedToScreenRx = (double)(m_bitmapOnScreen.Width())/ m_bitmapSizeStored.Width();
! m_storedToScreenRy = (double)(m_bitmapOnScreen.Height())/ m_bitmapSizeStored.Height();
! vRect = CRect(0,0,0,0);
! vRect.left = m_viewRectOnStored.left * m_storedToScreenRx;
! vRect.right = m_viewRectOnStored.right * m_storedToScreenRx;
! vRect.top = m_viewRectOnStored.top * m_storedToScreenRy;
! vRect.bottom = m_viewRectOnStored.bottom * m_storedToScreenRy;
! vRect.right = min(vRect.right, m_bitmapOnScreen.right);
! vRect.bottom = min(vRect.bottom, m_bitmapOnScreen.bottom);
! }
!
! void CPannButton::OnPaint()
{
+ CPaintDC dc(this); // device context for painting
+ dc.SetMapMode(MM_TEXT);
+
+ // clear it
+ CRect clientr;
+ GetParent()->GetClientRect(&clientr);
+ CBrush brush;
+ DWORD dw = GetSysColor(COLOR_3DFACE);
+ BYTE r = GetRValue(dw);
+ BYTE g = GetGValue(dw);
+ BYTE b = GetBValue(dw);
+ brush.CreateSolidBrush(RGB(r,g,b));
+ dc.FillRect(&clientr, &brush);
+
+ // no bitmap - return
if (!m_bitmapDC)
return;
+
+ m_bitmapDC->SetMapMode(MM_TEXT);
+
+ // transform bitmap to screen
+ bmpToScreen(clientr);
+ BOOL ret = dc.StretchBlt(0, 0, m_bitmapOnScreen.Width(), m_bitmapOnScreen.Height(), m_bitmapDC,
+ 0, 0, m_bitmapSizeStored.Width(), m_bitmapSizeStored.Height(), SRCCOPY);
+ CBrush brush1;
+ DWORD dw1 = GetSysColor(COLOR_WINDOWTEXT);
+ BYTE r1 = GetRValue(dw1);
+ BYTE g1 = GetGValue(dw1);
+ BYTE b1 = GetBValue(dw1);
+ brush1.CreateSolidBrush(RGB(r1,g1,b1));
+ if (!m_viewRectOnStored.IsRectEmpty() && !m_inMove)
+ {
+ CRect vRect(0,0,0,0);
+ viewRectToScreen(vRect);
+ m_viewRectOnScreen = vRect;
+ dc.FrameRect(&m_viewRectOnScreen, &brush1);
}
! else if (m_inMove)
! dc.FrameRect(&m_viewRectInMove, &brush1);
! }
!
! void CPannButton::OnMouseMove(UINT nFlags, CPoint point)
! {
! if (m_viewRectOnScreen.PtInRect(point) || m_inMove)
! SetCursor(m_sizeallh);
! else
! SetCursor(m_arrowh);
! if (m_inMove)
{
! // move panning frame only
! int dx = point.x -m_moveStartPoint.x ;
! int dy = point.y -m_moveStartPoint.y;
! CRect trackRect = m_viewRectOnScreen;
! trackRect.OffsetRect(dx, dy);
! CRect shadow;
! shadow.IntersectRect(&trackRect, &m_bitmapOnScreen);
! if (shadow.Width() != trackRect.Width() && shadow.Height() != trackRect.Height())
! return;
! if (m_viewRectInMove.IsRectEmpty())
! InvalidateRect(&m_viewRectOnScreen, FALSE);
! else
! InvalidateRect(&m_viewRectInMove, FALSE);
! if (shadow.Width() != trackRect.Width())
! {
! if (trackRect.left < 0)
! trackRect.OffsetRect(-trackRect.left, 0);
! else
! trackRect.OffsetRect(m_bitmapOnScreen.right-trackRect.right, 0);
! }
! else if (shadow.Height() != trackRect.Height())
! {
! if (trackRect.top < 0)
! trackRect.OffsetRect(0, -trackRect.top);
! else
! trackRect.OffsetRect(0, m_bitmapOnScreen.bottom-trackRect.bottom);
! }
! m_viewRectInMove = trackRect;
! InvalidateRect(&m_viewRectInMove, FALSE);
! UpdateWindow();
! }
! CWnd::OnMouseMove(nFlags, point);
! }
! void CPannButton::OnLButtonDown(UINT nFlags, CPoint point)
! {
! // TODO: Add your message handler code here and/or call default
! if (m_viewRectOnScreen.PtInRect(point))
! {
! SetCursor(m_sizeallh);
! SetCapture();
! m_inMove = true;
! m_moveStartPoint = point;
! m_moveStartRect = m_viewRectOnScreen;
! }
! else
! SetCursor(m_arrowh);
! CWnd::OnLButtonDown(nFlags, point);
! }
!
! void CPannButton::OnLButtonUp(UINT nFlags, CPoint point)
! {
! // TODO: Add your message handler code here and/or call default
! if (m_inMove)
! {
! ReleaseCapture();
! m_inMove = false;
! CWnd* mainw = AfxGetMainWnd();
! if (mainw)
{
! double dx = point.x -m_moveStartPoint.x ;
! double dy = point.y -m_moveStartPoint.y;
! // dx, dy in pann win screen coordinates
! // calculate real screen coordinates
! dx /= m_storedToScreenRx;
! dy /= m_storedToScreenRy;
! dx /= m_oriToStoredRx;
! dy /= m_oriToStoredRy;
! mainw->PostMessage(WM_PANN_SCROLL, (WPARAM)(int)dx, (LPARAM)(int)dy);
! Invalidate();
}
! m_viewRectInMove = CRect(0,0,0,0);
! m_moveStartPoint = CPoint(0,0);
! m_moveStartRect = CRect(0,0,0,0);
}
+
+ CWnd::OnLButtonUp(nFlags, point);
}
More information about the GME-commit
mailing list