From: cboissie Date: Tue, 10 May 2011 14:15:20 +0000 (+0200) Subject: Fills the map with a background tile X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ccb21c7e2706279415104bbe270393c3bd653721;p=Bug_Attack.git Fills the map with a background tile --- diff --git a/Bug_Attack.pro b/Bug_Attack.pro index b26ff18..35561fe 100644 --- a/Bug_Attack.pro +++ b/Bug_Attack.pro @@ -11,8 +11,10 @@ TEMPLATE = app SOURCES += main.cpp\ - mainwindow.cpp + mainwindow.cpp \ + tile.cpp -HEADERS += mainwindow.h +HEADERS += mainwindow.h \ + tile.h FORMS += mainwindow.ui diff --git a/mainwindow.cpp b/mainwindow.cpp index 49d64fc..f8847ff 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,6 +6,27 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + + + /// Test : try to draw some tiles into the QGraphicView + + _scene = new QGraphicsScene(parent); + _view = ui->graphicsView; + _view->setScene(_scene); + + QPixmap grass("media/textures/grass.jpg"); + grass = grass.scaled(32,32,Qt::IgnoreAspectRatio); + for(int i = 0; i < 16; ++i){ + for(int j = 0; j < 16 ; ++j){ + + _grassTile = _scene->addPixmap(grass); + _grassTile->setPos(32*i,32*j); + + } + } + + _view->show(); + } MainWindow::~MainWindow() diff --git a/mainwindow.h b/mainwindow.h index c9fd6a9..5342c79 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,9 @@ #define MAINWINDOW_H #include +#include +#include +#include namespace Ui { class MainWindow; @@ -17,6 +20,11 @@ public: private: Ui::MainWindow *ui; + + + QGraphicsScene *_scene; + QGraphicsView *_view; + QGraphicsPixmapItem *_grassTile; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 6050363..1c681f6 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -1,24 +1,211 @@ + MainWindow - - + + + true + + 0 0 - 400 - 300 + 800 + 600 - + + + 800 + 600 + + + + + 800 + 600 + + + MainWindow - - - - + + + + 800 + 600 + + + + + 800 + 600 + + + + + + 530 + 10 + 261 + 581 + + + + + + + + 0 + 0 + + + + + 0 + 10 + + + + + 16777215 + 20 + + + + TextLabel + + + + + + + PushButton + + + + + + + + + TextLabel + + + + + + + + + + + + + + TextLabel + + + + + + + + + + + + GroupBox + + + + + + + true + + + GroupBox + + + false + + + + + 90 + 40 + 67 + 17 + + + + TextLabel + + + + + + 20 + 80 + 98 + 27 + + + + PushButton + + + + + + 140 + 80 + 98 + 27 + + + + PushButton + + + + + + + + + + 10 + 40 + 512 + 512 + + + + + 512 + 512 + + + + + 512 + 512 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + - - + diff --git a/media/textures/grass.jpg b/media/textures/grass.jpg new file mode 100644 index 0000000..04caa28 Binary files /dev/null and b/media/textures/grass.jpg differ diff --git a/tile.cpp b/tile.cpp new file mode 100644 index 0000000..2b5a245 --- /dev/null +++ b/tile.cpp @@ -0,0 +1,8 @@ +#include "tile.h" + +Tile::Tile():QGraphicsPixmapItem() +{ + this->setPixmap(QPixmap("media/textures/grass.jpg")); + + +} diff --git a/tile.h b/tile.h new file mode 100644 index 0000000..562cff2 --- /dev/null +++ b/tile.h @@ -0,0 +1,12 @@ +#ifndef TILE_H +#define TILE_H + +#include + +class Tile : public QGraphicsPixmapItem +{ +public: + Tile(); +}; + +#endif // TILE_H