From 66457b70bfeb7d59b3e706417d5b5031db1ac51c Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Wed, 3 Mar 2010 15:30:38 +0000 Subject: [PATCH] Added hello world extension git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1442 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/extensions/ext-helloworld.js | 80 +++++++++++++++++++++++++++ editor/extensions/helloworld-icon.xml | 23 ++++++++ editor/svg-editor.html | 3 +- 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 editor/extensions/ext-helloworld.js create mode 100644 editor/extensions/helloworld-icon.xml diff --git a/editor/extensions/ext-helloworld.js b/editor/extensions/ext-helloworld.js new file mode 100644 index 00000000..7daf2a3a --- /dev/null +++ b/editor/extensions/ext-helloworld.js @@ -0,0 +1,80 @@ +/* + * ext-helloworld.js + * + * Licensed under the Apache License, Version 2 + * + * Copyright(c) 2010 Alexis Deveria + * + */ + +/* + 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 + user the point on the canvas that was clicked on. +*/ + +$(function() { + svgCanvas.addExtension("Hello World", function() { + + return { + name: "Hello World", + // For more notes on how to make an icon file, see the source of + // the hellorworld-icon.xml + svgicons: "extensions/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"); + } + } + }], + // 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(); + + // 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); + } + } + }; + }); +}); + diff --git a/editor/extensions/helloworld-icon.xml b/editor/extensions/helloworld-icon.xml new file mode 100644 index 00000000..68b6d964 --- /dev/null +++ b/editor/extensions/helloworld-icon.xml @@ -0,0 +1,23 @@ + + + + + + + Layer 1 + + Hello + World! + + + + + \ No newline at end of file diff --git a/editor/svg-editor.html b/editor/svg-editor.html index de4d7dcd..dc346d03 100644 --- a/editor/svg-editor.html +++ b/editor/svg-editor.html @@ -21,7 +21,8 @@ - + +