diff --git a/plates/cpp-sdl-cmake/.vscode/launch.json b/plates/cpp-sdl-cmake/.vscode/launch.json new file mode 100644 index 0000000..5a63ae7 --- /dev/null +++ b/plates/cpp-sdl-cmake/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/inherited", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/plates/cpp-sdl/CMakeLists.txt b/plates/cpp-sdl-cmake/CMakeLists.txt similarity index 100% rename from plates/cpp-sdl/CMakeLists.txt rename to plates/cpp-sdl-cmake/CMakeLists.txt diff --git a/plates/cpp-sdl/apps/inherited.cpp b/plates/cpp-sdl-cmake/apps/inherited.cpp similarity index 100% rename from plates/cpp-sdl/apps/inherited.cpp rename to plates/cpp-sdl-cmake/apps/inherited.cpp diff --git a/plates/cpp-sdl-cmake/src/lib-inherit.cpp b/plates/cpp-sdl-cmake/src/lib-inherit.cpp new file mode 100644 index 0000000..365afda --- /dev/null +++ b/plates/cpp-sdl-cmake/src/lib-inherit.cpp @@ -0,0 +1,71 @@ +/*############################################################################## +## 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.cpp +*/ + +#include + +// Shape class definitions + +Shape::Shape(double w, double h) { + height = h; + width = w; +}; + +Shape::Shape() { + height = 2; + width = 2; +}; + +Shape::~Shape() { /* Shape destructor */}; + +const std::string Shape::PrintInfo() { + info = name + " HxW: " + std::to_string(height) + "x" + std::to_string(width); + return info; +}; + +// Rectangle Class definitions + +Rectangle::Rectangle(double w, double h) { + height = h; + width = w; +}; + +Rectangle::Rectangle() { + height = 2; + width = 4; +}; + +Rectangle::~Rectangle() { /* Rectangle destructor */ }; + +/// SDL Helper 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; +} diff --git a/plates/cpp-sdl-cmake/src/lib-inherit.h b/plates/cpp-sdl-cmake/src/lib-inherit.h new file mode 100644 index 0000000..9ad7cc1 --- /dev/null +++ b/plates/cpp-sdl-cmake/src/lib-inherit.h @@ -0,0 +1,42 @@ +/*############################################################################# +## 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 +#include +#include +#include + +class Shape { + private: + double width, height; + std::string info; + const std::string name = "Shape"; + + public: + Shape(double w, double h); + Shape(); + ~Shape(); + virtual const std::string PrintInfo(); +}; + +class Rectangle: public Shape { + private: + double width, height; + std::string info; + + public: + Rectangle(double w, double h); + Rectangle(); + ~Rectangle(); + +}; + +int InitScreen(SDL_Window* &window, SDL_Renderer* &renderer); + +void DrawDelay(SDL_Renderer* renderer, int delay); diff --git a/plates/cpp-sdl/.vscode/launch.json b/plates/cpp-sdl/.vscode/launch.json index 5a63ae7..0ccc785 100644 --- a/plates/cpp-sdl/.vscode/launch.json +++ b/plates/cpp-sdl/.vscode/launch.json @@ -4,6 +4,8 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + + { "name": "(gdb) Launch", "type": "cppdbg", diff --git a/plates/cpp-sdl/.vscode/tasks.json b/plates/cpp-sdl/.vscode/tasks.json new file mode 100644 index 0000000..a575756 --- /dev/null +++ b/plates/cpp-sdl/.vscode/tasks.json @@ -0,0 +1,26 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "cpp build active file", + "command": "g++", + "args": [ + "${workspaceFolder}/inherited.cpp", + "-lSDL2", + "-o", + "${workspaceFolder}/build/inherited", + ], + "options": { + "cwd": "/usr/bin" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/plates/cpp-sdl/inherited.cpp b/plates/cpp-sdl/inherited.cpp new file mode 100644 index 0000000..119c5e9 --- /dev/null +++ b/plates/cpp-sdl/inherited.cpp @@ -0,0 +1,108 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## +############################################################################## +## apps/inherited.cpp +*/ + +#include +#include +#include +#include + +class Shape { + private: + double width, height; + std::string info; + const std::string name = "Shape"; + + public: + Shape(double w, double h) { + height = h; + width = w; + }; + Shape() { + height = 2; + width = 2; + }; + ~Shape() { /* Shape destructor */}; + virtual const std::string PrintInfo() { + info = name + " HxW: " + std::to_string(height) + "x" + std::to_string(width); + return info; + }; +}; + +class Rectangle: public Shape { + private: + double width, height; + std::string info; + + public: + Rectangle(double w, double h) { + height = h; + width = w; + }; + Rectangle() { + height = 2; + width = 4; + }; + ~Rectangle() { /* Rectangle destructor */ }; + +}; + +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; +} + +int main (int argc, char const * argv[]) { + // Cast cli arguments to void since they are unused in this exe + (void)argc; + (void)argv; + + // Ensure SDL is initialized before continuing + if (SDL_Init(SDL_INIT_EVERYTHING) < 0) + exit(2); + + SDL_Window *window; + SDL_Renderer *renderer; + + if (InitScreen(window, renderer) < 0) + std::cout << "Error - Unable to initialize SDL screen\n"; + + DrawDelay(renderer, 3000); + + std::cout << "Test\n"; + Shape shape(4,4), dShape; + Rectangle rect(4,8), dRect; + std::cout << dShape.PrintInfo() << std::endl; + std::cout << shape.PrintInfo() << std::endl; + std::cout << dRect.PrintInfo() << std::endl; + std::cout << rect.PrintInfo() << std::endl; + + return 0; +}