From a198e43b7e757483dea724dec142607eed38ad5c Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 27 Sep 2007 20:13:06 +0000 Subject: [PATCH] Added "save_file_as" and "options" commands. Added some dirty tricks to handle the mouse capture in Windows. --- ChangeLog | 11 +++++ NEWS.txt | 13 +++--- TODO.txt | 1 + config.h | 2 +- data/scripts/savespr.lua | 50 -------------------- jinete/src/jsystem.c | 81 +++++++++++++++++++++++++-------- misc/dist.sh | 4 +- src/commands/cmd_close_file.c | 6 ++- src/commands/cmd_customize.c | 1 + src/commands/cmd_options.c | 7 ++- src/commands/cmd_save_file_as.c | 63 ++++++++++++++++++++++++- src/commands/commands.c | 7 +-- 12 files changed, 159 insertions(+), 87 deletions(-) delete mode 100644 data/scripts/savespr.lua diff --git a/ChangeLog b/ChangeLog index 95720dbfc..7aae503dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2007-09-27 David A. Capello + * jinete/src/jsystem.c (jmouse_poll): Now (in Windows) we continue + getting mouse feedback even when the cursor is outside of the + window. + + * src/commands/cmd_close_file.c (command_execute_close_all_files): + Fixed. + * src/commands/cmd_drawing_tools.c: Added. All change of drawing-tool is in this file. @@ -16,6 +23,10 @@ 2007-09-26 David A. Capello + * jinete/src/jwidget.c (jwidget_hard_capture_mouse): Added usage + of SetCapture() (in Windows, to really capture the mouse in OS + level). + * src/commands/cmd_preview.c: Added. * src/dialogs/viewspr.c: Removed. diff --git a/NEWS.txt b/NEWS.txt index da1e74ff6..e4159b8db 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -2,17 +2,18 @@ NEWS =================================== -0.6 +0.9 --- -+ New XML format for the menus. Restructured all the menus (more user - friendly?) -+ Added menu customization through UI (Tools/Customize). ++ Restructured all the menus (more user friendly options). ++ New XML format for the menus. - Removed menu scripting customization. - Removed screen saver. -+ GUI enhanced: more borders for windows, and more spacing between - widgets. ++ GUI enhanced: + + more borders for windows and more spacing between widgets. + + better mouse behavior (in Windows). + Added support for PNG files (through libpng). ++ Finished the support for ICO files. + Finally screen scaling supported (with double-buffering). This means that you can use a screen of 320x240 between a window of 640x480 (screen-scaling x2). This is the new default video mode for ASE. diff --git a/TODO.txt b/TODO.txt index 65346db3e..8532492cf 100644 --- a/TODO.txt +++ b/TODO.txt @@ -44,6 +44,7 @@ High priority work Wish-list --------- +- Add menu customization through UI (Tools/Customize). - Mateusz Czaplinski ideas: + when move selections, will be good the possibility to see relative position from the starting point of movement; diff --git a/config.h b/config.h index f60d68a39..de188b795 100644 --- a/config.h +++ b/config.h @@ -24,7 +24,7 @@ /* general information */ #define PACKAGE "ase" -#define VERSION "0.6" +#define VERSION "0.9" #define WEBSITE "http://ase.sourceforge.net/" #define BUGREPORT "ase-help@lists.sourceforge.net" #define COPYRIGHT "Copyright (C) 2001-2005, 2007 David A. Capello" diff --git a/data/scripts/savespr.lua b/data/scripts/savespr.lua deleted file mode 100644 index ce1ccb01f..000000000 --- a/data/scripts/savespr.lua +++ /dev/null @@ -1,50 +0,0 @@ --- ase -- allegro-sprite-editor: the ultimate sprites factory --- Copyright (C) 2001-2005 by David A. Capello - -function GUI_SaveSprite() - if not current_sprite then - return - end - - local filename = current_sprite.filename - local ret - - while true do - filename = ji_file_select(_("Save Sprite"), filename, - get_writeable_extensions()) - if not filename then - return - end - - -- does the file exist? - if file_exists(filename) then - -- ask if the user wants overwrite the file? - ret = jalert(_("Warning").. - "<<".._("File exists, overwrite it?").. - "<<"..get_filename(filename).. - "||".._("&Yes||&No||&Cancel")) - else - break - end - - -- "yes": we must continue with the operation... - if ret == 1 then - break - -- "cancel" or per example: we back doing nothing - elseif ret != 2 then - return - end - -- "no": we must back to select other file-name */ - end - - sprite_set_filename(current_sprite, filename) - rebuild_sprite_list() - - if sprite_save(current_sprite) == 0 then - recent_file(filename) - sprite_was_saved(current_sprite) - else - unrecent_file(filename) - print(_("Error saving sprite file: ")..current_sprite.filename) - end -end diff --git a/jinete/src/jsystem.c b/jinete/src/jsystem.c index 857630ee8..800314b5d 100644 --- a/jinete/src/jsystem.c +++ b/jinete/src/jsystem.c @@ -30,6 +30,9 @@ */ #include +#ifdef ALLEGRO_WINDOWS +#include +#endif #include "jinete/intern.h" #include "jinete/manager.h" @@ -78,6 +81,7 @@ static volatile int click_mouse_b = 0; static void set_cursor(BITMAP *bmp, int x, int y); static void clock_inc(void); static void check_click(void); +static void update_mouse_position(void); static void clock_inc(void) { @@ -297,8 +301,11 @@ bool jmouse_is_shown() return mouse_scares == 0; } -/* Returns TRUE if the mouse moved. */ - +/** + * Updates the mouse information (position, wheel and buttons). + * + * @return Returns TRUE if the mouse moved. + */ bool jmouse_poll(void) { m_b[1] = m_b[0]; @@ -311,25 +318,11 @@ bool jmouse_poll(void) m_b[0] = mouse_b; m_z[0] = mouse_z; - if (ji_screen == screen) { - m_x[0] = mouse_x; - m_y[0] = mouse_y; - } - else { - m_x[0] = JI_SCREEN_W * mouse_x / SCREEN_W; - m_y[0] = JI_SCREEN_H * mouse_y / SCREEN_H; - } + update_mouse_position(); if ((m_x[0] != m_x[1]) || (m_y[0] != m_y[1])) { poll_mouse(); - if (ji_screen == screen) { - m_x[0] = mouse_x; - m_y[0] = mouse_y; - } - else { - m_x[0] = JI_SCREEN_W * mouse_x / SCREEN_W; - m_y[0] = JI_SCREEN_H * mouse_y / SCREEN_H; - } + update_mouse_position(); moved = TRUE; } @@ -409,3 +402,55 @@ void jmouse_set_click_level(int level) click_mouse_b = m_b[0]; } } + +static void update_mouse_position(void) +{ + if (ji_screen == screen) { + m_x[0] = mouse_x; + m_y[0] = mouse_y; + } + else { + m_x[0] = JI_SCREEN_W * mouse_x / SCREEN_W; + m_y[0] = JI_SCREEN_H * mouse_y / SCREEN_H; + } + +#ifdef ALLEGRO_WINDOWS + /* this help us (in windows) to get mouse feedback when we capture + the mouse but we are outside the Allegro window */ + { + POINT pt; + RECT rc; + + if (GetCursorPos(&pt) && GetClientRect(win_get_window(), &rc)) { + MapWindowPoints(win_get_window(), NULL, (POINT *)&rc, 2); + + if (!PtInRect(&rc, pt)) { + /* if the mouse is free we can hide the cursor putting the + mouse outside the screen (right-bottom corder) */ + if (!jmanager_get_capture()) { + m_x[0] = JI_SCREEN_W+focus_x; + m_y[0] = JI_SCREEN_H+focus_y; + } + /* if the mouse is captured we can put it in the edges of the screen */ + else { + pt.x -= rc.left; + pt.y -= rc.top; + + if (ji_screen == screen) { + m_x[0] = pt.x; + m_y[0] = pt.y; + } + else { + m_x[0] = JI_SCREEN_W * pt.x / SCREEN_W; + m_y[0] = JI_SCREEN_H * pt.y / SCREEN_H; + } + + m_x[0] = MID(0, m_x[0], JI_SCREEN_W-1); + m_y[0] = MID(0, m_y[0], JI_SCREEN_H-1); + } + } + } + } +#endif +} + diff --git a/misc/dist.sh b/misc/dist.sh index 6f1bffe12..c05538ff5 100644 --- a/misc/dist.sh +++ b/misc/dist.sh @@ -1,7 +1,7 @@ #! /bin/sh dir="`pwd`" -version=0.6 +version=0.9 distdir=ase-$version freetype_files="jinete/freetype/ChangeLog \ @@ -177,7 +177,7 @@ exit ###################################################################### # Files for binary distributions -function def_common_files () +function def_common_files() { txt_files=" \ $1/*.txt \ diff --git a/src/commands/cmd_close_file.c b/src/commands/cmd_close_file.c index 1cb0c0b10..c24631a51 100644 --- a/src/commands/cmd_close_file.c +++ b/src/commands/cmd_close_file.c @@ -57,7 +57,11 @@ bool command_enabled_close_all_files(const char *argument) void command_execute_close_all_files(const char *argument) { - while (close_current_sprite()) + if (!current_sprite) + sprite_show(get_first_sprite()); + + while (current_sprite != NULL && + close_current_sprite()) ; } diff --git a/src/commands/cmd_customize.c b/src/commands/cmd_customize.c index fa298a8bb..dc9053b0d 100644 --- a/src/commands/cmd_customize.c +++ b/src/commands/cmd_customize.c @@ -30,4 +30,5 @@ void command_execute_customize(const char *argument) { + jalert("Customize< -#include "core/app.h" +#include "jinete/alert.h" + +#include "console/console.h" +/* #include "core/app.h" */ +#include "dialogs/filesel.h" +#include "file/file.h" +#include "modules/recent.h" +#include "modules/gui.h" #include "modules/sprites.h" #include "raster/sprite.h" #endif +bool command_enabled_save_file_as(const char *argument) +{ + return current_sprite != NULL; +} + void command_execute_save_file_as(const char *argument) { + char filename[4096]; + char *newfilename; + int ret; + + ustrcpy(filename, current_sprite->filename); + + for (;;) { + newfilename = GUI_FileSelect(_("Save Sprite"), filename, + get_writeable_extensions()); + if (!newfilename) + return; + ustrcpy(filename, newfilename); + jfree(newfilename); + + /* does the file exist? */ + if (exists(filename)) { + /* ask if the user wants overwrite the file? */ + ret = jalert("%s<<%s<<%s||%s||%s||%s", + _("Warning"), + _("File exists, overwrite it?"), + get_filename(filename), + _("&Yes"), _("&No"), _("&Cancel")); + } + else + break; + + /* "yes": we must continue with the operation... */ + if (ret == 1) + break; + /* "cancel" or per example: we back doing nothing */ + else if (ret != 2) + return; + + /* "no": we must back to select other file-name */ + } + + sprite_set_filename(current_sprite, filename); + rebuild_sprite_list(); + + if (sprite_save(current_sprite) == 0) { + recent_file(filename); + sprite_was_saved(current_sprite); + } + else { + unrecent_file(filename); + console_printf("%s: %s", _("Error saving sprite file"), filename); + } } diff --git a/src/commands/commands.c b/src/commands/commands.c index afb191032..301d6ab8e 100644 --- a/src/commands/commands.c +++ b/src/commands/commands.c @@ -114,6 +114,7 @@ void command_execute_replace_color(const char *argument); void command_execute_reselect_mask(const char *argument); void command_execute_run_script(const char *argument); void command_execute_save_file(const char *argument); +bool command_enabled_save_file_as(const char *argument); void command_execute_save_file_as(const char *argument); void command_execute_save_mask(const char *argument); void command_execute_save_session(const char *argument); @@ -132,7 +133,7 @@ static Command commands[] = { CMD0(new_file), CMD0(open_file), { CMD_SAVE_FILE, NULL, NULL, NULL, NULL }, - { CMD_SAVE_FILE_AS, NULL, NULL, NULL, NULL }, + CMD1(save_file_as), CMD1(close_file), CMD1(close_all_files), { CMD_SCREEN_SHOT, NULL, NULL, NULL, NULL }, @@ -211,8 +212,8 @@ static Command commands[] = { { CMD_MAPGEN, NULL, NULL, NULL, NULL }, { CMD_RUN_SCRIPT, NULL, NULL, NULL, NULL }, CMD0(tips), - { CMD_CUSTOMIZE, NULL, NULL, NULL, NULL }, - { CMD_OPTIONS, NULL, NULL, NULL, NULL }, + CMD0(customize), + CMD0(options), CMD3(select_file), { NULL, NULL, NULL, NULL, NULL }