Modul

Ink API dimodularisasi, sehingga Anda hanya dapat menggunakan apa yang Anda butuhkan.

Gaya Renang

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.

Geometri

Modul Geometry mendukung operasi geometris pada bentuk dasar (menggunakan class khusus seperti Box dan Vec), serta bentuk arbitrer (menggunakan PartitionedMesh), termasuk deteksi dan transformasi persimpangan. PartitionedMesh juga dapat menyimpan data tambahan untuk mendukung rendering.

Kuas

The brush module defines the style of strokes. It consists of two main parts:

  • Brush: Specifies the style of a stroke including base color, base size, and BrushFamily. BrushFamily is analogous to a font family, it defines a stroke's style. For example, a BrushFamily can represent a specific style of marker or highlighter, allowing strokes with different sizes and colors to share that style.
  • StockBrushes: Provides factory functions for creating ready-to-use BrushFamily instances.

Pembuatan

Modul Penulisan Compose memungkinkan Anda merekam input sentuhan pengguna dan merendernya sebagai goresan latensi rendah di layar secara real time. Hal ini dicapai melalui composable InProgressStrokes, yang memproses peristiwa gerakan dan menampilkan goresan saat digambar.

Setelah goresan selesai, composable akan memberi tahu aplikasi klien menggunakan callback InProgressStrokesFinishedListener. Hal ini memungkinkan aplikasi mengambil goresan yang telah selesai untuk rendering atau penyimpanan.

Di Compose, InProgressStrokes menggunakan callback ini dalam parameter onStrokesFinished. Teruskan guratan yang telah selesai ke composable lain untuk menerapkannya ke layar menggunakan modul rendering.

Rendering

Modul Rendering menyederhanakan penggambaran goresan tinta ke Canvas Android. Library ini menyediakan CanvasStrokeRenderer untuk Compose dan ViewStrokeRenderer untuk tata letak berbasis tampilan. Renderer ini mengoptimalkan performa rendering dan membantu memberikan visual berkualitas tinggi, termasuk antialiasing.

Untuk merender goresan, panggil metode create() untuk mendapatkan instance CanvasStrokeRenderer, lalu panggil metode draw() untuk merender goresan yang sudah selesai (Stroke) atau sedang dalam proses (InProgressStroke) ke Canvas.

Anda dapat mengubah kanvas saat menggambar goresan. Contohnya mencakup menggeser, melakukan zoom, dan memutar. Untuk merender goresan dengan benar, Anda juga harus meneruskan transformasi canvas ke CanvasStrokeRenderer.draw.

Untuk menghindari pelacakan transformasi canvas secara terpisah, gunakan ViewStrokeRenderer.

Penyimpanan

The storage module provides utilities for efficiently serializing and deserializing stroke data, primarily focusing on StrokeInputBatch.

The module uses protocol buffers and optimized delta compression techniques, resulting in significant storage savings compared to naive methods.

The storage module simplifies saving, loading, and sharing strokes.