diff ext/guichan-0.8.1/examples/sdlhelloworld.cpp @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ext/guichan-0.8.1/examples/sdlhelloworld.cpp	Sun Jun 29 18:44:17 2008 +0000
@@ -0,0 +1,58 @@
+/**
+ * This is an example that shows a simple Hello World example
+ * with Guichan. The example uses the SDL back end.
+ */
+
+#include <guichan.hpp>
+#include <iostream>
+
+// Here we store a global Gui object.  We make it global
+// so it's easily accessable. Of course, global variables
+// should normally be avioded when it comes to OOP, but
+// this examples is not an example that shows how to make a 
+// good and clean C++ application but merely an example
+// that shows how to use Guichan.
+namespace globals
+{
+    gcn::Gui* gui;
+}
+
+// Include code to set up an SDL application with Guichan.
+// The sdl.hpp file is responsible for creating and deleting
+// the global Gui object.
+#include "sdl.hpp"
+// Include code to set up a Guichan GUI with a simple Hello
+// World example. The code populates the global Gui object.
+#include "helloworld.hpp"
+
+int main(int argc, char **argv)
+{
+    try
+    {
+        sdl::init();
+        helloworld::init();
+        sdl::run();
+        helloworld::halt();
+        sdl::halt();
+    }
+    // Catch all Guichan exceptions.
+    catch (gcn::Exception e)
+    {
+        std::cerr << e.getMessage() << std::endl;
+        return 1;
+    }
+    // Catch all Std exceptions.
+    catch (std::exception e)
+    {
+        std::cerr << "Std exception: " << e.what() << std::endl;
+        return 1;
+    }
+    // Catch all unknown exceptions.
+    catch (...)
+    {
+        std::cerr << "Unknown exception" << std::endl;
+        return 1;
+    }
+
+    return 0;
+}