Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions Docs/En/App/App.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
LibCanvas.App
=============

`LibCanvas.App` is the framework for building interactive applications on LibCanvas.

#### Global

After calling LibCanvas.extract (), you can use the short alias "App"

### Initialization

```js
var app = new LibCanvas.App (object settings)
```

Settings can contain the following parameters:

* `appendTo` - the element to which you want to add the application. The default is `body`
* `size` - dimensions of the application window, object LibCanvas.Size
* `simple` - if `true`, then it will generate a simplified layout - from one canvas, but without the ability to create and shift layers

#### Example

```js
var app = new App ({
appendTo: '#container',
size: new Size (800, 500)
})
```

#### Normal layout for three layers:

```html
<div style = "width: 1200px; height: 800px;" class = "libcanvas-app">
<div style = "overflow: hidden; position: absolute; width: 1200px; height: 800px;">
<canvas width = "1200" height = "800" data-name = "bg" style = "position: absolute; z-index: 0;"> </canvas>
<canvas width = "1200" height = "800" data-name = "foo" style = "position: absolute; z-index: 1;"> </canvas>
<canvas width = "1200" height = "800" data-name = "bar" style = "position: absolute; z-index: 2;"> </canvas>
</div>
</div>
```

#### Simplified layout (maximum one layer):

```html
<canvas width = "391" height = "71" class = "libcanvas-app-simple"> </canvas>
```

#### Resizing an application:

Only the size of the application will change, the size of each layer will remain the same.

```js
app.container.size = new Size (1500, 1200);
```


### Methods

#### createLayer

```js
LibCanvas.App.Layer createLayer (object settings)
```

Creates and returns a LibCanvas.App

```js
var layer = app.createLayer ({name: 'units'});
```

#### destroy

```js
LibCanvas.App destroy ()
```

Destroys the application

```js
app.destroy ();
```

#### zIndexCompare

```js
int zIndexCompare (LibCanvas.App.Element left, LibCanvas.App.Element right)
```

Compares the position of each of the elements and returns -1 if the left is higher, +1 if the right is higher and 0 if they are on the same level
136 changes: 136 additions & 0 deletions Docs/En/App/Element.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
LibCanvas.App.Element
=====================

`LibCanvas.App.Element` - abstract class-framework for creating elements that will be drawn

Unlike other LibCanvas classes, this is used exclusively through inheritance.
Our tool is to override it and create our own methods in the class of the heir:

```js

atom.declare ('Unit', App.Element, {
renderTo: function (ctx, resources) {
ctx.fill (this.shape, 'red');
}
});

new Unit (layer, {
shape: new Circle (100, 100, 50)
});

```

### Built-in methods and properties

`atom.Events events` - an object that listens to events
`atom.Settings settings` is an object with settings. Basic properties:
* `zIndex` - the order in which the element is rendered
* `shape` is a shape that indicates an element
* `hidden` (* boolean *) - hides or displays an element. Hiding via `hidden` is preferable to just empty rendering, because then the element does not participate in the miscalculation of collisions and its previous location is not erased.

#### `redraw`

`LibCanvas.App.Element redraw ()`

A method that tells the application that the item has changed.
Attention! The method itself does not redraw anything, it just puts the element in the queue for rendering.
The call element is very fast and can be repeated painlessly many times per frame
The method context is bound to the element, so that it can be passed as a collab without losing the context

```js
animate (element, {
color: 'red',
onChange: element.redraw
})
```

#### `destroy`

`LibCanvas.App.Element destroy ()`

Removes an element from the context (but does not untie mouse events if you were signed via mouseHandler!)
The method context is bound to the element, so that it can be passed as a collab without losing the context

```js
destroyButton.onclick = element.destroy;
```

### Methods to Override

#### renderTo

```js
void renderTo (LibCanvas.Context2D ctx, atom.Registry resources)
```

Render element in the context. Describe in this method only renderer, but not object changes!
By implication, calls the renderTo method of the renderer property if there is or nothing does

```js

atom.declare ('Unit', App.Element, {
renderTo: function (ctx, resources) {
ctx.fill (this.shape, 'red');
ctx.stroke (this.shape, 'blue');
}
});

```

#### configure

```js
void configure ()
```

Called immediately after construction. Used in the successors of `App.Element` instead of the constructor

#### get currentBoundingShape

Getter, which returns a figure describing the effect of an element on the context. By default - a rectangle, in which is enclosed the `shape` element

#### isTriggerPoint

```js
boolean isTriggerPoint (Point point)
```

Determines whether the point is a trigger point for a mouse or other input device. In an instinctive way - it checks for belonging to `shape`

#### onUpdate

```js
void onUpdate (int time)
```

If the layer has an invoke, each frame is called and serves to change the properties of the object according to the time.
In the argument `time`, the time in milliseconds passed from the last frame is transmitted to correct and unbind the speed of the application from the FPS

```js

atom.declare ('Unit', App.Element, {
onUpdate: function (time) {
// rotate at 90 degrees per second
this.rotate ((90) .degree () * time / 1000);

// since changes occur every frame - always cause the drawing
this.redraw ();
}
});
```

#### clearPrevious

```js
void clearPrevious (LibCanvas.Context2D ctx)
```

Clears the previous location of the element in ctx. By default - erases `this.previousBoundingShape`

#### distanceMove

```js
void distanceMove (LibCanvas.Point point)
```

Shifts the element to the `point` distance. Used, for example, in `App.Draggable`.
116 changes: 116 additions & 0 deletions Docs/En/App/Layer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
LibCanvas.App.Layer
===================

`LibCanvas.App.Layer` - a class for creating layers of the LibCanvas application

### Initialization

It is created only with the help of the method `LibCanvas.App # createLayer`:

```js
LibCanvas.App.Layer app.createLayer (object settings);
```

Settings can contain the following parameters:

* `name` (* string *) - the name of the layer (needed only for debugging)
* `zIndex` (* number *) - z-index layer
* `invoke` (* boolean *) - is it necessary to call the `onUpdate` method on each object every frame (by default `false`)
* "intersection" - when redrawing one of the elements, it is necessary to redraw the rest. Values:
  * `auto` (by default) - only those necessary for correct rendering
  * `manual` - no, none (for example, when you want to personally manage the redrawing)
  * `all` - yes, all (for example, if it is cheaper than calculating all the intersections)
  * `full` - erase the entire canvas and draw everything from scratch

#### Example

```js
var layer = app.createLayer ({
name: 'units',
zIndex: 3,
invoke: true,
intersection: 'all'
})
```

#### Resizing the layer

Only the size of the specified layer will change. The size of the application and other layers will remain the same.
Remember that changing the size of the layer will destroy all the rendered data, so you need to call `layer.redrawAll ()`

```js
layer.dom.size = new Size (1500, 1200);
layer.redrawAll ()
```

### Properties

#### ctx

`2d-libcanvas` context of the canvas element of the layer

```js
layer.ctx.fillAll ('red')
```

### Methods

#### stop

```js
LibCanvas.App.Layer stop ()
```

Stop drawing layer

```js
layer.stop ()
```

#### start

```js
LibCanvas.App.Layer start ()
```

Resume layer rendering

```js
layer.start ()
```

#### hide

```js
LibCanvas.App.Layer hide ()
```

Temporarily hide the layer

```js
layer.hide ()
```

#### show

```js
LibCanvas.App.Layer show ()
```

Re-show layer

```js
layer.show ()
```

#### redrawAll

```js
LibCanvas.App.Layer redrawAll ()
```

Redraws all layer elements

```js
layer.redrawAll ()
```
Loading