2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2018-11-28 21:30:33 +08:00
|
|
|
// Copyright (C) 2018 Igara Studio S.A.
|
2018-02-21 21:39:30 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2007-09-19 07:57:02 +08:00
|
|
|
|
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"
|
2017-08-15 21:39:06 +08:00
|
|
|
#include "app/app_menus.h"
|
2016-11-15 06:44:29 +08:00
|
|
|
#include "app/commands/cmd_open_file.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/commands.h"
|
|
|
|
#include "app/commands/params.h"
|
|
|
|
#include "app/console.h"
|
2017-08-16 02:47:06 +08:00
|
|
|
#include "app/crash/data_recovery.h"
|
2018-07-07 22:54:44 +08:00
|
|
|
#include "app/doc.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ini_file.h"
|
2017-08-16 02:47:06 +08:00
|
|
|
#include "app/modules/editors.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/modules/gfx.h"
|
|
|
|
#include "app/modules/gui.h"
|
|
|
|
#include "app/modules/palettes.h"
|
2015-04-17 22:11:36 +08:00
|
|
|
#include "app/pref/preferences.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/tools/ink.h"
|
|
|
|
#include "app/tools/tool_box.h"
|
|
|
|
#include "app/ui/editor/editor.h"
|
2014-10-29 22:58:03 +08:00
|
|
|
#include "app/ui/keyboard_shortcuts.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/main_menu_bar.h"
|
|
|
|
#include "app/ui/main_menu_bar.h"
|
|
|
|
#include "app/ui/main_window.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"
|
2018-11-28 21:30:33 +08:00
|
|
|
#include "base/fs.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"
|
2018-11-28 21:30:33 +08:00
|
|
|
#include "base/string.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/sprite.h"
|
2018-08-09 23:58:43 +08:00
|
|
|
#include "os/display.h"
|
|
|
|
#include "os/error.h"
|
|
|
|
#include "os/surface.h"
|
|
|
|
#include "os/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 <list>
|
|
|
|
#include <vector>
|
|
|
|
|
2016-11-08 04:47:53 +08:00
|
|
|
#if defined(_DEBUG) && defined(ENABLE_DATA_RECOVERY)
|
|
|
|
#include "app/crash/data_recovery.h"
|
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2009-07-10 10:08:41 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
class CustomizedGuiManager : public Manager
|
2017-08-17 02:17:11 +08:00
|
|
|
, public LayoutIO {
|
2012-06-16 10:37:59 +08:00
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
bool onProcessMessage(Message* msg) override;
|
2017-08-17 02:17:11 +08:00
|
|
|
#if ENABLE_DEVMODE
|
|
|
|
bool onProcessDevModeKeyDown(KeyMessage* msg);
|
|
|
|
#endif
|
2017-08-15 21:39:06 +08:00
|
|
|
void onInitTheme(InitThemeEvent& ev) override;
|
2014-08-15 10:07:47 +08:00
|
|
|
LayoutIO* onGetLayoutIO() override { return this; }
|
2015-07-30 05:12:35 +08:00
|
|
|
void onNewDisplayConfiguration() override;
|
2012-07-18 12:10:43 +08:00
|
|
|
|
|
|
|
// LayoutIO implementation
|
2014-08-15 10:07:47 +08:00
|
|
|
std::string loadLayout(Widget* widget) override;
|
|
|
|
void saveLayout(Widget* widget, const std::string& str) override;
|
2012-06-16 10:37:59 +08:00
|
|
|
};
|
|
|
|
|
2018-08-09 23:58:43 +08:00
|
|
|
static os::Display* main_display = NULL;
|
2012-06-16 10:37:59 +08:00
|
|
|
static CustomizedGuiManager* manager = NULL;
|
2015-04-17 23:24:33 +08:00
|
|
|
static Theme* gui_theme = NULL;
|
2010-03-09 10:43:28 +08:00
|
|
|
|
2015-04-22 00:31:24 +08:00
|
|
|
static ui::Timer* defered_invalid_timer = nullptr;
|
|
|
|
static gfx::Region defered_invalid_region;
|
|
|
|
|
2011-04-02 22:45:43 +08:00
|
|
|
// Load & save graphics configuration
|
2015-12-12 06:40:18 +08:00
|
|
|
static void load_gui_config(int& w, int& h, bool& maximized,
|
|
|
|
std::string& windowLayout);
|
2008-10-01 09:27:51 +08:00
|
|
|
static void save_gui_config();
|
2007-09-20 08:32:35 +08:00
|
|
|
|
2015-10-07 04:04:03 +08:00
|
|
|
static bool create_main_display(bool gpuAccel,
|
|
|
|
bool& maximized,
|
|
|
|
std::string& lastError)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2014-08-20 19:27:11 +08:00
|
|
|
int w, h;
|
2015-12-12 06:40:18 +08:00
|
|
|
std::string windowLayout;
|
|
|
|
load_gui_config(w, h, maximized, windowLayout);
|
2007-11-29 01:50:16 +08:00
|
|
|
|
2016-02-24 05:08:25 +08:00
|
|
|
// Scale is equal to 0 when it's the first time the program is
|
|
|
|
// executed.
|
|
|
|
int scale = Preferences::instance().general.screenScale();
|
|
|
|
|
2018-08-09 23:58:43 +08:00
|
|
|
os::instance()->setGpuAcceleration(gpuAccel);
|
2015-10-07 04:04:03 +08:00
|
|
|
|
2012-08-06 08:16:16 +08:00
|
|
|
try {
|
2016-02-24 05:08:25 +08:00
|
|
|
if (w > 0 && h > 0) {
|
2018-08-09 23:58:43 +08:00
|
|
|
main_display = os::instance()->createDisplay(
|
2016-02-24 05:08:25 +08:00
|
|
|
w, h, (scale == 0 ? 2: MID(1, scale, 4)));
|
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2018-08-09 23:58:43 +08:00
|
|
|
catch (const os::DisplayCreationException& e) {
|
2015-10-01 21:54:47 +08:00
|
|
|
lastError = e.what();
|
2014-08-20 19:27:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!main_display) {
|
|
|
|
for (int c=0; try_resolutions[c].width; ++c) {
|
2012-08-06 08:16:16 +08:00
|
|
|
try {
|
2012-08-11 10:14:54 +08:00
|
|
|
main_display =
|
2018-08-09 23:58:43 +08:00
|
|
|
os::instance()->createDisplay(
|
2016-02-24 05:08:25 +08:00
|
|
|
try_resolutions[c].width,
|
|
|
|
try_resolutions[c].height,
|
|
|
|
(scale == 0 ? try_resolutions[c].scale: scale));
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
2007-11-29 01:50:16 +08:00
|
|
|
}
|
2018-08-09 23:58:43 +08:00
|
|
|
catch (const os::DisplayCreationException& e) {
|
2015-10-01 21:54:47 +08:00
|
|
|
lastError = e.what();
|
2012-08-06 08:16:16 +08:00
|
|
|
}
|
2007-11-29 01:50:16 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
2010-09-19 10:33:32 +08:00
|
|
|
|
2016-03-01 09:21:59 +08:00
|
|
|
if (main_display) {
|
2016-02-24 05:08:25 +08:00
|
|
|
// Change the scale value only in the first run (this will be
|
|
|
|
// saved when the program is closed).
|
|
|
|
if (scale == 0)
|
|
|
|
Preferences::instance().general.screenScale(main_display->scale());
|
|
|
|
|
2016-03-01 09:21:59 +08:00
|
|
|
if (!windowLayout.empty()) {
|
|
|
|
main_display->setLayout(windowLayout);
|
|
|
|
if (main_display->isMinimized())
|
|
|
|
main_display->maximize();
|
|
|
|
}
|
2015-12-12 06:46:41 +08:00
|
|
|
}
|
2015-12-12 06:40:18 +08:00
|
|
|
|
2015-10-07 04:04:03 +08:00
|
|
|
return (main_display != nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initializes GUI.
|
|
|
|
int init_module_gui()
|
|
|
|
{
|
2017-08-15 21:39:06 +08:00
|
|
|
auto& pref = Preferences::instance();
|
2015-10-07 04:04:03 +08:00
|
|
|
bool maximized = false;
|
|
|
|
std::string lastError = "Unknown error";
|
2017-08-15 21:39:06 +08:00
|
|
|
bool gpuAccel = pref.general.gpuAcceleration();
|
2015-10-07 04:04:03 +08:00
|
|
|
|
|
|
|
if (!create_main_display(gpuAccel, maximized, lastError)) {
|
|
|
|
// If we've created the display with hardware acceleration,
|
|
|
|
// now we try to do it without hardware acceleration.
|
|
|
|
if (gpuAccel &&
|
2018-08-09 23:58:43 +08:00
|
|
|
(int(os::instance()->capabilities()) &
|
|
|
|
int(os::Capabilities::GpuAccelerationSwitch)) == int(os::Capabilities::GpuAccelerationSwitch)) {
|
2015-10-07 04:04:03 +08:00
|
|
|
if (create_main_display(false, maximized, lastError)) {
|
|
|
|
// Disable hardware acceleration
|
2017-08-15 21:39:06 +08:00
|
|
|
pref.general.gpuAcceleration(false);
|
2015-10-07 04:04:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
if (!main_display) {
|
2018-08-09 23:58:43 +08:00
|
|
|
os::error_message(
|
2015-10-07 04:04:03 +08:00
|
|
|
("Unable to create a user-interface display.\nDetails: "+lastError+"\n").c_str());
|
2012-08-06 08:16:16 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2007-09-19 07:57:02 +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);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2011-01-22 04:50:04 +08:00
|
|
|
// Setup the GUI theme for all widgets
|
2017-04-15 19:13:20 +08:00
|
|
|
gui_theme = new SkinTheme;
|
2017-08-15 21:39:06 +08:00
|
|
|
ui::set_theme(gui_theme, pref.general.uiScale());
|
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
|
|
|
// 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();
|
|
|
|
|
2015-04-22 00:31:24 +08:00
|
|
|
delete defered_invalid_timer;
|
2012-04-16 02:21:24 +08:00
|
|
|
delete manager;
|
2010-10-27 06:23:04 +08:00
|
|
|
|
|
|
|
// Now we can destroy theme
|
2017-08-15 21:39:06 +08:00
|
|
|
ui::set_theme(nullptr, ui::guiscale());
|
2015-04-17 23:24:33 +08:00
|
|
|
delete gui_theme;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2012-08-11 10:14:54 +08:00
|
|
|
main_display->dispose();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2015-12-12 06:40:18 +08:00
|
|
|
static void load_gui_config(int& w, int& h, bool& maximized,
|
|
|
|
std::string& windowLayout)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2018-08-09 23:58:43 +08:00
|
|
|
gfx::Size defSize = os::instance()->defaultNewDisplaySize();
|
2015-12-29 05:02:07 +08:00
|
|
|
|
|
|
|
w = get_config_int("GfxMode", "Width", defSize.w);
|
|
|
|
h = get_config_int("GfxMode", "Height", defSize.h);
|
2009-11-22 22:39:52 +08:00
|
|
|
maximized = get_config_bool("GfxMode", "Maximized", false);
|
2015-12-12 06:40:18 +08:00
|
|
|
windowLayout = get_config_string("GfxMode", "WindowLayout", "");
|
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
|
|
|
{
|
2018-08-09 23:58:43 +08:00
|
|
|
os::Display* display = manager->getDisplay();
|
2012-08-06 08:16:16 +08:00
|
|
|
if (display) {
|
|
|
|
set_config_bool("GfxMode", "Maximized", display->isMaximized());
|
|
|
|
set_config_int("GfxMode", "Width", display->originalWidth());
|
|
|
|
set_config_int("GfxMode", "Height", display->originalHeight());
|
2015-12-12 06:40:18 +08:00
|
|
|
|
|
|
|
std::string windowLayout = display->getLayout();
|
|
|
|
if (!windowLayout.empty())
|
|
|
|
set_config_string("GfxMode", "WindowLayout", windowLayout.c_str());
|
2010-03-29 03:18:49 +08:00
|
|
|
}
|
2007-11-25 02:23:53 +08:00
|
|
|
}
|
|
|
|
|
2018-07-07 22:54:44 +08:00
|
|
|
void update_screen_for_document(const Doc* 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.
|
2015-04-17 23:24:33 +08:00
|
|
|
if (manager)
|
|
|
|
manager->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 {
|
2018-07-07 22:54:44 +08:00
|
|
|
const_cast<Doc*>(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
Rect orig_pos = window->bounds();
|
- 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
|
|
|
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
|
|
|
|
2014-09-01 01:17:49 +08:00
|
|
|
pos.w = MID(orig_pos.w, pos.w, ui::display_w());
|
|
|
|
pos.h = MID(orig_pos.h, pos.h, ui::display_h());
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2014-09-01 01:17:49 +08:00
|
|
|
pos.setOrigin(Point(MID(0, pos.x, ui::display_w()-pos.w),
|
|
|
|
MID(0, pos.y, ui::display_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
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
set_config_rect(section, "WindowPos", window->bounds());
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:39:06 +08:00
|
|
|
// TODO Replace this with new theme styles
|
2014-01-26 19:39:33 +08:00
|
|
|
Widget* setup_mini_font(Widget* widget)
|
2011-03-30 08:07:37 +08:00
|
|
|
{
|
2015-05-06 06:14:33 +08:00
|
|
|
SkinPropertyPtr skinProp = get_skin_property(widget);
|
|
|
|
skinProp->setMiniFont();
|
2014-01-26 19:39:33 +08:00
|
|
|
return widget;
|
2011-03-30 08:07:37 +08:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:39:06 +08:00
|
|
|
// TODO Replace this with new theme styles
|
2014-01-26 19:39:33 +08:00
|
|
|
Widget* setup_mini_look(Widget* widget)
|
2010-03-22 10:18:30 +08:00
|
|
|
{
|
2013-12-05 12:19:46 +08:00
|
|
|
SkinPropertyPtr skinProp = get_skin_property(widget);
|
2017-02-14 05:34:23 +08:00
|
|
|
skinProp->setLook(MiniLook);
|
2014-01-26 19:39:33 +08:00
|
|
|
return widget;
|
2010-03-22 10:18:30 +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
|
|
|
|
2015-04-22 00:31:24 +08:00
|
|
|
void defer_invalid_rect(const gfx::Rect& rc)
|
|
|
|
{
|
|
|
|
if (!defered_invalid_timer)
|
|
|
|
defered_invalid_timer = new ui::Timer(250, manager);
|
|
|
|
|
|
|
|
defered_invalid_timer->stop();
|
|
|
|
defered_invalid_timer->start();
|
|
|
|
defered_invalid_region.createUnion(defered_invalid_region, gfx::Region(rc));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-07-31 03:15:21 +08:00
|
|
|
case kCloseDisplayMessage:
|
2012-02-03 07:01:54 +08:00
|
|
|
{
|
|
|
|
// Execute the "Exit" command.
|
2017-12-02 02:10:21 +08:00
|
|
|
Command* command = Commands::instance()->byId(CommandId::Exit());
|
2012-02-03 07:01:54 +08:00
|
|
|
UIContext::instance()->executeCommand(command);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-03-20 18:31:19 +08:00
|
|
|
case kDropFilesMessage:
|
2018-11-28 21:30:33 +08:00
|
|
|
// Files are processed only when the main window is the current
|
|
|
|
// window running.
|
|
|
|
//
|
|
|
|
// TODO could we send the files to each dialog?
|
|
|
|
if (getForegroundWindow() == App::instance()->mainWindow()) {
|
2018-02-21 21:39:30 +08:00
|
|
|
base::paths files = static_cast<DropFilesMessage*>(msg)->files();
|
2014-12-01 08:06:29 +08:00
|
|
|
UIContext* ctx = UIContext::instance();
|
|
|
|
|
2016-11-15 06:44:29 +08:00
|
|
|
while (!files.empty()) {
|
|
|
|
auto fn = files.front();
|
|
|
|
files.erase(files.begin());
|
|
|
|
|
2014-12-01 08:06:29 +08:00
|
|
|
// If the document is already open, select it.
|
2018-07-07 22:54:44 +08:00
|
|
|
Doc* doc = ctx->documents().getByFileName(fn);
|
2014-12-01 08:06:29 +08:00
|
|
|
if (doc) {
|
2018-07-15 10:24:49 +08:00
|
|
|
DocView* docView = ctx->getFirstDocView(doc);
|
2014-12-01 08:06:29 +08:00
|
|
|
if (docView)
|
|
|
|
ctx->setActiveView(docView);
|
|
|
|
else {
|
2018-07-15 10:24:49 +08:00
|
|
|
ASSERT(false); // Must be some DocView available
|
2014-12-01 08:06:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Load the file
|
|
|
|
else {
|
2018-11-28 21:30:33 +08:00
|
|
|
// Depending on the file type we will want to do different things:
|
|
|
|
std::string extension = base::string_to_lower(
|
|
|
|
base::get_file_extension(fn));
|
|
|
|
|
|
|
|
// Install the extension
|
|
|
|
if (extension == "aseprite-extension") {
|
|
|
|
Command* cmd = Commands::instance()->byId(CommandId::Options());
|
|
|
|
Params params;
|
|
|
|
params.set("installExtension", fn.c_str());
|
|
|
|
ctx->executeCommand(cmd, params);
|
|
|
|
}
|
|
|
|
// Other extensions will be handled as an image/sprite
|
|
|
|
else {
|
|
|
|
OpenFileCommand cmd;
|
|
|
|
Params params;
|
|
|
|
params.set("filename", fn.c_str());
|
|
|
|
params.set("repeat_checkbox", "true");
|
|
|
|
ctx->executeCommand(&cmd, params);
|
|
|
|
|
|
|
|
// Remove all used file names from the "dropped files"
|
|
|
|
for (const auto& usedFn : cmd.usedFiles()) {
|
|
|
|
auto it = std::find(files.begin(), files.end(), usedFn);
|
|
|
|
if (it != files.end())
|
|
|
|
files.erase(it);
|
|
|
|
}
|
2016-11-15 06:44:29 +08:00
|
|
|
}
|
2014-12-01 08:06:29 +08:00
|
|
|
}
|
2014-03-20 18:31:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-07-24 02:15:04 +08:00
|
|
|
case kKeyDownMessage: {
|
2017-08-16 02:47:06 +08:00
|
|
|
#if ENABLE_DEVMODE
|
2017-08-17 02:17:11 +08:00
|
|
|
if (onProcessDevModeKeyDown(static_cast<KeyMessage*>(msg)))
|
|
|
|
return true;
|
|
|
|
#endif // ENABLE_DEVMODE
|
2015-04-08 01:41:40 +08:00
|
|
|
|
2015-05-04 22:25:42 +08:00
|
|
|
// Call base impl to check if there is a foreground window as
|
|
|
|
// top level that needs keys. (In this way we just do not
|
|
|
|
// process keyboard shortcuts for menus and tools).
|
|
|
|
if (Manager::onProcessMessage(msg))
|
|
|
|
return true;
|
2010-10-29 22:26:32 +08:00
|
|
|
|
2018-07-24 02:15:04 +08:00
|
|
|
KeyboardShortcuts* keys = KeyboardShortcuts::instance();
|
|
|
|
for (const KeyPtr& key : *keys) {
|
|
|
|
if (key->isPressed(msg, *keys)) {
|
2012-01-06 06:45:03 +08:00
|
|
|
// Cancel menu-bar loops (to close any popup menu)
|
2016-04-23 00:19:06 +08:00
|
|
|
App::instance()->mainWindow()->getMenuBar()->cancelMenuLoop();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-10-29 22:58:03 +08:00
|
|
|
switch (key->type()) {
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-10-29 22:58:03 +08:00
|
|
|
case KeyType::Tool: {
|
2015-05-19 03:53:25 +08:00
|
|
|
tools::Tool* current_tool = App::instance()->activeTool();
|
2014-10-29 22:58:03 +08:00
|
|
|
tools::Tool* select_this_tool = key->tool();
|
2016-04-23 00:19:06 +08:00
|
|
|
tools::ToolBox* toolbox = App::instance()->toolBox();
|
2012-01-06 06:45:03 +08:00
|
|
|
std::vector<tools::Tool*> possibles;
|
|
|
|
|
2014-10-29 22:58:03 +08:00
|
|
|
// Collect all tools with the pressed keyboard-shortcut
|
|
|
|
for (tools::Tool* tool : *toolbox) {
|
2018-07-18 10:53:08 +08:00
|
|
|
const KeyPtr key = KeyboardShortcuts::instance()->tool(tool);
|
2018-07-24 02:15:04 +08:00
|
|
|
if (key && key->isPressed(msg, *keys))
|
2014-10-29 22:58:03 +08:00
|
|
|
possibles.push_back(tool);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-29 22:58:03 +08:00
|
|
|
case KeyType::Command: {
|
|
|
|
Command* command = key->command();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-02-12 21:55:33 +08:00
|
|
|
// Commands are executed only when the main window is
|
2017-09-02 00:32:23 +08:00
|
|
|
// the current window running.
|
|
|
|
if (getForegroundWindow() == App::instance()->mainWindow()) {
|
|
|
|
// OK, so we can execute the command represented
|
|
|
|
// by the pressed-key in the message...
|
|
|
|
UIContext::instance()->executeCommand(
|
|
|
|
command, key->params());
|
|
|
|
return true;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-10-29 22:58:03 +08:00
|
|
|
case KeyType::Quicktool: {
|
2012-01-06 06:45:03 +08:00
|
|
|
// Do nothing, it is used in the editor through the
|
2014-10-29 22:58:03 +08:00
|
|
|
// KeyboardShortcuts::getCurrentQuicktool() function.
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
break;
|
2018-07-24 02:15:04 +08:00
|
|
|
}
|
2008-01-04 07:22:04 +08:00
|
|
|
|
2015-04-22 00:31:24 +08:00
|
|
|
case kTimerMessage:
|
|
|
|
if (static_cast<TimerMessage*>(msg)->timer() == defered_invalid_timer) {
|
|
|
|
invalidateDisplayRegion(defered_invalid_region);
|
|
|
|
defered_invalid_region.clear();
|
|
|
|
defered_invalid_timer->stop();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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
|
|
|
|
2017-08-17 02:17:11 +08:00
|
|
|
#if ENABLE_DEVMODE
|
|
|
|
bool CustomizedGuiManager::onProcessDevModeKeyDown(KeyMessage* msg)
|
|
|
|
{
|
|
|
|
// Ctrl+Shift+Q generates a crash (useful to test the anticrash feature)
|
|
|
|
if (msg->ctrlPressed() &&
|
|
|
|
msg->shiftPressed() &&
|
|
|
|
msg->scancode() == kKeyQ) {
|
|
|
|
int* p = nullptr;
|
|
|
|
*p = 0; // *Crash*
|
|
|
|
return true; // This line should not be executed anyway
|
|
|
|
}
|
|
|
|
|
|
|
|
// F1 switches screen/UI scaling
|
2018-06-23 02:41:22 +08:00
|
|
|
if (msg->ctrlPressed() &&
|
|
|
|
msg->scancode() == kKeyF1) {
|
2017-08-23 01:54:08 +08:00
|
|
|
try {
|
2018-08-09 23:58:43 +08:00
|
|
|
os::Display* display = getDisplay();
|
2017-08-23 01:54:08 +08:00
|
|
|
int screenScale = display->scale();
|
|
|
|
int uiScale = ui::guiscale();
|
|
|
|
|
|
|
|
if (msg->shiftPressed()) {
|
|
|
|
if (screenScale == 2 && uiScale == 1) {
|
|
|
|
screenScale = 1;
|
|
|
|
uiScale = 1;
|
|
|
|
}
|
|
|
|
else if (screenScale == 1 && uiScale == 1) {
|
|
|
|
screenScale = 1;
|
|
|
|
uiScale = 2;
|
|
|
|
}
|
|
|
|
else if (screenScale == 1 && uiScale == 2) {
|
|
|
|
screenScale = 2;
|
|
|
|
uiScale = 1;
|
|
|
|
}
|
2017-08-17 02:17:11 +08:00
|
|
|
}
|
2017-08-23 01:54:08 +08:00
|
|
|
else {
|
|
|
|
if (screenScale == 2 && uiScale == 1) {
|
|
|
|
screenScale = 1;
|
|
|
|
uiScale = 2;
|
|
|
|
}
|
|
|
|
else if (screenScale == 1 && uiScale == 2) {
|
|
|
|
screenScale = 1;
|
|
|
|
uiScale = 1;
|
|
|
|
}
|
|
|
|
else if (screenScale == 1 && uiScale == 1) {
|
|
|
|
screenScale = 2;
|
|
|
|
uiScale = 1;
|
|
|
|
}
|
2017-08-17 02:17:11 +08:00
|
|
|
}
|
2017-08-23 01:54:08 +08:00
|
|
|
|
|
|
|
if (uiScale != ui::guiscale()) {
|
|
|
|
ui::set_theme(ui::get_theme(), uiScale);
|
2017-08-17 02:17:11 +08:00
|
|
|
}
|
2017-08-23 01:54:08 +08:00
|
|
|
if (screenScale != display->scale()) {
|
|
|
|
display->setScale(screenScale);
|
|
|
|
setDisplay(display);
|
2017-08-17 02:17:11 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-23 01:54:08 +08:00
|
|
|
catch (const std::exception& ex) {
|
|
|
|
Console::showException(ex);
|
2017-08-17 02:17:11 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_DATA_RECOVERY
|
|
|
|
// Ctrl+Shift+R recover active sprite from the backup store
|
|
|
|
if (msg->ctrlPressed() &&
|
|
|
|
msg->shiftPressed() &&
|
|
|
|
msg->scancode() == kKeyR &&
|
|
|
|
App::instance()->dataRecovery() &&
|
|
|
|
App::instance()->dataRecovery()->activeSession() &&
|
|
|
|
current_editor &&
|
|
|
|
current_editor->document()) {
|
|
|
|
App::instance()
|
|
|
|
->dataRecovery()
|
|
|
|
->activeSession()
|
|
|
|
->restoreBackupById(current_editor->document()->id());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // ENABLE_DATA_RECOVERY
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif // ENABLE_DEVMODE
|
|
|
|
|
2017-08-15 21:39:06 +08:00
|
|
|
void CustomizedGuiManager::onInitTheme(InitThemeEvent& ev)
|
|
|
|
{
|
|
|
|
Manager::onInitTheme(ev);
|
|
|
|
|
|
|
|
// Update the theme on all menus
|
|
|
|
AppMenus::instance()->initTheme();
|
|
|
|
}
|
|
|
|
|
2015-07-30 05:12:35 +08:00
|
|
|
void CustomizedGuiManager::onNewDisplayConfiguration()
|
|
|
|
{
|
|
|
|
Manager::onNewDisplayConfiguration();
|
|
|
|
save_gui_config();
|
|
|
|
}
|
|
|
|
|
2012-07-18 12:10:43 +08:00
|
|
|
std::string CustomizedGuiManager::loadLayout(Widget* widget)
|
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
if (widget->window() == nullptr)
|
2012-07-18 12:10:43 +08:00
|
|
|
return "";
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
std::string windowId = widget->window()->id();
|
|
|
|
std::string widgetId = widget->id();
|
2012-07-18 12:10:43 +08:00
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
return get_config_string(("layout:"+windowId).c_str(), widgetId.c_str(), "");
|
2012-07-18 12:10:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CustomizedGuiManager::saveLayout(Widget* widget, const std::string& str)
|
|
|
|
{
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
if (widget->window() == NULL)
|
2012-07-18 12:10:43 +08:00
|
|
|
return;
|
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
std::string windowId = widget->window()->id();
|
|
|
|
std::string widgetId = widget->id();
|
2012-07-18 12:10:43 +08:00
|
|
|
|
Refactor several "getNoun()" getters to "noun()"
This is a work-in-progress to create a consistent API and finally
separate the whole Aseprite base/gfx/ui libs into a reusable C++ library.
Classes:
app::IFileItem, app::AppMenuItem, app::skin::SkinPart,
gfx::Rect, gfx::Border, she::FileDialog,
ui::IButtonIcon, ui::Graphics, ui::Overlay, ui::Widget,
ui::ScrollableViewDelegate, and UI events
2015-12-05 01:39:04 +08:00
|
|
|
set_config_string(("layout:"+windowId).c_str(),
|
|
|
|
widgetId.c_str(),
|
|
|
|
str.c_str());
|
2012-07-18 12:10:43 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
} // namespace app
|