From 78d3b80df3552ef2d626db57677980470efb5de5 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 12 May 2012 23:25:36 -0300 Subject: [PATCH] Add ScopedAllegro class. --- src/CMakeLists.txt | 1 + src/main.cpp | 26 +++----------------------- src/scoped_allegro.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/scoped_allegro.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 src/scoped_allegro.cpp create mode 100644 src/scoped_allegro.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6c09f440f..166414ebb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -154,6 +154,7 @@ add_library(aseprite-library objects_container_impl.cpp recent_files.cpp resource_finder.cpp + scoped_allegro.cpp ui_context.cpp undo_transaction.cpp xml_exception.cpp diff --git a/src/main.cpp b/src/main.cpp index 23913664c..5f80c2bc2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,16 +18,15 @@ #include "config.h" -#include - #include "app.h" #include "base/exception.h" #include "base/memory.h" #include "base/memory_dump.h" #include "console.h" -#include "loadpng.h" #include "resource_finder.h" +#include "scoped_allegro.h" +#include #ifdef WIN32 #include #endif @@ -51,25 +50,6 @@ public: }; #endif -////////////////////////////////////////////////////////////////////// -// Allegro libray initialization - -class Allegro { -public: - Allegro() { - allegro_init(); - set_uformat(U_ASCII); - install_timer(); - - // Register PNG as a supported bitmap type - register_bitmap_file_type("png", load_png, save_png); - } - ~Allegro() { - remove_timer(); - allegro_exit(); - } -}; - static bool get_memory_dump_filename(std::string& filename) { #ifdef WIN32 @@ -90,7 +70,7 @@ int main(int argc, char* argv[]) #endif base::MemoryDump memoryDump; - Allegro allegro; + ScopedAllegro allegro; #ifdef MEMLEAK MemLeak memleak; #endif diff --git a/src/scoped_allegro.cpp b/src/scoped_allegro.cpp new file mode 100644 index 000000000..efce7229a --- /dev/null +++ b/src/scoped_allegro.cpp @@ -0,0 +1,40 @@ +/* ASEPRITE + * Copyright (C) 2001-2012 David Capello + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" + +#include "scoped_allegro.h" + +#include +#include "loadpng.h" + +ScopedAllegro::ScopedAllegro() +{ + allegro_init(); + set_uformat(U_ASCII); + install_timer(); + + // Register PNG as a supported bitmap type + register_bitmap_file_type("png", load_png, save_png); +} + +ScopedAllegro::~ScopedAllegro() +{ + remove_timer(); + allegro_exit(); +} diff --git a/src/scoped_allegro.h b/src/scoped_allegro.h new file mode 100644 index 000000000..39ecd2193 --- /dev/null +++ b/src/scoped_allegro.h @@ -0,0 +1,28 @@ +/* ASEPRITE + * Copyright (C) 2001-2012 David Capello + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SCOPED_ALLEGRO_H +#define SCOPED_ALLEGRO_H + +class ScopedAllegro { +public: + ScopedAllegro(); + ~ScopedAllegro(); +}; + +#endif