diff --git a/Makefile b/Makefile index 7bbac6de5..4d20bfcf2 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,12 @@ -HEADERS := $(wildcard includes/*.h) +HEADERS := $(wildcard src/*.h) $(wildcard src/*/*.h) -OLD_SOURCES := $(wildcard src/*.c) -OLD_OBJS := $(patsubst src/%.c,build/obj/%.o,$(OLD_SOURCES)) +SOURCES := $(wildcard src/*.cpp) $(wildcard src/*/*.cpp) +OBJS += $(patsubst src/%.cpp,build/obj/powder.exe/%.o,$(SOURCES)) -EL_SOURCES := $(wildcard elements/*.cpp) -EL_OBJS := $(patsubst elements/%.cpp,build/obj/elements/%.o,$(EL_SOURCES)) -EL_PREREQ := $(patsubst build/obj/elements/%.o,build/obj/elements/%.powder.exe.o,$(EL_OBJS)) +FOLDERS := $(sort $(dir $(OBJS))) -CORE_SOURCES := $(wildcard src/*.cpp) -CORE_OBJS := $(patsubst src/%.cpp,build/obj/core/%.o,$(CORE_SOURCES)) -CORE_PREREQ := $(patsubst build/obj/core/%.o,build/obj/core/%.powder.exe.o,$(CORE_OBJS)) - -UI_SOURCES := $(wildcard src/interface/*.cpp) -UI_OBJS := $(patsubst src/interface/%.cpp,build/obj/ui/%.o,$(UI_SOURCES)) -UI_PREREQ := $(patsubst build/obj/ui/%.o,build/obj/ui/%.powder.exe.o,$(UI_OBJS)) - -CFLAGS := -Iincludes/ -Idata/ -DWIN32 -DWINCONSOLE -OFLAGS := -fkeep-inline-functions #-O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations +CFLAGS := -Wno-deprecated -Wno-deprecated-declarations -Isrc/ -Idata/ -DWIN32 -DWINCONSOLE +OFLAGS := -O3 -ffast-math -ftree-vectorize -funsafe-math-optimizations -msse2 -fkeep-inline-functions LFLAGS := -lmingw32 -lregex -lws2_32 -lSDLmain -lpthread -lSDL -lm -lbz2 # -mwindows CFLAGS += $(OFLAGS) @@ -28,14 +18,15 @@ WIN_RES := i686-w64-mingw32-windres all: build/powder.exe powder.exe: build/powder.exe -build/powder.exe: $(EL_PREREQ) $(CORE_PREREQ) $(UI_PREREQ) - $(CPPC) $(CFLAGS) $(LDFLAGS) $(EXTRA_OBJS) $(EL_PREREQ) $(CORE_PREREQ) $(UI_PREREQ) $(LFLAGS) -o $@ -ggdb -build/obj/ui/%.powder.exe.o: src/interface/%.cpp $(HEADERS) - $(CPPC) -c $(CFLAGS) -o $@ $< -ggdb -build/obj/elements/%.powder.exe.o: elements/%.cpp $(HEADERS) - $(CPPC) -c $(CFLAGS) -o $@ $< -ggdb -build/obj/core/%.powder.exe.o: src/%.cpp $(HEADERS) + +build/powder.exe: buildpaths $(OBJS) + echo $(OBJS) + $(CPPC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LFLAGS) -o $@ -ggdb +build/obj/powder.exe/%.o: src/%.cpp $(HEADERS) $(CPPC) -c $(CFLAGS) -o $@ $< -ggdb +buildpaths: + $(shell mkdir build/obj/powder.exe/) + $(shell mkdir $(FOLDERS)) clean: rm build/obj/core/*.o diff --git a/PowderToy++.files b/PowderToy++.files index bcc42cd6f..5a3028534 100644 --- a/PowderToy++.files +++ b/PowderToy++.files @@ -152,3 +152,159 @@ src/interface/Label.cpp includes/interface/Label.h includes/Global.h src/Global.cpp +src/search/SearchModel.h +src/search/SearchModel.cpp +src/search/Save.h +src/search/SearchView.h +src/search/SearchView.cpp +src/search/SearchController.h +src/search/SearchController.cpp +src/game/GameController.h +src/game/GameController.cpp +src/game/GameModel.h +src/game/GameModel.cpp +src/interface/Window.h +src/interface/Window.cpp +src/game/GameView.h +src/game/GameView.cpp +src/Singleton.h +src/Simulation.h +src/Renderer.h +src/Misc.h +src/Gravity.h +src/Graphics.h +src/Global.h +src/Elements.h +src/ElementGraphics.h +src/ElementFunctions.h +src/Element.h +src/Console.h +src/Config.h +src/Air.h +src/Simulation.cpp +src/Renderer.cpp +src/PowderToy.cpp +src/Misc.cpp +src/Gravity.cpp +src/Graphics.cpp +src/Global.cpp +src/Console.cpp +src/Air.cpp +src/elements/yest.cpp +src/elements/wtrv.cpp +src/elements/wire.cpp +src/elements/wifi.cpp +src/elements/watr.cpp +src/elements/warp.cpp +src/elements/vine.cpp +src/elements/uran.cpp +src/elements/thrm.cpp +src/elements/thdr.cpp +src/elements/swch.cpp +src/elements/stor.cpp +src/elements/stkm2.cpp +src/elements/stkm.cpp +src/elements/sprk.cpp +src/elements/spng.cpp +src/elements/soap.cpp +src/elements/smke.cpp +src/elements/sltw.cpp +src/elements/sing.cpp +src/elements/shld.cpp +src/elements/rime.cpp +src/elements/qrtz.cpp +src/elements/pyro.cpp +src/elements/pvod.cpp +src/elements/pump.cpp +src/elements/prto.cpp +src/elements/prti.cpp +src/elements/plut.cpp +src/elements/plsm.cpp +src/elements/plnt.cpp +src/elements/pipe.cpp +src/elements/phot.cpp +src/elements/pcln.cpp +src/elements/pbcn.cpp +src/elements/O2.cpp +src/elements/nwhl.cpp +src/elements/nptct.cpp +src/elements/none.cpp +src/elements/newgraphics.cpp +src/elements/neut.cpp +src/elements/nbhl.cpp +src/elements/mort.cpp +src/elements/merc.cpp +src/elements/ligh.cpp +src/elements/legacy.cpp +src/elements/lcry.cpp +src/elements/lava.cpp +src/elements/isz.cpp +src/elements/iron.cpp +src/elements/ignt.cpp +src/elements/ice.cpp +src/elements/hswc.cpp +src/elements/h2.cpp +src/elements/graphics_default.cpp +src/elements/gpmp.cpp +src/elements/goo.cpp +src/elements/glow.cpp +src/elements/glas.cpp +src/elements/gbmb.cpp +src/elements/fwrk.cpp +src/elements/fuse.cpp +src/elements/fsep.cpp +src/elements/frzz.cpp +src/elements/frzw.cpp +src/elements/fog.cpp +src/elements/firw.cpp +src/elements/fire.cpp +src/elements/figh.cpp +src/elements/emp.cpp +src/elements/elementmisc.cpp +src/elements/elec.cpp +src/elements/dstw.cpp +src/elements/dlay.cpp +src/elements/deut.cpp +src/elements/dest.cpp +src/elements/conv.cpp +src/elements/coal.cpp +src/elements/co2.cpp +src/elements/clst.cpp +src/elements/clne.cpp +src/elements/cbnw.cpp +src/elements/caus.cpp +src/elements/c5.cpp +src/elements/btry.cpp +src/elements/brmt.cpp +src/elements/boyl.cpp +src/elements/bomb.cpp +src/elements/bmtl.cpp +src/elements/bizr.cpp +src/elements/bcol.cpp +src/elements/bcln.cpp +src/elements/bang.cpp +src/elements/aray.cpp +src/elements/anar.cpp +src/elements/amtr.cpp +src/elements/acid.cpp +src/elements/acel.cpp +src/interface/Window.h +src/interface/State.h +src/interface/Sandbox.h +src/interface/Point.h +src/interface/Platform.h +src/interface/Panel.h +src/interface/Label.h +src/interface/Engine.h +src/interface/ControlFactory.h +src/interface/Component.h +src/interface/Button.h +src/interface/Window.cpp +src/interface/State.cpp +src/interface/Sandbox.cpp +src/interface/Panel.cpp +src/interface/Label.cpp +src/interface/Engine.cpp +src/interface/ControlFactory.cpp +src/interface/Component.cpp +src/interface/Button.cpp diff --git a/build/obj/core/.empty b/build/obj/core/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/build/obj/elements/.empty b/build/obj/elements/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/build/obj/ui/.empty b/build/obj/ui/.empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/includes/GameSession.h b/includes/GameSession.h deleted file mode 100644 index 8417e0ca4..000000000 --- a/includes/GameSession.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef GAMESESSION_H -#define GAMESESSION_H - -class GameSession -{ -public: - GameSession(); -}; - -#endif // GAMESESSION_H diff --git a/includes/interface.old/Button.h b/includes/interface.old/Button.h deleted file mode 100644 index 1b2900e29..000000000 --- a/includes/interface.old/Button.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Button.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef BUTTON_H_ -#define BUTTON_H_ - -#include - -#include "Component.h" - -namespace ui -{ - class Button : public Component - { - public: - Button(int x, int y, int width, int height, const std::string& buttonText); - - bool Toggleable; - - std::string ButtonText; - - virtual void OnMouseClick(int x, int y, unsigned int button); - virtual void OnMouseUnclick(int x, int y, unsigned int button); - virtual void OnMouseUp(int x, int y, unsigned int button); - - virtual void OnMouseEnter(int x, int y, int dx, int dy); - virtual void OnMouseLeave(int x, int y, int dx, int dy); - - virtual void Draw(void* userdata); - - inline bool GetState() { return state; } - virtual void DoAction(); //action of button what ever it may be - - protected: - bool isButtonDown, state, isMouseInside; - }; -} -#endif /* BUTTON_H_ */ diff --git a/includes/interface.old/Component.h b/includes/interface.old/Component.h deleted file mode 100644 index a4d02dbc7..000000000 --- a/includes/interface.old/Component.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Component.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef COMPONENT_H_ -#define COMPONENT_H_ - -namespace ui -{ - class State; - - class Component - { - public: - Component(int x, int y, int width, int height); - virtual ~Component(); - - inline void LocalizePoint(int& x, int& y) { x -= X; y -= Y; } //convert a global point (point on the state) to a point based on component's position - inline void GlobalizePoint(int& x, int& y) { x += X; y += Y; } //convert a local point based on component's position to a global point on the state - - bool Focused; - bool Visible; - bool Enabled; - int Width; - int Height; - int X; - int Y; - - virtual void Tick(float dt); - virtual void Draw(void* userdata); - - virtual void OnMouseEnter(int localx, int localy, int dx, int dy); - virtual void OnMouseLeave(int localx, int localy, int dx, int dy); - virtual void OnMouseMoved(int localx, int localy, int dx, int dy); - virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy); - virtual void OnMouseHover(int localx, int localy); - virtual void OnMouseDown(int localx, int localy, unsigned int button); - virtual void OnMouseUp(int localx, int localy, unsigned int button); - virtual void OnMouseClick(int localx, int localy, unsigned int button); - virtual void OnMouseUnclick(int localx, int localy, unsigned int button); - virtual void OnMouseWheel(int localx, int localy, int d); - virtual void OnMouseWheelInside(int localx, int localy, int d); - virtual void OnMouseWheelFocused(int localx, int localy, int d); - virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt); - virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt); - - State* Parent; - }; -} -#endif /* COMPONENT_H_ */ diff --git a/includes/interface.old/ControlFactory.h b/includes/interface.old/ControlFactory.h deleted file mode 100644 index 8bfd7806a..000000000 --- a/includes/interface.old/ControlFactory.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CONTROLFACTORY_H -#define CONTROLFACTORY_H - -#include "Panel.h" -#include "Window.h" -#include "GameSession.h" - -class ControlFactory -{ -public: - static ui::Panel * MainMenu(GameSession * session, int x, int y, int width, int height); - -}; - -#endif // CONTROLFACTORY_H diff --git a/includes/interface.old/Panel.h b/includes/interface.old/Panel.h deleted file mode 100644 index 9549ff4ac..000000000 --- a/includes/interface.old/Panel.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Panel.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef PANEL_H_ -#define PANEL_H_ - -#include "interface/Component.h" - -namespace ui { - -class Panel: public ui::Component { -public: - Panel(int x, int y, int width, int height); - virtual ~Panel(); -}; - -} /* namespace ui */ -#endif /* PANEL_H_ */ diff --git a/includes/interface.old/Sandbox.h b/includes/interface.old/Sandbox.h deleted file mode 100644 index 32a047127..000000000 --- a/includes/interface.old/Sandbox.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Sandbox.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef SANDBOX_H_ -#define SANDBOX_H_ - -#include "Component.h" -#include "Simulation.h" -#include "Renderer.h" - -namespace ui { - -class Sandbox: public ui::Component { -private: - int lastCoordX, lastCoordY; - int activeElement; - bool isMouseDown; - Renderer * ren; - Simulation * sim; -public: - Sandbox(); - virtual Simulation * GetSimulation(); - virtual void OnMouseMovedInside(int localx, int localy, int dx, int dy); - virtual void OnMouseDown(int localx, int localy, unsigned int button); - virtual void OnMouseUp(int localx, int localy, unsigned int button); - virtual void Draw(void* userdata); - virtual void Tick(float delta); - virtual ~Sandbox(); -}; - -} /* namespace ui */ -#endif /* SANDBOX_H_ */ diff --git a/includes/interface.old/State.h b/includes/interface.old/State.h deleted file mode 100644 index 00df19916..000000000 --- a/includes/interface.old/State.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * State.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef STATE_H_ -#define STATE_H_ - -#include - -#include "interface/Component.h" - -namespace ui { - -class State -{ -public: - State(int w, int h); - virtual ~State(); - - bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds - - virtual void Tick(float dt); - virtual void Draw(void* userdata); - - virtual void OnMouseMove(int x, int y); - virtual void OnMouseDown(int x, int y, unsigned int button); - virtual void OnMouseUp(int x, int y, unsigned int button); - virtual void OnMouseWheel(int x, int y, int d); - virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt); - virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt); - - virtual void Add(Component *child); - virtual void Remove(Component *child); - - inline bool IsFocused(Component* c) { return (c == focusedComponent_); } - inline int GetMouseX() { return mouseX; } - inline int GetMouseY() { return mouseY; } - inline int GetWidth() { return width; } - inline int GetHeight() { return height; } - -protected: - std::vector Components; - - int width; - int height; - - int mouseX; - int mouseY; - int mouseXP; - int mouseYP; - -private: - Component* focusedComponent_; - -}; - -} /* namespace ui */ -#endif /* STATE_H_ */ diff --git a/includes/interface.old/Window.h b/includes/interface.old/Window.h deleted file mode 100644 index 86a4bcd52..000000000 --- a/includes/interface.old/Window.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Window.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef WINDOW_H_ -#define WINDOW_H_ - -#include "interface/State.h" - -namespace ui { - -class Window: public ui::State { -public: - Window(); - virtual ~Window(); -}; - -} /* namespace ui */ -#endif /* WINDOW_H_ */ diff --git a/includes/interface/Button.h b/includes/interface/Button.h deleted file mode 100644 index 9046ea190..000000000 --- a/includes/interface/Button.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Button.h - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#ifndef BUTTON_H_ -#define BUTTON_H_ - -#include - -#include "Component.h" - -namespace ui -{ - class Button : public Component - { - public: - Button(State* parent_state, std::string buttonText); - - Button(Point position, Point size, std::string buttonText); - - Button(std::string buttonText); - virtual ~Button(); - - bool Toggleable; - - std::string ButtonText; - - virtual void OnMouseClick(int x, int y, unsigned int button); - virtual void OnMouseUnclick(int x, int y, unsigned int button); - //virtual void OnMouseUp(int x, int y, unsigned int button); - - virtual void OnMouseEnter(int x, int y); - virtual void OnMouseLeave(int x, int y); - - virtual void Draw(const Point& screenPos); - - inline bool GetState() { return state; } - virtual void DoAction(); //action of button what ever it may be - void SetTogglable(bool isTogglable); - bool GetTogglable(); - inline bool GetToggleState(); - inline void SetToggleState(bool state); - - protected: - bool isButtonDown, state, isMouseInside, isTogglable, toggle; - }; -} -#endif /* BUTTON_H_ */ diff --git a/includes/Air.h b/src/Air.h similarity index 100% rename from includes/Air.h rename to src/Air.h diff --git a/includes/Config.h b/src/Config.h similarity index 100% rename from includes/Config.h rename to src/Config.h diff --git a/includes/Console.h b/src/Console.h similarity index 100% rename from includes/Console.h rename to src/Console.h diff --git a/includes/Element.h b/src/Element.h similarity index 100% rename from includes/Element.h rename to src/Element.h diff --git a/includes/ElementFunctions.h b/src/ElementFunctions.h similarity index 100% rename from includes/ElementFunctions.h rename to src/ElementFunctions.h diff --git a/includes/ElementGraphics.h b/src/ElementGraphics.h similarity index 100% rename from includes/ElementGraphics.h rename to src/ElementGraphics.h diff --git a/includes/Elements.h b/src/Elements.h similarity index 100% rename from includes/Elements.h rename to src/Elements.h diff --git a/src/GameSession.cpp b/src/GameSession.cpp deleted file mode 100644 index 364f268e6..000000000 --- a/src/GameSession.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "GameSession.h" - -GameSession::GameSession() -{ - //Boop -} diff --git a/src/Global.cpp b/src/Global.cpp index 7bf28f04c..c1e055907 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -1,5 +1,6 @@ -#include "Global.h" +/*#include "Global.h" Global::Global(){ } +*/ diff --git a/includes/Global.h b/src/Global.h similarity index 76% rename from includes/Global.h rename to src/Global.h index 8e94255c0..ceff38e76 100644 --- a/includes/Global.h +++ b/src/Global.h @@ -4,11 +4,11 @@ #include "Singleton.h" #include "Graphics.h" -class Global : public Singleton +/*class Global : public Singleton { public: Graphics * g; Global(); -}; +};*/ #endif // GAMESESSION_H diff --git a/includes/Graphics.h b/src/Graphics.h similarity index 100% rename from includes/Graphics.h rename to src/Graphics.h diff --git a/includes/Gravity.h b/src/Gravity.h similarity index 100% rename from includes/Gravity.h rename to src/Gravity.h diff --git a/includes/Misc.h b/src/Misc.h similarity index 100% rename from includes/Misc.h rename to src/Misc.h diff --git a/src/PowderToy.cpp b/src/PowderToy.cpp index 1e9630cb0..cf7d8046e 100644 --- a/src/PowderToy.cpp +++ b/src/PowderToy.cpp @@ -19,6 +19,9 @@ #include "interface/Point.h" #include "interface/Label.h" +#include "game/GameController.h" +#include "game/GameView.h" + using namespace std; SDL_Surface * SDLOpen() @@ -66,20 +69,24 @@ int main(int argc, char * argv[]) //Simulation * sim = new Simulation(); //ren = new Renderer(g, sim); - Global::Ref().g = new Graphics(); - Global::Ref().g->AttachSDLSurface(SDLOpen()); + ui::Engine::Ref().g = new Graphics(); + ui::Engine::Ref().g->AttachSDLSurface(SDLOpen()); ui::Engine * engine = &ui::Engine::Ref();//new ui::Engine(); - ui::State * engineState = new ui::State(); - ui::Sandbox * sandbox = new ui::Sandbox(); - ui::Button * button = new ui::Button(ui::Point(100, 100), ui::Point(100, 100), std::string("poP")); + //ui::State * engineState = new ui::State(); ui::Label * fpsLabel = new ui::Label(ui::Point(2, 2), ui::Point(200, 14), std::string("FPS: 0")); + //engineState->AddComponent(fpsLabel); engine->Begin(XRES, YRES); - engine->SetState(engineState); +// engine->SetState(engineState); + + GameController * gameController = new GameController(); + engine->ShowWindow(gameController->GetView()); + /*ui::Sandbox * sandbox = new ui::Sandbox(); + ui::Button * button = new ui::Button(ui::Point(100, 100), ui::Point(100, 100), std::string("poP")); engineState->AddComponent(fpsLabel); engineState->AddComponent(sandbox); engineState->AddComponent(button); - engineState->AddComponent(ControlFactory::MainMenu(0, YRES+MENUSIZE-17, XRES+BARSIZE, 16)); + engineState->AddComponent(ControlFactory::MainMenu(0, YRES+MENUSIZE-17, XRES+BARSIZE, 16));*/ SDL_Event event; while(engine->Running()) diff --git a/includes/Renderer.h b/src/Renderer.h similarity index 100% rename from includes/Renderer.h rename to src/Renderer.h diff --git a/includes/Simulation.h b/src/Simulation.h similarity index 100% rename from includes/Simulation.h rename to src/Simulation.h diff --git a/includes/Singleton.h b/src/Singleton.h similarity index 100% rename from includes/Singleton.h rename to src/Singleton.h diff --git a/elements/O2.cpp b/src/elements/O2.cpp similarity index 100% rename from elements/O2.cpp rename to src/elements/O2.cpp diff --git a/elements/acel.cpp b/src/elements/acel.cpp similarity index 100% rename from elements/acel.cpp rename to src/elements/acel.cpp diff --git a/elements/acid.cpp b/src/elements/acid.cpp similarity index 100% rename from elements/acid.cpp rename to src/elements/acid.cpp diff --git a/elements/amtr.cpp b/src/elements/amtr.cpp similarity index 100% rename from elements/amtr.cpp rename to src/elements/amtr.cpp diff --git a/elements/anar.cpp b/src/elements/anar.cpp similarity index 100% rename from elements/anar.cpp rename to src/elements/anar.cpp diff --git a/elements/aray.cpp b/src/elements/aray.cpp similarity index 100% rename from elements/aray.cpp rename to src/elements/aray.cpp diff --git a/elements/bang.cpp b/src/elements/bang.cpp similarity index 100% rename from elements/bang.cpp rename to src/elements/bang.cpp diff --git a/elements/bcln.cpp b/src/elements/bcln.cpp similarity index 100% rename from elements/bcln.cpp rename to src/elements/bcln.cpp diff --git a/elements/bcol.cpp b/src/elements/bcol.cpp similarity index 100% rename from elements/bcol.cpp rename to src/elements/bcol.cpp diff --git a/elements/bizr.cpp b/src/elements/bizr.cpp similarity index 100% rename from elements/bizr.cpp rename to src/elements/bizr.cpp diff --git a/elements/bmtl.cpp b/src/elements/bmtl.cpp similarity index 100% rename from elements/bmtl.cpp rename to src/elements/bmtl.cpp diff --git a/elements/bomb.cpp b/src/elements/bomb.cpp similarity index 100% rename from elements/bomb.cpp rename to src/elements/bomb.cpp diff --git a/elements/boyl.cpp b/src/elements/boyl.cpp similarity index 100% rename from elements/boyl.cpp rename to src/elements/boyl.cpp diff --git a/elements/brmt.cpp b/src/elements/brmt.cpp similarity index 100% rename from elements/brmt.cpp rename to src/elements/brmt.cpp diff --git a/elements/btry.cpp b/src/elements/btry.cpp similarity index 100% rename from elements/btry.cpp rename to src/elements/btry.cpp diff --git a/elements/c5.cpp b/src/elements/c5.cpp similarity index 100% rename from elements/c5.cpp rename to src/elements/c5.cpp diff --git a/elements/caus.cpp b/src/elements/caus.cpp similarity index 100% rename from elements/caus.cpp rename to src/elements/caus.cpp diff --git a/elements/cbnw.cpp b/src/elements/cbnw.cpp similarity index 100% rename from elements/cbnw.cpp rename to src/elements/cbnw.cpp diff --git a/elements/clne.cpp b/src/elements/clne.cpp similarity index 100% rename from elements/clne.cpp rename to src/elements/clne.cpp diff --git a/elements/clst.cpp b/src/elements/clst.cpp similarity index 100% rename from elements/clst.cpp rename to src/elements/clst.cpp diff --git a/elements/co2.cpp b/src/elements/co2.cpp similarity index 100% rename from elements/co2.cpp rename to src/elements/co2.cpp diff --git a/elements/coal.cpp b/src/elements/coal.cpp similarity index 100% rename from elements/coal.cpp rename to src/elements/coal.cpp diff --git a/elements/conv.cpp b/src/elements/conv.cpp similarity index 100% rename from elements/conv.cpp rename to src/elements/conv.cpp diff --git a/elements/dest.cpp b/src/elements/dest.cpp similarity index 100% rename from elements/dest.cpp rename to src/elements/dest.cpp diff --git a/elements/deut.cpp b/src/elements/deut.cpp similarity index 100% rename from elements/deut.cpp rename to src/elements/deut.cpp diff --git a/elements/dlay.cpp b/src/elements/dlay.cpp similarity index 100% rename from elements/dlay.cpp rename to src/elements/dlay.cpp diff --git a/elements/dstw.cpp b/src/elements/dstw.cpp similarity index 100% rename from elements/dstw.cpp rename to src/elements/dstw.cpp diff --git a/elements/elec.cpp b/src/elements/elec.cpp similarity index 100% rename from elements/elec.cpp rename to src/elements/elec.cpp diff --git a/elements/elementmisc.cpp b/src/elements/elementmisc.cpp similarity index 100% rename from elements/elementmisc.cpp rename to src/elements/elementmisc.cpp diff --git a/elements/emp.cpp b/src/elements/emp.cpp similarity index 100% rename from elements/emp.cpp rename to src/elements/emp.cpp diff --git a/elements/figh.cpp b/src/elements/figh.cpp similarity index 100% rename from elements/figh.cpp rename to src/elements/figh.cpp diff --git a/elements/fire.cpp b/src/elements/fire.cpp similarity index 100% rename from elements/fire.cpp rename to src/elements/fire.cpp diff --git a/elements/firw.cpp b/src/elements/firw.cpp similarity index 100% rename from elements/firw.cpp rename to src/elements/firw.cpp diff --git a/elements/fog.cpp b/src/elements/fog.cpp similarity index 100% rename from elements/fog.cpp rename to src/elements/fog.cpp diff --git a/elements/frzw.cpp b/src/elements/frzw.cpp similarity index 100% rename from elements/frzw.cpp rename to src/elements/frzw.cpp diff --git a/elements/frzz.cpp b/src/elements/frzz.cpp similarity index 100% rename from elements/frzz.cpp rename to src/elements/frzz.cpp diff --git a/elements/fsep.cpp b/src/elements/fsep.cpp similarity index 100% rename from elements/fsep.cpp rename to src/elements/fsep.cpp diff --git a/elements/fuse.cpp b/src/elements/fuse.cpp similarity index 100% rename from elements/fuse.cpp rename to src/elements/fuse.cpp diff --git a/elements/fwrk.cpp b/src/elements/fwrk.cpp similarity index 100% rename from elements/fwrk.cpp rename to src/elements/fwrk.cpp diff --git a/elements/gbmb.cpp b/src/elements/gbmb.cpp similarity index 100% rename from elements/gbmb.cpp rename to src/elements/gbmb.cpp diff --git a/elements/glas.cpp b/src/elements/glas.cpp similarity index 100% rename from elements/glas.cpp rename to src/elements/glas.cpp diff --git a/elements/glow.cpp b/src/elements/glow.cpp similarity index 100% rename from elements/glow.cpp rename to src/elements/glow.cpp diff --git a/elements/goo.cpp b/src/elements/goo.cpp similarity index 100% rename from elements/goo.cpp rename to src/elements/goo.cpp diff --git a/elements/gpmp.cpp b/src/elements/gpmp.cpp similarity index 100% rename from elements/gpmp.cpp rename to src/elements/gpmp.cpp diff --git a/elements/graphics_default.cpp b/src/elements/graphics_default.cpp similarity index 100% rename from elements/graphics_default.cpp rename to src/elements/graphics_default.cpp diff --git a/elements/h2.cpp b/src/elements/h2.cpp similarity index 100% rename from elements/h2.cpp rename to src/elements/h2.cpp diff --git a/elements/hswc.cpp b/src/elements/hswc.cpp similarity index 100% rename from elements/hswc.cpp rename to src/elements/hswc.cpp diff --git a/elements/ice.cpp b/src/elements/ice.cpp similarity index 100% rename from elements/ice.cpp rename to src/elements/ice.cpp diff --git a/elements/ignt.cpp b/src/elements/ignt.cpp similarity index 100% rename from elements/ignt.cpp rename to src/elements/ignt.cpp diff --git a/elements/iron.cpp b/src/elements/iron.cpp similarity index 100% rename from elements/iron.cpp rename to src/elements/iron.cpp diff --git a/elements/isz.cpp b/src/elements/isz.cpp similarity index 100% rename from elements/isz.cpp rename to src/elements/isz.cpp diff --git a/elements/lava.cpp b/src/elements/lava.cpp similarity index 100% rename from elements/lava.cpp rename to src/elements/lava.cpp diff --git a/elements/lcry.cpp b/src/elements/lcry.cpp similarity index 100% rename from elements/lcry.cpp rename to src/elements/lcry.cpp diff --git a/elements/legacy.cpp b/src/elements/legacy.cpp similarity index 100% rename from elements/legacy.cpp rename to src/elements/legacy.cpp diff --git a/elements/ligh.cpp b/src/elements/ligh.cpp similarity index 100% rename from elements/ligh.cpp rename to src/elements/ligh.cpp diff --git a/elements/merc.cpp b/src/elements/merc.cpp similarity index 100% rename from elements/merc.cpp rename to src/elements/merc.cpp diff --git a/elements/mort.cpp b/src/elements/mort.cpp similarity index 100% rename from elements/mort.cpp rename to src/elements/mort.cpp diff --git a/elements/nbhl.cpp b/src/elements/nbhl.cpp similarity index 100% rename from elements/nbhl.cpp rename to src/elements/nbhl.cpp diff --git a/elements/neut.cpp b/src/elements/neut.cpp similarity index 100% rename from elements/neut.cpp rename to src/elements/neut.cpp diff --git a/elements/newgraphics.cpp b/src/elements/newgraphics.cpp similarity index 100% rename from elements/newgraphics.cpp rename to src/elements/newgraphics.cpp diff --git a/elements/none.cpp b/src/elements/none.cpp similarity index 100% rename from elements/none.cpp rename to src/elements/none.cpp diff --git a/elements/nptct.cpp b/src/elements/nptct.cpp similarity index 100% rename from elements/nptct.cpp rename to src/elements/nptct.cpp diff --git a/elements/nwhl.cpp b/src/elements/nwhl.cpp similarity index 100% rename from elements/nwhl.cpp rename to src/elements/nwhl.cpp diff --git a/elements/pbcn.cpp b/src/elements/pbcn.cpp similarity index 100% rename from elements/pbcn.cpp rename to src/elements/pbcn.cpp diff --git a/elements/pcln.cpp b/src/elements/pcln.cpp similarity index 100% rename from elements/pcln.cpp rename to src/elements/pcln.cpp diff --git a/elements/phot.cpp b/src/elements/phot.cpp similarity index 100% rename from elements/phot.cpp rename to src/elements/phot.cpp diff --git a/elements/pipe.cpp b/src/elements/pipe.cpp similarity index 100% rename from elements/pipe.cpp rename to src/elements/pipe.cpp diff --git a/elements/plnt.cpp b/src/elements/plnt.cpp similarity index 100% rename from elements/plnt.cpp rename to src/elements/plnt.cpp diff --git a/elements/plsm.cpp b/src/elements/plsm.cpp similarity index 100% rename from elements/plsm.cpp rename to src/elements/plsm.cpp diff --git a/elements/plut.cpp b/src/elements/plut.cpp similarity index 100% rename from elements/plut.cpp rename to src/elements/plut.cpp diff --git a/elements/prti.cpp b/src/elements/prti.cpp similarity index 100% rename from elements/prti.cpp rename to src/elements/prti.cpp diff --git a/elements/prto.cpp b/src/elements/prto.cpp similarity index 100% rename from elements/prto.cpp rename to src/elements/prto.cpp diff --git a/elements/pump.cpp b/src/elements/pump.cpp similarity index 100% rename from elements/pump.cpp rename to src/elements/pump.cpp diff --git a/elements/pvod.cpp b/src/elements/pvod.cpp similarity index 100% rename from elements/pvod.cpp rename to src/elements/pvod.cpp diff --git a/elements/pyro.cpp b/src/elements/pyro.cpp similarity index 100% rename from elements/pyro.cpp rename to src/elements/pyro.cpp diff --git a/elements/qrtz.cpp b/src/elements/qrtz.cpp similarity index 100% rename from elements/qrtz.cpp rename to src/elements/qrtz.cpp diff --git a/elements/rime.cpp b/src/elements/rime.cpp similarity index 100% rename from elements/rime.cpp rename to src/elements/rime.cpp diff --git a/elements/shld.cpp b/src/elements/shld.cpp similarity index 100% rename from elements/shld.cpp rename to src/elements/shld.cpp diff --git a/elements/sing.cpp b/src/elements/sing.cpp similarity index 100% rename from elements/sing.cpp rename to src/elements/sing.cpp diff --git a/elements/sltw.cpp b/src/elements/sltw.cpp similarity index 100% rename from elements/sltw.cpp rename to src/elements/sltw.cpp diff --git a/elements/smke.cpp b/src/elements/smke.cpp similarity index 100% rename from elements/smke.cpp rename to src/elements/smke.cpp diff --git a/elements/soap.cpp b/src/elements/soap.cpp similarity index 100% rename from elements/soap.cpp rename to src/elements/soap.cpp diff --git a/elements/spng.cpp b/src/elements/spng.cpp similarity index 100% rename from elements/spng.cpp rename to src/elements/spng.cpp diff --git a/elements/sprk.cpp b/src/elements/sprk.cpp similarity index 100% rename from elements/sprk.cpp rename to src/elements/sprk.cpp diff --git a/elements/stkm.cpp b/src/elements/stkm.cpp similarity index 100% rename from elements/stkm.cpp rename to src/elements/stkm.cpp diff --git a/elements/stkm2.cpp b/src/elements/stkm2.cpp similarity index 100% rename from elements/stkm2.cpp rename to src/elements/stkm2.cpp diff --git a/elements/stor.cpp b/src/elements/stor.cpp similarity index 100% rename from elements/stor.cpp rename to src/elements/stor.cpp diff --git a/elements/swch.cpp b/src/elements/swch.cpp similarity index 100% rename from elements/swch.cpp rename to src/elements/swch.cpp diff --git a/elements/thdr.cpp b/src/elements/thdr.cpp similarity index 100% rename from elements/thdr.cpp rename to src/elements/thdr.cpp diff --git a/elements/thrm.cpp b/src/elements/thrm.cpp similarity index 100% rename from elements/thrm.cpp rename to src/elements/thrm.cpp diff --git a/elements/uran.cpp b/src/elements/uran.cpp similarity index 100% rename from elements/uran.cpp rename to src/elements/uran.cpp diff --git a/elements/vine.cpp b/src/elements/vine.cpp similarity index 100% rename from elements/vine.cpp rename to src/elements/vine.cpp diff --git a/elements/warp.cpp b/src/elements/warp.cpp similarity index 100% rename from elements/warp.cpp rename to src/elements/warp.cpp diff --git a/elements/watr.cpp b/src/elements/watr.cpp similarity index 100% rename from elements/watr.cpp rename to src/elements/watr.cpp diff --git a/elements/wifi.cpp b/src/elements/wifi.cpp similarity index 100% rename from elements/wifi.cpp rename to src/elements/wifi.cpp diff --git a/elements/wire.cpp b/src/elements/wire.cpp similarity index 100% rename from elements/wire.cpp rename to src/elements/wire.cpp diff --git a/elements/wtrv.cpp b/src/elements/wtrv.cpp similarity index 100% rename from elements/wtrv.cpp rename to src/elements/wtrv.cpp diff --git a/elements/yest.cpp b/src/elements/yest.cpp similarity index 100% rename from elements/yest.cpp rename to src/elements/yest.cpp diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp new file mode 100644 index 000000000..becb54082 --- /dev/null +++ b/src/game/GameController.cpp @@ -0,0 +1,62 @@ + +#include +#include +#include "Config.h" +#include "GameController.h" +#include "GameModel.h" +#include "interface/Point.h" + +using namespace std; + +GameController::GameController() +{ + gameView = new GameView(); + gameModel = new GameModel(); + + gameView->AttachController(this); + gameModel->AddObserver(gameView); + + sim = new Simulation(); +} + +GameView * GameController::GetView() +{ + return gameView; +} + +void GameController::DrawPoints(queue & pointQueue) +{ + Simulation * sim = gameModel->GetSimulation(); + int activeElement = gameModel->GetActiveElement(); + if(!pointQueue.empty()) + { + ui::Point * sPoint = NULL; + while(!pointQueue.empty()) + { + ui::Point * fPoint = pointQueue.front(); + pointQueue.pop(); + if(sPoint) + { + sim->create_line(fPoint->X, fPoint->Y, sPoint->X, sPoint->Y, 1, 1, activeElement, 0); + delete sPoint; + } + else + { + sim->create_parts(fPoint->X, fPoint->Y, 1, 1, activeElement, 0); + } + sPoint = fPoint; + } + if(sPoint) + delete sPoint; + } +} + +void GameController::Tick() +{ + gameModel->GetSimulation()->update_particles(); +} + +void GameController::SetPaused(bool pauseState) +{ + gameModel->SetPaused(pauseState); +} diff --git a/src/game/GameController.h b/src/game/GameController.h new file mode 100644 index 000000000..c3c827318 --- /dev/null +++ b/src/game/GameController.h @@ -0,0 +1,28 @@ +#ifndef GAMECONTROLLER_H +#define GAMECONTROLLER_H + +#include +#include "GameView.h" +#include "GameModel.h" +#include "interface/Point.h" +#include "Simulation.h" + +using namespace std; + +class GameModel; +class GameView; +class GameController +{ +private: + Simulation * sim; + GameView * gameView; + GameModel * gameModel; +public: + GameController(); + GameView * GetView(); + void DrawPoints(queue & pointQueue); + void Tick(); + void SetPaused(bool pauseState); +}; + +#endif // GAMECONTROLLER_H diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp new file mode 100644 index 000000000..96b29a9f4 --- /dev/null +++ b/src/game/GameModel.cpp @@ -0,0 +1,75 @@ +#include "interface/Engine.h" +#include "GameModel.h" +#include "GameView.h" +#include "Simulation.h" +#include "Renderer.h" + +GameModel::GameModel(): + activeElement(1) +{ + sim = new Simulation(); + ren = new Renderer(ui::Engine::Ref().g, sim); +} + +void GameModel::AddObserver(GameView * observer){ + observers.push_back(observer); + + observer->NotifySimulationChanged(this); + observer->NotifyRendererChanged(this); + observer->NotifyPausedChanged(this); +} + +int GameModel::GetActiveElement() +{ + return activeElement; +} + +void GameModel::SetActiveElement(int element) +{ + activeElement = element; +} + +Simulation * GameModel::GetSimulation() +{ + return sim; +} + +Renderer * GameModel::GetRenderer() +{ + return ren; +} + +void GameModel::SetPaused(bool pauseState) +{ + sim->sys_pause = pauseState?1:0; + notifyPausedChanged(); +} + +bool GameModel::GetPaused() +{ + return sim->sys_pause?true:false; +} + +void GameModel::notifyRendererChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyRendererChanged(this); + } +} + +void GameModel::notifySimulationChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifySimulationChanged(this); + } +} + +void GameModel::notifyPausedChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + observers[i]->NotifyPausedChanged(this); + } +} diff --git a/src/game/GameModel.h b/src/game/GameModel.h new file mode 100644 index 000000000..a2eb3cea0 --- /dev/null +++ b/src/game/GameModel.h @@ -0,0 +1,37 @@ +#ifndef GAMEMODEL_H +#define GAMEMODEL_H + +#include +#include "Simulation.h" +#include "Renderer.h" +#include "GameView.h" + +using namespace std; + +class GameView; +class Simulation; +class Renderer; + +class GameModel +{ +private: + vector observers; + Simulation * sim; + Renderer * ren; + int activeElement; + void notifyRendererChanged(); + void notifySimulationChanged(); + void notifyPausedChanged(); +public: + GameModel(); + void AddObserver(GameView * observer); + int GetActiveElement(); + void SetActiveElement(int element); + bool GetPaused(); + void SetPaused(bool pauseState); + + Simulation * GetSimulation(); + Renderer * GetRenderer(); +}; + +#endif // GAMEMODEL_H diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp new file mode 100644 index 000000000..2576527fd --- /dev/null +++ b/src/game/GameView.cpp @@ -0,0 +1,83 @@ +#include "Config.h" +#include "GameView.h" +#include "interface/Window.h" +#include "interface/Button.h" + +GameView::GameView(): + ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)), + pointQueue(queue()), + isMouseDown(false), + ren(NULL) +{ + //Set up UI + class PauseAction : public ui::ButtonAction + { + GameView * v; + public: + PauseAction(GameView * _v) { v = _v; } + void ActionCallback(ui::Button * sender) + { + v->c->SetPaused(sender->GetToggleState()); + } + }; + pauseButton = new ui::Button(ui::Point(Size.X-18, Size.Y-18), ui::Point(16, 16), "\x90"); //Pause + pauseButton->SetTogglable(true); + pauseButton->SetActionCallback(new PauseAction(this)); + AddComponent(pauseButton); +} + +void GameView::NotifyRendererChanged(GameModel * sender) +{ + ren = sender->GetRenderer(); +} + +void GameView::NotifySimulationChanged(GameModel * sender) +{ + +} + +void GameView::NotifyPausedChanged(GameModel * sender) +{ + pauseButton->SetToggleState(sender->GetPaused()); +} + +void GameView::OnMouseMove(int x, int y, int dx, int dy) +{ + if(isMouseDown) + { + pointQueue.push(new ui::Point(x-dx, y-dy)); + pointQueue.push(new ui::Point(x, y)); + } +} + +void GameView::OnMouseDown(int x, int y, unsigned button) +{ + isMouseDown = true; + pointQueue.push(new ui::Point(x, y)); +} + +void GameView::OnMouseUp(int x, int y, unsigned button) +{ + if(isMouseDown) + { + isMouseDown = false; + pointQueue.push(new ui::Point(x, y)); + } +} + +void GameView::OnTick(float dt) +{ + if(!pointQueue.empty()) + { + c->DrawPoints(pointQueue); + } + c->Tick(); +} + +void GameView::OnDraw() +{ + if(ren) + { + ren->render_parts(); + } +} diff --git a/src/game/GameView.h b/src/game/GameView.h new file mode 100644 index 000000000..531a4b9fd --- /dev/null +++ b/src/game/GameView.h @@ -0,0 +1,48 @@ +#ifndef GAMEVIEW_H +#define GAMEVIEW_H + +#include +#include "GameController.h" +#include "GameModel.h" +#include "interface/Window.h" +#include "interface/Point.h" +#include "interface/Button.h" + +using namespace std; + +class GameController; +class GameModel; +class GameView: public ui::Window +{ +private: + bool isMouseDown; + queue pointQueue; + GameController * c; + Renderer * ren; + //UI Elements + ui::Button * pauseButton; +public: + GameView(); + void AttachController(GameController * _c){ c = _c; } + void NotifyRendererChanged(GameModel * sender); + void NotifySimulationChanged(GameModel * sender); + void NotifyPausedChanged(GameModel * sender); + /*virtual void DoMouseMove(int x, int y, int dx, int dy); + virtual void DoMouseDown(int x, int y, unsigned button); + virtual void DoMouseUp(int x, int y, unsigned button); + //virtual void DoMouseWheel(int x, int y, int d); + //virtual void DoKeyPress(int key, bool shift, bool ctrl, bool alt); + //virtual void DoKeyRelease(int key, bool shift, bool ctrl, bool alt); + virtual void DoTick(float dt); + virtual void DoDraw();*/ + virtual void OnMouseMove(int x, int y, int dx, int dy); + virtual void OnMouseDown(int x, int y, unsigned button); + virtual void OnMouseUp(int x, int y, unsigned button); + //virtual void OnMouseWheel(int x, int y, int d) {} + //virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {} + //virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {} + virtual void OnTick(float dt); + virtual void OnDraw(); +}; + +#endif // GAMEVIEW_H diff --git a/src/interface.old/Button.cpp b/src/interface.old/Button.cpp deleted file mode 100644 index a357c363d..000000000 --- a/src/interface.old/Button.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Button.cpp - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#include - -#include "interface/Button.h" -#include "Graphics.h" - -namespace ui { - -Button::Button(int x, int y, int width, int height, const std::string& buttonText): - Component(x, y, width, height), - Toggleable(false), - ButtonText(buttonText), - isMouseInside(false), - isButtonDown(false), - state(false) -{ - -} - -void Button::Draw(void* userdata) -{ - Graphics * g = reinterpret_cast(userdata); - //TODO: Cache text location, that way we don't have the text alignment code here - if(isButtonDown) - { - g->fillrect(X, Y, Width, Height, 255, 255, 255, 255); - g->drawtext(X+(Width-Graphics::textwidth((char *)ButtonText.c_str()))/2, Y+(Height-10)/2, ButtonText, 0, 0, 0, 255); - } - else - { - if(isMouseInside) - g->fillrect(X, Y, Width, Height, 20, 20, 20, 255); - g->drawrect(X, Y, Width, Height, 255, 255, 255, 255); - g->drawtext(X+(Width-Graphics::textwidth((char *)ButtonText.c_str()))/2, Y+(Height-10)/2, ButtonText, 255, 255, 255, 255); - } - /*sf::RenderWindow* rw = reinterpret_cast(userdata); //it better be a RenderWindow or so help your god - - //Draw component here - sf::Text textGraphic(ButtonText); - textGraphic.SetCharacterSize(11); - if(isButtonDown) - textGraphic.SetColor(sf::Color::Black); - else - textGraphic.SetColor(sf::Color::White); - sf::FloatRect tempRect = textGraphic.GetRect(); - textGraphic.SetPosition(ceil(X + Width/2 - tempRect.Width/2), ceil(Y + Height/2 - tempRect.Height/2)); - - if(isMouseInside) - { - if(isButtonDown) - rw->Draw(sf::Shape::Rectangle(X+2, Y+2, Width-4, Width-4, sf::Color::White, 2.f, sf::Color::Black)); - else - rw->Draw(sf::Shape::Rectangle(X+2, Y+2, Width-4, Width-4, sf::Color::Black, 2.f, sf::Color::White)); - } - else - { - if(isButtonDown) - rw->Draw(sf::Shape::Rectangle(X+2, Y+2, Width-4, Width-4, sf::Color::White, 2.f, sf::Color::Black)); - else - rw->Draw(sf::Shape::Rectangle(X+1, Y+1, Width-2, Width-2, sf::Color::Black, 1.f, sf::Color::White)); - } - - rw->Draw(textGraphic);*/ -} - -void Button::OnMouseUnclick(int x, int y, unsigned int button) -{ - if(button != 1) - { - return; //left click only! - } - - if(isButtonDown) - { - if(state) - { - state = false; - } - else - { - if(Toggleable) - { - state = true; - } - DoAction(); - } - } - - isButtonDown = false; -} - -void Button::OnMouseUp(int x, int y, unsigned int button) //mouse unclick is called before this -{ - if(button != 1) return; //left click only! - - isButtonDown = false; -} - -void Button::OnMouseClick(int x, int y, unsigned int button) -{ - if(button != 1) return; //left click only! - - isButtonDown = true; -} - -void Button::OnMouseEnter(int x, int y, int dx, int dy) -{ - isMouseInside = true; -} - -void Button::OnMouseLeave(int x, int y, int dx, int dy) -{ - isMouseInside = false; -} - -void Button::DoAction() -{ - std::cout << "Do action!"<Add(new ui::Button(0, 0, 20, 20, "Turd")); - return mainMenu; -} diff --git a/src/interface.old/Panel.cpp b/src/interface.old/Panel.cpp deleted file mode 100644 index 164bfa305..000000000 --- a/src/interface.old/Panel.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Panel.cpp - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#include "interface/Panel.h" - -namespace ui { - -Panel::Panel(int x, int y, int width, int height): - Component(x, y, width, height) -{ - // TODO Auto-generated constructor stub - -} - -Panel::~Panel() { - // TODO Auto-generated destructor stub -} - -} /* namespace ui */ diff --git a/src/interface.old/Sandbox.cpp b/src/interface.old/Sandbox.cpp deleted file mode 100644 index 5e29bae04..000000000 --- a/src/interface.old/Sandbox.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Sandbox.cpp - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#include - -#include "Config.h" - -#include "interface/Sandbox.h" -#include "interface/Component.h" -#include "Renderer.h" -#include "Simulation.h" - -namespace ui { - -Sandbox::Sandbox(): - Component(0, 0, XRES, YRES), - ren(NULL), - isMouseDown(false), - activeElement(1) -{ - sim = new Simulation(); -} - -Simulation * Sandbox::GetSimulation() -{ - return sim; -} - -void Sandbox::OnMouseMovedInside(int localx, int localy, int dx, int dy) -{ - if(isMouseDown) - { - sim->create_line(lastCoordX, lastCoordY, localx, localy, 2, 2, activeElement, 0); - lastCoordX = localx; - lastCoordY = localy; - } -} - -void Sandbox::OnMouseDown(int localx, int localy, unsigned int button) -{ - sim->create_line(localx, localy, localx, localy, 2, 2, activeElement, 0); - lastCoordX = localx; - lastCoordY = localy; - isMouseDown = true; -} - -void Sandbox::OnMouseUp(int localx, int localy, unsigned int button) -{ - sim->create_line(lastCoordX, lastCoordY, localx, localy, 2, 2, activeElement, 0); - lastCoordX = localx; - lastCoordY = localy; - isMouseDown = false; -} - -void Sandbox::Draw(void* userdata) -{ - Graphics * g = reinterpret_cast(userdata); - if(!ren) - ren = new Renderer(g, sim); - ren->render_parts(); -} - -void Sandbox::Tick(float delta) -{ - sim->update_particles(); -} - -Sandbox::~Sandbox() { - // TODO Auto-generated destructor stub -} - -} /* namespace ui */ diff --git a/src/interface.old/State.cpp b/src/interface.old/State.cpp deleted file mode 100644 index 28287510b..000000000 --- a/src/interface.old/State.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* - * State.cpp - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#include -#include -#include - -#include "interface/State.h" - -namespace ui { - -State::State(int w, int h): - mouseX(0), - mouseY(0), - mouseXP(0), - mouseYP(0), - width(w), - height(h), - Components() -{ -} - -State::~State() -{ - //Components.~vector(); // just in case // devnote : Nope.jpg Nate :3 -frankbro -} - -void State::Add(Component* child) -{ - Components.push_back(child); - child->Parent = this; -} - -void State::Remove(Component* child) -{ - for(int i = 0; i < Components.size(); i++) - if(Components[i] == child) - { - Components.erase(Components.begin() + i); - break; - } -} - -void State::Draw(void* userdata) -{ - //draw - for(int i = 0; i < Components.size(); i++) - { - if(Components[i]->Visible) - { - if(AllowExclusiveDrawing) - { - Components[i]->Draw(userdata); - } - else if( - Components[i]->X + Components[i]->Width >= 0 && - Components[i]->Y + Components[i]->Height >= 0 && - Components[i]->X < width && - Components[i]->Y < height ) - { - Components[i]->Draw(userdata); - } - } - } -} - -void State::Tick(float dt) -{ - //on mouse hover - for(int i = 0; i < Components.size(); i++) - if( mouseX >= Components[i]->X && - mouseY >= Components[i]->Y && - mouseX < Components[i]->X + Components[i]->Width && - mouseY < Components[i]->Y + Components[i]->Height ) - { - if(Components[i]->Enabled) - { - Components[i]->OnMouseHover(mouseX, mouseY); - } - break; - } - - //tick - for(int i = 0; i < Components.size(); i++) - Components[i]->Tick(dt); -} - -void State::OnKeyPress(int key, bool shift, bool ctrl, bool alt) -{ - //on key press - if(focusedComponent_ != NULL) - if(focusedComponent_->Enabled) - focusedComponent_->OnKeyPress(key, shift, ctrl, alt); -} - -void State::OnKeyRelease(int key, bool shift, bool ctrl, bool alt) -{ - //on key unpress - if(focusedComponent_ != NULL) - if(focusedComponent_->Enabled) - focusedComponent_->OnKeyRelease(key, shift, ctrl, alt); -} - -void State::OnMouseDown(int x, int y, unsigned int button) -{ - //on mouse click - for(int i = Components.size() - 1; i > -1 ; i--) - if(Components[i]->Enabled) - if(x >= Components[i]->X && y >= Components[i]->Y && x < Components[i]->X + Components[i]->Width && y < Components[i]->Y + Components[i]->Height) - { - Components[i]->OnMouseClick(x - Components[i]->X, y - Components[i]->Y, button); - this->focusedComponent_ = Components[i]; //set this component as the focused component - break; - } - - //on mouse down - for(int i = Components.size() - 1; i > -1 ; i--) - if(Components[i]->Enabled) - Components[i]->OnMouseDown(x - Components[i]->X, y - Components[i]->Y, button); -} - -void State::OnMouseMove(int x, int y) -{ - //update mouse coords - mouseX = x; - mouseY = y; - - //on mouse move (if true, and inside) - for(int i = Components.size() - 1; i > -1 ; i--) - if(Components[i]->Enabled) - { - int localX = x - Components[i]->X; - int localY = y - Components[i]->Y; - int localXP = mouseXP - Components[i]->X; - int localYP = mouseYP - Components[i]->Y; - int dx = x - mouseXP; - int dy = x - mouseYP; - - Components[i]->OnMouseMoved(localX, localY, dx, dy); - - //is the mouse inside - if(localX >= 0 && - localY >= 0 && - localX < Components[i]->Width && - localY < Components[i]->Height ) - { - //was the mouse outside last tick? - if(localXP < 0 || - localXP >= Components[i]->Width || - localYP < 0 || - localYP >= Components[i]->Height ) - { - Components[i]->OnMouseEnter(localX, localY, dx, dy); - } - - Components[i]->OnMouseMovedInside(localX, localY, dx, dy); - - break; //found the top-most component under mouse, break that shit - } - //not inside, let's see if it used to be inside last tick - else if (localXP >= 0 && - localYP >= 0 && - localXP < Components[i]->Width && - localYP < Components[i]->Height ) - { - Components[i]->OnMouseLeave(localX, localY, x - mouseXP, y - mouseYP); - } - } - else //is locked - { - int localX = x - Components[i]->X; - int localY = y - Components[i]->Y; - - //is the mouse inside - if(localX >= 0 && - localY >= 0 && - localX < Components[i]->Width && - localY < Components[i]->Height ) - { - break; //it's the top-most component under the mouse, we don't want to go under it. - } - } - // end of for loop here - - //set the previous mouse coords - mouseXP = x; - mouseYP = y; -} - -void State::OnMouseUp(int x, int y, unsigned int button) -{ - //on mouse unclick - for(int i = Components.size() - 1; i > -1 ; i--) - if(Components[i]->Enabled) - if(x >= Components[i]->X && y >= Components[i]->Y && x < Components[i]->X + Components[i]->Width && y < Components[i]->Y + Components[i]->Height) - { - Components[i]->OnMouseUnclick(x - Components[i]->X, y - Components[i]->Y, button); - break; - } - - //on mouse up - for(int i = Components.size() - 1; i > -1 ; i--) - if(Components[i]->Enabled) - Components[i]->OnMouseUp(x - Components[i]->X, y - Components[i]->Y, button); -} - -void State::OnMouseWheel(int x, int y, int d) -{ - //focused mouse wheel - if(focusedComponent_ != NULL) - focusedComponent_->OnMouseWheelFocused(x - focusedComponent_->X, y - focusedComponent_->Y, d); - - //mouse wheel inside - for(int i = Components.size() - 1; i > -1 ; i--) - if(x >= Components[i]->X && y >= Components[i]->Y && x < Components[i]->X + Components[i]->Width && y < Components[i]->Y + Components[i]->Height) - { - if(Components[i]->Enabled) - Components[i]->OnMouseWheelInside(x - Components[i]->X, y - Components[i]->Y, d); - break; //found top-most component under mouse - } - - //on mouse wheel - for(int i = Components.size() - 1; i > -1 ; i--) - if(Components[i]->Enabled) - Components[i]->OnMouseWheel(x - Components[i]->X, y - Components[i]->Y, d); -} - - -} /* namespace ui */ diff --git a/src/interface.old/Window.cpp b/src/interface.old/Window.cpp deleted file mode 100644 index 624bf9a6c..000000000 --- a/src/interface.old/Window.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Window.cpp - * - * Created on: Jan 8, 2012 - * Author: Simon - */ - -#include "interface/Window.h" - -namespace ui { - -Window::Window(): - State(width, height) -{ - // TODO Auto-generated constructor stub - -} - -Window::~Window() { - // TODO Auto-generated destructor stub -} - -} /* namespace ui */ diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp index 6ea985432..a3f76b94c 100644 --- a/src/interface/Button.cpp +++ b/src/interface/Button.cpp @@ -10,15 +10,17 @@ #include "interface/Button.h" #include "Graphics.h" #include "Global.h" +#include "Engine.h" namespace ui { -Button::Button(State* parent_state, std::string buttonText): +Button::Button(Window* parent_state, std::string buttonText): Component(parent_state), ButtonText(buttonText), isMouseInside(false), isButtonDown(false), - isTogglable(false) + isTogglable(false), + actionCallback(NULL) { } @@ -28,7 +30,8 @@ Button::Button(Point position, Point size, std::string buttonText): ButtonText(buttonText), isMouseInside(false), isButtonDown(false), - isTogglable(false) + isTogglable(false), + actionCallback(NULL) { } @@ -38,7 +41,8 @@ Button::Button(std::string buttonText): ButtonText(buttonText), isMouseInside(false), isButtonDown(false), - isTogglable(false) + isTogglable(false), + actionCallback(NULL) { } @@ -68,13 +72,13 @@ inline void Button::SetToggleState(bool state) void Button::Draw(const Point& screenPos) { - Graphics * g = Global::Ref().g; + Graphics * g = ui::Engine::Ref().g; Point Position = screenPos; // = reinterpret_cast(userdata); //TODO: Cache text location, that way we don't have the text alignment code here if(isButtonDown || (isTogglable && toggle)) { - g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255); + g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, 255, 255, 255, 255); g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)ButtonText.c_str()))/2, Position.Y+(Size.Y-10)/2, ButtonText, 0, 0, 0, 255); } else @@ -116,7 +120,6 @@ void Button::Draw(const Point& screenPos) void Button::OnMouseUnclick(int x, int y, unsigned int button) { - std::cout << "Unclick!" << std::endl; if(button != 1) { return; //left click only! @@ -160,6 +163,15 @@ void Button::OnMouseLeave(int x, int y) void Button::DoAction() { std::cout << "Do action!"<ActionCallback(this); +} + +void Button::SetActionCallback(ButtonAction * action) +{ + actionCallback = action; } Button::~Button() diff --git a/src/interface/Button.h b/src/interface/Button.h new file mode 100644 index 000000000..5f2d71ff7 --- /dev/null +++ b/src/interface/Button.h @@ -0,0 +1,60 @@ +/* + * Button.h + * + * Created on: Jan 8, 2012 + * Author: Simon + */ + +#ifndef BUTTON_H_ +#define BUTTON_H_ + +#include + +#include "Component.h" + +namespace ui +{ +class Button; +class ButtonAction +{ +public: + virtual void ActionCallback(ui::Button * sender) {} +}; + +class Button : public Component +{ +public: + Button(Window* parent_state, std::string buttonText); + + Button(Point position, Point size, std::string buttonText); + + Button(std::string buttonText); + virtual ~Button(); + + bool Toggleable; + + std::string ButtonText; + + virtual void OnMouseClick(int x, int y, unsigned int button); + virtual void OnMouseUnclick(int x, int y, unsigned int button); + //virtual void OnMouseUp(int x, int y, unsigned int button); + + virtual void OnMouseEnter(int x, int y); + virtual void OnMouseLeave(int x, int y); + + virtual void Draw(const Point& screenPos); + + inline bool GetState() { return state; } + virtual void DoAction(); //action of button what ever it may be + void SetTogglable(bool isTogglable); + bool GetTogglable(); + inline bool GetToggleState(); + inline void SetToggleState(bool state); + void SetActionCallback(ButtonAction * action); + +protected: + bool isButtonDown, state, isMouseInside, isTogglable, toggle; + ButtonAction * actionCallback; +}; +} +#endif /* BUTTON_H_ */ diff --git a/src/interface/Component.cpp b/src/interface/Component.cpp index 49ff7f800..75e9c40f5 100644 --- a/src/interface/Component.cpp +++ b/src/interface/Component.cpp @@ -2,12 +2,12 @@ #include "interface/Component.h" #include "interface/Engine.h" #include "interface/Point.h" -#include "interface/State.h" +#include "interface/Window.h" #include "interface/Panel.h" using namespace ui; -Component::Component(State* parent_state): +Component::Component(Window* parent_state): parentstate_(parent_state), _parent(NULL), Position(Point(0,0)), @@ -45,9 +45,9 @@ bool Component::IsFocused() const return parentstate_->IsFocused(this); } -void Component::SetParentState(State* state) +void Component::SetParentWindow(Window* window) { - parentstate_ = state; + parentstate_ = window; } void Component::SetParent(Panel* new_parent) @@ -65,7 +65,7 @@ void Component::SetParent(Panel* new_parent) _parent->RemoveChild(i, false); // add ourself to the parent state - GetParentState()->AddComponent(this); + GetParentWindow()->AddComponent(this); //done in this loop. break; @@ -76,8 +76,8 @@ void Component::SetParent(Panel* new_parent) else { // remove from parent state (if in parent state) and place in new parent - if(GetParentState()) - GetParentState()->RemoveComponent(this); + if(GetParentWindow()) + GetParentWindow()->RemoveComponent(this); new_parent->children.push_back(this); } this->_parent = new_parent; diff --git a/includes/interface/Component.h b/src/interface/Component.h similarity index 96% rename from includes/interface/Component.h rename to src/interface/Component.h index 5759c082e..578aba672 100644 --- a/includes/interface/Component.h +++ b/src/interface/Component.h @@ -1,12 +1,12 @@ #pragma once #include "Point.h" -#include "State.h" +#include "Window.h" #include "Platform.h" namespace ui { - class State; + class Window; class Panel; /* class Component @@ -17,13 +17,13 @@ namespace ui class Component { public: - Component(State* parent_state); + Component(Window* parent_state); Component(Point position, Point size); Component(); virtual ~Component(); void* UserData; - inline State* const GetParentState() const { return parentstate_; } + inline Window* const GetParentWindow() const { return parentstate_; } bool IsFocused() const; Point Position; @@ -34,7 +34,7 @@ namespace ui /* See the parent of this component. * If new_parent is NULL, this component will have no parent. (THIS DOES NOT delete THE COMPONENT. See XComponent::RemoveChild) */ - void SetParentState(State* state); + void SetParentWindow(Window* window); void SetParent(Panel* new_parent); //Get the parent component. @@ -198,7 +198,7 @@ namespace ui virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt); private: - State* parentstate_; + Window* parentstate_; Panel* _parent; }; } diff --git a/src/interface/ControlFactory.cpp b/src/interface/ControlFactory.cpp index 372ed311e..7132499ed 100644 --- a/src/interface/ControlFactory.cpp +++ b/src/interface/ControlFactory.cpp @@ -50,10 +50,5 @@ ui::Panel * ControlFactory::MainMenu(int x, int y, int width, int height) mainMenu->AddChild(tempButton); //Render options currentX += 18; - tempButton = new ui::Button(ui::Point(currentX, 1), ui::Point(16, height-2), "\x90"); //Pause - tempButton->SetTogglable(true); - mainMenu->AddChild(tempButton); - currentX += 18; - return mainMenu; } diff --git a/includes/interface/ControlFactory.h b/src/interface/ControlFactory.h similarity index 100% rename from includes/interface/ControlFactory.h rename to src/interface/ControlFactory.h diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp index 25f203805..55a23709b 100644 --- a/src/interface/Engine.cpp +++ b/src/interface/Engine.cpp @@ -1,22 +1,25 @@ #include #include "Config.h" +#include + #include "Global.h" +#include "interface/Window.h" #include "interface/Platform.h" #include "interface/Engine.h" -#include "interface/State.h" #include "Graphics.h" using namespace ui; +using namespace std; Engine::Engine(): state_(NULL), - statequeued_(NULL), mousex_(0), mousey_(0), mousexp_(0), mouseyp_(0), - FpsLimit(60.0f) + FpsLimit(60.0f), + windows(stack()) { } @@ -40,7 +43,30 @@ void Engine::Exit() running_ = false; } -void Engine::SetState(State * state) +void Engine::ShowWindow(Window * window) +{ + if(state_) + { + windows.push(window); + } + state_ = window; + windows.push(window); +} + +void Engine::CloseWindow() +{ + if(!windows.empty()) + { + state_ = windows.top(); + windows.pop(); + } + else + { + state_ = NULL; + } +} + +/*void Engine::SetState(State * state) { if(state_) //queue if currently in a state statequeued_ = state; @@ -50,7 +76,7 @@ void Engine::SetState(State * state) if(state_) state_->DoInitialized(); } -} +}*/ void Engine::SetSize(int width, int height) { @@ -63,7 +89,7 @@ void Engine::Tick(float dt) if(state_ != NULL) state_->DoTick(dt); - if(statequeued_ != NULL) + /*if(statequeued_ != NULL) { if(state_ != NULL) { @@ -76,15 +102,15 @@ void Engine::Tick(float dt) if(state_ != NULL) state_->DoInitialized(); - } + }*/ } void Engine::Draw() { if(state_) state_->DoDraw(); - Global::Ref().g->Blit(); - Global::Ref().g->Clear(); + g->Blit(); + g->Clear(); } void Engine::onKeyPress(int key, bool shift, bool ctrl, bool alt) diff --git a/includes/interface/Engine.h b/src/interface/Engine.h similarity index 78% rename from includes/interface/Engine.h rename to src/interface/Engine.h index 6136fb4e3..7bf78f9d6 100644 --- a/includes/interface/Engine.h +++ b/src/interface/Engine.h @@ -1,14 +1,15 @@ #pragma once +#include #include #include "Singleton.h" #include "Platform.h" -#include "State.h" #include "Graphics.h" +#include "Window.h" namespace ui { - class State; + class Window; /* class Engine * @@ -21,6 +22,9 @@ namespace ui Engine(); ~Engine(); + void ShowWindow(Window * window); + void CloseWindow(); + void onMouseMove(int x, int y); void onMouseClick(int x, int y, unsigned button); void onMouseUnclick(int x, int y, unsigned button); @@ -44,12 +48,15 @@ namespace ui inline void SetSize(int width, int height); - void SetState(State* state); - inline State* GetState() { return state_; } + //void SetState(Window* state); + //inline State* GetState() { return state_; } + inline Window* GetWindow() { return state_; } float FpsLimit; + Graphics * g; private: - State* statequeued_; - State* state_; + std::stack windows; + //Window* statequeued_; + Window* state_; bool running_; diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp index c77b6bf04..cf09d4e42 100644 --- a/src/interface/Label.cpp +++ b/src/interface/Label.cpp @@ -6,7 +6,7 @@ using namespace ui; -Label::Label(State* parent_state, std::string labelText): +Label::Label(Window* parent_state, std::string labelText): Component(parent_state), LabelText(labelText) { @@ -35,6 +35,6 @@ Label::~Label() void Label::Draw(const Point& screenPos) { - Graphics * g = Global::Ref().g; + Graphics * g = Engine::Ref().g; g->drawtext(Position.X+(Size.X-Graphics::textwidth((char *)LabelText.c_str()))/2, Position.Y+(Size.Y-10)/2, LabelText, 255, 255, 255, 255); } diff --git a/includes/interface/Label.h b/src/interface/Label.h similarity index 86% rename from includes/interface/Label.h rename to src/interface/Label.h index 216895684..e56852e81 100644 --- a/includes/interface/Label.h +++ b/src/interface/Label.h @@ -10,7 +10,7 @@ namespace ui class Label : public Component { public: - Label(State* parent_state, std::string labelText); + Label(Window* parent_state, std::string labelText); Label(Point position, Point size, std::string labelText); diff --git a/src/interface/Panel.cpp b/src/interface/Panel.cpp index e44663a7b..acfcf5344 100644 --- a/src/interface/Panel.cpp +++ b/src/interface/Panel.cpp @@ -5,12 +5,12 @@ #include "interface/Panel.h" #include "interface/Point.h" -#include "interface/State.h" +#include "interface/Window.h" #include "interface/Component.h" using namespace ui; -Panel::Panel(State* parent_state): +Panel::Panel(Window* parent_state): Component(parent_state) { @@ -84,7 +84,7 @@ void Panel::Draw(const Point& screenPos) // the component must be visible if(children[i]->Visible) { - if(GetParentState()->AllowExclusiveDrawing) + if(GetParentWindow()->AllowExclusiveDrawing) { //who cares if the component is off the screen? draw anyway. Point scrpos = screenPos + children[i]->Position; @@ -143,7 +143,7 @@ void Panel::OnMouseClick(int localx, int localy, unsigned button) localy < children[i]->Position.Y + children[i]->Size.Y ) { childclicked = true; - GetParentState()->FocusComponent(children[i]); + GetParentWindow()->FocusComponent(children[i]); children[i]->OnMouseClick(localx - children[i]->Position.X, localy - children[i]->Position.Y, button); break; } @@ -154,7 +154,7 @@ void Panel::OnMouseClick(int localx, int localy, unsigned button) if(!childclicked) { XOnMouseClick(localx, localy, button); - GetParentState()->FocusComponent(this); + GetParentWindow()->FocusComponent(this); } } diff --git a/includes/interface/Panel.h b/src/interface/Panel.h similarity index 98% rename from includes/interface/Panel.h rename to src/interface/Panel.h index 7c9adabf2..51f52aa60 100644 --- a/includes/interface/Panel.h +++ b/src/interface/Panel.h @@ -3,7 +3,7 @@ //#include "Platform.h" #include "interface/Point.h" -#include "interface/State.h" +#include "interface/Window.h" #include "interface/Component.h" namespace ui @@ -21,7 +21,7 @@ class Component; public: friend class Component; - Panel(State* parent_state); + Panel(Window* parent_state); Panel(Point position, Point size); Panel(); virtual ~Panel(); diff --git a/includes/interface/Platform.h b/src/interface/Platform.h similarity index 100% rename from includes/interface/Platform.h rename to src/interface/Platform.h diff --git a/includes/interface/Point.h b/src/interface/Point.h similarity index 100% rename from includes/interface/Point.h rename to src/interface/Point.h diff --git a/src/interface/Sandbox.cpp b/src/interface/Sandbox.cpp index a9760e724..9a858f82c 100644 --- a/src/interface/Sandbox.cpp +++ b/src/interface/Sandbox.cpp @@ -16,6 +16,7 @@ #include "interface/Component.h" #include "Renderer.h" #include "Simulation.h" +#include "Engine.h" namespace ui { @@ -60,7 +61,7 @@ void Sandbox::OnMouseUp(int localx, int localy, unsigned int button) void Sandbox::Draw(const Point& screenPos) { - Graphics * g = Global::Ref().g; + Graphics * g = Engine::Ref().g; if(!ren) ren = new Renderer(g, sim); ren->render_parts(); diff --git a/includes/interface/Sandbox.h b/src/interface/Sandbox.h similarity index 100% rename from includes/interface/Sandbox.h rename to src/interface/Sandbox.h diff --git a/src/interface/State.cpp b/src/interface/Window.cpp similarity index 70% rename from src/interface/State.cpp rename to src/interface/Window.cpp index 665e2e8ea..e28d34bed 100644 --- a/src/interface/State.cpp +++ b/src/interface/Window.cpp @@ -1,30 +1,29 @@ -#include -#include "interface/Component.h" -#include "interface/Engine.h" -#include "interface/State.h" -//#include "Platform.h" +#include "Window.h" +#include "Component.h" +#include "interface/Point.h" using namespace ui; -State::State() -: UserData(NULL) -, focusedComponent_(NULL) +Window::Window(Point _position, Point _size): + Position(_position), + Size(_size), + focusedComponent_(NULL) { } -State::~State() +Window::~Window() { for(unsigned i = 0, sz = Components.size(); i < sz; ++i) if( Components[i] ) delete Components[i]; } -void State::AddComponent(Component* c) +void Window::AddComponent(Component* c) { // TODO: do a check if component was already added? - if(c->GetParentState()==NULL) + if(c->GetParentWindow()==NULL) { - c->SetParentState(this); + c->SetParentWindow(this); Components.push_back(c); } else @@ -33,17 +32,17 @@ void State::AddComponent(Component* c) } } -unsigned State::GetComponentCount() +unsigned Window::GetComponentCount() { return Components.size(); } -Component* State::GetComponent(unsigned idx) +Component* Window::GetComponent(unsigned idx) { return Components[idx]; } -void State::RemoveComponent(Component* c) +void Window::RemoveComponent(Component* c) { // remove component WITHOUT freeing it. for(unsigned i = 0; i < Components.size(); ++i) @@ -52,43 +51,43 @@ void State::RemoveComponent(Component* c) if(Components[i] == c) { Components.erase(Components.begin() + i); - + // we're done return; } } } -void State::RemoveComponent(unsigned idx) +void Window::RemoveComponent(unsigned idx) { // free component and remove it. delete Components[idx]; Components.erase(Components.begin() + idx); } -bool State::IsFocused(const Component* c) const +bool Window::IsFocused(const Component* c) const { return c == focusedComponent_; } -void State::FocusComponent(Component* c) +void Window::FocusComponent(Component* c) { this->focusedComponent_ = c; } -void State::DoExit() +void Window::DoExit() { OnExit(); } -void State::DoInitialized() +void Window::DoInitialized() { OnInitialized(); } -void State::DoDraw() +void Window::DoDraw() { //draw for(int i = 0, sz = Components.size(); i < sz; ++i) @@ -101,12 +100,12 @@ void State::DoDraw() } else { - if( Components[i]->Position.X + Components[i]->Size.X >= 0 && - Components[i]->Position.Y + Components[i]->Size.Y >= 0 && - Components[i]->Position.X < ui::Engine::Ref().GetWidth() && - Components[i]->Position.Y < ui::Engine::Ref().GetHeight() ) + if( Components[i]->Position.X+Position.X + Components[i]->Size.X >= 0 && + Components[i]->Position.Y+Position.Y + Components[i]->Size.Y >= 0 && + Components[i]->Position.X+Position.X < ui::Engine::Ref().GetWidth() && + Components[i]->Position.Y+Position.Y < ui::Engine::Ref().GetHeight() ) { - Point scrpos(Components[i]->Position.X, Components[i]->Position.Y); + Point scrpos(Components[i]->Position.X + Position.X, Components[i]->Position.Y + Position.Y); Components[i]->Draw( Point(scrpos) ); } } @@ -115,22 +114,22 @@ void State::DoDraw() OnDraw(); } -void State::DoTick(float dt) +void Window::DoTick(float dt) { //on mouse hover for(int i = Components.size() - 1; i >= 0; --i) { if(!Components[i]->Locked && - ui::Engine::Ref().GetMouseX() >= Components[i]->Position.X && - ui::Engine::Ref().GetMouseY() >= Components[i]->Position.Y && - ui::Engine::Ref().GetMouseX() < Components[i]->Position.X + Components[i]->Size.X && - ui::Engine::Ref().GetMouseY() < Components[i]->Position.Y + Components[i]->Size.Y ) + ui::Engine::Ref().GetMouseX() >= Components[i]->Position.X+Position.X && + ui::Engine::Ref().GetMouseY() >= Components[i]->Position.Y+Position.Y && + ui::Engine::Ref().GetMouseX() < Components[i]->Position.X+Position.X + Components[i]->Size.X && + ui::Engine::Ref().GetMouseY() < Components[i]->Position.Y+Position.Y + Components[i]->Size.Y ) { - Components[i]->OnMouseHover(ui::Engine::Ref().GetMouseX() - Components[i]->Position.X, ui::Engine::Ref().GetMouseY() - Components[i]->Position.Y); + Components[i]->OnMouseHover(ui::Engine::Ref().GetMouseX() - (Components[i]->Position.X + Position.X), ui::Engine::Ref().GetMouseY() - (Components[i]->Position.Y + Position.Y)); break; } } - + //tick for(int i = 0, sz = Components.size(); i < sz; ++i) { @@ -140,7 +139,7 @@ void State::DoTick(float dt) OnTick(dt); } -void State::DoKeyPress(int key, bool shift, bool ctrl, bool alt) +void Window::DoKeyPress(int key, bool shift, bool ctrl, bool alt) { //on key press if(focusedComponent_ != NULL) @@ -152,7 +151,7 @@ void State::DoKeyPress(int key, bool shift, bool ctrl, bool alt) OnKeyPress(key, shift, ctrl, alt); } -void State::DoKeyRelease(int key, bool shift, bool ctrl, bool alt) +void Window::DoKeyRelease(int key, bool shift, bool ctrl, bool alt) { //on key unpress if(focusedComponent_ != NULL) @@ -164,7 +163,7 @@ void State::DoKeyRelease(int key, bool shift, bool ctrl, bool alt) OnKeyRelease(key, shift, ctrl, alt); } -void State::DoMouseDown(int x, int y, unsigned button) +void Window::DoMouseDown(int x, int y, unsigned button) { //on mouse click bool clickState = false; @@ -195,7 +194,7 @@ void State::DoMouseDown(int x, int y, unsigned button) OnMouseDown(x, y, button); } -void State::DoMouseMove(int x, int y, int dx, int dy) +void Window::DoMouseMove(int x, int y, int dx, int dy) { //on mouse move (if true, and inside) for(int i = Components.size() - 1; i > -1 ; --i) @@ -204,16 +203,16 @@ void State::DoMouseMove(int x, int y, int dx, int dy) { Point local (x - Components[i]->Position.X, y - Components[i]->Position.Y) , a (local.X - dx, local.Y - dy); - + Components[i]->OnMouseMoved(local.X, local.Y, dx, dy); - + if(local.X >= 0 && local.Y >= 0 && local.X < Components[i]->Size.X && local.Y < Components[i]->Size.Y ) { Components[i]->OnMouseMovedInside(local.X, local.Y, dx, dy); - + // entering? if(!( a.X >= 0 && @@ -234,7 +233,7 @@ void State::DoMouseMove(int x, int y, int dx, int dy) { Components[i]->OnMouseLeave(local.X, local.Y); } - + } } } @@ -242,7 +241,7 @@ void State::DoMouseMove(int x, int y, int dx, int dy) OnMouseMove(x, y, dx, dy); } -void State::DoMouseUp(int x, int y, unsigned button) +void Window::DoMouseUp(int x, int y, unsigned button) { //on mouse unclick for(int i = Components.size() - 1; i >= 0 ; --i) @@ -267,7 +266,7 @@ void State::DoMouseUp(int x, int y, unsigned button) OnMouseUp(x, y, button); } -void State::DoMouseWheel(int x, int y, int d) +void Window::DoMouseWheel(int x, int y, int d) { //on mouse wheel focused for(int i = Components.size() - 1; i >= 0 ; --i) @@ -279,7 +278,7 @@ void State::DoMouseWheel(int x, int y, int d) break; } } - + //on mouse wheel for(int i = Components.size() - 1; i >= 0 ; --i) { @@ -289,3 +288,4 @@ void State::DoMouseWheel(int x, int y, int d) OnMouseWheel(x, y, d); } + diff --git a/includes/interface/State.h b/src/interface/Window.h similarity index 54% rename from includes/interface/State.h rename to src/interface/Window.h index 75e969d82..581b91f4c 100644 --- a/includes/interface/State.h +++ b/src/interface/Window.h @@ -1,54 +1,59 @@ -#pragma once +#ifndef WINDOW_H +#define WINDOW_H #include - +#include "interface/Point.h" #include "Engine.h" -#include "Component.h" -#include "Platform.h" namespace ui { + +enum ChromeStyle +{ + None, Title, Resizable +}; +//class State; class Engine; class Component; - + /* class State - * + * * A UI state. Contains all components. */ - class State + class Window { public: - State(); - virtual ~State(); + Window(Point _position, Point _size); + virtual ~Window(); bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds // Add Component to state void AddComponent(Component* c); - + // Get the number of components this state has. unsigned GetComponentCount(); - + // Get component by index. (See GetComponentCount()) Component* GetComponent(unsigned idx); - + // Remove a component from state. NOTE: This DOES NOT free component from memory. void RemoveComponent(Component* c); - + // Remove a component from state. NOTE: This WILL free component from memory. void RemoveComponent(unsigned idx); - - void DoInitialized(); - void DoExit(); - void DoTick(float dt); - void DoDraw(); - void DoMouseMove(int x, int y, int dx, int dy); - void DoMouseDown(int x, int y, unsigned button); - void DoMouseUp(int x, int y, unsigned button); - void DoMouseWheel(int x, int y, int d); - void DoKeyPress(int key, bool shift, bool ctrl, bool alt); - void DoKeyRelease(int key, bool shift, bool ctrl, bool alt); + virtual void DoInitialized(); + virtual void DoExit(); + virtual void DoTick(float dt); + virtual void DoDraw(); + + virtual void DoMouseMove(int x, int y, int dx, int dy); + virtual void DoMouseDown(int x, int y, unsigned button); + virtual void DoMouseUp(int x, int y, unsigned button); + virtual void DoMouseWheel(int x, int y, int d); + virtual void DoKeyPress(int key, bool shift, bool ctrl, bool alt); + virtual void DoKeyRelease(int key, bool shift, bool ctrl, bool alt); bool IsFocused(const Component* c) const; void FocusComponent(Component* c); @@ -67,11 +72,32 @@ namespace ui virtual void OnMouseWheel(int x, int y, int d) {} virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {} virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {} - - private: std::vector Components; Component* focusedComponent_; + Point Position; + Point Size; + ChromeStyle chrome; + }; + +/*class Window : public State +{ +private: + ChromeStyle chrome; +public: + Window(Point _position, Point _size); + Point Position; + Point Size; + + virtual void DoTick(float dt); + virtual void DoDraw(); + + virtual void DoMouseMove(int x, int y, int dx, int dy); + virtual void DoMouseDown(int x, int y, unsigned button); + virtual void DoMouseUp(int x, int y, unsigned button); + virtual void DoMouseWheel(int x, int y, int d); +};*/ } +#endif // WINDOW_H diff --git a/src/search/Save.h b/src/search/Save.h new file mode 100644 index 000000000..a3ef48512 --- /dev/null +++ b/src/search/Save.h @@ -0,0 +1,41 @@ +#ifndef SAVE_H +#define SAVE_H + +#include + +using namespace std; + +class Save +{ +private: + int id; + int votesUp, votesDown; + string userName; + string name; +public: + Save(int _id, int _votesUp, int _votesDown, string _userName, string _name): + id(_id), + votesUp(_votesUp), + votesDown(_votesDown), + userName(_userName), + name(_name) + { + } + + void SetName(string name){ this->name = name; } + string GetName(){ return name; } + + void SetUserName(string userName){ this->userName = userName; } + string GetUserName(){ return userName; } + + void SetID(int id){ this->id = id; } + int GetID(){ return id; } + + void SetVotesUp(int votesUp){ this->votesUp = votesUp; } + int GetVotesUp(){ return votesUp; } + + void SetVotesDown(int votesDown){ this->votesDown = votesDown; } + int GetVotesDown(){ return votesDown; } +}; + +#endif // SAVE_H diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp new file mode 100644 index 000000000..cf13f2e49 --- /dev/null +++ b/src/search/SearchController.cpp @@ -0,0 +1,14 @@ +#include "SearchController.h" +#include "SearchModel.h" +#include "SearchView.h" +#include "interface/Panel.h" + +SearchController::SearchController() +{ + searchModel = new SearchModel(); + searchView = new SearchView(); + searchModel->AddObserver(searchView); + + //Set up interface + //windowPanel.AddChild(); +} diff --git a/src/search/SearchController.h b/src/search/SearchController.h new file mode 100644 index 000000000..8755a07aa --- /dev/null +++ b/src/search/SearchController.h @@ -0,0 +1,18 @@ +#ifndef SEARCHCONTROLLER_H +#define SEARCHCONTROLLER_H + +#include "interface/Panel.h" +#include "SearchModel.h" +#include "SearchView.h" + +class SearchController +{ +private: + SearchModel * searchModel; + SearchView * searchView; + ui::Panel * windowPanel; +public: + SearchController(); +}; + +#endif // SEARCHCONTROLLER_H diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp new file mode 100644 index 000000000..63188bdc6 --- /dev/null +++ b/src/search/SearchModel.cpp @@ -0,0 +1,23 @@ +#include "SearchModel.h" +#include "Save.h" + +SearchModel::SearchModel() +{ +} + +void SearchModel::UpdateSaveList() +{ + saveList.clear(); + notifySaveListChanged(); + saveList.push_back(Save(1, 45, 5, "Simon", "Post logic gates")); + notifySaveListChanged(); +} + +void SearchModel::notifySaveListChanged() +{ + for(int i = 0; i < observers.size(); i++) + { + SearchView* cObserver = observers[i]; + cObserver->NotifySaveListChanged(this); + } +} diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h new file mode 100644 index 000000000..095157708 --- /dev/null +++ b/src/search/SearchModel.h @@ -0,0 +1,23 @@ +#ifndef SEARCHMODEL_H +#define SEARCHMODEL_H + +#include +#include "Save.h" +#include "SearchView.h" + +using namespace std; + +class SearchModel +{ +private: + vector observers; + vector saveList; + void notifySaveListChanged(); +public: + SearchModel(); + void AddObserver(SearchView * observer){ observers.push_back(observer); } + void UpdateSaveList(); + vector GetSaveList(); +}; + +#endif // SEARCHMODEL_H diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp new file mode 100644 index 000000000..4b551f395 --- /dev/null +++ b/src/search/SearchView.cpp @@ -0,0 +1,10 @@ +#include "SearchView.h" + +SearchView::SearchView() +{ +} + +void SearchView::NotifySaveListChanged(SearchModel * sender) +{ + +} diff --git a/src/search/SearchView.h b/src/search/SearchView.h new file mode 100644 index 000000000..e540f21bd --- /dev/null +++ b/src/search/SearchView.h @@ -0,0 +1,13 @@ +#ifndef SEARCHVIEW_H +#define SEARCHVIEW_H + +class SearchModel; + +class SearchView +{ +public: + void NotifySaveListChanged(SearchModel * sender); + SearchView(); +}; + +#endif // SEARCHVIEW_H