Skip to content

Commit bb7589d

Browse files
committed
Feat: pass selected tool to preview [2/3]
1 parent 3c77dd9 commit bb7589d

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

lib/components/canvas/canvas.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ class Canvas extends StatelessWidget {
5454
} else if (currentTool is Highlighter) {
5555
return 4;
5656
} else if (currentTool is Eraser) {
57-
return 4;
57+
return 1;
5858
} else if (currentTool is Select) {
5959
return 3;
6060
} else if (currentTool is LaserPointer) {
6161
return 4;
6262
} else if (currentTool is Pen) {
6363
if ((currentTool as Pen).isPressureEnabled()) {
64-
return 0;
64+
return 2;
6565
} else {
6666
return 1;
6767
}
@@ -81,10 +81,11 @@ class Canvas extends StatelessWidget {
8181
}
8282
double getWidth() {
8383
if (currentTool is Highlighter) {
84-
print('highlighter detected');
85-
return 50.0;
84+
return (currentTool as Pen).getSize() * currentScale * 2;
85+
} else if (currentTool is Pen) {
86+
return (currentTool as Pen).getSize() * currentScale;
8687
} else {
87-
return 5;
88+
return 3.0;
8889
}
8990
}
9091

lib/data/tools/pen.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class Pen extends Tool {
7575
bool isPressureEnabled() {
7676
return pressureEnabled;
7777
}
78+
double getSize() {
79+
return options.size;
80+
}
7881

7982
void onDragStart(
8083
Offset position, EditorPage page, int pageIndex, double? pressure) {

packages/onyxsdk_pen/android/src/main/kotlin/com/example/onyxsdk_pen/OnyxsdkPenArea.kt

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import com.onyx.android.sdk.pen.NeoCharcoalPenV2
1717
import com.onyx.android.sdk.pen.NeoMarkerPen
1818
import com.onyx.android.sdk.pen.NeoFountainPen
1919
import com.onyx.android.sdk.pen.NeoPen
20-
import com.onyx.android.sdk.pen.style.StrokeStyle
2120
import com.onyx.android.sdk.api.device.epd.EpdController
2221
import io.flutter.plugin.platform.PlatformView
2322
import io.flutter.plugin.common.MethodChannel
@@ -47,7 +46,45 @@ internal class OnyxsdkPenArea(context: Context, messenger: BinaryMessenger, id:
4746
var strokeStyle = StrokeStyle.FountainPen
4847

4948
private fun updateStroke(paramsRef: Map<String, Any>?) {
50-
strokeColor = paramsRef?.get("strokeColor") as? Int ?: Color.BLACK
49+
/*
50+
Flutter ints are variable width
51+
Personally, I think it is utterly dumb. I hope there is a way to fix
52+
int size in flutter (why would you need 64 bits to store srgb??),
53+
but unless or until there isn't, this stupidity should be performed
54+
*/
55+
val pureColor = (paramsRef?.get("strokeColor") as? Long)?.toInt()
56+
?: paramsRef?.get("strokeColor") as? Int
57+
?: Color.BLACK
58+
/*
59+
ONYXSDK Pen saturates the colors. Whatever it deems as "light" (luma < 128?)
60+
gets automagically turned to white. Transparency is also accounted apparently.
61+
Unless this is some case-by-case situation, if resulting color, assuming
62+
being drawn on absolutely white background, with a fully opaque brush
63+
is lighter than a certain unknown arbitrary threshold, it turns white,
64+
otherwise, is saturated to max.
65+
These thoughts are, however, purely observational. Nothing in documentation
66+
says this and no binary artifacts have been decompiled to come to these
67+
conclusions. Thus, feel free to correct my incompetence if I turn out wrong
68+
*/
69+
var dest = FloatArray(3)
70+
Color.RGBToHSV(
71+
Color.red(pureColor),
72+
Color.green(pureColor),
73+
Color.blue(pureColor),
74+
dest
75+
)
76+
dest[1] = 1.0f /* saturation */
77+
/*
78+
I suppose rounding value is reasonable, but I want color to show
79+
So clamp to black if it's visually indistinguishable from black
80+
and to colorful otherwise. E.g. brown will look red instead of black
81+
*/
82+
if (dest[2] < 0.2) {
83+
dest[2] = 0.0f
84+
} else {
85+
dest[2] = 1.0f
86+
}
87+
strokeColor = Color.HSVToColor(dest)
5188
strokeWidth = (paramsRef?.get("strokeWidth") as? Double ?: 3.0).toFloat()
5289
strokeStyle = when (paramsRef?.get("strokeStyle") as? Int ?: 0) {
5390
0 -> StrokeStyle.FountainPen
@@ -149,9 +186,9 @@ internal class OnyxsdkPenArea(context: Context, messenger: BinaryMessenger, id:
149186
private fun strokeStyleToOnyx(style: StrokeStyle): Int {
150187
return when (style) {
151188
StrokeStyle.FountainPen -> TouchHelper.STROKE_STYLE_FOUNTAIN
152-
StrokeStyle.Pen -> TouchHelper.STROKE_STYLE_CHARCOAL_V2
189+
StrokeStyle.Pen -> TouchHelper.STROKE_STYLE_PENCIL
153190
StrokeStyle.Brush -> TouchHelper.STROKE_STYLE_NEO_BRUSH
154-
StrokeStyle.Pencil -> TouchHelper.STROKE_STYLE_PENCIL
191+
StrokeStyle.Pencil -> TouchHelper.STROKE_STYLE_CHARCOAL_V2
155192
StrokeStyle.Marker -> TouchHelper.STROKE_STYLE_MARKER
156193
}
157194
}

0 commit comments

Comments
 (0)