]> khamidou — GitHub mirrors - Bug_Attack.git/commitdiff
Fills the map with a background tile
authorcboissie <clemzbox@gmail.com>
Tue, 10 May 2011 14:15:20 +0000 (16:15 +0200)
committercboissie <clemzbox@gmail.com>
Tue, 10 May 2011 14:15:20 +0000 (16:15 +0200)
Bug_Attack.pro
mainwindow.cpp
mainwindow.h
mainwindow.ui
media/textures/grass.jpg [new file with mode: 0644]
tile.cpp [new file with mode: 0644]
tile.h [new file with mode: 0644]

index b26ff18408f49e4fd8b0f70f504c6bbf466a5c8f..35561fe8d1e56660e84693c353a2febf349d270c 100644 (file)
@@ -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
index 49d64fce7cedf4ed8c5e0124cfe43e90c23c6ab6..f8847ffef9de55e58314ea244a1d0a014d950fcf 100644 (file)
@@ -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()
index c9fd6a915868abc8d836c38f7280a0f457960283..5342c7951153c23354706ed8fb89bc9fe76a70ad 100644 (file)
@@ -2,6 +2,9 @@
 #define MAINWINDOW_H
 
 #include <QMainWindow>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+#include <QGraphicsPixmapItem>
 
 namespace Ui {
     class MainWindow;
@@ -17,6 +20,11 @@ public:
 
 private:
     Ui::MainWindow *ui;
+
+
+    QGraphicsScene *_scene;
+    QGraphicsView *_view;
+    QGraphicsPixmapItem *_grassTile;
 };
 
 #endif // MAINWINDOW_H
index 6050363fa71ed2da04105077f9fef06150d05ee2..1c681f6a856951da3b3940026671c3a51ff6260c 100644 (file)
+<?xml version="1.0" encoding="UTF-8"?>
 <ui version="4.0">
  <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow" >
-  <property name="geometry" >
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="enabled">
+   <bool>true</bool>
+  </property>
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>400</width>
-    <height>300</height>
+    <width>800</width>
+    <height>600</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="minimumSize">
+   <size>
+    <width>800</width>
+    <height>600</height>
+   </size>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>800</width>
+    <height>600</height>
+   </size>
+  </property>
+  <property name="windowTitle">
    <string>MainWindow</string>
   </property>
-  <widget class="QMenuBar" name="menuBar" />
-  <widget class="QToolBar" name="mainToolBar" />
-  <widget class="QWidget" name="centralWidget" />
-  <widget class="QStatusBar" name="statusBar" />
+  <widget class="QWidget" name="centralWidget">
+   <property name="minimumSize">
+    <size>
+     <width>800</width>
+     <height>600</height>
+    </size>
+   </property>
+   <property name="maximumSize">
+    <size>
+     <width>800</width>
+     <height>600</height>
+    </size>
+   </property>
+   <widget class="QWidget" name="verticalLayoutWidget">
+    <property name="geometry">
+     <rect>
+      <x>530</x>
+      <y>10</y>
+      <width>261</width>
+      <height>581</height>
+     </rect>
+    </property>
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="minimumSize">
+        <size>
+         <width>0</width>
+         <height>10</height>
+        </size>
+       </property>
+       <property name="maximumSize">
+        <size>
+         <width>16777215</width>
+         <height>20</height>
+        </size>
+       </property>
+       <property name="text">
+        <string>TextLabel</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pushButton">
+       <property name="text">
+        <string>PushButton</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item>
+        <widget class="QLabel" name="label_2">
+         <property name="text">
+          <string>TextLabel</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLCDNumber" name="lcdNumber"/>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <layout class="QHBoxLayout" name="horizontalLayout_3">
+       <item>
+        <widget class="QLabel" name="label_3">
+         <property name="text">
+          <string>TextLabel</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLCDNumber" name="lcdNumber_2"/>
+       </item>
+      </layout>
+     </item>
+     <item>
+      <widget class="QGroupBox" name="groupBox">
+       <property name="title">
+        <string>GroupBox</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QGroupBox" name="groupBox_2">
+       <property name="enabled">
+        <bool>true</bool>
+       </property>
+       <property name="title">
+        <string>GroupBox</string>
+       </property>
+       <property name="flat">
+        <bool>false</bool>
+       </property>
+       <widget class="QLabel" name="label_4">
+        <property name="geometry">
+         <rect>
+          <x>90</x>
+          <y>40</y>
+          <width>67</width>
+          <height>17</height>
+         </rect>
+        </property>
+        <property name="text">
+         <string>TextLabel</string>
+        </property>
+       </widget>
+       <widget class="QPushButton" name="pushButton_2">
+        <property name="geometry">
+         <rect>
+          <x>20</x>
+          <y>80</y>
+          <width>98</width>
+          <height>27</height>
+         </rect>
+        </property>
+        <property name="text">
+         <string>PushButton</string>
+        </property>
+       </widget>
+       <widget class="QPushButton" name="pushButton_3">
+        <property name="geometry">
+         <rect>
+          <x>140</x>
+          <y>80</y>
+          <width>98</width>
+          <height>27</height>
+         </rect>
+        </property>
+        <property name="text">
+         <string>PushButton</string>
+        </property>
+       </widget>
+      </widget>
+     </item>
+    </layout>
+   </widget>
+   <widget class="QGraphicsView" name="graphicsView">
+    <property name="geometry">
+     <rect>
+      <x>10</x>
+      <y>40</y>
+      <width>512</width>
+      <height>512</height>
+     </rect>
+    </property>
+    <property name="minimumSize">
+     <size>
+      <width>512</width>
+      <height>512</height>
+     </size>
+    </property>
+    <property name="maximumSize">
+     <size>
+      <width>512</width>
+      <height>512</height>
+     </size>
+    </property>
+    <property name="verticalScrollBarPolicy">
+     <enum>Qt::ScrollBarAlwaysOff</enum>
+    </property>
+    <property name="horizontalScrollBarPolicy">
+     <enum>Qt::ScrollBarAlwaysOff</enum>
+    </property>
+    <property name="alignment">
+     <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+    </property>
+   </widget>
+  </widget>
  </widget>
- <layoutDefault spacing="6" margin="11" />
- <pixmapfunction></pixmapfunction>
+ <layoutdefault spacing="6" margin="11"/>
  <resources/>
  <connections/>
 </ui>
diff --git a/media/textures/grass.jpg b/media/textures/grass.jpg
new file mode 100644 (file)
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 (file)
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 (file)
index 0000000..562cff2
--- /dev/null
+++ b/tile.h
@@ -0,0 +1,12 @@
+#ifndef TILE_H
+#define TILE_H
+
+#include <QGraphicsPixmapItem>
+
+class Tile : public QGraphicsPixmapItem
+{
+public:
+    Tile();
+};
+
+#endif // TILE_H