diff --git a/ChangeLog b/ChangeLog index 4f8ac99fb..1940c88db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-08-04 David A. Capello + + * Version 0.7 released. + + * makefile.vc: Prepared to be compiled with VC++ 9.0 Express Edition. + +2009-08-03 David A. Capello + + * Modified some error handling code from return-value to exceptions. + 2009-08-02 David A. Capello * src/util/render.cpp (merge_zoomed_image): unified all diff --git a/fix.sh b/fix.sh index a0cf51dd3..5dd91a9f0 100644 --- a/fix.sh +++ b/fix.sh @@ -102,6 +102,9 @@ gen_makefile() echo "" >> $makefile fi + if [ X"$debug" == X"y" ] ; then echo -n "#" >> $makefile ; fi + echo "RELEASE = 1" >> $makefile + if [ X"$debug" != X"y" ] ; then echo -n "#" >> $makefile ; fi echo "DEBUGMODE = 1" >> $makefile diff --git a/makefile.cfg b/makefile.cfg index b0ccf4840..9950a3fe0 100644 --- a/makefile.cfg +++ b/makefile.cfg @@ -10,9 +10,11 @@ ###################################################################### # Uncomment this if you want to debug or profile information +#RELEASE = 1 #DEBUGMODE = 1 #PROFILE = 1 #MEMLEAK = 1 +#STATIC_ALLEG_LINK = 1 ###################################################################### # Default Unix directory to look for ASE data (to this path will be diff --git a/makefile.lst b/makefile.lst index 6ce38be71..3fa2ce610 100644 --- a/makefile.lst +++ b/makefile.lst @@ -138,6 +138,7 @@ COMMON_SOURCES = \ src/jinete/jfontbmp.cpp \ src/jinete/jhook.cpp \ src/jinete/jimage.cpp \ + src/jinete/jinete.cpp \ src/jinete/jintern.cpp \ src/jinete/jlabel.cpp \ src/jinete/jlist.cpp \ diff --git a/makefile.vc b/makefile.vc index bb9914706..7cb6297cb 100644 --- a/makefile.vc +++ b/makefile.vc @@ -41,9 +41,25 @@ ifdef DEBUGMODE LFLAGS += -DEBUG LIBS += Alld.lib psapi.lib else - CFLAGS += -O2 -MD -DNDEBUG - LFLAGS += -RELEASE - LIBS += Alleg.lib + ifdef RELEASE + CFLAGS += -O2 -DNDEBUG + LFLAGS += -RELEASE + + ifdef STATIC_ALLEG_LINK + CFLAGS += -MT -DALLEGRO_STATICLINK + LIBS += Alleg_s_crt.lib + LIBS += dinput8.lib ddraw.lib dxguid.lib dsound.lib + else + CFLAGS += -MD + LIBS += Alleg.lib + endif + else + # Release with debug info + CFLAGS += -Zi -O2 -MD -DNDEBUG + LFLAGS += -DEBUG + LIBS += Alleg.lib + LIBS += psapi.lib + endif endif ifdef MEMLEAK @@ -73,27 +89,27 @@ distclean: clean $(LIBART_LIB): $(LIBART_OBJS) -rm -f $@ - lib -NOLOGO /OUT:$@ $^ + lib -NOLOGO -OUT:$@ $^ $(LIBFREETYPE_LIB): $(LIBFREETYPE_OBJS) -rm -f $@ - lib -NOLOGO /OUT:$@ $^ + lib -NOLOGO -OUT:$@ $^ $(LIBGD_LIB): $(LIBGD_OBJS) -rm -f $@ - lib -NOLOGO /OUT:$@ $^ + lib -NOLOGO -OUT:$@ $^ $(LIBJPEG_LIB): $(LIBJPEG_OBJS) -rm -f $@ - lib -NOLOGO /OUT:$@ $^ + lib -NOLOGO -OUT:$@ $^ $(LIBPNG_LIB): $(LIBPNG_OBJS) -rm -f $@ - lib -NOLOGO /OUT:$@ $^ + lib -NOLOGO -OUT:$@ $^ $(ZLIB_LIB): $(ZLIB_OBJS) -rm -f $@ - lib -NOLOGO /OUT:$@ $^ + lib -NOLOGO -OUT:$@ $^ ###################################################################### # Rules to build objects and the application @@ -174,3 +190,7 @@ $(OBJ_DIR)/icon.res: src/icon.rc $(ASE): $(ASE_DEPS) $(OBJ_DIR)/icon.res link $(LFLAGS) $^ $(LIBS) -OUT:$@ + +# To embed the manifest file uncomment the following lines: +# mt -nologo -manifest $@.manifest -outputresource:$@;#2 +# rm $@.manifest diff --git a/misc/dist.sh b/misc/dist.sh index aa698ead3..72fe3b77c 100644 --- a/misc/dist.sh +++ b/misc/dist.sh @@ -195,20 +195,17 @@ $1/docs/*.pdf" if [ ! -f $distdir-win32.zip ] ; then cd "$dir/.." -make -f makefile.mgw CONFIGURED=1 clean -make -f makefile.mgw CONFIGURED=1 -strip -s aseprite.exe +make -f makefile.vc CONFIGURED=1 RELEASE=1 STATIC_ALLEG_LINK=1 clean +make -f makefile.vc CONFIGURED=1 RELEASE=1 STATIC_ALLEG_LINK=1 def_common_files . mkdir "$dir/$distdir-win32" cp -r --parents $txt_files $bin_files aseprite.exe "$dir/$distdir-win32" cd "$dir" -cp alleg42.dll "$dir/$distdir-win32" def_common_files $distdir-win32 zip -9 $distdir-win32.zip $txt_files zip -9 $distdir-win32.zip $bin_files \ - $distdir-win32/aseprite.exe \ - $distdir-win32/alleg42.dll + $distdir-win32/aseprite.exe rm -fr $distdir-win32 fi diff --git a/src/commands/cmd_configure_screen.cpp b/src/commands/cmd_configure_screen.cpp index 26f916728..99af48247 100644 --- a/src/commands/cmd_configure_screen.cpp +++ b/src/commands/cmd_configure_screen.cpp @@ -176,7 +176,6 @@ static bool try_new_gfx_mode() /* oh no! more errors!, we can't restore the old graphics mode! */ set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); user_printf(_("FATAL ERROR: Unable to restore the old graphics mode!\n")); - app_exit(); exit(1); } /* only print a message of the old error */ diff --git a/src/core/app.cpp b/src/core/app.cpp index 93d83ee32..561396c37 100644 --- a/src/core/app.cpp +++ b/src/core/app.cpp @@ -30,6 +30,7 @@ #include "jinete/jinete.h" #include "jinete/jintern.h" +#include "ase_exception.h" #include "ase/ui_context.h" #include "commands/commands.h" #include "console/console.h" @@ -110,7 +111,7 @@ static char *palette_filename = NULL; static void tabsbar_select_callback(JWidget tabs, void *data, int button); -static int check_args(int argc, char *argv[]); +static void check_args(int argc, char *argv[]); static void usage(int status); static Option *option_new(int type, const char *data); @@ -120,29 +121,22 @@ static void option_free(Option *option); * Initializes the application loading the modules, setting the * graphics mode, loading the configuration and resources, etc. */ -bool app_init(int argc, char *argv[]) +Application::Application(int argc, char *argv[]) { exe_name = argv[0]; /* initialize application hooks */ - { - int c; - for (c=0; cpath); dirs_free(dirs); #endif - - return TRUE; } void core_exit() diff --git a/src/core/core.h b/src/core/core.h index e49e68676..38f6ce808 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -29,7 +29,7 @@ enum { extern int ase_mode; -bool core_init(); +void core_init(); void core_exit(); void verbose_printf(const char *format, ...); diff --git a/src/core/drop_files.cpp b/src/core/drop_files.cpp index 317e8180a..bfb1fd9a4 100644 --- a/src/core/drop_files.cpp +++ b/src/core/drop_files.cpp @@ -35,7 +35,7 @@ #ifdef ALLEGRO_WINDOWS static WNDPROC base_wnd_proc = NULL; -static std::vector dropped_files; +static std::vector* dropped_files; static JMutex dropped_files_mutex; static void subclass_hwnd(); @@ -44,6 +44,7 @@ static LRESULT ase_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); void install_drop_files() { + dropped_files = new std::vector(); dropped_files_mutex = jmutex_new(); subclass_hwnd(); @@ -56,7 +57,7 @@ void uninstall_drop_files() jmutex_free(dropped_files_mutex); dropped_files_mutex = NULL; - dropped_files.clear(); + delete dropped_files; } void check_for_dropped_files() @@ -68,9 +69,9 @@ void check_for_dropped_files() return; jmutex_lock(dropped_files_mutex); - if (!dropped_files.empty()) { - std::vector files = dropped_files; - dropped_files.clear(); + if (!dropped_files->empty()) { + std::vector files = *dropped_files; + dropped_files->clear(); // open all files Command* cmd_open_file = command_get_by_name(CMD_OPEN_FILE); @@ -117,7 +118,7 @@ static LRESULT ase_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (length > 0) { TCHAR* lpstr = new TCHAR[length+1]; DragQueryFile(hdrop, index, lpstr, length+1); - dropped_files.push_back(lpstr); + dropped_files->push_back(lpstr); delete[] lpstr; } } diff --git a/src/core/file_system.cpp b/src/core/file_system.cpp index e1122f48a..289a4d9a2 100644 --- a/src/core/file_system.cpp +++ b/src/core/file_system.cpp @@ -136,8 +136,8 @@ typedef std::map ThumbnailMap; // the root of the file-system static FileItem* rootitem = NULL; -static FileItemMap fileitems_map; -static ThumbnailMap thumbnail_map; +static FileItemMap* fileitems_map; +static ThumbnailMap* thumbnail_map; static unsigned int current_file_system_version = 0; #ifdef USE_PIDLS @@ -174,8 +174,11 @@ static unsigned int current_file_system_version = 0; /** * Initializes the file-system module to navigate the file-system. */ -bool file_system_init() +void file_system_init() { + fileitems_map = new FileItemMap; + thumbnail_map = new ThumbnailMap; + #ifdef USE_PIDLS /* get the IMalloc interface */ SHGetMalloc(&shl_imalloc); @@ -190,8 +193,6 @@ bool file_system_init() // get the root element of the file system (this will create // the 'rootitem' FileItem) get_root_fileitem(); - - return TRUE; } /** @@ -200,16 +201,16 @@ bool file_system_init() void file_system_exit() { for (FileItemMap::iterator - it=fileitems_map.begin(); it!=fileitems_map.end(); ++it) { + it=fileitems_map->begin(); it!=fileitems_map->end(); ++it) { delete it->second; } - fileitems_map.clear(); + fileitems_map->clear(); for (ThumbnailMap::iterator - it=thumbnail_map.begin(); it!=thumbnail_map.end(); ++it) { + it=thumbnail_map->begin(); it!=thumbnail_map->end(); ++it) { destroy_bitmap(it->second); } - thumbnail_map.clear(); + thumbnail_map->clear(); #ifdef USE_PIDLS // relase desktop IShellFolder interface @@ -219,6 +220,9 @@ void file_system_exit() shl_imalloc->Release(); shl_imalloc = NULL; #endif + + delete fileitems_map; + delete thumbnail_map; } /** @@ -534,8 +538,8 @@ BITMAP* fileitem_get_thumbnail(FileItem* fileitem) { assert(fileitem); - ThumbnailMap::iterator it = thumbnail_map.find(fileitem->filename); - if (it != thumbnail_map.end()) + ThumbnailMap::iterator it = thumbnail_map->find(fileitem->filename); + if (it != thumbnail_map->end()) return it->second; else return NULL; @@ -546,14 +550,14 @@ void fileitem_set_thumbnail(FileItem* fileitem, BITMAP* thumbnail) assert(fileitem); // destroy the current thumbnail of the file (if exists) - ThumbnailMap::iterator it = thumbnail_map.find(fileitem->filename); - if (it != thumbnail_map.end()) { + ThumbnailMap::iterator it = thumbnail_map->find(fileitem->filename); + if (it != thumbnail_map->end()) { destroy_bitmap(it->second); - thumbnail_map.erase(it); + thumbnail_map->erase(it); } // insert the new one in the map - thumbnail_map.insert(std::make_pair(fileitem->filename, thumbnail)); + thumbnail_map->insert(std::make_pair(fileitem->filename, thumbnail)); } FileItem::FileItem(FileItem* parent) @@ -899,8 +903,8 @@ static jstring get_key_for_pidl(LPITEMIDLIST pidl) static FileItem* get_fileitem_by_fullpidl(LPITEMIDLIST fullpidl, bool create_if_not) { - FileItemMap::iterator it = fileitems_map.find(get_key_for_pidl(fullpidl)); - if (it != fileitems_map.end()) + FileItemMap::iterator it = fileitems_map->find(get_key_for_pidl(fullpidl)); + if (it != fileitems_map->end()) return it->second; if (!create_if_not) @@ -943,7 +947,7 @@ static void put_fileitem(FileItem* fileitem) assert(fileitem->keyname != NOTINITIALIZED); // insert this file-item in the hash-table - fileitems_map.insert(std::make_pair(fileitem->keyname, fileitem)); + fileitems_map->insert(std::make_pair(fileitem->keyname, fileitem)); } #else @@ -957,8 +961,8 @@ static FileItem* get_fileitem_by_path(const jstring& path, bool create_if_not) if (path.empty()) return rootitem; - FileItemMap::iterator it = fileitems_map.find(get_key_for_filename(path)); - if (it != fileitems_map.end()) + FileItemMap::iterator it = fileitems_map->find(get_key_for_filename(path)); + if (it != fileitems_map->end()) return it->second; if (!create_if_not) @@ -1066,7 +1070,7 @@ static void put_fileitem(FileItem* fileitem) assert(fileitem->keyname != NOTINITIALIZED); // insert this file-item in the hash-table - fileitems_map.insert(std::make_pair(fileitem->keyname, fileitem)); + fileitems_map->insert(std::make_pair(fileitem->keyname, fileitem)); } #endif diff --git a/src/core/file_system.h b/src/core/file_system.h index b289f2d61..7a21a6698 100644 --- a/src/core/file_system.h +++ b/src/core/file_system.h @@ -29,7 +29,7 @@ class FileItem; typedef std::vector FileItemList; -bool file_system_init(); +void file_system_init(); void file_system_exit(); void file_system_refresh(); diff --git a/src/core/modules.cpp b/src/core/modules.cpp index b9028c000..1b148d9b4 100644 --- a/src/core/modules.cpp +++ b/src/core/modules.cpp @@ -58,27 +58,22 @@ static Module module[] = static int modules = sizeof(module) / sizeof(Module); -bool modules_init(int requirements) +void modules_init(int requirements) { - int c; - - for (c=0; c=0; c--) + for (int c=modules-1; c>=0; c--) if (module[c].installed) { PRINTF("Unstalling module: %s\n", module[c].name); (*module[c].exit)(); diff --git a/src/core/modules.h b/src/core/modules.h index 15a285073..08a168132 100644 --- a/src/core/modules.h +++ b/src/core/modules.h @@ -23,7 +23,7 @@ #define REQUIRE_INTERFACE 1 -bool modules_init(int requirements); +void modules_init(int requirements); void modules_exit(); #endif /* CORE_MODULES_H */ diff --git a/src/jinete/jbase.h b/src/jinete/jbase.h index fa49bab81..4aa008f67 100644 --- a/src/jinete/jbase.h +++ b/src/jinete/jbase.h @@ -257,9 +257,11 @@ char* jstrdup (const char* string); #define jrenew(struct_type, mem, n_structs) \ ((struct_type*)jrealloc((mem), (sizeof(struct_type) * (n_structs)))) -#if defined MEMLEAK -void jmemleak_init(); -void jmemleak_exit(); -#endif +class Jinete +{ +public: + Jinete(); + ~Jinete(); +}; #endif /* JINETE_BASE_H */ diff --git a/src/jinete/jinete.cpp b/src/jinete/jinete.cpp new file mode 100644 index 000000000..2362f6a33 --- /dev/null +++ b/src/jinete/jinete.cpp @@ -0,0 +1,81 @@ +/* Jinete - a GUI library + * Copyright (C) 2003-2009 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. + */ + +#include "config.h" + +#include "jinete/jbase.h" + +#ifdef MEMLEAK +void _jmemleak_init(); +void _jmemleak_exit(); +#endif + +int _ji_widgets_init(); +void _ji_widgets_exit(); + +int _ji_system_init(); +void _ji_system_exit(); + +int _ji_font_init(); +void _ji_font_exit(); + +int _ji_theme_init(); +void _ji_theme_exit(); + +/** + * Initializes the Jinete library. + */ +Jinete::Jinete() +{ +#ifdef MEMLEAK + _jmemleak_init(); +#endif + + // initialize system + _ji_system_init(); + _ji_font_init(); + _ji_widgets_init(); + _ji_theme_init(); +} + +Jinete::~Jinete() +{ + // shutdown system + _ji_theme_exit(); + _ji_widgets_exit(); + _ji_font_exit(); + _ji_system_exit(); + +#ifdef MEMLEAK + _jmemleak_exit(); +#endif +} + diff --git a/src/jinete/jintern.cpp b/src/jinete/jintern.cpp index 441004362..a9b8b8399 100644 --- a/src/jinete/jintern.cpp +++ b/src/jinete/jintern.cpp @@ -39,19 +39,30 @@ #include "jinete/jwidget.h" #include "jinete/jwindow.h" -static std::vector widgets; +static std::vector* widgets; + +int _ji_widgets_init() +{ + widgets = new std::vector; + return 0; +} + +void _ji_widgets_exit() +{ + delete widgets; +} JWidget _ji_get_widget_by_id(JID widget_id) { - assert((widget_id >= 0) && (widget_id < widgets.size())); + assert((widget_id >= 0) && (widget_id < widgets->size())); - return widgets[widget_id]; + return (*widgets)[widget_id]; } JWidget* _ji_get_widget_array(int* n) { - *n = widgets.size(); - return &widgets.front(); + *n = widgets->size(); + return &widgets->front(); } void _ji_add_widget(JWidget widget) @@ -59,30 +70,30 @@ void _ji_add_widget(JWidget widget) JID widget_id; // first widget - if (widgets.empty()) { - widgets.resize(2); + if (widgets->empty()) { + widgets->resize(2); // id=0 no widget - widgets[0] = NULL; + (*widgets)[0] = NULL; // id>0 all widgets - widgets[1] = widget; - widgets[1]->id = widget_id = 1; + (*widgets)[1] = widget; + (*widgets)[1]->id = widget_id = 1; } else { // find a free slot - for (widget_id=1; widget_idsize(); widget_id++) { // is it free? - if (widgets[widget_id] == NULL) + if ((*widgets)[widget_id] == NULL) break; } // we need space for other widget more? - if (widget_id == widgets.size()) - widgets.resize(widgets.size()+1); + if (widget_id == widgets->size()) + widgets->resize(widgets->size()+1); - widgets[widget_id] = widget; - widgets[widget_id]->id = widget_id; + (*widgets)[widget_id] = widget; + (*widgets)[widget_id]->id = widget_id; } } @@ -90,37 +101,37 @@ void _ji_remove_widget(JWidget widget) { assert_valid_widget(widget); - widgets[widget->id] = NULL; + (*widgets)[widget->id] = NULL; } bool _ji_is_valid_widget(JWidget widget) { return (widget && widget->id >= 0 && - widget->id < widgets.size() && - widgets[widget->id] && - widgets[widget->id]->id == widget->id); + widget->id < widgets->size() && + (*widgets)[widget->id] && + (*widgets)[widget->id]->id == widget->id); } void _ji_set_font_of_all_widgets(struct FONT *f) { int c; - /* first of all, we have to set the font to all the widgets */ - for (c=0; cfont(f); + // first of all, we have to set the font to all the widgets + for (c=0; csize(); c++) + if (_ji_is_valid_widget((*widgets)[c])) + (*widgets)[c]->font(f); /* then we can reinitialize the theme of each widget */ - for (c=0; csize(); c++) + if (_ji_is_valid_widget((*widgets)[c])) + jwidget_init_theme((*widgets)[c]); /* remap the windows */ - for (c=0; ctype == JI_WINDOW) - jwindow_remap(widgets[c]); + for (c=0; csize(); c++) + if (_ji_is_valid_widget((*widgets)[c])) { + if ((*widgets)[c]->type == JI_WINDOW) + jwindow_remap((*widgets)[c]); } /* refresh the screen */ diff --git a/src/jinete/jintern.h b/src/jinete/jintern.h index 06e932cf7..5155b6747 100644 --- a/src/jinete/jintern.h +++ b/src/jinete/jintern.h @@ -37,8 +37,8 @@ struct FONT; struct BITMAP; -/**********************************************************************/ -/* jintern.c */ +////////////////////////////////////////////////////////////////////// +// jintern.c JWidget _ji_get_widget_by_id(JID widget_id); JWidget *_ji_get_widget_array(int *nwidgets); @@ -49,40 +49,25 @@ bool _ji_is_valid_widget(JWidget widget); void _ji_set_font_of_all_widgets(struct FONT *f); -/**********************************************************************/ -/* jsystem.c */ - -int _ji_system_init(); -void _ji_system_exit(); - -/**********************************************************************/ -/* jfont.c */ - -int _ji_font_init(); -void _ji_font_exit(); - -/**********************************************************************/ -/* jwidget.c */ +////////////////////////////////////////////////////////////////////// +// jwidget.c void _jwidget_add_hook(JWidget widget, JHook hook); void _jwidget_remove_hook(JWidget widget, JHook hook); -/**********************************************************************/ -/* jwindow.c */ +////////////////////////////////////////////////////////////////////// +// jwindow.c bool _jwindow_is_moving(); -/**********************************************************************/ -/* jmanager.c */ +////////////////////////////////////////////////////////////////////// +// jmanager.c void _jmanager_open_window(JWidget manager, JWidget window); void _jmanager_close_window(JWidget manager, JWidget window, bool redraw_background); -/**********************************************************************/ -/* jtheme.c */ - -int _ji_theme_init(); -void _ji_theme_exit(); +////////////////////////////////////////////////////////////////////// +// jtheme.c void _ji_theme_draw_sprite_color(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); @@ -90,8 +75,8 @@ void _ji_theme_draw_sprite_color(struct BITMAP *bmp, struct BITMAP *sprite, void _ji_theme_textbox_draw(struct BITMAP *bmp, JWidget textbox, int *w, int *h, int bg, int fg); -/**********************************************************************/ -/* jfontbmp.c */ +////////////////////////////////////////////////////////////////////// +// jfontbmp.c struct FONT *_ji_bitmap2font(struct BITMAP *bmp); diff --git a/src/jinete/jmanager.cpp b/src/jinete/jmanager.cpp index 7f0eb1234..a6405b564 100644 --- a/src/jinete/jmanager.cpp +++ b/src/jinete/jmanager.cpp @@ -157,10 +157,8 @@ JWidget jmanager_new() int c; if (!default_manager) { - /* initialize system */ - _ji_system_init(); - _ji_font_init(); - _ji_theme_init(); + if (!ji_screen) + ji_set_screen(screen); /* hook the window close message */ want_close_stage = STAGE_NORMAL; @@ -254,10 +252,6 @@ void jmanager_free(JWidget widget) default_manager = NULL; /* shutdown system */ - _ji_theme_exit(); - _ji_font_exit(); - _ji_system_exit(); - jlist_free(msg_queue); jlist_free(new_windows); jlist_free(proc_windows_list); diff --git a/src/jinete/jmem.cpp b/src/jinete/jmem.cpp index 3ce6d4ced..3ad068250 100644 --- a/src/jinete/jmem.cpp +++ b/src/jinete/jmem.cpp @@ -137,7 +137,7 @@ static bool memleak_status = false; static slot_t* headslot; static JMutex mutex; -void jmemleak_init() +void _jmemleak_init() { assert(!memleak_status); @@ -147,7 +147,7 @@ void jmemleak_init() memleak_status = true; } -void jmemleak_exit() +void _jmemleak_exit() { assert(memleak_status); memleak_status = false; diff --git a/src/jinete/jsystem.cpp b/src/jinete/jsystem.cpp index db1fcafe2..e71579d8f 100644 --- a/src/jinete/jsystem.cpp +++ b/src/jinete/jsystem.cpp @@ -118,7 +118,8 @@ int _ji_system_init() if (install_int_ex(clock_inc, BPS_TO_TIMER(1000)) < 0) return -1; - jmouse_poll(); + if (screen) + jmouse_poll(); moved = TRUE; m_cursor = JI_CURSOR_NULL; diff --git a/src/main.cpp b/src/main.cpp index e555612eb..145f56318 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,8 +20,10 @@ #include +#include "ase_exception.h" #include "core/app.h" +////////////////////////////////////////////////////////////////////// // Information for "ident". const char ase_ident[] = @@ -29,41 +31,41 @@ const char ase_ident[] = "$Website: " WEBSITE " $\n"; ////////////////////////////////////////////////////////////////////// -// Basic classes for some RAII +// Allegro libray initialization class Allegro { public: - Allegro() { allegro_init(); } - ~Allegro() { allegro_exit(); } + Allegro() { + allegro_init(); + set_uformat(U_ASCII); + install_timer(); + } + ~Allegro() { + remove_timer(); + allegro_exit(); + } }; -#if defined MEMLEAK -class MemLeaks { -public: - MemLeaks() { jmemleak_init(); } - ~MemLeaks() { jmemleak_exit(); } -}; -#endif - -////////////////////////////////////////////////////////////////////// -// Main Routine -////////////////////////////////////////////////////////////////////// - +/** + * Here ASE starts. + */ int main(int argc, char *argv[]) { - Allegro allegro; -#if defined MEMLEAK - MemLeaks memleaks; -#endif + try { + Allegro allegro; + try { + Jinete jinete; + Application app(argc, argv); - set_uformat(U_ASCII); - - // initialises the application - if (!app_init(argc, argv)) - return 1; - - app_loop(); - app_exit(); + app.run(); + } + catch (std::exception& e) { + allegro_message(e.what()); + } + } + catch (...) { + // do nothing + } return 0; } diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp index c87faf6ba..99462c719 100644 --- a/src/modules/gui.cpp +++ b/src/modules/gui.cpp @@ -128,8 +128,8 @@ struct Monitor static JWidget manager = NULL; static int monitor_timer = -1; -static std::list monitors; -static std::vector shortcuts; +static std::list* monitors = NULL; +static std::vector* shortcuts = NULL; static bool ji_screen_created = FALSE; @@ -168,11 +168,8 @@ int init_module_gui() int c, w, h, bpp, autodetect; bool fullscreen; - /* install timer related stuff */ - if (install_timer() < 0) { - user_printf(_("Error installing timer handler\n")); - return -1; - } + monitors = new std::list(); + shortcuts = new std::vector(); /* install the mouse */ if (install_mouse() < 0) { @@ -313,20 +310,24 @@ int init_module_gui() void exit_module_gui() { // destroy shortcuts + assert(shortcuts != NULL); for (std::vector::iterator - it = shortcuts.begin(); it != shortcuts.end(); ++it) { + it = shortcuts->begin(); it != shortcuts->end(); ++it) { Shortcut* shortcut = *it; delete shortcut; } - shortcuts.clear(); + delete shortcuts; + shortcuts = NULL; // destroy monitors + assert(monitors != NULL); for (std::list::iterator - it2 = monitors.begin(); it2 != monitors.end(); ++it2) { + it2 = monitors->begin(); it2 != monitors->end(); ++it2) { Monitor* monitor = *it2; delete monitor; } - monitors.clear(); + delete monitors; + monitors = NULL; if (double_buffering) { BITMAP *old_bmp = ji_screen; @@ -344,7 +345,6 @@ void exit_module_gui() remove_keyboard(); remove_mouse(); - remove_timer(); } int guiscale() @@ -783,7 +783,7 @@ JAccel add_keyboard_shortcut_to_execute_command(const char* shortcut_string, Com shortcut->command = command; shortcut->argument = argument ? argument: ""; - shortcuts.push_back(shortcut); + shortcuts->push_back(shortcut); } shortcut->add_shortcut(shortcut_string); @@ -798,7 +798,7 @@ JAccel add_keyboard_shortcut_to_change_tool(const char* shortcut_string, Tool* t shortcut = new Shortcut(Shortcut_ChangeTool); shortcut->tool = tool; - shortcuts.push_back(shortcut); + shortcuts->push_back(shortcut); } shortcut->add_shortcut(shortcut_string); @@ -808,7 +808,7 @@ JAccel add_keyboard_shortcut_to_change_tool(const char* shortcut_string, Tool* t Command* get_command_from_key_message(JMessage msg) { for (std::vector::iterator - it = shortcuts.begin(); it != shortcuts.end(); ++it) { + it = shortcuts->begin(); it != shortcuts->end(); ++it) { Shortcut* shortcut = *it; if (shortcut->type == Shortcut_ExecuteCommand && @@ -873,7 +873,7 @@ static Shortcut* get_keyboard_shortcut_for_command(Command* command, const char* argument = ""; for (std::vector::iterator - it = shortcuts.begin(); it != shortcuts.end(); ++it) { + it = shortcuts->begin(); it != shortcuts->end(); ++it) { Shortcut* shortcut = *it; if (shortcut->type == Shortcut_ExecuteCommand && @@ -889,7 +889,7 @@ static Shortcut* get_keyboard_shortcut_for_command(Command* command, const char* static Shortcut* get_keyboard_shortcut_for_tool(Tool* tool) { for (std::vector::iterator - it = shortcuts.begin(); it != shortcuts.end(); ++it) { + it = shortcuts->begin(); it != shortcuts->end(); ++it) { Shortcut* shortcut = *it; if (shortcut->type == Shortcut_ChangeTool && @@ -911,7 +911,7 @@ Monitor* add_gui_monitor(void (*proc)(void *), { Monitor* monitor = new Monitor(proc, free, data); - monitors.push_back(monitor); + monitors->push_back(monitor); if (monitor_timer < 0) monitor_timer = jmanager_add_timer(manager, MONITOR_TIMER_MSECS); @@ -927,17 +927,17 @@ Monitor* add_gui_monitor(void (*proc)(void *), void remove_gui_monitor(Monitor* monitor) { std::list::iterator it = - std::find(monitors.begin(), monitors.end(), monitor); + std::find(monitors->begin(), monitors->end(), monitor); - assert(it != monitors.end()); + assert(it != monitors->end()); if (!monitor->lock) delete monitor; else monitor->deleted = true; - monitors.erase(it); - if (monitors.empty()) + monitors->erase(it); + if (monitors->empty()) jmanager_stop_timer(monitor_timer); } @@ -958,7 +958,7 @@ static bool manager_msg_proc(JWidget widget, JMessage msg) case JM_TIMER: if (msg->timer.timer_id == monitor_timer) { for (std::list::iterator - it = monitors.begin(), next; it != monitors.end(); it = next) { + it = monitors->begin(), next; it != monitors->end(); it = next) { Monitor* monitor = *it; next = it; ++next; @@ -976,14 +976,14 @@ static bool manager_msg_proc(JWidget widget, JMessage msg) } // is monitors empty? we can stop the timer so - if (monitors.empty()) + if (monitors->empty()) jmanager_stop_timer(monitor_timer); } break; case JM_KEYPRESSED: for (std::vector::iterator - it = shortcuts.begin(); it != shortcuts.end(); ++it) { + it = shortcuts->begin(); it != shortcuts->end(); ++it) { Shortcut* shortcut = *it; if (shortcut->is_key_pressed(msg)) { diff --git a/src/raster/gfxobj.cpp b/src/raster/gfxobj.cpp index 767b3011f..0d8448d9c 100644 --- a/src/raster/gfxobj.cpp +++ b/src/raster/gfxobj.cpp @@ -29,26 +29,24 @@ #include "raster/gfxobj.h" static JMutex objects_mutex; -static gfxobj_id object_id = 0; // last object ID created -static std::map objects_map; // graphics objects map +static gfxobj_id object_id = 0; // last object ID created +static std::map* objects_map; // graphics objects map static void insert_gfxobj(GfxObj* gfxobj); static void erase_gfxobj(GfxObj* gfxobj); ////////////////////////////////////////////////////////////////////// - -bool gfxobj_init() -{ - objects_mutex = jmutex_new(); - if (!objects_mutex) - return false; - return true; +void gfxobj_init() +{ + objects_map = new std::map; + objects_mutex = jmutex_new(); } void gfxobj_exit() { - assert(objects_map.empty()); + assert(objects_map->empty()); + delete objects_map; jmutex_free(objects_mutex); } @@ -100,9 +98,9 @@ GfxObj* gfxobj_find(gfxobj_id id) jmutex_lock(objects_mutex); { std::map::iterator - it = objects_map.find(id); + it = objects_map->find(id); - if (it != objects_map.end()) + if (it != objects_map->end()) ret = it->second; } jmutex_unlock(objects_mutex); @@ -128,15 +126,15 @@ void _gfxobj_set_id(GfxObj* gfxobj, gfxobj_id id) static void insert_gfxobj(GfxObj* gfxobj) { - objects_map.insert(std::make_pair(gfxobj->id, gfxobj)); + objects_map->insert(std::make_pair(gfxobj->id, gfxobj)); } static void erase_gfxobj(GfxObj* gfxobj) { std::map::iterator - it = objects_map.find(gfxobj->id); + it = objects_map->find(gfxobj->id); - assert(it != objects_map.end()); + assert(it != objects_map->end()); - objects_map.erase(it); + objects_map->erase(it); } diff --git a/src/raster/gfxobj.h b/src/raster/gfxobj.h index d7c2b5560..3e6020a5f 100644 --- a/src/raster/gfxobj.h +++ b/src/raster/gfxobj.h @@ -50,7 +50,7 @@ private: void assign_id(); }; -bool gfxobj_init(); +void gfxobj_init(); void gfxobj_exit(); GfxObj* gfxobj_find(gfxobj_id id);