2018-05-16 00:53:27 +00:00
|
|
|
/* eslint-disable no-var */
|
|
|
|
/* globals svgEditor, svgCanvas, $ */
|
2010-03-03 15:30:38 +00:00
|
|
|
/*
|
|
|
|
* ext-helloworld.js
|
|
|
|
*
|
2012-09-16 18:53:27 +00:00
|
|
|
* Licensed under the MIT License
|
2010-03-03 15:30:38 +00:00
|
|
|
*
|
|
|
|
* Copyright(c) 2010 Alexis Deveria
|
|
|
|
*
|
|
|
|
*/
|
2018-05-16 00:53:27 +00:00
|
|
|
|
|
|
|
/*
|
2010-03-03 15:30:38 +00:00
|
|
|
This is a very basic SVG-Edit extension. It adds a "Hello World" button in
|
|
|
|
the left panel. Clicking on the button, and then the canvas will show the
|
2014-02-12 09:38:38 +00:00
|
|
|
user the point on the canvas that was clicked on.
|
2010-03-03 15:30:38 +00:00
|
|
|
*/
|
|
|
|
|
2018-05-16 00:53:27 +00:00
|
|
|
svgEditor.addExtension('Hello World', function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: 'Hello World',
|
|
|
|
// For more notes on how to make an icon file, see the source of
|
|
|
|
// the helloworld-icon.xml
|
|
|
|
svgicons: svgEditor.curConfig.extPath + 'helloworld-icon.xml',
|
|
|
|
|
|
|
|
// Multiple buttons can be added in this array
|
|
|
|
buttons: [{
|
|
|
|
// Must match the icon ID in helloworld-icon.xml
|
|
|
|
id: 'hello_world',
|
|
|
|
|
|
|
|
// This indicates that the button will be added to the "mode"
|
|
|
|
// button panel on the left side
|
|
|
|
type: 'mode',
|
|
|
|
|
|
|
|
// Tooltip text
|
|
|
|
title: "Say 'Hello World'",
|
|
|
|
|
|
|
|
// Events
|
|
|
|
events: {
|
|
|
|
'click': function () {
|
|
|
|
// The action taken when the button is clicked on.
|
|
|
|
// For "mode" buttons, any other button will
|
|
|
|
// automatically be de-pressed.
|
|
|
|
svgCanvas.setMode('hello_world');
|
2010-03-03 15:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-16 00:53:27 +00:00
|
|
|
}],
|
|
|
|
// This is triggered when the main mouse button is pressed down
|
|
|
|
// on the editor canvas (not the tool panels)
|
|
|
|
mouseDown: function () {
|
|
|
|
// Check the mode on mousedown
|
|
|
|
if (svgCanvas.getMode() === 'hello_world') {
|
|
|
|
// The returned object must include "started" with
|
|
|
|
// a value of true in order for mouseUp to be triggered
|
|
|
|
return {started: true};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// This is triggered from anywhere, but "started" must have been set
|
|
|
|
// to true (see above). Note that "opts" is an object with event info
|
|
|
|
mouseUp: function (opts) {
|
|
|
|
// Check the mode on mouseup
|
|
|
|
if (svgCanvas.getMode() === 'hello_world') {
|
|
|
|
var zoom = svgCanvas.getZoom();
|
2010-03-03 15:30:38 +00:00
|
|
|
|
2018-05-16 00:53:27 +00:00
|
|
|
// Get the actual coordinate by dividing by the zoom value
|
|
|
|
var x = opts.mouse_x / zoom;
|
|
|
|
var y = opts.mouse_y / zoom;
|
|
|
|
|
|
|
|
var text = 'Hello World!\n\nYou clicked here: ' +
|
|
|
|
x + ', ' + y;
|
|
|
|
|
|
|
|
// Show the text using the custom alert function
|
|
|
|
$.alert(text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|