-
Notifications
You must be signed in to change notification settings - Fork 0
/
danmakuview.cpp
60 lines (44 loc) · 1.31 KB
/
danmakuview.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
#include "danmakuview.h"
#include <QPainter>
#include <QMouseEvent>
#include "scene.h"
#include "bosstemplate.h"
#include "drawable.h"
DanmakuView::DanmakuView(QWidget *parent) :
QWidget(parent)
{
setMinimumSize(480,640);
setMaximumSize(480,640);
setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
setMouseTracking(true);
m_sceneTemplate = SceneTemplate::create();
m_scene = m_sceneTemplate->run();
}
void DanmakuView::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.fillRect(rect(),Qt::black);
p.setPen(Qt::white);
p.drawRect(QRect(0,0,479,639));
// Draw the scene
if(m_scene)
{
foreach(sBoss boss,m_scene->m_lbBosses)
{
boss->doPhysics();
sDrawable draw = boss->m_btTemplate->m_dImage;
QPointF pos = boss->m_location;
draw->paint(pos.x(),pos.y(),p);
}
}
p.drawLine(0,m_pMouse.y(),width(),m_pMouse.y());
p.drawLine(m_pMouse.x(),0,m_pMouse.x(),height());
QRect text=p.fontMetrics().boundingRect(QString("(X: %1,Y: %2)").arg(m_pMouse.x()).arg(m_pMouse.y()));
text.moveBottomLeft(QPoint(0,height()));
p.drawText(text,QString("(X: %1,Y: %2)").arg(m_pMouse.x()).arg(m_pMouse.y()));
}
void DanmakuView::mouseMoveEvent(QMouseEvent *ev)
{
m_pMouse = ev->pos();
update();
}