Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactor picture rotating

The new implementation supports both rotating by fixed angles of +90 degree
(used for remote controls) and rotating by an arbitrary angle which makes
rotating with touch gestures much more intuitive. Nothing changes for zooming
by fixed angles. For rotating by an arbitrary factor every rotation must start
by sending the ACTION_GESTURE_BEGIN action and end by sending the
ACTION_GESTURE_END action. In between the ACTION_GESTURE_ROTATE can be sent
containing an arbitrary floating-point angle (in degrees) to perform rotation
actions.
  • Loading branch information...
commit b6f611d7545a115861c936565ef54ceb6d5d7392 1 parent 76f8c0c
Sascha Montellese authored
25 xbmc/pictures/GUIWindowSlideShow.cpp
@@ -170,7 +170,8 @@ void CGUIWindowSlideShow::Reset()
170 170 m_Image[1].UnLoad();
171 171 m_Image[1].Close();
172 172
173   - m_iRotate = 0;
  173 + m_fRotate = 0.0f;
  174 + m_fInitialRotate = 0.0f;
174 175 m_iZoomFactor = 1;
175 176 m_fZoom = 1.0f;
176 177 m_fInitialZoom = 0.0f;
@@ -478,7 +479,7 @@ void CGUIWindowSlideShow::Process(unsigned int currentTime, CDirtyRegionList &re
478 479 m_iNextSlide = GetNextSlide();
479 480
480 481 // m_iZoomFactor = 1;
481   - m_iRotate = 0;
  482 + m_fRotate = 0.0f;
482 483 }
483 484
484 485 if (m_Image[m_iCurrentPic].IsLoaded())
@@ -523,6 +524,7 @@ EVENT_RESULT CGUIWindowSlideShow::OnMouseEvent(const CPoint &point, const CMouse
523 524 {
524 525 m_firstGesturePoint = point;
525 526 m_fInitialZoom = m_fZoom;
  527 + m_fInitialRotate = m_fRotate;
526 528 return EVENT_RESULT_HANDLED;
527 529 }
528 530 else if (event.m_id == ACTION_GESTURE_PAN)
@@ -549,6 +551,7 @@ EVENT_RESULT CGUIWindowSlideShow::OnMouseEvent(const CPoint &point, const CMouse
549 551 else if (event.m_id == ACTION_GESTURE_END)
550 552 {
551 553 m_fInitialZoom = 0.0f;
  554 + m_fInitialRotate = 0.0f;
552 555 return EVENT_RESULT_HANDLED;
553 556 }
554 557 else if (event.m_id == ACTION_GESTURE_ZOOM)
@@ -556,6 +559,11 @@ EVENT_RESULT CGUIWindowSlideShow::OnMouseEvent(const CPoint &point, const CMouse
556 559 ZoomRelative(m_fInitialZoom * event.m_offsetX, true);
557 560 return EVENT_RESULT_HANDLED;
558 561 }
  562 + else if (event.m_id == ACTION_GESTURE_ROTATE)
  563 + {
  564 + RotateRelative(m_fInitialRotate + event.m_offsetX - m_fRotate, true);
  565 + return EVENT_RESULT_HANDLED;
  566 + }
559 567 return EVENT_RESULT_UNHANDLED;
560 568 }
561 569
@@ -800,8 +808,17 @@ void CGUIWindowSlideShow::RenderPause()
800 808
801 809 void CGUIWindowSlideShow::Rotate()
802 810 {
803   - if (!m_Image[m_iCurrentPic].DrawNextImage() && m_iZoomFactor == 1)
804   - m_Image[m_iCurrentPic].Rotate(++m_iRotate);
  811 + RotateRelative(90.0f);
  812 +}
  813 +
  814 +void CGUIWindowSlideShow::RotateRelative(float fAngle, bool immediate /* = false */)
  815 +{
  816 + if (m_Image[m_iCurrentPic].DrawNextImage() || m_fZoom > 1.0f)
  817 + return;
  818 +
  819 + m_fRotate += fAngle;
  820 +
  821 + m_Image[m_iCurrentPic].Rotate(fAngle, immediate);
805 822 }
806 823
807 824 void CGUIWindowSlideShow::Zoom(int iZoom)
4 xbmc/pictures/GUIWindowSlideShow.h
@@ -103,6 +103,7 @@ class CGUIWindowSlideShow : public CGUIWindow
103 103 void RenderPause();
104 104 void RenderErrorMessage();
105 105 void Rotate();
  106 + void RotateRelative(float fAngle, bool immediate = false);
106 107 void Zoom(int iZoom);
107 108 void ZoomRelative(float fZoom, bool immediate = false);
108 109 void Move(float fX, float fY);
@@ -112,7 +113,8 @@ class CGUIWindowSlideShow : public CGUIWindow
112 113 int m_iCurrentSlide;
113 114 int m_iNextSlide;
114 115 int m_iDirection;
115   - int m_iRotate;
  116 + float m_fRotate;
  117 + float m_fInitialRotate;
116 118 int m_iZoomFactor;
117 119 float m_fZoom;
118 120 float m_fInitialZoom;
46 xbmc/pictures/SlideShowPicture.cpp
@@ -103,18 +103,18 @@ void CSlideShowPic::SetTexture(int iSlideNumber, CBaseTexture* pTexture, DISPLAY
103 103 m_transistionTemp.type = TRANSISTION_NONE;
104 104 m_fTransistionAngle = 0;
105 105 m_fTransistionZoom = 0;
106   - m_fAngle = 0;
  106 + m_fAngle = 0.0f;
107 107 if (pTexture->GetOrientation() == 7)
108 108 { // rotate to 270 degrees
109   - m_fAngle = 3.0f;
  109 + m_fAngle = 270.0f;
110 110 }
111 111 if (pTexture->GetOrientation() == 2)
112 112 { // rotate to 180 degrees
113   - m_fAngle = 2.0f;
  113 + m_fAngle = 180.0f;
114 114 }
115 115 if (pTexture->GetOrientation() == 5)
116 116 { // rotate to 90 degrees
117   - m_fAngle = 1.0f;
  117 + m_fAngle = 90.0f;
118 118 }
119 119 m_fZoomAmount = 1;
120 120 m_fZoomLeft = 0;
@@ -159,7 +159,7 @@ void CSlideShowPic::SetOriginalSize(int iOriginalWidth, int iOriginalHeight, boo
159 159
160 160 int CSlideShowPic::GetOriginalWidth()
161 161 {
162   - int iAngle = (int)(m_fAngle + 0.4f);
  162 + int iAngle = (int)(m_fAngle / 90.0f + 0.4f);
163 163 if (iAngle % 2)
164 164 return m_iOriginalHeight;
165 165 else
@@ -168,7 +168,7 @@ int CSlideShowPic::GetOriginalWidth()
168 168
169 169 int CSlideShowPic::GetOriginalHeight()
170 170 {
171   - int iAngle = (int)(m_fAngle + 0.4f);
  171 + int iAngle = (int)(m_fAngle / 90.0f + 0.4f);
172 172 if (iAngle % 2)
173 173 return m_iOriginalWidth;
174 174 else
@@ -253,22 +253,23 @@ void CSlideShowPic::Process(unsigned int currentTime, CDirtyRegionList &dirtyreg
253 253 m_fZoomAmount = zoomamount[i];
254 254 m_bNoEffect = (m_fZoomAmount != 1.0f); // turn effect rendering back on.
255 255 }
256   - if (m_transistionTemp.type == TRANSISTION_ROTATE)
257   - { // round to nearest integer for accuracy purposes
258   - m_fAngle = floor(m_fAngle + 0.4f);
259   - }
  256 + /* not really needed anymore as we support arbitrary rotations
  257 + else if (m_transistionTemp.type == TRANSISTION_ROTATE)
  258 + { // round to nearest of 0, 90, 180 and 270
  259 + float reminder = fmodf(m_fAngle, 90.0f);
  260 + if (reminder < 45.0f)
  261 + m_fAngle -= reminder;
  262 + else
  263 + m_fAngle += 90.0f - reminder;
  264 + }*/
260 265 m_transistionTemp.type = TRANSISTION_NONE;
261 266 }
262 267 else
263 268 {
264 269 if (m_transistionTemp.type == TRANSISTION_ROTATE)
265   - {
266 270 m_fAngle += m_fTransistionAngle;
267   - }
268 271 if (m_transistionTemp.type == TRANSISTION_ZOOM)
269   - {
270 272 m_fZoomAmount += m_fTransistionZoom;
271   - }
272 273 }
273 274 }
274 275 }
@@ -367,8 +368,8 @@ void CSlideShowPic::Process(unsigned int currentTime, CDirtyRegionList &dirtyreg
367 368 // Rotate the image as needed
368 369 float x[4];
369 370 float y[4];
370   - float si = (float)sin(m_fAngle * M_PI * 0.5);
371   - float co = (float)cos(m_fAngle * M_PI * 0.5);
  371 + float si = (float)sin(m_fAngle / 180.0f * M_PI);
  372 + float co = (float)cos(m_fAngle / 180.0f * M_PI);
372 373 x[0] = -m_fWidth * co + m_fHeight * si;
373 374 y[0] = -m_fWidth * si - m_fHeight * co;
374 375 x[1] = m_fWidth * co + m_fHeight * si;
@@ -602,14 +603,19 @@ void CSlideShowPic::SetTransistionTime(int iType, int iTime)
602 603 m_transistionEnd.length = iTime;
603 604 }
604 605
605   -void CSlideShowPic::Rotate(int iRotate)
  606 +void CSlideShowPic::Rotate(float fRotateAngle, bool immediate /* = false */)
606 607 {
607   - if (m_bDrawNextImage) return ;
608   - if (m_transistionTemp.type == TRANSISTION_ZOOM) return ;
  608 + if (m_bDrawNextImage) return;
  609 + if (m_transistionTemp.type == TRANSISTION_ZOOM) return;
  610 + if (immediate)
  611 + {
  612 + m_fAngle += fRotateAngle;
  613 + return;
  614 + }
609 615 m_transistionTemp.type = TRANSISTION_ROTATE;
610 616 m_transistionTemp.start = m_iCounter;
611 617 m_transistionTemp.length = IMMEDIATE_TRANSISTION_TIME;
612   - m_fTransistionAngle = (float)(iRotate - m_fAngle) / (float)m_transistionTemp.length;
  618 + m_fTransistionAngle = (float)fRotateAngle / (float)m_transistionTemp.length;
613 619 // reset the timer
614 620 m_transistionEnd.start = m_iCounter + m_transistionStart.length + (int)(g_graphicsContext.GetFPS() * g_guiSettings.GetInt("slideshow.staytime"));
615 621 }
2  xbmc/pictures/SlideShowPicture.h
@@ -67,7 +67,7 @@ class CSlideShowPic
67 67 int SlideNumber() const { return m_iSlideNumber;};
68 68
69 69 void Zoom(float fZoomAmount, bool immediate = false);
70   - void Rotate(int iRotateAmount);
  70 + void Rotate(float fRotateAngle, bool immediate = false);
71 71 void Pause(bool bPause);
72 72 void SetInSlideshow(bool slideshow);
73 73 void SetOriginalSize(int iOriginalWidth, int iOriginalHeight, bool bFullSize);

0 comments on commit b6f611d

Please sign in to comment.
Something went wrong with that request. Please try again.