| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- /*
- * Copyright 2011-2023 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
- */
- #ifndef ENTRY_H_HEADER_GUARD
- #define ENTRY_H_HEADER_GUARD
- #include "dbg.h"
- #include <bgfx/bgfx.h>
- #include <bx/bx.h>
- #include <bx/filepath.h>
- #include <bx/string.h>
- namespace bx { struct FileReaderI; struct FileWriterI; struct AllocatorI; }
- extern "C" int _main_(int _argc, char** _argv);
- #define ENTRY_WINDOW_FLAG_NONE UINT32_C(0x00000000)
- #define ENTRY_WINDOW_FLAG_ASPECT_RATIO UINT32_C(0x00000001)
- #define ENTRY_WINDOW_FLAG_FRAME UINT32_C(0x00000002)
- #ifndef ENTRY_CONFIG_IMPLEMENT_MAIN
- # define ENTRY_CONFIG_IMPLEMENT_MAIN 0
- #endif // ENTRY_CONFIG_IMPLEMENT_MAIN
- #if ENTRY_CONFIG_IMPLEMENT_MAIN
- #define ENTRY_IMPLEMENT_MAIN(_app, ...) \
- int _main_(int _argc, char** _argv) \
- { \
- _app app(__VA_ARGS__); \
- return entry::runApp(&app, _argc, _argv); \
- }
- #else
- #define ENTRY_IMPLEMENT_MAIN(_app, ...) \
- _app s_ ## _app ## App(__VA_ARGS__)
- #endif // ENTRY_CONFIG_IMPLEMENT_MAIN
- ///
- #define ENTRY_HANDLE(_name) \
- struct _name { uint16_t idx; }; \
- inline bool isValid(_name _handle) { return UINT16_MAX != _handle.idx; }
- namespace entry
- {
- ENTRY_HANDLE(WindowHandle);
- ENTRY_HANDLE(GamepadHandle);
- ///
- constexpr WindowHandle kDefaultWindowHandle = { 0 };
- ///
- struct MouseButton
- {
- enum Enum
- {
- None,
- Left,
- Middle,
- Right,
- Count
- };
- };
- ///
- struct GamepadAxis
- {
- enum Enum
- {
- LeftX,
- LeftY,
- LeftZ,
- RightX,
- RightY,
- RightZ,
- Count
- };
- };
- ///
- struct Modifier
- {
- enum Enum
- {
- None = 0,
- LeftAlt = 0x01,
- RightAlt = 0x02,
- LeftCtrl = 0x04,
- RightCtrl = 0x08,
- LeftShift = 0x10,
- RightShift = 0x20,
- LeftMeta = 0x40,
- RightMeta = 0x80,
- };
- };
- ///
- struct Key
- {
- enum Enum
- {
- None = 0,
- Esc,
- Return,
- Tab,
- Space,
- Backspace,
- Up,
- Down,
- Left,
- Right,
- Insert,
- Delete,
- Home,
- End,
- PageUp,
- PageDown,
- Print,
- Plus,
- Minus,
- LeftBracket,
- RightBracket,
- Semicolon,
- Quote,
- Comma,
- Period,
- Slash,
- Backslash,
- Tilde,
- F1,
- F2,
- F3,
- F4,
- F5,
- F6,
- F7,
- F8,
- F9,
- F10,
- F11,
- F12,
- NumPad0,
- NumPad1,
- NumPad2,
- NumPad3,
- NumPad4,
- NumPad5,
- NumPad6,
- NumPad7,
- NumPad8,
- NumPad9,
- Key0,
- Key1,
- Key2,
- Key3,
- Key4,
- Key5,
- Key6,
- Key7,
- Key8,
- Key9,
- KeyA,
- KeyB,
- KeyC,
- KeyD,
- KeyE,
- KeyF,
- KeyG,
- KeyH,
- KeyI,
- KeyJ,
- KeyK,
- KeyL,
- KeyM,
- KeyN,
- KeyO,
- KeyP,
- KeyQ,
- KeyR,
- KeyS,
- KeyT,
- KeyU,
- KeyV,
- KeyW,
- KeyX,
- KeyY,
- KeyZ,
- GamepadA,
- GamepadB,
- GamepadX,
- GamepadY,
- GamepadThumbL,
- GamepadThumbR,
- GamepadShoulderL,
- GamepadShoulderR,
- GamepadUp,
- GamepadDown,
- GamepadLeft,
- GamepadRight,
- GamepadBack,
- GamepadStart,
- GamepadGuide,
- Count
- };
- };
- ///
- struct Suspend
- {
- enum Enum
- {
- WillSuspend,
- DidSuspend,
- WillResume,
- DidResume,
- Count
- };
- };
- ///
- const char* getName(Key::Enum _key);
- ///
- struct MouseState
- {
- MouseState()
- : m_mx(0)
- , m_my(0)
- , m_mz(0)
- {
- for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
- {
- m_buttons[ii] = entry::MouseButton::None;
- }
- }
- int32_t m_mx;
- int32_t m_my;
- int32_t m_mz;
- uint8_t m_buttons[entry::MouseButton::Count];
- };
- ///
- struct GamepadState
- {
- GamepadState()
- {
- bx::memSet(m_axis, 0, sizeof(m_axis) );
- }
- int32_t m_axis[entry::GamepadAxis::Count];
- };
- ///
- bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
- ///
- bx::FileReaderI* getFileReader();
- ///
- bx::FileWriterI* getFileWriter();
- ///
- bx::AllocatorI* getAllocator();
- ///
- WindowHandle createWindow(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height, uint32_t _flags = ENTRY_WINDOW_FLAG_NONE, const char* _title = "");
- ///
- void destroyWindow(WindowHandle _handle);
- ///
- void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y);
- ///
- void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height);
- ///
- void setWindowTitle(WindowHandle _handle, const char* _title);
- ///
- void setWindowFlags(WindowHandle _handle, uint32_t _flags, bool _enabled);
- ///
- void toggleFullscreen(WindowHandle _handle);
- ///
- void setMouseLock(WindowHandle _handle, bool _lock);
- ///
- void* getNativeWindowHandle(WindowHandle _handle);
- ///
- void* getNativeDisplayHandle();
- ///
- bgfx::NativeWindowHandleType::Enum getNativeWindowHandleType(WindowHandle _handle);
- ///
- void setCurrentDir(const char* _dir);
- ///
- struct WindowState
- {
- WindowState()
- : m_width(0)
- , m_height(0)
- , m_nwh(NULL)
- {
- m_handle.idx = UINT16_MAX;
- }
- WindowHandle m_handle;
- uint32_t m_width;
- uint32_t m_height;
- MouseState m_mouse;
- void* m_nwh;
- bx::FilePath m_dropFile;
- };
- ///
- bool processWindowEvents(WindowState& _state, uint32_t& _debug, uint32_t& _reset);
- ///
- class BX_NO_VTABLE AppI
- {
- public:
- ///
- AppI(const char* _name, const char* _description, const char* _url = "https://bkaradzic.github.io/bgfx/index.html");
- ///
- virtual ~AppI() = 0;
- ///
- virtual void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) = 0;
- ///
- virtual int shutdown() = 0;
- ///
- virtual bool update() = 0;
- ///
- const char* getName() const;
- ///
- const char* getDescription() const;
- ///
- const char* getUrl() const;
- ///
- AppI* getNext();
- private:
- BX_ALIGN_DECL(16, uintptr_t) m_internal[4];
- };
- ///
- AppI* getFirstApp();
- ///
- uint32_t getNumApps();
- ///
- int runApp(AppI* _app, int _argc, const char* const* _argv);
- } // namespace entry
- #endif // ENTRY_H_HEADER_GUARD
|