Skip to content

Instantly share code, notes, and snippets.

@maraigue
Created May 24, 2016 13:26
Show Gist options
  • Save maraigue/cb4a58fcdc964d5d10976f037b442521 to your computer and use it in GitHub Desktop.
Save maraigue/cb4a58fcdc964d5d10976f037b442521 to your computer and use it in GitHub Desktop.
sapporocpp/4moku https://github.com/sapporocpp/4moku Qt版の表示内容の大枠を作ってみているところ
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::paintEvent(QPaintEvent *){
// 盤面の大きさ
// (将来的に、Boardクラスから引っ張るようにする)
int size_x = 10;
int size_y = 5;
// 1マスのサイズを決める
const QRect window_size = this->geometry();
const int gridsize = std::min(window_size.height()/size_y, window_size.width()/size_x);
/*
std::cerr << "desktopsize.width = " << window_size.width() << std::endl;
std::cerr << "desktopsize.height = " << window_size.height() << std::endl;
std::cerr << "gridsize = " << gridsize << std::endl;
*/
// 描画
// 参考:http://memotiyou.blogspot.jp/2011/12/qt-c-qpainter_9359.html
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap));
const QBrush brush_white_stone(Qt::white, Qt::SolidPattern);
const QBrush brush_black_stone(Qt::black, Qt::SolidPattern);
const QBrush brush_board_stone(QColor(255, 255, 224), Qt::SolidPattern);
for(int x = 0; x < size_x; ++x){
for(int y = 0; y < size_y; ++y){
// (x, y)の点の情報を表示
// (将来的に、Boardクラスから引っ張るようにする)
const int place_left = x * gridsize;
const int place_top = (size_y - y - 1) * gridsize;
painter.setBrush(brush_board_stone);
painter.drawRect(place_left, place_top, gridsize, gridsize);
switch((x + y) % 3){
case 0:
painter.setBrush(brush_white_stone);
painter.drawEllipse(place_left, place_top, gridsize, gridsize);
break;
case 1:
painter.setBrush(brush_black_stone);
painter.drawEllipse(place_left, place_top, gridsize, gridsize);
break;
default:
// どちらの石も置かれていない
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment