/* * InfiniPaint * Copyright (C) 2025-2026 Yousef Khadadeh * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "CanvasTheme.hpp" #include "DrawingProgram/DrawingProgram.hpp" #include #include "MainProgram.hpp" #include "World.hpp" using namespace NetworkingObjects; CanvasTheme::CanvasTheme(World& w): world(w) {} void CanvasTheme::server_init_no_file() { backColor = world.netObjMan.make_obj_direct(world.main.conf.defaultCanvasBackgroundColor); set_tool_front_color(world.drawProg); } SkColor4f CanvasTheme::get_back_color() const { if(!backColor) return SkColor4f{world.main.conf.defaultCanvasBackgroundColor.x(), world.main.conf.defaultCanvasBackgroundColor.y(), world.main.conf.defaultCanvasBackgroundColor.z(), 1.0f}; else return SkColor4f{backColor->c.x(), backColor->c.y(), backColor->c.z(), 1.0f}; } const SkColor4f& CanvasTheme::get_tool_front_color() const { return toolFrontColor; } void CanvasTheme::set_back_color(const Vector3f& newBackColor) { if(backColor && newBackColor != backColor->c) { backColor->c = newBackColor; world.delayedUpdateObjectManager.send_update_to_all(backColor, false); set_tool_front_color(world.drawProg); } } void CanvasTheme::set_tool_front_color(DrawingProgram& drawP) { Vector3f newHSV = rgb_to_hsv(backColor->c); if(newHSV.z() >= 0.6f) toolFrontColor = SkColor4f{0.0f, 0.0f, 0.0f, 1.0f}; else toolFrontColor = SkColor4f{1.0f, 1.0f, 1.0f, 1.0f}; drawP.drawCache.clear_own_cached_surfaces(); world.set_to_layout_gui_if_focus(); } void CanvasTheme::register_class() { world.delayedUpdateObjectManager.register_class(world.netObjMan, NetworkingObjects::DelayUpdateSerializedClassManager::CustomConstructors{ .postUpdateFunc = [&](BackColor& o) { set_tool_front_color(world.drawProg); } }); } void CanvasTheme::read_create_message(cereal::PortableBinaryInputArchive& a) { backColor = world.netObjMan.read_create_message(a, nullptr); } void CanvasTheme::write_create_message(cereal::PortableBinaryOutputArchive& a) const { backColor.write_create_message(a); } void CanvasTheme::save_file(cereal::PortableBinaryOutputArchive& a) const { a(convert_vec3(get_back_color())); } void CanvasTheme::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) { backColor = world.netObjMan.make_obj_direct(world.main.conf.defaultCanvasBackgroundColor); set_tool_front_color(world.drawProg); if(version < VersionNumber(0, 1, 0)) set_back_color(DEFAULT_CANVAS_BACKGROUND_COLOR); else { Vector3f canvasBackColor; a(canvasBackColor); const Vector3f OLD_DEFAULT_CANVAS_BACKGROUND_COLOR{0.12f, 0.12f, 0.12f}; if(version < VersionNumber(0, 3, 0) && canvasBackColor == OLD_DEFAULT_CANVAS_BACKGROUND_COLOR) set_back_color(DEFAULT_CANVAS_BACKGROUND_COLOR); else set_back_color(canvasBackColor); } }