Skip to content

Commit

Permalink
pen: disable pressure sensitivity for ballpoint pen
Browse files Browse the repository at this point in the history
  • Loading branch information
adil192 committed Nov 29, 2022
1 parent 01349a6 commit d508bc4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/components/canvas/_stroke.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class Stroke {
}..addAll(strokeProperties.toJson());

addPoint(EditorCoreInfo context, Offset offset, [ double? pressure ]) {
if (!strokeProperties.pressureEnabled) pressure = null;

double x = max(min(offset.dx, context.width), 0);
double y = max(min(offset.dy, context.height), 0);
Point point = Point(x, y, pressure ?? 0.5);
Expand Down Expand Up @@ -106,7 +108,7 @@ class Stroke {
taperEnd: strokeProperties.taperEnd,
capStart: strokeProperties.capStart,
capEnd: strokeProperties.capEnd,
simulatePressure: strokeProperties.simulatePressure,
simulatePressure: strokeProperties.simulatePressure && strokeProperties.pressureEnabled,
)
.map((Point point) => Offset(point.x, point.y))
.toList(growable: false);
Expand Down
4 changes: 3 additions & 1 deletion lib/components/canvas/tools/stroke_properties.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StrokeProperties {
double taperEnd = defaultTaperEnd;
bool capStart = defaultCapStart;
bool capEnd = defaultCapEnd;
bool pressureEnabled = defaultPressureEnabled; // todo: don't use pressure sensitivity if false
bool pressureEnabled = defaultPressureEnabled;
bool simulatePressure = defaultSimulatePressure;

StrokeProperties({
Expand All @@ -49,6 +49,7 @@ class StrokeProperties {
taperEnd = json['te'] ?? defaultTaperEnd;
capStart = json['cs'] ?? defaultCapStart;
capEnd = json['ce'] ?? defaultCapEnd;
pressureEnabled = json['pe'] ?? defaultPressureEnabled;
simulatePressure = json['sp'] ?? defaultSimulatePressure;
}
Map<String, dynamic> toJson() => {
Expand All @@ -61,6 +62,7 @@ class StrokeProperties {
if (taperEnd != defaultTaperEnd) 'te': taperEnd,
if (capStart != defaultCapStart) 'cs': capStart,
if (capEnd != defaultCapEnd) 'ce': capEnd,
if (pressureEnabled != defaultPressureEnabled) 'pe': pressureEnabled,
if (simulatePressure != defaultSimulatePressure) 'sp': simulatePressure,
};

Expand Down

0 comments on commit d508bc4

Please sign in to comment.