تم تقسيم Ink API إلى وحدات، ما يتيح لك استخدام ما تحتاج إليه فقط.
الضربات
The strokes module serves as the foundation of the Ink API. Key data types within this module are:
StrokeInputBatch: Represents a series of pointer inputs, including their position, timestamp, and optionally pressure, tilt, and orientation.InProgressStroke: Represents a stroke that is actively being drawn.InProgressStrokeis used to render partial strokes with low latency and to build the finalStrokeonce input is complete, after which the object can be reused.InProgressStrokeis used by theInProgressStrokescomposable.Stroke: An immutable representation of a finalized stroke with fixed geometry. EachStrokehas anImmutableStrokeInputBatch(input points), aBrush(style), and aPartitionedMesh(geometric shape). You can store, manipulate, and render strokes within your application.
هندسة
يتيح نموذج Geometry إجراء عمليات هندسية على الأشكال الأساسية (باستخدام فئات مخصّصة مثل Box وVec)، بالإضافة إلى الأشكال العشوائية (باستخدام PartitionedMesh)، بما في ذلك رصد التقاطع والتحويل. يمكن أن يحتوي PartitionedMesh أيضًا على بيانات إضافية للمساعدة في العرض.
فرشاة
يحدّد الوحدة brush نمط الخطوط. ويتألف من جزأين رئيسيين:
Brush: تحدّد هذه السمة نمط الخط، بما في ذلك اللون الأساسي والحجم الأساسي وBrushFamily.BrushFamilyمشابهة لمجموعة خطوط، فهي تحدد نمطًا للسكتة الدماغية. على سبيل المثال، يمكن أن يمثّلBrushFamilyنمطًا معيّنًا من أقلام التحديد أو أقلام التمييز، ما يتيح مشاركة هذا النمط مع ضربات بأحجام وألوان مختلفة.-
StockBrushes: توفّر هذه السمة دوال مصنع لإنشاء مثيلاتBrushFamilyجاهزة للاستخدام.
التأليف
The Compose Authoring module lets you capture user touch input and render it
as low-latency strokes on the screen in real time. This is achieved through
the InProgressStrokes composable, which processes motion events and displays
the strokes as they are drawn.
Once a stroke is completed, the composable notifies the client application using
an InProgressStrokesFinishedListener callback. This allows the application
to retrieve the finished strokes for rendering or storage.
In Compose, InProgressStrokes takes this callback in the onStrokesFinished
parameter. Pass the finished strokes to another composable to commit them to the
screen using the rendering module.
العرض
تسهّل وحدة "العرض" رسم ضربات الحبر على Canvas يعمل بنظام التشغيل Android.
توفّر هذه السمة CanvasStrokeRenderer لـ Compose وViewStrokeRenderer للتنسيقات المستندة إلى العرض. تعمل أدوات العرض هذه على تحسين أداء العرض وتساعد في تقديم صور عالية الجودة، بما في ذلك التنعيم.
لعرض ضربات الفرشاة، استدعِ طريقة create() للحصول على مثيل CanvasStrokeRenderer، ثم استدعِ طريقة draw() لعرض ضربات الفرشاة المكتملة (Stroke) أو الجاري تنفيذها (InProgressStroke) على Canvas.
يمكنك تغيير شكل لوحة العرض عند رسم خط. وتشمل الأمثلة تحريك الكاميرا أفقيًا أو عموديًا وتكبير الصورة وتدويرها. لعرض الضربة بشكل صحيح، يجب أيضًا تمرير عملية التحويل canvas إلى CanvasStrokeRenderer.draw.
لتجنُّب تتبُّع عملية التحويل canvas بشكل منفصل، استخدِم ViewStrokeRenderer بدلاً من ذلك.
مساحة التخزين
يوفّر وحدة التخزين أدوات لتسلسل بيانات ضربات الفرشاة وإلغاء تسلسلها بكفاءة، مع التركيز بشكل أساسي على StrokeInputBatch.
تستخدم الوحدة مخازن مؤقتة للبروتوكول وتقنيات ضغط دلتا محسّنة، ما يؤدي إلى توفير كبير في مساحة التخزين مقارنةً بالطرق البسيطة.
تسهّل وحدة التخزين حفظ اللمسات وتحميلها ومشاركتها.