Skip to content

Commit

Permalink
Get hellotriangle demo working on Windows without EMSCRIPTEN
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkewley committed Jun 13, 2024
1 parent f2e70af commit fc34d27
Show file tree
Hide file tree
Showing 17 changed files with 409 additions and 390 deletions.
24 changes: 19 additions & 5 deletions src/OpenSimCreator/UI/MainUIScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,16 @@ class osc::MainUIScreen::Impl final :

// called when an event is pumped into this screen but isn't handled by
// either the global 2D UI context or the active tab
void onUnhandledEvent(SDL_Event const& e)
bool onUnhandledEvent(SDL_Event const& e)
{
bool handled = false;
if (e.type == SDL_KEYUP &&
e.key.keysym.mod & (KMOD_CTRL | KMOD_GUI) &&
e.key.keysym.scancode == SDL_SCANCODE_P)
{
// `Ctrl+P` or `Super+P`: "take a screenshot"
m_MaybeScreenshotRequest = App::upd().request_screenshot();
handled = true;
}
if ((e.type == SDL_KEYUP &&
e.key.keysym.mod & (KMOD_CTRL | KMOD_GUI) &&
Expand All @@ -107,6 +109,7 @@ class osc::MainUIScreen::Impl final :
--it; // previous
select_tab((*it)->id());
}
handled = true;
}
if ((e.type == SDL_KEYUP &&
e.key.keysym.mod & (KMOD_CTRL | KMOD_GUI) &&
Expand All @@ -123,6 +126,7 @@ class osc::MainUIScreen::Impl final :
++it; // next
select_tab((*it)->id());
}
handled = true;
}
if (e.type == SDL_KEYUP &&
((e.key.keysym.mod & (KMOD_CTRL | KMOD_GUI)) != 0) &&
Expand All @@ -131,7 +135,10 @@ class osc::MainUIScreen::Impl final :
m_ActiveTabID != m_Tabs.front()->id())
{
close_tab(m_ActiveTabID);
handled = true;
}

return handled;
}

UID addTab(std::unique_ptr<ITab> tab)
Expand Down Expand Up @@ -192,8 +199,9 @@ class osc::MainUIScreen::Impl final :
ui::context::shutdown();
}

void onEvent(SDL_Event const& e)
bool onEvent(SDL_Event const& e)
{
bool handled = false;
if (e.type == SDL_KEYUP or
e.type == SDL_MOUSEBUTTONUP or
e.type == SDL_MOUSEMOTION) {
Expand All @@ -210,6 +218,7 @@ class osc::MainUIScreen::Impl final :
// during `ITab::onDraw` (immediate-mode UI)

m_ShouldRequestRedraw = true;
handled = true;
}
else if (e.type == SDL_QUIT) {
// if it's an application-level QUIT request, then it should be pumped into each
Expand Down Expand Up @@ -253,6 +262,8 @@ class osc::MainUIScreen::Impl final :

App::upd().request_quit();
}

handled = true;
}
else if (ITab* active = getActiveTab()) {
// if there's an active tab, pump the event into the active tab and check
Expand All @@ -278,11 +289,14 @@ class osc::MainUIScreen::Impl final :

if (activeTabHandledEvent) {
m_ShouldRequestRedraw = true;
handled = true;
}
else {
onUnhandledEvent(e);
handled = onUnhandledEvent(e);
}
}

return handled;
}

void on_tick()
Expand Down Expand Up @@ -914,9 +928,9 @@ void osc::MainUIScreen::impl_on_unmount()
m_Impl->on_unmount();
}

void osc::MainUIScreen::impl_on_event(SDL_Event const& e)
bool osc::MainUIScreen::impl_on_event(SDL_Event const& e)
{
m_Impl->onEvent(e);
return m_Impl->onEvent(e);
}

void osc::MainUIScreen::impl_on_tick()
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSimCreator/UI/MainUIScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace osc
private:
void impl_on_mount() final;
void impl_on_unmount() final;
void impl_on_event(SDL_Event const&) final;
bool impl_on_event(SDL_Event const&) final;
void impl_on_tick() final;
void impl_on_draw() final;

Expand Down
22 changes: 11 additions & 11 deletions src/OpenSimThirdPartyPlugins/RegisterTypes_osimPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
using namespace OpenSim;
using namespace std;

static dllObjectInstantiator instantiator;
static dllObjectInstantiator instantiator;

//_____________________________________________________________________________
/**
* The purpose of this routine is to register all class types exported by
Expand All @@ -48,14 +48,14 @@ OSIMPLUGIN_API void RegisterTypes_osimPlugin()
Object::registerType( Smith2018ContactMesh() );
}

dllObjectInstantiator::dllObjectInstantiator()
{
registerDllClasses();
}
void dllObjectInstantiator::registerDllClasses()
{
RegisterTypes_osimPlugin();
}
dllObjectInstantiator::dllObjectInstantiator()
{
registerDllClasses();
}

void dllObjectInstantiator::registerDllClasses()
{
RegisterTypes_osimPlugin();
}

// NOLINTEND
18 changes: 9 additions & 9 deletions src/OpenSimThirdPartyPlugins/RegisterTypes_osimPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@

extern "C" {

OSIMPLUGIN_API void RegisterTypes_osimPlugin();
OSIMPLUGIN_API void RegisterTypes_osimPlugin();

}

/** @cond **/ // hide from Doxygen
class dllObjectInstantiator
{
public:
dllObjectInstantiator();
private:
void registerDllClasses();
};
/** @endcond **/
class dllObjectInstantiator
{
public:
dllObjectInstantiator();
private:
void registerDllClasses();
};
/** @endcond **/

#endif // _RegisterTypes_OsimPlugin_h_

Expand Down
Loading

0 comments on commit fc34d27

Please sign in to comment.