Skip to content

Commit

Permalink
perf: smooth painter and dump to v0.3.04. 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
Joker2770 committed Apr 5, 2023
1 parent f5c45fb commit da4a373
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
36 changes: 21 additions & 15 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ MainWindow::MainWindow(QWidget *parent)
QPixmap pm;
pm.load(":/skins/HGarden2.bmp");
for (size_t i = 0; i < 5; i++)
{
this->m_images.push_back(pm.copy(i * 20, 0, 20, 20).scaled(RECT_WIDTH, RECT_HEIGHT));
}
this->m_images.push_back(pm.copy(i * 20, 0, 20, 20).scaled(RECT_WIDTH, RECT_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation));

this->m_freeStyleGomoku = new FreeStyleGomoku();
this->m_standardGomoku = new StandardGomoku();
Expand Down Expand Up @@ -365,6 +363,9 @@ void MainWindow::DrawMark()
QPainter painter(this);
QPoint pMark;
painter.setBrush(Qt::red);
painter.setRenderHints(QPainter::Antialiasing, true);
painter.setRenderHints(QPainter::SmoothPixmapTransform, true);

pair<int, int> last_move_pos = this->mBoard->coord2idx(this->mBoard->getVRecord().back().first);
pMark.setX(last_move_pos.first + 1);
pMark.setY(last_move_pos.second + 2);
Expand All @@ -389,6 +390,8 @@ void MainWindow::DrawItems()
{
QPainter painter(this);
painter.setPen(QPen(QColor(Qt::transparent)));
painter.setRenderHints(QPainter::Antialiasing, true);
painter.setRenderHints(QPainter::SmoothPixmapTransform, true);

for (size_t i = 0; i < this->mBoard->getVRecord().size(); i++)
{
Expand Down Expand Up @@ -455,22 +458,25 @@ void MainWindow::DrawTimeLeft()
}

if (0 != this->m_time_left_p1)
painter.drawText(50, 30, 150, 50, Qt::AlignLeft, QString::fromStdString(to_string(this->m_time_left_p1) + "ms"));
painter.drawText(50, (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignLeft, QString::fromStdString(to_string(this->m_time_left_p1) + "ms"));
else
painter.drawText(50, 30, 150, 50, Qt::AlignLeft, "TIMEOUT");
painter.drawText(50, (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignLeft, "TIMEOUT");

if (0 != this->m_time_left_p2)
painter.drawText(this->geometry().width() - 200, 30, 150, 50, Qt::AlignRight, QString::fromStdString(to_string(this->m_time_left_p2) + "ms"));
painter.drawText(this->geometry().width() - 200, (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignRight, QString::fromStdString(to_string(this->m_time_left_p2) + "ms"));
else
painter.drawText(this->geometry().width() - 200, 30, 150, 50, Qt::AlignRight, "TIMEOUT");
painter.drawText(this->geometry().width() - 200, (int)(RECT_HEIGHT * 0.8), 150, 50, Qt::AlignRight, "TIMEOUT");
}

void MainWindow::DrawPlayerState()
{
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing, true);
painter.setRenderHints(QPainter::SmoothPixmapTransform, true);

QPoint pPos;
pair<int, int> pos_1(30, 35);
pair<int, int> pos_2(this->geometry().width() - 30, 35);
pair<int, int> pos_1((int)(RECT_WIDTH * 0.8), RECT_HEIGHT);
pair<int, int> pos_2(this->geometry().width() - (int)(RECT_WIDTH * 0.8), RECT_HEIGHT);

if ((GAME_STATE::PLAYING == this->mState) && (this->m_bOK_P1 || !(this->m_manager->m_p1->m_isComputer)))
{
Expand Down Expand Up @@ -560,10 +566,10 @@ void MainWindow::DrawIndication()
painter.setPen(QPen(QColor(Qt::black), 2));

for (size_t i = 0; i < this->mBoard->getBSize().first; i++)
painter.drawText((i + 1) * RECT_WIDTH + 5, 60, 20, 20, Qt::AlignRight, QString::fromStdString(to_string(i)));
painter.drawText((i + 1) * RECT_WIDTH + 5, (int)(RECT_HEIGHT * 1.5), 20, 20, Qt::AlignRight, QString::fromStdString(to_string(i)));

for (size_t i = 0; i < this->mBoard->getBSize().second; i++)
painter.drawText(15, (i + 2) * RECT_HEIGHT + 10, 20, 20, Qt::AlignBottom, QString::fromStdString(to_string(i)));
painter.drawText((int)(RECT_WIDTH * 0.5), (i + 2) * RECT_HEIGHT + 5, 20, 20, Qt::AlignBottom, QString::fromStdString(to_string(i)));
}
}

Expand Down Expand Up @@ -1263,7 +1269,7 @@ void MainWindow::OnActionSkin()
if (!pm.isNull())
{
for (size_t i = 0; i < 5; i++)
this->m_images.push_back(pm.copy(i * 20, 0, 20, 20).scaled(RECT_WIDTH, RECT_HEIGHT));
this->m_images.push_back(pm.copy(i * 20, 0, 20, 20).scaled(RECT_WIDTH, RECT_HEIGHT, Qt::KeepAspectRatio, Qt::SmoothTransformation));

this->m_bSkin = true;
}
Expand Down Expand Up @@ -1311,15 +1317,15 @@ void MainWindow::OnActionPlayerSetting()
this->m_manager->m_p2->m_sPath = this->m_player_setting->getP2Path();
this->m_manager->m_p1->m_isComputer = !(this->m_player_setting->isP1Human());
this->m_manager->m_p2->m_isComputer = !(this->m_player_setting->isP2Human());
qDebug() << this->m_manager->m_p1->m_sPath;
qDebug() << this->m_manager->m_p2->m_sPath;
qDebug() << "p1: " << this->m_manager->m_p1->m_sPath;
qDebug() << "p2: " << this->m_manager->m_p2->m_sPath;
}
}
}

void MainWindow::OnActionVer()
{
const QString strVerNum = "Ver Num: 0.2.10\n";
const QString strVerNum = "Ver Num: 0.3.04\n";
QString strBuildTime = "Build at ";
strBuildTime.append(__TIMESTAMP__);
strBuildTime.append("\n");
Expand Down
4 changes: 2 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#include "PlayerSettingDialog.h"
#include "timer.h"

#define RECT_WIDTH 40
#define RECT_HEIGHT 40
#define RECT_WIDTH (36)
#define RECT_HEIGHT (36)

typedef enum game_state
{
Expand Down

0 comments on commit da4a373

Please sign in to comment.