-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab4dad9
commit ca927b3
Showing
11 changed files
with
299 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
set main=./examples/canvasinput/thin-cursor.js | ||
cd .. | ||
cd .. | ||
npm run dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import phaser from 'phaser/src/phaser.js'; | ||
import CanvasInputPlugin from '../../plugins/canvasinput-plugin.js'; | ||
|
||
class Demo extends Phaser.Scene { | ||
constructor() { | ||
super({ | ||
key: 'examples' | ||
}) | ||
} | ||
|
||
preload() { | ||
|
||
} | ||
|
||
create() { | ||
var txt0 = CreateCanvasInput(this, 'Apple012345678901234567890123456789').setPosition(400, 100) | ||
var txt1 = CreateCanvasInput(this, 'A').setPosition(400, 200).appendText('pple') | ||
var txt2 = CreateCanvasInput(this, 'Apple').setPosition(400, 300).setReadOnly() | ||
var txt3 = CreateCanvasInput(this, 'Apple', 100).setPosition(100, 400).setOrigin(0) | ||
|
||
this.add.text(0, 0, 'Full screen') | ||
.setInteractive() | ||
.on('pointerdown', function () { | ||
if (this.scale.isFullscreen) { | ||
this.scale.stopFullscreen(); | ||
// On stop fulll screen | ||
} else { | ||
this.scale.startFullscreen(); | ||
// On start fulll screen | ||
} | ||
}, this) | ||
} | ||
|
||
update() { } | ||
} | ||
|
||
var CreateCanvasInput = function (scene, text, width) { | ||
if (width === undefined) { | ||
width = 600; | ||
} | ||
return scene.add.rexCanvasInput( | ||
{ | ||
width: width, | ||
|
||
background: { | ||
'focus.stroke': 'red', | ||
}, | ||
|
||
style: { | ||
fontSize: 24, | ||
backgroundBottomY: 5, | ||
backgroundHeight: 24, | ||
|
||
'range.backgroundColor': 'green', | ||
|
||
'cursor.backgroundColor': 'green', | ||
'cursor.backgroundHeight': 20, | ||
'cursor.backgroundBottomY': 2, | ||
'cursor.backgroundLeftX': 10, | ||
}, | ||
|
||
text: text, | ||
|
||
selectAll: true | ||
} | ||
) | ||
.on('keydown-ENTER', function (text) { | ||
console.log(text) | ||
}) | ||
} | ||
|
||
var config = { | ||
type: Phaser.AUTO, | ||
parent: 'phaser-example', | ||
width: 800, | ||
height: 600, | ||
scale: { | ||
mode: Phaser.Scale.FIT, | ||
autoCenter: Phaser.Scale.CENTER_BOTH, | ||
}, | ||
scene: Demo, | ||
plugins: { | ||
global: [{ | ||
key: 'rexCanvasInput', | ||
plugin: CanvasInputPlugin, | ||
start: true | ||
}] | ||
} | ||
}; | ||
|
||
var game = new Phaser.Game(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
plugins/gameobjects/dynamictext/canvasinput/methods/RegisterRangeStyle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import IsEmpty from '../../../../utils/object/IsEmpty.js'; | ||
import GetPartialData from '../../../../utils/object/GetPartialData.js'; | ||
import IsKeyValueEqual from '../../../../utils/object/IsKeyValueEqual.js'; | ||
|
||
var RegisterRangeStyle = function (rangeStyle) { | ||
if (IsEmpty(rangeStyle)) { | ||
return; | ||
} | ||
|
||
this | ||
.setRangeStyle(rangeStyle) | ||
.on('rangein', function (child) { | ||
var rangeStyle = this.rangeStyle; | ||
var styleSave = GetPartialData(child.style, rangeStyle); | ||
if (IsKeyValueEqual(rangeStyle, styleSave)) { | ||
return; | ||
} | ||
|
||
child.styleSave = styleSave; | ||
child.modifyStyle(rangeStyle); | ||
}, this) | ||
.on('rangeout', function (child) { | ||
if (!child.styleSave) { | ||
return; | ||
} | ||
|
||
child.modifyStyle(child.styleSave); | ||
child.styleSave = undefined; | ||
}, this) | ||
} | ||
|
||
export default RegisterRangeStyle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.