Refactor
This commit is contained in:
parent
49cfe70c0d
commit
72c4740f82
18 changed files with 592 additions and 203 deletions
|
|
@ -52,6 +52,36 @@ void Canvas::rect(RectF rec, const RGBA& col, halnf round) {
|
|||
nvgFill(mContext->vg);
|
||||
}
|
||||
|
||||
void Canvas::debugCross(RectF rec, const RGBA& col) {
|
||||
nvgBeginPath(mContext->vg);
|
||||
|
||||
nvgMoveTo(mContext->vg, rec.p1().x, rec.p1().y);
|
||||
nvgLineTo(mContext->vg, rec.p3().x, rec.p3().y);
|
||||
|
||||
nvgMoveTo(mContext->vg, rec.p2().x, rec.p2().y);
|
||||
nvgLineTo(mContext->vg, rec.p4().x, rec.p4().y);
|
||||
|
||||
nvgStrokeWidth(mContext->vg, 2);
|
||||
nvgStrokeColor(mContext->vg, { col.r, col.g, col.b, col.a });
|
||||
nvgStroke(mContext->vg);
|
||||
// nvgFill(mContext->vg);
|
||||
}
|
||||
|
||||
void Canvas::frame(RectF rec, const RGBA& col, halnf round) {
|
||||
nvgBeginPath(mContext->vg);
|
||||
|
||||
nvgMoveTo(mContext->vg, rec.p1().x, rec.p1().y);
|
||||
nvgLineTo(mContext->vg, rec.p2().x, rec.p2().y);
|
||||
nvgLineTo(mContext->vg, rec.p3().x, rec.p3().y);
|
||||
nvgLineTo(mContext->vg, rec.p4().x, rec.p4().y);
|
||||
nvgLineTo(mContext->vg, rec.p1().x, rec.p1().y);
|
||||
|
||||
nvgStrokeWidth(mContext->vg, 2);
|
||||
nvgStrokeColor(mContext->vg, { col.r, col.g, col.b, col.a });
|
||||
nvgStroke(mContext->vg);
|
||||
// nvgFill(mContext->vg);
|
||||
}
|
||||
|
||||
void Canvas::circle(Vec2F pos, halnf size, const RGBA& col) {
|
||||
pos += mOrigin;
|
||||
|
||||
|
|
|
|||
|
|
@ -122,16 +122,22 @@ Vec2F EventHandler::getPointer() const { return mPointer - mPointerOrigin; }
|
|||
Vec2F EventHandler::getPointerPrev() const { return mPointerPrev - mPointerOrigin; }
|
||||
|
||||
bool EventHandler::isPressed(InputID id) const {
|
||||
if (!mEnableKeyEvents) return false;
|
||||
return mInputStates[(int) id].mCurrentState == InputState::State::PRESSED;
|
||||
}
|
||||
|
||||
bool EventHandler::isReleased(InputID id) const {
|
||||
if (!mEnableKeyEvents) return false;
|
||||
return mInputStates[(int) id].mCurrentState == InputState::State::RELEASED;
|
||||
}
|
||||
|
||||
halnf EventHandler::getPointerPressure() const { return mPointerPressure; }
|
||||
halnf EventHandler::getPointerPressure() const {
|
||||
if (!mEnableKeyEvents) return 0;
|
||||
return mPointerPressure;
|
||||
}
|
||||
|
||||
bool EventHandler::isDown(InputID id) const {
|
||||
if (!mEnableKeyEvents) return false;
|
||||
return mInputStates[(int) id].mCurrentState == InputState::State::PRESSED ||
|
||||
mInputStates[(int) id].mCurrentState == InputState::State::HOLD;
|
||||
}
|
||||
|
|
@ -139,3 +145,7 @@ bool EventHandler::isDown(InputID id) const {
|
|||
halnf EventHandler::getScrollY() const { return mScrollDelta.y; }
|
||||
|
||||
Vec2F EventHandler::getPointerDelta() const { return mPointer - mPointerPrev; }
|
||||
|
||||
void EventHandler::setEnableKeyEvents(bool enable) {
|
||||
mEnableKeyEvents = enable;
|
||||
}
|
||||
|
|
@ -73,7 +73,6 @@ namespace tp {
|
|||
void processEvent();
|
||||
void processAllEvent();
|
||||
|
||||
|
||||
void setCursorOrigin(const Vec2F& origin);
|
||||
|
||||
[[nodiscard]] Vec2F getPointer() const;
|
||||
|
|
@ -87,6 +86,8 @@ namespace tp {
|
|||
|
||||
[[nodiscard]] halnf getPointerPressure() const;
|
||||
|
||||
void setEnableKeyEvents(bool);
|
||||
|
||||
private:
|
||||
void processEventUnguarded();
|
||||
|
||||
|
|
@ -108,6 +109,8 @@ namespace tp {
|
|||
InputState mInputStates[(int) InputID::LAST_KEY_CODE]{};
|
||||
|
||||
Timer mTimerEvent = Timer(1000);
|
||||
|
||||
bool mEnableKeyEvents = true;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -60,7 +60,9 @@ namespace tp {
|
|||
void pushClamp(const RectF& rec);
|
||||
void popClamp();
|
||||
|
||||
void debugCross(RectF rec, const RGBA& col);
|
||||
void rect(RectF rec, const RGBA& col, halnf round = 0);
|
||||
void frame(RectF rec, const RGBA& col, halnf round = 0);
|
||||
void circle(Vec2F pos, halnf size, const RGBA& col);
|
||||
void text(const char*, const RectF&, halnf size, Align, halnf padding, const RGBA&);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue