diff --git a/include/window.h b/include/window.h index f54b13bb720aff736ab8b7bb91d0733a22d3361b..258c1ab7030c893a7317ac12d2ed01adc7fd10af 100644 --- a/include/window.h +++ b/include/window.h @@ -10,6 +10,7 @@ #include <cstring> #include <string> #include "logger.h" +#include "maths/vec2.h" const uint16_t SCREEN_HEIGHT = 600; @@ -53,6 +54,10 @@ class Window SDL_Surface* _screenSurface; SDL_Surface* _renderSurface; + SDL_Rect _drawRect( int x, int y, uint16_t width, uint16_t height ); + void _drawLine( int16_t x1, int16_t y1, int16_t x2, int16_t y2 ); + void _drawPoint( Vec2 point ); + void initialise(); void clean(); }; \ No newline at end of file diff --git a/src/window.cpp b/src/window.cpp index fb23eb5db114e6050b11bf023b6b8b02039e464f..efe1705b57845358bdd93fa4933d410fcff8f1df 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -78,11 +78,46 @@ void Window::loadMedia( std::string path ) } void Window::update() { + SDL_SetRenderDrawColor( this->_renderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( this->_renderer ); SDL_RenderCopy( this->_renderer, this->_activeTexture, NULL, NULL ); + + // Render Example Primatives + this->_drawRect( SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 ); + this->_drawRect( 0, 0, 10, 10 ); + this->_drawLine( 0, SCREEN_HEIGHT / 2, SCREEN_WIDTH, SCREEN_HEIGHT / 2 ); + for( uint16_t i = 0; i < SCREEN_HEIGHT; i += 10 ) + { + this->_drawPoint( { SCREEN_WIDTH / 2, i } ); + } + + SDL_RenderPresent( this->_renderer ); } +SDL_Rect Window::_drawRect( int x, int y, uint16_t width, uint16_t height ) +{ + SDL_Rect fillRect = { x, y, width, height }; + SDL_SetRenderDrawColor( this->_renderer, 0xFF, 0x00, 0x00, 0xFF ); + SDL_RenderFillRect( this->_renderer, &fillRect ); + + SDL_Rect outlineRect = { x, y, width, height }; + SDL_SetRenderDrawColor( this->_renderer, 0x00, 0xFF, 0x00, 0xFF ); + SDL_RenderDrawRect( this->_renderer, &outlineRect ); + return fillRect; +} +void Window::_drawLine( int16_t x1, int16_t y1, int16_t x2, int16_t y2 ) +{ + SDL_SetRenderDrawColor( this->_renderer, 0x00, 0x00, 0xFF, 0xFF ); + SDL_RenderDrawLine( this->_renderer, x1, y1, x2, y2 ); +} +void Window::_drawPoint( Vec2 point ) +{ + SDL_SetRenderDrawColor( this->_renderer, 0xFF, 0xFF, 0x00, 0xFF ); + SDL_RenderDrawPoint( this->_renderer, point.x, point.y ); +} + + void Window::spawn() { this->_window = SDL_CreateWindow( @@ -133,6 +168,7 @@ void Window::processInput() if( e.type == SDL_QUIT ) this->_toClose = true; else if( e.type == SDL_KEYDOWN ) { + if( e.key.keysym.sym == SDLK_ESCAPE ) this->_toClose = true; std::cout << "Key: " << e.key.keysym.sym << std::endl; } }