Rearrange graphics projects into subdirectory
This commit is contained in:
47
cpp/graphics/sdl-cmake/src/lib-sdl-test.cpp
Normal file
47
cpp/graphics/sdl-cmake/src/lib-sdl-test.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################
|
||||
##
|
||||
*/
|
||||
|
||||
#include <lib-sdl-test.h>
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
// Shape base class definitions
|
||||
std::string Shape::PrintInfo() {
|
||||
return name + " HxW: " + std::to_string(height) + "x" + std::to_string(width);
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
// SDL helper function definitions
|
||||
|
||||
int InitScreen(SDL_Window* &window, SDL_Renderer* &renderer) {
|
||||
int state = 0;
|
||||
|
||||
// Create window, renderer to draw to screen
|
||||
if (SDL_CreateWindowAndRenderer(500, 500, 0, &window, &renderer) < 0) {
|
||||
std::cout << "Error - Unable to create SDL screen and renderer objects\n";
|
||||
state = -1;
|
||||
}
|
||||
|
||||
// Set render DrawColor, fill screen with color
|
||||
if (SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255) < 0 || SDL_RenderClear(renderer) < 0) {
|
||||
std::cout << "Error - Unable to set renderer draw color\n";
|
||||
state = -1;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void DrawDelay(SDL_Renderer* renderer, int delay) {
|
||||
// Show what we have rendered
|
||||
SDL_RenderPresent(renderer);
|
||||
// Wait 3000ms, then continue
|
||||
SDL_Delay(delay);
|
||||
return;
|
||||
}
|
||||
51
cpp/graphics/sdl-cmake/src/lib-sdl-test.h
Normal file
51
cpp/graphics/sdl-cmake/src/lib-sdl-test.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*#############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################
|
||||
## src/lib-inherit.h
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Shape {
|
||||
public:
|
||||
// Provide ctor to set name of derived shape
|
||||
Shape(double w, double h, std::string name_) :
|
||||
width(w), height(h), name(std::move(name_)) {}
|
||||
Shape(double w, double h) : width(w), height(h) {}
|
||||
Shape() : width(2), height(2) {}
|
||||
virtual ~Shape() = default;
|
||||
|
||||
// All derived inherit ability to show name
|
||||
virtual std::string PrintInfo();
|
||||
|
||||
private:
|
||||
double width, height;
|
||||
const std::string name = "Shape";
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
// Rectangle derived Shape
|
||||
|
||||
class Rectangle: public Shape {
|
||||
public:
|
||||
Rectangle(double w, double h) : Shape(w, h, "Rectangle") {}
|
||||
Rectangle() : Shape(4, 2, "Rectangle") {}
|
||||
~Rectangle() override = default;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
// SDL helper functions
|
||||
|
||||
int InitScreen(SDL_Window* &window, SDL_Renderer* &renderer);
|
||||
|
||||
void DrawDelay(SDL_Renderer* renderer, int delay);
|
||||
Reference in New Issue
Block a user