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 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.
|
|
The instance of the active tool object.
|
Method Attributes | Method Name and Description |
---|---|
<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:
- 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.
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. One new property is 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".
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.