diff options
Diffstat (limited to 'js/dojo/dojox/drawing/plugins')
| -rw-r--r-- | js/dojo/dojox/drawing/plugins/_Plugin.js | 43 | ||||
| -rw-r--r-- | js/dojo/dojox/drawing/plugins/drawing/GreekPalette.js | 340 | ||||
| -rw-r--r-- | js/dojo/dojox/drawing/plugins/drawing/Grid.js | 102 | ||||
| -rw-r--r-- | js/dojo/dojox/drawing/plugins/drawing/Silverlight.js | 197 | ||||
| -rw-r--r-- | js/dojo/dojox/drawing/plugins/tools/Iconize.js | 104 | ||||
| -rw-r--r-- | js/dojo/dojox/drawing/plugins/tools/Pan.js | 246 | ||||
| -rw-r--r-- | js/dojo/dojox/drawing/plugins/tools/Zoom.js | 129 |
7 files changed, 1161 insertions, 0 deletions
diff --git a/js/dojo/dojox/drawing/plugins/_Plugin.js b/js/dojo/dojox/drawing/plugins/_Plugin.js new file mode 100644 index 0000000..44ebd51 --- /dev/null +++ b/js/dojo/dojox/drawing/plugins/_Plugin.js @@ -0,0 +1,43 @@ +//>>built +// wrapped by build app +define("dojox/drawing/plugins/_Plugin", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.plugins._Plugin"); + +dojox.drawing.plugins._Plugin = dojox.drawing.util.oo.declare( + // summary: + // Base class for plugins. + // description: + // When creating a plugin, use this class as the + // base to ensure full functionality. + function(options){ + this._cons = []; + dojo.mixin(this, options); + if(this.button && this.onClick){ + this.connect(this.button, "onClick", this, "onClick") + } + }, + { + util:null, + keys:null, + mouse:null, + drawing:null, + stencils:null, + anchors:null, + canvas:null, + node:null, + button:null,//gfx button + type:"dojox.drawing.plugins._Plugin", + connect: function(){ + this._cons.push(dojo.connect.apply(dojo, arguments)); + }, + disconnect: function(/*handle | Array*/handles){ + // summary: + // Removes connections based on passed + // handles arguments + if(!handles){ return }; + if(!dojo.isArray(handles)){ handles=[handles]; } + dojo.forEach(handles, dojo.disconnect, dojo); + } + } +); +}); diff --git a/js/dojo/dojox/drawing/plugins/drawing/GreekPalette.js b/js/dojo/dojox/drawing/plugins/drawing/GreekPalette.js new file mode 100644 index 0000000..66f21f8 --- /dev/null +++ b/js/dojo/dojox/drawing/plugins/drawing/GreekPalette.js @@ -0,0 +1,340 @@ +//>>built +// wrapped by build app +define("dojox/drawing/plugins/drawing/GreekPalette", ["dijit","dojo","dojox","dojo/i18n!dojox/editor/plugins/nls/latinEntities","dojo/require!dojox/drawing/library/greek,dijit/focus,dijit/_Widget,dijit/_TemplatedMixin,dijit/_PaletteMixin,dojo/i18n"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.plugins.drawing.GreekPalette"); + +dojo.require("dojox.drawing.library.greek"); +dojo.require("dijit.focus"); +dojo.require("dijit._Widget"); +dojo.require("dijit._TemplatedMixin"); +dojo.require("dijit._PaletteMixin"); +dojo.require("dojo.i18n"); + +dojo.requireLocalization("dojox.editor.plugins", "latinEntities"); + +dojo.declare("dojox.drawing.plugins.drawing.GreekPalette", + [dijit._Widget, dijit._TemplatedMixin, dijit._PaletteMixin], + { + // summary: + // This plugin uses the palette dijit in order to give tips for + // non-english (mostly greek for now) letters. + // + // IMPORTANT! Because it is a full blown dijit it is NOT loaded + // like the other plugins. INSTEAD currently it is instantiated + // in markup. TextBlock LOOKS FOR IT by ID - "greekPalette" + // and if it finds it does the necessary initialization/connections. + // description: + // Grid showing all available entity options which the + // user can pick from. The library loaded for use by the picker + // is found in dojox.drawing.library.greek. Adding characters + // there will automatically add them to the palette. + // + // This works as a popup and as such its onChange and onCancel + // close it. TextBlock manages it, since it's what uses the assist + // so it calls show (all actual popup management happens here). + // In order to activate the plugin require it and then include the + // markup in the example: + // + // example: + // | <!--Because this is a widget it is included in markup and NOT like the other plugins--> + // | <div dojoType="dojox.drawing.plugins.drawing.GreekPalette" id="greekPalette"></div> + + postMixInProperties: function(){ + // Convert hash of entities into two-dimensional rows/columns table (array of arrays) + var choices = dojox.drawing.library.greek; + var numChoices = 0; + var entityKey; + for(entityKey in choices){numChoices++;} + var choicesPerRow = Math.floor(Math.sqrt(numChoices)); + var numRows = choicesPerRow; + var currChoiceIdx = 0; + var rows = []; + var row = []; + for(entityKey in choices){ + currChoiceIdx++; + row.push(entityKey); + if(currChoiceIdx % numRows === 0){ + rows.push(row); + row = []; + } + } + if(row.length > 0){ + rows.push(row); + } + this._palette = rows; + }, + + show: function(obj){ + dojo.mixin(obj, {popup: this}); + dijit.popup.open(obj); + }, + + onChange: function(val){ + var textBlock = this._textBlock; + dijit.popup.hide(this); + textBlock.insertText(this._pushChangeTo,val); + textBlock._dropMode = false; + }, + + onCancel: function(/*Boolean*/ closeAll){ + // summary: + // attach point for notification about when the user cancels the current menu + dijit.popup.hide(this); + this._textBlock._dropMode = false; + }, + + // templateString: String + // The template of this widget. Using dojoxEntityPalette classes + // in order to allow easy transfer of css + templateString: '<div class="dojoxEntityPalette">\n' + + ' <table>\n' + + ' <tbody>\n' + + ' <tr>\n' + + ' <td>\n' + + ' <table class="dijitPaletteTable">\n' + + ' <tbody dojoAttachPoint="gridNode"></tbody>\n' + + ' </table>\n' + + ' </td>\n' + + ' </tr>\n' + + ' <tr>\n' + + ' <td>\n'+ + ' <table dojoAttachPoint="previewPane" class="dojoxEntityPalettePreviewTable">\n' + + ' <tbody>\n' + + ' <tr>\n' + + ' <td class="dojoxEntityPalettePreviewDetailEntity">Type: <span class="dojoxEntityPalettePreviewDetail" dojoAttachPoint="previewNode"></span></td>\n' + + ' </tr>\n' + + ' </tbody>\n' + + ' </table>\n' + + ' </td>\n' + + ' </tr>\n' + + ' </tbody>\n' + + ' </table>\n' + + '</div>', + + + baseClass: "dojoxEntityPalette", + + // showPreview: [public] Boolean + // Whether the preview pane will be displayed, to show details about the selected entity. + showPreview: true, + + dyeClass: 'dojox.drawing.plugins.Greeks', + + // domNodeClass [protected] String + paletteClass: 'editorLatinEntityPalette', + + cellClass: "dojoxEntityPaletteCell", + + buildRendering: function(){ + this.inherited(arguments); + + var i18n = dojo.i18n.getLocalization("dojox.editor.plugins", "latinEntities"); + + this._preparePalette( + this._palette, + i18n + ); + + var cells = dojo.query(".dojoxEntityPaletteCell", this.gridNode); + dojo.forEach(cells, function(cellNode){ + this.connect(cellNode, "onmouseenter", "_onCellMouseEnter"); + }, this); + }, + + _onCellMouseEnter: function(e){ + // summary: + // Simple function to handle updating the display at the bottom of + // the palette. + // e: + // The event. + // tags: + // private + if(this.showPreview){ + this._displayDetails(e.target); + } + }, + + _onCellClick: function(/*Event*/ evt){ + // summary: + // Handler for click, enter key & space key. Selects the cell. + // evt: + // The event. + // tags: + // private + var target = evt.type == "click" ? evt.currentTarget : this._currentFocus, + value = this._getDye(target).getValue(); + + // First focus the clicked cell, and then send onChange() notification. + // onChange() (via _setValueAttr) must be after the focus call, because + // it may trigger a refocus to somewhere else (like the Editor content area), and that + // second focus should win. + // Use setTimeout because IE doesn't like changing focus inside of an event handler. + this._setCurrent(target); + setTimeout(dojo.hitch(this, function(){ + dijit.focus(target); + this._setValueAttr(value, true); + })); + + // workaround bug where hover class is not removed on popup because the popup is + // closed and then there's no onblur event on the cell + dojo.removeClass(target, "dijitPaletteCellHover"); + + dojo.stopEvent(evt); + }, + + postCreate: function(){ + this.inherited(arguments); + + if(!this.showPreview){ + dojo.style(this.previewNode,"display","none"); + } + dijit.popup.moveOffScreen(this); + }, + + _setCurrent: function(/*DOMNode*/ node){ + // summary: + // Sets which node is the focused cell. + // description: + // At any point in time there's exactly one + // cell with tabIndex != -1. If focus is inside the palette then + // focus is on that cell. + // + // After calling this method, arrow key handlers and mouse click handlers + // should focus the cell in a setTimeout(). + // tags: + // protected + if("_currentFocus" in this){ + // Remove tabIndex on old cell + dojo.attr(this._currentFocus, "tabIndex", "-1"); + dojo.removeClass(this._currentFocus,"dojoxEntityPaletteCellHover"); + } + + // Set tabIndex of new cell + this._currentFocus = node; + if(node){ + dojo.attr(node, "tabIndex", this.tabIndex); + dojo.addClass(this._currentFocus,"dojoxEntityPaletteCellHover"); + } + if(this.showPreview){ + this._displayDetails(node); + } + }, + + _displayDetails: function(/*DOMNode*/ cell){ + // summary: + // Display the details of the currently focused entity in the preview pane + var dye = this._getDye(cell); + if(dye){ + var ehtml = dye.getValue(); + var ename = dye._alias; + //console.warn("Greek help: ",dye._alias); + this.previewNode.innerHTML=ehtml; + }else{ + this.previewNode.innerHTML=""; + this.descNode.innerHTML=""; + } + }, + + _preparePalette: function(choices, titles) { + // summary: + // Subclass must call _preparePalette() from postCreate(), passing in the tooltip + // for each cell + // choices: String[][] + // id's for each cell of the palette, used to create Dye JS object for each cell + // titles: String[] + // Localized tooltip for each cell + + this._cells = []; + var url = this._blankGif; + + var dyeClassObj = dojo.getObject(this.dyeClass); + + for(var row=0; row < choices.length; row++){ + var rowNode = dojo.create("tr", {tabIndex: "-1"}, this.gridNode); + for(var col=0; col < choices[row].length; col++){ + var value = choices[row][col]; + if(value){ + var cellObject = new dyeClassObj(value); + + var cellNode = dojo.create("td", { + "class": this.cellClass, + tabIndex: "-1", + title: titles[value] + }); + + // prepare cell inner structure + cellObject.fillCell(cellNode, url); + + this.connect(cellNode, "ondijitclick", "_onCellClick"); + this._trackMouseState(cellNode, this.cellClass); + + dojo.place(cellNode, rowNode); + + cellNode.index = this._cells.length; + + // save cell info into _cells + this._cells.push({node:cellNode, dye:cellObject}); + } + } + } + this._xDim = choices[0].length; + this._yDim = choices.length; + + }, + + _navigateByArrow: function(evt){ + // summary: + // This is a departure from the dijit, the textBlock needs + // navigation without losing focus, this allows that + // increment: + // How much the key is navigated. + // tags: + // private + var keyIncrementMap = { + 38: -this._xDim, + // The down key the index is increase by the x dimension. + 40: this._xDim, + // Right and left move the index by 1. + 39: this.isLeftToRight() ? 1 : -1, + 37: this.isLeftToRight() ? -1 : 1 + }; + + var increment = keyIncrementMap[evt.keyCode]; + var newFocusIndex = this._currentFocus.index + increment; + if(newFocusIndex < this._cells.length && newFocusIndex > -1){ + var focusNode = this._cells[newFocusIndex].node; + this._setCurrent(focusNode); + } + } +}); + +dojo.declare("dojox.drawing.plugins.Greeks", + null, +{ + // summary: + // Represents a character. + // Initialized using an alias for the character (like cent) rather + // than with the character itself. + + constructor: function(/*String*/ alias){ + // summary: + // Construct JS object representing an entity (associated w/a cell + // in the palette) + // value: String + // alias name: 'cent', 'pound' .. + this._alias = alias; + }, + + getValue: function(){ + // summary: + // Returns HTML representing the character, like & + // + return this._alias; + }, + + fillCell: function(/*DOMNode*/ cell){ + // Deal with entities that have keys which are reserved words. + cell.innerHTML = "&"+this._alias+";"; + } +}); +}); diff --git a/js/dojo/dojox/drawing/plugins/drawing/Grid.js b/js/dojo/dojox/drawing/plugins/drawing/Grid.js new file mode 100644 index 0000000..5ee6109 --- /dev/null +++ b/js/dojo/dojox/drawing/plugins/drawing/Grid.js @@ -0,0 +1,102 @@ +//>>built +// wrapped by build app +define("dojox/drawing/plugins/drawing/Grid", ["dijit","dojo","dojox","dojo/require!dojox/drawing/plugins/_Plugin"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.plugins.drawing.Grid"); +dojo.require("dojox.drawing.plugins._Plugin"); + +dojox.drawing.plugins.drawing.Grid = dojox.drawing.util.oo.declare( + // summary: + // Plugin that displays a grid on the Drawing canvas. + // example: + // | <div dojoType="dojox.drawing.Drawing" id="drawingNode" + // | plugins="[{'name':'dojox.drawing.plugins.drawing.Grid', 'options':{gap:50}}]"> + // | </div> + // + dojox.drawing.plugins._Plugin, + function(options){ + if(options.gap){ + this.major = options.gap; + } + this.majorColor = options.majorColor || this.majorColor; + this.minorColor = options.minorColor || this.minorColor; + + this.setGrid(); + dojo.connect(this.canvas, "setZoom", this, "setZoom"); + }, + { + type:"dojox.drawing.plugins.drawing.Grid", + // + // gap: Number + // How far apart to set the grid lines + gap:100, + major:100, + minor:0, + // + // majorColor: String + // Major lines color + majorColor: "#00ffff", + // + // minorColor: String + // Minor lines color + minorColor: "#d7ffff", + // + // zoom: [readonly] Number + // The current zoom of the grid + zoom:1, + + setZoom: function(zoom){ + // summary: + // Set's the zoom of the canvas + this.zoom = zoom; + this.setGrid(); + }, + setGrid: function(options){ + // summary: + // Renders grid + // + // TODO: major minor lines + // minors dont show on zoom out + // draw minors first + // + var mjr = Math.floor(this.major * this.zoom); + var mnr = this.minor ? Math.floor(this.minor * this.zoom) : mjr; + + this.grid && this.grid.removeShape(); + + var x1,x2,y1,y2,i,clr,len; + var s = this.canvas.underlay.createGroup(); + var w = 2000;//this.canvas.width; + var h = 1000;//this.canvas.height; + var b = 1; + var mj = this.majorColor; + var mn = this.minorColor; + + var createGridLine = function(x1,y1,x2,y2, c){ + s.createLine({x1: x1, y1: y1, x2: x2, y2: y2}).setStroke({style: "Solid", width: b, cap: "round", color:c}); + }; + + // horz + for(i=1,len = h/mnr; i<len; i++){ + x1 = 0, x2 = w; + y1 = mnr*i, y2 = y1; + + + clr = y1%mjr ? mn : mj; + createGridLine(x1,y1,x2,y2, clr); + } + // vert + for(i=1,len = w/mnr; i<len; i++){ + y1 = 0, y2 = h; + x1 = mnr*i, x2 = x1; + clr = x1%mjr ? mn : mj; + createGridLine(x1,y1,x2,y2, clr); + } + + s.moveToBack(); + this.grid = s; + this.util.attr(s, "id", "grid"); + return s; + } + } +); +}); diff --git a/js/dojo/dojox/drawing/plugins/drawing/Silverlight.js b/js/dojo/dojox/drawing/plugins/drawing/Silverlight.js new file mode 100644 index 0000000..50fbbea --- /dev/null +++ b/js/dojo/dojox/drawing/plugins/drawing/Silverlight.js @@ -0,0 +1,197 @@ +//>>built +// wrapped by build app +define("dojox/drawing/plugins/drawing/Silverlight", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.plugins.drawing.Silverlight"); + +dojox.drawing.plugins.drawing.Silverlight = dojox.drawing.util.oo.declare( + // summary: + // "Plugin" to allow the Silverlight plugin to work + // with DojoX Drawing. + // + // WARNING: This is not completely implemented. For the most + // part, DojoX Drawing does not support Silverlight. This class + // was created in an attempt for support, but there were too many + // obstacles and not enough time. The basic functionality is here + // and there's a good head start if anyone elase wishes to pick up + // where I left off. + // + function(options){ + // summary: + // The constructor is the only method in this class. + // What is happening here is other methods in other + // classes are being overridden to adapt to Silverlight. + // + + if(dojox.gfx.renderer != "silverlight"){ return; } + this.mouse = options.mouse; + this.stencils = options.stencils; + this.anchors = options.anchors; + this.canvas = options.canvas; + this.util = options.util; + + + dojo.connect(this.stencils, "register", this, function(item){ + var c1, c2, c3, c4, c5, self = this; + var conMouse = function(){ + //console.info("------connect shape", item.id) + + // Connect to PARENT (SL Canvas) , not SHAPE + c1 = item.container.connect("onmousedown", function(evt){ + //console.info("----------------------------------SHAPE DOWN", item.container) + evt.superTarget = item; + self.mouse.down(evt); + }); + } + conMouse(); + + c2 = dojo.connect(item, "setTransform", this, function(){ + //dojo.disconnect(c1); + }); + + c3 = dojo.connect(item, "onBeforeRender", function(){ + //dojo.disconnect(c1); + }); + + + c4 = dojo.connect(item, "onRender", this, function(){ + //conMouse(); + }); + + c5 = dojo.connect(item, "destroy", this, function(){ + dojo.forEach([c1,c2,c3,c4,c5], dojo.disconnect, dojo); + }); + }); + + dojo.connect(this.anchors, "onAddAnchor", this, function(anchor){ + var c1 = anchor.shape.connect("onmousedown", this.mouse, function(evt){ + evt.superTarget = anchor; + this.down(evt) + }); + var c2 = dojo.connect(anchor, "disconnectMouse", this, function(){ + dojo.disconnect(c1); + dojo.disconnect(c2); + }); + + }); + + + this.mouse._down = function(evt){ + var dim = this._getXY(evt); + var x = dim.x - this.origin.x; + var y = dim.y - this.origin.y; + + x*= this.zoom; + y*= this.zoom; + + this.origin.startx = x; + this.origin.starty = y; + this._lastx = x; + this._lasty = y; + + this.drawingType = this.util.attr(evt, "drawingType") || ""; + var id = this._getId(evt); + var obj = {x:x,y:y, id:id}; + console.log(" > > > id:", id, "drawingType:", this.drawingType, "evt:", evt) + + this.onDown(obj); + + this._clickTime = new Date().getTime(); + if(this._lastClickTime){ + if(this._clickTime-this._lastClickTime<this.doublClickSpeed){ + var dnm = this.eventName("doubleClick"); + console.warn("DOUBLE CLICK", dnm, obj); + this._broadcastEvent(dnm, obj); + }else{ + //console.log(" slow:", this._clickTime-this._lastClickTime) + } + } + this._lastClickTime = this._clickTime; + + // throws errors in IE silverlight. Oddness. + //dojo.stopEvent(evt); + } + + this.mouse.down = function(evt){ + clearTimeout(this.__downInv); + if(this.util.attr(evt, "drawingType")=="surface"){ + this.__downInv = setTimeout(dojo.hitch(this, function(){ + this._down(evt); + }),500); + return; + } + this._down(evt); + + + } + + this.mouse._getXY = function(evt){ + + if(evt.pageX){ + return {x:evt.pageX, y:evt.pageY, cancelBubble:true}; + } + console.log("EVT", evt) + //console.log("EVT", evt.pageX) + for(var nm in evt){ + //console.log("..."+nm+"="+evt[nm]); + } + console.log("EVTX", evt.x) + if(evt.x !== undefined){ + return { + x:evt.x + this.origin.x, + y:evt.y + this.origin.y + }; + }else{ + return {x:evt.pageX, y:evt.pageY}; + } + } + + this.mouse._getId = function(evt){ + return this.util.attr(evt, "id"); + } + + this.util.attr = function(/* Object */ elem, /* property */ prop, /* ? value */ value, squelchErrors){ + if(!elem){ return false; } + try{ + + var t; + if(elem.superTarget){ + t = elem.superTarget; + }else if(elem.superClass){ + t = elem.superClass; + }else if(elem.target){ + t = elem.target; + }else{ + t = elem; + } + + if(value!==undefined){ + elem[prop] = value; + return value; + } + + if(t.tagName){ + if(prop=="drawingType" && t.tagName.toLowerCase()=="object"){ + return "surface"; + } + var r = dojo.attr(t, prop); + } + var r = t[prop]; + return r + + + }catch(e){ + if(!squelchErrors){ + // For debugging only. These errors actually cause more errors in IE's console + //console.error("BAD ATTR: prop:", prop, "el:", elem) + //console.error(e) + //console.trace(); + } + return false; + } + } + }, + { + + } +); +}); diff --git a/js/dojo/dojox/drawing/plugins/tools/Iconize.js b/js/dojo/dojox/drawing/plugins/tools/Iconize.js new file mode 100644 index 0000000..6d2437c --- /dev/null +++ b/js/dojo/dojox/drawing/plugins/tools/Iconize.js @@ -0,0 +1,104 @@ +//>>built +// wrapped by build app +define("dojox/drawing/plugins/tools/Iconize", ["dijit","dojo","dojox","dojo/require!dojox/drawing/plugins/_Plugin"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.plugins.tools.Iconize"); +dojo.require("dojox.drawing.plugins._Plugin"); + +dojox.drawing.plugins.tools.Iconize = dojox.drawing.util.oo.declare( + // summary: + // Somewhat of internal use... + // Outputs a path to be used as an icon. Will end up being a + // sub-icon under Export options + + dojox.drawing.plugins._Plugin, + function(options){ + + }, + { + onClick: function(){ + var item; + for(var nm in this.stencils.stencils){ + console.log(" stanceil item:", this.stencils.stencils[nm].id, this.stencils.stencils[nm]) + if(this.stencils.stencils[nm].shortType=="path"){ + item = this.stencils.stencils[nm]; + break; + } + } + if(item){ + console.log("click Iconize plugin", item.points); + this.makeIcon(item.points); + } + }, + makeIcon: function(/*Array*/p){ + var rnd = function(n){ + return Number(n.toFixed(1)); + } + + var x = 10000; + var y = 10000; + p.forEach(function(pt){ + if(pt.x!==undefined && !isNaN(pt.x)){ + x = Math.min(x, pt.x); + y = Math.min(y, pt.y); + } + }); + + var xmax = 0; + var ymax = 0; + p.forEach(function(pt){ + if(pt.x!==undefined && !isNaN(pt.x)){ + pt.x = rnd(pt.x - x); + //console.log("Y:", pt.y, y, pt.y - y) + pt.y = rnd(pt.y - y); + xmax = Math.max(xmax, pt.x); + ymax = Math.max(ymax, pt.y); + } + }); + + console.log("xmax:", xmax, "ymax:", ymax) + + var s = 60 + var m = 20 + + p.forEach(function(pt){ + pt.x = rnd(pt.x / xmax) * s + m; + pt.y = rnd(pt.y / ymax) * s + m; + }); + + var txt = "[\n"; + dojo.forEach(p, function(pt, i){ + txt += "{\t" + if(pt.t){ + txt += "t:'"+pt.t+"'" + } + if(pt.x!==undefined && !isNaN(pt.x)){ + if(pt.t){ + txt += ", "; + } + txt += "x:"+pt.x+",\t\ty:"+pt.y; + } + txt += "\t}"; + if(i!=p.length-1){ + txt += "," + } + txt += "\n" + }); + txt+="]" + + console.log(txt) + var n = dojo.byId("data"); + if(n){ + n.value = txt; + } + } + } +); + +dojox.drawing.plugins.tools.Iconize.setup = { + name:"dojox.drawing.plugins.tools.Iconize", + tooltip:"Iconize Tool", + iconClass:"iconPan" +}; + +dojox.drawing.register(dojox.drawing.plugins.tools.Iconize.setup, "plugin"); +}); diff --git a/js/dojo/dojox/drawing/plugins/tools/Pan.js b/js/dojo/dojox/drawing/plugins/tools/Pan.js new file mode 100644 index 0000000..2cd3d68 --- /dev/null +++ b/js/dojo/dojox/drawing/plugins/tools/Pan.js @@ -0,0 +1,246 @@ +//>>built +// wrapped by build app +define("dojox/drawing/plugins/tools/Pan", ["dijit","dojo","dojox","dojo/require!dojox/drawing/plugins/_Plugin"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.plugins.tools.Pan"); +dojo.require("dojox.drawing.plugins._Plugin"); + +dojox.drawing.plugins.tools.Pan = dojox.drawing.util.oo.declare( + // summary: + // A plugin that allows for a scrolling canvas. An action + // tool is added to the toolbar that allows for panning. Holding + // the space bar is a shortcut to that action. The canvas will + // only pan and scroll if there are objects out of the viewable + // area. + // example: + // | <div dojoType="dojox.drawing.Toolbar" drawingId="drawingNode" class="drawingToolbar vertical"> + // | <div tool="dojox.drawing.tools.Line" selected="true">Line</div> + // | <div plugin="dojox.drawing.plugins.tools.Pan" options="{}">Pan</div> + // | </div> + // + dojox.drawing.plugins._Plugin, + function(options){ + this.domNode = options.node; + var _scrollTimeout; + this.toolbar = options.scope; + this.connect(this.toolbar, "onToolClick", this, function(){ + this.onSetPan(false) + }); + this.connect(this.keys, "onKeyUp", this, "onKeyUp"); + this.connect(this.keys, "onKeyDown", this, "onKeyDown"); + this.connect(this.keys, "onArrow", this, "onArrow"); + this.connect(this.anchors, "onAnchorUp", this, "checkBounds"); + this.connect(this.stencils, "register", this, "checkBounds"); + this.connect(this.canvas, "resize", this, "checkBounds"); + this.connect(this.canvas, "setZoom", this, "checkBounds"); + this.connect(this.canvas, "onScroll", this, function(){ + if(this._blockScroll){ + this._blockScroll = false; + return; + } + _scrollTimeout && clearTimeout(_scrollTimeout); + _scrollTimeout = setTimeout(dojo.hitch(this, "checkBounds"), 200); + }); + this._mouseHandle = this.mouse.register(this); + // This HAS to be called after setting initial objects or things get screwy. + //this.checkBounds(); + + },{ + selected:false, + keyScroll:false, + type:"dojox.drawing.plugins.tools.Pan", + + onPanUp: function(obj){ + if(obj.id == this.button.id){ + this.onSetPan(false); + } + }, + + onKeyUp: function(evt){ + switch(evt.keyCode){ + case 32: + this.onSetPan(false); + break; + case 39: case 37: case 38: case 40: + clearInterval(this._timer); + break; + } + }, + + onKeyDown: function(evt){ + if(evt.keyCode == 32){ + this.onSetPan(true); + } + }, + + interval: 20, + + onArrow: function(evt){ + if(this._timer){ clearInterval(this._timer); } + this._timer = setInterval(dojo.hitch(this,function(evt){ + this.canvas.domNode.parentNode.scrollLeft += evt.x*10; + this.canvas.domNode.parentNode.scrollTop += evt.y*10; + },evt), this.interval); + }, + + onSetPan: function(/*Boolean | Event*/ bool){ + if(bool === true || bool === false){ + this.selected = !bool; + } + console.log('ON SET PAN:', this.selected) + if(this.selected){ + this.selected = false; + this.button.deselect(); + }else{ + this.selected = true; + this.button.select(); + } + this.mouse.setEventMode(this.selected ? "pan" : ""); + }, + + onPanDrag: function(obj){ + var x = obj.x - obj.last.x; + var y = obj.y - obj.last.y; + this.canvas.domNode.parentNode.scrollTop -= obj.move.y; + this.canvas.domNode.parentNode.scrollLeft -= obj.move.x; + this.canvas.onScroll(); + }, + + onUp: function(obj){ + if(obj.withinCanvas){ + this.keyScroll = true; + }else{ + this.keyScroll = false; + } + }, + + onStencilUp: function(obj){ + // this gets called even on click-off because of the + // issues with TextBlock deselection + this.checkBounds(); + }, + onStencilDrag: function(obj){ + // this gets called even on click-off because of the + // issues with TextBlock deselection + //this.checkBounds(); + }, + + checkBounds: function(){ + + //watch("CHECK BOUNDS DISABLED", true); return; + + + // summary: + // Scans all items on the canvas and checks if they are out of + // bounds. If so, a scroll bar (in Canvas) is shown. If the position + // is left or top, the canvas is scrolled all items are relocated + // the distance of the scroll. Ideally, it should look as if the + // items do not move. + + // logging stuff here so it can be turned on and off. This method is + // very high maintenance. + var log = function(){ + //console.log.apply(console, arguments); + } + var warn = function(){ + //console.warn.apply(console, arguments); + } + //console.clear(); + //console.time("check bounds"); + + // initialize a shot-tin of vars + var t=Infinity, r=-Infinity, b=-10000, l=10000, + sx=0, sy=0, dy=0, dx=0, + mx = this.stencils.group ? this.stencils.group.getTransform() : {dx:0, dy:0}, + sc = this.mouse.scrollOffset(), + // scY, scX: the scrollbar creates the need for extra dimension + scY = sc.left ? 10 : 0, + scX = sc.top ? 10 : 0, + // ch, cw: the current size of the canvas + ch = this.canvas.height, + cw = this.canvas.width, + z = this.canvas.zoom, + // pch, pcw: the normal size of the canvas (not scrolled) + // these could change if the container resizes. + pch = this.canvas.parentHeight, + pcw = this.canvas.parentWidth; + + + this.stencils.withSelected(function(m){ + var o = m.getBounds(); + warn("SEL BOUNDS:", o); + t = Math.min(o.y1 + mx.dy, t); + r = Math.max(o.x2 + mx.dx, r); + b = Math.max(o.y2 + mx.dy, b); + l = Math.min(o.x1 + mx.dx, l); + }); + + this.stencils.withUnselected(function(m){ + var o = m.getBounds(); + warn("UN BOUNDS:", o); + t = Math.min(o.y1, t); + r = Math.max(o.x2, r); + b = Math.max(o.y2, b); + l = Math.min(o.x1, l); + log("----------- B:", b, o.y2) + }); + + b *= z; + var xscroll = 0, yscroll = 0; + log("Bottom test", "b:", b, "z:", z, "ch:", ch, "pch:", pch, "top:", sc.top, "sy:", sy, "mx.dy:", mx.dy); + if(b > pch || sc.top ){ + log("*bottom scroll*"); + // item off bottom + ch = Math.max(b, pch + sc.top); + sy = sc.top; + xscroll += this.canvas.getScrollWidth(); + }else if(!sy && ch>pch){ + log("*bottom remove*"); + // item moved from bottom + ch = pch; + } + + r *= z; + if(r > pcw || sc.left){ + //log("*right scroll*"); + // item off right + cw = Math.max(r, pcw + sc.left); + sx = sc.left; + yscroll += this.canvas.getScrollWidth(); + }else if(!sx && cw>pcw){ + //log("*right remove*"); + // item moved from right + cw = pcw; + } + + // add extra space for scrollbars + // double it to give some breathing room + cw += xscroll*2; + ch += yscroll*2; + + this._blockScroll = true; + + // selected items are not transformed. The selection itself is + // and the items are on de-select + this.stencils.group && this.stencils.group.applyTransform({dx:dx, dy:dy}); + + // non-selected items are transformed + this.stencils.withUnselected(function(m){ + m.transformPoints({dx:dx, dy:dy}); + }); + + this.canvas.setDimensions(cw, ch, sx, sy); + + //console.timeEnd("check bounds"); + } + } +); + +dojox.drawing.plugins.tools.Pan.setup = { + name:"dojox.drawing.plugins.tools.Pan", + tooltip:"Pan Tool", + iconClass:"iconPan", + button:false +}; + +dojox.drawing.register(dojox.drawing.plugins.tools.Pan.setup, "plugin"); +}); diff --git a/js/dojo/dojox/drawing/plugins/tools/Zoom.js b/js/dojo/dojox/drawing/plugins/tools/Zoom.js new file mode 100644 index 0000000..a35073f --- /dev/null +++ b/js/dojo/dojox/drawing/plugins/tools/Zoom.js @@ -0,0 +1,129 @@ +//>>built +// wrapped by build app +define("dojox/drawing/plugins/tools/Zoom", ["dijit","dojo","dojox","dojo/require!dojox/drawing/plugins/_Plugin"], function(dijit,dojo,dojox){ +dojo.provide("dojox.drawing.plugins.tools.Zoom"); +dojo.require("dojox.drawing.plugins._Plugin"); + +(function(){ + // + // zoomInc: Float + // The amount of zoom that will occur upon each click. + var zoomInc = Math.pow(2.0,0.25), + // + // maxZoom: Number + // The maximum the canvas can be zoomed in. 10 = 1000% + maxZoom = 10, + // + // minZoom: Float + // The most the canvas can be zoomed out. .1 = 10% + minZoom = 0.1, + // + // zoomFactor: [readonly] Float + // The current zoom amount + zoomFactor = 1, + + dt = dojox.drawing.plugins.tools; + + dt.ZoomIn = dojox.drawing.util.oo.declare( + // summary: + // A plugin that allows for zooming the canvas in and out. An + // action-tool is added to the toolbar with plus, minus and 100% + // buttons. + // + function(options){ + // mix in private vars + + }, + {} + ); + + + dt.ZoomIn = dojox.drawing.util.oo.declare( + // summary: + dojox.drawing.plugins._Plugin, + function(options){ + + }, + { + type:"dojox.drawing.plugins.tools.ZoomIn", + onZoomIn: function(){ + // summary: + // Handles zoom in. + // + zoomFactor *= zoomInc; + zoomFactor = Math.min(zoomFactor, maxZoom); + this.canvas.setZoom(zoomFactor); + this.mouse.setZoom(zoomFactor); + }, + onClick: function(){ + this.onZoomIn(); + } + } + ); + + dt.Zoom100 = dojox.drawing.util.oo.declare( + // summary: + dojox.drawing.plugins._Plugin, + function(options){ + + }, + { + type:"dojox.drawing.plugins.tools.Zoom100", + onZoom100: function(){ + // summary: + // Zooms to 100% + // + zoomFactor = 1; + this.canvas.setZoom(zoomFactor); + this.mouse.setZoom(zoomFactor); + }, + onClick: function(){ + this.onZoom100(); + } + } + ); + + dt.ZoomOut = dojox.drawing.util.oo.declare( + // summary: + dojox.drawing.plugins._Plugin, + function(options){ + + }, + { + type:"dojox.drawing.plugins.tools.ZoomOut", + onZoomOut: function(){ + // summary: + // Handles zoom out. + // + zoomFactor /= zoomInc; + zoomFactor = Math.max(zoomFactor, minZoom); + this.canvas.setZoom(zoomFactor); + this.mouse.setZoom(zoomFactor); + }, + onClick: function(){ + this.onZoomOut(); + } + } + ); + + + dt.ZoomIn.setup = { + name:"dojox.drawing.plugins.tools.ZoomIn", + tooltip:"Zoom In" + }; + dojox.drawing.register(dt.ZoomIn.setup, "plugin"); + + dt.Zoom100.setup = { + name:"dojox.drawing.plugins.tools.Zoom100", + tooltip:"Zoom to 100%" + }; + dojox.drawing.register(dt.Zoom100.setup, "plugin"); + + dt.ZoomOut.setup = { + name:"dojox.drawing.plugins.tools.ZoomOut", + tooltip:"Zoom In" + }; + dojox.drawing.register(dt.ZoomOut.setup, "plugin"); + +})(); +}); |
