设为首页 加入收藏

TOP

17.9.3 电子相册浏览模块的设计与实现(5)
2013-10-07 14:39:49 来源: 作者: 【 】 浏览:43
Tags:17.9.3 电子相册 浏览 模块 设计 实现

17.9.3  电子相册浏览模块的设计与实现(5)

第7行所定义的区域是相册的区域。

(7)重载对话框的OnPanit()函数。

  1. void CMyBookDlg::OnPaint()   
  2. {  
  3.     CPaintDC dc(this);   
  4.     if(m_turnType == type_left || m_turnType == type_endToleft)  
  5.     {  
  6.         LeftTurn();                 //左侧翻页  
  7.     }  
  8.     else if(m_turnType == type_right || m_turnType == type_headToright)  
  9.     {  
  10.         RightTurn();                //右侧翻页  
  11.     }  
  12.     else  
  13.     {  
  14.         DrawBothEnds();             //封底或封面  
  15.     }  
  16.     //将内存设备内的内容复制到屏幕上  
  17.     dc.BitBlt(0,0,m_bkRect.Width(),m_bkRect.Height(),&dcMemory,0,0,SRCCO    PY);  
  18. }  

【代码解析】

根据当前的翻页状态决定下一步的翻页动作。当前状态为左侧翻页或为封底到左侧翻页时,将进行左侧翻页,为右侧翻页或为封面到右侧翻页时将进行右侧翻页,否则进行两侧的翻页动作。

(8)函数RightTurn()实现右侧翻页的功能,在前面已经讲过。LeftTurn()实现左侧翻页的功能,实现过程与RightTurn()类似。DrawBothEnds()函数实现封面、封底参与的翻页过程。共分4种情况:封面到右侧翻页;左侧翻页到封面;封底到左侧翻页;右侧翻页到封底。

下面分步讲解DrawBothEnds()函数。

① 变量的定义与计算

  1. 01      Graphics g(dcMemory.m_hDC);  
  2. 02      Image bk_image(L"背景\\bg002.bmp");  
  3. 03      //绘制背景图像  
  4. 04      g.DrawImage(&bk_image,m_bkRect.left,m_bkRect.top,  
  5. 05                      m_bkRect.Width(),m_bkRect.Height());  
  6. 06      Color clrPen(255,0,0,0);                            //画笔颜色  
  7. 07      Pen penDraw(clrPen,1 );                             //画笔  
  8. 08      SolidBrush solidBrush(Color(255, 255, 255, 255));   //画刷  
  9. 09      double a = 45 + ((45 * m_x) /(m_pPage[0]->GetWidth()));  
  10.                                                             //对称线角度  
  11. 10      double radians = a * (PI / 180.0);  
  12. 11      double pageUndersideRotationAngle =  (180 - (2 * a));  
  13.                                                             //区域3旋转角度  
  14. 12      double calculated_y = 0;  
  15. 13      double calculated_x = 0;  
  16. 14      calculated_y = (m_x)* (tan(radians));               //h(见图17.21)  
  17. 15      int width = m_pPage[5]->GetWidth();             //width  
  18. 16      int height = m_pPage[5]->GetHeight();               //height  

【代码解析】

这一部分同RightTurn()函数的第1~5行绘制背景图像。第6~8行定义下面需要的画笔与画刷。第10、11行计算对称线的角度及区域3旋转的角度。第14行计算h。第15、16行计算页图像的高度与宽度。

② 翻页完成时的处理

  1. 01      if (m_x >= width)  
  2. 02      {  
  3. 03          m_x = 0;                                    //初始化m_x  
  4. 04          if(m_turnType == type_head ||m_turnType == type_end)  
  5. 05          {   //初始化页面1及页面2  
  6. 06              g.DrawImage(m_pPage[0],m_photoFrameLeft,m_photoFrameTop,  
  7. 07                          m_pPage[0]->GetWidth(),m_pPage[0]->GetHei-  
  8.                             ght());  
  9. 08              g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[0]->Get  
  10.                 Width(),  
  11. 09                          m_photoFrameTop,m_pPage[1]->GetWidth(),  
  12. 10                          m_pPage[1]->GetHeight());  
  13. 11              if(m_turnType == type_head)             //封面到右侧翻页  
  14. 12              {  
  15. 13                  m_turnType = type_headToright;  
  16. 14                  PostMessage(WM_MY_TURN,0,0);        //发送换页消息  
  17. 15              }  
  18. 16              else  
  19. 17              {  
  20. 18                  m_turnType = type_endToleft;        //封底到左侧翻页  
  21. 19                  PostMessage(WM_MY_TURN,0,0);        //发送换页消息  
  22. 20              }  
  23. 21          }  
  24. 22          else if(m_turnType == type_leftTohead)      //左侧翻页到封面  
  25. 23          {   //只绘制封面即可  
  26. 24              g.DrawImage(m_pPage[4],m_photoFrameLeft + m_pPage[0]-> 
  27.                 GetWidth(),  
  28. 25                              m_photoFrameTop,m_pPage[1]->GetWidth(),  
  29. 26                              m_pPage[1]->GetHeight());  
  30. 27              m_turnType = type_head;                 //修改翻页类型  
  31. 28          }  
  32. 29          else if(m_turnType == type_rightToend)      //右侧翻页到封底  
  33. 30          {   //只绘制封底即可  
  34. 31              g.DrawImage(m_pPage[5],m_photoFrameLeft,m_photoFrameTop,  
  35. 32                          m_pPage[0]->GetWidth(),m_pPage[0]-> 
  36.                             GetHeight());  
  37. 33              m_turnType = type_end;                  //修改翻页类型  
  38. 34          }  
  39. 35          if(m_bTOnce)  
  40. 36              m_bTOnce =false;                        //结束一次性翻页  
  41. 37      }  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇17.9.3 电子相册浏览模块的设计与.. 下一篇17.9.3 电子相册浏览模块的设计与..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: