Add color sliders to sketch3d
This commit is contained in:
parent
70daeeea54
commit
5f0ce77fca
5 changed files with 127 additions and 5 deletions
|
|
@ -315,10 +315,6 @@ void Project::sample(halnf pressure, halnf cameraRatio, Vec2F relativeCameraPos)
|
||||||
if (idx) {
|
if (idx) {
|
||||||
auto brush = mBrushes.getSlotVal(idx);
|
auto brush = mBrushes.getSlotVal(idx);
|
||||||
|
|
||||||
if (brush->mType == "pencil") {
|
|
||||||
((tp::PencilBrush*) brush)->mCol = RGBA(1.f);
|
|
||||||
}
|
|
||||||
|
|
||||||
brush->sample(this, relativeCameraPos, pressure);
|
brush->sample(this, relativeCameraPos, pressure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,10 @@ namespace tp {
|
||||||
canvas.drawImage(this->mArea, &mImage, 0, 1, 12);
|
canvas.drawImage(this->mArea, &mImage, 0, 1, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setColor(const RGBA& color) {
|
||||||
|
((PencilBrush*) mProject.mBrushes.get("pencil"))->mCol = color;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class Mode {
|
enum class Mode {
|
||||||
MOVE, ROTATE, ZOOM, DRAW, NONE
|
MOVE, ROTATE, ZOOM, DRAW, NONE
|
||||||
|
|
@ -113,6 +117,21 @@ namespace tp {
|
||||||
mOptions.mContents.append(mMoveButton);
|
mOptions.mContents.append(mMoveButton);
|
||||||
mOptions.mContents.append(mRotateButton);
|
mOptions.mContents.append(mRotateButton);
|
||||||
mOptions.mContents.append(mZoomButton);
|
mOptions.mContents.append(mZoomButton);
|
||||||
|
|
||||||
|
// add color sliders
|
||||||
|
mRed = new NamedSliderWidget < Events, Canvas >("Red");
|
||||||
|
mGreen = new NamedSliderWidget < Events, Canvas >("Green");
|
||||||
|
mBlue = new NamedSliderWidget < Events, Canvas >("Blue");
|
||||||
|
|
||||||
|
mOptions.mContents.append(mRed);
|
||||||
|
mOptions.mContents.append(mGreen);
|
||||||
|
mOptions.mContents.append(mBlue);
|
||||||
|
}
|
||||||
|
|
||||||
|
~Sketch3DGUI() {
|
||||||
|
for (auto item : mOptions.mContents) {
|
||||||
|
delete item.data();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc(const Events& events, const RectF& areaParent, const RectF& area) override {
|
void proc(const Events& events, const RectF& areaParent, const RectF& area) override {
|
||||||
|
|
@ -133,6 +152,8 @@ namespace tp {
|
||||||
} else if (mZoomButton->mIsPressed) {
|
} else if (mZoomButton->mIsPressed) {
|
||||||
mViewport.mMode = Sketch3DWidget<Events, Canvas>::Mode::ZOOM;
|
mViewport.mMode = Sketch3DWidget<Events, Canvas>::Mode::ZOOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mViewport.setColor(RGBA(mRed->mSlider.mFactor, mGreen->mSlider.mFactor, mBlue->mSlider.mFactor, 1.f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(Canvas& canvas) override {
|
void draw(Canvas& canvas) override {
|
||||||
|
|
@ -154,5 +175,9 @@ namespace tp {
|
||||||
ButtonWidget<Events, Canvas>* mMoveButton = nullptr;
|
ButtonWidget<Events, Canvas>* mMoveButton = nullptr;
|
||||||
ButtonWidget<Events, Canvas>* mRotateButton = nullptr;
|
ButtonWidget<Events, Canvas>* mRotateButton = nullptr;
|
||||||
ButtonWidget<Events, Canvas>* mZoomButton = nullptr;
|
ButtonWidget<Events, Canvas>* mZoomButton = nullptr;
|
||||||
|
|
||||||
|
NamedSliderWidget<Events, Canvas>* mRed = nullptr;
|
||||||
|
NamedSliderWidget<Events, Canvas>* mGreen = nullptr;
|
||||||
|
NamedSliderWidget<Events, Canvas>* mBlue = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
98
Widgets/public/SliderWidget.hpp
Normal file
98
Widgets/public/SliderWidget.hpp
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "LabelWidget.hpp"
|
||||||
|
|
||||||
|
namespace tp {
|
||||||
|
|
||||||
|
template <typename Events, typename Canvas>
|
||||||
|
class SliderWidget : public Widget<Events, Canvas> {
|
||||||
|
public:
|
||||||
|
SliderWidget() {
|
||||||
|
this->createConfig("SliderWidget");
|
||||||
|
this->addColor("Default", "Base");
|
||||||
|
this->addColor("Handle", "Accent");
|
||||||
|
this->addColor("Hovered", "Interaction");
|
||||||
|
this->addColor("Scrolling", "Action");
|
||||||
|
this->addValue("Padding", "Padding");
|
||||||
|
this->addValue("HandleSize", 20.f);
|
||||||
|
this->addValue("MinSize", 20.f);
|
||||||
|
this->addValue("Rounding", "Rounding");
|
||||||
|
}
|
||||||
|
|
||||||
|
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
|
||||||
|
this->mArea = aArea;
|
||||||
|
this->mVisible = areaParent.isOverlap(aArea);
|
||||||
|
if (!this->mVisible) return;
|
||||||
|
|
||||||
|
if (events.isPressed(InputID::MOUSE1) && this->mArea.isInside(events.getPointer())) {
|
||||||
|
mIsSliding = true;
|
||||||
|
} else if (events.isReleased(InputID::MOUSE1)) {
|
||||||
|
mIsSliding = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mIsSliding) {
|
||||||
|
const auto handleSize = this->getValue("HandleSize");
|
||||||
|
mFactor = (events.getPointer().x - this->mArea.x - handleSize / 2.f) / (this->mArea.z - handleSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
mFactor = tp::clamp(mFactor, 0.f, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(Canvas& canvas) override {
|
||||||
|
if (!this->mVisible) return;
|
||||||
|
canvas.rect(this->mArea, this->getColor("Default"), this->getValue("Rounding"));
|
||||||
|
canvas.rect(getHandle(), this->getColor("Handle"), this->getValue("Rounding"));
|
||||||
|
}
|
||||||
|
|
||||||
|
RectF getHandle() const {
|
||||||
|
const auto handle = this->getValue("HandleSize");
|
||||||
|
const auto halfHandle = handle / 2.f;
|
||||||
|
const auto left = this->mArea.x + (this->mArea.z - handle) * mFactor;
|
||||||
|
return { left, this->mArea.y, handle, this->mArea.w };
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
halnf mFactor = 0.f;
|
||||||
|
bool mIsSliding = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Events, typename Canvas>
|
||||||
|
class NamedSliderWidget : public Widget<Events, Canvas> {
|
||||||
|
public:
|
||||||
|
NamedSliderWidget(const char* name = "Value") {
|
||||||
|
mLabel.mLabel = name;
|
||||||
|
this->mArea = { 0, 0, 100, 30 };
|
||||||
|
}
|
||||||
|
|
||||||
|
void proc(const Events& events, const tp::RectF& areaParent, const tp::RectF& aArea) override {
|
||||||
|
this->mArea = aArea;
|
||||||
|
this->mVisible = areaParent.isOverlap(aArea);
|
||||||
|
if (!this->mVisible) return;
|
||||||
|
|
||||||
|
const auto widthFirst = this->mArea.z * mFactor;
|
||||||
|
const auto widthSecond = this->mArea.z * (1.f - mFactor);
|
||||||
|
|
||||||
|
RectF rec = this->mArea;
|
||||||
|
rec.size.x = widthFirst;
|
||||||
|
|
||||||
|
mLabel.proc(events, this->mArea, rec);
|
||||||
|
|
||||||
|
rec.pos.x += widthFirst;
|
||||||
|
rec.size.x = widthSecond;
|
||||||
|
|
||||||
|
mSlider.proc(events, this->mArea, rec);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw(Canvas& canvas) override {
|
||||||
|
if (!this->mVisible) return;
|
||||||
|
mSlider.draw(canvas);
|
||||||
|
mLabel.draw(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
SliderWidget<Events, Canvas> mSlider;
|
||||||
|
LabelWidget<Events, Canvas> mLabel;
|
||||||
|
|
||||||
|
halnf mFactor = 0.5f;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -7,7 +7,9 @@ namespace tp {
|
||||||
template <typename Events, typename Canvas>
|
template <typename Events, typename Canvas>
|
||||||
class Widget {
|
class Widget {
|
||||||
public:
|
public:
|
||||||
Widget() = default;
|
Widget() {
|
||||||
|
this->mArea = { 0, 0, 100, 100 };
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] const RGBA& getColor(const String& name) const {
|
[[nodiscard]] const RGBA& getColor(const String& name) const {
|
||||||
const auto& node = cfg->values.get(name);
|
const auto& node = cfg->values.get(name);
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,5 @@
|
||||||
#include "ScrollableWidget.hpp"
|
#include "ScrollableWidget.hpp"
|
||||||
#include "SplitViewWidget.hpp"
|
#include "SplitViewWidget.hpp"
|
||||||
#include "TextInputWidget.hpp"
|
#include "TextInputWidget.hpp"
|
||||||
|
#include "SliderWidget.hpp"
|
||||||
#include "Animations.hpp"
|
#include "Animations.hpp"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue