diff --git a/src/musikcube/CMakeLists.txt b/src/musikcube/CMakeLists.txt index b29091c8c..f42748aa2 100644 --- a/src/musikcube/CMakeLists.txt +++ b/src/musikcube/CMakeLists.txt @@ -39,6 +39,7 @@ set (CUBE_SRCS ./app/util/Rating.cpp ./app/util/TrackRowRenderers.cpp ./app/util/UpdateCheck.cpp + ./app/util/WindowUtil.cpp ./app/window/CategoryListView.cpp ./app/window/TrackListView.cpp ./app/window/TransportWindow.cpp diff --git a/src/musikcube/app/layout/BrowseLayout.cpp b/src/musikcube/app/layout/BrowseLayout.cpp index e7ee26800..c887d5e1f 100755 --- a/src/musikcube/app/layout/BrowseLayout.cpp +++ b/src/musikcube/app/layout/BrowseLayout.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -273,19 +274,15 @@ void BrowseLayout::RequeryTrackList(ListWindow *view) { } void BrowseLayout::OnWindowMouseEvent(Window* window, const IMouseHandler::Event* mouseEvent) { - if (mouseEvent->y == -1) { - auto title = window->GetFrameTitle(); - /* the title will be in the format "- title -". this check is kludgy. */ - if (mouseEvent->x > 0 && mouseEvent->x < u8cols(title) + 3) { - if (window == this->categoryList.get()) { - if (this->categoryListHeaderClickHandler) { - this->categoryListHeaderClickHandler(); - } - } - else if (window == this->trackList.get()) { - this->ShowTrackSortOverlay(); + if (windowutil::WasHeaderClicked(window, mouseEvent)) { + if (window == this->categoryList.get()) { + if (this->categoryListHeaderClickHandler) { + this->categoryListHeaderClickHandler(); } } + else if (window == this->trackList.get()) { + this->ShowTrackSortOverlay(); + } } } diff --git a/src/musikcube/app/layout/TrackSearchLayout.cpp b/src/musikcube/app/layout/TrackSearchLayout.cpp index acd768e21..e75a36a29 100755 --- a/src/musikcube/app/layout/TrackSearchLayout.cpp +++ b/src/musikcube/app/layout/TrackSearchLayout.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -207,12 +208,8 @@ void TrackSearchLayout::OnEnterPressed(cursespp::TextInput* sender) { } void TrackSearchLayout::OnWindowMouseEvent(Window* window, const IMouseHandler::Event* mouseEvent) { - if (window == this->trackList.get() && mouseEvent->y == -1) { - auto title = window->GetFrameTitle(); - /* the title will be in the format "- title -". this check is kludgy. */ - if (mouseEvent->x > 0 && mouseEvent->x < u8cols(title) + 3) { - this->ShowTrackSortOverlay(); - } + if (windowutil::WasHeaderClicked(window, mouseEvent)) { + this->ShowTrackSortOverlay(); } } diff --git a/src/musikcube/app/util/WindowUtil.cpp b/src/musikcube/app/util/WindowUtil.cpp new file mode 100644 index 000000000..f566bd3aa --- /dev/null +++ b/src/musikcube/app/util/WindowUtil.cpp @@ -0,0 +1,55 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2004-2021 musikcube team +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include "WindowUtil.h" + +using namespace cursespp; + +namespace musik { namespace cube { namespace windowutil { + + bool WasHeaderClicked(Window* window, const IMouseHandler::Event* mouseEvent) noexcept { + if (window && mouseEvent->y == -1) { + auto title = window->GetFrameTitle(); + /* the title will be in the format "- title -". this check is kludgy. */ + if (mouseEvent->x > 0 && mouseEvent->x < u8cols(title) + 3) { + return true; + } + } + return false; + } + +} } } \ No newline at end of file diff --git a/src/musikcube/app/util/WindowUtil.h b/src/musikcube/app/util/WindowUtil.h new file mode 100644 index 000000000..820607691 --- /dev/null +++ b/src/musikcube/app/util/WindowUtil.h @@ -0,0 +1,45 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2004-2021 musikcube team +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +namespace musik { namespace cube { namespace windowutil { + + extern bool WasHeaderClicked( + cursespp::Window* window, + const cursespp::IMouseHandler::Event* mouseEvent) noexcept; + +} } } \ No newline at end of file diff --git a/src/musikcube/musikcube.vcxproj b/src/musikcube/musikcube.vcxproj index b27af3cbd..18e7b8126 100755 --- a/src/musikcube/musikcube.vcxproj +++ b/src/musikcube/musikcube.vcxproj @@ -895,6 +895,7 @@ xcopy "$(SolutionDir)src\3rdparty\bin\win\font\*.ttf" "$(TargetDir)fonts\" /Y /e + @@ -980,6 +981,7 @@ xcopy "$(SolutionDir)src\3rdparty\bin\win\font\*.ttf" "$(TargetDir)fonts\" /Y /e + diff --git a/src/musikcube/musikcube.vcxproj.filters b/src/musikcube/musikcube.vcxproj.filters index 8245dfc15..4266aa207 100755 --- a/src/musikcube/musikcube.vcxproj.filters +++ b/src/musikcube/musikcube.vcxproj.filters @@ -204,6 +204,9 @@ app\layout + + app\util + @@ -460,6 +463,9 @@ app\layout + + app\util +