2025-08-05 12:11:50 +03:00
|
|
|
#include "EyeDropperTool.hpp"
|
2025-12-26 10:40:58 +03:00
|
|
|
#include "../DrawingProgram.hpp"
|
|
|
|
|
#include "../../MainProgram.hpp"
|
|
|
|
|
#include "../../DrawData.hpp"
|
2025-08-02 20:10:33 +03:00
|
|
|
#include "DrawingProgramToolBase.hpp"
|
2025-07-06 20:43:53 +03:00
|
|
|
#include <include/core/SkAlphaType.h>
|
|
|
|
|
#include <include/core/SkCanvas.h>
|
|
|
|
|
#include <include/core/SkColor.h>
|
|
|
|
|
#include <include/core/SkColorType.h>
|
|
|
|
|
#include <include/core/SkRRect.h>
|
|
|
|
|
#include <include/core/SkRect.h>
|
|
|
|
|
#include <include/core/SkColorSpace.h>
|
|
|
|
|
#include <include/core/SkStream.h>
|
|
|
|
|
#include <include/core/SkSurface.h>
|
|
|
|
|
#include <Helpers/Logger.hpp>
|
|
|
|
|
|
2026-03-30 12:32:41 +03:00
|
|
|
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
|
|
|
|
#include "../../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp"
|
|
|
|
|
|
2025-08-05 12:11:50 +03:00
|
|
|
EyeDropperTool::EyeDropperTool(DrawingProgram& initDrawP):
|
2025-08-02 20:10:33 +03:00
|
|
|
DrawingProgramToolBase(initDrawP)
|
2025-07-06 20:43:53 +03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 12:11:50 +03:00
|
|
|
DrawingProgramToolType EyeDropperTool::get_type() {
|
|
|
|
|
return DrawingProgramToolType::EYEDROPPER;
|
2025-08-02 20:10:33 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-05 12:11:50 +03:00
|
|
|
void EyeDropperTool::gui_toolbox() {
|
2026-03-30 12:32:41 +03:00
|
|
|
using namespace GUIStuff;
|
|
|
|
|
using namespace ElementHelpers;
|
|
|
|
|
|
2025-07-06 20:43:53 +03:00
|
|
|
Toolbar& t = drawP.world.main.toolbar;
|
2026-01-26 19:08:36 +03:00
|
|
|
auto& selectingStrokeColor = drawP.world.main.toolConfig.eyeDropper.selectingStrokeColor;
|
2026-03-30 18:51:14 +03:00
|
|
|
t.gui.new_id("Color select tool", [&] {
|
|
|
|
|
text_label_centered(t.gui, "Color Select");
|
2026-03-30 12:32:41 +03:00
|
|
|
|
2026-03-30 18:51:14 +03:00
|
|
|
radio_button_selector<bool>(t.gui, "Stroke type", &selectingStrokeColor, {
|
|
|
|
|
{"Stroke Color", true},
|
|
|
|
|
{"Fill Color", false}
|
|
|
|
|
});
|
2026-03-30 12:32:41 +03:00
|
|
|
});
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
|
|
|
|
|
2026-03-30 12:32:41 +03:00
|
|
|
void EyeDropperTool::right_click_popup_gui(Vector2f popupPos) {
|
2025-12-01 17:33:14 +03:00
|
|
|
Toolbar& t = drawP.world.main.toolbar;
|
|
|
|
|
t.paint_popup(popupPos);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 09:54:43 +03:00
|
|
|
void EyeDropperTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
2026-01-26 19:08:36 +03:00
|
|
|
auto& toolConfig = drawP.world.main.toolConfig;
|
|
|
|
|
auto& selectingStrokeColor = drawP.world.main.toolConfig.eyeDropper.selectingStrokeColor;
|
|
|
|
|
|
2026-03-03 09:54:43 +03:00
|
|
|
if(button.button == InputManager::MouseButton::LEFT && button.down && !drawP.selection.is_being_transformed()) {
|
2026-03-20 20:53:59 +03:00
|
|
|
auto& surface = drawP.world.main.window.intermediateSurface;
|
2025-07-06 20:43:53 +03:00
|
|
|
|
2026-03-03 09:54:43 +03:00
|
|
|
int xPos = std::clamp<int>(button.pos.x(), 0, drawP.world.main.window.size.x() - 1);
|
|
|
|
|
int yPos = std::clamp<int>(button.pos.y(), 0, drawP.world.main.window.size.y() - 1);
|
2025-07-06 20:43:53 +03:00
|
|
|
|
|
|
|
|
Vector4<uint8_t> readData;
|
|
|
|
|
SkImageInfo readDataInfo = SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);
|
|
|
|
|
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
|
|
|
|
// NOT WORKING IN GRAPHITE YET
|
|
|
|
|
//surface->makeImageSnapshot()->readPixels(drawP.world.main.window.ctx.get(), readDataInfo, (void*)readData.data(), 4, xPos, yPos);
|
|
|
|
|
#elif USE_SKIA_BACKEND_GANESH
|
|
|
|
|
surface->makeImageSnapshot()->readPixels(drawP.world.main.window.ctx.get(), readDataInfo, (void*)readData.data(), 4, xPos, yPos);
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-09-26 10:39:26 +03:00
|
|
|
if(selectingStrokeColor)
|
2026-01-26 19:08:36 +03:00
|
|
|
toolConfig.globalConf.foregroundColor = readData.cast<float>() / 255.0f;
|
2025-09-26 10:39:26 +03:00
|
|
|
else
|
2026-01-26 19:08:36 +03:00
|
|
|
toolConfig.globalConf.backgroundColor = readData.cast<float>() / 255.0f;
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-03 09:54:43 +03:00
|
|
|
void EyeDropperTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EyeDropperTool::tool_update() {
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 12:11:50 +03:00
|
|
|
bool EyeDropperTool::prevent_undo_or_redo() {
|
2025-07-27 16:53:22 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 12:11:50 +03:00
|
|
|
void EyeDropperTool::draw(SkCanvas* canvas, const DrawData& drawData) {
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
2025-08-02 20:10:33 +03:00
|
|
|
|
2025-08-05 12:11:50 +03:00
|
|
|
void EyeDropperTool::switch_tool(DrawingProgramToolType newTool) {
|
2025-08-02 20:10:33 +03:00
|
|
|
}
|