mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-29 10:20:48 +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;
|
||||
base::SystemConsole systemConsole;
|
||||
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;
|
||||
|
||||
// Change the name of the memory dump file
|
||||
|
@ -233,7 +233,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
System* create_system() {
|
||||
System* create_system_impl() {
|
||||
return new Alleg4System();
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,9 @@
|
||||
|
||||
#include <Carbon/Carbon.h> // For VK codes
|
||||
|
||||
using namespace she;
|
||||
namespace she {
|
||||
|
||||
bool osx_is_key_pressed(KeyScancode scancode);
|
||||
|
||||
namespace {
|
||||
|
||||
@ -74,7 +76,7 @@ KeyModifiers get_modifiers_from_nsevent(NSEvent* event)
|
||||
if (nsFlags & NSControlKeyMask) modifiers |= kKeyCtrlModifier;
|
||||
if (nsFlags & NSAlternateKeyMask) modifiers |= kKeyAltModifier;
|
||||
if (nsFlags & NSCommandKeyMask) modifiers |= kKeyCmdModifier;
|
||||
if (she::instance()->isKeyPressed(kKeySpace)) modifiers |= kKeySpaceModifier;
|
||||
if (osx_is_key_pressed(kKeySpace)) modifiers |= kKeySpaceModifier;
|
||||
return (KeyModifiers)modifiers;
|
||||
}
|
||||
|
||||
@ -119,8 +121,6 @@ CFStringRef get_unicode_from_key_code(NSEvent* event,
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace she {
|
||||
|
||||
bool osx_is_key_pressed(KeyScancode scancode)
|
||||
{
|
||||
if (scancode >= 0 && scancode < kKeyScancodes)
|
||||
@ -139,6 +139,8 @@ int osx_get_unicode_from_scancode(KeyScancode scancode)
|
||||
|
||||
} // namespace she
|
||||
|
||||
using namespace she;
|
||||
|
||||
@implementation OSXView
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
namespace she {
|
||||
|
||||
System* create_system() {
|
||||
System* create_system_impl() {
|
||||
return new SkiaSystem();
|
||||
}
|
||||
|
||||
|
@ -12,12 +12,19 @@
|
||||
|
||||
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()
|
||||
{
|
||||
static System* sys = nullptr;
|
||||
if (!sys)
|
||||
sys = create_system();
|
||||
return sys;
|
||||
return g_system;
|
||||
}
|
||||
|
||||
} // namespace she
|
||||
|
@ -38,7 +38,7 @@ int main(int argc, char* argv[])
|
||||
#ifdef TEST_GUI
|
||||
{
|
||||
// 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::Manager uiManager;
|
||||
#endif
|
||||
|
@ -337,6 +337,9 @@ bool Accelerator::isPressed(KeyModifiers modifiers, KeyScancode scancode, int un
|
||||
bool Accelerator::isPressed() const
|
||||
{
|
||||
she::System* sys = she::instance();
|
||||
if (!sys)
|
||||
return false;
|
||||
|
||||
KeyModifiers pressedModifiers = sys->keyModifiers();
|
||||
|
||||
// Check if this shortcut is only
|
||||
@ -358,6 +361,9 @@ bool Accelerator::isPressed() const
|
||||
bool Accelerator::isLooselyPressed() const
|
||||
{
|
||||
she::System* sys = she::instance();
|
||||
if (!sys)
|
||||
return false;
|
||||
|
||||
KeyModifiers pressedModifiers = sys->keyModifiers();
|
||||
|
||||
if ((m_modifiers & pressedModifiers) != m_modifiers)
|
||||
|
Loading…
x
Reference in New Issue
Block a user