//
// DemoContext.h
// MacOSX-Framework
//
// Created by John Ryland on 1/10/17.
// Copyright © 2017 John Ryland. All rights reserved.
//
#ifndef DemoContext_h
#define DemoContext_h
#include "Common.h"
class DemoContext
{
public:
virtual ~DemoContext() {}
virtual void prepare() {}
virtual void update(float a_seconds) {}
virtual void draw() {}
virtual void onClose() {}
virtual void onResize(const vec2f& a_shape) {}
virtual void onMouseUp(const MouseEvent& a_event) {}
virtual void onMouseDown(const MouseEvent& a_event) {}
virtual void onMouseMove(const MouseEvent& a_event) {}
bool m_needsPrepare = false;
};
// TODO: return shared_ptr instead of raw pointer
typedef DemoContext* (*DemoContextFactory)();
using DemoContextFactoryItem = GenericFactoryItem<DemoContextFactory>;
template <typename T>
struct RegisterDemoContext
{
RegisterDemoContext(const char* demoName) : registrationItem(demoName, createDemo) { }
static DemoContext* createDemo() { return new T; }
DemoContextFactoryItem registrationItem;
};
// This can go in the header or cpp file, doesn't matter
#define REGISTER_DEMO_CONTEXT(demoName, demoClass) \
RegisterDemoContext<demoClass> register##demoClass(demoName);
#endif /* DemoContext_h */