|
| 1 | +/* |
| 2 | + * |
| 3 | + * * Copyright 2025 Google LLC. All rights reserved. |
| 4 | + * * |
| 5 | + * * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * * you may not use this file except in compliance with the License. |
| 7 | + * * You may obtain a copy of the License at |
| 8 | + * * |
| 9 | + * * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * * |
| 11 | + * * Unless required by applicable law or agreed to in writing, software |
| 12 | + * * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * * See the License for the specific language governing permissions and |
| 15 | + * * limitations under the License. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +package com.example.cahier.developer.brushdesigner.data |
| 20 | + |
| 21 | +import androidx.ink.strokes.Stroke |
| 22 | +import ink.proto.BrushCoat as ProtoBrushCoat |
| 23 | +import ink.proto.BrushFamily as ProtoBrushFamily |
| 24 | +import ink.proto.BrushPaint as ProtoBrushPaint |
| 25 | +import ink.proto.BrushTip as ProtoBrushTip |
| 26 | +import ink.proto.ColorFunction as ProtoColorFunction |
| 27 | +import javax.inject.Inject |
| 28 | +import javax.inject.Singleton |
| 29 | +import kotlinx.coroutines.flow.MutableStateFlow |
| 30 | +import kotlinx.coroutines.flow.StateFlow |
| 31 | +import kotlinx.coroutines.flow.asStateFlow |
| 32 | + |
| 33 | +@Singleton |
| 34 | +class BrushDesignerRepository @Inject constructor() { |
| 35 | + |
| 36 | + private val initialProto: ProtoBrushFamily = ProtoBrushFamily.newBuilder() |
| 37 | + .addCoats( |
| 38 | + ProtoBrushCoat.newBuilder() |
| 39 | + .setTip( |
| 40 | + ProtoBrushTip.newBuilder().setScaleX(1f).setScaleY(1f).setCornerRounding(1f) |
| 41 | + ) |
| 42 | + .addPaintPreferences( |
| 43 | + ProtoBrushPaint.newBuilder() |
| 44 | + .setSelfOverlap(ProtoBrushPaint.SelfOverlap.SELF_OVERLAP_ANY) |
| 45 | + .addColorFunctions( |
| 46 | + ProtoColorFunction.newBuilder() |
| 47 | + .setOpacityMultiplier(1f) |
| 48 | + ) |
| 49 | + ) |
| 50 | + ) |
| 51 | + .setInputModel( |
| 52 | + ProtoBrushFamily.InputModel.newBuilder() |
| 53 | + .setSlidingWindowModel( |
| 54 | + ProtoBrushFamily.SlidingWindowModel.newBuilder() |
| 55 | + .setWindowSizeSeconds(0.02f) |
| 56 | + .setExperimentalUpsamplingPeriodSeconds(0.005f) |
| 57 | + ) |
| 58 | + ) |
| 59 | + .build() |
| 60 | + |
| 61 | + private val _activeBrushProto = MutableStateFlow(initialProto) |
| 62 | + val activeBrushProto: StateFlow<ProtoBrushFamily> = _activeBrushProto.asStateFlow() |
| 63 | + |
| 64 | + private val _testStrokes = MutableStateFlow<List<Stroke>>(emptyList()) |
| 65 | + val testStrokes: StateFlow<List<Stroke>> = _testStrokes.asStateFlow() |
| 66 | + |
| 67 | + fun updateActiveBrushProto(proto: ProtoBrushFamily) { |
| 68 | + _activeBrushProto.value = proto |
| 69 | + } |
| 70 | + |
| 71 | + fun updateTestStrokes(strokes: List<Stroke>) { |
| 72 | + _testStrokes.value = strokes |
| 73 | + } |
| 74 | +} |
0 commit comments