HStrokeEditDlg.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // HStrokeEditDlg.cpp : implementation file
  2. // Download by http://www.codefans.net
  3. #include "stdafx.h"
  4. #include "HDraw.h"
  5. #include "HStrokeEditDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // HStrokeEditDlg dialog
  13. HStrokeEditDlg::HStrokeEditDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(HStrokeEditDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(HStrokeEditDlg)
  17. //}}AFX_DATA_INIT
  18. }
  19. void HStrokeEditDlg::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(HStrokeEditDlg)
  23. DDX_Control(pDX, IDC_BTN_COLOR, m_btnColor);
  24. DDX_Control(pDX, IDC_EDIT_WIDTH, m_editWidth);
  25. DDX_Control(pDX, IDC_LIST_STROKES, m_listStroke);
  26. DDX_Control(pDX, IDC_EDIT_STROKE, m_editStroke);
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(HStrokeEditDlg, CDialog)
  30. //{{AFX_MSG_MAP(HStrokeEditDlg)
  31. ON_LBN_SELCHANGE(IDC_LIST_STROKES, OnSelchangeListStrokes)
  32. ON_BN_CLICKED(IDC_BTN_UPDATE, OnBtnUpdate)
  33. ON_BN_CLICKED(IDC_BTN_DEL, OnBtnDel)
  34. ON_BN_CLICKED(IDC_BTN_COLOR, OnBtnColor)
  35. ON_WM_CTLCOLOR()
  36. ON_BN_CLICKED(ID_OK, OnOk)
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // HStrokeEditDlg message handlers
  41. BOOL HStrokeEditDlg::OnInitDialog()
  42. {
  43. CDialog::OnInitDialog();
  44. for(int i = 0; i < m_ptrStrokeList->GetSize(); i ++){
  45. m_listStroke.AddString(strokeInfo(m_ptrStrokeList->GetAt(i), i));
  46. }
  47. return TRUE; // return TRUE unless you set the focus to a control
  48. // EXCEPTION: OCX Property Pages should return FALSE
  49. }
  50. void HStrokeEditDlg::setStrokeList(CTypedPtrArray<CObArray, HStroke *> *p)
  51. {
  52. m_ptrStrokeList = p;
  53. }
  54. CString HStrokeEditDlg::strokeInfo(HStroke *stroke, int index)
  55. {
  56. CString info, result;
  57. switch (stroke->m_picType)
  58. {
  59. case PIC_line:
  60. info = "直线";
  61. break;
  62. case PIC_poly:
  63. info = "曲线";
  64. break;
  65. case PIC_rect:
  66. info = "矩形";
  67. break;
  68. case PIC_ellipse:
  69. info = "椭圆";
  70. break;
  71. case PIC_text:
  72. info = "文本";
  73. break;
  74. default:
  75. info = "错误";
  76. }
  77. result.Format("%s %d", info, index);
  78. return result;
  79. }
  80. void HStrokeEditDlg::OnSelchangeListStrokes()
  81. {
  82. // TODO: Add your control notification handler code here
  83. CString info, result;
  84. int i, index = m_listStroke.GetCurSel();
  85. HStroke *stroke = m_ptrStrokeList->ElementAt(index);
  86. //显示点集
  87. for(i = 0; i < stroke->m_points.GetSize(); i ++){
  88. info.Format(" [%d,%d]",
  89. stroke->m_points.GetAt(i).x,
  90. stroke->m_points.GetAt(i).y);
  91. result += info;
  92. }
  93. m_editStroke.SetWindowText(result);
  94. //显示颜色
  95. info.Format("%d", stroke->m_penWidth);
  96. //显示线宽
  97. m_editWidth.SetWindowText(info);
  98. //选中某个图形
  99. for(i = 0; i <m_ptrStrokeList->GetSize(); i ++)
  100. m_ptrStrokeList->GetAt(i)->m_bSelected = FALSE;
  101. m_ptrStrokeList->GetAt(index)->m_bSelected = TRUE;
  102. GetParent()->Invalidate();
  103. }
  104. void HStrokeEditDlg::OnBtnUpdate()
  105. {
  106. // TODO: Add your control notification handler code here
  107. int pos, index = m_listStroke.GetCurSel();
  108. CString info, strPoint;
  109. //修改线宽
  110. m_editWidth.GetWindowText(info);
  111. CString m_width = info;
  112. if(index == LB_ERR)
  113. return ;
  114. m_ptrStrokeList->ElementAt(index)->m_penWidth = atoi(m_width);
  115. m_editStroke.GetWindowText(info);
  116. CPoint point;
  117. //修改点集
  118. m_ptrStrokeList->ElementAt(index)->m_points.RemoveAll();
  119. while( (pos=info.Find("]")) != -1){
  120. strPoint = info.Left(pos);
  121. info = info.Right(info.GetLength() - strPoint.GetLength() - 1);
  122. point.x = atoi(strPoint.Mid(2, strPoint.Find(",")));
  123. point.y = atoi(strPoint.Mid(strPoint.Find(",")+1));
  124. m_ptrStrokeList->ElementAt(index)->m_points.Add(point);
  125. }
  126. GetParent()->Invalidate();
  127. }
  128. void HStrokeEditDlg::OnBtnDel()
  129. {
  130. // TODO: Add your control notification handler code here
  131. int index = m_listStroke.GetCurSel();
  132. //in condition of null selection
  133. if(LB_ERR == index)
  134. return ;
  135. //must delete this, otherwise there will be memory leak
  136. delete m_ptrStrokeList->ElementAt(index);
  137. //remove picture
  138. m_ptrStrokeList->RemoveAt(index);
  139. //refresh list
  140. m_listStroke.DeleteString(index);
  141. GetParentFrame()->Invalidate();
  142. }
  143. void HStrokeEditDlg::OnBtnColor()
  144. {
  145. // TODO: Add your control notification handler code here
  146. CColorDialog dlg;
  147. int curIndex = m_listStroke.GetCurSel();
  148. if(LB_ERR != curIndex){
  149. dlg.m_cc.Flags |= CC_RGBINIT;
  150. dlg.m_cc.rgbResult = m_ptrStrokeList->GetAt(curIndex)->m_penColor;
  151. }
  152. if(dlg.DoModal() == IDOK){
  153. if(curIndex != LB_ERR){
  154. m_ptrStrokeList->ElementAt(curIndex)->m_penColor = dlg.GetColor();
  155. Invalidate();
  156. }
  157. }
  158. }
  159. HBRUSH HStrokeEditDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  160. {
  161. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  162. // TODO: Change any attributes of the DC here
  163. int curIndex = m_listStroke.GetCurSel();
  164. if(curIndex != LB_ERR && pWnd->GetDlgCtrlID() == IDC_EDIT_WIDTH){
  165. pDC->SetTextColor(m_ptrStrokeList->ElementAt(curIndex)->m_penColor);
  166. }
  167. // TODO: Return a different brush if the default is not desired
  168. return hbr;
  169. }
  170. void HStrokeEditDlg::OnOk()
  171. {
  172. // TODO: Add your control notification handler code here
  173. CDialog::OnOK();
  174. }