Ian Burgmyer
4 years ago
10 changed files with 166 additions and 19 deletions
@ -1,5 +0,0 @@
|
||||
#include "Hello.h" |
||||
|
||||
int Hello::Calculate() { |
||||
return 42; |
||||
} |
@ -1,8 +0,0 @@
|
||||
#pragma once |
||||
|
||||
class Hello { |
||||
public: |
||||
static int Calculate(); |
||||
}; |
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
/* Plip.cpp
|
||||
* |
||||
* The main class for controlling the Plip emulation suite. |
||||
*/ |
||||
|
||||
#include "Plip.h" |
@ -0,0 +1,10 @@
|
||||
/* Plip.h
|
||||
* |
||||
* The main class for controlling the Plip emulation suite. |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
class Plip { |
||||
|
||||
}; |
@ -0,0 +1,20 @@
|
||||
/* PlipVideo.h
|
||||
* |
||||
* Provides a toolkit-agnostic video interface. |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <string> |
||||
|
||||
namespace Plip { |
||||
class PlipVideo { |
||||
public: |
||||
virtual void Resize(int width, int height) = 0; |
||||
virtual void SetTitle(std::string title) = 0; |
||||
|
||||
protected: |
||||
PlipVideo() = default; |
||||
~PlipVideo() = default; |
||||
}; |
||||
} |
@ -0,0 +1,17 @@
|
||||
/* plipVideoException.h
|
||||
* |
||||
* An exception that may occur during video initialization. |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <stdexcept> |
||||
#include <string> |
||||
#include <utility> |
||||
|
||||
namespace Plip { |
||||
struct PlipVideoException : std::runtime_error { |
||||
explicit PlipVideoException(const char *message) |
||||
: std::runtime_error(message) {} |
||||
}; |
||||
} |
@ -0,0 +1,73 @@
|
||||
/* SdlWindow.cpp
|
||||
* |
||||
* Describe this file here. |
||||
*/ |
||||
|
||||
#include <sstream> |
||||
|
||||
#include "PlipVideoException.h" |
||||
|
||||
#include "SdlWindow.h" |
||||
|
||||
namespace PlipSdl { |
||||
SdlWindow::SdlWindow(int scale, std::string title) { |
||||
std::stringstream error; |
||||
|
||||
m_scale = scale; |
||||
|
||||
// Try to create a window.
|
||||
m_window = SDL_CreateWindow(title.c_str(), |
||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, |
||||
m_width * m_scale, m_height * m_scale, 0); |
||||
|
||||
if(m_window == nullptr) { |
||||
error << "Unable to create SDL window: " << SDL_GetError() << "\n"; |
||||
throw Plip::PlipVideoException(error.str().c_str()); |
||||
} |
||||
|
||||
// Try to create a renderer.
|
||||
m_renderer = SDL_CreateRenderer(m_window, -1, 0); |
||||
|
||||
if(m_renderer == nullptr) { |
||||
error << "Unable to create SDL renderer: " << SDL_GetError() << "\n"; |
||||
throw Plip::PlipVideoException(error.str().c_str()); |
||||
} |
||||
|
||||
// Try to create a small starting texture. This will be removed and
|
||||
// recreated later, but we want to ensure that we can make one in the
|
||||
// first place.
|
||||
m_texture = SDL_CreateTexture(m_renderer, 0, 0, m_width, m_height); |
||||
|
||||
if(m_texture == nullptr) { |
||||
error << "Unable to create SDL texture: " << SDL_GetError() << "\n"; |
||||
throw Plip::PlipVideoException(error.str().c_str()); |
||||
} |
||||
} |
||||
|
||||
SdlWindow::~SdlWindow() { |
||||
if(m_texture != nullptr) SDL_DestroyTexture(m_texture); |
||||
if(m_renderer != nullptr) SDL_DestroyRenderer(m_renderer); |
||||
if(m_window != nullptr) SDL_DestroyWindow(m_window); |
||||
} |
||||
|
||||
void SdlWindow::Resize(int width, int height) { |
||||
m_width = width; |
||||
m_height = height; |
||||
|
||||
// Resize the window.
|
||||
SDL_SetWindowSize(m_window, m_width * m_scale, m_height * m_scale); |
||||
|
||||
// Destroy and recreate the texture.
|
||||
SDL_DestroyTexture(m_texture); |
||||
SDL_CreateTexture(m_renderer, 0, 0, m_width, m_height); |
||||
} |
||||
|
||||
void SdlWindow::SetScale(int scale) { |
||||
m_scale = scale; |
||||
SDL_SetWindowSize(m_window, m_width * m_scale, m_height * m_scale); |
||||
} |
||||
|
||||
void SdlWindow::SetTitle(std::string title) { |
||||
SDL_SetWindowTitle(m_window, title.c_str()); |
||||
} |
||||
} |
@ -0,0 +1,35 @@
|
||||
/* SdlWindow.h
|
||||
* |
||||
* Describe this file here. |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <SDL.h> |
||||
|
||||
#include "PlipVideo.h" |
||||
|
||||
namespace PlipSdl { |
||||
class SdlWindow : Plip::PlipVideo { |
||||
public: |
||||
SdlWindow(int scale = 1, std::string title = ""); |
||||
~SdlWindow(); |
||||
|
||||
void Resize(int width, int height); |
||||
void SetScale(int scale); |
||||
void SetTitle(std::string title); |
||||
|
||||
private: |
||||
const int m_init_width = 64; |
||||
const int m_init_height = 64; |
||||
|
||||
int m_width = m_init_width; |
||||
int m_height = m_init_height; |
||||
|
||||
SDL_Window *m_window = nullptr; |
||||
SDL_Renderer *m_renderer = nullptr; |
||||
SDL_Texture *m_texture = nullptr; |
||||
|
||||
int m_scale; |
||||
}; |
||||
} |
Loading…
Reference in new issue