מודולים

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. InProgressStroke is used to render partial strokes with low latency and to build the final Stroke once input is complete, after which the object can be reused. InProgressStroke is used by the InProgressStrokes composable.
  • Stroke: An immutable representation of a finalized stroke with fixed geometry. Each Stroke has an ImmutableStrokeInputBatch (input points), a Brush (style), and a PartitionedMesh (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.

רינדור

מודול העיבוד מפשט את ציור המשיכות של הדיו ב-Android Canvas. הוא מספק CanvasStrokeRenderer לכתיבה וViewStrokeRenderer לפריסות מבוססות-תצוגה. המעבדים האלה מבצעים אופטימיזציה של ביצועי העיבוד ועוזרים לספק תוכן ויזואלי באיכות גבוהה, כולל החלקת קצוות.

כדי לעבד את הקווים, קוראים ל-method‏ create() כדי לקבל מופע CanvasStrokeRenderer, ואז קוראים ל-method‏ draw() כדי לעבד קווים שהושלמו (Stroke) או קווים בתהליך (InProgressStroke) על Canvas.

אפשר לשנות את הצורה של הקנבס כשמציירים קו. לדוגמה, הזזה, שינוי גודל וסיבוב. כדי שהקו יופיע בצורה נכונה, צריך להעביר גם את טרנספורמציית canvas אל CanvasStrokeRenderer.draw.

כדי להימנע ממעקב נפרד של טרנספורמציית canvas, משתמשים במקום זאת ב-ViewStrokeRenderer.

אחסון

מודול האחסון מספק כלי עזר לסדרות ולביטול סדרות של נתוני משיכות מכחול בצורה יעילה, ומתמקד בעיקר ב-StrokeInputBatch.

המודול משתמש במאגרי פרוטוקולים ובטכניקות אופטימליות של דחיסת דלתא, וכך חוסך נפח אחסון משמעותי בהשוואה לשיטות פשוטות.

מודול האחסון מפשט את השמירה, הטעינה והשיתוף של משיכות המכחול.