summaryrefslogtreecommitdiff
path: root/source/logic/AllegroWrappers.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/logic/AllegroWrappers.h')
-rw-r--r--source/logic/AllegroWrappers.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/source/logic/AllegroWrappers.h b/source/logic/AllegroWrappers.h
new file mode 100644
index 0000000..851f219
--- /dev/null
+++ b/source/logic/AllegroWrappers.h
@@ -0,0 +1,112 @@
+#ifndef ALLEGRO_WRAPPERS_H
+#define ALLEGRO_WRAPPERS_H
+
+#include <allegro5/allegro.h>
+#include <allegro5/allegro_primitives.h>
+#include <allegro5/allegro_font.h>
+#include <allegro5/allegro_ttf.h>
+
+/**
+* @brief Exception to be thrown if any component of Allegro fails to install at runtime.
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class InstallFailure {};
+
+/**
+* @brief Class ensures that Allegro is initialized and uninstalled when appropriate.
+*
+* Any classes that use Allegro should include this class as a data member.
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class AllegroInit
+{
+ public:
+ /**
+ * @brief Constructor calls al_init() if it is the first instance.
+ */
+ AllegroInit();
+ /**
+ * @brief Copy constructor, implemented to be included in instance count.
+ */
+ AllegroInit(const AllegroInit& ref);
+ /**
+ * @brief Destructor calls al_uninstall_system() if it is the last instant.
+ */
+
+ //assignment operator provided by compiler. _initCount does not need incrementing on assignment,
+ //because assignment does not make a new instance, just changes one.
+
+ ~AllegroInit();
+ private:
+ static int _initCount; ///< Count of the current number of initialised AllegroInit objects.
+};
+
+/**
+* @brief Class ensures that Allegro's keyboard is installed and uninstalled when appropriate.
+*
+* Any classes that use the keyboard for input should include this class as a data member.
+* This class includes AllegroInit, so both of them do not need to be included.
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class AllegroKeyboardInit
+{
+ public:
+ /**
+ * @brief Constructor calls al_install_keyboard() if it is the first instance.
+ */
+ AllegroKeyboardInit();
+ /**
+ * @brief Copy constructor, implemented to be included in instance count.
+ */
+ AllegroKeyboardInit(const AllegroKeyboardInit& ref);
+ /**
+ * @brief Destructor calls al_uninstall_keyboard() if it is the last instant.
+ */
+ ~AllegroKeyboardInit();
+ private:
+ static int _initCount; ///< Count of the current number of initialised AllegroKeyboardInit objects.
+ AllegroInit _allegro; ///< Depends on Allegro being initialised.
+
+ //assignment operator provided by compiler. _initCount does not need incrementing on assignment,
+ //because assignment does not make a new instance, just changes one.
+};
+
+/**
+* @brief Class ensures that Allegro's primitive and text drawing is installed and uninstalled when appropriate.
+*
+* Any classes that draw primitives should include this class as a data member.
+* This class includes AllegroInit, so both of them do not need to be included.
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class AllegroDrawingInit
+{
+ public:
+ /**
+ * @brief Constructor calls al_init_primitives_addon(), al_init_font_addon(), and al_init_ttf_addon() if it is the first instance.
+ */
+ AllegroDrawingInit();
+ /**
+ * @brief Copy constructor, implemented to be included in instance count.
+ */
+ AllegroDrawingInit(const AllegroDrawingInit& ref);
+ /**
+ * @brief Destructor calls al_shutdown_primitives_addon(), al_shutdown_font_addon(), and al_shutdown_ttf_addon() if it is the last instant.
+ */
+ ~AllegroDrawingInit();
+ private:
+ static int _initCount;
+ AllegroInit _allegro;
+
+ //assignment operator provided by compiler. _initCount does not need incrementing on assignment,
+ //because assignment does not make a new instance, just changes one.
+};
+
+#endif