17.9.3 电子相册浏览模块的设计与实现(7)
所以对于封面翻页所需求的是页面2与页面1的路径,而左翻页到封底所需求的是页面2与页封底的路径。
- 01 if(m_turnType == type_head || m_turnType == type_rightToend)
- 02 {
- 03 GraphicsPath gpLeft,gpRight;
- 04 int undersideOffset = width;
- 05 if(m_turnType == type_head) //封面翻页求页面2的路径
- 06 {
- 07 if(calculated_y < height) //三角形时页面2的路径
- 08 {
- 09 gpLeft.AddLine( PointF(abs(width - m_x + undersideOffset), height),
- 10 PointF(width + undersideOffset, height));
- 11 gpLeft.AddLine( PointF(width + undersideOffset, height),
- 12 PointF(width + undersideOffset, (height –
- 13 (float)calculated_y)));
- 14 }
- 15 else //梯形时页面2的路径
- 16 {
- 17 gpLeft.AddLine(PointF(abs(width - m_x + undersideOffset), height),
- 18 PointF(width + undersideOffset, height));
- 19 gpLeft.AddLine(PointF(width + undersideOffset, height),
- 20 PointF(width + undersideOffset, 0));
- 21 //绘制对称线
- 22 calculated_x = height / tan(radians);
- 23 gpLeft.AddLine( PointF(width + undersideOffset, 0),
- 24 PointF(abs(width - (m_x - (float)calculated_x) +
- 25 undersideOffset), 0));
- 26 }
- 27 gpLeft.CloseFigure();
- 28 Matrix PathTranslationMatrix;
- 29 PathTranslationMatrix.Translate((float)m_photoFrameLeft,
- 30 (float)m_photoFrameTop);
- 31 gpLeft.Transform(&PathTranslationMatrix); //原点平移
- 32 Region oldRegion;
- 33 g.GetClip(&oldRegion);
- 34 g.SetClip(&gpLeft); //添加路径
- 35 g.DrawPath(&penDraw,&gpLeft); //绘制边框
- 36 g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[1]->
- GetWidth(),
- 37 m_photoFrameTop,m_pPage[1]->GetWidth(),
- 38 m_pPage[1]->GetHeight()); //绘制页面2
- 39 g.SetClip(&oldRegion); //恢复原属性
- 40 }
- 41 else //右翻页到封底时求页面2的路径
- 42 {
- 43 if(calculated_y < height) //三角形时页面2的路径
- 44 {
- 45 gpLeft.AddLine( PointF(width , 0), PointF( width , height) );
- 46 gpLeft.AddLine( PointF( width , height),
- 47 PointF(abs(width - m_x + undersideOffset),
- height));
- 48 gpLeft.AddLine( PointF(abs(width - m_x + undersideOffset),
- height),
- 49 PointF(width + undersideOffset,
- 50 (height - (float)calculated_y)));
- 51 gpLeft.AddLine( PointF(width + undersideOffset,
- 52 (height - (float)calculated_y)),
- 53 PointF(width + undersideOffset, 0));
- 54 }
- 55 else //梯形时页面2的路径
- 56 {
- 57 gpLeft.AddLine(PointF(width, 0),PointF( width , height));
- 58 gpLeft.AddLine(PointF( width , height) ,
- 59 PointF(abs(width - m_x + undersideOffset),
- height));
- 60
- 61 calculated_x = height / tan(radians);
- 62 gpLeft.AddLine( PointF(abs(width - m_x + undersideOffset), height),
- 63 PointF(abs(width - (m_x - (float)calculated_x)+
- 64 undersideOffset), 0));
- 65 }
- 66 gpLeft.CloseFigure();
- 67 Matrix PathTranslationMatrix;
- 68 PathTranslationMatrix.Translate((float)m_photoFrameLeft,
- 69 (float)m_photoFrameTop);
- 70 gpLeft.Transform(&PathTranslationMatrix); //平移坐标原点
- 71 Region oldRegion;
- 72 g.GetClip(&oldRegion); //保存原属性
- 73 g.SetClip(&gpLeft); //添加路径
- 74 g.DrawPath(&penDraw,&gpLeft); //绘制边框
- 75 g.DrawImage(m_pPage[1],m_photoFrameLeft + m_pPage[1]->
- GetWidth(),
- 76 m_photoFrameTop,m_pPage[1]->GetWidth(),
- 77 m_pPage[1]->GetHeight()); //绘制界面2
- 78 g.SetClip(&oldRegion); //恢复原属性
- 79 }
- 80 //创建临时画板
- 81 Bitmap pageUndersideImage(width,height);
- 82 undersideOffset = width;
- 83 if(calculated_y < height) //三角形时旋转区域大小
- 84 {
- 85 gpRight.AddLine( PointF(abs(width - m_x - undersideOffset),
- height),
- 86 PointF(width - undersideOffset, height));
- 87 gpRight.AddLine( PointF(width - undersideOffset, height),
- 88 PointF(width - undersideOffset, (height - (float)
- calculated_y)));
- 89 }
- 90 else //梯形时旋转区域大小
- 91 {
- 92 gpRight.AddLine(PointF(abs(float(width) - m_x – underside-
- Offset),height),
- 93 PointF(width - undersideOffset, height));
- 94 gpRight.AddLine(PointF(width - undersideOffset, height),
- 95 PointF(width - undersideOffset, 0));
- 96
- 97 calculated_x = height / tan(radians);
- 98 gpRight.AddLine( PointF(width - undersideOffset, 0),
- 99 PointF(abs(width - (m_x - (float)calculated_x) –
- 00 undersideOffset), 0));
- 101 }
- 102 Graphics ug(&pageUndersideImage);
- 103 ug.SetClip(&gpRight);
- 104 ug.DrawPath(&penDraw,&gpRight); //添加路径
- 105 if(m_turnType == type_rightToend) //右翻页到封底时绘制封底
- 106 {
- 107 ug.DrawImage(m_pPage[5], 0,0,m_pPage[1]->GetWidth(),
- 108 m_pPage[1]->GetHeight());
- 109 Matrix PathTranslationMatrix1;
- 110 PathTranslationMatrix1.Translate(m_photoFrameLeft +
- 111 m_pPage[1]->GetWidth()*2 - m_x,
- 112 m_photoFrameTop +
- 113 m_pPage[1]->GetHeight());
- 114 PathTranslationMatrix1.Rotate((float)(pageUndersideRotation-
- Angle ));
- 115 g.SetTransform(&PathTranslationMatrix1); //平移原点
- 116 g.DrawImage(&pageUndersideImage, -int(m_x),-height ,width,
- height );
- 117 }
- 118 else //首页翻页绘制图像1
- 119 {
- 120 ug.DrawImage(m_pPage[0], 0,0,m_pPage[1]->GetWidth(),
- 121 m_pPage[1]->GetHeight());
- 122 Matrix PathTranslationMatrix1;
- 123 PathTranslationMatrix1.Translate(m_photoFrameLeft +
- 124 m_pPage[1]->GetWidth()*2 -
- 125 m_x, m_photoFrameTop +
- 126 m_pPage[1]->GetHeight());
- 127 PathTranslationMatrix1.Rotate((float)(pageUndersideRotation-
- Angle ));
- 128 g.SetTransform(&PathTranslationMatrix1); //平移原点
- 129 g.DrawImage(&pageUndersideImage, -int(m_x),-height ,width,
- height );
- 130 }
- 131 }