Skip to content

Commit 51f225b

Browse files
committed
Add GraphicsEffect class
1 parent 9e01c65 commit 51f225b

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ qt_add_qml_module(scratchcpp-render
5858
penlayerpainter.h
5959
penattributes.h
6060
penstate.h
61+
graphicseffect.cpp
62+
graphicseffect.h
6163
blocks/penextension.cpp
6264
blocks/penextension.h
6365
blocks/penblocks.cpp

src/graphicseffect.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: LGPL-3.0-or-later
2+
3+
#include "graphicseffect.h"
4+
5+
using namespace scratchcpprender;
6+
7+
GraphicsEffect::GraphicsEffect(ShaderManager::Effect effect, const std::string &name) :
8+
m_effect(effect),
9+
m_name(name)
10+
{
11+
}
12+
13+
ShaderManager::Effect GraphicsEffect::effect() const
14+
{
15+
return m_effect;
16+
}
17+
18+
std::string GraphicsEffect::name() const
19+
{
20+
return m_name;
21+
}

src/graphicseffect.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: LGPL-3.0-or-later
2+
3+
#pragma once
4+
5+
#include <scratchcpp/igraphicseffect.h>
6+
7+
#include "shadermanager.h"
8+
9+
namespace scratchcpprender
10+
{
11+
12+
class GraphicsEffect : public libscratchcpp::IGraphicsEffect
13+
{
14+
public:
15+
GraphicsEffect(ShaderManager::Effect effect, const std::string &name);
16+
17+
ShaderManager::Effect effect() const;
18+
std::string name() const override;
19+
20+
private:
21+
ShaderManager::Effect m_effect = static_cast<ShaderManager::Effect>(0);
22+
std::string m_name;
23+
};
24+
25+
} // namespace scratchcpprender

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ add_subdirectory(penstate)
3636
add_subdirectory(penlayer)
3737
add_subdirectory(penlayerpainter)
3838
add_subdirectory(blocks)
39+
add_subdirectory(graphicseffect)

test/graphicseffect/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_executable(
2+
graphicseffect_test
3+
graphicseffect_test.cpp
4+
)
5+
6+
target_link_libraries(
7+
graphicseffect_test
8+
GTest::gtest_main
9+
scratchcpp-render
10+
qnanopainter
11+
)
12+
13+
add_test(graphicseffect_test)
14+
gtest_discover_tests(graphicseffect_test)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <graphicseffect.h>
2+
3+
#include "../common.h"
4+
5+
using namespace scratchcpprender;
6+
using namespace libscratchcpp;
7+
8+
TEST(GraphicsEffectTest, Constructor)
9+
{
10+
{
11+
GraphicsEffect effect(ShaderManager::Effect::Color, "color");
12+
ASSERT_EQ(effect.effect(), ShaderManager::Effect::Color);
13+
ASSERT_EQ(effect.name(), "color");
14+
15+
IGraphicsEffect *iface = dynamic_cast<IGraphicsEffect *>(&effect);
16+
ASSERT_TRUE(iface);
17+
ASSERT_EQ(iface->name(), "color");
18+
}
19+
20+
{
21+
GraphicsEffect effect(ShaderManager::Effect::Brightness, "brightness");
22+
ASSERT_EQ(effect.effect(), ShaderManager::Effect::Brightness);
23+
ASSERT_EQ(effect.name(), "brightness");
24+
25+
IGraphicsEffect *iface = dynamic_cast<IGraphicsEffect *>(&effect);
26+
ASSERT_TRUE(iface);
27+
ASSERT_EQ(iface->name(), "brightness");
28+
}
29+
}

0 commit comments

Comments
 (0)