A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / apps / mplayerc / ChildView.cpp
blobbec015bd60a366db8b7d864c5b0842be438353c2
1 /*
2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // ChildView.cpp : implementation of the CChildView class
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "ChildView.h"
28 #include "MainFrm.h"
29 #include "libpng.h"
31 #ifdef _DEBUG
32 #define new DEBUG_NEW
33 #undef THIS_FILE
34 static char THIS_FILE[] = __FILE__;
35 #endif
37 /////////////////////////////////////////////////////////////////////////////
38 // CChildView
40 CChildView::CChildView() : m_vrect(0,0,0,0)
42 m_lastlmdowntime = 0;
43 m_lastlmdownpoint.SetPoint(0, 0);
45 LoadLogo();
48 CChildView::~CChildView()
52 BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
54 if(!CWnd::PreCreateWindow(cs))
55 return FALSE;
57 cs.style &= ~WS_BORDER;
58 cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
59 ::LoadCursor(NULL, IDC_HAND), HBRUSH(COLOR_WINDOW+1), NULL);
61 return TRUE;
64 BOOL CChildView::PreTranslateMessage(MSG* pMsg)
66 if(pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MYMOUSELAST)
68 CWnd* pParent = GetParent();
69 CPoint p(pMsg->lParam);
70 ::MapWindowPoints(pMsg->hwnd, pParent->m_hWnd, &p, 1);
72 bool fDblClick = false;
74 bool fInteractiveVideo = ((CMainFrame*)AfxGetMainWnd())->IsInteractiveVideo();
76 if(fInteractiveVideo)
78 if(pMsg->message == WM_LBUTTONDOWN)
80 if((pMsg->time - m_lastlmdowntime) <= GetDoubleClickTime()
81 && abs(pMsg->pt.x - m_lastlmdownpoint.x) <= GetSystemMetrics(SM_CXDOUBLECLK)
82 && abs(pMsg->pt.y - m_lastlmdownpoint.y) <= GetSystemMetrics(SM_CYDOUBLECLK))
84 fDblClick = true;
85 m_lastlmdowntime = 0;
86 m_lastlmdownpoint.SetPoint(0, 0);
88 else
90 m_lastlmdowntime = pMsg->time;
91 m_lastlmdownpoint = pMsg->pt;
94 else if(pMsg->message == WM_LBUTTONDBLCLK)
96 m_lastlmdowntime = pMsg->time;
97 m_lastlmdownpoint = pMsg->pt;
101 if((pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONUP || pMsg->message == WM_MOUSEMOVE)
102 && fInteractiveVideo)
104 if(pMsg->message == WM_MOUSEMOVE)
106 pParent->PostMessage(pMsg->message, pMsg->wParam, MAKELPARAM(p.x, p.y));
109 if(fDblClick)
111 pParent->PostMessage(WM_LBUTTONDOWN, pMsg->wParam, MAKELPARAM(p.x, p.y));
112 pParent->PostMessage(WM_LBUTTONDBLCLK, pMsg->wParam, MAKELPARAM(p.x, p.y));
115 else
117 pParent->PostMessage(pMsg->message, pMsg->wParam, MAKELPARAM(p.x, p.y));
118 return TRUE;
122 return CWnd::PreTranslateMessage(pMsg);
125 void CChildView::SetVideoRect(CRect r)
127 m_vrect = r;
129 Invalidate();
132 void CChildView::LoadLogo()
134 AppSettings& s = AfxGetAppSettings();
136 CAutoLock cAutoLock(&m_csLogo);
138 m_logo.Destroy();
140 if(s.logoext)
142 if(AfxGetAppSettings().fXpOrBetter)
143 m_logo.Load(s.logofn);
144 else if(HANDLE h = LoadImage(NULL, s.logofn, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE))
145 m_logo.Attach((HBITMAP)h); // win9x bug: Inside Attach GetObject() will return all zeros in DIBSECTION and silly CImage uses that to init width, height, bpp, ... so we can't use CImage::Draw later
148 if(m_logo.IsNull())
150 m_logo.LoadFromResource(s.logoid);
151 // m_logo.LoadFromResource(AfxGetInstanceHandle(), s.logoid);
154 if(m_hWnd) Invalidate();
157 CSize CChildView::GetLogoSize()
159 CSize ret(0,0);
160 if(!m_logo.IsNull())
161 ret.SetSize(m_logo.GetWidth(), m_logo.GetHeight());
162 return ret;
165 IMPLEMENT_DYNAMIC(CChildView, CWnd)
167 BEGIN_MESSAGE_MAP(CChildView, CWnd)
168 //{{AFX_MSG_MAP(CChildView)
169 ON_WM_PAINT()
170 ON_WM_ERASEBKGND()
171 ON_WM_SIZE()
172 ON_WM_WINDOWPOSCHANGED()
173 ON_COMMAND_EX(ID_PLAY_PLAYPAUSE, OnPlayPlayPauseStop)
174 ON_COMMAND_EX(ID_PLAY_PLAY, OnPlayPlayPauseStop)
175 ON_COMMAND_EX(ID_PLAY_PAUSE, OnPlayPlayPauseStop)
176 ON_COMMAND_EX(ID_PLAY_STOP, OnPlayPlayPauseStop)
177 ON_WM_SETCURSOR()
178 ON_WM_NCCALCSIZE()
179 ON_WM_NCPAINT()
180 //}}AFX_MSG_MAP
181 END_MESSAGE_MAP()
184 /////////////////////////////////////////////////////////////////////////////
185 // CChildView message handlers
187 void CChildView::OnPaint()
189 CPaintDC dc(this); // device context for painting
191 ((CMainFrame*)GetParentFrame())->RepaintVideo();
193 // Do not call CWnd::OnPaint() for painting messages
196 BOOL CChildView::OnEraseBkgnd(CDC* pDC)
198 CRect r;
200 CAutoLock cAutoLock(&m_csLogo);
202 if(((CMainFrame*)GetParentFrame())->IsSomethingLoaded())
204 pDC->ExcludeClipRect(m_vrect);
206 else if(!m_logo.IsNull() /*&& ((CMainFrame*)GetParentFrame())->IsPlaylistEmpty()*/)
208 BITMAP bm;
209 GetObject(m_logo, sizeof(bm), &bm);
211 GetClientRect(r);
212 int w = min(bm.bmWidth, r.Width());
213 int h = min(abs(bm.bmHeight), r.Height());
214 // int w = min(m_logo.GetWidth(), r.Width());
215 // int h = min(m_logo.GetHeight(), r.Height());
216 int x = (r.Width() - w) / 2;
217 int y = (r.Height() - h) / 2;
218 r = CRect(CPoint(x, y), CSize(w, h));
220 int oldmode = pDC->SetStretchBltMode(STRETCH_HALFTONE);
221 m_logo.StretchBlt(*pDC, r, CRect(0,0,bm.bmWidth,abs(bm.bmHeight)));
222 // m_logo.Draw(*pDC, r);
223 pDC->SetStretchBltMode(oldmode);
225 pDC->ExcludeClipRect(r);
228 GetClientRect(r);
229 pDC->FillSolidRect(r, 0);
231 return TRUE;
234 void CChildView::OnSize(UINT nType, int cx, int cy)
236 CWnd::OnSize(nType, cx, cy);
238 ((CMainFrame*)GetParentFrame())->MoveVideoWindow();
241 void CChildView::OnWindowPosChanged(WINDOWPOS* lpwndpos)
243 CWnd::OnWindowPosChanged(lpwndpos);
245 ((CMainFrame*)GetParentFrame())->MoveVideoWindow();
248 BOOL CChildView::OnPlayPlayPauseStop(UINT nID)
250 if(nID == ID_PLAY_STOP) SetVideoRect();
251 return FALSE;
254 BOOL CChildView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
256 if(((CMainFrame*)GetParentFrame())->m_fHideCursor)
258 SetCursor(NULL);
259 return TRUE;
262 return CWnd::OnSetCursor(pWnd, nHitTest, message);
265 void CChildView::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
267 if(!((CMainFrame*)GetParentFrame())->IsFrameLessWindow())
269 InflateRect(&lpncsp->rgrc[0], -1, -1);
272 CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
275 void CChildView::OnNcPaint()
277 if(!((CMainFrame*)GetParentFrame())->IsFrameLessWindow())
279 CRect r;
280 GetWindowRect(r);
281 r.OffsetRect(-r.left, -r.top);
283 CWindowDC(this).Draw3dRect(&r, GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHILIGHT));