diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e0b15a5b4..8cd68e57a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,20 +15,24 @@ jobs: strategy: matrix: - os: [ubuntu-20.04, macos-11.0] + include: + - os: ubuntu-20.04 + - os: macos-11.0 + - os: windows-2019 + cmake_toolchain_file: "C:/vcpkg/scripts/buildsystems/vcpkg.cmake" steps: - uses: actions/checkout@v2 - name: Install Dependencies - run: $GITHUB_WORKSPACE/scripts/install_prerequisites.sh -v -u -m "apt-get brew" all + run: $GITHUB_WORKSPACE/scripts/install_prerequisites.sh -v -u -m "apt-get brew vcpkg" all - name: Create Build Directory run: cmake -E make_directory ${{runner.workspace}}/build - name: Configure CMake working-directory: ${{runner.workspace}}/build - run: cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE $GITHUB_WORKSPACE + run: cmake -DCMAKE_TOOLCHAIN_FILE=${{matrix.cmake_toolchain_file}} -DCMAKE_BUILD_TYPE=$BUILD_TYPE $GITHUB_WORKSPACE - name: Build working-directory: ${{runner.workspace}}/build diff --git a/.gitignore b/.gitignore index 82c3a5e44..f2884bd19 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ CMakeLists.txt.user build* _builds _logs +.vscode diff --git a/cmake/FindLibRealSense.cmake b/cmake/FindLibRealSense.cmake deleted file mode 100644 index a8d7a82f2..000000000 --- a/cmake/FindLibRealSense.cmake +++ /dev/null @@ -1,33 +0,0 @@ -# -*- mode: cmake; -*- -############################################################################### -# Find librealsense https://github.com/IntelRealSense/librealsense -# -# This sets the following variables: -# LIBREALSENSE_FOUND - True if OPENNI was found. -# LIBREALSENSE_INCLUDE_DIRS - Directories containing the OPENNI include files. -# LIBREALSENSE_LIBRARIES - Libraries needed to use OPENNI. -# LIBREALSENSE_DEFINITIONS - Compiler flags for OPENNI. -# -# File forked from augmented_dev, project of alantrrs -# (https://github.com/alantrrs/augmented_dev). - -find_package(PkgConfig) -if(${CMAKE_VERSION} VERSION_LESS 2.8.2) -endif() - -#add a hint so that it can find it without the pkg-config -find_path(LIBREALSENSE_INCLUDE_DIR librealsense/rs.h - HINTS /usr/include/ /usr/local/include) -#add a hint so that it can find it without the pkg-config -find_library(LIBREALSENSE_LIBRARY - NAMES librealsense.so - HINTS /usr/lib /usr/local/lib ) - - set(LIBREALSENSE_INCLUDE_DIRS ${LIBREALSENSE_INCLUDE_DIR}) - set(LIBREALSENSE_LIBRARIES ${LIBREALSENSE_LIBRARY}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LibRealSense DEFAULT_MSG - LIBREALSENSE_LIBRARY LIBREALSENSE_INCLUDE_DIR) - -mark_as_advanced(LIBREALSENSE_LIBRARY LIBREALSENSE_INCLUDE_DIR) diff --git a/cmake/FindLibRealSense2.cmake b/cmake/FindLibRealSense2.cmake deleted file mode 100644 index 12ae95d56..000000000 --- a/cmake/FindLibRealSense2.cmake +++ /dev/null @@ -1,33 +0,0 @@ -# -*- mode: cmake; -*- -############################################################################### -# Find librealsense2 https://github.com/IntelRealSense/librealsense -# -# This sets the following variables: -# LIBREALSENSE2_FOUND - True if LIBREALSENSE2 was found. -# LIBREALSENSE2_INCLUDE_DIRS - Directories containing the LIBREALSENSE2 include files. -# LIBREALSENSE2_LIBRARIES - Libraries needed to use LIBREALSENSE2. -# LIBREALSENSE2_DEFINITIONS - Compiler flags for LIBREALSENSE2. -# -# File forked from augmented_dev, project of alantrrs -# (https://github.com/alantrrs/augmented_dev). - -find_package(PkgConfig) -if(${CMAKE_VERSION} VERSION_LESS 2.8.2) -endif() - -#add a hint so that it can find it without the pkg-config -find_path(LIBREALSENSE2_INCLUDE_DIR librealsense2/rs.h - HINTS /usr/include/ /usr/local/include) -#add a hint so that it can find it without the pkg-config -find_library(LIBREALSENSE2_LIBRARY - NAMES librealsense2.so - HINTS /usr/lib /usr/local/lib ) - - set(LIBREALSENSE2_INCLUDE_DIRS ${LIBREALSENSE2_INCLUDE_DIR}) - set(LIBREALSENSE2_LIBRARIES ${LIBREALSENSE2_LIBRARY}) - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(LibRealSense2 DEFAULT_MSG - LIBREALSENSE2_LIBRARY LIBREALSENSE2_INCLUDE_DIR) - -mark_as_advanced(LIBREALSENSE2_LIBRARY LIBREALSENSE2_INCLUDE_DIR) diff --git a/cmake/FindRealSense.cmake b/cmake/FindRealSense.cmake new file mode 100644 index 000000000..99cea4478 --- /dev/null +++ b/cmake/FindRealSense.cmake @@ -0,0 +1,33 @@ +# -*- mode: cmake; -*- +############################################################################### +# Find realsense https://github.com/IntelRealSense/librealsense +# +# This sets the following variables: +# REALSENSE_FOUND - True if RealSense was found. +# REALSENSE_INCLUDE_DIRS - Directories containing the RealSense include files. +# REALSENSE_LIBRARIES - Libraries needed to use RealSense. +# REALSENSE_DEFINITIONS - Compiler flags for RealSense. +# +# File forked from augmented_dev, project of alantrrs +# (https://github.com/alantrrs/augmented_dev). + +find_package(PkgConfig) +if(${CMAKE_VERSION} VERSION_LESS 2.8.2) +endif() + +#add a hint so that it can find it without the pkg-config +find_path(REALSENSE_INCLUDE_DIR librealsense/rs.h + HINTS /usr/include/ /usr/local/include) +#add a hint so that it can find it without the pkg-config +find_library(REALSENSE_LIBRARY + NAMES realsense + HINTS /usr/lib /usr/local/lib ) + + set(REALSENSE_INCLUDE_DIRS ${REALSENSE_INCLUDE_DIR}) + set(REALSENSE_LIBRARIES ${REALSENSE_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(RealSense DEFAULT_MSG + REALSENSE_LIBRARY REALSENSE_INCLUDE_DIR) + +mark_as_advanced(REALSENSE_LIBRARY REALSENSE_INCLUDE_DIR) diff --git a/cmake/FindRealSense2.cmake b/cmake/FindRealSense2.cmake new file mode 100644 index 000000000..8f9f13701 --- /dev/null +++ b/cmake/FindRealSense2.cmake @@ -0,0 +1,33 @@ +# -*- mode: cmake; -*- +############################################################################### +# Find realsense2 https://github.com/IntelRealSense/librealsense +# +# This sets the following variables: +# REALSENSE2_FOUND - True if REALSENSE2 was found. +# REALSENSE2_INCLUDE_DIRS - Directories containing the REALSENSE2 include files. +# REALSENSE2_LIBRARIES - Libraries needed to use REALSENSE2. +# REALSENSE2_DEFINITIONS - Compiler flags for REALSENSE2. +# +# File forked from augmented_dev, project of alantrrs +# (https://github.com/alantrrs/augmented_dev). + +find_package(PkgConfig) +if(${CMAKE_VERSION} VERSION_LESS 2.8.2) +endif() + +#add a hint so that it can find it without the pkg-config +find_path(REALSENSE2_INCLUDE_DIR librealsense2/rs.h + HINTS /usr/include/ /usr/local/include) +#add a hint so that it can find it without the pkg-config +find_library(REALSENSE2_LIBRARY + NAMES realsense2 + HINTS /usr/lib /usr/local/lib ) + + set(REALSENSE2_INCLUDE_DIRS ${REALSENSE2_INCLUDE_DIR}) + set(REALSENSE2_LIBRARIES ${REALSENSE2_LIBRARY}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(RealSense2 DEFAULT_MSG + REALSENSE2_LIBRARY REALSENSE2_INCLUDE_DIR) + +mark_as_advanced(REALSENSE2_LIBRARY REALSENSE2_INCLUDE_DIR) diff --git a/components/pango_core/include/pangolin/platform.h b/components/pango_core/include/pangolin/platform.h index a22cdeb22..4b7d818b9 100644 --- a/components/pango_core/include/pangolin/platform.h +++ b/components/pango_core/include/pangolin/platform.h @@ -35,13 +35,15 @@ #ifdef __GNUC__ # define PANGOLIN_DEPRECATED(x) __attribute__((deprecated(x))) #elif defined(_MSC_VER) -# define PANGOLIN_DEPRECATED __declspec(deprecated(x)) +# define PANGOLIN_DEPRECATED(x) __declspec(deprecated(x)) #else -# define PANGOLIN_DEPRECATED +# define PANGOLIN_DEPRECATED(x) #endif #ifdef _MSC_VER # define __thread __declspec(thread) +// TODO: Fix this for shared libs on Windows +# define PANGOLIN_EXPORT #else # define PANGOLIN_EXPORT #endif //_MSVC_ diff --git a/components/pango_video/CMakeLists.txt b/components/pango_video/CMakeLists.txt index 5753849d8..d533ef8f6 100644 --- a/components/pango_video/CMakeLists.txt +++ b/components/pango_video/CMakeLists.txt @@ -89,27 +89,27 @@ if(BUILD_PANGOLIN_FFMPEG) endif() endif() -option(BUILD_PANGOLIN_LIBREALSENSE "Build support for LibRealSense video input" ON) -if(BUILD_PANGOLIN_LIBREALSENSE) - find_package(LibRealSense QUIET) - if(LIBREALSENSE_FOUND) +option(BUILD_PANGOLIN_REALSENSE "Build support for RealSense video input" ON) +if(BUILD_PANGOLIN_REALSENSE) + find_package(RealSense QUIET) + if(REALSENSE_FOUND) target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/realsense.cpp) - target_link_libraries(${COMPONENT} PRIVATE ${LIBREALSENSE_LIBRARIES} ) - target_include_directories(${COMPONENT} PRIVATE ${LIBREALSENSE_INCLUDE_DIRS} ) + target_link_libraries(${COMPONENT} PRIVATE ${REALSENSE_LIBRARIES} ) + target_include_directories(${COMPONENT} PRIVATE ${REALSENSE_INCLUDE_DIRS} ) PangolinRegisterFactory( VideoInterface RealSenseVideo ) - message(STATUS "LibRealSense Found and Enabled") + message(STATUS "RealSense Found and Enabled") endif() endif() -option(BUILD_PANGOLIN_LIBREALSENSE2 "Build support for LibRealSense2 video input" ON) -if(BUILD_PANGOLIN_LIBREALSENSE2) - find_package(LibRealSense2 QUIET) - if(LIBREALSENSE2_FOUND) +option(BUILD_PANGOLIN_REALSENSE2 "Build support for RealSense2 video input" ON) +if(BUILD_PANGOLIN_REALSENSE2) + find_package(RealSense2 QUIET) + if(REALSENSE2_FOUND) target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/realsense2.cpp) - target_link_libraries(${COMPONENT} PRIVATE ${LIBREALSENSE2_LIBRARIES} ) - target_include_directories(${COMPONENT} PRIVATE ${LIBREALSENSE2_INCLUDE_DIRS} ) + target_link_libraries(${COMPONENT} PRIVATE ${REALSENSE2_LIBRARIES} ) + target_include_directories(${COMPONENT} PRIVATE ${REALSENSE2_INCLUDE_DIRS} ) PangolinRegisterFactory( VideoInterface RealSense2Video ) - message(STATUS "LibRealSense2 Found and Enabled") + message(STATUS "RealSense2 Found and Enabled") endif() endif() @@ -166,7 +166,7 @@ if (BUILD_PANGOLIN_UVC_MEDIAFOUNDATION) if (MediaFoundation_FOUND) target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/uvc_mediafoundation.cpp) target_link_libraries(${COMPONENT} PRIVATE ${MediaFoundation_LIBRARIES} ) - PangolinRegisterFactory( VideoInterface UvcMediaFoundation ) + PangolinRegisterFactory( VideoInterface UvcMediaFoundationVideo ) message(STATUS "MediaFoundation Found and Enabled") endif() endif() @@ -178,7 +178,7 @@ if(BUILD_PANGOLIN_DEPTHSENSE) target_sources( ${COMPONENT} PRIVATE ${DRIVER_DIR}/depthsense.cpp) target_link_libraries(${COMPONENT} PRIVATE ${DepthSense_LIBRARIES} ) target_include_directories(${COMPONENT} PRIVATE ${DepthSense_INCLUDE_DIRS} ) - PangolinRegisterFactory( VideoInterface DepthSense ) + PangolinRegisterFactory( VideoInterface DepthSenseVideo ) message(STATUS "DepthSense Found and Enabled") endif() endif() diff --git a/components/pango_video/src/drivers/openni.cpp b/components/pango_video/src/drivers/openni.cpp index f96e2e0a2..ca4fa28bd 100644 --- a/components/pango_video/src/drivers/openni.cpp +++ b/components/pango_video/src/drivers/openni.cpp @@ -271,7 +271,7 @@ PANGOLIN_REGISTER_FACTORY(OpenNiVideo) struct OpenNiVideoFactory final : public TypedFactoryInterface { std::map Schemes() const override { - return {{"openni1",10}, {"openni",100}, {"kinect",100}}; + return {{"openni1",10}, {"openni",100}, {"oni",100}}; } const char* Description() const override { diff --git a/components/pango_video/src/drivers/openni2.cpp b/components/pango_video/src/drivers/openni2.cpp index d450fa9a4..9b2cb72ea 100644 --- a/components/pango_video/src/drivers/openni2.cpp +++ b/components/pango_video/src/drivers/openni2.cpp @@ -32,6 +32,11 @@ #include #include +// OpenNI must be including a horrid windows header +// which defines these nasty macros. +#undef max +#undef min + namespace pangolin { @@ -638,6 +643,27 @@ size_t OpenNi2Video::Seek(size_t frameid) PANGOLIN_REGISTER_FACTORY(OpenNi2Video) { struct OpenNI2VideoFactory final : public TypedFactoryInterface { + std::map Schemes() const override + { + return {{"openni2",10}, {"openni",10}, {"oni",10}}; + } + const char* Description() const override + { + return "OpenNI v2 Driver to access Kinect / Primesense devices."; + } + ParamSet Params() const override + { + return {{ + {"size","640x480","Image dimension"}, + {"fps","30","Framerate"}, + {"roi","0+0+0x0","Region of interest"}, + {"realtime","","If playback rate should be slowed to real-time speed."}, + {"img\\d+", "","Device stream for nth image. Choose from [gray,rgb,ir,depth1mm,depth100um,depth_reg,ir8,ir24,ir+,ir8+]"}, + {"closerange","false","Use close-range mode (lower projector intensity)"}, + {"holefilter","false","Enable hole filter"}, + {"fastcrop","false","?"} + }}; + } std::unique_ptr Open(const Uri& uri) override { const bool realtime = uri.Contains("realtime"); const ImageDim default_dim = uri.Get("size", ImageDim(640,480)); @@ -681,10 +707,9 @@ PANGOLIN_REGISTER_FACTORY(OpenNi2Video) } }; - auto factory = std::make_shared(); - FactoryRegistry::I()->RegisterFactory(factory, 10, "openni"); - FactoryRegistry::I()->RegisterFactory(factory, 10, "openni2"); - FactoryRegistry::I()->RegisterFactory(factory, 10, "oni"); + return FactoryRegistry::I()->RegisterFactory( + std::make_shared() + ); } } diff --git a/components/pango_video/src/drivers/uvc_mediafoundation.cpp b/components/pango_video/src/drivers/uvc_mediafoundation.cpp index 65afe8648..df6b2d48a 100644 --- a/components/pango_video/src/drivers/uvc_mediafoundation.cpp +++ b/components/pango_video/src/drivers/uvc_mediafoundation.cpp @@ -1047,7 +1047,7 @@ bool UvcMediaFoundationVideo::SymLinkIDMatches(const std::wstring& symLink, cons PANGOLIN_REGISTER_FACTORY(UvcMediaFoundationVideo) { - struct UvcVideoFactory final : public TypedFactoryInterface + struct UvcMediaFoundationVideoFactory final : public TypedFactoryInterface { std::map Schemes() const override { @@ -1085,7 +1085,7 @@ PANGOLIN_REGISTER_FACTORY(UvcMediaFoundationVideo) } }; - return FactoryRegistry::I()->RegisterFactory(std::make_shared()); + return FactoryRegistry::I()->RegisterFactory(std::make_shared()); } } diff --git a/components/pango_windowing/include/pangolin/windowing/WinWindow.h b/components/pango_windowing/include/pangolin/windowing/WinWindow.h index 35e85adcf..ed3806011 100644 --- a/components/pango_windowing/include/pangolin/windowing/WinWindow.h +++ b/components/pango_windowing/include/pangolin/windowing/WinWindow.h @@ -27,17 +27,15 @@ #pragma once -#include -#include - #include - +#include +#include #include namespace pangolin { -struct WinWindow : public PangolinGl +struct WinWindow : public WindowInterface { WinWindow( const std::string& title, int width, int height @@ -45,30 +43,29 @@ struct WinWindow : public PangolinGl ~WinWindow(); - void StartFullScreen(); - - void StopFullScreen(); - - void ToggleFullscreen() override; - void Move(int x, int y) override; void Resize(unsigned int w, unsigned int h) override; + void ShowFullscreen(const TrueFalseToggle on_off) override; + void MakeCurrent() override; void RemoveCurrent() override; - void SwapBuffers() override; - void ProcessEvents() override; + void SwapBuffers() override; + HGLRC GetGLRenderContext() { return hGLRC; } private: + void StartFullScreen(); + void StopFullScreen(); + static LRESULT APIENTRY WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); LRESULT HandleWinMessages(UINT message, WPARAM wParam, LPARAM lParam); @@ -84,6 +81,9 @@ struct WinWindow : public PangolinGl HDC hDC; HGLRC hGLRC; HPALETTE hPalette; + bool bIsFullscreen; + RECT cWindowedRect; + float afLastMousePos[2]; }; } diff --git a/components/pango_windowing/src/display_win.cpp b/components/pango_windowing/src/display_win.cpp index 0c93e2f00..b8a755acd 100644 --- a/components/pango_windowing/src/display_win.cpp +++ b/components/pango_windowing/src/display_win.cpp @@ -28,10 +28,7 @@ #include #include #include -#include -#include - -#include +#include #include #define CheckWGLDieOnError() pangolin::_CheckWLDieOnError( __FILE__, __LINE__ ); @@ -56,8 +53,6 @@ namespace pangolin const char *className = "Pangolin"; -extern __thread PangolinGl* context; - //////////////////////////////////////////////////////////////////////// // Utils //////////////////////////////////////////////////////////////////////// @@ -101,14 +96,13 @@ unsigned char GetPangoKey(WPARAM wParam, LPARAM lParam) return 0; } -int GetMouseModifierKey(WPARAM wParam) +KeyModifierBitmask GetMouseModifierKey(WPARAM wParam) { - //maps windows key modifier to glutGetModifiers values - int gluKeyModVal = 0; - if (wParam & MK_SHIFT) gluKeyModVal += 1; - if (wParam & MK_CONTROL) gluKeyModVal += 2; - if (HIBYTE(GetKeyState(VK_MENU))) gluKeyModVal += 4; - return gluKeyModVal << 4; + KeyModifierBitmask mask; + if (wParam & MK_SHIFT) mask |= KeyModifierShift; + if (wParam & MK_CONTROL) mask |= KeyModifierCtrl; + if (HIBYTE(GetKeyState(VK_MENU))) mask |= KeyModifierCmd; + return mask; } //////////////////////////////////////////////////////////////////////// @@ -213,7 +207,7 @@ void WinWindow::SetupPalette(HDC hDC) WinWindow::WinWindow( const std::string& window_title, int width, int height -) : hWnd(0) +) : hWnd(0), bIsFullscreen(false) { const HMODULE hCurrentInst = GetModuleHandleA(nullptr); if(hCurrentInst==NULL) { @@ -236,13 +230,6 @@ WinWindow::WinWindow( throw std::runtime_error("Pangolin Window Creation Failed."); } - // Gets the size of the window, excluding the top bar - RECT cRect; - GetClientRect(thishwnd, &cRect); - - PangolinGl::windowed_size[0] = cRect.right; - PangolinGl::windowed_size[1] = cRect.bottom; - // Display Window ShowWindow(hWnd, SW_SHOW); } @@ -344,10 +331,7 @@ LRESULT WinWindow::HandleWinMessages(UINT message, WPARAM wParam, LPARAM lParam) PostQuitMessage(0); return 0; case WM_SIZE: - /* track window size changes */ - if (context == this) { - process::Resize((int)LOWORD(lParam), (int)HIWORD(lParam)); - } + ResizeSignal(WindowResizeEvent({(int)LOWORD(lParam), (int)HIWORD(lParam)})); return 0; case WM_PALETTECHANGED: /* realize palette if this is *not* the current window */ @@ -377,66 +361,89 @@ LRESULT WinWindow::HandleWinMessages(UINT message, WPARAM wParam, LPARAM lParam) if(RealizePalette(hDC)==GDI_ERROR) { std::cerr << "WM_QUERYNEWPALETTE RealizePalette() failed" << std::endl; } - //redraw(); return TRUE; } break; case WM_PAINT: - { - //PAINTSTRUCT ps; - //BeginPaint(hWnd, &ps); - //if (hGLRC) { - // redraw(); - //} - //EndPaint(hWnd, &ps); - //return 0; - } break; case WM_KEYDOWN: - { - unsigned char key = GetPangoKey(wParam, lParam); - if(key>0) process::Keyboard(key, 1, 1); - return 0; - } case WM_KEYUP: { unsigned char key = GetPangoKey(wParam, lParam); - if (key>0) process::KeyboardUp(key, 1, 1); + if(key > 0) { + // TODO: Fix + KeyboardSignal(KeyboardEvent({ + afLastMousePos[0], afLastMousePos[1], + KeyModifierBitmask(), + (unsigned char)key, message == WM_KEYDOWN + })); + } return 0; } case WM_LBUTTONDOWN: - process::Mouse(0 | GetMouseModifierKey(wParam), 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + MouseSignal(MouseEvent({ + (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam), + GetMouseModifierKey(wParam), 0, true + })); return 0; case WM_MBUTTONDOWN: - process::Mouse(1 | GetMouseModifierKey(wParam), 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + MouseSignal(MouseEvent({ + (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam), + GetMouseModifierKey(wParam), 1, true + })); return 0; case WM_RBUTTONDOWN: - process::Mouse(2 | GetMouseModifierKey(wParam), 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + MouseSignal(MouseEvent({ + (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam), + GetMouseModifierKey(wParam), 2, true + })); return 0; - case WM_LBUTTONUP: - process::Mouse(0 | GetMouseModifierKey(wParam), 1, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + MouseSignal(MouseEvent({ + (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam), + GetMouseModifierKey(wParam), 0, false + })); return 0; case WM_MBUTTONUP: - process::Mouse(1 | GetMouseModifierKey(wParam), 1, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + MouseSignal(MouseEvent({ + (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam), + GetMouseModifierKey(wParam), 1, false + })); return 0; case WM_RBUTTONUP: - process::Mouse(2 | GetMouseModifierKey(wParam), 1, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + MouseSignal(MouseEvent({ + (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam), + GetMouseModifierKey(wParam), 2, false + })); return 0; - case WM_MOUSEMOVE: if (wParam & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON) ) { - process::MouseMotion(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + MouseMotionSignal(MouseMotionEvent({ + (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam), + GetMouseModifierKey(wParam), + })); } else{ - process::PassiveMouseMotion(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); + PassiveMouseMotionSignal(MouseMotionEvent({ + (float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam), + GetMouseModifierKey(wParam), + })); } + afLastMousePos[0] = (float)GET_X_LPARAM(lParam); + afLastMousePos[1] = (float)GET_Y_LPARAM(lParam); return 0; - case WM_MOUSEWHEEL: - process::Scroll(0.0f, GET_WHEEL_DELTA_WPARAM(wParam) / 5.0f ); + SpecialInputSignal(SpecialInputEvent({ + afLastMousePos[0], afLastMousePos[1], + GetMouseModifierKey(wParam), InputSpecialScroll, + {0.0f, GET_WHEEL_DELTA_WPARAM(wParam) / 5.0f, 0.0f, 0.0f } + })); return 0; case WM_MOUSEHWHEEL: - process::Scroll(GET_WHEEL_DELTA_WPARAM(wParam) / 5.0f, 0.0f); + SpecialInputSignal(SpecialInputEvent({ + afLastMousePos[0], afLastMousePos[1], + GetMouseModifierKey(wParam), InputSpecialScroll, + {GET_WHEEL_DELTA_WPARAM(wParam) / 5.0f, 0.0f, 0.0f, 0.0f } + })); return 0; default: break; @@ -467,10 +474,10 @@ void WinWindow::StartFullScreen() { CheckWGLDieOnError(); } - GLint prev[2]; - std::memcpy(prev, context->windowed_size, sizeof(prev)); + // Save windowed size so that we can un-fullscreen to + // to this dimension + GetWindowRect(hWnd, &cWindowedRect); ShowWindow(hWnd, SW_SHOWMAXIMIZED); - std::memcpy(context->windowed_size, prev, sizeof(prev)); } void WinWindow::StopFullScreen() { @@ -498,21 +505,22 @@ void WinWindow::StopFullScreen() { CheckWGLDieOnError(); } - if(!SetWindowPos(hWnd, HWND_TOP, 0, 0, context->windowed_size[0], context->windowed_size[1], SWP_FRAMECHANGED)) { - std::cerr << "SetWindowPos() failed" << std::endl; - CheckWGLDieOnError(); - } + // Restore previous size + Resize(cWindowedRect.right-cWindowedRect.left, cWindowedRect.bottom-cWindowedRect.top); + Move(cWindowedRect.left, cWindowedRect.top); } -void WinWindow::ToggleFullscreen() +void WinWindow::ShowFullscreen(const TrueFalseToggle on_off) { - if(!context->is_fullscreen) { - StartFullScreen(); - context->is_fullscreen = true; - }else{ - StopFullScreen(); - context->is_fullscreen = false; + const bool target = to_bool(on_off, bIsFullscreen); + if(target != bIsFullscreen) { + if(target) { + StartFullScreen(); + }else{ + StopFullScreen(); + } } + bIsFullscreen = target; } void WinWindow::Move(int x, int y) @@ -538,9 +546,6 @@ void WinWindow::MakeCurrent() CheckWGLDieOnError(); } - // Setup threadlocal context as this - context = this; - RECT rect; if(!GetWindowRect(hWnd, &rect)) { std::cerr << "GetWindowRect() failed" << std::endl; @@ -567,10 +572,18 @@ void WinWindow::SwapBuffers() void WinWindow::ProcessEvents() { + static bool needs_init = true; + if(needs_init) { + RECT cRect; + GetClientRect(hWnd, &cRect); + ResizeSignal(WindowResizeEvent({cRect.right, cRect.bottom})); + needs_init = false; + } + MSG msg; while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { - pangolin::Quit(); + CloseSignal(); break; } TranslateMessage(&msg); @@ -588,6 +601,22 @@ std::unique_ptr CreateWinWindowAndBind(std::string window_title PANGOLIN_REGISTER_FACTORY(WinWindow) { struct WinWindowFactory : public TypedFactoryInterface { + std::map Schemes() const override + { + return {{"winapi",10}, {"default",100}}; + } + const char* Description() const override + { + return "Use Windows native window"; + } + ParamSet Params() const override + { + return {{ + {"window_title","window","Title of application Window"}, + {"w","640","Requested window width"}, + {"h","480","Requested window height"} + }}; + } std::unique_ptr Open(const Uri& uri) override { const std::string window_title = uri.Get("window_title", "window"); @@ -597,9 +626,7 @@ PANGOLIN_REGISTER_FACTORY(WinWindow) } }; - auto factory = std::make_shared(); - FactoryRegistry::I().RegisterFactory(factory, 10, "winapi"); - FactoryRegistry::I().RegisterFactory(factory, 100, "default"); + return FactoryRegistry::I()->RegisterFactory(std::make_shared()); } } diff --git a/scripts/install_prerequisites.sh b/scripts/install_prerequisites.sh index 2ed272473..5e6d1c518 100755 --- a/scripts/install_prerequisites.sh +++ b/scripts/install_prerequisites.sh @@ -137,7 +137,6 @@ elif [[ "$MANAGER" == "port" ]]; then PKGS_RECOMMENDED+=(jpeg libpng openexr tiff ffmpeg-devel lz4 zstd py37-pybind11) PKGS_ALL+=(libdc1394 openni) elif [[ "$MANAGER" == "brew" ]]; then - PKGS_UPDATE="" PKGS_OPTIONS+=(install) if ((VERBOSE > 0)); then PKGS_OPTIONS+=(--verbose); fi PKGS_REQUIRED+=(glew eigen cmake) @@ -146,6 +145,12 @@ elif [[ "$MANAGER" == "brew" ]]; then if ((DRYRUN > 0)); then MANAGER="echo $MANAGER" fi +elif [[ "$MANAGER" == "vcpkg" ]]; then + PKGS_OPTIONS+=(install --triplet=x64-windows ) + if ((DRYRUN > 0)); then PKGS_OPTIONS+=(--dry-run); fi + PKGS_REQUIRED+=(glew eigen3) + PKGS_RECOMMENDED+=(libjpeg-turbo libpng openexr tiff ffmpeg lz4 zstd) + PKGS_ALL+=(openni2 realsense2) else echo "Error: Don't know how to use \"$MANAGER\", please fix the script." >&2 exit 1