mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-18 11:42:47 +00:00
Avoid creating a System instance in she::instance()
This is necessary for tests that don't need a System but call the instance() function anyway.
This commit is contained in:
parent
5dc8f9c8a0
commit
02b9a953ef
@ -66,7 +66,7 @@ int app_main(int argc, char* argv[])
|
|||||||
MemLeak memleak;
|
MemLeak memleak;
|
||||||
base::SystemConsole systemConsole;
|
base::SystemConsole systemConsole;
|
||||||
app::AppOptions options(argc, const_cast<const char**>(argv));
|
app::AppOptions options(argc, const_cast<const char**>(argv));
|
||||||
she::ScopedHandle<she::System> system(she::instance());
|
she::ScopedHandle<she::System> system(she::create_system());
|
||||||
app::App app;
|
app::App app;
|
||||||
|
|
||||||
// Change the name of the memory dump file
|
// Change the name of the memory dump file
|
||||||
|
@ -233,7 +233,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
System* create_system() {
|
System* create_system_impl() {
|
||||||
return new Alleg4System();
|
return new Alleg4System();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,9 @@
|
|||||||
|
|
||||||
#include <Carbon/Carbon.h> // For VK codes
|
#include <Carbon/Carbon.h> // For VK codes
|
||||||
|
|
||||||
using namespace she;
|
namespace she {
|
||||||
|
|
||||||
|
bool osx_is_key_pressed(KeyScancode scancode);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -74,7 +76,7 @@ KeyModifiers get_modifiers_from_nsevent(NSEvent* event)
|
|||||||
if (nsFlags & NSControlKeyMask) modifiers |= kKeyCtrlModifier;
|
if (nsFlags & NSControlKeyMask) modifiers |= kKeyCtrlModifier;
|
||||||
if (nsFlags & NSAlternateKeyMask) modifiers |= kKeyAltModifier;
|
if (nsFlags & NSAlternateKeyMask) modifiers |= kKeyAltModifier;
|
||||||
if (nsFlags & NSCommandKeyMask) modifiers |= kKeyCmdModifier;
|
if (nsFlags & NSCommandKeyMask) modifiers |= kKeyCmdModifier;
|
||||||
if (she::instance()->isKeyPressed(kKeySpace)) modifiers |= kKeySpaceModifier;
|
if (osx_is_key_pressed(kKeySpace)) modifiers |= kKeySpaceModifier;
|
||||||
return (KeyModifiers)modifiers;
|
return (KeyModifiers)modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +121,6 @@ CFStringRef get_unicode_from_key_code(NSEvent* event,
|
|||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
namespace she {
|
|
||||||
|
|
||||||
bool osx_is_key_pressed(KeyScancode scancode)
|
bool osx_is_key_pressed(KeyScancode scancode)
|
||||||
{
|
{
|
||||||
if (scancode >= 0 && scancode < kKeyScancodes)
|
if (scancode >= 0 && scancode < kKeyScancodes)
|
||||||
@ -139,6 +139,8 @@ int osx_get_unicode_from_scancode(KeyScancode scancode)
|
|||||||
|
|
||||||
} // namespace she
|
} // namespace she
|
||||||
|
|
||||||
|
using namespace she;
|
||||||
|
|
||||||
@implementation OSXView
|
@implementation OSXView
|
||||||
|
|
||||||
- (id)initWithFrame:(NSRect)frameRect
|
- (id)initWithFrame:(NSRect)frameRect
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
namespace she {
|
namespace she {
|
||||||
|
|
||||||
System* create_system() {
|
System* create_system_impl() {
|
||||||
return new SkiaSystem();
|
return new SkiaSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,12 +12,19 @@
|
|||||||
|
|
||||||
namespace she {
|
namespace she {
|
||||||
|
|
||||||
|
static System* g_system = nullptr;
|
||||||
|
|
||||||
|
System* create_system_impl(); // Defined on each back-end
|
||||||
|
|
||||||
|
System* create_system()
|
||||||
|
{
|
||||||
|
ASSERT(!g_system);
|
||||||
|
return g_system = create_system_impl();
|
||||||
|
}
|
||||||
|
|
||||||
System* instance()
|
System* instance()
|
||||||
{
|
{
|
||||||
static System* sys = nullptr;
|
return g_system;
|
||||||
if (!sys)
|
|
||||||
sys = create_system();
|
|
||||||
return sys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace she
|
} // namespace she
|
||||||
|
@ -38,7 +38,7 @@ int main(int argc, char* argv[])
|
|||||||
#ifdef TEST_GUI
|
#ifdef TEST_GUI
|
||||||
{
|
{
|
||||||
// Do not create a she::System, as we don't need it for testing purposes.
|
// Do not create a she::System, as we don't need it for testing purposes.
|
||||||
//she::ScopedHandle<she::System> system(she::instance());
|
//she::ScopedHandle<she::System> system(she::create_system());
|
||||||
ui::UISystem uiSystem;
|
ui::UISystem uiSystem;
|
||||||
ui::Manager uiManager;
|
ui::Manager uiManager;
|
||||||
#endif
|
#endif
|
||||||
|
@ -337,6 +337,9 @@ bool Accelerator::isPressed(KeyModifiers modifiers, KeyScancode scancode, int un
|
|||||||
bool Accelerator::isPressed() const
|
bool Accelerator::isPressed() const
|
||||||
{
|
{
|
||||||
she::System* sys = she::instance();
|
she::System* sys = she::instance();
|
||||||
|
if (!sys)
|
||||||
|
return false;
|
||||||
|
|
||||||
KeyModifiers pressedModifiers = sys->keyModifiers();
|
KeyModifiers pressedModifiers = sys->keyModifiers();
|
||||||
|
|
||||||
// Check if this shortcut is only
|
// Check if this shortcut is only
|
||||||
@ -358,6 +361,9 @@ bool Accelerator::isPressed() const
|
|||||||
bool Accelerator::isLooselyPressed() const
|
bool Accelerator::isLooselyPressed() const
|
||||||
{
|
{
|
||||||
she::System* sys = she::instance();
|
she::System* sys = she::instance();
|
||||||
|
if (!sys)
|
||||||
|
return false;
|
||||||
|
|
||||||
KeyModifiers pressedModifiers = sys->keyModifiers();
|
KeyModifiers pressedModifiers = sys->keyModifiers();
|
||||||
|
|
||||||
if ((m_modifiers & pressedModifiers) != m_modifiers)
|
if ((m_modifiers & pressedModifiers) != m_modifiers)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user