1 | /*
|
---|
2 | * ext-helloworld.js
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2
|
---|
5 | *
|
---|
6 | * Copyright(c) 2010 Alexis Deveria
|
---|
7 | *
|
---|
8 | */
|
---|
9 |
|
---|
10 | /*
|
---|
11 | This is a very basic SVG-Edit extension. It adds a "Hello World" button in
|
---|
12 | the left panel. Clicking on the button, and then the canvas will show the
|
---|
13 | user the point on the canvas that was clicked on.
|
---|
14 | */
|
---|
15 |
|
---|
16 | methodDraw.addExtension("Hello World", function() {
|
---|
17 |
|
---|
18 | return {
|
---|
19 | name: "Hello World",
|
---|
20 | // For more notes on how to make an icon file, see the source of
|
---|
21 | // the hellorworld-icon.xml
|
---|
22 | svgicons: "extensions/helloworld-icon.xml",
|
---|
23 |
|
---|
24 | // Multiple buttons can be added in this array
|
---|
25 | buttons: [{
|
---|
26 | // Must match the icon ID in helloworld-icon.xml
|
---|
27 | id: "hello_world",
|
---|
28 |
|
---|
29 | // This indicates that the button will be added to the "mode"
|
---|
30 | // button panel on the left side
|
---|
31 | type: "mode",
|
---|
32 |
|
---|
33 | // Tooltip text
|
---|
34 | title: "Say 'Hello World'",
|
---|
35 |
|
---|
36 | // Events
|
---|
37 | events: {
|
---|
38 | 'click': function() {
|
---|
39 | // The action taken when the button is clicked on.
|
---|
40 | // For "mode" buttons, any other button will
|
---|
41 | // automatically be de-pressed.
|
---|
42 | svgCanvas.setMode("hello_world");
|
---|
43 | }
|
---|
44 | }
|
---|
45 | }],
|
---|
46 | // This is triggered when the main mouse button is pressed down
|
---|
47 | // on the editor canvas (not the tool panels)
|
---|
48 | mouseDown: function() {
|
---|
49 | // Check the mode on mousedown
|
---|
50 | if(svgCanvas.getMode() == "hello_world") {
|
---|
51 |
|
---|
52 | // The returned object must include "started" with
|
---|
53 | // a value of true in order for mouseUp to be triggered
|
---|
54 | return {started: true};
|
---|
55 | }
|
---|
56 | },
|
---|
57 |
|
---|
58 | // This is triggered from anywhere, but "started" must have been set
|
---|
59 | // to true (see above). Note that "opts" is an object with event info
|
---|
60 | mouseUp: function(opts) {
|
---|
61 | // Check the mode on mouseup
|
---|
62 | if(svgCanvas.getMode() == "hello_world") {
|
---|
63 | var zoom = svgCanvas.getZoom();
|
---|
64 |
|
---|
65 | // Get the actual coordinate by dividing by the zoom value
|
---|
66 | var x = opts.mouse_x / zoom;
|
---|
67 | var y = opts.mouse_y / zoom;
|
---|
68 |
|
---|
69 | var text = "Hello World!\n\nYou clicked here: "
|
---|
70 | + x + ", " + y;
|
---|
71 |
|
---|
72 | // Show the text using the custom alert function
|
---|
73 | $.alert(text);
|
---|
74 | }
|
---|
75 | }
|
---|
76 | };
|
---|
77 | });
|
---|
78 |
|
---|