Skip to content

Commit

Permalink
Merge pull request #93 from rmpowell77/dev/bitmap
Browse files Browse the repository at this point in the history
issue #92: Need a Bitmap
  • Loading branch information
rmpowell77 authored Mar 9, 2023
2 parents b270054 + 0049f22 commit 69c185f
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions LATEST_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions docs/ProgrammersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions docs/src/docs/ProgrammersGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
72 changes: 72 additions & 0 deletions include/wxUI/Bitmap.h
Original file line number Diff line number Diff line change
@@ -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 <wx/statbmp.h>

namespace wxUI {

struct Bitmap : public details::WidgetDetails<Bitmap, wxStaticBitmap> {
using super = details::WidgetDetails<Bitmap, wxStaticBitmap>;

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<Bitmap>);
}
1 change: 1 addition & 0 deletions include/wxUI/wxUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <wxUI/Bitmap.h>
#include <wxUI/BitmapButton.h>
#include <wxUI/BitmapComboBox.h>
#include <wxUI/BitmapToggleButton.h>
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
64 changes: 64 additions & 0 deletions tests/wxUI_BitmapTests.cpp
Original file line number Diff line number Diff line change
@@ -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 <catch2/catch_test_macros.hpp>
#include <wxUI/Bitmap.h>

#include <wx/wx.h>

// 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<TypeUnderTest::underlying_t*>(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<TypeUnderTest::underlying_t*>(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<TypeUnderTest::underlying_t*>(uut.create(&frame));
CHECK(10000 == window->GetId());
}
}
// NOLINTEND(cppcoreguidelines-avoid-magic-numbers, readability-magic-numbers, readability-function-cognitive-complexity)

0 comments on commit 69c185f

Please sign in to comment.