BorderedMorph subclass: #GreetingMorph instanceVariableNames: 'music greetString ' classVariableNames: '' poolDictionaries: '' category: 'Morphic-Greeting'! !GreetingMorph methodsFor: 'stepping' stamp: 'EDC 8/21/2002 17:40'! step | x y n each | submorphs size = 0 ifTrue: [ self doGreet]. n _ (1 to: submorphs size) atRandom. each _ submorphs at: n. each class == ImageMorph ifTrue: [^self]. x _ (20 to: 730) atRandom. y _ (20 to: 470) atRandom. each position: x@y. each comeToFront. self refreshWorld ! ! !GreetingMorph methodsFor: 'stepping' stamp: 'EDC 7/20/2002 07:20'! stepTime "Answer the desired time between steps in milliseconds." ^ 1000! ! !GreetingMorph methodsFor: 'menu' stamp: 'EDC 7/21/2002 06:20'! addCustomMenuItems: aCustomMenu hand: aHandMorph "Include our modest command set in the ctrl-menu" super addCustomMenuItems: aCustomMenu hand: aHandMorph. aCustomMenu addLine. self addMenuItemsTo: aCustomMenu hand: aHandMorph! ! !GreetingMorph methodsFor: 'menu' stamp: 'EDC 7/22/2002 08:03'! addMenuItemsTo: aMenu hand: aHandMorph aMenu add: 'new background color' target: self action: #chooseColor. aMenu add: 'new midi music.' target: self action: #chooseMidi. aMenu add: 'save this greet' target: self action: #saveMorph! ! !GreetingMorph methodsFor: 'initialization' stamp: 'EDC 7/20/2002 15:41'! backColor: aColor self color: aColor! ! !GreetingMorph methodsFor: 'initialization' stamp: 'EDC 7/21/2002 06:25'! chooseColor | buttons file rgb linea valores b max paleta maxX x y cuenta | paleta _ PasteUpMorph new. paleta layoutPolicy: nil. paleta hResizing: #rigid. paleta vResizing: #rigid. paleta borderWidth: 2. paleta borderColor: Color black. paleta color: Color white. paleta openInWorld. maxX _ 0. x _ 0. y _ 0. cuenta _ 0. buttons _ OrderedCollection new. file _ FileStream oldFileNamed: 'ColoresCrayon.text'. [file atEnd] whileFalse: [ linea_ file nextLine. valores _ linea findTokens: Character space. rgb _ valores collect: [:each| (each asInteger / 65535) asFloat]. linea_ file nextLine. b _ (SimpleButtonMorph new label: linea; color: (Color fromArray: rgb); target: self; actionSelector: #backColor:; arguments: (Array with: (Color fromArray: rgb)) ). buttons add: b]. b _ (SimpleButtonMorph new label: 'Enough Fun ?'; color: Color white; target: self; actionSelector: #killFrontDialog). buttons add: b. "Compute the max width" max _ 0. buttons do: [:each | max _ each width max: max]. "Set all widths to the max value" buttons do: [:each | each width: max]. buttons reverseDo: [:each | each position: x@y. paleta addMorph: each. cuenta < 7 ifTrue: [x _ x + each width. cuenta _ cuenta + 1] ifFalse: [y _ y + each height. x > maxX ifTrue: [maxX _ x]. x _ 0. cuenta _ 0. ]]. maxX _ maxX + 10 . y _ y + 10. paleta extent: maxX @ y. paleta position: 30@30 . paleta becomeLikeAHolder. ! ! !GreetingMorph methodsFor: 'initialization' stamp: 'EDC 7/22/2002 08:08'! chooseMidi | f score fileName | fileName _ Utilities chooseFileWithSuffixFromList: #('.mid' '.midi') withCaption: 'Choose a MIDI file to open'. (fileName isNil or: [ fileName == #none ]) ifTrue: [^ self inform: 'No .mid/.midi files found in the Squeak directory']. f _ FileStream readOnlyFileNamed: fileName. score _ (MIDIFileReader new readMIDIFrom: f binary) asScore. f close. music _ ScorePlayer onScore: score. ! ! !GreetingMorph methodsFor: 'initialization' stamp: 'EDC 8/21/2002 17:24'! choosePhoto | fileName foto | fileName _ Utilities chooseFileWithSuffixFromList: #('.jpg' '.gif') withCaption: 'Choose a graphic file to open'. (fileName isNil or: [ fileName == #none ]) ifTrue: [^ self inform: 'No .mid/.midi files found in the Squeak directory']. foto _ (Form fromFileNamed: fileName) asMorph. self addMorphCentered: foto ! ! !GreetingMorph methodsFor: 'initialization' stamp: 'EDC 7/22/2002 08:25'! doGreet | greetWords cartel | music reset. music resumePlaying. self position: 18 @ 0. self toggleStickiness. greetWords _ greetString findTokens: Character space. greetWords do: [:greet | cartel _ TTSampleStringMorph new initializeToStandAlone. cartel string: greet. cartel center: self center. cartel bottom: self bottom + 10. self addMorphBack: cartel. self openInWorld]! ! !GreetingMorph methodsFor: 'initialization' stamp: 'EDC 8/21/2002 17:25'! initialize super initialize. self extent: 750 @ 490. self color: Color paleBlue. self borderWidth: 2. greetString _ FillInTheBlank request: 'Please, type your message' initialAnswer: 'Edgar, from SqueakRos, say long life and prosperity.'. self choosePhoto. self chooseMidi. self doGreet! ! !GreetingMorph methodsFor: 'initialization' stamp: 'EDC 7/21/2002 06:05'! killFrontDialog | dialog | . dialog _ ActiveWorld submorphs detect: [:m | m class == PasteUpMorph]. dialog delete.! ! !GreetingMorph methodsFor: 'fileIn/out' stamp: 'EDC 7/22/2002 08:12'! saveMorph self stopStepping. submorphs _ EmptyArray. ^ self saveOnFile! ! !GreetingMorph methodsFor: 'event handling' stamp: 'EDC 5/17/2002 05:34'! handlesMouseDown: evt "Prevent stray clicks from picking up the whole game in MVC." ^ Smalltalk isMorphic not or: [evt yellowButtonPressed]! ! !GreetingMorph methodsFor: 'event handling' stamp: 'EDC 5/17/2002 05:32'! mouseDown: evt | menu | evt yellowButtonPressed ifFalse: [^ self]. menu _ MenuMorph new defaultTarget: self. self addMenuItemsTo: menu hand: evt hand. menu popUpEvent: evt in: self world! !