Initial commit

This commit is contained in:
2022-05-19 20:07:15 +02:00
commit 41a75f7422
17 changed files with 881 additions and 0 deletions

20
include/AMI.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include "widgets.h"
#include <SDL2/SDL.h>
constexpr const char* FT_LOGO_PATH = "resources/Fasttube_Logo-white.bmp";
class AMI {
public:
AMI(SDL_Renderer* renderer);
void draw();
private:
SDL_Renderer* renderer;
ImageWidget ft_logo;
TextWidget choose;
};

45
include/App.h Normal file
View File

@ -0,0 +1,45 @@
#pragma once
#include "AMI.h"
#include <SDL2/SDL.h>
#include <memory>
constexpr int SCREEN_WIDTH = 480;
constexpr int SCREEN_HEIGHT = 320;
enum class AppView { AMI, DRIVER, TESTING };
class SDLManager {
public:
SDLManager();
~SDLManager();
};
class App {
public:
App();
~App();
int run();
private:
void init_sdl();
void handle_events();
void render();
// The SDLManager initializes & quits SDL and its subsystems. Thus, it must be
// the first member of the class, so that its constructor is called before the
// others and its destructor is called after the others.
SDLManager sdl_manager;
std::unique_ptr<AMI> ami;
bool running;
AppView view;
SDL_Window* window;
SDL_Renderer* renderer;
};

13
include/util.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <string>
namespace util {
SDL_Texture* load_img(SDL_Renderer* renderer, const std::string& path);
TTF_Font* load_font(const std::string& path, int pt);
}

57
include/widgets.h Normal file
View File

@ -0,0 +1,57 @@
#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <optional>
#include <string>
class Widget {
public:
Widget(SDL_Renderer* renderer, SDL_Rect dest_rect);
virtual void update_rect(SDL_Rect new_rect);
virtual void draw() = 0;
protected:
SDL_Renderer* renderer;
SDL_Rect dest_rect;
};
class TextureWidget : public Widget {
public:
TextureWidget(SDL_Renderer* renderer, SDL_Rect dest_rect,
std::optional<SDL_Texture*> texture);
~TextureWidget();
virtual void draw() override;
void update_texture(SDL_Texture* new_texture);
private:
std::optional<SDL_Texture*> texture;
};
class ImageWidget : public TextureWidget {
public:
ImageWidget(SDL_Renderer* renderer, SDL_Rect dest_rect,
const std::string& path);
};
class TextWidget : public TextureWidget {
public:
TextWidget(SDL_Renderer* renderer, SDL_Rect dest_rect,
const std::string& font_path,
const std::string& initial_text = "");
~TextWidget();
void update_text(const std::string& new_text);
protected:
TTF_Font* font;
std::string text;
SDL_Texture* generate_text(const std::string& text);
};