Ticket #10256: animation.patch

File animation.patch, 26.8 KB (added by Jonatan <mythtv@…>, 12 years ago)
  • mythtv/libs/libmythui/libmythui.pro

    diff --git a/mythtv/libs/libmythui/libmythui.pro b/mythtv/libs/libmythui/libmythui.pro
    index 0f0a49b..64c68bb 100644
    a b HEADERS += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h 
    3131HEADERS += mythrender_base.h mythfontmanager.h mythuieditbar.h
    3232HEADERS += mythdisplay.h mythuivideo.h mythudplistener.h
    3333HEADERS += mythuiexp.h mythuisimpletext.h mythuistatetracker.h
     34HEADERS += mythanimation.h
    3435
    3536SOURCES  = mythmainwindow.cpp mythpainter.cpp mythimage.cpp mythrect.cpp
    3637SOURCES += myththemebase.cpp  mythpainter_qimage.cpp mythpainter_yuva.cpp
    SOURCES += mythvirtualkeyboard.cpp mythuishape.cpp mythuiguidegrid.cpp 
    4950SOURCES += mythfontmanager.cpp mythuieditbar.cpp
    5051SOURCES += mythdisplay.cpp mythuivideo.cpp mythudplistener.cpp
    5152SOURCES += mythuisimpletext.cpp mythuistatetracker.cpp
     53SOURCES += mythanimation.cpp
    5254
    5355
    5456inc.path = $${PREFIX}/include/mythtv/libmythui/
    inc.files += mythvirtualkeyboard.h mythuishape.h mythuiguidegrid.h 
    6769inc.files += mythuieditbar.h mythuifilebrowser.h mythuivideo.h
    6870inc.files += mythuiexp.h mythuisimpletext.h mythuiactions.h
    6971inc.files += mythuistatetracker.h
     72inc.files += mythanimation.h
    7073
    7174INSTALLS += inc
    7275
  • new file mythtv/libs/libmythui/mythanimation.cpp

    diff --git a/mythtv/libs/libmythui/mythanimation.cpp b/mythtv/libs/libmythui/mythanimation.cpp
    new file mode 100644
    index 0000000..6e56050
    - +  
     1#include "mythanimation.h"
     2#include "mythuitype.h"
     3#include "mythmainwindow.h"
     4
     5#include <QDomDocument>
     6
     7MythAnimation::MythAnimation(MythUIType* parent, Type type)
     8    : m_parent(parent), m_type(type), m_when(AboutToShow),
     9      m_active(false), m_looped(false), m_reversible(false)
     10{
     11}
     12
     13void MythAnimation::Activate(void)
     14{
     15    m_active = true;
     16    setCurrentTime(0);
     17}
     18
     19MythAnimation::When MythAnimation::GetWhen(void) const
     20{
     21    return m_when;
     22}
     23
     24void MythAnimation::updateCurrentValue(const QVariant& value)
     25{
     26    if (!m_active)
     27        return;
     28
     29    m_value = value;
     30    if (m_parent)
     31    {
     32        if (Position == m_type)
     33            m_parent->SetPosition(m_value.toPoint());
     34        else if (Alpha == m_type)
     35            m_parent->SetAlpha(m_value.toInt());
     36        else if (Size == m_type)
     37            m_parent->SetSize(m_value.toSize());
     38        else if (Zoom == m_type)
     39            m_parent->SetZoom(m_value.toFloat());
     40        else if (Angle == m_type)
     41            m_parent->SetAngle(m_value.toFloat());
     42    }
     43}
     44
     45void MythAnimation::CopyFrom(const MythAnimation* animation)
     46{
     47    m_type = animation->m_type;
     48    m_value = animation->m_value;
     49    m_when = animation->m_when;
     50    m_looped = animation->m_looped;
     51    m_reversible = animation->m_reversible;
     52
     53    setStartValue(animation->startValue());
     54    setEndValue(animation->endValue());
     55    setEasingCurve(animation->easingCurve());
     56    setDuration(animation->duration());
     57    if (m_looped)
     58        setLoopCount(-1);
     59}
     60
     61void MythAnimation::incrementCurrentTime(void)
     62{
     63    if (!m_active)
     64        return;
     65
     66    int time = currentTime();
     67    if (direction() == Forward)
     68        time += GetMythMainWindow()->GetDrawInterval();
     69    else
     70        time -= GetMythMainWindow()->GetDrawInterval();
     71
     72    setCurrentTime(time);
     73
     74    if (endValue() == currentValue())
     75    {
     76        if (direction() == Forward)
     77        {
     78            if (m_reversible)
     79                setDirection(Backward);
     80            else if (!m_looped)
     81                m_active = false;
     82        }
     83    }
     84    else if (startValue() == currentValue())
     85    {
     86        if (direction() == Backward)
     87        {
     88            if (m_reversible)
     89                setDirection(Forward);
     90            else if (!m_looped)
     91                m_active = false;
     92        }
     93    }
     94}
     95
     96void MythAnimation::setEasingCurve(const QString& curve)
     97{
     98    if (curve == "Linear") setEasingCurve(QEasingCurve::Linear);
     99    else if (curve == "InQuad") setEasingCurve(QEasingCurve::InQuad);
     100    else if (curve == "OutQuad") setEasingCurve(QEasingCurve::OutQuad);
     101    else if (curve == "InOutQuad") setEasingCurve(QEasingCurve::InOutQuad);
     102    else if (curve == "OutInQuad") setEasingCurve(QEasingCurve::OutInQuad);
     103    else if (curve == "InCubic") setEasingCurve(QEasingCurve::InCubic);
     104    else if (curve == "OutCubic") setEasingCurve(QEasingCurve::OutCubic);
     105    else if (curve == "InOutCubic") setEasingCurve(QEasingCurve::InOutCubic);
     106    else if (curve == "OutInCubic") setEasingCurve(QEasingCurve::OutInCubic);
     107    else if (curve == "InQuart") setEasingCurve(QEasingCurve::InQuart);
     108    else if (curve == "OutQuart") setEasingCurve(QEasingCurve::OutQuart);
     109    else if (curve == "InOutQuart") setEasingCurve(QEasingCurve::InOutQuart);
     110    else if (curve == "OutInQuart") setEasingCurve(QEasingCurve::OutInQuart);
     111    else if (curve == "InQuint") setEasingCurve(QEasingCurve::InQuint);
     112    else if (curve == "OutQuint") setEasingCurve(QEasingCurve::OutQuint);
     113    else if (curve == "InOutQuint") setEasingCurve(QEasingCurve::InOutQuint);
     114    else if (curve == "OutInQuint") setEasingCurve(QEasingCurve::OutInQuint);
     115    else if (curve == "InSine") setEasingCurve(QEasingCurve::InSine);
     116    else if (curve == "OutSine") setEasingCurve(QEasingCurve::OutSine);
     117    else if (curve == "InOutSine") setEasingCurve(QEasingCurve::InOutSine);
     118    else if (curve == "OutInSine") setEasingCurve(QEasingCurve::OutInSine);
     119    else if (curve == "InExpo") setEasingCurve(QEasingCurve::InExpo);
     120    else if (curve == "OutExpo") setEasingCurve(QEasingCurve::OutExpo);
     121    else if (curve == "InOutExpo") setEasingCurve(QEasingCurve::InOutExpo);
     122    else if (curve == "OutInExpo") setEasingCurve(QEasingCurve::OutInExpo);
     123    else if (curve == "InCirc") setEasingCurve(QEasingCurve::InCirc);
     124    else if (curve == "OutCirc") setEasingCurve(QEasingCurve::OutCirc);
     125    else if (curve == "InOutCirc") setEasingCurve(QEasingCurve::InOutCirc);
     126    else if (curve == "OutInCirc") setEasingCurve(QEasingCurve::OutInCirc);
     127    else if (curve == "InElastic") setEasingCurve(QEasingCurve::InElastic);
     128    else if (curve == "OutElastic") setEasingCurve(QEasingCurve::OutElastic);
     129    else if (curve == "InOutElastic") setEasingCurve(QEasingCurve::InOutElastic);
     130    else if (curve == "OutInElastic") setEasingCurve(QEasingCurve::OutInElastic);
     131    else if (curve == "InOutBack") setEasingCurve(QEasingCurve::InOutBack);
     132    else if (curve == "OutInBack") setEasingCurve(QEasingCurve::OutInBack);
     133    else if (curve == "InBounce") setEasingCurve(QEasingCurve::InBounce);
     134    else if (curve == "OutBounce") setEasingCurve(QEasingCurve::OutBounce);
     135    else if (curve == "InOutBounce") setEasingCurve(QEasingCurve::InOutBounce);
     136    else if (curve == "OutInBounce") setEasingCurve(QEasingCurve::OutInBounce);
     137    else if (curve == "InCurve") setEasingCurve(QEasingCurve::InCurve);
     138    else if (curve == "OutCurve") setEasingCurve(QEasingCurve::OutCurve);
     139    else if (curve == "SineCurve") setEasingCurve(QEasingCurve::SineCurve);
     140    else if (curve == "CosineCurve") setEasingCurve(QEasingCurve::CosineCurve);
     141}
     142
     143void MythAnimation::setEasingCurve(QEasingCurve curve)
     144{
     145    QVariantAnimation::setEasingCurve(curve);
     146}
     147
     148bool MythAnimation::ParseElement(const QDomElement& element)
     149{
     150    bool result = true;
     151    QVariant startValue;
     152    QVariant endValue;
     153
     154    QString when = element.attribute("when", "AboutToShow");
     155    if (when == "AboutToShow")
     156        m_when = AboutToShow;
     157    else if (when == "AboutToHide")
     158        m_when = AboutToHide;
     159
     160    m_looped = parseBool(element.attribute("looped", "false"));
     161    m_reversible = parseBool(element.attribute("reversible", "false"));
     162
     163    if (element.attribute("type", "") == "alpha")
     164    {
     165        parseAlpha(element, startValue, endValue);
     166    }
     167    else if (element.attribute("type", "") == "position")
     168    {
     169        parsePosition(element, startValue, endValue);
     170    }
     171    else if (element.attribute("type", "") == "size")
     172    {
     173        parseSize(element, startValue, endValue);
     174    }
     175    else if (element.attribute("type", "") == "zoom")
     176    {
     177        parseZoom(element, startValue, endValue);
     178    }
     179    else if (element.attribute("type", "") == "angle")
     180    {
     181        parseAngle(element, startValue, endValue);
     182    }
     183    else
     184        result = false;
     185
     186    if (result)
     187    {
     188        setStartValue(startValue);
     189        setEndValue(endValue);
     190        setDuration(element.attribute("duration", "500").toInt());
     191        setEasingCurve(element.attribute("easingcurve"));
     192        if (m_looped)
     193            setLoopCount(-1);
     194    }
     195
     196    return result;
     197}
     198
     199void MythAnimation::parseAlpha(const QDomElement& element, QVariant& startValue, QVariant& endValue)
     200{
     201    m_type = Alpha;
     202    startValue = element.attribute("start", "0").toInt();
     203    endValue = element.attribute("end", "0").toInt();
     204}
     205
     206void MythAnimation::parsePosition(const QDomElement& element, QVariant& startValue, QVariant& endValue)
     207{
     208    m_type = Position;
     209
     210    MythPoint start = parsePoint(element.attribute("start", "0,0"), false);
     211    MythPoint startN = parsePoint(element.attribute("start", "0,0"));
     212    MythPoint end = parsePoint(element.attribute("end", "0,0"), false);
     213    MythPoint endN = parsePoint(element.attribute("end", "0,0"));
     214
     215    if (start.x() == -1)
     216        startN.setX(m_parent->GetArea().x());
     217
     218    if (start.y() == -1)
     219        startN.setY(m_parent->GetArea().y());
     220
     221    if (end.x() == -1)
     222        endN.setX(m_parent->GetArea().x());
     223
     224    if (end.y() == -1)
     225        endN.setY(m_parent->GetArea().y());
     226
     227    startN.CalculatePoint(m_parent->GetArea());
     228    endN.CalculatePoint(m_parent->GetArea());
     229
     230    startValue = startN.toQPoint();
     231    endValue = endN.toQPoint();
     232}
     233
     234void MythAnimation::parseSize(const QDomElement& element, QVariant& startValue, QVariant& endValue)
     235{
     236    m_type = Size;
     237    startValue = XMLParseBase::parseSize(element.attribute("start", "0,0"));
     238    endValue = XMLParseBase::parseSize(element.attribute("end", "0,0"));
     239}
     240
     241void MythAnimation::parseZoom(const QDomElement& element, QVariant& startValue, QVariant& endValue)
     242{
     243    m_type = Zoom;
     244    startValue = element.attribute("start", "0").toFloat();
     245    endValue = element.attribute("end", "0").toFloat();
     246}
     247
     248void MythAnimation::parseAngle(const QDomElement& element, QVariant& startValue, QVariant& endValue)
     249{
     250    m_type = Angle;
     251    startValue = element.attribute("start", "0").toFloat();
     252    endValue = element.attribute("end", "0").toFloat();
     253}
  • new file mythtv/libs/libmythui/mythanimation.h

    diff --git a/mythtv/libs/libmythui/mythanimation.h b/mythtv/libs/libmythui/mythanimation.h
    new file mode 100644
    index 0000000..a6040cb
    - +  
     1#ifndef MYTHANIMATION_H_
     2#define MYTHANIMATION_H_
     3
     4#include "xmlparsebase.h"
     5#include <QVariantAnimation>
     6
     7class MythUIType;
     8
     9struct Effects
     10{
     11    int alpha;
     12    float zoom;
     13    float angle;
     14    Effects(int alpha_ = 255, float zoom_ = 1.0, float angle_ = 0.0) : alpha(alpha_), zoom(zoom_), angle(angle_) {}
     15};
     16
     17class MythAnimation : public QVariantAnimation, XMLParseBase
     18{
     19  public:
     20    enum Type {Alpha, Position, Size, Zoom, Angle};
     21    enum When {AboutToHide, AboutToShow};
     22
     23    MythAnimation(MythUIType* parent = NULL, Type type = Position);
     24
     25    void Activate(void);
     26    void CopyFrom(const MythAnimation* animation);
     27    bool ParseElement(const QDomElement& element);
     28    When GetWhen(void) const;
     29
     30    QVariant value() const { return m_value; }
     31
     32    void updateCurrentValue(const QVariant& value);
     33
     34    void incrementCurrentTime(void);
     35
     36    void setEasingCurve(const QString& curve);
     37    void setEasingCurve(QEasingCurve curve);
     38
     39  private:
     40    void parseAlpha(const QDomElement& element, QVariant& startValue, QVariant& endValue);
     41    void parsePosition(const QDomElement& element, QVariant& startValue, QVariant& endValue);
     42    void parseSize(const QDomElement& element, QVariant& startValue, QVariant& endValue);
     43    void parseZoom(const QDomElement& element, QVariant& startValue, QVariant& endValue);
     44    void parseAngle(const QDomElement& element, QVariant& startValue, QVariant& endValue);
     45
     46    MythUIType* m_parent;
     47    Type m_type;
     48    When m_when;
     49    QVariant m_value;
     50    bool m_active;
     51    bool m_looped;
     52    bool m_reversible;
     53};
     54
     55#endif
  • mythtv/libs/libmythui/mythmainwindow.cpp

    diff --git a/mythtv/libs/libmythui/mythmainwindow.cpp b/mythtv/libs/libmythui/mythmainwindow.cpp
    index a01931f..884f892 100644
    a b class MythMainWindowPrivate 
    158158
    159159        sysEventHandler(NULL),
    160160
     161        drawInterval(1000 / 70),
    161162        drawTimer(NULL),
    162163        mainStack(NULL),
    163164
    class MythMainWindowPrivate 
    235236
    236237    QObject *sysEventHandler;
    237238
     239    int drawInterval;
    238240    MythSignalingTimer *drawTimer;
    239241    QVector<MythScreenStack *> stackList;
    240242    MythScreenStack *mainStack;
    MythMainWindow::MythMainWindow(const bool useDB) 
    479481    connect(d->hideMouseTimer, SIGNAL(timeout()), SLOT(HideMouseTimeout()));
    480482
    481483    d->drawTimer = new MythSignalingTimer(this, SLOT(animate()));
    482     d->drawTimer->start(1000 / 70);
     484    d->drawTimer->start(d->drawInterval);
    483485
    484486    d->AllowInput = true;
    485487
    void MythMainWindow::SetUIScreenRect(QRect &rect) 
    24562458    d->uiScreenRect = rect;
    24572459}
    24582460
     2461int MythMainWindow::GetDrawInterval() const
     2462{
     2463    return d->drawInterval;
     2464}
     2465
    24592466void MythMainWindow::StartLIRC(void)
    24602467{
    24612468#ifdef USE_LIRC
  • mythtv/libs/libmythui/mythmainwindow.h

    diff --git a/mythtv/libs/libmythui/mythmainwindow.h b/mythtv/libs/libmythui/mythmainwindow.h
    index 388ca3f..c1702b6 100644
    a b class MUI_PUBLIC MythMainWindow : public QWidget 
    105105    QRect GetUIScreenRect();
    106106    void  SetUIScreenRect(QRect &rect);
    107107
     108    int GetDrawInterval() const;
    108109    int NormalizeFontSize(int pointSize);
    109110    MythRect NormRect(const MythRect &rect);
    110111    QPoint NormPoint(const QPoint &point);
  • mythtv/libs/libmythui/mythpainter.h

    diff --git a/mythtv/libs/libmythui/mythpainter.h b/mythtv/libs/libmythui/mythpainter.h
    index 1625aa2..70bcc48 100644
    a b class QColor; 
    2121
    2222class MythFontProperties;
    2323class MythImage;
     24struct Effects;
    2425
    2526typedef QVector<QTextLayout *>            LayoutVector;
    2627typedef QVector<QTextLayout::FormatRange> FormatVector;
    class MUI_PUBLIC MythPainter 
    6768    virtual void DrawEllipse(const QRect &area, const QBrush &fillBrush,
    6869                             const QPen &linePen, int alpha);
    6970
     71    virtual void SetTransform(const Effects &zoom, QPointF center = QPointF()) { }
     72    virtual void RestoreTransform(void) { }
     73
    7074    MythImage *GetFormatImage();
    7175    void DeleteFormatImage(MythImage *im);
    7276
  • mythtv/libs/libmythui/mythpainter_ogl.cpp

    diff --git a/mythtv/libs/libmythui/mythpainter_ogl.cpp b/mythtv/libs/libmythui/mythpainter_ogl.cpp
    index 2dd047c..85e17fa 100644
    a b void MythOpenGLPainter::DeleteFormatImagePriv(MythImage *im) 
    227227        m_ImageExpireList.remove(im);
    228228    }
    229229}
     230
     231void MythOpenGLPainter::SetTransform(const Effects &fx, QPointF center)
     232{
     233    if (realRender)
     234        realRender->SetTransform(fx, center);
     235}
     236
     237void MythOpenGLPainter::RestoreTransform(void)
     238{
     239    if (realRender)
     240        realRender->RestoreTransform();
     241}
  • mythtv/libs/libmythui/mythpainter_ogl.h

    diff --git a/mythtv/libs/libmythui/mythpainter_ogl.h b/mythtv/libs/libmythui/mythpainter_ogl.h
    index 34fffb0..600c930 100644
    a b class MUI_PUBLIC MythOpenGLPainter : public MythPainter 
    3434                               const QBrush &fillBrush, const QPen &linePen,
    3535                               int alpha);
    3636
     37    virtual void SetTransform(const Effects &fx, QPointF center = QPointF());
     38    virtual void RestoreTransform(void);
     39
    3740  protected:
    3841    virtual MythImage* GetFormatImagePriv(void) { return new MythImage(this); }
    3942    virtual void DeleteFormatImagePriv(MythImage *im);
  • mythtv/libs/libmythui/mythrender_opengl.cpp

    diff --git a/mythtv/libs/libmythui/mythrender_opengl.cpp b/mythtv/libs/libmythui/mythrender_opengl.cpp
    index b7bf454..1d463a3 100644
    a b  
    11#include <algorithm>
    22using namespace std;
    33
     4#include "mythanimation.h"
    45#include "mythlogging.h"
    56#include "mythrender_opengl.h"
    67#include "mythxdisplay.h"
    void MythRenderOpenGL::SetFence(void) 
    258259    doneCurrent();
    259260}
    260261
     262void MythRenderOpenGL::SetTransform(const Effects &fx, QPointF center)
     263{
     264    makeCurrent();
     265    glPushMatrix();
     266    glTranslatef(center.x(), center.y(), 0.0);
     267    glScalef(fx.zoom, fx.zoom, 1.0);
     268    glRotatef(fx.angle, 0, 0, 1);
     269    glTranslatef(-center.x(), -center.y(), 0.0);
     270    doneCurrent();
     271}
     272
     273void MythRenderOpenGL::RestoreTransform(void)
     274{
     275    makeCurrent();
     276    glPopMatrix();
     277    doneCurrent();
     278}
     279
    261280void* MythRenderOpenGL::GetTextureBuffer(uint tex, bool create_buffer)
    262281{
    263282    if (!m_textures.contains(tex))
  • mythtv/libs/libmythui/mythrender_opengl.h

    diff --git a/mythtv/libs/libmythui/mythrender_opengl.h b/mythtv/libs/libmythui/mythrender_opengl.h
    index 05f9384..adc0f8e 100644
    a b  
    3333#include "mythrender_base.h"
    3434#include "mythrender_opengl_defs.h"
    3535
     36struct Effects;
     37
    3638typedef enum
    3739{
    3840    kGLFeatNone    = 0x0000,
    class MUI_PUBLIC MythRenderOpenGL : public QGLContext, public MythRender 
    127129    virtual void SetColor(int r, int g, int b, int a) { }
    128130    void  SetBackground(int r, int g, int b, int a);
    129131    void  SetFence(void);
     132    void  SetTransform(const Effects &fx, QPointF center = QPointF());
     133    void  RestoreTransform(void);
    130134
    131135    void* GetTextureBuffer(uint tex, bool create_buffer = true);
    132136    void  UpdateTexture(uint tex, void *buf);
  • mythtv/libs/libmythui/mythscreentype.cpp

    diff --git a/mythtv/libs/libmythui/mythscreentype.cpp b/mythtv/libs/libmythui/mythscreentype.cpp
    index 0c495a1..ca05ecf 100644
    a b  
    1515#include "mythprogressdialog.h"
    1616#include "mythuigroup.h"
    1717#include "mythlogging.h"
     18#include "mythanimation.h"
    1819
    1920QEvent::Type ScreenLoadCompletionEvent::kEventType =
    2021    (QEvent::Type) QEvent::registerEventType();
    void MythScreenType::aboutToHide(void) 
    237238                GetMythMainWindow()->GetPaintWindow()->setMask(m_SavedMask);
    238239        }
    239240    }
     241
     242    ActivateAnimations(MythAnimation::AboutToHide);
    240243}
    241244
    242245void MythScreenType::aboutToShow(void)
    void MythScreenType::aboutToShow(void) 
    253256            GetMythMainWindow()->GetPaintWindow()->setMask(region);
    254257        }
    255258    }
     259
     260    ActivateAnimations(MythAnimation::AboutToShow);
    256261}
    257262
    258263bool MythScreenType::IsDeleting(void) const
    bool MythScreenType::ParseElement( 
    546551    }
    547552    else
    548553    {
    549         return false;
     554        return MythUIType::ParseElement(filename, element, showWarnings);
    550555    }
    551556
    552557    return true;
  • mythtv/libs/libmythui/mythuitype.cpp

    diff --git a/mythtv/libs/libmythui/mythuitype.cpp b/mythtv/libs/libmythui/mythuitype.cpp
    index c6ce242..45ca7d6 100644
    a b  
    1111#include "mythlogging.h"
    1212
    1313// MythUI headers
     14#include "mythanimation.h"
    1415#include "mythgesture.h"
    1516#include "mythimage.h"
    1617#include "mythpainter.h"
    MythUIType::MythUIType(QObject *parent, const QString &name) 
    4142    m_Area = MythRect(0, 0, 0, 0);
    4243    m_MinArea = MythRect(0, 0, 0, 0);
    4344    m_NeedsRedraw = false;
    44     m_Alpha = 255;
    4545    m_AlphaChangeMode = m_AlphaChange = m_AlphaMin = 0;
    4646    m_AlphaMax = 255;
    4747    m_Moving = false;
    MythUIType::MythUIType(QObject *parent, const QString &name) 
    7171MythUIType::~MythUIType()
    7272{
    7373    delete m_Fonts;
     74    qDeleteAll(m_animations);
    7475}
    7576
    7677/**
    MythUIType *MythUIType::GetChildAt(const QPoint &p, bool recursive, 
    272273    return NULL;
    273274}
    274275
     276void MythUIType::ActivateAnimations(MythAnimation::When when)
     277{
     278    foreach (MythAnimation* animation, m_animations)
     279        if (animation->GetWhen() == when)
     280            animation->Activate();
     281
     282    foreach (MythUIType* uiType, m_ChildrenList)
     283        uiType->ActivateAnimations(when);
     284}
     285
    275286bool MythUIType::NeedsRedraw(void) const
    276287{
    277288    return m_NeedsRedraw;
    void MythUIType::HandleAlphaPulse(void) 
    402413    if (m_AlphaChangeMode == 0)
    403414        return;
    404415
    405     m_Alpha += m_AlphaChange;
     416    m_Effects.alpha += m_AlphaChange;
    406417
    407     if (m_Alpha > m_AlphaMax)
    408         m_Alpha = m_AlphaMax;
     418    if (m_Effects.alpha > m_AlphaMax)
     419        m_Effects.alpha = m_AlphaMax;
    409420
    410     if (m_Alpha < m_AlphaMin)
    411         m_Alpha = m_AlphaMin;
     421    if (m_Effects.alpha < m_AlphaMin)
     422        m_Effects.alpha = m_AlphaMin;
    412423
    413424    // Reached limits so change direction
    414     if (m_Alpha == m_AlphaMax || m_Alpha == m_AlphaMin)
     425    if (m_Effects.alpha == m_AlphaMax || m_Effects.alpha == m_AlphaMin)
    415426    {
    416427        if (m_AlphaChangeMode == 2)
    417428        {
    void MythUIType::Pulse(void) 
    441452    HandleMovementPulse();
    442453    HandleAlphaPulse();
    443454
     455    QList<MythAnimation*>::Iterator i;
     456    for (i = m_animations.begin(); i != m_animations.end(); ++i)
     457        (*i)->incrementCurrentTime();
     458
    444459    QList<MythUIType *>::Iterator it;
    445460
    446461    for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it)
    void MythUIType::Pulse(void) 
    449464
    450465int MythUIType::CalcAlpha(int alphamod)
    451466{
    452     return (int)(m_Alpha * (alphamod / 255.0));
     467    return (int)(m_Effects.alpha * (alphamod / 255.0));
    453468}
    454469
    455470void MythUIType::DrawSelf(MythPainter *, int, int, int, QRect)
    void MythUIType::Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod, 
    470485    if (!realArea.intersects(clipRect))
    471486        return;
    472487
     488    QPointF center(xoffset + m_Area.x() + m_Area.width() / 2.0,
     489                   yoffset + m_Area.y() + m_Area.height() / 2.0);
     490    p->SetTransform(m_Effects, center);
     491
    473492    DrawSelf(p, xoffset, yoffset, alphaMod, clipRect);
    474493
    475494    QList<MythUIType *>::Iterator it;
    void MythUIType::Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod, 
    494513            p->DrawText(realArea, objectName(), 0, font, 255, realArea);
    495514        }
    496515    }
     516
     517    p->RestoreTransform();
    497518}
    498519
    499520void MythUIType::SetPosition(int x, int y)
    void MythUIType::AdjustAlpha(int mode, int alphachange, int minalpha, 
    894915    m_AlphaMin = minalpha;
    895916    m_AlphaMax = maxalpha;
    896917
    897     if (m_Alpha > m_AlphaMax)
    898         m_Alpha = m_AlphaMax;
     918    if (m_Effects.alpha > m_AlphaMax)
     919        m_Effects.alpha = m_AlphaMax;
    899920
    900     if (m_Alpha < m_AlphaMin)
    901         m_Alpha = m_AlphaMin;
     921    if (m_Effects.alpha < m_AlphaMin)
     922        m_Effects.alpha = m_AlphaMin;
    902923}
    903924
    904925void MythUIType::SetAlpha(int newalpha)
    905926{
    906     if (m_Alpha == newalpha)
     927    if (m_Effects.alpha == newalpha)
    907928        return;
    908929
    909     m_Alpha = newalpha;
     930    m_Effects.alpha = newalpha;
    910931    SetRedraw();
    911932}
    912933
    913934int MythUIType::GetAlpha(void) const
    914935{
    915     return m_Alpha;
     936    return m_Effects.alpha;
     937}
     938
     939void MythUIType::SetZoom(float newzoom)
     940{
     941    m_Effects.zoom = newzoom;
     942    SetRedraw();
     943}
     944
     945float MythUIType::GetZoom(void) const
     946{
     947    return m_Effects.zoom;
     948}
     949
     950void MythUIType::SetAngle(float newangle)
     951{
     952    m_Effects.angle = newangle;
     953    SetRedraw();
     954}
     955
     956float MythUIType::GetAngle(void) const
     957{
     958    return m_Effects.angle;
    916959}
    917960
    918961/** \brief Key event handler
    void MythUIType::CopyFrom(MythUIType *base) 
    10521095    m_MinSize = base->m_MinSize;
    10531096    m_Vanish = base->m_Vanish;
    10541097    m_Vanished = false;
    1055     m_Alpha = base->m_Alpha;
     1098    m_Effects = base->m_Effects;
    10561099    m_AlphaChangeMode = base->m_AlphaChangeMode;
    10571100    m_AlphaChange = base->m_AlphaChange;
    10581101    m_AlphaMin = base->m_AlphaMin;
    void MythUIType::CopyFrom(MythUIType *base) 
    10631106    m_XYSpeed = base->m_XYSpeed;
    10641107    m_deferload = base->m_deferload;
    10651108
     1109    QList<MythAnimation*>::Iterator i;
     1110    for (i = base->m_animations.begin(); i != base->m_animations.end(); ++i)
     1111    {
     1112        MythAnimation* animation = new MythAnimation(this);
     1113        animation->CopyFrom(*i);
     1114        m_animations.push_back(animation);
     1115    }
     1116
    10661117    QList<MythUIType *>::Iterator it;
    10671118
    10681119    for (it = base->m_ChildrenList.begin(); it != base->m_ChildrenList.end();
    bool MythUIType::ParseElement( 
    11161167    }
    11171168    else if (element.tagName() == "alpha")
    11181169    {
    1119         m_Alpha = getFirstText(element).toInt();
     1170        m_Effects.alpha = getFirstText(element).toInt();
    11201171        m_AlphaChangeMode = 0;
    11211172    }
    11221173    else if (element.tagName() == "alphapulse")
    11231174    {
    11241175        m_AlphaChangeMode = 2;
    11251176        m_AlphaMin = element.attribute("min", "0").toInt();
    1126         m_Alpha = m_AlphaMax = element.attribute("max", "255").toInt();
     1177        m_Effects.alpha = m_AlphaMax = element.attribute("max", "255").toInt();
    11271178
    11281179        if (m_AlphaMax > 255)
    1129             m_Alpha = m_AlphaMax = 255;
     1180            m_Effects.alpha = m_AlphaMax = 255;
    11301181
    11311182        if (m_AlphaMin < 0)
    11321183            m_AlphaMin = 0;
    bool MythUIType::ParseElement( 
    11461197    {
    11471198        m_helptext = getFirstText(element);
    11481199    }
     1200    else if (element.tagName() == "animation")
     1201    {
     1202        MythAnimation* animation = new MythAnimation(this);
     1203        if (animation->ParseElement(element))
     1204            m_animations.push_back(animation);
     1205        else
     1206            delete animation;
     1207    }
    11491208    else
    11501209        return false;
    11511210
  • mythtv/libs/libmythui/mythuitype.h

    diff --git a/mythtv/libs/libmythui/mythuitype.h b/mythtv/libs/libmythui/mythuitype.h
    index 99ce423..f24a982 100644
    a b  
    99#include <QColor>
    1010
    1111#include "xmlparsebase.h"
     12#include "mythanimation.h"
    1213#include "mythrect.h"
    1314#include "mythgesture.h"
    1415#include "mythmedia.h"
    class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase 
    9899    bool MoveToTop(void);
    99100    bool MoveChildToTop(MythUIType *child);
    100101
     102    void ActivateAnimations(MythAnimation::When when);
     103
    101104    // Called each draw pulse.  Will redraw automatically if dirty afterwards
    102105    virtual void Pulse(void);
    103106
    class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase 
    153156    virtual MythPainter *GetPainter(void);
    154157    void SetPainter(MythPainter *painter) { m_Painter = painter; }
    155158
     159    void SetZoom(float zoom);
     160    float GetZoom(void) const;
     161
     162    void SetAngle(float angle);
     163    float GetAngle(void) const;
     164
    156165  protected:
    157166    virtual void customEvent(QEvent *);
    158167
    class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase 
    217226    QRegion m_DirtyRegion;
    218227    bool m_NeedsRedraw;
    219228
    220     int m_Alpha;
     229    Effects m_Effects;
     230
    221231    int m_AlphaChangeMode; // 0 - none, 1 - once, 2 - cycle
    222232    int m_AlphaChange;
    223233    int m_AlphaMin;
    class MUI_PUBLIC MythUIType : public QObject, public XMLParseBase 
    232242    MythUIType *m_Parent;
    233243    MythPainter *m_Painter;
    234244
     245    QList<MythAnimation*> m_animations;
    235246    QString m_helptext;
    236247
    237248    bool m_deferload;