-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpuzzlemenuitems.cpp
148 lines (126 loc) · 3.71 KB
/
puzzlemenuitems.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "puzzlemenuitems.h"
#include <QVector>
#include <QPixmap>
#include <QFileInfo>
#include <QDir>
#include <QPainter>
#include "pixmapoperations.h"
#define LOGICAL_WIDTH 1024
#define LOGICAL_HEIGHT 600
// Total color number of the items
const static int kTotalItems = 3;
// File path of the items
// (The last two are the same as two before them, may make
// cause some bug later)
const static char * kItemPaths[] =
{":/images/puzzlemenuitems/exchange_theme*.png",
":/images/puzzlemenuitems/unite_theme*.png",
":/images/puzzlemenuitems/lock_theme*.png"};
// Pixmaps of the items
QVector<QVector<QPixmap> > puzzleMenuItemPixmaps;
// Total frame count of the items
QVector<int> puzzleMenuItemFrameCounts;
void initPuzzleMenuItemPixmaps()
{
initPixmaps(kTotalItems,
kItemPaths,
puzzleMenuItemPixmaps,
puzzleMenuItemFrameCounts);
}
const QPixmap& AbstractPuzzleMenuItem::pixmap(ItemType type,
int frame)
{
// Init pixmaps if neccessary
if (puzzleMenuItemPixmaps.isEmpty())
initPuzzleMenuItemPixmaps();
return puzzleMenuItemPixmaps[type][frame % puzzleMenuItemFrameCounts[type]];
}
double AbstractPuzzleMenuItem::width()
{
return 300;
}
double AbstractPuzzleMenuItem::height()
{
return 300;
}
PuzzleMenuExchangeItem::PuzzleMenuExchangeItem()
{
setPos(QPointF(0, 0));
}
void PuzzleMenuExchangeItem::paint(QPainter *painter,
int width,
int height,
int frame)
{
// Get the pixmap
const QPixmap& pixmap = AbstractPuzzleMenuItem::pixmap(
AbstractPuzzleMenuItem::ExchangeItem,
frame);
// Calculate the values to locate
double x = getPos().x() * width;
double y = getPos().y() * height;
double xRate = 1.0 * width / LOGICAL_WIDTH;
double yRate = 1.0 * height / LOGICAL_HEIGHT;
// draw the pixmap
drawPixmapAt(painter,
pixmap,
xRate,
yRate,
QPointF(x, y),
true,
true);
}
PuzzleMenuUniteItem::PuzzleMenuUniteItem()
{
setPos(QPointF(0, 0));
}
void PuzzleMenuUniteItem::paint(QPainter *painter,
int width,
int height,
int frame)
{
// Get the pixmap
const QPixmap& pixmap = AbstractPuzzleMenuItem::pixmap(
AbstractPuzzleMenuItem::UniteItem,
frame);
// Calculate the values to locate
double x = getPos().x() * width;
double y = getPos().y() * height;
double xRate = 1.0 * width / LOGICAL_WIDTH;
double yRate = 1.0 * height / LOGICAL_HEIGHT;
// draw the pixmap
drawPixmapAt(painter,
pixmap,
xRate,
yRate,
QPointF(x, y),
true,
true);
}
PuzzleMenuLockItem::PuzzleMenuLockItem()
{
setPos(QPointF(0, 0));
}
void PuzzleMenuLockItem::paint(QPainter *painter,
int width,
int height,
int frame)
{
// Get the pixmap
const QPixmap& pixmap = AbstractPuzzleMenuItem::pixmap(
AbstractPuzzleMenuItem::LockItem,
frame);
// Calculate the values to locate
double x = getPos().x() * width;
double y = getPos().y() * height;
double xRate = 1.0 * width / LOGICAL_WIDTH;
double yRate = 1.0 * height / LOGICAL_HEIGHT;
// draw the pixmap
drawPixmapAt(painter,
pixmap,
xRate,
yRate,
QPointF(x, y),
true,
true);
}