Etoys: Etoys-Richo.108.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Etoys: Etoys-Richo.108.mcz

commits-2
Ricardo Moran uploaded a new version of Etoys to project Etoys:
http://source.squeak.org/etoys/Etoys-Richo.108.mcz

==================== Summary ====================

Name: Etoys-Richo.108
Author: Richo
Time: 21 February 2012, 10:28:10 pm
UUID: 2092c689-2333-2848-83c2-12273c44c7a1
Ancestors: Etoys-Richo.107

* Added a morph to test if a key is currently pressed.

=============== Diff against Etoys-Richo.107 ===============

Item was changed:
  SystemOrganization addCategory: #'EToys-Kedama'!
  SystemOrganization addCategory: #'Etoys-Buttons'!
  SystemOrganization addCategory: #'Etoys-CustomEvents'!
  SystemOrganization addCategory: #'Etoys-Experimental'!
  SystemOrganization addCategory: #'Etoys-Help'!
  SystemOrganization addCategory: #'Etoys-Outliner'!
  SystemOrganization addCategory: #'Etoys-Protocols'!
  SystemOrganization addCategory: #'Etoys-Protocols-Type Vocabularies'!
  SystemOrganization addCategory: #'Etoys-Scratch'!
  SystemOrganization addCategory: #'Etoys-Scripting'!
  SystemOrganization addCategory: #'Etoys-Scripting Support'!
  SystemOrganization addCategory: #'Etoys-Scripting Tiles'!
  SystemOrganization addCategory: #'Etoys-Stacks'!
  SystemOrganization addCategory: #'Etoys-StarSqueak'!
  SystemOrganization addCategory: #'Etoys-Tile Scriptors'!
  SystemOrganization addCategory: #'Etoys-Widgets'!
  SystemOrganization addCategory: #'Etoys-SpeechBubbles'!
  SystemOrganization addCategory: #'Etoys-Debugger'!
  SystemOrganization addCategory: #'Etoys-Calendar'!
+ SystemOrganization addCategory: #'Etoys-Input'!

Item was added:
+ Morph subclass: #KeyPressMorph
+ instanceVariableNames: 'currentKey lastTimePressed isWaitingToSetCurrentKey'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Etoys-Input'!

Item was added:
+ ----- Method: KeyPressMorph class>>additionsToViewerCategories (in category 'viewer categories') -----
+ additionsToViewerCategories
+ ^ #(
+ (#input (
+ #(slot currentKey 'The current key' String readOnly Player getCurrentKey Player unused)
+ #(slot keyIsPressed 'Whether the current key is pressed at the moment' Boolean readOnly Player getKeyIsPressed Player unused)
+ #(slot timePressed 'The time in milliseconds the current key has been pressed' Number readOnly Player getTimePressed Player unused)
+ )))!

Item was added:
+ ----- Method: KeyPressMorph class>>descriptionForPartsBin (in category 'parts bin') -----
+ descriptionForPartsBin
+ ^ self
+ partName: 'Key press'
+ categories: #('Just for Fun' )
+ documentation: 'An object that tells you when a specific key has been pressed.'
+ !

Item was added:
+ ----- Method: KeyPressMorph>>changeCurrentKey (in category 'actions') -----
+ changeCurrentKey
+ isWaitingToSetCurrentKey
+ ifTrue: [self setCurrentKey: currentKey]
+ ifFalse: [self say: 'Press new key' translated;
+ color: Color red muchLighter.
+ isWaitingToSetCurrentKey := true]!

Item was added:
+ ----- Method: KeyPressMorph>>currentKey (in category 'accessing') -----
+ currentKey
+ ^ currentKey!

Item was added:
+ ----- Method: KeyPressMorph>>delete (in category 'initialize') -----
+ delete
+ super delete.
+ self unregisterToEvents!

Item was added:
+ ----- Method: KeyPressMorph>>duplicate (in category 'copying') -----
+ duplicate
+ ^ super duplicate registerToEvents!

Item was added:
+ ----- Method: KeyPressMorph>>handleKeyboardEvent: (in category 'events') -----
+ handleKeyboardEvent: anEvent
+ isWaitingToSetCurrentKey
+ ifTrue: [self setCurrentKey: anEvent keyString asLowercase]
+ ifFalse: [self setIsPressed: anEvent]
+ !

Item was added:
+ ----- Method: KeyPressMorph>>handleListenEvent: (in category 'events') -----
+ handleListenEvent: anEvent
+ anEvent isMouse
+ ifTrue: [self handleMouseEvent: anEvent]
+ ifFalse: [self handleKeyboardEvent: anEvent]!

Item was added:
+ ----- Method: KeyPressMorph>>handleMouseEvent: (in category 'events') -----
+ handleMouseEvent: anEvent
+ (isWaitingToSetCurrentKey and: [anEvent type = #mouseUp])
+ ifTrue: [self setCurrentKey: self currentKey]!

Item was added:
+ ----- Method: KeyPressMorph>>initialize (in category 'initialize') -----
+ initialize
+ super initialize.
+ currentKey := 'a'.
+ isWaitingToSetCurrentKey := false.
+ self layoutPolicy: TableLayout new;
+ listDirection: #topToBottom;
+ wrapCentering: #topLeft;
+ hResizing: #shrinkWrap;
+ vResizing: #shrinkWrap;
+ layoutInset: 5;
+ color: Color blue muchLighter;
+ borderColor: Color blue;
+ cornerStyle: #rounded;
+ rebuild;
+ registerToEvents!

Item was added:
+ ----- Method: KeyPressMorph>>isPressed (in category 'accessing') -----
+ isPressed
+ ^ self timePressed > 0!

Item was added:
+ ----- Method: KeyPressMorph>>rebuild (in category 'building') -----
+ rebuild
+ | keyButton |
+ self removeAllMorphs.
+ self addMorphBack: 'Key:' translated asMorph.
+ self addMorphBack: (keyButton := SimpleButtonMorph new
+ labelString: self currentKey;
+ color: Color white;
+ target: self;
+ actionSelector: #changeCurrentKey;
+ yourself).
+ keyButton width < 50
+ ifTrue: [keyButton width: 50]!

Item was added:
+ ----- Method: KeyPressMorph>>registerToEvents (in category 'events') -----
+ registerToEvents
+ self currentHand
+ addKeyboardListener: self;
+ addMouseListener: self!

Item was added:
+ ----- Method: KeyPressMorph>>setCurrentKey: (in category 'events') -----
+ setCurrentKey: aString
+ isWaitingToSetCurrentKey := false.
+ self stopSayingOrThinking;
+ color: Color blue muchLighter.
+ currentKey := aString.
+ self rebuild!

Item was added:
+ ----- Method: KeyPressMorph>>setIsPressed: (in category 'events') -----
+ setIsPressed: anEvent
+ anEvent keyString asLowercase = self currentKey asLowercase
+ ifFalse: [^ self].
+ anEvent type caseOf: {
+ [#keyDown] -> [self isPressed ifTrue: [^ self].
+ lastTimePressed := Time millisecondClockValue].
+ [#keyUp] -> [lastTimePressed := nil]
+ } otherwise: [].
+ lastTimePressed notNil
+ ifTrue: [self borderWidth: 2]
+ ifFalse: [self borderWidth: 0]
+ !

Item was added:
+ ----- Method: KeyPressMorph>>timePressed (in category 'accessing') -----
+ timePressed
+ ^ lastTimePressed
+ ifNil: [0]
+ ifNotNil: [:last | Time millisecondsSince: last]!

Item was added:
+ ----- Method: KeyPressMorph>>unregisterToEvents (in category 'events') -----
+ unregisterToEvents
+ self currentHand
+ removeKeyboardListener: self;
+ removeMouseListener: self!

Item was added:
+ ----- Method: KeyPressMorph>>usableSiblingInstance (in category 'copying') -----
+ usableSiblingInstance
+ ^ super usableSiblingInstance registerToEvents!

Item was added:
+ ----- Method: Player>>getCurrentKey (in category '*etoys-input') -----
+ getCurrentKey
+ ^ self sendMessageToCostume: #currentKey!

Item was added:
+ ----- Method: Player>>getKeyIsPressed (in category '*etoys-input') -----
+ getKeyIsPressed
+ ^ self sendMessageToCostume: #isPressed!

Item was added:
+ ----- Method: Player>>getTimePressed (in category '*etoys-input') -----
+ getTimePressed
+ ^ self sendMessageToCostume: #timePressed!

_______________________________________________
etoys-dev mailing list
[hidden email]
http://lists.squeakland.org/mailman/listinfo/etoys-dev