Added keyboard shortcut to open color picker

This commit is contained in:
Igor Zinken
2021-01-16 20:46:52 +01:00
parent c55de06fea
commit 1e5ce673d7
3 changed files with 26 additions and 11 deletions

View File

@@ -68,9 +68,11 @@ export default {
}
});
pickrInstance.on( "save", this.saveColor.bind( this ));
window.pickrInstance = pickrInstance;
},
destroy() {
pickrInstance?.destroyAndRemove();
window.pickrInstance = null;
},
methods: {
saveColor( value ) {

View File

@@ -220,9 +220,13 @@ function handleKeyDown( event ) {
case 67: // C
// copy current selection
if ( hasOption && getters.activeDocument?.selection?.length > 0 ) {
dispatch( "requestSelectionCopy" );
preventDefault( event );
if ( hasOption ) {
if ( getters.activeDocument?.selection?.length > 0 ) {
dispatch( "requestSelectionCopy" );
preventDefault( event );
}
} else {
window.pickrInstance?.show();
}
break;
@@ -273,8 +277,10 @@ function handleKeyDown( event ) {
break;
case 76: // L
if ( hasOption && shiftDown ) {
openModal( ADD_LAYER );
if ( hasOption ) {
if ( shiftDown ) {
openModal( ADD_LAYER );
}
} else {
commit( "setActiveTool", { tool: ToolTypes.LASSO })
setActiveTool( ToolTypes.LASSO );
@@ -337,9 +343,11 @@ function handleKeyDown( event ) {
case 86: // V
// paste current selection
if ( hasOption && !!state.selectionContent ) {
dispatch( "pasteSelection" );
preventDefault( event ); // override browser paste
if ( hasOption ) {
if ( !!state.selectionContent ) {
dispatch( "pasteSelection" );
preventDefault( event ); // override browser paste
}
} else if ( getters.activeDocument ) {
setActiveTool( ToolTypes.DRAG );
}

View File

@@ -27,6 +27,9 @@ import { distanceBetween, angleBetween, pointBetween, translatePointerRotation }
import { randomInRange } from "@/math/unit-math";
import { createCanvas, resizeImage } from "@/utils/canvas-util";
const { cos, sin } = Math;
const TWO_PI = Math.PI * 2;
const tempCanvas = createCanvas();
export const renderCross = ( ctx, x, y, size ) => {
@@ -78,10 +81,12 @@ export const renderBrushStroke = ( sprite, brush, ctx, destinationPoint ) => {
if ( type === BrushTypes.SPRAY ) {
ctx.fillStyle = brush.colors[ 0 ];
for ( let i = doubleRadius; i--; ) {
const angle = randomInRange( 0, TWO_PI );
const size = randomInRange( 1, 3 );
ctx.fillRect(
destinationPoint.x + randomInRange( -halfRadius, halfRadius ),
destinationPoint.y + randomInRange( -halfRadius, halfRadius ),
1, 1
destinationPoint.x + randomInRange( -halfRadius, halfRadius ) * cos( angle ),
destinationPoint.y + randomInRange( -halfRadius, halfRadius ) * sin( angle ),
size, size
);
}
return ctx.restore();