added namespaces

This commit is contained in:
Bob Polis 2020-10-23 13:55:57 +02:00
parent 3de586a516
commit c6e6333f9a
6 changed files with 49 additions and 31 deletions

View File

@ -10,6 +10,8 @@
#include <stdexcept>
#include "SDLImageWrapper.hpp"
using namespace sc::gui;
SDLImageWrapper::SDLImageWrapper() {
int flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF;
int result = IMG_Init(flags);

View File

@ -9,15 +9,19 @@
#ifndef __SDLIMAGEWRAPPER_H_
#define __SDLIMAGEWRAPPER_H_
struct SDLImageWrapper {
SDLImageWrapper();
~SDLImageWrapper();
namespace sc {
namespace gui {
struct SDLImageWrapper {
SDLImageWrapper();
~SDLImageWrapper();
// prohibit copy and move
SDLImageWrapper(const SDLImageWrapper&) = delete;
SDLImageWrapper& operator=(const SDLImageWrapper&) = delete;
SDLImageWrapper(SDLImageWrapper&&) = delete;
SDLImageWrapper& operator=(SDLImageWrapper&&) = delete;
};
// prohibit copy and move
SDLImageWrapper(const SDLImageWrapper&) = delete;
SDLImageWrapper& operator=(const SDLImageWrapper&) = delete;
SDLImageWrapper(SDLImageWrapper&&) = delete;
SDLImageWrapper& operator=(SDLImageWrapper&&) = delete;
};
}
}
#endif // __SDLIMAGEWRAPPER_H_

View File

@ -9,6 +9,8 @@
#include <SDL2/SDL.h>
#include "SDLWrapper.hpp"
using namespace sc::gui;
SDLWrapper::SDLWrapper() {
SDL_Init(SDL_INIT_VIDEO);
}

View File

@ -9,15 +9,19 @@
#ifndef __SDLWRAPPER_H_
#define __SDLWRAPPER_H_
struct SDLWrapper {
SDLWrapper();
~SDLWrapper();
namespace sc {
namespace gui {
struct SDLWrapper {
SDLWrapper();
~SDLWrapper();
// prohibit copy and move
SDLWrapper(const SDLWrapper&) = delete;
SDLWrapper& operator=(const SDLWrapper&) = delete;
SDLWrapper(SDLWrapper&&) = delete;
SDLWrapper& operator=(SDLWrapper&&) = delete;
};
// prohibit copy and move
SDLWrapper(const SDLWrapper&) = delete;
SDLWrapper& operator=(const SDLWrapper&) = delete;
SDLWrapper(SDLWrapper&&) = delete;
SDLWrapper& operator=(SDLWrapper&&) = delete;
};
}
}
#endif // __SDLWRAPPER_H_

View File

@ -10,6 +10,8 @@
#include <cmath>
#include "Window.hpp"
using namespace sc::gui;
Window::Window(const char* title) : _path {title} {
SDL_Window* win = SDL_CreateWindow(title,
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,

View File

@ -14,21 +14,25 @@
#include <memory>
#include <stdexcept>
class Window {
public:
Window(const char* title);
namespace sc {
namespace gui {
class Window {
public:
Window(const char* title);
SDL_Window* get_window() const { return _w.get(); }
void set_size(int w, int h);
SDL_Window* get_window() const { return _w.get(); }
void set_size(int w, int h);
void update() const;
void load_image();
void update() const;
void load_image();
private:
std::string _path;
std::unique_ptr<SDL_Window, void(*)(SDL_Window*)> _w {nullptr, SDL_DestroyWindow};
std::unique_ptr<SDL_Renderer, void(*)(SDL_Renderer*)> _r {nullptr, SDL_DestroyRenderer};
std::unique_ptr<SDL_Texture, void(*)(SDL_Texture*)> _t {nullptr, SDL_DestroyTexture};
};
private:
std::string _path;
std::unique_ptr<SDL_Window, void(*)(SDL_Window*)> _w {nullptr, SDL_DestroyWindow};
std::unique_ptr<SDL_Renderer, void(*)(SDL_Renderer*)> _r {nullptr, SDL_DestroyRenderer};
std::unique_ptr<SDL_Texture, void(*)(SDL_Texture*)> _t {nullptr, SDL_DestroyTexture};
};
}
}
#endif // __WINDOW_H_