-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathNavigator.cpp
107 lines (86 loc) · 2.73 KB
/
Navigator.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
///////////
// This file is a part of the ATools project
// Some parts of code are the property of Microsoft, Qt or Aeonsoft
// The rest is released without license and without any warranty
///////////
#include "stdafx.h"
#include "Navigator.h"
#include <World.h>
#include "MainFrame.h"
CNavigator::CNavigator(QWidget* parent, Qt::WindowFlags flags)
: QWidget(parent, flags),
m_world(null)
{
setMinimumHeight(100);
setAutoFillBackground(false);
setMouseTracking(false);
}
void CNavigator::paintEvent(QPaintEvent* event)
{
if (!m_world)
{
event->accept();
return;
}
QPainter painter;
painter.begin(this);
const QRectF rect(QPointF(event->rect().left() + 1, event->rect().top() + 1),
QPointF(event->rect().right(), event->rect().bottom()));
const float worldWidth = m_world->m_width;
const float worldHeight = m_world->m_height;
const float landWidth = (rect.width() - worldWidth) / worldWidth;
const float landHeight = (rect.height() - worldHeight) / worldHeight;
QBrush light(QColor(208, 208, 208)), dark(QColor(128, 128, 128));
int x, y;
for (x = 0; x < m_world->m_width; x++)
{
for (y = 0; y < m_world->m_height; y++)
{
painter.fillRect(QRectF(
rect.left() + (float)x * (landWidth + 1.0f),
rect.bottom() - ((float)y * (landHeight + 1.0f)),
landWidth, -landHeight).normalized(),
m_world->GetLand(x, y) ? dark : light);
}
}
const D3DXVECTOR3 camPos = m_world->m_cameraPos;
if (m_world->VecInWorld(camPos))
{
painter.fillRect(QRectF(
rect.left() + (rect.width() / (worldWidth * (float)MAP_SIZE * (float)MPU)) * camPos.x - 1.5f,
rect.bottom() - ((rect.height() / (worldHeight * (float)MAP_SIZE * (float)MPU)) * camPos.z - 1.5f),
3.0f, 3.0f),
QBrush(QColor(0, 0, 255)));
}
painter.end();
event->accept();
}
void CNavigator::mouseDoubleClickEvent(QMouseEvent* event)
{
if (event->button() != Qt::LeftButton)
return;
if (!m_world)
{
event->accept();
return;
}
const QRectF rect(QPointF(1, 1), QPointF(width(), height()));
const float worldWidth = m_world->m_width;
const float worldHeight = m_world->m_height;
m_world->m_cameraPos.x = (rect.left() - 1.5f - (float)event->x()) / (-(rect.width() / (worldWidth * (float)MAP_SIZE * (float)MPU)));
m_world->m_cameraPos.z = (rect.bottom() + 1.5f - (float)event->y()) / (rect.height() / (worldHeight * (float)MAP_SIZE * (float)MPU));
m_world->m_cameraAngle.x = 0.0f;
m_world->m_cameraAngle.y = -89.89f;
m_world->_loadLndFiles();
m_world->m_cameraPos.y = m_world->GetHeight(m_world->m_cameraPos.x, m_world->m_cameraPos.z) + 200.0f;
if (m_world->m_cameraPos.y > 999.0f)
m_world->m_cameraPos.y = 999.0f;
event->accept();
MainFrame->UpdateWorldEditor();
update();
}
void CNavigator::SetWorld(CWorld* world)
{
m_world = world;
update();
}