Fixed cache not updating when canvas color updated

This commit is contained in:
Yousef Khadadeh 2025-08-18 08:16:29 +03:00
parent 1e30e3596d
commit 32c9329e4f
3 changed files with 11 additions and 2 deletions

View file

@ -54,8 +54,7 @@ DrawingProgram::DrawingProgram(World& initWorld):
components.clientInsertCallback(c);
};
components.clientServerFirstPosShiftCallback = [&](uint64_t firstShiftPos) {
compCache.clear_own_cached_surfaces();
selection.clear_own_cached_surfaces();
clear_draw_cache();
};
}
@ -171,6 +170,11 @@ std::unordered_set<ServerClientID> DrawingProgram::get_used_resources() {
return toRet;
}
void DrawingProgram::clear_draw_cache() {
compCache.clear_own_cached_surfaces();
selection.clear_own_cached_surfaces();
}
void DrawingProgram::toolbar_gui() {
Toolbar& t = world.main.toolbar;
CLAY({

View file

@ -53,6 +53,8 @@ class DrawingProgram {
void switch_to_tool(DrawingProgramToolType newToolType);
void switch_to_tool_ptr(std::unique_ptr<DrawingProgramToolBase> newTool);
void clear_draw_cache();
private:
void client_erase_set(std::unordered_set<CollabListType::ObjectInfoPtr> erasedComponents); // The set might be modified while this is being called, so dont pass by reference

View file

@ -175,10 +175,13 @@ void World::set_canvas_background_color(const Vector3f& newBackColor, bool sendC
if(newBackColor != convert_vec3<Vector3f>(canvasTheme.backColor)) {
canvasTheme.backColor = SkColor4f{newBackColor.x(), newBackColor.y(), newBackColor.z(), 1.0f};
Vector3f newHSV = rgb_to_hsv<Vector3f>(newBackColor);
SkColor4f oldToolFrontColor = canvasTheme.toolFrontColor;
if(newHSV.z() >= 0.6f)
canvasTheme.toolFrontColor = SkColor4f{0.0f, 0.0f, 0.0f, 1.0f};
else
canvasTheme.toolFrontColor = SkColor4f{1.0f, 1.0f, 1.0f, 1.0f};
if(oldToolFrontColor != canvasTheme.toolFrontColor)
drawProg.clear_draw_cache();
if(sendChangeOverNetwork)
con.client_send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_CANVAS_COLOR, newBackColor);
}