A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / apps / mplayerc / PnSPresetsDlg.cpp
blobae203595c456c9d47c7cccfb886b8ef48a8cb856
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 // PnSPresetsDlg.cpp : implementation file
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "PnSPresetsDlg.h"
30 // CPnSPresetsDlg dialog
32 IMPLEMENT_DYNAMIC(CPnSPresetsDlg, CCmdUIDialog)
33 CPnSPresetsDlg::CPnSPresetsDlg(CWnd* pParent /*=NULL*/)
34 : CCmdUIDialog(CPnSPresetsDlg::IDD, pParent)
35 , m_label(_T(""))
39 CPnSPresetsDlg::~CPnSPresetsDlg()
43 void CPnSPresetsDlg::DoDataExchange(CDataExchange* pDX)
45 __super::DoDataExchange(pDX);
46 DDX_Control(pDX, IDC_EDIT2, m_PosX);
47 DDX_Control(pDX, IDC_EDIT3, m_PosY);
48 DDX_Control(pDX, IDC_EDIT4, m_ZoomX);
49 DDX_Control(pDX, IDC_EDIT5, m_ZoomY);
50 DDX_Text(pDX, IDC_EDIT1, m_label);
51 DDX_Control(pDX, IDC_LIST1, m_list);
54 BOOL CPnSPresetsDlg::OnInitDialog()
56 __super::OnInitDialog();
58 for(int i = 0, j = m_pnspresets.GetCount(); i < j; i++)
60 CString label;
61 double PosX, PosY, ZoomX, ZoomY;
62 StringToParams(m_pnspresets[i], label, PosX, PosY, ZoomX, ZoomY);
64 m_list.AddString(label);
66 if(i == 0)
68 m_list.SetCurSel(0);
69 OnLbnSelchangeList1();
73 return TRUE; // return TRUE unless you set the focus to a control
74 // EXCEPTION: OCX Property Pages should return FALSE
78 void CPnSPresetsDlg::StringToParams(CString str, CString& label, double& PosX, double& PosY, double& ZoomX, double& ZoomY)
80 int i = 0, j = 0;
82 for(CString token = str.Tokenize(_T(","), i); !token.IsEmpty(); token = str.Tokenize(_T(","), i), j++)
84 if(j == 0)
86 label = token;
88 else
90 float f = 0;
91 if(_stscanf(token, _T("%f"), &f) != 1) continue;
93 switch(j)
95 case 1: PosX = f; break;
96 case 2: PosY = f; break;
97 case 3: ZoomX = f; break;
98 case 4: ZoomY = f; break;
99 default: break;
105 CString CPnSPresetsDlg::ParamsToString(CString label, double PosX, double PosY, double ZoomX, double ZoomY)
107 CString str;
108 str.Format(_T("%s,%.3f,%.3f,%.3f,%.3f"), label, PosX, PosY, ZoomX, ZoomY);
109 return(str);
112 BEGIN_MESSAGE_MAP(CPnSPresetsDlg, CCmdUIDialog)
113 ON_LBN_SELCHANGE(IDC_LIST1, OnLbnSelchangeList1)
114 ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
115 ON_UPDATE_COMMAND_UI(IDC_BUTTON2, OnUpdateButton2)
116 ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton6)
117 ON_UPDATE_COMMAND_UI(IDC_BUTTON3, OnUpdateButton6)
118 ON_BN_CLICKED(IDC_BUTTON4, OnBnClickedButton9)
119 ON_UPDATE_COMMAND_UI(IDC_BUTTON4, OnUpdateButton9)
120 ON_BN_CLICKED(IDC_BUTTON5, OnBnClickedButton10)
121 ON_UPDATE_COMMAND_UI(IDC_BUTTON5, OnUpdateButton10)
122 ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
123 ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateButton1)
124 END_MESSAGE_MAP()
127 // CPnSPresetsDlg message handlers
128 void CPnSPresetsDlg::OnLbnSelchangeList1()
130 int i = m_list.GetCurSel();
131 if(i >= 0 && i < m_pnspresets.GetCount())
133 double PosX, PosY, ZoomX, ZoomY;
134 StringToParams(m_pnspresets[i], m_label, PosX, PosY, ZoomX, ZoomY);
135 m_PosX = PosX; m_PosY = PosY;
136 m_ZoomX = ZoomX; m_ZoomY = ZoomY;
138 else
140 m_label.Empty();
141 m_PosX.SetWindowText(_T(""));
142 m_PosY.SetWindowText(_T(""));
143 m_ZoomX.SetWindowText(_T(""));
144 m_ZoomY.SetWindowText(_T(""));
147 UpdateData(FALSE);
150 void CPnSPresetsDlg::OnBnClickedButton2() // new
152 m_pnspresets.Add(_T("New,0.5,0.5,1.0,1.0"));
153 m_list.SetCurSel(m_list.AddString(_T("New")));
154 OnLbnSelchangeList1();
157 void CPnSPresetsDlg::OnUpdateButton2(CCmdUI* pCmdUI)
159 CString str;
160 int len = m_list.GetCount();
161 if(len > 0) m_list.GetText(len-1, str);
162 pCmdUI->Enable(str != _T("New"));
165 void CPnSPresetsDlg::OnBnClickedButton6() // del
167 int i = m_list.GetCurSel();
168 m_list.DeleteString(i);
169 m_pnspresets.RemoveAt(i);
170 if(i == m_list.GetCount()) i--;
171 m_list.SetCurSel(i);
172 OnLbnSelchangeList1();
175 void CPnSPresetsDlg::OnUpdateButton6(CCmdUI* pCmdUI)
177 pCmdUI->Enable(m_list.GetCurSel() >= 0);
180 void CPnSPresetsDlg::OnBnClickedButton9() // up
182 int i = m_list.GetCurSel();
183 CString str, str2;
184 m_list.GetText(i, str);
185 str2 = m_pnspresets.GetAt(i);
186 m_list.DeleteString(i);
187 m_pnspresets.RemoveAt(i);
188 i--;
189 m_list.InsertString(i, str);
190 m_pnspresets.InsertAt(i, str2);
191 m_list.SetCurSel(i);
194 void CPnSPresetsDlg::OnUpdateButton9(CCmdUI* pCmdUI)
196 pCmdUI->Enable(m_list.GetCurSel() > 0 && m_list.GetCurSel() < m_list.GetCount());
199 void CPnSPresetsDlg::OnBnClickedButton10() // down
201 int i = m_list.GetCurSel();
202 CString str, str2;
203 m_list.GetText(i, str);
204 str2 = m_pnspresets.GetAt(i);
205 m_list.DeleteString(i);
206 m_pnspresets.RemoveAt(i);
207 i++;
208 m_list.InsertString(i, str);
209 m_pnspresets.InsertAt(i, str2);
210 m_list.SetCurSel(i);
213 void CPnSPresetsDlg::OnUpdateButton10(CCmdUI* pCmdUI)
215 pCmdUI->Enable(m_list.GetCurSel() >= 0 && m_list.GetCurSel() < m_list.GetCount()-1);
218 void CPnSPresetsDlg::OnBnClickedButton1() // set
220 int i = m_list.GetCurSel();
221 UpdateData();
222 if(m_label.Remove(',') > 0)
223 UpdateData(FALSE);
224 m_pnspresets[i] = ParamsToString(m_label, m_PosX, m_PosY, m_ZoomX, m_ZoomY);
225 m_list.DeleteString(i);
226 m_list.InsertString(i, m_label);
227 m_list.SetCurSel(i);
230 void CPnSPresetsDlg::OnUpdateButton1(CCmdUI* pCmdUI)
232 UpdateData();
233 pCmdUI->Enable(m_list.GetCurSel() >= 0
234 && !m_label.IsEmpty() && m_label.Find(',') < 0
235 && m_PosX >= 0 && m_PosX <= 1
236 && m_PosY >= 0 && m_PosY <= 1
237 && m_ZoomX >= 0.2 && m_ZoomX <= 3.0
238 && m_ZoomY >= 0.2 && m_ZoomY <= 3.0);
241 void CPnSPresetsDlg::OnOK()
243 if(m_list.GetCurSel() >= 0)
244 OnBnClickedButton1();
246 __super::OnOK();