ff7tk  0.02
Toolkit for making FF7 Tools
SaveIcon.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  **
3  ** Copyright (C) 2010 Arzel Jérôme <myst6re@gmail.com>
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 3 of the License, or
8  ** (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, see <http://www.gnu.org/licenses/>.
17  ****************************************************************************/
18 
19 #include "SaveIcon.h"
20 
21 QTimer SaveIcon::timer;
22 
24  : nbFrames(0), curFrame(0)
25 {
26 }
27 
28 SaveIcon::SaveIcon(QByteArray data, quint8 nbFrames)
29  : curFrame(0)
30 {
31  setAll(data, nbFrames);
32 }
33 SaveIcon::SaveIcon(QList<QByteArray> data)
34  : curFrame(0)
35 {
36  setAll(data);
37 }
38 void SaveIcon::setAll(QByteArray data, quint8 nbFrames)
39 {
40  this->data = data;
41  this->nbFrames = nbFrames;
42  if(nbFrames>1)
43  {
44  connect(&timer, SIGNAL(timeout()), SLOT(nextFrame()));
45  timer.start(160);
46  }
47 }
48 
49 void SaveIcon::setAll(QList<QByteArray> data)
50 {
51  this->data.clear();
52  this->nbFrames=data.size();
53  for(int i=0;i < this->nbFrames;i++)
54  {
55  this->data.append(data.at(i));
56  }
57  if(nbFrames>1)
58  {
59  connect(&timer, SIGNAL(timeout()), SLOT(nextFrame()));
60  timer.start(160);
61  }
62 }
63 QByteArray SaveIcon::sauver()
64 {
65  return data;
66 }
67 
68 QPixmap SaveIcon::icon(bool chocobo_world_icon)
69 {
70  quint16 i;
71  quint8 y=0, x=0;
72 
73  if(data.isEmpty()) return QPixmap();
74 
75  if(!chocobo_world_icon)
76  {
77  //palette
78  const char *access_data = data.constData();
79  QList<QRgb> colors;
80  quint16 color;
81  for(i=0 ; i<16 ; ++i)
82  {
83  memcpy(&color, access_data, 2);
84  colors.append(qRgb((color & 31)*8.2258, (color>>5 & 31)*8.2258, (color>>10 & 31)*8.2258));
85  access_data += 2;
86  }
87 
88  QImage image(16, 16, QImage::Format_RGB32);
89  quint8 index;
90  quint16 firstPos = 32+curFrame*128, lastPos = firstPos+128;
91 
92  if(data.size()<lastPos) return QPixmap();
93 
94  for(i=firstPos ; i<lastPos ; ++i)
95  {
96  index = (quint8)data.at(i);
97 
98  image.setPixel(x, y, colors.at(index & 0xF));
99 
100  if(x == 15)
101  {
102  x = 0;
103  ++y;
104  }
105  else
106  ++x;
107 
108  image.setPixel(x, y, colors.at(index >> 4));
109 
110  if(x == 15)
111  {
112  x = 0;
113  ++y;
114  }
115  else
116  ++x;
117  }
118 
119  return QPixmap::fromImage(image);
120  }
121 
122  if(data.size()!=288) return QPixmap();
123 
124  QImage image(32, 32, QImage::Format_Mono);
125  quint8 j, curPx;
126 
127  for(i=160 ; i<288 ; ++i)
128  {
129  curPx = (quint8)data.at(i);
130  for(j=0 ; j<8 ; ++j)
131  {
132  image.setPixel(x, y, !((curPx >> j) & 1));
133 
134  if(x == 31)
135  {
136  x = 0;
137  ++y;
138  }
139  else
140  ++x;
141  }
142  }
143 
144  return QPixmap::fromImage(image);
145 }
146 
148 {
149  if(nbFrames==0) return;
150 
151  curFrame = (curFrame + 1) % nbFrames;
152  QPixmap pix = icon();
153 
154  if(!pix.isNull())
155  emit nextIcon(pix);
156 }
QByteArray sauver()
incase you wish to write the icon to a file
Definition: SaveIcon.cpp:63
void setAll(QByteArray data, quint8 nbFrames=1)
fill SaveIcon with data
Definition: SaveIcon.cpp:38
void nextFrame()
get get next icon if more then one frame
Definition: SaveIcon.cpp:147
QPixmap icon(bool chocobo_world_icon=false)
pixmap of your icon
Definition: SaveIcon.cpp:68
SaveIcon()
create a new Save icon
Definition: SaveIcon.cpp:23
static QTimer timer
frame change timer.
Definition: SaveIcon.h:76
QByteArray data
hold our icon data
Definition: SaveIcon.h:74
quint8 curFrame
current Frame
Definition: SaveIcon.h:75
quint8 nbFrames
number of frames
Definition: SaveIcon.h:75
void nextIcon(QPixmap)
Emit Signal: Time to update your QPixmap. connect to object your displaying on to tell it time for a ...