From a5898b131b677ef5e14ac64ab190272ecf1d37e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Wed, 14 Aug 2019 21:19:03 -0700 Subject: [PATCH] examples: Added documentation link. --- examples/common/entry/dialog.cpp | 24 ++++++++++++++++++++---- examples/common/entry/dialog.h | 15 +++++++++------ examples/common/entry/entry.cpp | 8 +++++++- examples/common/entry/entry.h | 14 +++++++++----- examples/common/example-glue.cpp | 11 +++++++++++ scripts/example-common.lua | 1 - scripts/genie.lua | 2 +- 7 files changed, 57 insertions(+), 18 deletions(-) diff --git a/examples/common/entry/dialog.cpp b/examples/common/entry/dialog.cpp index d5a790956..f2e2820be 100644 --- a/examples/common/entry/dialog.cpp +++ b/examples/common/entry/dialog.cpp @@ -12,9 +12,6 @@ #include "dialog.h" #if BX_PLATFORM_WINDOWS -extern "C" void* __stdcall GetModuleHandleA(const char* _moduleName); -extern "C" uint32_t __stdcall GetModuleFileNameA(void* _module, char* _outFilePath, uint32_t _size); - typedef uintptr_t (__stdcall *LPOFNHOOKPROC)(void*, uint32_t, uintptr_t, uint64_t); struct OPENFILENAMEA @@ -44,10 +41,29 @@ struct OPENFILENAMEA uint32_t flagsEx; }; -extern "C" bool __stdcall GetOpenFileNameA(OPENFILENAMEA* _ofn); +extern "C" bool __stdcall GetOpenFileNameA(OPENFILENAMEA* _ofn); +extern "C" void* __stdcall GetModuleHandleA(const char* _moduleName); +extern "C" uint32_t __stdcall GetModuleFileNameA(void* _module, char* _outFilePath, uint32_t _size); +extern "C" void* __stdcall ShellExecuteA(void* _hwnd, void* _operation, void* _file, void* _parameters, void* _directory, int32_t _showCmd); #endif // BX_PLATFORM_WINDOWS +void openUrl(const bx::StringView& _url) +{ +#if BX_PLATFORM_WINDOWS + ShellExecuteA(NULL, NULL, _url, NULL, NULL, false); +#else + char tmp[4096]; +# if BX_PLATFORM_OSX +# define OPEN "open" +# else +# define OPEN "xdg-open" +# endif // BX_PLATFORM_OSX + bx::snprintf(tmp, BX_COUNTOF(tmp), OPEN " %.*s", _url.getLength(), _url.getPtr() ); + system(tmp); +#endif // BX_PLATFORM_* +} + class Split { public: diff --git a/examples/common/entry/dialog.h b/examples/common/entry/dialog.h index 3b6182ca8..4a75951ac 100644 --- a/examples/common/entry/dialog.h +++ b/examples/common/entry/dialog.h @@ -14,17 +14,20 @@ struct FileSelectionDialogType { Open, Save, - + Count }; }; +/// bool openFileSelectionDialog( - bx::FilePath& _inOutFilePath - , FileSelectionDialogType::Enum _type - , const bx::StringView& _title - , const bx::StringView& _filter = "All Files | *" - ); + bx::FilePath& _inOutFilePath + , FileSelectionDialogType::Enum _type + , const bx::StringView& _title + , const bx::StringView& _filter = "All Files | *" + ); +/// +void openUrl(const bx::StringView& _url); #endif // DIALOG_H_HEADER_GUARD diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index 6dd9a19a2..98b1a4057 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -446,10 +446,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); return bx::kExitFailure; } - AppI::AppI(const char* _name, const char* _description) + AppI::AppI(const char* _name, const char* _description, const char* _url) { m_name = _name; m_description = _description; + m_url = _url; m_next = s_apps; s_apps = this; @@ -490,6 +491,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); return m_description; } + const char* AppI::getUrl() const + { + return m_url; + } + AppI* AppI::getNext() { return m_next; diff --git a/examples/common/entry/entry.h b/examples/common/entry/entry.h index 26c3c1cfc..e5c9a7fd0 100644 --- a/examples/common/entry/entry.h +++ b/examples/common/entry/entry.h @@ -24,15 +24,15 @@ extern "C" int _main_(int _argc, char** _argv); #endif // ENTRY_CONFIG_IMPLEMENT_MAIN #if ENTRY_CONFIG_IMPLEMENT_MAIN -#define ENTRY_IMPLEMENT_MAIN(_app, _name, _description) \ +#define ENTRY_IMPLEMENT_MAIN(_app, ...) \ int _main_(int _argc, char** _argv) \ { \ - _app app(_name, _description); \ + _app app(__VA_ARGS__); \ return entry::runApp(&app, _argc, _argv); \ } #else -#define ENTRY_IMPLEMENT_MAIN(_app, _name, _description) \ - _app s_ ## _app ## App(_name, _description) +#define ENTRY_IMPLEMENT_MAIN(_app, ...) \ + _app s_ ## _app ## App(__VA_ARGS__) #endif // ENTRY_CONFIG_IMPLEMENT_MAIN namespace entry @@ -282,7 +282,7 @@ namespace entry { public: /// - AppI(const char* _name, const char* _description); + AppI(const char* _name, const char* _description, const char* _url = "https://bkaradzic.github.io/bgfx/index.html"); /// virtual ~AppI() = 0; @@ -302,6 +302,9 @@ namespace entry /// const char* getDescription() const; + /// + const char* getUrl() const; + /// AppI* getNext(); @@ -310,6 +313,7 @@ namespace entry private: const char* m_name; const char* m_description; + const char* m_url; }; /// diff --git a/examples/common/example-glue.cpp b/examples/common/example-glue.cpp index 214b54fd7..dca750572 100644 --- a/examples/common/example-glue.cpp +++ b/examples/common/example-glue.cpp @@ -6,6 +6,7 @@ #include "imgui/imgui.h" #include "entry/entry.h" #include "entry/cmd.h" +#include "entry/dialog.h" #include #include #include @@ -138,6 +139,16 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) ImGui::Begin(temp); ImGui::TextWrapped("%s", _app->getDescription() ); + + bx::StringView url = _app->getUrl(); + if (!url.isEmpty() ) + { + if (ImGui::Button("Documentation") ) + { + openUrl(url); + } + } + ImGui::Separator(); if (NULL != _errorText) diff --git a/scripts/example-common.lua b/scripts/example-common.lua index 2a1a07302..66f5fad8e 100644 --- a/scripts/example-common.lua +++ b/scripts/example-common.lua @@ -33,7 +33,6 @@ project ("example-common") path.join(BGFX_DIR, "3rdparty/dear-imgui/**.cpp"), path.join(BGFX_DIR, "3rdparty/dear-imgui/**.h"), path.join(BGFX_DIR, "examples/common/**.cpp"), - path.join(BGFX_DIR, "examples/common/**.cpp"), path.join(BGFX_DIR, "examples/common/**.h"), } diff --git a/scripts/genie.lua b/scripts/genie.lua index 427be320a..516833df6 100644 --- a/scripts/genie.lua +++ b/scripts/genie.lua @@ -170,8 +170,8 @@ function exampleProjectDefaults() } links { - "example-common", "example-glue", + "example-common", "bgfx", "bimg_decode", "bimg",