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 <stdexcept>
#include "SDLImageWrapper.hpp" #include "SDLImageWrapper.hpp"
using namespace sc::gui;
SDLImageWrapper::SDLImageWrapper() { SDLImageWrapper::SDLImageWrapper() {
int flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF; int flags = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF;
int result = IMG_Init(flags); int result = IMG_Init(flags);

View File

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

View File

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

View File

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

View File

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

View File

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