From 0049f228b9cf0fbb7667cc10d004f7e00ce7d5ee Mon Sep 17 00:00:00 2001 From: Richard Powell Date: Wed, 8 Mar 2023 20:48:39 -0800 Subject: [PATCH] issue #92: Need a Bitmap --- CMakeLists.txt | 1 + LATEST_RELEASE_NOTES.md | 2 + docs/ProgrammersGuide.md | 1 + docs/src/docs/ProgrammersGuide.md | 1 + include/wxUI/Bitmap.h | 72 +++++++++++++++++++++++++++++++ include/wxUI/wxUI.h | 1 + tests/CMakeLists.txt | 1 + tests/wxUI_BitmapTests.cpp | 64 +++++++++++++++++++++++++++ 8 files changed, 143 insertions(+) create mode 100644 include/wxUI/Bitmap.h create mode 100644 tests/wxUI_BitmapTests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d83c20..3f82461 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ add_library( wxUI INTERFACE include/wxUI/wxUI.h + include/wxUI/Bitmap.h include/wxUI/BitmapToggleButton.h include/wxUI/BitmapComboBox.h include/wxUI/BitmapButton.h diff --git a/LATEST_RELEASE_NOTES.md b/LATEST_RELEASE_NOTES.md index 20bf96f..5eb9e3f 100644 --- a/LATEST_RELEASE_NOTES.md +++ b/LATEST_RELEASE_NOTES.md @@ -18,4 +18,6 @@ Other changes: * [#76](../../issues/76) add wxBitmapComboBox * [#79](../../issues/79) CheckBox has some unneeded member variables (that should be private) * [#82](../../issues/82) wxCheckBox needs a setValue +* [#89](../../issues/89) Change stack to sizer +* [#92](../../issues/92) Need a Bitmap diff --git a/docs/ProgrammersGuide.md b/docs/ProgrammersGuide.md index 326ec25..713de23 100644 --- a/docs/ProgrammersGuide.md +++ b/docs/ProgrammersGuide.md @@ -160,6 +160,7 @@ The list of Methods supported by all controllers: The "Controllers" currently supported by `wxUI`: + * `Bitmap` for `wxStaticBitmap` * `BitmapButton` for `wxBitmapButton` * `BitmapComboBox` for `wxBitmapComboBox` * `BitmapToggleButton` for `wxBitmapToggleButton` diff --git a/docs/src/docs/ProgrammersGuide.md b/docs/src/docs/ProgrammersGuide.md index 2cf5857..c5b4e59 100644 --- a/docs/src/docs/ProgrammersGuide.md +++ b/docs/src/docs/ProgrammersGuide.md @@ -111,6 +111,7 @@ The list of Methods supported by all controllers: The "Controllers" currently supported by `wxUI`: + * `Bitmap` for `wxStaticBitmap` * `BitmapButton` for `wxBitmapButton` * `BitmapComboBox` for `wxBitmapComboBox` * `BitmapToggleButton` for `wxBitmapToggleButton` diff --git a/include/wxUI/Bitmap.h b/include/wxUI/Bitmap.h new file mode 100644 index 0000000..7816453 --- /dev/null +++ b/include/wxUI/Bitmap.h @@ -0,0 +1,72 @@ +/* +MIT License + +Copyright (c) 2022 Richard Powell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +#pragma once + +#include "Widget.h" +#include + +namespace wxUI { + +struct Bitmap : public details::WidgetDetails { + using super = details::WidgetDetails; + + Bitmap(wxWindowID identity, wxBitmap const& bitmap) + : super(identity) + , bitmap(bitmap) + { + } + + explicit Bitmap(wxBitmap const& bitmap) + : Bitmap(wxID_ANY, bitmap) + { + } + + explicit Bitmap(wxSizerFlags const& flags, wxWindowID identity, wxBitmap const& bitmap) + : super(flags, identity) + , bitmap(bitmap) + { + } + + explicit Bitmap(wxSizerFlags const& flags, wxBitmap const& bitmap) + : Bitmap(flags, wxID_ANY, bitmap) + { + } + + auto create(wxWindow* parent) -> wxWindow* override + { + return new underlying_t(parent, getIdentity(), bitmap, getPos(), getSize(), getStyle()); + } + + virtual ~Bitmap() = default; + Bitmap(Bitmap const&) = default; + Bitmap(Bitmap&&) = default; + auto operator=(Bitmap const&) -> Bitmap& = default; + auto operator=(Bitmap&&) -> Bitmap& = default; + +private: + wxBitmap bitmap; +}; + +static_assert(details::Widget); +} diff --git a/include/wxUI/wxUI.h b/include/wxUI/wxUI.h index 1cdbc97..9940f6e 100644 --- a/include/wxUI/wxUI.h +++ b/include/wxUI/wxUI.h @@ -27,6 +27,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#include #include #include #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9e9c53a..3031f55 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.23) add_executable(wxUI_Tests + ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_BitmapTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_BitmapButtonTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_BitmapComboBox.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wxUI_BitmapToggleButtonTests.cpp diff --git a/tests/wxUI_BitmapTests.cpp b/tests/wxUI_BitmapTests.cpp new file mode 100644 index 0000000..d033930 --- /dev/null +++ b/tests/wxUI_BitmapTests.cpp @@ -0,0 +1,64 @@ +/* +MIT License + +Copyright (c) 2022 Richard Powell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +#include +#include + +#include + +// NOLINTBEGIN(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers, readability-function-cognitive-complexity) +using TypeUnderTest = wxUI::Bitmap; + +TEST_CASE("Bitmap") +{ + SECTION("bitmap") + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto uut = TypeUnderTest { wxBitmap {} }; + } + + SECTION("id.bitmap") + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto uut = TypeUnderTest { 10000, wxBitmap {} }; + auto* window = dynamic_cast(uut.create(&frame)); + CHECK(10000 == window->GetId()); + } + + SECTION("size.bitmap") + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto uut = TypeUnderTest { wxSizerFlags(1), wxBitmap {} }; + auto* window = dynamic_cast(uut.create(&frame)); + CHECK(window != nullptr); + } + + SECTION("size.id.bitmap") + { + wxFrame frame { nullptr, wxID_ANY, "" }; + auto uut = TypeUnderTest { wxSizerFlags(1), 10000, wxBitmap {} }; + auto* window = dynamic_cast(uut.create(&frame)); + CHECK(10000 == window->GetId()); + } +} +// NOLINTEND(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers, readability-function-cognitive-complexity)