Skip to content

Commit

Permalink
use CSS to set special cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
novakps committed Jun 13, 2011
1 parent 1cc7fb2 commit 4d9d626
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 34 deletions.
14 changes: 13 additions & 1 deletion css/kemia.css
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,21 @@ See the COPYING file for details.
background-position: -142px;
}

kemia-eraser {
.kemia-eraser {
cursor: url(../images/erase-cursor-32.png), pointer;
}

.kemia-rotator {
cursor: url(../images/rotate-cursor-32.png), pointer;
}

.kemia-mover {
cursor: move;
}

.kemia-editor {
cursor: pointer;
}



File renamed without changes
File renamed without changes
5 changes: 3 additions & 2 deletions kemia/controller/plugins/atom_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ kemia.controller.plugins.AtomEdit.prototype.getKeyboardShortcuts = function() {
*/
kemia.controller.plugins.AtomEdit.prototype.resetState = function() {
this.symbol = undefined;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', false)
};

/**
Expand Down Expand Up @@ -169,15 +170,15 @@ kemia.controller.plugins.AtomEdit.prototype.handleKeyboardShortcut = function(e)
kemia.controller.plugins.AtomEdit.prototype.handleMouseMove = function(e) {
if (this.symbol) {
this.editorObject.clearSelected();
this.editorObject.getOriginalElement().style.cursor = 'default';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', false)
var target = this.editorObject.findTarget(e);
if (e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup.clear();
}

if (target instanceof kemia.model.Atom) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = 'pointer';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightAtom(target);
} else {
Expand Down
7 changes: 4 additions & 3 deletions kemia/controller/plugins/bond_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ kemia.controller.plugins.BondEdit.prototype.handleMouseMove = function(e) {
if (this.bond_type && !this._dragging) {
var target = this.editorObject.findTarget(e);
this.editorObject.clearSelected();
this.editorObject.getOriginalElement().style.cursor = 'default';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', false)
if (e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup.clear();
}
e.currentTarget.highlightGroup = undefined;

if (target instanceof kemia.model.Atom) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = 'pointer';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightAtom(target);
} else {
Expand All @@ -192,7 +192,7 @@ kemia.controller.plugins.BondEdit.prototype.handleMouseMove = function(e) {
return true;
} else if (target instanceof kemia.model.Bond) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = 'pointer';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightBond(target);
} else {
Expand Down Expand Up @@ -356,6 +356,7 @@ kemia.controller.plugins.BondEdit.prototype.highlightBond = function(bond,
*/
kemia.controller.plugins.BondEdit.prototype.resetState = function() {
this.bond_type = undefined;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', false)
};

/** @inheritDoc */
Expand Down
22 changes: 10 additions & 12 deletions kemia/controller/plugins/erase.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,17 @@ kemia.controller.plugins.Erase.prototype.execCommandInternal = function(
this.isActive = active;
};

kemia.controller.plugins.Erase.CURSOR_STYLE = 'url("../../elements/images/erase-cursor-32.png") 0 32, hand';

kemia.controller.plugins.Erase.prototype.handleMouseMove = function(e) {

if (this.isActive) {
var target = this.editorObject.findTarget(e);
this.editorObject.getOriginalElement().style.cursor = 'default';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-eraser', false)
if (e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup.clear();
}

if (target instanceof kemia.model.Atom) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Erase.CURSOR_STYLE;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-eraser', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightAtom(target);
} else {
Expand All @@ -88,7 +86,7 @@ kemia.controller.plugins.Erase.prototype.handleMouseMove = function(e) {
}
return true;
} else if (target instanceof kemia.model.Bond) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Erase.CURSOR_STYLE;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-eraser', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightBond(target);
} else {
Expand All @@ -97,7 +95,7 @@ kemia.controller.plugins.Erase.prototype.handleMouseMove = function(e) {
}
return true;
} else if (target instanceof kemia.model.Molecule) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Erase.CURSOR_STYLE;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-eraser', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightMolecule(target);
} else {
Expand All @@ -106,7 +104,7 @@ kemia.controller.plugins.Erase.prototype.handleMouseMove = function(e) {
}
return true;
} else if (target instanceof kemia.model.Plus) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Erase.CURSOR_STYLE;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-eraser', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightPlus(target);
} else {
Expand All @@ -115,9 +113,9 @@ kemia.controller.plugins.Erase.prototype.handleMouseMove = function(e) {
}
return true;
} else if (target instanceof kemia.model.Arrow) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Erase.CURSOR_STYLE;
if (!e.currentTarget.hightlightGroup) {
e.currentTarget.hightlightGroup = this.highlightArrow(target);
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-eraser', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightArrow(target);
} else {
e.currentTarget.highlightGroup = this.highlightArrow(target,
e.currentTarget.highlightGroup);
Expand Down Expand Up @@ -179,7 +177,7 @@ kemia.controller.plugins.Erase.prototype.eraseBond = function(bond) {
var molecule = bond.molecule;
molecule.removeBond(bond);
var fragments = molecule.getFragments();
this.logger.fine('fragements.length: ' + fragments.length);
// this.logger.fine('fragments.length: ' + fragments.length);
var reaction = molecule.reaction;
if (reaction) {
reaction.removeMolecule(molecule);
Expand Down Expand Up @@ -217,7 +215,7 @@ kemia.controller.plugins.Erase.prototype.eraseArrow = function(arrow) {
*/
kemia.controller.plugins.Erase.prototype.resetState = function() {
this.isActive = false;
this.editorObject.getOriginalElement().style.cursor = 'default';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-eraser', false)
};

/** @inheritDoc */
Expand Down
7 changes: 4 additions & 3 deletions kemia/controller/plugins/molecule_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ kemia.controller.plugins.MoleculeEdit.prototype.handleMouseMove = function(e) {
if (this.template) {
var target = this.editorObject.findTarget(e);
this.editorObject.clearSelected();
this.editorObject.getOriginalElement().style.cursor = 'default';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', false)
if (e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup.clear();
}
e.currentTarget.highlightGroup = undefined;

if (target instanceof kemia.model.Atom) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = 'pointer';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightAtom(target);
} else {
Expand All @@ -225,7 +225,7 @@ kemia.controller.plugins.MoleculeEdit.prototype.handleMouseMove = function(e) {
return true;
} else if (target instanceof kemia.model.Bond) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = 'pointer';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', true)
if (!e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup = this.highlightBond(target);
} else {
Expand Down Expand Up @@ -454,6 +454,7 @@ kemia.controller.plugins.MoleculeEdit.prototype.addTemplateToAtom = function(
*/
kemia.controller.plugins.MoleculeEdit.prototype.resetState = function() {
this.template = undefined;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-editor', false)
};

/** @inheritDoc */
Expand Down
25 changes: 12 additions & 13 deletions kemia/controller/plugins/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ kemia.controller.plugins.Move.COMMAND = {
kemia.controller.plugins.Move.SUPPORTED_COMMANDS_ = goog.object
.transpose(kemia.controller.plugins.Move.COMMAND);

kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE = 'url("../../elements/images/rotate-cursor-32.png") 16 16, pointer';

/** @inheritDoc */
kemia.controller.plugins.Move.prototype.isSupportedCommand = function(command) {
return command in kemia.controller.plugins.Move.SUPPORTED_COMMANDS_;
Expand All @@ -69,6 +67,7 @@ kemia.controller.plugins.Move.prototype.getTrogClassId = goog.functions
kemia.controller.plugins.Move.prototype.resetState = function() {
this.isActive[kemia.controller.plugins.Move.COMMAND.MOVE] = false;
this.isActive[kemia.controller.plugins.Move.COMMAND.ROTATE] = false;
goog.dom.classes.remove(this.editorObject.getOriginalElement(), 'kemia-rotator', 'kemia-mover')
};

/**
Expand All @@ -90,15 +89,15 @@ kemia.controller.plugins.Move.prototype.handleMouseMove = function(e) {
&& !this.isDragging) {
var target = this.editorObject.findTarget(e);
this.editorObject.clearSelected();
this.editorObject.getOriginalElement().style.cursor = 'default';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-rotator', false)
if (e.currentTarget.highlightGroup) {
e.currentTarget.highlightGroup.clear();
}
if (this.isActive[kemia.controller.plugins.Move.COMMAND.ROTATE]) {
//rotate
if (target instanceof kemia.model.Molecule) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-rotator', true)
e.currentTarget.highlightGroup = this.highlightMolecule(
target, e.currentTarget.highlightGroup);
return true;
Expand All @@ -107,7 +106,7 @@ kemia.controller.plugins.Move.prototype.handleMouseMove = function(e) {
//move
if (target instanceof kemia.model.Atom) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = 'move';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-mover', true)
e.currentTarget.highlightGroup = this.highlightAtom(target,
e.currentTarget.highlightGroup);
return true;
Expand All @@ -116,14 +115,14 @@ kemia.controller.plugins.Move.prototype.handleMouseMove = function(e) {
if (bond.source.bonds.getValues().length == 1
|| bond.target.bonds.getValues().length == 1) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = 'move';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-mover', true)
e.currentTarget.highlightGroup = this.highlightBond(
target, e.currentTarget.highlightGroup);
}
return true;
} else if (target instanceof kemia.model.Molecule) {
this.editorObject.addSelected(target);
this.editorObject.getOriginalElement().style.cursor = 'move';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-mover', true)

e.currentTarget.highlightGroup = this.highlightMolecule(
target, e.currentTarget.highlightGroup);
Expand All @@ -132,7 +131,7 @@ kemia.controller.plugins.Move.prototype.handleMouseMove = function(e) {
} else if (target instanceof kemia.model.Arrow) {
this.editorObject.addSelected(target);
if (!e.shiftKey) {
this.editorObject.getOriginalElement().style.cursor = 'move';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-mover', true)

e.currentTarget.highlightGroup = this.highlightArrow(
target, e.currentTarget.highlightGroup);
Expand All @@ -142,15 +141,15 @@ kemia.controller.plugins.Move.prototype.handleMouseMove = function(e) {
} else if (target instanceof kemia.model.Plus) {
this.editorObject.addSelected(target);
if (!e.shiftKey) {
this.editorObject.getOriginalElement().style.cursor = 'move';
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-mover', true)

e.currentTarget.highlightGroup = this.highlightPlus(
target, e.currentTarget.highlightGroup);

return true;
}
} else if (!target) {
this.editorObject.getOriginalElement().style.cursor = 'all-scroll';
} else if (!target) {
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-mover', true)
return true;
}
}
Expand All @@ -173,7 +172,7 @@ kemia.controller.plugins.Move.prototype.handleMouseDown = function(e) {
if (target instanceof kemia.model.Molecule) {
var molecule = target;
this.editorObject.dispatchBeforeChange();
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-rotator', true)
this.rotateMolecule(e, target);
this.editorObject.dispatchChange();
return true;
Expand Down Expand Up @@ -202,7 +201,7 @@ kemia.controller.plugins.Move.prototype.handleMouseDown = function(e) {
var molecule = target;
this.editorObject.dispatchBeforeChange();
if (e.shiftKey) {
this.editorObject.getOriginalElement().style.cursor = kemia.controller.plugins.Move.ROTATE_CURSOR_STYLE;
goog.dom.classes.enable(this.editorObject.getOriginalElement(), 'kemia-rotator', true)
this.rotateMolecule(e, target);
} else {
this.dragMolecule(e, target);
Expand Down

0 comments on commit 4d9d626

Please sign in to comment.