Ticket #1876: addTransitionLength.txt

File addTransitionLength.txt, 11.2 KB (added by mdobossy@…, 18 years ago)

MythGallery, OpenGL Transition Length Patch

Line 
1Index: mythgallery/glsingleview.cpp
2===================================================================
3--- mythgallery/glsingleview.cpp        (revision 10014)
4+++ mythgallery/glsingleview.cpp        (working copy)
5@@ -25,12 +25,14 @@
6 using namespace std;
7 
8 #include <qtimer.h>
9+#include <qdatetime.h>
10 #include <qimage.h>
11 #include <qlayout.h>
12 #include <qsize.h>
13 #include <qfileinfo.h>
14 #include <qdir.h>
15 #include <qpainter.h>
16+#include <qobject.h>
17 
18 #include <mythtv/mythcontext.h>
19 #include <mythtv/lcddevice.h>
20@@ -131,7 +133,7 @@
21     QString transType = gContext->GetSetting("SlideshowOpenGLTransition");
22     if (!transType.isEmpty() && m_effectMap.contains(transType))
23         m_effectMethod = m_effectMap[transType];
24-
25+    m_transTimeout = gContext->GetNumSetting("SlideshowOpenGLTransitionLength", 0);
26     if (!m_effectMethod || transType == QString("random (gl)"))
27     {
28         m_effectMethod = getRandomEffect();
29@@ -156,6 +158,7 @@
30     // ---------------------------------------------------------------
31 
32     m_timer = new QTimer(this);
33+    m_time = new QTime();
34     connect(m_timer, SIGNAL(timeout()),
35             SLOT(slotTimeOut()));
36 
37@@ -217,6 +220,7 @@
38 
39     m_timer->stop();
40     delete m_timer;
41+    delete m_time;
42 
43     if (m_texItem[0].tex)
44         glDeleteTextures(1, &m_texItem[0].tex);
45@@ -294,9 +298,7 @@
46         (this->*m_effectMethod)();
47     }
48     else
49-    {
50         paintTexture();
51-    }
52 
53     if (glGetError())
54         VERBOSE(VB_GENERAL, LOC_ERR + "OpenGL error detected");
55@@ -780,7 +782,7 @@
56 
57 void GLSingleView::effectBlend(void)
58 {
59-    if (m_i > 100)
60+    if (m_time->elapsed() > 1000.0*m_transTimeout)
61     {
62         paintTexture();
63         m_effectRunning = false;
64@@ -790,6 +792,7 @@
65 
66     int a = (m_curr == 0) ? 1 : 0;
67     int b =  m_curr;
68+    float t = 1.0f * (float)m_time->elapsed() / (1000.0f * m_transTimeout);
69 
70     TexItem& ta = m_texItem[a];
71     TexItem& tb = m_texItem[b];
72@@ -819,7 +822,7 @@
73 
74     glBegin(GL_QUADS);
75     {
76-        glColor4f(0.0f, 0.0f, 0.0f, 1.0f / (100.0f) * (float)m_i);
77+        glColor4f(0.0f, 0.0f, 0.0f, 1.0f * t);
78         glVertex3f(-1.0f, -1.0f, 0.0f);
79         glVertex3f(+1.0f, -1.0f, 0.0f);
80         glVertex3f(+1.0f, +1.0f, 0.0f);
81@@ -835,7 +838,7 @@
82 
83     glBegin(GL_QUADS);
84     {
85-        glColor4f(1.0f, 1.0f, 1.0f, 1.0f / (100.0f) * (float)m_i);
86+        glColor4f(1.0f, 1.0f, 1.0f, 1.0f * t);
87         glTexCoord2f(0.0f, 0.0f);
88         glVertex3f(-tb.cx, -tb.cy, 0.0f);
89 
90@@ -855,14 +858,13 @@
91 
92 void GLSingleView::effectZoomBlend(void)
93 {
94-    if (m_i > 100)
95+    if (m_time->elapsed() > 1000.0f * m_transTimeout)
96     {
97         paintTexture();
98         m_effectRunning = false;
99         m_tmout = -1;
100         return;
101     }
102-
103     int a = (m_curr == 0) ? 1 : 0;
104     int b =  m_curr;
105     float zf = 0.75f;
106@@ -873,7 +875,7 @@
107     glMatrixMode(GL_TEXTURE);
108     glLoadIdentity();
109     glRotatef(ta.angle, 0.0f, 0.0f, 1.0f);
110-    float t = 1.0f / (100.00f) * (float)m_i;
111+    float t = 1.0f * (float)m_time->elapsed() / (1000.0f * m_transTimeout);
112     glBindTexture(GL_TEXTURE_2D, ta.tex);
113 
114     glBegin(GL_QUADS);
115@@ -901,7 +903,7 @@
116 
117     glBegin(GL_QUADS);
118     {
119-        glColor4f(1.0f, 1.0f, 1.0f, 1.0f / (100.0f) * (float) m_i);
120+        glColor4f(1.0f, 1.0f, 1.0f, 0.0f + t);
121         glTexCoord2f(0.0f, 0.0f);
122         glVertex3f(-tb.cx, -tb.cy, 0.0f);
123 
124@@ -921,7 +923,7 @@
125 
126 void GLSingleView::effectRotate(void)
127 {
128-    if (m_i > 100)
129+    if (m_time->elapsed() > 1000.0f * m_transTimeout)
130     {
131         paintTexture();
132         m_effectRunning = false;
133@@ -934,6 +936,7 @@
134 
135     int a = (m_curr == 0) ? 1 : 0;
136     int b =  m_curr;
137+    float t = 1.0f * (float)m_time->elapsed() / (1000.0f * m_transTimeout);
138 
139     TexItem& ta = m_texItem[a];
140     TexItem& tb = m_texItem[b];
141@@ -962,10 +965,10 @@
142 
143     glMatrixMode(GL_MODELVIEW);
144     glLoadIdentity();
145-    float rotate = 360.0f/100.0f*(float)m_i;
146+    float rotate = 360.0f * t;
147     glRotatef(((m_dir == 0) ? -1 : 1) * rotate,
148               0.0f, 0.0f, 1.0f);
149-    float scale = 1.0f/100.0f*(100.0f-(float)(m_i));
150+    float scale = 1.0f * (1.0f - t);
151     glScalef(scale, scale, 1.0f);
152 
153     glMatrixMode(GL_TEXTURE);
154@@ -996,7 +999,7 @@
155 
156 void GLSingleView::effectBend(void)
157 {
158-    if (m_i > 100)
159+    if (m_time->elapsed() > 1000.0f * m_transTimeout)
160     {
161         paintTexture();
162         m_effectRunning = false;
163@@ -1009,6 +1012,7 @@
164 
165     int a = (m_curr == 0) ? 1 : 0;
166     int b =  m_curr;
167+    float t = 1.0f * (float)m_time->elapsed() / (1000.0f * m_transTimeout);
168 
169     TexItem& ta = m_texItem[a];
170     TexItem& tb = m_texItem[b];
171@@ -1037,7 +1041,7 @@
172 
173     glMatrixMode(GL_MODELVIEW);
174     glLoadIdentity();
175-    glRotatef(90.0f/100.0f*(float)m_i,
176+    glRotatef(90.0f * t,
177               (m_dir == 0) ? 1.0f : 0.0f,
178               (m_dir == 1) ? 1.0f : 0.0f,
179               0.0f);
180@@ -1069,7 +1073,7 @@
181 
182 void GLSingleView::effectFade(void)
183 {
184-    if (m_i > 100)
185+    if (m_time->elapsed() > 1000.0f * m_transTimeout)
186     {
187         paintTexture();
188         m_effectRunning = false;
189@@ -1079,13 +1083,15 @@
190 
191     int a;
192     float opacity;
193-    if (m_i <= 50)
194+    float t = 1.0f * (float)m_time->elapsed() / (1000.0f * m_transTimeout);
195+
196+    if (m_time->elapsed() < 1000.0f * m_transTimeout * 0.5f)
197     {
198         a =  (m_curr == 0) ? 1 : 0;
199-        opacity = 1.0f - 1.0f/50.0f*(float)(m_i);
200+        opacity = 1.0f - (2.0f * t);
201     }
202     else {
203-        opacity = 1.0f/50.0f*(float)(m_i-50.0f);
204+        opacity = 2.0f * (t - 0.5);
205         a = m_curr;
206     }
207 
208@@ -1120,7 +1126,7 @@
209 
210 void GLSingleView::effectInOut(void)
211 {
212-    if (m_i > 100)
213+    if (m_time->elapsed() > 1000.0f * m_transTimeout)
214     {
215         paintTexture();
216         m_effectRunning = false;
217@@ -1135,7 +1141,8 @@
218 
219     int a;
220     bool out;
221-    if (m_i <= 50)
222+    float tt = 1.0f * (float)m_time->elapsed() / (1000.0f * m_transTimeout);
223+    if (m_time->elapsed() <= 1000.0f * m_transTimeout * 0.5f)
224     {
225         a   = (m_curr == 0) ? 1 : 0;
226         out = 1;
227@@ -1151,8 +1158,8 @@
228     glMatrixMode(GL_MODELVIEW);
229     glLoadIdentity();
230     float t = (out) ?
231-        1.0f / 50.0f * (50.0f - m_i) :
232-        1.0f / 50.0f * (m_i - 50.0f);
233+        1.0f / 0.5f * (0.5f - tt) :
234+        1.0f / 0.5f * (tt - 0.5f);
235 
236     glScalef(t, t, 1.0f);
237     t = 1.0f - t;
238@@ -1190,7 +1197,7 @@
239 
240 void GLSingleView::effectSlide(void)
241 {
242-    if (m_i > 100)
243+    if (m_time->elapsed() > 1000.0f * m_transTimeout)
244     {
245         paintTexture();
246         m_effectRunning = false;
247@@ -1203,6 +1210,7 @@
248 
249     int a = (m_curr == 0) ? 1 : 0;
250     int b =  m_curr;
251+    float t = 1.0f * (float)m_time->elapsed() / (1000.0f * m_transTimeout);
252 
253     TexItem& ta = m_texItem[a];
254     TexItem& tb = m_texItem[b];
255@@ -1231,7 +1239,7 @@
256 
257     glMatrixMode(GL_MODELVIEW);
258     glLoadIdentity();
259-    float trans = 2.0f/100.0f*(float)m_i;
260+    float trans = 2.0f * t;
261     glTranslatef((m_dir % 2 == 0) ? ((m_dir == 2)? 1 : -1) * trans : 0.0f,
262                  (m_dir % 2 == 1) ? ((m_dir == 1)? 1 : -1) * trans : 0.0f,
263                  0.0f);
264@@ -1265,7 +1273,7 @@
265 
266 void GLSingleView::effectFlutter(void)
267 {
268-    if (m_i > 100)
269+    if (m_time->elapsed() > 1000.0f * m_transTimeout)
270     {
271         paintTexture();
272         m_effectRunning = false;
273@@ -1275,6 +1283,7 @@
274 
275     int a = (m_curr == 0) ? 1 : 0;
276     int b =  m_curr;
277+    float t = 1.0f * (float)m_time->elapsed() / (1000.0f * m_transTimeout);
278 
279     TexItem& ta = m_texItem[a];
280     TexItem& tb = m_texItem[b];
281@@ -1318,11 +1327,11 @@
282 
283     glMatrixMode(GL_MODELVIEW);
284     glLoadIdentity();
285-    float rotate = 60.0f/100.0f*(float)m_i;
286+    float rotate = 60.0f*t;
287     glRotatef(rotate, 1.0f, 0.0f, 0.0f);
288-    float scale = 1.0f/100.0f*(100.0f-(float)m_i);
289+    float scale = 1.0f*(1-t);
290     glScalef(scale, scale, scale);
291-    glTranslatef(1.0f/100.0f*(float)m_i, 1.0f/100.0f*(float)m_i, 0.0f);
292+    glTranslatef(1.0f*t, 1.0f*t, 0.0f);
293 
294     glMatrixMode(GL_TEXTURE);
295     glLoadIdentity();
296@@ -1386,10 +1395,10 @@
297 
298 void GLSingleView::effectCube(void)
299 {
300-    int tot = 200;
301-    int rotStart = 50;
302+    float tot = 1000.0f * m_transTimeout;
303+    float rotStart = 250.0f * m_transTimeout;
304 
305-    if (m_i > tot)
306+    if (m_time->elapsed() > 1000.0f * m_transTimeout)
307     {
308         paintTexture();
309         m_effectRunning = false;
310@@ -1435,7 +1444,7 @@
311     glLoadIdentity();
312 
313     float trans = 5.0f *
314-        (float) ((m_i <= tot / 2) ? m_i : tot - m_i) / (float)tot;
315+        (float) (((float)m_time->elapsed() <= tot / 2) ? (float)m_time->elapsed() : tot - (float)m_time->elapsed()) / (float)tot;
316 
317     glTranslatef(0.0f, 0.0f, -znear - 1.0f - trans);
318 
319@@ -1547,10 +1556,10 @@
320     }
321     glEnd();
322 
323-    if (m_i >= rotStart && m_i < (tot-rotStart))
324+    if ((float)m_time->elapsed() >= rotStart && (float)m_time->elapsed() < (tot-rotStart))
325     {
326-        xrot += 360.0f / (float)(tot - 2 * rotStart);
327-        yrot += 180.0f / (float)(tot - 2 * rotStart);
328+        xrot = 360.0f * ((float)m_time->elapsed() - ( rotStart))/(tot - 2 * rotStart);
329+        yrot = 180.0f * ((float)m_time->elapsed() - ( rotStart))/(tot - 2 * rotStart);
330     }
331 
332     m_i++;
333@@ -1602,7 +1611,9 @@
334                 m_tmout = 10;
335                 m_effectRunning = true;
336                 m_i = 0;
337+               m_disp = 0;
338             }
339+           m_time->restart();
340         }
341     }
342 
343Index: mythgallery/glsingleview.h
344===================================================================
345--- mythgallery/glsingleview.h  (revision 10014)
346+++ mythgallery/glsingleview.h  (working copy)
347@@ -30,6 +30,7 @@
348 
349 class QImage;
350 class QTimer;
351+class QTime;
352 
353 class GLSingleView;
354 
355@@ -94,12 +95,14 @@
356     float         m_sx, m_sy;
357 
358     QTimer       *m_timer;
359+    QTime       *m_time;
360     int           m_tmout;
361     int           m_delay;
362+    float        m_transTimeout;
363     bool          m_effectRunning;
364     bool          m_running;
365     int           m_slideShow;
366-
367+    int                  m_disp;
368     GLuint        m_texInfo;
369     bool          m_showInfo;
370     int           m_maxTexDim;
371Index: mythgallery/gallerysettings.cpp
372===================================================================
373--- mythgallery/gallerysettings.cpp     (revision 10014)
374+++ mythgallery/gallerysettings.cpp     (working copy)
375@@ -92,6 +92,17 @@
376     return gc;
377 };
378 
379+static HostSpinBox *SlideshowOpenGLTransitionLength()
380+{
381+    HostSpinBox *gc = new HostSpinBox("SlideshowOpenGLTransitionLength", 1, 10, 1);
382+    gc->setLabel(QObject::tr("Durration of OpenGL Transition (seconds)"));
383+    gc->setValue(2);
384+    gc->setHelpText(QObject::tr("This is the durration of the OpenGL transition "
385+                    "selected above, in seconds."));
386+    return gc;
387+};
388+
389+
390 #endif /* OPENGL_SUPPORT */
391 
392 static HostComboBox *SlideshowTransition()
393@@ -129,7 +140,6 @@
394                     "picture in single view mode."));
395     return gc;
396 };
397-
398 static HostSpinBox *SlideshowDelay()
399 {
400     HostSpinBox *gc = new HostSpinBox("SlideshowDelay", 1, 600, 1);
401@@ -172,6 +182,7 @@
402     
403         ConfigurationGroup* openGLConfig = new VerticalConfigurationGroup(false);
404         openGLConfig->addChild(SlideshowOpenGLTransition());
405+        openGLConfig->addChild(SlideshowOpenGLTransitionLength());
406         addTarget("1", openGLConfig);
407 
408         ConfigurationGroup* regularConfig = new VerticalConfigurationGroup(false);