**************************************************************************/
#include <cstdlib> // atexit, getenv
+#include <functional>
#include <iostream>
#include <string>
#include <unistd.h> // access
#include <Moof/OpenGL.hh>
#include <Moof/Resource.hh>
#include <Moof/Settings.hh>
-#include <Moof/Transition.hh>
#include <Moof/Video.hh>
#include "ErrorHandler.hh"
#include "version.h"
-Main::Main()
+Main::Main(Mf::Settings& settings, Mf::Video& video) :
+ Mf::View(settings, video)
{
- mDispatchHandler = Mf::core.addHandler("video.newcontext",
- boost::bind(&Main::contextCreated));
+ Mf::Dispatch& dispatch = Mf::Dispatch::global();
+ mNewContextDispatch = dispatch.addTarget("video.newcontext",
+ boost::bind(&Main::setupGL));
setupGL();
-}
-void Main::addedToCore()
-{
- //Mf::Scalar coeff[] = {0.0, 1.0};
- //Mf::Lerp interp(coeff, 0.25);
-
- //Mf::LayerP gameLayer = GameLayer::alloc();
- //Mf::Transition<Mf::Lerp>::Ptr transition =
- //Mf::Transition<Mf::Lerp>::alloc(gameLayer, Mf::LayerP(), interp);
- //core.push(transition);
- //core.push(GameLayer::alloc());
- Mf::core.push(TitleLayer::alloc());
+ addChild(TitleLayer::alloc());
}
void Main::update(Mf::Scalar t, Mf::Scalar dt)
{
- if (Mf::core.getSize() == 1)
+ if (children().size() == 0)
{
- // this is the only layer left on the stack
- //Mf::core.push(TitleLayer::alloc());
- Mf::core.clear();
+ Mf::logWarning("main view has no children");
+ stop();
+ return;
}
+
+ Mf::View::update(t, dt);
}
void Main::draw(Mf::Scalar alpha) const
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
+
+ Mf::View::draw(alpha);
}
bool Main::handleEvent(const Mf::Event& event)
{
+ if (Mf::View::handleEvent(event)) return true;
+
switch (event.type)
{
case SDL_KEYUP:
- if (event.key.keysym.sym == SDLK_ESCAPE)
+ if (event.key.keysym.sym == SDLK_f)
{
- Mf::core.clear();
- }
- else if (event.key.keysym.sym == SDLK_f)
- {
- Mf::video->toggleFull();
+ video().toggleFull();
}
else if (event.key.keysym.sym == SDLK_l)
{
- Mf::video->toggleCursorGrab();
- Mf::video->toggleCursorVisible();
+ video().toggleCursorGrab();
+ video().toggleCursorVisible();
}
break;
break;
case SDL_QUIT:
- Mf::core.clear();
- break;
+ stop();
+ return true;
}
return false;
std::string path = Mf::Resource::getPath("yoinkrc");
-#if !defined(_WIN32) && !defined(__WIN32__)
+#if !defined(_WIN32)
path += ":/etc/yoinkrc";
#endif
path += ":$HOME/.yoinkrc";
//glMatrixMode(GL_MODELVIEW);
}
-void Main::contextCreated()
-{
- // whenever the context is destroyed and a new one created, it probably
- // won't contain our state so we need to set that up again
- setupGL();
-}
-
-
void Main::printUsage()
{
std::cout << std::endl << "Goodbye..." << std::endl << std::endl;
}
+
int main(int argc, char* argv[])
{
if (argc > 1)
Mf::Resource::addSearchPaths(Main::getSearchPath());
- Mf::settings.loadFromFiles(Main::getConfigPath());
- Mf::settings.parseArgs(argc, argv);
+ Mf::Settings settings(argc, argv, Main::getConfigPath());
Mf::Log::Level logLevel = Mf::Log::INFO;
- Mf::settings.get("loglevel", logLevel);
+ settings.get("loglevel", logLevel);
Mf::Log::setLevel(logLevel);
try
{
- Mf::Video video(PACKAGE_STRING,
- Mf::Resource::getPath(PACKAGE".png"));
- MainP app = Main::alloc();
- Mf::core.push(app);
- Mf::core.run();
+ Mf::Video::Attributes attributes(settings);
+ attributes.caption = PACKAGE_STRING;
+ attributes.icon = Mf::Resource::getPath(PACKAGE".png");
+
+ Mf::Video video(attributes);
+ Main mainView(settings, video);
+
+ mainView.run();
+ return 0;
}
catch (const Mf::Error& error)
{
- Mf::ModalDialog dialog;
- dialog.title = PACKAGE_STRING;
- dialog.text1 = "Unhandled Exception";
- dialog.text2 = getErrorString(error);
- dialog.type = Mf::ModalDialog::CRITICAL;
- dialog.run();
+ Mf::ModalDialog dialog(Mf::ModalDialog::CRITICAL,
+ PACKAGE_STRING, "Unhandled Exception",
+ getErrorString(error));
+ dialog.run();
return 1;
}
-
- return 0;
}