mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-21 21:41:02 +00:00
Add "she" layer.
This is the starting point to create a layer to isolate Allegro access. In the future, we will be able to switch to SDL or Allegro 5 easily. Anyway this will be a progressive refactoring.
This commit is contained in:
parent
6caaca8179
commit
35f1249662
@ -1,6 +1,8 @@
|
||||
# ASEPRITE
|
||||
# Copyright (C) 2001-2012 David Capello
|
||||
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
|
||||
if(MSVC)
|
||||
# Do not link with libcmt.lib (to avoid duplicated symbols with msvcrtd.lib)
|
||||
if(CMAKE_BUILD_TYPE STREQUAL Debug)
|
||||
@ -9,7 +11,7 @@ if(MSVC)
|
||||
endif(MSVC)
|
||||
|
||||
# Libraries in this directory
|
||||
set(aseprite_libraries aseprite-library undo-lib filters-lib ui-lib gfx-lib base-lib)
|
||||
set(aseprite_libraries aseprite-library undo-lib filters-lib ui-lib she gfx-lib base-lib)
|
||||
|
||||
# Directories where .h files can be found
|
||||
include_directories(. .. ../third_party)
|
||||
@ -139,6 +141,7 @@ set(all_libs ${aseprite_libraries} ${libs3rdparty} ${sys_libs})
|
||||
add_subdirectory(base)
|
||||
add_subdirectory(filters)
|
||||
add_subdirectory(gfx)
|
||||
add_subdirectory(she)
|
||||
add_subdirectory(ui)
|
||||
add_subdirectory(undo)
|
||||
|
||||
@ -166,7 +169,6 @@ add_library(aseprite-library
|
||||
objects_container_impl.cpp
|
||||
recent_files.cpp
|
||||
resource_finder.cpp
|
||||
scoped_allegro.cpp
|
||||
thumbnail_generator.cpp
|
||||
ui_context.cpp
|
||||
undo_transaction.cpp
|
||||
|
5
src/README.md
Normal file
5
src/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# ASEPRITE Source Code
|
||||
|
||||
If you are here is because you want to learn about ASEPRITE source
|
||||
code. I'll try to write in these `README.md` files a summary of each
|
||||
module/library.
|
27
src/main.cpp
27
src/main.cpp
@ -24,32 +24,37 @@
|
||||
#include "base/memory_dump.h"
|
||||
#include "console.h"
|
||||
#include "resource_finder.h"
|
||||
#include "scoped_allegro.h"
|
||||
#include "she/she.h"
|
||||
#include "ui/base.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#ifdef WIN32
|
||||
#include <winalleg.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Information for "ident".
|
||||
|
||||
const char ase_ident[] =
|
||||
const char aseprite_ident[] =
|
||||
"$" PACKAGE ": " VERSION " " COPYRIGHT " $\n"
|
||||
"$Website: " WEBSITE " $\n";
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Memory leak detector wrapper
|
||||
|
||||
#ifdef MEMLEAK
|
||||
class MemLeak
|
||||
{
|
||||
public:
|
||||
MemLeak() { base_memleak_init(); }
|
||||
~MemLeak() { base_memleak_exit(); }
|
||||
};
|
||||
MemLeak() {
|
||||
#ifdef MEMLEAK
|
||||
base_memleak_init();
|
||||
#endif
|
||||
}
|
||||
~MemLeak() {
|
||||
#ifdef MEMLEAK
|
||||
base_memleak_exit();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
static bool get_memory_dump_filename(std::string& filename)
|
||||
{
|
||||
@ -71,10 +76,8 @@ int main(int argc, char* argv[])
|
||||
#endif
|
||||
|
||||
base::MemoryDump memoryDump;
|
||||
ScopedAllegro allegro;
|
||||
#ifdef MEMLEAK
|
||||
she::ScopedHandle<she::System> system(she::CreateSystem());
|
||||
MemLeak memleak;
|
||||
#endif
|
||||
ui::GuiSystem guiSystem;
|
||||
App app(argc, argv);
|
||||
|
||||
@ -87,5 +90,3 @@ int main(int argc, char* argv[])
|
||||
|
||||
return app.run();
|
||||
}
|
||||
|
||||
END_OF_MAIN();
|
||||
|
@ -1,40 +0,0 @@
|
||||
/* 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 <allegro.h>
|
||||
#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();
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
/* 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
|
5
src/she/CMakeLists.txt
Normal file
5
src/she/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
# SHE
|
||||
# Copyright (C) 2012 David Capello
|
||||
|
||||
add_library(she
|
||||
she_alleg4.cpp)
|
29
src/she/LICENSE.txt
Normal file
29
src/she/LICENSE.txt
Normal file
@ -0,0 +1,29 @@
|
||||
SHE library
|
||||
Copyright (c) 2012 David Capello
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of the author nor the names of its contributors may
|
||||
be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
5
src/she/README.md
Normal file
5
src/she/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# SHE - Simplified Hardware Entry-point
|
||||
|
||||
SHE is an abstraction layer to access in different way to the
|
||||
hardware/operating system. It will use Allegro 4, Allegro 5 or SDL
|
||||
libraries, but will be easily portable to other back-ends.
|
35
src/she/she.h
Normal file
35
src/she/she.h
Normal file
@ -0,0 +1,35 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2012 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef SHE_H_INCLUDED
|
||||
#define SHE_H_INCLUDED
|
||||
|
||||
namespace she {
|
||||
|
||||
class System {
|
||||
public:
|
||||
virtual ~System() { }
|
||||
virtual void dispose() = 0;
|
||||
};
|
||||
|
||||
System* CreateSystem();
|
||||
|
||||
template<typename T>
|
||||
class ScopedHandle {
|
||||
public:
|
||||
ScopedHandle(T* handle) : m_handle(handle) { }
|
||||
~ScopedHandle() { m_handle->dispose(); }
|
||||
private:
|
||||
T* m_handle;
|
||||
|
||||
// Cannot copy
|
||||
ScopedHandle(const ScopedHandle&);
|
||||
ScopedHandle& operator=(const ScopedHandle&);
|
||||
};
|
||||
|
||||
} // namespace she
|
||||
|
||||
#endif
|
54
src/she/she_alleg4.cpp
Normal file
54
src/she/she_alleg4.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2012 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "she.h"
|
||||
|
||||
#include <allegro.h>
|
||||
#include "loadpng.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace she {
|
||||
|
||||
class Alleg4System : public System {
|
||||
public:
|
||||
Alleg4System() {
|
||||
allegro_init();
|
||||
set_uformat(U_ASCII);
|
||||
install_timer();
|
||||
|
||||
// Register PNG as a supported bitmap type
|
||||
register_bitmap_file_type("png", load_png, save_png);
|
||||
}
|
||||
|
||||
~Alleg4System() {
|
||||
remove_timer();
|
||||
allegro_exit();
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
System* CreateSystem() {
|
||||
return new Alleg4System();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
#undef main
|
||||
extern int main(int argc, char* argv[]);
|
||||
return main(argc, argv);
|
||||
}
|
||||
|
||||
END_OF_MAIN();
|
Loading…
x
Reference in New Issue
Block a user