Moduły

Ink API jest podzielony na moduły, więc możesz używać tylko tych funkcji, których potrzebujesz.

Pociągnięcia

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 InProgressStrokesView.
  • 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.

Geometria

Moduł Geometry obsługuje operacje geometryczne na kształtach podstawowych (przy użyciu dedykowanych klas, takich jak BoxVec), a także na dowolnych kształtach (przy użyciu PartitionedMesh), w tym wykrywanie przecięć i transformacje. PartitionedMesh może też zawierać dodatkowe dane potrzebne do renderowania.

Pędzel

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.

Tworzenie

The Authoring module lets you capture user pointer input and render it as low-latency strokes on the screen in real time. It provides an InProgressStrokesView, which processes motion events and displays the strokes as they are drawn.

Once a stroke is completed, the view notifies the client application by means of a registered callback (InProgressStrokesFinishedListener). The callback lets the application retrieve the finished stroke for rendering or storage.

Renderowanie

Moduł renderowania pomaga rysować pociągnięcia piórem na urządzeniu z AndroidemCanvas. Zapewnia CanvasStrokeRenderer w przypadku Compose i ViewStrokeRenderer w przypadku układów opartych na widokach. Te renderery są przeznaczone do renderowania o wysokiej wydajności i pomagają wyświetlać wysokiej jakości treści wizualne, w tym wygładzanie krawędzi.

Aby wyrenderować pociągnięcia, wywołaj metodę create(), aby uzyskać instancję CanvasStrokeRenderer. Następnie wywołaj metodę draw(), aby wyrenderować na obiekcie Canvas gotowe (Stroke) lub trwające (InProgressStroke) pociągnięcia.

Podczas rysowania pociągnięcia możesz przekształcać obszar roboczy. Może to być na przykład przesuwanie, powiększanie i obracanie. Aby obrys był renderowany prawidłowo, musisz też przekazać canvas transform do CanvasStrokeRenderer.draw.

Aby uniknąć oddzielnego śledzenia przekształcenia canvas, użyj zasady ViewStrokeRenderer.

Miejsce na dane

Moduł storage udostępnia narzędzia do wydajnego serializowania i deserializowania danych dotyczących pociągnięć, koncentrując się głównie na StrokeInputBatch.

Moduł korzysta z buforów protokołów i zoptymalizowanych technik kompresji różnicowej, co pozwala znacznie zaoszczędzić miejsce na dane w porównaniu z prostymi metodami.

Moduł pamięci ułatwia zapisywanie, wczytywanie i udostępnianie pociągnięć.