Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[seekbar] adds seek handler rather than handling seeking directly in …

…CGUIDialogSeekBar.
  • Loading branch information...
commit 124b538fb92e104046fa50990751791c97da8ba3 1 parent d9ca8ee
authored January 18, 2012
6  XBMC-ATV2.xcodeproj/project.pbxproj
@@ -28,6 +28,7 @@
28 28
 		7C0A7FC913A9E75400AFC2BD /* DirtyRegionTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7FC613A9E75400AFC2BD /* DirtyRegionTracker.cpp */; };
29 29
 		7C0A7FCC13A9E76E00AFC2BD /* GUIWindowDebugInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7FCA13A9E76E00AFC2BD /* GUIWindowDebugInfo.cpp */; };
30 30
 		7C0B990A154B80200065A238 /* AEDeviceInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0B9908154B80200065A238 /* AEDeviceInfo.cpp */; };
  31
+		7C1A493D15A968BA004AF4A4 /* SeekHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1A493B15A968BA004AF4A4 /* SeekHandler.cpp */; };
31 32
 		7C1A89BB152671FB00C63311 /* TextureCacheJob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1A89B9152671FB00C63311 /* TextureCacheJob.cpp */; };
32 33
 		7C1D698B15A8142F00658B65 /* DatabaseManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1D698915A8142F00658B65 /* DatabaseManager.cpp */; };
33 34
 		7C1F6F8C13ED17CC001726AB /* LibraryDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1F6F8A13ED17CC001726AB /* LibraryDirectory.cpp */; };
@@ -1027,6 +1028,8 @@
1027 1028
 		7C0B9908154B80200065A238 /* AEDeviceInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AEDeviceInfo.cpp; sourceTree = "<group>"; };
1028 1029
 		7C0B9909154B80200065A238 /* AEDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AEDeviceInfo.h; sourceTree = "<group>"; };
1029 1030
 		7C1A494015A968D6004AF4A4 /* SaveFileStateJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaveFileStateJob.h; sourceTree = "<group>"; };
  1031
+		7C1A493B15A968BA004AF4A4 /* SeekHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SeekHandler.cpp; sourceTree = "<group>"; };
  1032
+		7C1A493C15A968BA004AF4A4 /* SeekHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SeekHandler.h; sourceTree = "<group>"; };
1030 1033
 		7C1A89B9152671FB00C63311 /* TextureCacheJob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextureCacheJob.cpp; sourceTree = "<group>"; };
1031 1034
 		7C1A89BA152671FB00C63311 /* TextureCacheJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextureCacheJob.h; sourceTree = "<group>"; };
1032 1035
 		7C1D698915A8142F00658B65 /* DatabaseManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DatabaseManager.cpp; sourceTree = "<group>"; };
@@ -5454,6 +5457,8 @@
5454 5457
 				F56C775F131EC154000AD0F6 /* ScraperParser.h */,
5455 5458
 				F56C7760131EC154000AD0F6 /* ScraperUrl.cpp */,
5456 5459
 				F56C7761131EC154000AD0F6 /* ScraperUrl.h */,
  5460
+				7C1A493B15A968BA004AF4A4 /* SeekHandler.cpp */,
  5461
+				7C1A493C15A968BA004AF4A4 /* SeekHandler.h */,
5457 5462
 				36A9445B15821FAB00727135 /* SortUtils.cpp */,
5458 5463
 				36A9445C15821FAB00727135 /* SortUtils.h */,
5459 5464
 				F56C7762131EC154000AD0F6 /* Splash.cpp */,
@@ -7233,6 +7238,7 @@
7233 7238
 				DF08E84515829BA600058C77 /* Exception.cpp in Sources */,
7234 7239
 				36A9465315AA269B00727135 /* DirectoryNodeTags.cpp in Sources */,
7235 7240
 				7C1D698B15A8142F00658B65 /* DatabaseManager.cpp in Sources */,
  7241
+				7C1A493D15A968BA004AF4A4 /* SeekHandler.cpp in Sources */,
7236 7242
 			);
7237 7243
 			runOnlyForDeploymentPostprocessing = 0;
7238 7244
 		};
6  XBMC-IOS.xcodeproj/project.pbxproj
@@ -29,6 +29,7 @@
29 29
 		7C0A7FB213A9E72E00AFC2BD /* DirtyRegionSolvers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7FAE13A9E72E00AFC2BD /* DirtyRegionSolvers.cpp */; };
30 30
 		7C0A7FB313A9E72E00AFC2BD /* DirtyRegionTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7FB013A9E72E00AFC2BD /* DirtyRegionTracker.cpp */; };
31 31
 		7C0B98F9154B7FF30065A238 /* AEDeviceInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0B98F7154B7FF30065A238 /* AEDeviceInfo.cpp */; };
  32
+		7C1A495315A968FB004AF4A4 /* SeekHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1A495115A968FB004AF4A4 /* SeekHandler.cpp */; };
32 33
 		7C1A89CE1526722200C63311 /* TextureCacheJob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1A89CC1526722200C63311 /* TextureCacheJob.cpp */; };
33 34
 		7C1D697815A8141000658B65 /* DatabaseManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1D697615A8141000658B65 /* DatabaseManager.cpp */; };
34 35
 		7C1F6F7A13ED178F001726AB /* LibraryDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1F6F7813ED178F001726AB /* LibraryDirectory.cpp */; };
@@ -1027,6 +1028,8 @@
1027 1028
 		7C0B98F7154B7FF30065A238 /* AEDeviceInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AEDeviceInfo.cpp; sourceTree = "<group>"; };
1028 1029
 		7C0B98F8154B7FF30065A238 /* AEDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AEDeviceInfo.h; sourceTree = "<group>"; };
1029 1030
 		7C1A495415A96908004AF4A4 /* SaveFileStateJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaveFileStateJob.h; sourceTree = "<group>"; };
  1031
+		7C1A495115A968FB004AF4A4 /* SeekHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SeekHandler.cpp; sourceTree = "<group>"; };
  1032
+		7C1A495215A968FB004AF4A4 /* SeekHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SeekHandler.h; sourceTree = "<group>"; };
1030 1033
 		7C1A89CC1526722200C63311 /* TextureCacheJob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextureCacheJob.cpp; sourceTree = "<group>"; };
1031 1034
 		7C1A89CD1526722200C63311 /* TextureCacheJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextureCacheJob.h; sourceTree = "<group>"; };
1032 1035
 		7C1D697615A8141000658B65 /* DatabaseManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DatabaseManager.cpp; sourceTree = "<group>"; };
@@ -5819,6 +5822,8 @@
5819 5822
 				F56C874E131F42EC000AD0F6 /* ScraperParser.h */,
5820 5823
 				F56C874F131F42EC000AD0F6 /* ScraperUrl.cpp */,
5821 5824
 				F56C8750131F42EC000AD0F6 /* ScraperUrl.h */,
  5825
+				7C1A495115A968FB004AF4A4 /* SeekHandler.cpp */,
  5826
+				7C1A495215A968FB004AF4A4 /* SeekHandler.h */,
5822 5827
 				36A9445015821F5300727135 /* SortUtils.cpp */,
5823 5828
 				36A9445115821F5300727135 /* SortUtils.h */,
5824 5829
 				F56C8751131F42EC000AD0F6 /* Splash.cpp */,
@@ -7244,6 +7249,7 @@
7244 7249
 				DFC3867E158296EC008AE277 /* Exception.cpp in Sources */,
7245 7250
 				36A9465B15AA26BC00727135 /* DirectoryNodeTags.cpp in Sources */,
7246 7251
 				7C1D697815A8141000658B65 /* DatabaseManager.cpp in Sources */,
  7252
+				7C1A495315A968FB004AF4A4 /* SeekHandler.cpp in Sources */,
7247 7253
 			);
7248 7254
 			runOnlyForDeploymentPostprocessing = 0;
7249 7255
 		};
6  XBMC.xcodeproj/project.pbxproj
@@ -258,6 +258,7 @@
258 258
 		43BF09AB1080D2ED00E25290 /* RdrConnectionManagerSCPD.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 43BF09A81080D2ED00E25290 /* RdrConnectionManagerSCPD.cpp */; };
259 259
 		7C0A7EC013A5DBCE00AFC2BD /* AppParamParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0A7EBE13A5DBCE00AFC2BD /* AppParamParser.cpp */; };
260 260
 		7C0B98A4154B79C30065A238 /* AEDeviceInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C0B98A1154B79C30065A238 /* AEDeviceInfo.cpp */; };
  261
+		7C1A492315A962EE004AF4A4 /* SeekHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1A492115A962EE004AF4A4 /* SeekHandler.cpp */; };
261 262
 		7C1A85661520522500C63311 /* TextureCacheJob.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1A85631520522500C63311 /* TextureCacheJob.cpp */; };
262 263
 		7C1D682915A7D2FD00658B65 /* DatabaseManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1D682715A7D2FD00658B65 /* DatabaseManager.cpp */; };
263 264
 		7C1F6EBB13ECCFA7001726AB /* LibraryDirectory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C1F6EB913ECCFA7001726AB /* LibraryDirectory.cpp */; };
@@ -1533,6 +1534,8 @@
1533 1534
 		7C0B98A1154B79C30065A238 /* AEDeviceInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AEDeviceInfo.cpp; sourceTree = "<group>"; };
1534 1535
 		7C0B98A2154B79C30065A238 /* AEDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AEDeviceInfo.h; sourceTree = "<group>"; };
1535 1536
 		7C1A495B15A96918004AF4A4 /* SaveFileStateJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SaveFileStateJob.h; sourceTree = "<group>"; };
  1537
+		7C1A492115A962EE004AF4A4 /* SeekHandler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SeekHandler.cpp; sourceTree = "<group>"; };
  1538
+		7C1A492215A962EE004AF4A4 /* SeekHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SeekHandler.h; sourceTree = "<group>"; };
1536 1539
 		7C1A85631520522500C63311 /* TextureCacheJob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextureCacheJob.cpp; sourceTree = "<group>"; };
1537 1540
 		7C1A85641520522500C63311 /* TextureCacheJob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextureCacheJob.h; sourceTree = "<group>"; };
1538 1541
 		7C1D682715A7D2FD00658B65 /* DatabaseManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DatabaseManager.cpp; sourceTree = "<group>"; };
@@ -5898,6 +5901,8 @@
5898 5901
 				E38E1E780D25F9FD00618676 /* ScraperParser.h */,
5899 5902
 				E36C29E70DA72486001F0C9D /* ScraperUrl.cpp */,
5900 5903
 				7CAA25381085971C0096DE39 /* ScraperUrl.h */,
  5904
+				7C1A492115A962EE004AF4A4 /* SeekHandler.cpp */,
  5905
+				7C1A492215A962EE004AF4A4 /* SeekHandler.h */,
5901 5906
 				36A9443F15821E7C00727135 /* SortUtils.cpp */,
5902 5907
 				36A9444015821E7C00727135 /* SortUtils.h */,
5903 5908
 				E38E1E7F0D25F9FD00618676 /* Splash.cpp */,
@@ -7325,6 +7330,7 @@
7325 7330
 				1DE0443515828F4B005DDB4D /* Exception.cpp in Sources */,
7326 7331
 				36A9464C15AA25FD00727135 /* DirectoryNodeTags.cpp in Sources */,
7327 7332
 				7C1D682915A7D2FD00658B65 /* DatabaseManager.cpp in Sources */,
  7333
+				7C1A492315A962EE004AF4A4 /* SeekHandler.cpp in Sources */,
7328 7334
 			);
7329 7335
 			runOnlyForDeploymentPostprocessing = 0;
7330 7336
 		};
2  project/VS2010Express/XBMC.vcxproj
@@ -1110,6 +1110,7 @@
1110 1110
     <ClCompile Include="..\..\xbmc\utils\RssReader.cpp" />
1111 1111
     <ClCompile Include="..\..\xbmc\utils\ScraperParser.cpp" />
1112 1112
     <ClCompile Include="..\..\xbmc\utils\ScraperUrl.cpp" />
  1113
+    <ClCompile Include="..\..\xbmc\utils\SeekHandler.cpp" />
1113 1114
     <ClCompile Include="..\..\xbmc\utils\SortUtils.cpp" />
1114 1115
     <ClCompile Include="..\..\xbmc\utils\Splash.cpp" />
1115 1116
     <ClCompile Include="..\..\xbmc\utils\ssrc.cpp" />
@@ -1906,6 +1907,7 @@
1906 1907
     <ClInclude Include="..\..\xbmc\utils\SaveFileStateJob.h" />
1907 1908
     <ClInclude Include="..\..\xbmc\utils\ScraperParser.h" />
1908 1909
     <ClInclude Include="..\..\xbmc\utils\ScraperUrl.h" />
  1910
+    <ClInclude Include="..\..\xbmc\utils\SeekHandler.h" />
1909 1911
     <ClInclude Include="..\..\xbmc\utils\SortUtils.h" />
1910 1912
     <ClInclude Include="..\..\xbmc\utils\Splash.h" />
1911 1913
     <ClInclude Include="..\..\xbmc\utils\ssrc.h" />
6  project/VS2010Express/XBMC.vcxproj.filters
@@ -2581,6 +2581,9 @@
2581 2581
     <ClCompile Include="..\..\xbmc\network\AirTunesServer.cpp">
2582 2582
       <Filter>network</Filter>
2583 2583
     </ClCompile>
  2584
+    <ClCompile Include="..\..\xbmc\utils\SeekHandler.cpp">
  2585
+      <Filter>utils</Filter>
  2586
+    </ClCompile>
2584 2587
     <ClCompile Include="..\..\xbmc\utils\SortUtils.cpp">
2585 2588
       <Filter>utils</Filter>
2586 2589
     </ClCompile>
@@ -5215,6 +5218,9 @@
5215 5218
     <ClInclude Include="..\..\xbmc\network\DllLibShairplay.h">
5216 5219
       <Filter>network</Filter>
5217 5220
     </ClInclude>
  5221
+    <ClInclude Include="..\..\xbmc\utils\SeekHandler.h">
  5222
+      <Filter>utils</Filter>
  5223
+    </ClInclude>
5218 5224
     <ClInclude Include="..\..\xbmc\utils\SortUtils.h">
5219 5225
       <Filter>utils</Filter>
5220 5226
     </ClInclude>
76  xbmc/dialogs/GUIDialogSeekBar.cpp
@@ -24,20 +24,14 @@
24 24
 #include "GUIUserMessages.h"
25 25
 #include "Application.h"
26 26
 #include "GUIInfoManager.h"
27  
-#include "utils/TimeUtils.h"
28 27
 #include "utils/StringUtils.h"
29 28
 
30  
-#define SEEK_BAR_DISPLAY_TIME 2000L
31  
-#define SEEK_BAR_SEEK_TIME     500L
32  
-
33 29
 #define POPUP_SEEK_SLIDER       401
34 30
 #define POPUP_SEEK_LABEL        402
35 31
 
36 32
 CGUIDialogSeekBar::CGUIDialogSeekBar(void)
37 33
     : CGUIDialog(WINDOW_DIALOG_SEEK_BAR, "DialogSeekBar.xml")
38 34
 {
39  
-  m_fSeekPercentage = 0.0f;
40  
-  m_bRequireSeek = false;
41 35
   m_loadOnDemand = false;    // the application class handles our resources
42 36
 }
43 37
 
@@ -49,40 +43,7 @@ bool CGUIDialogSeekBar::OnAction(const CAction &action)
49 43
 {
50 44
   if (action.GetID() == ACTION_ANALOG_SEEK_FORWARD || action.GetID() == ACTION_ANALOG_SEEK_BACK)
51 45
   {
52  
-    if (!m_bRequireSeek)
53  
-    { // start of seeking
54  
-
55  
-      if (g_infoManager.GetTotalPlayTime())
56  
-        m_fSeekPercentage = (float)g_infoManager.GetPlayTime() / g_infoManager.GetTotalPlayTime() * 0.1f;
57  
-      else
58  
-        m_fSeekPercentage = 0.0f;
59  
-
60  
-      // tell info manager that we have started a seekbar operation
61  
-      m_bRequireSeek = true;
62  
-      g_infoManager.SetSeeking(true);
63  
-    }
64  
-
65  
-    // calculate our seek amount
66  
-    if (g_application.m_pPlayer && !g_infoManager.m_performingSeek)
67  
-    {
68  
-      //100% over 1 second.
69  
-      float speed = 100.0f;
70  
-      if( action.GetRepeat() )
71  
-        speed *= action.GetRepeat();
72  
-      else
73  
-        speed /= g_infoManager.GetFPS();
74  
-
75  
-      if (action.GetID() == ACTION_ANALOG_SEEK_FORWARD)
76  
-        m_fSeekPercentage += action.GetAmount() * action.GetAmount() * speed;
77  
-      else
78  
-        m_fSeekPercentage -= action.GetAmount() * action.GetAmount() * speed;
79  
-      if (m_fSeekPercentage > 100.0f) m_fSeekPercentage = 100.0f;
80  
-      if (m_fSeekPercentage < 0.0f) m_fSeekPercentage = 0.0f;
81  
-      CGUISliderControl *pSlider = (CGUISliderControl*)GetControl(POPUP_SEEK_SLIDER);
82  
-      if (pSlider) pSlider->SetPercentage((int)m_fSeekPercentage);   // Update our seek bar accordingly
83  
-    }
84  
-
85  
-    ResetTimer();
  46
+    m_handler.Seek(action.GetID() == ACTION_ANALOG_SEEK_FORWARD, action.GetAmount(), action.GetRepeat());
86 47
     return true;
87 48
   }
88 49
   return CGUIDialog::OnAction(action);
@@ -103,11 +64,8 @@ bool CGUIDialogSeekBar::OnMessage(CGUIMessage& message)
103 64
     }
104 65
     break;
105 66
   case GUI_MSG_PLAYBACK_STARTED:
106  
-    { // new song started while our window is up - update our details
107  
-
108  
-      m_bRequireSeek = false;
109  
-      m_fSeekPercentage = 0.0f;
110  
-
  67
+    { // new song started while our window is up - reset our seek handler
  68
+      m_handler.Reset();
111 69
     }
112 70
     break;
113 71
 
@@ -115,11 +73,6 @@ bool CGUIDialogSeekBar::OnMessage(CGUIMessage& message)
115 73
   return false; // don't process anything other than what we need!
116 74
 }
117 75
 
118  
-void CGUIDialogSeekBar::ResetTimer()
119  
-{
120  
-  m_timer = CTimeUtils::GetFrameTime();
121  
-}
122  
-
123 76
 void CGUIDialogSeekBar::FrameMove()
124 77
 {
125 78
   if (!g_application.m_pPlayer)
@@ -128,12 +81,8 @@ void CGUIDialogSeekBar::FrameMove()
128 81
     return;
129 82
   }
130 83
 
131  
-  // check if we should seek or exit
132  
-  if (!g_infoManager.m_performingSeek && CTimeUtils::GetFrameTime() - m_timer > SEEK_BAR_DISPLAY_TIME)
133  
-    g_infoManager.SetSeeking(false);
134  
-
135  
-  // render our controls
136  
-  if (!m_bRequireSeek && !g_infoManager.m_performingSeek)
  84
+  // update controls
  85
+  if (!m_handler.InProgress() && !g_infoManager.m_performingSeek)
137 86
   { // position the bar at our current time
138 87
     CGUISliderControl *pSlider = (CGUISliderControl*)GetControl(POPUP_SEEK_SLIDER);
139 88
     if (pSlider && g_infoManager.GetTotalPlayTime())
@@ -145,25 +94,24 @@ void CGUIDialogSeekBar::FrameMove()
145 94
   }
146 95
   else
147 96
   {
  97
+    CGUISliderControl *pSlider = (CGUISliderControl*)GetControl(POPUP_SEEK_SLIDER);
  98
+    if (pSlider)
  99
+      pSlider->SetPercentage((int)m_handler.GetPercent());
  100
+
148 101
     CGUIMessage msg(GUI_MSG_LABEL_SET, GetID(), POPUP_SEEK_LABEL);
149 102
     msg.SetLabel(GetSeekTimeLabel());
150 103
     OnMessage(msg);
151 104
   }
152 105
 
153 106
   // Check for seek timeout, and perform the seek
154  
-  if (m_bRequireSeek && CTimeUtils::GetFrameTime() - m_timer > SEEK_BAR_SEEK_TIME)
155  
-  {
156  
-    g_infoManager.m_performingSeek = true;
157  
-    double time = g_infoManager.GetTotalPlayTime() * m_fSeekPercentage * 0.01;
158  
-    g_application.SeekTime(time);
159  
-    m_bRequireSeek = false;
160  
-  }
  107
+  m_handler.Process();
  108
+
161 109
   CGUIDialog::FrameMove();
162 110
 }
163 111
 
164 112
 CStdString CGUIDialogSeekBar::GetSeekTimeLabel(TIME_FORMAT format)
165 113
 {
166  
-  int time = (int)(g_infoManager.GetTotalPlayTime() * m_fSeekPercentage * 0.01f);
  114
+  int time = (int)(g_infoManager.GetTotalPlayTime() * m_handler.GetPercent() * 0.01f);
167 115
   return StringUtils::SecondsToTimeString(time, format);
168 116
 }
169 117
 
8  xbmc/dialogs/GUIDialogSeekBar.h
@@ -23,6 +23,7 @@
23 23
 
24 24
 #include "guilib/GUIDialog.h"
25 25
 #include "XBDateTime.h"
  26
+#include "utils/SeekHandler.h"
26 27
 
27 28
 class CGUIDialogSeekBar : public CGUIDialog
28 29
 {
@@ -32,11 +33,8 @@ class CGUIDialogSeekBar : public CGUIDialog
32 33
   virtual bool OnMessage(CGUIMessage& message);
33 34
   virtual bool OnAction(const CAction &action);
34 35
   virtual void FrameMove();
35  
-  void ResetTimer();
36  
-  float GetPercentage() {return m_fSeekPercentage;};
  36
+  float GetPercentage() {return m_handler.GetPercent();};
37 37
   CStdString GetSeekTimeLabel(TIME_FORMAT format = TIME_FORMAT_GUESS);
38 38
 protected:
39  
-  unsigned int m_timer;
40  
-  float m_fSeekPercentage;
41  
-  bool m_bRequireSeek;
  39
+  CSeekHandler m_handler;
42 40
 };
1  xbmc/utils/Makefile
@@ -46,6 +46,7 @@ SRCS=AlarmClock.cpp \
46 46
      RssReader.cpp \
47 47
      ScraperParser.cpp \
48 48
      ScraperUrl.cpp \
  49
+     SeekHandler.cpp \
49 50
      SortUtils.cpp \
50 51
      Splash.cpp \
51 52
      ssrc.cpp \
95  xbmc/utils/SeekHandler.cpp
... ...
@@ -0,0 +1,95 @@
  1
+/*
  2
+ *      Copyright (C) 2012 Team XBMC
  3
+ *      http://www.xbmc.org
  4
+ *
  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.
  14
+ *
  15
+ *  You should have received a copy of the GNU General Public License
  16
+ *  along with XBMC; 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
  19
+ *
  20
+ */
  21
+
  22
+#include "SeekHandler.h"
  23
+#include "GUIInfoManager.h"
  24
+#include "Application.h"
  25
+
  26
+CSeekHandler::CSeekHandler()
  27
+: m_requireSeek(false),
  28
+  m_percent(0.0f)
  29
+{
  30
+}
  31
+
  32
+void CSeekHandler::Reset()
  33
+{
  34
+  m_requireSeek = false;
  35
+  m_percent = 0;
  36
+}
  37
+
  38
+void CSeekHandler::Seek(bool forward, float amount, float duration)
  39
+{
  40
+  if (!m_requireSeek)
  41
+  { // not yet seeking
  42
+    if (g_infoManager.GetTotalPlayTime())
  43
+      m_percent = (float)g_infoManager.GetPlayTime() / g_infoManager.GetTotalPlayTime() * 0.1f;
  44
+    else
  45
+      m_percent = 0.0f;
  46
+
  47
+    // tell info manager that we have started a seek operation
  48
+    m_requireSeek = true;
  49
+    g_infoManager.SetSeeking(true);
  50
+  }
  51
+  // calculate our seek amount
  52
+  if (!g_infoManager.m_performingSeek)
  53
+  {
  54
+    //100% over 1 second.
  55
+    float speed = 100.0f;
  56
+    if( duration )
  57
+      speed *= duration;
  58
+    else
  59
+      speed /= g_infoManager.GetFPS();
  60
+
  61
+    if (forward)
  62
+      m_percent += amount * amount * speed;
  63
+    else
  64
+      m_percent -= amount * amount * speed;
  65
+    if (m_percent > 100.0f) m_percent = 100.0f;
  66
+    if (m_percent < 0.0f)   m_percent = 0.0f;
  67
+  }
  68
+  m_timer.StartZero();
  69
+}
  70
+
  71
+float CSeekHandler::GetPercent() const
  72
+{
  73
+  return m_percent;
  74
+}
  75
+
  76
+bool CSeekHandler::InProgress() const
  77
+{
  78
+  return m_requireSeek;
  79
+}
  80
+
  81
+void CSeekHandler::Process()
  82
+{
  83
+  if (m_timer.GetElapsedMilliseconds() > time_before_seek)
  84
+  {
  85
+    if (!g_infoManager.m_performingSeek && m_timer.GetElapsedMilliseconds() > time_for_display) // TODO: Why?
  86
+      g_infoManager.SetSeeking(false);
  87
+    if (m_requireSeek)
  88
+    {
  89
+      g_infoManager.m_performingSeek = true;
  90
+      double time = g_infoManager.GetTotalPlayTime() * m_percent * 0.01;
  91
+      g_application.SeekTime(time);
  92
+      m_requireSeek = false;
  93
+    }
  94
+  }
  95
+}
42  xbmc/utils/SeekHandler.h
... ...
@@ -0,0 +1,42 @@
  1
+#pragma once
  2
+/*
  3
+ *      Copyright (C) 2012 Team XBMC
  4
+ *      http://www.xbmc.org
  5
+ *
  6
+ *  This Program is free software; you can redistribute it and/or modify
  7
+ *  it under the terms of the GNU General Public License as published by
  8
+ *  the Free Software Foundation; either version 2, or (at your option)
  9
+ *  any later version.
  10
+ *
  11
+ *  This Program is distributed in the hope that it will be useful,
  12
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14
+ *  GNU General Public License for more details.
  15
+ *
  16
+ *  You should have received a copy of the GNU General Public License
  17
+ *  along with XBMC; see the file COPYING.  If not, write to
  18
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19
+ *  http://www.gnu.org/copyleft/gpl.html
  20
+ *
  21
+ */
  22
+
  23
+#include "utils/Stopwatch.h"
  24
+
  25
+class CSeekHandler
  26
+{
  27
+public:
  28
+  CSeekHandler();
  29
+
  30
+  void Seek(bool forward, float amount, float duration = 0);
  31
+  void Process();
  32
+  void Reset();
  33
+
  34
+  float GetPercent() const;
  35
+  bool InProgress() const;
  36
+private:
  37
+  static const int time_before_seek = 500;
  38
+  static const int time_for_display = 2000; // TODO: WTF?
  39
+  bool       m_requireSeek;
  40
+  float      m_percent;
  41
+  CStopWatch m_timer;
  42
+};

0 notes on commit 124b538

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