~ubuntu-branches/ubuntu/dapper/psi/dapper

« back to all changes in this revision

Viewing changes to src/anim.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2002-04-19 02:28:44 UTC
  • Revision ID: james.westby@ubuntu.com-20020419022844-za7xgai5qyfd9xv6
Tags: upstream-0.8.5
ImportĀ upstreamĀ versionĀ 0.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** anim.cpp - handles animations
 
3
** Copyright (C) 2001, 2002  Justin Karneges
 
4
**
 
5
** This program is free software; you can redistribute it and/or
 
6
** modify it under the terms of the GNU General Public License
 
7
** as published by the Free Software Foundation; either version 2
 
8
** of the License, or (at your option) 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 this program; if not, write to the Free Software
 
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 
18
**
 
19
****************************************************************************/
 
20
 
 
21
#include"anim.h"
 
22
#include<qimage.h>
 
23
 
 
24
Anim::Anim(const QPixmap &pix)
 
25
{
 
26
        QImage image = pix.convertToImage();
 
27
 
 
28
        seq.setAutoDelete(TRUE);
 
29
        qim_seq.setAutoDelete(TRUE);
 
30
 
 
31
        int n;
 
32
        for(n = 0; ((n+1) * 16) <= image.width(); ++n) {
 
33
                seq.resize(n+1);
 
34
                qim_seq.resize(n+1);
 
35
 
 
36
                qim_seq.insert(n, new QImage(image.copy(n * 16, 0, 16, 16)) );
 
37
                seq.insert(n, new QPixmap);
 
38
                seq[n]->convertFromImage(*qim_seq[n]);
 
39
        }
 
40
 
 
41
        // hopefully this never happens
 
42
        if(n == 0) {
 
43
                seq.resize(1);
 
44
                qim_seq.resize(1);
 
45
 
 
46
                seq.insert(0, new QPixmap(16,16));
 
47
                seq[0]->fill(Qt::black);
 
48
                qim_seq.insert(0, new QImage(seq[0]->convertToImage()) );
 
49
                v_isAnim = FALSE;
 
50
                v_numFrames = 0;
 
51
                return;
 
52
        }
 
53
 
 
54
        v_isAnim = FALSE;
 
55
        v_numFrames = n - 1;
 
56
        if(v_numFrames > 0)
 
57
                v_isAnim = TRUE;
 
58
}
 
59
 
 
60
Anim::~Anim()
 
61
{
 
62
}
 
63
 
 
64
QPixmap & Anim::frame(int x)
 
65
{
 
66
        // if we don't have the frame, just return the base
 
67
        if(!seq[x+1])
 
68
                return *seq[0];
 
69
 
 
70
        return *seq[x+1];
 
71
}
 
72
 
 
73
QPixmap & Anim::base()
 
74
{
 
75
        return *seq[0];
 
76
}
 
77
 
 
78
QImage & Anim::qim_frame(int x)
 
79
{
 
80
        if(!qim_seq[x+1])
 
81
                return *qim_seq[0];
 
82
 
 
83
        return *qim_seq[x+1];
 
84
}
 
85
 
 
86
QImage & Anim::qim_base()
 
87
{
 
88
        return *qim_seq[0];
 
89
}
 
90