More GUI code moved to events, code now compiles but application doesn't run
This commit is contained in:
parent
3566b7e563
commit
b4c35124c3
37 changed files with 913 additions and 879 deletions
|
|
@ -77,15 +77,6 @@ template <typename T> class ColorPicker : public Element {
|
|||
static constexpr float BAR_WIDTH = 30.0;
|
||||
static constexpr float BAR_GAP = 5.0;
|
||||
|
||||
|
||||
static sk_sp<SkShader> hueBarShader;
|
||||
static sk_sp<SkRuntimeEffect> svSelectionAreaEffect;
|
||||
static sk_sp<SkRuntimeEffect> alphaBarEffect;
|
||||
|
||||
static sk_sp<SkShader> get_hue_shader();
|
||||
static sk_sp<SkShader> get_sv_selection_shader(float hue);
|
||||
static sk_sp<SkShader> get_alpha_bar_shader(const Vector3f& mainColor, float horizontalResolution);
|
||||
|
||||
T* data;
|
||||
Vector3f savedHsv; // We save the HSV so that conversion doesnt ruin the UI
|
||||
std::function<void()> onChange;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
namespace GUIStuff {
|
||||
|
||||
template <typename T> ColorPicker<T>::ColorPicker(GUIManager& gui): Element(gui) {}
|
||||
|
||||
template <typename T> void ColorPicker<T>::layout(T* data, bool selectAlpha, const std::function<void()>& onChange) {
|
||||
this->data = data;
|
||||
savedHsv = rgb_to_hsv<T>(*data);
|
||||
savedHsv = rgb_to_hsv<Vector3f, T>(*data);
|
||||
this->selectAlpha = selectAlpha;
|
||||
this->onChange = onChange;
|
||||
|
||||
|
|
@ -29,7 +31,7 @@ template <typename T> void ColorPicker<T>::clay_draw(SkCanvas* canvas, UpdateInp
|
|||
canvas->clipRect(SkRect::MakeXYWH(0.0f, 0.0f, 1.0f, 1.0f), skiaAA);
|
||||
|
||||
SkPaint svSelectionAreaPaint;
|
||||
svSelectionAreaPaint.setShader(get_sv_selection_shader(savedHsv.x() / 360.0f));
|
||||
svSelectionAreaPaint.setShader(ColorPickerShaders::get_sv_selection_shader(savedHsv.x() / 360.0f));
|
||||
canvas->drawPaint(svSelectionAreaPaint);
|
||||
|
||||
SkPaint selectionLinePaint({1.0f, 1.0f, 1.0f, 1.0f});
|
||||
|
|
@ -50,7 +52,7 @@ template <typename T> void ColorPicker<T>::clay_draw(SkCanvas* canvas, UpdateInp
|
|||
canvas->clipRect(SkRect::MakeXYWH(0.0f, 0.0f, 1.0f, 1.0f), skiaAA);
|
||||
|
||||
SkPaint hueBarPaint;
|
||||
hueBarPaint.setShader(get_hue_shader());
|
||||
hueBarPaint.setShader(ColorPickerShaders::get_hue_shader());
|
||||
canvas->drawPaint(hueBarPaint);
|
||||
canvas->drawLine(0.0f, 1.0f - normalizedHue, 1.0f, 1.0f - normalizedHue, selectionLinePaint);
|
||||
|
||||
|
|
@ -64,7 +66,7 @@ template <typename T> void ColorPicker<T>::clay_draw(SkCanvas* canvas, UpdateInp
|
|||
|
||||
SkPaint alphaBarPaint;
|
||||
if(selectAlpha)
|
||||
alphaBarPaint.setShader(get_alpha_bar_shader({(*data)[0], (*data)[1], (*data)[2]}, alphaBarDim.x()));
|
||||
alphaBarPaint.setShader(ColorPickerShaders::get_alpha_bar_shader({(*data)[0], (*data)[1], (*data)[2]}, alphaBarDim.x()));
|
||||
else
|
||||
alphaBarPaint.setColor4f(SkColor4f{(*data)[0], (*data)[1], (*data)[2], 1.0f});
|
||||
canvas->drawPaint(alphaBarPaint);
|
||||
|
|
@ -103,7 +105,7 @@ template <typename T> bool ColorPicker<T>::input_mouse_button_callback(const Inp
|
|||
|
||||
template <typename T> bool ColorPicker<T>::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) {
|
||||
update_color_picker_pos(motion.pos);
|
||||
return Element::input_mouse_button_callback(motion, mouseHovering);
|
||||
return Element::input_mouse_motion_callback(motion, mouseHovering);
|
||||
}
|
||||
|
||||
template <typename T> void ColorPicker<T>::update_color_picker_pos(const Vector2f& p) {
|
||||
|
|
@ -111,6 +113,8 @@ template <typename T> void ColorPicker<T>::update_color_picker_pos(const Vector2
|
|||
gui.set_post_callback_func([&, p]() {
|
||||
auto& bb = boundingBox.value();
|
||||
switch(held) {
|
||||
case HeldBar::NONE:
|
||||
break;
|
||||
case HeldBar::SV_HELD: {
|
||||
float svSelectionAreaSize = bb.width() - (BAR_GAP + BAR_WIDTH);
|
||||
Vector2f newSv = cwise_vec_clamp<Vector2f>((p - bb.min) / svSelectionAreaSize, Vector2f{0.0f, 0.0f}, Vector2f{1.0f, 1.0f});
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@
|
|||
namespace GUIStuff {
|
||||
|
||||
struct ColorPickerButtonData {
|
||||
bool hasAlpha = false;
|
||||
bool hasAlpha = true;
|
||||
std::function<void()> onEdit;
|
||||
};
|
||||
|
||||
template <typename T> class ColorPickerButton : public Element {
|
||||
public:
|
||||
ColorPickerButton(GUIManager& gui);
|
||||
void layout(T* val, ColorPickerButtonData& d);
|
||||
void layout(T* val, const ColorPickerButtonData& d);
|
||||
private:
|
||||
ColorPickerButtonData data;
|
||||
bool isOpen = false;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#include "ColorPickerButton.decl.hpp"
|
||||
#include "../ElementHelpers/ColorPickerHelpers.hpp"
|
||||
#include "../ElementHelpers/ColorPickerItemsHelpers.hpp"
|
||||
#include "../ElementHelpers/ButtonHelpers.hpp"
|
||||
#include "../ElementHelpers/LayoutHelpers.hpp"
|
||||
|
||||
namespace GUIStuff {
|
||||
|
||||
template <typename T> ColorPickerButton<T>::ColorPickerButton(GUIManager& gui): Element(gui) {}
|
||||
|
||||
template <typename T> void ColorPickerButton<T>::layout(T* val, ColorPickerButtonData& d) {
|
||||
template <typename T> void ColorPickerButton<T>::layout(T* val, const ColorPickerButtonData& d) {
|
||||
this->data = d;
|
||||
|
||||
GUIStuff::ElementHelpers::color_button(gui, "Color Picker Button", val, {
|
||||
|
|
@ -17,7 +18,7 @@ template <typename T> void ColorPickerButton<T>::layout(T* val, ColorPickerButto
|
|||
}
|
||||
});
|
||||
if(isOpen) {
|
||||
top_to_bottom_window_popup_layout("Color Picker", CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&, val, data = data]() {
|
||||
ElementHelpers::top_to_bottom_window_popup_layout(gui, "Color Picker", CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&, val, data = data]() {
|
||||
ElementHelpers::color_picker_items(gui, "c", val, {
|
||||
.hasAlpha = data.hasAlpha,
|
||||
.onEdit = data.onEdit
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace GUIStuff {
|
||||
|
||||
sk_sp<SkRuntimeEffect> ColorRectangleDisplay::alphaBackgroundEffect;
|
||||
|
||||
ColorRectangleDisplay::ColorRectangleDisplay(GUIManager& gui): Element(gui) {}
|
||||
|
||||
void ColorRectangleDisplay::layout(const std::function<SkColor4f()>& colorFunc) {
|
||||
|
|
|
|||
|
|
@ -14,9 +14,8 @@ constexpr double ROTATE_BAR_SNAP_DISTRIBUTION = std::numbers::pi * 0.25;
|
|||
PaintCircleMenu::PaintCircleMenu(GUIManager& gui):
|
||||
Element(gui) {}
|
||||
|
||||
void PaintCircleMenu::layout(const Data& data, const std::function<void()>& onChange) {
|
||||
void PaintCircleMenu::layout(const Data& data) {
|
||||
d = data;
|
||||
this->onChange = onChange;
|
||||
|
||||
CLAY_AUTO_ID({
|
||||
.layout = {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class PaintCircleMenu : public Element {
|
|||
std::function<void()> onRotate;
|
||||
std::function<void()> onPaletteClick;
|
||||
};
|
||||
void layout(const Data& data, const std::function<void()>& onChange);
|
||||
void layout(const Data& data);
|
||||
virtual bool collides_with_point(const Vector2f& p) const override;
|
||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override;
|
||||
virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override;
|
||||
|
|
@ -22,7 +22,6 @@ class PaintCircleMenu : public Element {
|
|||
void draw_rotate_bar(SkCanvas* canvas, UpdateInputData& io, bool skiaAA);
|
||||
void draw_palette_bar(SkCanvas* canvas, UpdateInputData& io, bool skiaAA);
|
||||
Data d;
|
||||
std::function<void()> onChange;
|
||||
unsigned colorSelectionIndex = 0;
|
||||
bool isHovering = false;
|
||||
bool isRotateBarHeld = false;
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
|
||||
namespace GUIStuff {
|
||||
|
||||
template <typename T> TextBox<T>::TextBox(GUIManager& gui): Element(gui) {}
|
||||
|
||||
template <typename T> void TextBox<T>::layout(const TextBoxData<T>& userInfo) {
|
||||
auto& io = *gui.io;
|
||||
this->userInfo = userInfo;
|
||||
textbox->onUserTextEdit = [&] {
|
||||
if(userInfo.immutable)
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, toStr(*userInfo.data));
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
|
||||
else {
|
||||
if(update_data() && userInfo.onEdit)
|
||||
gui.set_post_callback_func(userInfo.onEdit);
|
||||
|
|
@ -79,7 +81,7 @@ template <typename T> bool TextBox<T>::input_mouse_button_callback(const InputMa
|
|||
gui.io->input->remove_rich_text_box_input(textbox);
|
||||
if(update_data())
|
||||
gui.set_post_callback_func(userInfo.onEdit);
|
||||
update_textbox(io);
|
||||
init_textbox(*gui.io);
|
||||
isSelected = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -115,7 +117,7 @@ template <typename T> void TextBox<T>::init_textbox(UpdateInputData& io) {
|
|||
cur = std::make_shared<RichText::TextBox::Cursor>();
|
||||
rect = std::make_shared<SCollision::AABB<float>>();
|
||||
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, toStr(*userInfo.data));
|
||||
cur->pos = cur->selectionBeginPos = cur->selectionEndPos = textbox->insert({0, 0}, userInfo.toStr(*userInfo.data));
|
||||
}
|
||||
|
||||
template <typename T> bool TextBox<T>::update_data() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue