diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..8ea7b1917 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +CC=g++ +CFLAGS=-c -Wall +LDFLAGS=-lSDL +SRCSOURCES=main.cpp Renderer.cpp GuiComponent.cpp +SOURCES=$(addprefix src/,$(SRCSOURCES)) +OBJECTS=$(SOURCES:.cpp=.o) +EXECUTABLE=emulationstation + +all: $(SOURCES) $(EXECUTABLE) + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(OBJECTS) $(LDFLAGS) -o $@ + +.cpp.o: + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm -rf *o $(EXECUTABLE) diff --git a/src/GuiComponent.cpp b/src/GuiComponent.cpp new file mode 100644 index 000000000..e172a4e16 --- /dev/null +++ b/src/GuiComponent.cpp @@ -0,0 +1,12 @@ +#include "GuiComponent.h" +#include "Renderer.h" + +GuiComponent::GuiComponent() +{ + Renderer::registerComponent(this); +} + +GuiComponent::~GuiComponent() +{ + Renderer::unregisterComponent(this); +} diff --git a/src/GuiComponent.h b/src/GuiComponent.h new file mode 100644 index 000000000..786671bed --- /dev/null +++ b/src/GuiComponent.h @@ -0,0 +1,13 @@ +#ifndef _GUICOMPONENT_H_ +#define _GUICOMPONENT_H_ + +class GuiComponent +{ +public: + GuiComponent(); + ~GuiComponent(); + virtual void render() { }; + virtual unsigned int getLayer() { return 0; }; +}; + +#endif diff --git a/src/Renderer.cpp b/src/Renderer.cpp new file mode 100644 index 000000000..17404be8a --- /dev/null +++ b/src/Renderer.cpp @@ -0,0 +1,31 @@ +#include "Renderer.h" + +void Renderer::registerComponent(GuiComponent* comp) +{ + renderVector.push_back(comp); +} + +void Renderer::unregisterComponent(GuiComponent* comp) +{ + for(unsigned int i = 0; i < renderVector.size(); i++) + { + if(renderVector.at(i) == comp) + { + renderVector.erase(renderVector.begin() + i); + break; + } + } +} + +void Renderer::render() +{ + for(unsigned int layer = 0; layer < LAYER_COUNT; layer++) + { + unsigned int layerBit = BIT(layer); + for(unsigned int i = 0; i < renderVector.size(); i++) + { + if(renderVector.at(i)->getLayer() & layerBit) + renderVector.at(i)->render(); + } + } +} diff --git a/src/Renderer.h b/src/Renderer.h new file mode 100644 index 000000000..b140ea540 --- /dev/null +++ b/src/Renderer.h @@ -0,0 +1,20 @@ +#ifndef _RENDERER_H_ +#define _RENDERER_H_ + +#define LAYER_COUNT 3 + +#define BIT(x) (1 << (x)) + +#include "GuiComponent.h" +#include +namespace Renderer +{ + void registerComponent(GuiComponent* comp); + void unregisterComponent(GuiComponent* comp); + + void render(); + + std::vector renderVector; +} + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 000000000..7006348f8 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,18 @@ +#include +#include +#include "Renderer.h" + + +int main() +{ + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0) + { + std::cerr << "Error - could not initialize SDL!\n"; + return 1; + } + + + + SDL_Quit(); + return 0; +}