2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2014-06-23 05:53:14 +08:00
|
|
|
* Copyright (C) 2001-2014 David Capello
|
2007-09-19 07:57:02 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-09-19 07:57:02 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/commands.h"
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
#include "app/console.h"
|
|
|
|
#include "app/ini_file.h"
|
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#include "app/modules/gfx.h"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
|
|
|
#include "app/settings/settings.h"
|
|
|
|
#include "app/tools/ink.h"
|
|
|
|
#include "app/tools/tool_box.h"
|
|
|
|
#include "app/ui/editor/editor.h"
|
|
|
|
#include "app/ui/main_menu_bar.h"
|
|
|
|
#include "app/ui/main_menu_bar.h"
|
|
|
|
#include "app/ui/main_window.h"
|
|
|
|
#include "app/ui/skin/button_icon_impl.h"
|
|
|
|
#include "app/ui/skin/skin_property.h"
|
|
|
|
#include "app/ui/skin/skin_theme.h"
|
|
|
|
#include "app/ui/status_bar.h"
|
|
|
|
#include "app/ui/toolbar.h"
|
|
|
|
#include "app/ui_context.h"
|
2011-10-30 06:21:19 +08:00
|
|
|
#include "base/memory.h"
|
2010-09-30 04:14:11 +08:00
|
|
|
#include "base/shared_ptr.h"
|
2012-04-08 00:12:01 +08:00
|
|
|
#include "base/unique_ptr.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
#include "raster/sprite.h"
|
2014-03-30 09:12:01 +08:00
|
|
|
#include "she/clipboard.h"
|
2012-08-06 08:16:16 +08:00
|
|
|
#include "she/display.h"
|
2014-06-18 11:53:15 +08:00
|
|
|
#include "she/error.h"
|
2012-08-06 08:16:16 +08:00
|
|
|
#include "she/surface.h"
|
|
|
|
#include "she/system.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/intern.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
#include <algorithm>
|
|
|
|
#include <allegro.h>
|
|
|
|
#include <allegro/internal/aintern.h>
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#ifdef ALLEGRO_WINDOWS
|
|
|
|
#include <winalleg.h>
|
2014-03-30 09:12:01 +08:00
|
|
|
|
2012-02-13 10:21:06 +08:00
|
|
|
#endif
|
|
|
|
|
2012-01-08 05:47:48 +08:00
|
|
|
#define SPRITEDITOR_ACTION_COPYSELECTION "CopySelection"
|
|
|
|
#define SPRITEDITOR_ACTION_SNAPTOGRID "SnapToGrid"
|
|
|
|
#define SPRITEDITOR_ACTION_ANGLESNAP "AngleSnap"
|
|
|
|
#define SPRITEDITOR_ACTION_MAINTAINASPECTRATIO "MaintainAspectRatio"
|
2012-07-07 06:51:40 +08:00
|
|
|
#define SPRITEDITOR_ACTION_LOCKAXIS "LockAxis"
|
2011-10-30 06:21:19 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2007-11-29 01:50:16 +08:00
|
|
|
|
2010-09-26 03:22:32 +08:00
|
|
|
using namespace gfx;
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
2013-08-06 08:20:19 +08:00
|
|
|
using namespace app::skin;
|
2010-09-26 03:22:32 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
static struct {
|
2007-11-29 01:50:16 +08:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int scale;
|
2011-04-07 07:15:36 +08:00
|
|
|
} try_resolutions[] = { { 1024, 768, 2 },
|
2012-01-06 06:45:03 +08:00
|
|
|
{ 800, 600, 2 },
|
|
|
|
{ 640, 480, 2 },
|
|
|
|
{ 320, 240, 1 },
|
|
|
|
{ 320, 200, 1 },
|
|
|
|
{ 0, 0, 0 } };
|
2007-11-29 01:50:16 +08:00
|
|
|
|
2010-03-25 00:56:31 +08:00
|
|
|
static int try_depths[] = { 32, 24, 16, 15 };
|
2007-11-29 01:50:16 +08:00
|
|
|
|
2009-07-10 10:08:41 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
enum ShortcutType { Shortcut_ExecuteCommand,
|
2012-01-06 06:45:03 +08:00
|
|
|
Shortcut_ChangeTool,
|
|
|
|
Shortcut_EditorQuicktool,
|
|
|
|
Shortcut_SpriteEditor };
|
2009-07-10 10:08:41 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
struct Shortcut {
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* accel;
|
2009-07-10 10:08:41 +08:00
|
|
|
ShortcutType type;
|
|
|
|
union {
|
|
|
|
Command* command;
|
2011-04-02 21:47:03 +08:00
|
|
|
tools::Tool* tool;
|
2011-10-30 06:21:19 +08:00
|
|
|
char* action;
|
2009-07-10 10:08:41 +08:00
|
|
|
};
|
2009-10-09 09:34:06 +08:00
|
|
|
Params* params;
|
2009-07-10 10:08:41 +08:00
|
|
|
|
|
|
|
Shortcut(ShortcutType type);
|
|
|
|
~Shortcut();
|
|
|
|
|
|
|
|
void add_shortcut(const char* shortcut_string);
|
2011-04-03 00:14:07 +08:00
|
|
|
bool is_pressed(Message* msg);
|
2010-10-28 08:02:48 +08:00
|
|
|
bool is_pressed_from_key_array();
|
2009-07-10 10:08:41 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-10-09 09:34:06 +08:00
|
|
|
static Shortcut* get_keyboard_shortcut_for_command(const char* command_name, Params* params);
|
2011-04-02 21:47:03 +08:00
|
|
|
static Shortcut* get_keyboard_shortcut_for_tool(tools::Tool* tool);
|
|
|
|
static Shortcut* get_keyboard_shortcut_for_quicktool(tools::Tool* tool);
|
2011-10-30 06:21:19 +08:00
|
|
|
static Shortcut* get_keyboard_shortcut_for_spriteeditor(const char* action_name);
|
2009-07-10 10:08:41 +08:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2007-11-29 01:50:16 +08:00
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
class CustomizedGuiManager : public Manager
|
2012-07-18 12:10:43 +08:00
|
|
|
, public LayoutIO
|
2012-06-16 10:37:59 +08:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
bool onProcessMessage(Message* msg) OVERRIDE;
|
2012-07-18 12:10:43 +08:00
|
|
|
LayoutIO* onGetLayoutIO() OVERRIDE { return this; }
|
|
|
|
|
|
|
|
// LayoutIO implementation
|
|
|
|
std::string loadLayout(Widget* widget) OVERRIDE;
|
|
|
|
void saveLayout(Widget* widget, const std::string& str) OVERRIDE;
|
2012-06-16 10:37:59 +08:00
|
|
|
};
|
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
static she::Display* main_display = NULL;
|
2014-03-30 09:12:01 +08:00
|
|
|
static she::Clipboard* main_clipboard = NULL;
|
2012-06-16 10:37:59 +08:00
|
|
|
static CustomizedGuiManager* manager = NULL;
|
2011-01-22 04:50:04 +08:00
|
|
|
static Theme* ase_theme = NULL;
|
2008-02-04 10:37:26 +08:00
|
|
|
|
2009-08-05 09:53:02 +08:00
|
|
|
static std::vector<Shortcut*>* shortcuts = NULL;
|
2008-02-04 10:37:26 +08:00
|
|
|
|
2010-10-31 07:37:31 +08:00
|
|
|
static volatile int restored_width = 0;
|
|
|
|
static volatile int restored_height = 0;
|
|
|
|
|
2011-04-02 22:45:43 +08:00
|
|
|
// Default GUI screen configuration
|
2007-09-20 08:32:35 +08:00
|
|
|
static int screen_scaling;
|
|
|
|
|
2010-03-09 10:43:28 +08:00
|
|
|
static void reload_default_font();
|
|
|
|
|
2011-04-02 22:45:43 +08:00
|
|
|
// Load & save graphics configuration
|
2012-08-06 08:16:16 +08:00
|
|
|
static void load_gui_config(int& w, int& h, bool& maximized);
|
2008-10-01 09:27:51 +08:00
|
|
|
static void save_gui_config();
|
2007-09-20 08:32:35 +08:00
|
|
|
|
2012-06-16 11:05:01 +08:00
|
|
|
static bool button_with_icon_msg_proc(Widget* widget, Message* msg);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-05-01 02:29:33 +08:00
|
|
|
// Initializes GUI.
|
2008-10-01 09:27:51 +08:00
|
|
|
int init_module_gui()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2012-08-06 08:16:16 +08:00
|
|
|
int c, w, h, min_possible_dsk_res = 0;
|
2009-11-22 22:39:52 +08:00
|
|
|
bool maximized;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2009-08-10 10:36:06 +08:00
|
|
|
shortcuts = new std::vector<Shortcut*>;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-05-01 02:29:33 +08:00
|
|
|
// Set the graphics mode...
|
2012-08-06 08:16:16 +08:00
|
|
|
load_gui_config(w, h, maximized);
|
2007-11-29 01:50:16 +08:00
|
|
|
|
2012-08-06 08:16:16 +08:00
|
|
|
try {
|
2014-06-23 05:53:14 +08:00
|
|
|
main_display = she::instance()->createDisplay(w, h, screen_scaling);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2012-08-06 08:16:16 +08:00
|
|
|
catch (const she::DisplayCreationException&) {
|
2007-11-29 01:50:16 +08:00
|
|
|
for (c=min_possible_dsk_res; try_resolutions[c].width; ++c) {
|
2012-08-06 08:16:16 +08:00
|
|
|
try {
|
2012-08-11 10:14:54 +08:00
|
|
|
main_display =
|
2014-06-23 05:53:14 +08:00
|
|
|
she::instance()->createDisplay(try_resolutions[c].width,
|
2012-08-11 10:14:54 +08:00
|
|
|
try_resolutions[c].height,
|
|
|
|
try_resolutions[c].scale);
|
2010-09-19 10:33:32 +08:00
|
|
|
|
2012-08-06 08:16:16 +08:00
|
|
|
screen_scaling = try_resolutions[c].scale;
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
2007-11-29 01:50:16 +08:00
|
|
|
}
|
2012-08-06 08:16:16 +08:00
|
|
|
catch (const she::DisplayCreationException&) {
|
|
|
|
// Ignore
|
|
|
|
}
|
2007-11-29 01:50:16 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2010-09-19 10:33:32 +08:00
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
if (!main_display) {
|
2014-06-18 11:53:15 +08:00
|
|
|
she::error_message("Unable to create a user-interface display.\n");
|
2012-08-06 08:16:16 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2014-06-23 05:53:14 +08:00
|
|
|
main_clipboard = she::instance()->createClipboard();
|
2014-03-30 09:12:01 +08:00
|
|
|
|
2011-05-01 02:29:33 +08:00
|
|
|
// Create the default-manager
|
2012-06-16 10:37:59 +08:00
|
|
|
manager = new CustomizedGuiManager();
|
2012-08-11 10:14:54 +08:00
|
|
|
manager->setDisplay(main_display);
|
2014-03-30 09:12:01 +08:00
|
|
|
manager->setClipboard(main_clipboard);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-01-22 04:50:04 +08:00
|
|
|
// Setup the GUI theme for all widgets
|
|
|
|
CurrentTheme::set(ase_theme = new SkinTheme());
|
2010-10-31 07:37:31 +08:00
|
|
|
|
2012-08-06 08:16:16 +08:00
|
|
|
if (maximized)
|
2012-08-11 10:14:54 +08:00
|
|
|
main_display->maximize();
|
2009-11-22 22:39:52 +08:00
|
|
|
|
2011-05-01 02:29:33 +08:00
|
|
|
// Configure ji_screen
|
2009-11-22 22:39:52 +08:00
|
|
|
gui_setup_screen(true);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-05-01 02:29:33 +08:00
|
|
|
// Set graphics options for next time
|
2007-09-19 07:57:02 +08:00
|
|
|
save_gui_config();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
void exit_module_gui()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2014-02-08 11:19:20 +08:00
|
|
|
save_gui_config();
|
|
|
|
|
2009-07-10 10:08:41 +08:00
|
|
|
// destroy shortcuts
|
2010-08-04 10:33:44 +08:00
|
|
|
ASSERT(shortcuts != NULL);
|
2009-07-10 10:08:41 +08:00
|
|
|
for (std::vector<Shortcut*>::iterator
|
2012-01-06 06:45:03 +08:00
|
|
|
it = shortcuts->begin(); it != shortcuts->end(); ++it) {
|
2009-07-10 10:08:41 +08:00
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
delete shortcut;
|
|
|
|
}
|
2009-08-05 09:53:02 +08:00
|
|
|
delete shortcuts;
|
|
|
|
shortcuts = NULL;
|
2008-02-04 10:37:26 +08:00
|
|
|
|
2012-04-16 02:21:24 +08:00
|
|
|
delete manager;
|
2010-10-27 06:23:04 +08:00
|
|
|
|
|
|
|
// Now we can destroy theme
|
2011-01-22 04:50:04 +08:00
|
|
|
CurrentTheme::set(NULL);
|
2009-11-22 04:02:31 +08:00
|
|
|
delete ase_theme;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
remove_keyboard();
|
|
|
|
remove_mouse();
|
2012-08-11 10:14:54 +08:00
|
|
|
|
2014-03-30 09:12:01 +08:00
|
|
|
main_clipboard->dispose();
|
2012-08-11 10:14:54 +08:00
|
|
|
main_display->dispose();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2012-08-06 08:16:16 +08:00
|
|
|
static void load_gui_config(int& w, int& h, bool& maximized)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2009-11-22 22:39:52 +08:00
|
|
|
w = get_config_int("GfxMode", "Width", 0);
|
|
|
|
h = get_config_int("GfxMode", "Height", 0);
|
2011-04-07 07:15:36 +08:00
|
|
|
screen_scaling = get_config_int("GfxMode", "ScreenScale", 2);
|
2007-11-25 02:23:53 +08:00
|
|
|
screen_scaling = MID(1, screen_scaling, 4);
|
2009-11-22 22:39:52 +08:00
|
|
|
maximized = get_config_bool("GfxMode", "Maximized", false);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
static void save_gui_config()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2012-08-06 08:16:16 +08:00
|
|
|
she::Display* display = Manager::getDefault()->getDisplay();
|
|
|
|
if (display) {
|
|
|
|
set_config_bool("GfxMode", "Maximized", display->isMaximized());
|
|
|
|
set_config_int("GfxMode", "Width", display->originalWidth());
|
|
|
|
set_config_int("GfxMode", "Height", display->originalHeight());
|
2010-03-29 03:18:49 +08:00
|
|
|
set_config_int("GfxMode", "Depth", bitmap_color_depth(screen));
|
|
|
|
}
|
2011-04-07 07:15:36 +08:00
|
|
|
set_config_int("GfxMode", "ScreenScale", screen_scaling);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
int get_screen_scaling()
|
2007-11-25 02:23:53 +08:00
|
|
|
{
|
|
|
|
return screen_scaling;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_screen_scaling(int scaling)
|
|
|
|
{
|
|
|
|
screen_scaling = scaling;
|
|
|
|
}
|
|
|
|
|
2013-01-21 05:40:37 +08:00
|
|
|
void update_screen_for_document(Document* document)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2011-03-23 08:11:25 +08:00
|
|
|
// Without document.
|
|
|
|
if (!document) {
|
|
|
|
// Well, change to the default palette.
|
2010-01-31 00:43:13 +08:00
|
|
|
if (set_current_palette(NULL, false)) {
|
2011-03-23 08:11:25 +08:00
|
|
|
// If the palette changes, refresh the whole screen.
|
2012-06-18 09:02:54 +08:00
|
|
|
Manager::getDefault()->invalidate();
|
2007-11-19 22:23:15 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2011-03-23 08:11:25 +08:00
|
|
|
// With a document.
|
2007-09-19 07:57:02 +08:00
|
|
|
else {
|
2013-01-21 05:40:37 +08:00
|
|
|
document->notifyGeneralUpdate();
|
2011-03-27 06:58:52 +08:00
|
|
|
|
|
|
|
// Update the tabs (maybe the modified status has been changed).
|
2013-01-21 05:40:37 +08:00
|
|
|
app_rebuild_documents_tabs();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
void gui_run()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2012-04-16 02:21:24 +08:00
|
|
|
manager->run();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
void gui_feedback()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2012-08-06 12:17:29 +08:00
|
|
|
Manager* manager = Manager::getDefault();
|
|
|
|
OverlayManager* overlays = OverlayManager::instance();
|
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
ui::UpdateCursorOverlay();
|
2010-10-31 07:37:31 +08:00
|
|
|
|
2012-08-24 09:25:56 +08:00
|
|
|
// Avoid updating a non-dirty screen over and over again.
|
2013-01-21 05:40:37 +08:00
|
|
|
#if 0 // TODO It doesn't work yet
|
2012-08-24 09:25:56 +08:00
|
|
|
if (!dirty_display_flag)
|
|
|
|
return;
|
2012-08-24 21:25:19 +08:00
|
|
|
#endif
|
2012-08-24 09:25:56 +08:00
|
|
|
|
2012-08-06 12:17:29 +08:00
|
|
|
// Draw overlays.
|
|
|
|
overlays->captureOverlappedAreas();
|
|
|
|
overlays->drawOverlays();
|
|
|
|
|
|
|
|
if (!manager->getDisplay()->flip()) {
|
2012-08-06 08:16:16 +08:00
|
|
|
// In case that the display was resized.
|
2009-11-22 22:39:52 +08:00
|
|
|
gui_setup_screen(false);
|
2013-01-11 23:43:25 +08:00
|
|
|
App::instance()->getMainWindow()->remapWindow();
|
2012-08-06 12:17:29 +08:00
|
|
|
manager->invalidate();
|
2009-11-22 22:39:52 +08:00
|
|
|
}
|
2012-08-06 12:17:29 +08:00
|
|
|
else
|
|
|
|
overlays->restoreOverlappedAreas();
|
2012-08-24 09:25:56 +08:00
|
|
|
|
|
|
|
dirty_display_flag = false;
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2011-05-01 02:29:33 +08:00
|
|
|
// Sets the ji_screen variable. This routine should be called
|
|
|
|
// everytime you changes the graphics mode.
|
2009-11-22 22:39:52 +08:00
|
|
|
void gui_setup_screen(bool reload_font)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2010-03-09 09:35:32 +08:00
|
|
|
bool regen = false;
|
2010-03-09 10:43:28 +08:00
|
|
|
bool reinit = false;
|
2010-03-09 09:35:32 +08:00
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
main_display->setScale(screen_scaling);
|
2014-06-23 05:53:14 +08:00
|
|
|
ui::set_display(main_display);
|
2007-09-20 08:32:35 +08:00
|
|
|
|
2010-03-09 09:35:32 +08:00
|
|
|
// Update guiscale factor
|
|
|
|
int old_guiscale = jguiscale();
|
2011-01-22 04:50:04 +08:00
|
|
|
CurrentTheme::get()->guiscale = (screen_scaling == 1 &&
|
2012-01-06 06:45:03 +08:00
|
|
|
JI_SCREEN_W > 512 &&
|
|
|
|
JI_SCREEN_H > 256) ? 2: 1;
|
2010-03-08 10:42:41 +08:00
|
|
|
|
2010-03-09 09:35:32 +08:00
|
|
|
// If the guiscale have changed
|
|
|
|
if (old_guiscale != jguiscale()) {
|
|
|
|
reload_font = true;
|
|
|
|
regen = true;
|
|
|
|
}
|
|
|
|
|
2010-03-09 10:43:28 +08:00
|
|
|
if (reload_font) {
|
2009-11-22 22:39:52 +08:00
|
|
|
reload_default_font();
|
2010-03-09 10:43:28 +08:00
|
|
|
reinit = true;
|
|
|
|
}
|
2008-03-01 03:29:49 +08:00
|
|
|
|
2010-03-09 09:35:32 +08:00
|
|
|
// Regenerate the theme
|
2010-03-09 10:43:28 +08:00
|
|
|
if (regen) {
|
2011-01-22 04:50:04 +08:00
|
|
|
CurrentTheme::get()->regenerate();
|
2010-03-09 10:43:28 +08:00
|
|
|
reinit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reinit)
|
2013-03-31 00:38:24 +08:00
|
|
|
reinitThemeForAllWidgets();
|
2010-03-09 09:35:32 +08:00
|
|
|
|
|
|
|
// Set the configuration
|
2007-09-20 08:32:35 +08:00
|
|
|
save_gui_config();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2010-10-27 06:23:04 +08:00
|
|
|
static void reload_default_font()
|
|
|
|
{
|
2011-01-22 04:50:04 +08:00
|
|
|
Theme* theme = CurrentTheme::get();
|
2011-01-22 04:29:45 +08:00
|
|
|
SkinTheme* skin_theme = static_cast<SkinTheme*>(theme);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-04-02 22:45:43 +08:00
|
|
|
// Reload theme fonts
|
|
|
|
skin_theme->reload_fonts();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-03-01 08:09:46 +08:00
|
|
|
// Set all widgets fonts
|
2013-03-31 00:38:24 +08:00
|
|
|
setFontOfAllWidgets(theme->default_font);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2012-06-16 11:05:01 +08:00
|
|
|
void load_window_pos(Widget* window, const char *section)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
// Default position
|
|
|
|
Rect orig_pos = window->getBounds();
|
|
|
|
Rect pos = orig_pos;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
// Load configurated position
|
|
|
|
pos = get_config_rect(section, "WindowPos", pos);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
pos.w = MID(orig_pos.w, pos.w, JI_SCREEN_W);
|
|
|
|
pos.h = MID(orig_pos.h, pos.h, JI_SCREEN_H);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
pos.setOrigin(Point(MID(0, pos.x, JI_SCREEN_W-pos.w),
|
2012-01-06 06:45:03 +08:00
|
|
|
MID(0, pos.y, JI_SCREEN_H-pos.h)));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
window->setBounds(pos);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2012-06-16 11:05:01 +08:00
|
|
|
void save_window_pos(Widget* window, const char *section)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
- All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.
Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-08 03:47:45 +08:00
|
|
|
set_config_rect(section, "WindowPos", window->getBounds());
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2014-01-26 19:39:33 +08:00
|
|
|
Widget* setup_mini_font(Widget* widget)
|
2011-03-30 08:07:37 +08:00
|
|
|
{
|
2014-01-26 19:39:33 +08:00
|
|
|
widget->setFont(((SkinTheme*)widget->getTheme())->getMiniFont());
|
|
|
|
return widget;
|
2011-03-30 08:07:37 +08:00
|
|
|
}
|
|
|
|
|
2014-01-26 19:39:33 +08:00
|
|
|
Widget* setup_mini_look(Widget* widget)
|
|
|
|
{
|
|
|
|
return setup_look(widget, MiniLook);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget* setup_look(Widget* widget, LookType lookType)
|
2010-03-22 10:18:30 +08:00
|
|
|
{
|
2013-12-05 12:19:46 +08:00
|
|
|
SkinPropertyPtr skinProp = get_skin_property(widget);
|
2011-03-30 08:07:37 +08:00
|
|
|
skinProp->setLook(lookType);
|
2014-01-26 19:39:33 +08:00
|
|
|
return widget;
|
2010-03-22 10:18:30 +08:00
|
|
|
}
|
|
|
|
|
2010-08-24 04:41:19 +08:00
|
|
|
void setup_bevels(Widget* widget, int b1, int b2, int b3, int b4)
|
|
|
|
{
|
2013-12-05 12:19:46 +08:00
|
|
|
SkinPropertyPtr skinProp = get_skin_property(widget);
|
2010-08-24 04:41:19 +08:00
|
|
|
skinProp->setUpperLeft(b1);
|
|
|
|
skinProp->setUpperRight(b2);
|
|
|
|
skinProp->setLowerLeft(b3);
|
|
|
|
skinProp->setLowerRight(b4);
|
|
|
|
}
|
|
|
|
|
2011-03-07 03:15:05 +08:00
|
|
|
// Sets the IconInterface pointer interface of the button to show the
|
|
|
|
// specified set of icons. Each icon is a part of the SkinTheme.
|
|
|
|
void set_gfxicon_to_button(ButtonBase* button,
|
2012-01-06 06:45:03 +08:00
|
|
|
int normal_part_id,
|
|
|
|
int selected_part_id,
|
|
|
|
int disabled_part_id, int icon_align)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2011-03-07 03:15:05 +08:00
|
|
|
ButtonIconImpl* buttonIcon =
|
|
|
|
new ButtonIconImpl(static_cast<SkinTheme*>(button->getTheme()),
|
2012-01-06 06:45:03 +08:00
|
|
|
normal_part_id,
|
|
|
|
selected_part_id,
|
|
|
|
disabled_part_id,
|
|
|
|
icon_align);
|
2011-03-07 03:15:05 +08:00
|
|
|
|
|
|
|
button->setIconInterface(buttonIcon);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2011-05-01 02:29:33 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Button style (convert radio or check buttons and draw it like
|
|
|
|
// normal buttons)
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2010-08-24 04:41:19 +08:00
|
|
|
CheckBox* check_button_new(const char *text, int b1, int b2, int b3, int b4)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2013-04-04 09:07:24 +08:00
|
|
|
CheckBox* widget = new CheckBox(text, kButtonWidget);
|
2010-08-24 04:41:19 +08:00
|
|
|
|
|
|
|
widget->setAlign(JI_CENTER | JI_MIDDLE);
|
|
|
|
|
|
|
|
setup_mini_look(widget);
|
|
|
|
setup_bevels(widget, b1, b2, b3, b4);
|
2007-09-19 07:57:02 +08:00
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2009-07-10 10:08:41 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Keyboard shortcuts
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* add_keyboard_shortcut_to_execute_command(const char* shortcut_string, const char* command_name, Params* params)
|
2009-07-10 10:08:41 +08:00
|
|
|
{
|
2009-10-09 09:34:06 +08:00
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_command(command_name, params);
|
2009-07-10 10:08:41 +08:00
|
|
|
if (!shortcut) {
|
|
|
|
shortcut = new Shortcut(Shortcut_ExecuteCommand);
|
2011-01-21 07:49:03 +08:00
|
|
|
shortcut->command = CommandsModule::instance()->getCommandByName(command_name);
|
2009-10-09 09:34:06 +08:00
|
|
|
shortcut->params = params ? params->clone(): new Params;
|
2009-07-10 10:08:41 +08:00
|
|
|
|
2009-08-05 09:53:02 +08:00
|
|
|
shortcuts->push_back(shortcut);
|
2009-07-10 10:08:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
shortcut->add_shortcut(shortcut_string);
|
|
|
|
return shortcut->accel;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* add_keyboard_shortcut_to_change_tool(const char* shortcut_string, tools::Tool* tool)
|
2009-07-10 10:08:41 +08:00
|
|
|
{
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_tool(tool);
|
|
|
|
if (!shortcut) {
|
|
|
|
shortcut = new Shortcut(Shortcut_ChangeTool);
|
|
|
|
shortcut->tool = tool;
|
|
|
|
|
2009-08-05 09:53:02 +08:00
|
|
|
shortcuts->push_back(shortcut);
|
2009-07-10 10:08:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
shortcut->add_shortcut(shortcut_string);
|
|
|
|
return shortcut->accel;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* add_keyboard_shortcut_to_quicktool(const char* shortcut_string, tools::Tool* tool)
|
2010-10-28 08:02:48 +08:00
|
|
|
{
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_quicktool(tool);
|
|
|
|
if (!shortcut) {
|
|
|
|
shortcut = new Shortcut(Shortcut_EditorQuicktool);
|
|
|
|
shortcut->tool = tool;
|
|
|
|
|
|
|
|
shortcuts->push_back(shortcut);
|
|
|
|
}
|
|
|
|
|
|
|
|
shortcut->add_shortcut(shortcut_string);
|
|
|
|
return shortcut->accel;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* add_keyboard_shortcut_to_spriteeditor(const char* shortcut_string, const char* action_name)
|
2011-10-30 06:21:19 +08:00
|
|
|
{
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(action_name);
|
|
|
|
if (!shortcut) {
|
|
|
|
shortcut = new Shortcut(Shortcut_SpriteEditor);
|
|
|
|
shortcut->action = base_strdup(action_name);
|
|
|
|
|
|
|
|
shortcuts->push_back(shortcut);
|
|
|
|
}
|
|
|
|
|
|
|
|
shortcut->add_shortcut(shortcut_string);
|
|
|
|
return shortcut->accel;
|
|
|
|
}
|
|
|
|
|
2012-03-21 01:41:20 +08:00
|
|
|
bool get_command_from_key_message(Message* msg, Command** command, Params** params)
|
2009-07-10 10:08:41 +08:00
|
|
|
{
|
|
|
|
for (std::vector<Shortcut*>::iterator
|
2012-01-06 06:45:03 +08:00
|
|
|
it = shortcuts->begin(); it != shortcuts->end(); ++it) {
|
2009-07-10 10:08:41 +08:00
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
2012-03-21 01:41:20 +08:00
|
|
|
if (shortcut->type == Shortcut_ExecuteCommand && shortcut->is_pressed(msg)) {
|
|
|
|
if (command) *command = shortcut->command;
|
|
|
|
if (params) *params = shortcut->params;
|
|
|
|
return true;
|
2009-07-10 10:08:41 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-21 01:41:20 +08:00
|
|
|
return false;
|
2009-07-10 10:08:41 +08:00
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* get_accel_to_execute_command(const char* command_name, Params* params)
|
2009-07-10 10:08:41 +08:00
|
|
|
{
|
2009-10-09 09:34:06 +08:00
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_command(command_name, params);
|
2009-07-10 10:08:41 +08:00
|
|
|
if (shortcut)
|
|
|
|
return shortcut->accel;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* get_accel_to_change_tool(tools::Tool* tool)
|
2009-07-10 10:08:41 +08:00
|
|
|
{
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_tool(tool);
|
|
|
|
if (shortcut)
|
|
|
|
return shortcut->accel;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* get_accel_to_copy_selection()
|
2010-10-28 08:02:48 +08:00
|
|
|
{
|
2011-10-30 06:21:19 +08:00
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_COPYSELECTION);
|
|
|
|
if (shortcut)
|
|
|
|
return shortcut->accel;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* get_accel_to_snap_to_grid()
|
2012-01-08 03:37:07 +08:00
|
|
|
{
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_SNAPTOGRID);
|
|
|
|
if (shortcut)
|
|
|
|
return shortcut->accel;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* get_accel_to_angle_snap()
|
2012-01-08 03:37:07 +08:00
|
|
|
{
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_ANGLESNAP);
|
|
|
|
if (shortcut)
|
|
|
|
return shortcut->accel;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* get_accel_to_maintain_aspect_ratio()
|
2012-01-08 05:47:48 +08:00
|
|
|
{
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_MAINTAINASPECTRATIO);
|
|
|
|
if (shortcut)
|
|
|
|
return shortcut->accel;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* get_accel_to_lock_axis()
|
2012-07-07 06:51:40 +08:00
|
|
|
{
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(SPRITEDITOR_ACTION_LOCKAXIS);
|
|
|
|
if (shortcut)
|
|
|
|
return shortcut->accel;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-30 06:21:19 +08:00
|
|
|
tools::Tool* get_selected_quicktool(tools::Tool* currentTool)
|
|
|
|
{
|
|
|
|
if (currentTool && currentTool->getInk(0)->isSelection()) {
|
2012-07-18 08:42:02 +08:00
|
|
|
Accelerator* copyselection_accel = get_accel_to_copy_selection();
|
|
|
|
if (copyselection_accel && copyselection_accel->checkFromAllegroKeyArray())
|
2011-10-30 06:21:19 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-02 21:47:03 +08:00
|
|
|
tools::ToolBox* toolbox = App::instance()->getToolBox();
|
2010-10-28 08:02:48 +08:00
|
|
|
|
|
|
|
// Iterate over all tools
|
2011-04-02 21:47:03 +08:00
|
|
|
for (tools::ToolIterator it = toolbox->begin(); it != toolbox->end(); ++it) {
|
2010-10-28 08:02:48 +08:00
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_quicktool(*it);
|
|
|
|
|
|
|
|
// Collect all tools with the pressed keyboard-shortcut
|
|
|
|
if (shortcut && shortcut->is_pressed_from_key_array()) {
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-10 10:08:41 +08:00
|
|
|
Shortcut::Shortcut(ShortcutType type)
|
|
|
|
{
|
|
|
|
this->type = type;
|
2012-07-18 08:42:02 +08:00
|
|
|
this->accel = new Accelerator;
|
2009-10-09 09:34:06 +08:00
|
|
|
this->command = NULL;
|
|
|
|
this->tool = NULL;
|
|
|
|
this->params = NULL;
|
2009-07-10 10:08:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Shortcut::~Shortcut()
|
|
|
|
{
|
2009-10-09 09:34:06 +08:00
|
|
|
delete params;
|
2011-10-30 06:21:19 +08:00
|
|
|
if (type == Shortcut_SpriteEditor)
|
|
|
|
base_free(action);
|
2012-07-18 08:42:02 +08:00
|
|
|
delete accel;
|
2009-07-10 10:08:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shortcut::add_shortcut(const char* shortcut_string)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
usprintf(buf, "<%s>", shortcut_string);
|
2012-07-18 08:42:02 +08:00
|
|
|
this->accel->addKeysFromString(buf);
|
2009-07-10 10:08:41 +08:00
|
|
|
}
|
|
|
|
|
2011-04-03 00:14:07 +08:00
|
|
|
bool Shortcut::is_pressed(Message* msg)
|
2009-07-10 10:08:41 +08:00
|
|
|
{
|
|
|
|
if (accel) {
|
2013-07-29 08:17:07 +08:00
|
|
|
return accel->check(msg->keyModifiers(),
|
|
|
|
static_cast<KeyMessage*>(msg)->scancode(),
|
2013-10-15 06:58:11 +08:00
|
|
|
static_cast<KeyMessage*>(msg)->unicodeChar());
|
2009-07-10 10:08:41 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-28 08:02:48 +08:00
|
|
|
bool Shortcut::is_pressed_from_key_array()
|
|
|
|
{
|
|
|
|
if (accel) {
|
2012-07-18 08:42:02 +08:00
|
|
|
return accel->checkFromAllegroKeyArray();
|
2010-10-28 08:02:48 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-09 09:34:06 +08:00
|
|
|
static Shortcut* get_keyboard_shortcut_for_command(const char* command_name, Params* params)
|
2009-07-10 10:08:41 +08:00
|
|
|
{
|
2011-01-21 07:49:03 +08:00
|
|
|
Command* command = CommandsModule::instance()->getCommandByName(command_name);
|
2009-10-09 09:34:06 +08:00
|
|
|
if (!command)
|
|
|
|
return NULL;
|
2009-07-10 10:08:41 +08:00
|
|
|
|
|
|
|
for (std::vector<Shortcut*>::iterator
|
2012-01-06 06:45:03 +08:00
|
|
|
it = shortcuts->begin(); it != shortcuts->end(); ++it) {
|
2009-07-10 10:08:41 +08:00
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
|
|
|
if (shortcut->type == Shortcut_ExecuteCommand &&
|
2012-01-06 06:45:03 +08:00
|
|
|
shortcut->command == command &&
|
|
|
|
((!params && shortcut->params->empty()) ||
|
|
|
|
(params && *shortcut->params == *params))) {
|
2009-07-10 10:08:41 +08:00
|
|
|
return shortcut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-02 21:47:03 +08:00
|
|
|
static Shortcut* get_keyboard_shortcut_for_tool(tools::Tool* tool)
|
2009-07-10 10:08:41 +08:00
|
|
|
{
|
|
|
|
for (std::vector<Shortcut*>::iterator
|
2012-01-06 06:45:03 +08:00
|
|
|
it = shortcuts->begin(); it != shortcuts->end(); ++it) {
|
2009-07-10 10:08:41 +08:00
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
|
|
|
if (shortcut->type == Shortcut_ChangeTool &&
|
2012-01-06 06:45:03 +08:00
|
|
|
shortcut->tool == tool) {
|
2009-07-10 10:08:41 +08:00
|
|
|
return shortcut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-02 21:47:03 +08:00
|
|
|
static Shortcut* get_keyboard_shortcut_for_quicktool(tools::Tool* tool)
|
2010-10-28 08:02:48 +08:00
|
|
|
{
|
|
|
|
for (std::vector<Shortcut*>::iterator
|
2012-01-06 06:45:03 +08:00
|
|
|
it = shortcuts->begin(); it != shortcuts->end(); ++it) {
|
2010-10-28 08:02:48 +08:00
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
|
|
|
if (shortcut->type == Shortcut_EditorQuicktool &&
|
2012-01-06 06:45:03 +08:00
|
|
|
shortcut->tool == tool) {
|
2010-10-28 08:02:48 +08:00
|
|
|
return shortcut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-30 06:21:19 +08:00
|
|
|
static Shortcut* get_keyboard_shortcut_for_spriteeditor(const char* action_name)
|
|
|
|
{
|
|
|
|
for (std::vector<Shortcut*>::iterator
|
2012-01-06 06:45:03 +08:00
|
|
|
it = shortcuts->begin(); it != shortcuts->end(); ++it) {
|
2011-10-30 06:21:19 +08:00
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
|
|
|
if (shortcut->type == Shortcut_SpriteEditor &&
|
2012-01-06 06:45:03 +08:00
|
|
|
strcmp(shortcut->action, action_name) == 0) {
|
2011-10-30 06:21:19 +08:00
|
|
|
return shortcut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-01 08:09:46 +08:00
|
|
|
// Manager event handler.
|
2012-06-16 10:37:59 +08:00
|
|
|
bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2013-07-29 08:17:07 +08:00
|
|
|
switch (msg->type()) {
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kCloseAppMessage:
|
2012-02-03 07:01:54 +08:00
|
|
|
{
|
|
|
|
// Execute the "Exit" command.
|
|
|
|
Command* command = CommandsModule::instance()->getCommandByName(CommandId::Exit);
|
|
|
|
UIContext::instance()->executeCommand(command);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-03-20 18:31:19 +08:00
|
|
|
case kDropFilesMessage:
|
|
|
|
{
|
|
|
|
// If the main window is not the current foreground one. We
|
|
|
|
// discard the drop-files event.
|
|
|
|
if (getForegroundWindow() != App::instance()->getMainWindow())
|
|
|
|
break;
|
|
|
|
|
|
|
|
const DropFilesMessage::Files& files = static_cast<DropFilesMessage*>(msg)->files();
|
|
|
|
|
|
|
|
// Open all files
|
|
|
|
Command* cmd_open_file =
|
|
|
|
CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
|
|
|
|
Params params;
|
|
|
|
|
|
|
|
for (DropFilesMessage::Files::const_iterator
|
|
|
|
it = files.begin(); it != files.end(); ++it) {
|
|
|
|
params.set("filename", it->c_str());
|
|
|
|
UIContext::instance()->executeCommand(cmd_open_file, ¶ms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kQueueProcessingMessage:
|
2007-09-19 07:57:02 +08:00
|
|
|
gui_feedback();
|
|
|
|
break;
|
|
|
|
|
2013-04-05 08:53:29 +08:00
|
|
|
case kKeyDownMessage: {
|
2012-07-09 10:24:42 +08:00
|
|
|
Window* toplevel_window = getTopWindow();
|
2010-10-29 22:26:32 +08:00
|
|
|
|
|
|
|
// If there is a foreground window as top level...
|
2012-07-09 10:24:42 +08:00
|
|
|
if (toplevel_window &&
|
2012-07-10 00:20:58 +08:00
|
|
|
toplevel_window != App::instance()->getMainWindow() &&
|
2013-01-11 23:43:25 +08:00
|
|
|
toplevel_window->isForeground()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
// We just do not process keyboard shortcuts for menus and tools
|
|
|
|
break;
|
2010-10-29 22:26:32 +08:00
|
|
|
}
|
|
|
|
|
2009-07-10 10:08:41 +08:00
|
|
|
for (std::vector<Shortcut*>::iterator
|
2012-01-06 06:45:03 +08:00
|
|
|
it = shortcuts->begin(); it != shortcuts->end(); ++it) {
|
|
|
|
Shortcut* shortcut = *it;
|
|
|
|
|
|
|
|
if (shortcut->is_pressed(msg)) {
|
|
|
|
// Cancel menu-bar loops (to close any popup menu)
|
2012-07-10 00:20:58 +08:00
|
|
|
App::instance()->getMainWindow()->getMenuBar()->cancelMenuLoop();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
switch (shortcut->type) {
|
|
|
|
|
|
|
|
case Shortcut_ChangeTool: {
|
|
|
|
tools::Tool* current_tool = UIContext::instance()->getSettings()->getCurrentTool();
|
|
|
|
tools::Tool* select_this_tool = shortcut->tool;
|
|
|
|
tools::ToolBox* toolbox = App::instance()->getToolBox();
|
|
|
|
std::vector<tools::Tool*> possibles;
|
|
|
|
|
|
|
|
// Iterate over all tools
|
|
|
|
for (tools::ToolIterator it = toolbox->begin(); it != toolbox->end(); ++it) {
|
|
|
|
Shortcut* shortcut = get_keyboard_shortcut_for_tool(*it);
|
|
|
|
|
|
|
|
// Collect all tools with the pressed keyboard-shortcut
|
|
|
|
if (shortcut && shortcut->is_pressed(msg))
|
|
|
|
possibles.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (possibles.size() >= 2) {
|
|
|
|
bool done = false;
|
|
|
|
|
|
|
|
for (size_t i=0; i<possibles.size(); ++i) {
|
|
|
|
if (possibles[i] != current_tool &&
|
2012-07-10 00:20:58 +08:00
|
|
|
ToolBar::instance()->isToolVisible(possibles[i])) {
|
2012-01-06 06:45:03 +08:00
|
|
|
select_this_tool = possibles[i];
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!done) {
|
|
|
|
for (size_t i=0; i<possibles.size(); ++i) {
|
|
|
|
// If one of the possibilities is the current tool
|
|
|
|
if (possibles[i] == current_tool) {
|
|
|
|
// We select the next tool in the possibilities
|
|
|
|
select_this_tool = possibles[(i+1) % possibles.size()];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-10 00:20:58 +08:00
|
|
|
ToolBar::instance()->selectTool(select_this_tool);
|
2012-01-06 06:45:03 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Shortcut_ExecuteCommand: {
|
|
|
|
Command* command = shortcut->command;
|
|
|
|
|
2012-02-12 21:55:33 +08:00
|
|
|
// Commands are executed only when the main window is
|
|
|
|
// the current window running at foreground.
|
2012-07-18 08:42:02 +08:00
|
|
|
UI_FOREACH_WIDGET(getChildren(), it) {
|
|
|
|
Window* child = static_cast<Window*>(*it);
|
2012-02-12 21:55:33 +08:00
|
|
|
|
|
|
|
// There are a foreground window executing?
|
2013-01-11 23:43:25 +08:00
|
|
|
if (child->isForeground()) {
|
2012-02-12 21:55:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Is it the desktop and the top-window=
|
2013-01-11 23:43:25 +08:00
|
|
|
else if (child->isDesktop() && child == App::instance()->getMainWindow()) {
|
2012-02-12 21:55:33 +08:00
|
|
|
// OK, so we can execute the command represented
|
|
|
|
// by the pressed-key in the message...
|
|
|
|
UIContext::instance()->executeCommand(command, shortcut->params);
|
|
|
|
return true;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Shortcut_EditorQuicktool: {
|
|
|
|
// Do nothing, it is used in the editor through the
|
|
|
|
// get_selected_quicktool() function.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
break;
|
2010-10-29 22:26:32 +08:00
|
|
|
}
|
2008-01-04 07:22:04 +08:00
|
|
|
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
return Manager::onProcessMessage(msg);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2008-01-14 04:49:02 +08:00
|
|
|
|
2012-07-18 12:10:43 +08:00
|
|
|
std::string CustomizedGuiManager::loadLayout(Widget* widget)
|
|
|
|
{
|
|
|
|
if (widget->getRoot() == NULL)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
std::string rootId = widget->getRoot()->getId();
|
|
|
|
std::string widgetId = widget->getId();
|
|
|
|
|
|
|
|
return get_config_string(("layout:"+rootId).c_str(), widgetId.c_str(), "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CustomizedGuiManager::saveLayout(Widget* widget, const std::string& str)
|
|
|
|
{
|
|
|
|
if (widget->getRoot() == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string rootId = widget->getRoot()->getId();
|
|
|
|
std::string widgetId = widget->getId();
|
|
|
|
|
|
|
|
set_config_string(("layout:"+rootId).c_str(), widgetId.c_str(), str.c_str());
|
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|