Paint Editor: Pipette tool

and code formatting adjustments for JSLint
pull/3/merge
jmoenig 2013-07-12 11:28:55 +02:00
rodzic 7eba03eaf1
commit 1a8b2658db
2 zmienionych plików z 88 dodań i 45 usunięć

Wyświetl plik

@ -1805,3 +1805,8 @@ ______
* Blocks: fixed occasional flickering in scripting areas (caused by deleted feedback morphs, a bug that surfaced in Chrome 28 on OSX and may be due to a possible Chrome GC issue)
* Blocks: preserve nested blocks in the scripting area when replacing a variadic input list with another input ("kick out" the nested blocks instead of "swallowing" them)
* Blocks, Threads: new floor() function in monadic math reporter's drop-down
130712
------
* Blocks: Pipette symbol
* Paint: Pipette tool

Wyświetl plik

@ -46,8 +46,9 @@
revision history
----------------
May 10 - first full release (Kartik)
May 14 - bugfixes (bugfixes, Snap integration (Jens)
May 14 - bugfixes, Snap integration (Jens)
May 16 - flat design adjustments (Jens)
July 12 - pipette tool, code formatting adjustments (Jens)
*/
@ -56,12 +57,12 @@
CostumeIconMorph, IDE_Morph, Costume, SpriteMorph, nop, Image, WardrobeMorph,
TurtleIconMorph, localize, MenuMorph, InputFieldMorph, SliderMorph,
ToggleMorph, ToggleButtonMorph, BoxMorph, modules, radians,
MorphicPreferences
MorphicPreferences, getDocumentPositionOf
*/
// Global stuff ////////////////////////////////////////////////////////
modules.paint = '2013-May-16';
modules.paint = '2013-July-12';
// Declarations
@ -166,7 +167,9 @@ PaintEditorMorph.prototype.buildToolbox = function() {
circleSolid:
"Filled Ellipse\n(shift: circle)",
paintbucket:
"Fill a region"
"Fill a region",
pipette:
"Pipette tool\n(pick a color anywhere)"
},
myself = this,
left = this.toolbox.left(),
@ -381,6 +384,9 @@ PaintEditorMorph.prototype.toolButton = function(icon, hint) {
myself.paper.currentTool = icon;
myself.paper.toolChanged(icon);
myself.refreshToolButtons();
if (icon === 'pipette') {
myself.getUserColor();
}
},
new SymbolMorph(icon, 18),
function () {return myself.paper.currentTool === icon; }
@ -402,6 +408,38 @@ PaintEditorMorph.prototype.pushButton = function(title, action, hint) {
);
};
PaintEditorMorph.prototype.getUserColor = function () {
var myself = this,
world = this.world(),
hand = world.hand,
posInDocument = getDocumentPositionOf(world.worldCanvas),
mouseMoveBak = hand.processMouseMove,
mouseDownBak = hand.processMouseDown,
mouseUpBak = hand.processMouseUp;
hand.processMouseMove = function (event) {
var color;
hand.setPosition(new Point(
event.pageX - posInDocument.x,
event.pageY - posInDocument.y
));
color = world.getGlobalPixelColor(hand.position());
myself.propertiesControls.colorpicker.action(color);
myself.paper.settings.primarycolor = color;
};
hand.processMouseDown = nop;
hand.processMouseUp = function () {
myself.paper.currentTool = 'brush';
myself.paper.toolChanged('brush');
myself.refreshToolButtons();
hand.processMouseMove = mouseMoveBak;
hand.processMouseDown = mouseDownBak;
hand.processMouseUp = mouseUpBak;
};
};
// AdvancedColorPickerMorph //////////////////
// A large hsl color picker