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>
|
|
|
|
|
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
|
|
|
|
#include <include/gpu/graphite/Surface.h>
|
|
|
|
|
#elif USE_SKIA_BACKEND_GANESH
|
|
|
|
|
#include <include/gpu/ganesh/GrDirectContext.h>
|
|
|
|
|
#include <include/gpu/ganesh/SkSurfaceGanesh.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <Helpers/Logger.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() {
|
2025-07-06 20:43:53 +03:00
|
|
|
Toolbar& t = drawP.world.main.toolbar;
|
|
|
|
|
t.gui.push_id("Color select tool");
|
|
|
|
|
t.gui.text_label_centered("Color Select");
|
2025-09-26 10:39:26 +03:00
|
|
|
if(t.gui.radio_button_field("Stroke Color", "Stroke Color", selectingStrokeColor)) selectingStrokeColor = true;
|
|
|
|
|
if(t.gui.radio_button_field("Fill Color", "Fill Color", !selectingStrokeColor)) selectingStrokeColor = false;
|
2025-07-06 20:43:53 +03:00
|
|
|
t.gui.pop_id();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-01 17:33:14 +03:00
|
|
|
bool EyeDropperTool::right_click_popup_gui(Vector2f popupPos) {
|
|
|
|
|
Toolbar& t = drawP.world.main.toolbar;
|
|
|
|
|
t.paint_popup(popupPos);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-15 15:36:42 +03:00
|
|
|
void EyeDropperTool::erase_component(const CanvasComponentContainer::ObjInfoSharedPtr& erasedComp) {
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 12:11:50 +03:00
|
|
|
void EyeDropperTool::tool_update() {
|
2025-07-06 20:43:53 +03:00
|
|
|
if(drawP.controls.leftClick) {
|
|
|
|
|
SkSurfaceProps props;
|
2025-08-20 11:17:05 +03:00
|
|
|
#ifdef USE_BACKEND_OPENGLES_3_0
|
|
|
|
|
SkImageInfo imgInfo = SkImageInfo::Make(drawP.world.main.window.size.x(), drawP.world.main.window.size.y(), kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
#else
|
2025-08-20 12:59:46 +03:00
|
|
|
SkImageInfo imgInfo = SkImageInfo::MakeN32Premul(drawP.world.main.window.size.x(), drawP.world.main.window.size.y());
|
2025-08-20 11:17:05 +03:00
|
|
|
#endif
|
2025-07-06 20:43:53 +03:00
|
|
|
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
|
|
|
|
sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(drawP.world.main.window.recorder(), imgInfo, skgpu::Mipmapped::kNo, &props);
|
|
|
|
|
#elif USE_SKIA_BACKEND_GANESH
|
|
|
|
|
sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(drawP.world.main.window.ctx.get(), skgpu::Budgeted::kNo, imgInfo, 0, &props);
|
|
|
|
|
#endif
|
|
|
|
|
if(!surface) {
|
2025-08-05 12:11:50 +03:00
|
|
|
Logger::get().log("INFO", "[SkSurfaces::WrapBackendRenderTarget] Eye Dropper Tool could not make surface");
|
2025-07-06 20:43:53 +03:00
|
|
|
return;
|
|
|
|
|
}
|
2025-08-05 12:11:50 +03:00
|
|
|
SkCanvas* eyeDropperCanvas = surface->getCanvas();
|
|
|
|
|
if(!eyeDropperCanvas) {
|
|
|
|
|
Logger::get().log("INFO", "Eye Dropper Tool could not make canvas");
|
2025-07-06 20:43:53 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int xPos = std::clamp<int>(drawP.world.main.input.mouse.pos.x(), 0, drawP.world.main.window.size.x() - 1);
|
|
|
|
|
int yPos = std::clamp<int>(drawP.world.main.input.mouse.pos.y(), 0, drawP.world.main.window.size.y() - 1);
|
|
|
|
|
|
2025-08-05 12:11:50 +03:00
|
|
|
eyeDropperCanvas->save();
|
2025-07-06 20:43:53 +03:00
|
|
|
drawP.world.drawData.dontUseDrawProgCache = true;
|
2025-08-05 12:11:50 +03:00
|
|
|
drawP.world.main.draw(eyeDropperCanvas);
|
2025-07-06 20:43:53 +03:00
|
|
|
drawP.world.drawData.dontUseDrawProgCache = false;
|
2025-08-05 12:11:50 +03:00
|
|
|
eyeDropperCanvas->restore();
|
2025-07-06 20:43:53 +03:00
|
|
|
//drawP.world.main.window.ctx->flush();
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
drawP.controls.foregroundColor = readData.cast<float>() / 255.0f;
|
|
|
|
|
else
|
|
|
|
|
drawP.controls.backgroundColor = readData.cast<float>() / 255.0f;
|
2025-07-06 20:43:53 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|