[ENH] Set image as background from FileList

Brent Vukmer bvukmer at blackboard.com
Sat Nov 23 18:36:15 UTC 2002


-------------- next part --------------
'From Squeak3.4alpha of ''11 November 2002'' [latest update: #5125] on 23 November 2002 at 1:32:47 pm'!
"Change Set:		FileList-Form-bkv
Date:			23 November 2002
Author:			Brent Vukmer

For 3.4alpha images only.  This changeset tweaks the services that Form registers with FileList; specifically, it enhances the capabilities of the 'background' button that appears when browsing an image file.  This code was based on Stephan Wessels  set-image-as-background code -- you can find that, and many other groovy Squeak goodies, at: http://w3.one.net/~swessels/pages/steve/squeak/index.html "!


!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/22/2002 18:54'!
fileReaderServicesForFile: fullName suffix: suffix

	^( self registeredImageFileSuffixes includes: suffix )
		ifTrue: [ self services ]
		ifFalse: [#()]
! !

!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/23/2002 13:05'!
openAsBackgroundWithOptions: fullName
	| choices actions response theForm |

	theForm _ self fromFileNamed: fullName.
	Smalltalk isMorphic
		ifFalse: [^ theForm setAsBackground].
	choices _ #('Tile the image' 'Scale the image full' 'Scale the image keep aspect' 'Center the image' ).
	actions _ #(#setAsBackgroundTiled: #setAsBackgroundScaleFull: #setAsBackgroundKeepAspect: #setAsBackgroundCenter: ).
	response _ (SelectionMenu labelList: choices selections: actions)
				startUpWithCaption: 'Set in background with option...'.
     ( response notNil ) 
          ifTrue: [ ^self perform: response withArguments: { theForm. } ].

! !

!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/22/2002 18:59'!
openImageCenteredOnBackground: image 
	| sketch previous |
	sketch _ SketchMorph withForm: image.
	sketch setToAdhereToEdge: #center;
		 name: 'worldBackgroundImage';
		 lock.
	previous _ self currentWorld submorphNamed: 'worldBackgroundImage'.
	previous isNil
		ifFalse: [previous delete].
	sketch openInWorld.
	sketch goBehind.! !

!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/22/2002 18:54'!
registeredImageFileSuffixes
"Form registers its services with FileList, for files ending with one of these suffixes."

	^{ 'bmp'. 'gif'. 'jpg'.  'form'. '*'. 'png'. }

! !

!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/22/2002 18:56'!
serviceImageAsBackground
	"Answer a service for setting the desktop background from a given graphical file's contents"

	^ SimpleServiceEntry 
		provider: self 
		label: 'use graphic as background'
		selector: #openAsBackgroundWithOptions:
		description: 'use the graphic as the background for the desktop'
		buttonLabel: 'background'! !

!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/23/2002 13:01'!
setAsBackgroundCenter: formFromImageFile
^ self openImageCenteredOnBackground: formFromImageFile
! !

!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/23/2002 13:00'!
setAsBackgroundKeepAspect: formFromImageFile

^ self openImageCenteredOnBackground: (formFromImageFile scaledToSize: self currentWorld extent)! !

!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/23/2002 13:00'!
setAsBackgroundScaleFull: formFromImageFile

^(formFromImageFile scaledToSize: self currentWorld extent) setAsBackground! !

!Form class methodsFor: 'fileIn/Out' stamp: 'bkv 11/23/2002 13:02'!
setAsBackgroundTiled: formFromImageFile
^formFromImageFile setAsBackground



! !



More information about the Squeak-dev mailing list