Skip to content
Emmanuel Proulx edited this page Sep 4, 2017 · 1 revision

Welcome to the FabricView wiki!

A library for creating graphics on an object model on top of canvas.

How to use:

Layout

Create a view in your layout, like this:
 <com.agsw.FabricView.FabricView
 android:id="@+id/my_fabric_view"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:padding="20dp"
 android:text="@string/my_fabric_view_title"
 />

Activity code

Retrieve and configure your FabricView

FabricView myFabricView = (FabricView) parent.findViewById(R.id.my_fabric_view); //Retrieve by ID

//Configuration. All of which is optional. Defaults are marked with an asterisk here.
myFabricView.setBackgroundMode(BACKGROUND_STYLE_BLANK); //Set the background style (BACKGROUND_STYLE_BLANK*, BACKGROUND_STYLE_NOTEBOOK_PAPER, BACKGROUND_STYLE_GRAPH_PAPER)

myFabricView.setInteractionMode(FabricView.DRAW_MODE); //Set its draw mode (DRAW_MODE*, SELECT_MODE, ROTATE_MODE, LOCKED_MODE)
myFabricView.setDeleteIcon(deleteIcon); //If you don't like the default delete icon
myFabricView.setColor(R.color.purple); //Line color
myFabricView.setSize(10); //Line width
myFabricView.setSelectionColor(R.color.lightergray); //Selection box color
//To be notified of any deletion:
myFabricView.setDeletionListener(new FabricView.DeletionListener() {
  public void deleted(CDrawable drawable) {
    doSomethingAboutThis(drawable);
  }
});

Manipulations

The following functions could be attached to buttons of your choosing:
myFabricView.cleanPage(); //Erases everything.
myFabricView.undo(); //Cancels the last operation.
myFabricView.redo(); //Reinstates the last undone operation.
myFabricView.selectLastDrawn(); //Mark the last drawn object as selected.
myFabricView.deSelect(); //Unmark all objects for selection.
myFabricView.deleteSelection(); //Removes all selected objects and its transforms.
myFabricView.deleteDrawable(); //Removes a single object and its transforms.

Retrieving the picture from the view

Bitmap fullResult = myFabricView.getCanvasBitmap(); //Gets a copy of the whole view. This includes decorations such as selection rectangle. So make sure you switch to LOCKED_MODE before calling.
Bitmap croppedResult = myFabricView.getCroppedCanvasBitmap(); //Same as previous, except with no margin around the picture.
List<CDrabable> drawablesList = myFabricView.getDrawablesList(); //Returns all the drawables of the view. See next sections.
CDrawable currentSelection = myFabricView.getSelection();

Save point functions

boolean everythingIsSaved = myFabricView.isSaved(); //true = there were no operations added or undone after the last call to markSaved().
markSaved(); //Indicates that everything was saved. You can save the bitmap or the drawable objects. (See previous section.)
revertUnsaved(); //Restore the drawables to the last save point.
List<CDrabable> unsavedDrawablesList = getUnsavedDrawablesList(); //Returns all the drawables that were not saved yet.

Drawables and Transforms

The list of visible objects inside the view is a stack. There are two kinds: CDrawable and CTransform (subclass of the latter).

A CDrawable is an object that can be "drawn" on the canvas. A CTransform represents a modification of a CDrawable.

A CDrawable is linked to its CTransforms (see getTransforms() and hasTransforms()), and each CTransform is aware of its CDrawable (see getDrawable()).

The subclasses of CDrawable are CPath (a set of continuous lines), CBitmap, and CText. Another subclass is CTransform, and this one has its one subclasses which are CRotation, CScale, and CTranslation.