Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //OOP_aplication.h
- #ifndef APPLICATION_TYPE_HEADER
- #define APPLICATION_TYPE_HEADER
- #include "Main.h"
- #include "InterfaceMapWidget.h"
- namespace Render {
- class OOP_aplication {
- protected:
- sf::RenderWindow* Window;
- InterfaceMapWidget *MapWidget;
- public:
- OOP_aplication();
- ~OOP_aplication();
- void Init();
- void Run();
- void End();
- };
- }
- #endif
- //OOP_aplication.cpp
- #include "OOP_aplication.h"
- namespace Render {
- OOP_aplication::OOP_aplication() :
- Window(nullptr),
- MapWidget(nullptr) {
- }
- //OOP_aplication::~OOP_aplication() {
- //}
- void OOP_aplication::Init() {
- Window = new sf::RenderWindow(sf::VideoMode(640, 640), "First Version of Engine");
- MapWidget = new InterfaceMapWidget(0, 0, 640, 640);
- }
- void OOP_aplication::Run() {
- while (Window->isOpen()) {
- sf::Event event;
- while (Window->pollEvent(event)) {
- if (event.type == sf::Event::Closed)
- Window->close();
- }
- Window->clear(sf::Color::Black);
- MapWidget->Draw(Window);
- Window->display();
- }
- }
- void OOP_aplication::End() {
- if (Window != nullptr) {
- delete Window;
- Window = nullptr;
- }
- if (MapWidget != nullptr) {
- delete MapWidget;
- MapWidget = nullptr;
- }
- }
- }
- //Main.h
- #ifndef MAIN_HEADER
- #define MAIN_HEADER
- #include <SFML/Graphics.hpp>
- #include <SFML/Window.hpp>
- #include <SFML/Audio.hpp>
- #include <SFML/Network.hpp>
- #include <SFML/System.hpp>
- #include "InterfaceMapWidget.h"
- #include "OOP_aplication.h"
- #endif
- //Main.cpp
- #include "Main.h"
- int main(int argc, char* argv[]) {
- Render::OOP_aplication Application;
- Application.Init();
- Application.Run();
- Application.End();
- return 0;
- }
- //InterfaceMapWidget.h
- #ifndef INTERFACEMAPWIDGET_HEADER
- #define INTERFACEMAPWIDGET_HEADER
- #include "Main.h"
- class InterfaceMapWidget {
- protected:
- int X, Y, Width, Height;
- sf::Texture SomeTexture;
- //методы класса
- //поля класса
- public:
- InterfaceMapWidget(int aX, int aY, int aWidth, int aHeight);
- ~InterfaceMapWidget ();
- void Draw(sf::RenderWindow* Window);
- };
- #endif
- //InterfaceMapWidget.cpp
- #include "InterfaceMapWidget.h"
- InterfaceMapWidget::InterfaceMapWidget(int aX, int aY, int aWidth, int aHeight) :
- X(aX),
- Y(aY),
- Width(aWidth),
- Height(aHeight),
- SomeTexture() {
- SomeTexture.loadFromFile("../images/Test.png");
- }
- InterfaceMapWidget:: ~InterfaceMapWidget() {
- }
- void InterfaceMapWidget::Draw(sf::RenderWindow * Window) {
- sf::Sprite SpriteStuff;
- SpriteStuff.setTexture(SomeTexture);
- SpriteStuff.setPosition(X, Y);
- float WidgetWidth = (float)Width / (float)SomeTexture.getSize().x;
- float WidgetHeight = (float)Height / (float)SomeTexture.getSize().y;
- SpriteStuff.setScale(WidgetWidth, WidgetHeight);
- Window->draw(SpriteStuff);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement