Skip to content

Commit 819f9db

Browse files
committed
Prepare code for pen blocks
1 parent 69dff11 commit 819f9db

File tree

7 files changed

+89
-3
lines changed

7 files changed

+89
-3
lines changed

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ qt_add_qml_module(scratchcpp-render
7878
effecttransform.h
7979
)
8080

81+
target_sources(scratchcpp-render
82+
PRIVATE
83+
blocks/penblocks.cpp
84+
blocks/penblocks.h)
85+
8186
list(APPEND QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
8287
list(REMOVE_DUPLICATES QML_IMPORT_PATH)
8388
set(QML_IMPORT_PATH ${QML_IMPORT_PATH} CACHE STRING "" FORCE)

src/blocks/penblocks.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "penblocks.h"
2+
3+
using namespace scratchcpprender;
4+
using namespace libscratchcpp;
5+
6+
std::string PenBlocks::name() const
7+
{
8+
return "Pen";
9+
}
10+
11+
std::string PenBlocks::description() const
12+
{
13+
return name() + " blocks";
14+
}
15+
16+
Rgb PenBlocks::color() const
17+
{
18+
return rgb(15, 189, 140);
19+
}
20+
21+
void PenBlocks::registerBlocks(libscratchcpp::IEngine *engine)
22+
{
23+
}

src/blocks/penblocks.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <scratchcpp/iextension.h>
2+
3+
namespace scratchcpprender
4+
{
5+
6+
class PenBlocks : public libscratchcpp::IExtension
7+
{
8+
public:
9+
std::string name() const override;
10+
std::string description() const override;
11+
libscratchcpp::Rgb color() const override;
12+
13+
void registerBlocks(libscratchcpp::IEngine *engine) override;
14+
};
15+
16+
} // namespace scratchcpprender

src/projectloader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "valuemonitormodel.h"
1313
#include "listmonitormodel.h"
1414
#include "renderedtarget.h"
15-
// #include "blocks/penblocks.h"
15+
#include "blocks/penblocks.h"
1616

1717
using namespace scratchcpprender;
1818
using namespace libscratchcpp;
@@ -37,8 +37,8 @@ ProjectLoader::ProjectLoader(QObject *parent) :
3737
initTimer();
3838
m_renderTimer.start();
3939

40-
// TODO: Register pen blocks
41-
// ScratchConfiguration::registerExtension(std::make_shared<PenBlocks>());
40+
// Register pen blocks
41+
ScratchConfiguration::registerExtension(std::make_shared<PenBlocks>());
4242
}
4343

4444
ProjectLoader::~ProjectLoader()

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_subdirectory(penattributes)
3636
add_subdirectory(penstate)
3737
add_subdirectory(penlayer)
3838
add_subdirectory(penlayerpainter)
39+
add_subdirectory(blocks)
3940
add_subdirectory(graphicseffect)
4041
add_subdirectory(shadermanager)
4142
add_subdirectory(textbubbleshape)

test/blocks/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# pen_blocks_test
2+
add_executable(
3+
pen_blocks_test
4+
pen_blocks_test.cpp
5+
)
6+
7+
target_link_libraries(
8+
pen_blocks_test
9+
GTest::gtest_main
10+
GTest::gmock_main
11+
scratchcpp-render
12+
scratchcpprender_mocks
13+
${QT_LIBS}
14+
)
15+
16+
add_test(pen_blocks_test)
17+
gtest_discover_tests(pen_blocks_test)

test/blocks/pen_blocks_test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <scratchcpp/project.h>
2+
#include <enginemock.h>
3+
#include <gtest/gtest.h>
4+
5+
#include "blocks/penblocks.h"
6+
7+
using namespace scratchcpprender;
8+
using namespace libscratchcpp;
9+
10+
class PenBlocksTest : public testing::Test
11+
{
12+
public:
13+
void SetUp() override
14+
{
15+
m_extension = std::make_unique<PenBlocks>();
16+
m_engine = m_project.engine().get();
17+
m_extension->registerBlocks(m_engine);
18+
}
19+
20+
std::unique_ptr<IExtension> m_extension;
21+
Project m_project;
22+
IEngine *m_engine = nullptr;
23+
EngineMock m_engineMock;
24+
};

0 commit comments

Comments
 (0)