mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-29 19:55:37 +00:00
More work on the skeleton of the program.
This commit is contained in:
parent
30ada8a9b3
commit
1177fde6c3
4
Makefile
4
Makefile
|
@ -1,7 +1,7 @@
|
|||
CC=g++
|
||||
CFLAGS=-c -Wall
|
||||
LDFLAGS=-lSDL
|
||||
SRCSOURCES=main.cpp Renderer.cpp GuiComponent.cpp
|
||||
SRCSOURCES=main.cpp Renderer.cpp Renderer_draw.cpp GuiComponent.cpp components/GuiTitleScreen.cpp
|
||||
SOURCES=$(addprefix src/,$(SRCSOURCES))
|
||||
OBJECTS=$(SOURCES:.cpp=.o)
|
||||
EXECUTABLE=emulationstation
|
||||
|
@ -15,4 +15,4 @@ $(EXECUTABLE): $(OBJECTS)
|
|||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf src/*o $(EXECUTABLE)
|
||||
rm -rf src/*o src/components/*o $(EXECUTABLE)
|
||||
|
|
|
@ -1,12 +1,32 @@
|
|||
#include "GuiComponent.h"
|
||||
#include "Renderer.h"
|
||||
#include <iostream>
|
||||
|
||||
GuiComponent::GuiComponent()
|
||||
void GuiComponent::addChild(GuiComponent* comp)
|
||||
{
|
||||
Renderer::registerComponent(this);
|
||||
mChildren.push_back(comp);
|
||||
}
|
||||
|
||||
GuiComponent::~GuiComponent()
|
||||
void GuiComponent::removeChild(GuiComponent* comp)
|
||||
{
|
||||
Renderer::unregisterComponent(this);
|
||||
for(unsigned int i = 0; i < mChildren.size(); i++)
|
||||
{
|
||||
if(mChildren.at(i) == comp)
|
||||
{
|
||||
mChildren.erase(mChildren.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Error - tried to remove GuiComponent child, but couldn't find it!\n";
|
||||
}
|
||||
|
||||
void GuiComponent::render()
|
||||
{
|
||||
onRender();
|
||||
|
||||
for(unsigned int i = 0; i < mChildren.size(); i++)
|
||||
{
|
||||
mChildren.at(i)->render();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
#ifndef _GUICOMPONENT_H_
|
||||
#define _GUICOMPONENT_H_
|
||||
|
||||
#include <vector>
|
||||
#include "Renderer.h"
|
||||
|
||||
class GuiComponent
|
||||
{
|
||||
public:
|
||||
GuiComponent();
|
||||
~GuiComponent();
|
||||
virtual void render() { };
|
||||
virtual unsigned int getLayer() { return 0; };
|
||||
void render();
|
||||
virtual void onRender() { };
|
||||
virtual unsigned int getLayer() { return BIT(0); };
|
||||
|
||||
void addChild(GuiComponent* comp);
|
||||
void removeChild(GuiComponent* comp);
|
||||
unsigned int getChildCount() { return mChildren.size(); }
|
||||
GuiComponent* getChild(unsigned int i) { return mChildren.at(i); }
|
||||
private:
|
||||
std::vector<GuiComponent*> mChildren;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Renderer.h"
|
||||
#include "GuiComponent.h"
|
||||
|
||||
std::vector<GuiComponent*> renderVector;
|
||||
|
||||
|
@ -31,3 +32,4 @@ void Renderer::render()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,22 @@
|
|||
|
||||
#define BIT(x) (1 << (x))
|
||||
|
||||
#include "GuiComponent.h"
|
||||
#include <vector>
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
class GuiComponent;
|
||||
|
||||
namespace Renderer
|
||||
{
|
||||
void registerComponent(GuiComponent* comp);
|
||||
void unregisterComponent(GuiComponent* comp);
|
||||
|
||||
void render();
|
||||
|
||||
extern SDL_Surface* screen;
|
||||
|
||||
//drawing commands
|
||||
void drawRect(int x, int y, int w, int h, int color);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
10
src/Renderer_draw.cpp
Normal file
10
src/Renderer_draw.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "Renderer.h"
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
SDL_Surface* Renderer::screen;
|
||||
|
||||
void Renderer::drawRect(int x, int y, int h, int w, int color)
|
||||
{
|
||||
SDL_Rect rect = {x, y, h, w};
|
||||
SDL_FillRect(Renderer::screen, &rect, color);
|
||||
}
|
16
src/components/GuiTitleScreen.cpp
Normal file
16
src/components/GuiTitleScreen.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "GuiTitleScreen.h"
|
||||
#include "../Renderer.h"
|
||||
#include <iostream>
|
||||
|
||||
GuiTitleScreen::GuiTitleScreen()
|
||||
{
|
||||
Renderer::registerComponent(this);
|
||||
|
||||
//add children here
|
||||
}
|
||||
|
||||
void GuiTitleScreen::onRender()
|
||||
{
|
||||
Renderer::drawRect(0, 0, 640, 480, 0xFFFFFF);
|
||||
std::cout << "rendering guititlescreen\n";
|
||||
}
|
13
src/components/GuiTitleScreen.h
Normal file
13
src/components/GuiTitleScreen.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef _GUITITLESCREEN_H_
|
||||
#define _GUITITLESCREEN_H_
|
||||
|
||||
#include "../GuiComponent.h"
|
||||
|
||||
class GuiTitleScreen : public GuiComponent
|
||||
{
|
||||
public:
|
||||
GuiTitleScreen();
|
||||
void onRender();
|
||||
};
|
||||
|
||||
#endif
|
38
src/main.cpp
38
src/main.cpp
|
@ -1,17 +1,49 @@
|
|||
#include <iostream>
|
||||
#include <SDL/SDL.h>
|
||||
#include "Renderer.h"
|
||||
|
||||
#include "components/GuiTitleScreen.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) != 0)
|
||||
//if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0)
|
||||
if(SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||
{
|
||||
std::cerr << "Error - could not initialize SDL!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Renderer::screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
|
||||
if(Renderer::screen == NULL)
|
||||
{
|
||||
std::cerr << "Error - could not set video mode!\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
GuiTitleScreen* testGui = new GuiTitleScreen();
|
||||
|
||||
bool running = true;
|
||||
while(running)
|
||||
{
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
running = false;
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Renderer::render();
|
||||
SDL_Flip(Renderer::screen);
|
||||
}
|
||||
|
||||
delete testGui;
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue