Class Painter
The paint tool application object.
Defined in: index.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Painter()
|
Field Attributes | Field Name and Description |
---|---|
Holds all the removable functionality from the paint application.
|
|
Holds the buffer canvas and context references.
|
|
<private> |
Holds references to important DOM elements.
|
<private> <inner> |
Holds the keyboard event listener object.
|
Holds the current layer ID, canvas and context references.
|
|
<private> |
Holds the last recorded mouse coordinates and the button state (if it's
down or not).
|
The instance of the active tool object.
|
Method Attributes | Method Name and Description |
---|---|
actionAdd(id, func, overwrite)
Add a new action to the paint tool.
|
|
actionRemove(id)
Remove an action from the paint tool.
|
|
<private> <inner> |
ev_canvas(ev)
The Canvas event handler.
|
<private> <inner> |
ev_keyhandler(ev)
The global keyboard events handler.
|
<private> <inner> |
The event handler for any changes made to the tool selector.
|
<private> <inner> |
init()
Initialize the paint application.
|
This method draws the buffer canvas on top of the current image layer,
after which the buffer is cleared.
|
|
toolActivate(id)
Activate a drawing tool by ID.
|
- See:
- Painter#actionAdd Add a new action.
- Painter#actionRemove Remove an action.
- See:
- lib.dom.KeyboardEventListener The class dealing with the cross-browser differences in the DOM keyboard events.
- See:
- PainterConfig.tool_default holds the ID of the tool which is activated when the application loads.
- Parameters:
- {String} id
- The ID of the new action.
- {Function} func
- The constructor function of the new action object.
- {Boolean} overwrite Optional, Default: false
- Tells to overwrite or not an existing action, with the same ID.
- Returns:
- {Boolean} True if the action was successfully added, or false if not.
- See:
- Painter#actionRemove allows you to remove actions.
- Painter#actions Holds the action objects.
If the action object being destructed has the
actionRemove()
method, then it will be invoked, allowing any
custom action removal code to run.
- Parameters:
- {String} id
- The ID of the action object you want to remove.
- Returns:
- {Boolean} True if the action was removed, or false if it does not exist or some error occurred.
- See:
- Painter#actionAdd allows you to add new actions.
- Painter#actions Holds the action objects.
This method determines the mouse position relative to the canvas
element, after which it invokes the method of the currently active tool
with the same name as the current event type. For example, for the
mousedown
event the tool.mousedown()
method is invoked.
The mouse coordinates are added to the ev DOM Event object: ev.x_ and ev.y_.
- Parameters:
- {Event} ev
- The DOM Event object.
- Returns:
- The result returned by the event handler of the current tool. If no event handler was executed, false is returned.
This method determines the key the user pressed, based on the ev DOM Event object, taking into consideration any browser differences. Two new properties are added to the ev object:
- ev.kid_ is a string holding the key and the modifiers list (Control, Alt and/or Shift). For example, if the user would press the key A while holding down Control, then ev.kid_ would be "Control A". If the user would press "9" while holding down Shift, then ev.kid_ would be "Shift 9".
- ev.kobj_ holds a reference to the keyboard shortcut definition object from the configuration. This is useful for reuse, for passing parameters from the keyboard shortcut configuration object to the event handler.
In PainterConfig.keys one can setup the keyboard shortcuts. If the keyboard combination is found in that list, then the associated tool is activated.
- Parameters:
- {Event} ev
- The DOM Event object.
- See:
- PainterConfig.keys The keyboard shortcuts configuration.
- lib.dom.KeyboardEventListener The class dealing with the cross-browser differences in the DOM keyboard events.
- See:
- Painter#toolActivate The method which does the actual drawing tool activation.
The id provided must be available in the global PaintTools object.
- Parameters:
- {String} id
- The ID of the drawing tool to be activated.
- Returns:
- {Boolean} True if the tool has been activated, or false if not.
- See:
- PaintTools The object holding all the drawing tools.