-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <Geode/Geode.hpp> | ||
|
||
namespace allium { | ||
enum class BrushType { | ||
None, | ||
Line, | ||
Curve, | ||
Free | ||
}; | ||
|
||
class BrushDrawer; | ||
|
||
class BrushManager { | ||
public: | ||
static BrushManager* get(); | ||
|
||
BrushType m_currentBrush = BrushType::None; | ||
BrushDrawer* m_currentDrawer = nullptr; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#pragma once | ||
|
||
#include <Geode/ui/Popup.hpp> | ||
|
||
namespace allium { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <Geode/Geode.hpp> | ||
|
||
namespace allium { | ||
class BrushDrawer : public cocos2d::CCNode { | ||
protected: | ||
cocos2d::CCDrawNode* m_overlay = nullptr; | ||
public: | ||
bool init() override; | ||
|
||
virtual bool handleTouchStart(cocos2d::CCPoint const& point); | ||
virtual void handleTouchMove(cocos2d::CCPoint const& point); | ||
virtual void handleTouchEnd(cocos2d::CCPoint const& point); | ||
|
||
virtual void updateOverlay(); | ||
void clearOverlay(); | ||
|
||
virtual void updateLine(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#pragma once | ||
|
||
#include "BrushDrawer.hpp" | ||
|
||
namespace allium { | ||
class LineBrushDrawer : public BrushDrawer { | ||
protected: | ||
cocos2d::CCPoint m_firstPoint = ccp(0, 0); | ||
cocos2d::CCPoint m_lastPoint = ccp(0, 0); | ||
|
||
// Todo: Implement adjustable line width | ||
float m_lineWidth = 5.0f; | ||
// Todo: Implement adjustable line color | ||
cocos2d::ccColor3B m_lineColor = cocos2d::ccc3(255, 255, 255); | ||
|
||
public: | ||
static LineBrushDrawer* create(); | ||
bool init() override; | ||
|
||
bool handleTouchStart(cocos2d::CCPoint const& point) override; | ||
void handleTouchMove(cocos2d::CCPoint const& point) override; | ||
void handleTouchEnd(cocos2d::CCPoint const& point) override; | ||
|
||
void updateOverlay() override; | ||
|
||
void updateLine() override; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <manager/BrushManager.hpp> | ||
|
||
using namespace geode::prelude; | ||
using namespace allium; | ||
|
||
BrushManager* BrushManager::get() { | ||
static BrushManager* instance = nullptr; | ||
if (!instance) { | ||
instance = new (std::nothrow) BrushManager(); | ||
} | ||
return instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <util/BrushDrawer.hpp> | ||
|
||
using namespace geode::prelude; | ||
using namespace allium; | ||
|
||
bool BrushDrawer::init() { | ||
m_overlay = cocos2d::CCDrawNode::create(); | ||
this->addChild(m_overlay); | ||
|
||
return true; | ||
} | ||
|
||
bool BrushDrawer::handleTouchStart(cocos2d::CCPoint const& point) { | ||
return true; | ||
} | ||
void BrushDrawer::handleTouchMove(cocos2d::CCPoint const& point) {} | ||
void BrushDrawer::handleTouchEnd(cocos2d::CCPoint const& point) {} | ||
|
||
void BrushDrawer::updateOverlay() {} | ||
void BrushDrawer::clearOverlay() { | ||
m_overlay->clear(); | ||
} | ||
|
||
void BrushDrawer::updateLine() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <util/LineBrushDrawer.hpp> | ||
|
||
using namespace geode::prelude; | ||
using namespace allium; | ||
|
||
LineBrushDrawer* LineBrushDrawer::create() { | ||
auto ret = new (std::nothrow) LineBrushDrawer(); | ||
if (ret && ret->init()) { | ||
ret->autorelease(); | ||
return ret; | ||
} | ||
delete ret; | ||
return nullptr; | ||
} | ||
|
||
bool LineBrushDrawer::init() { | ||
if (!BrushDrawer::init()) return false; | ||
|
||
return true; | ||
} | ||
|
||
bool LineBrushDrawer::handleTouchStart(cocos2d::CCPoint const& point) { | ||
m_firstPoint = point; | ||
m_lastPoint = point; | ||
this->updateOverlay(); | ||
return true; | ||
} | ||
void LineBrushDrawer::handleTouchMove(cocos2d::CCPoint const& point) { | ||
m_lastPoint = point; | ||
this->updateOverlay(); | ||
} | ||
void LineBrushDrawer::handleTouchEnd(cocos2d::CCPoint const& point) { | ||
m_lastPoint = point; | ||
this->clearOverlay(); | ||
this->updateLine(); | ||
} | ||
|
||
void LineBrushDrawer::updateOverlay() { | ||
this->clearOverlay(); | ||
m_overlay->drawSegment(m_firstPoint, m_lastPoint, m_lineWidth / 2.f, ccc4FFromccc3B(m_lineColor)); | ||
} | ||
|
||
void LineBrushDrawer::updateLine() { | ||
static constexpr int SQUARE_OBJECT_ID = 211; | ||
static constexpr int WHITE_COLOR_ID = 1011; | ||
|
||
auto center = (m_firstPoint + m_lastPoint) / 2.0f; | ||
|
||
auto angle = std::atan2(m_lastPoint.y - m_firstPoint.y, m_lastPoint.x - m_firstPoint.x); | ||
|
||
auto offsetFirst = m_firstPoint - ccp(m_lineWidth / 2.f, 0).rotateByAngle(ccp(0, 0), angle); | ||
auto offsetLast = m_lastPoint + ccp(m_lineWidth / 2.f, 0).rotateByAngle(ccp(0, 0), angle); | ||
|
||
auto object = LevelEditorLayer::get()->createObject(SQUARE_OBJECT_ID, center, false); | ||
object->setRotation(-angle * 180.0f / M_PI); | ||
|
||
auto scaleX = offsetFirst.getDistance(offsetLast) / 30.f; | ||
auto scaleY = m_lineWidth / 30.f; | ||
|
||
object->updateCustomScaleX(scaleX); | ||
object->updateCustomScaleY(scaleY); | ||
|
||
if (object->m_baseColor) { | ||
object->m_baseColor->m_colorID = WHITE_COLOR_ID; | ||
object->m_shouldUpdateColorSprite = true; | ||
} | ||
if (object->m_detailColor) { | ||
object->m_detailColor->m_colorID = WHITE_COLOR_ID; | ||
object->m_shouldUpdateColorSprite = true; | ||
} | ||
} |