Etoys: MorphicExtras-kfr.58.mcz

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

Etoys: MorphicExtras-kfr.58.mcz

commits-2
Karl Ramberg uploaded a new version of MorphicExtras to project Etoys:
http://source.squeak.org/etoys/MorphicExtras-kfr.58.mcz

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

Name: MorphicExtras-kfr.58
Author: kfr
Time: 4 February 2012, 12:08:51 am
UUID: a3966eaa-1a4e-5442-bc6b-92d8cd68ff92
Ancestors: MorphicExtras-kfr.57

Add Ricardo Moran's "Sector" object to the system. Provides a new kind of object corresponding to a "sector" of a circle; its viewer offers items reporting the angle and radius of the sector.
http://tracker.squeakland.org/browse/SQ-1007

=============== Diff against MorphicExtras-kfr.57 ===============

Item was added:
+ ----- Method: Player>>getSectorAngle (in category '*MorphicExtras-AdditionalMorphs') -----
+ getSectorAngle
+ ^ self sendMessageToCostume: #angle!

Item was added:
+ ----- Method: Player>>getSectorRadius (in category '*MorphicExtras-AdditionalMorphs') -----
+ getSectorRadius
+ ^ self sendMessageToCostume: #radius!

Item was added:
+ ----- Method: Player>>setSectorAngle: (in category '*MorphicExtras-AdditionalMorphs') -----
+ setSectorAngle: aNumber
+ ^ self sendMessageToCostume: #angle: with: aNumber!

Item was added:
+ ----- Method: Player>>setSectorRadius: (in category '*MorphicExtras-AdditionalMorphs') -----
+ setSectorRadius: aNumber
+ ^ self sendMessageToCostume: #radius: with: aNumber!

Item was added:
+ PolygonMorph subclass: #SectorMorph
+ instanceVariableNames: 'angle'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'MorphicExtras-AdditionalMorphs'!

Item was added:
+ ----- Method: SectorMorph class>>additionsToViewerCategories (in category 'viewer categories') -----
+ additionsToViewerCategories
+ "Answer additions to viewer categories."
+
+ ^ #((basic
+ ((slot angle 'the angle, in degrees, at the vertex of the sector' Number readWrite Player getSectorAngle Player setSectorAngle:)
+ (slot radius 'length of a radius of the sector' Number readWrite Player getSectorRadius Player setSectorRadius:)))
+
+ (sector
+ ((slot angle 'the angle, in degrees, at the vertex of the sector' Number readWrite Player getSectorAngle Player setSectorAngle:)
+ (slot radius 'length of a radius of the sector' Number readWrite Player getSectorRadius Player setSectorRadius:)
+ (slot showingHandles 'Whether the handles are showing' Boolean readWrite Player getShowingHandles  Player setShowingHandles:)
+ )))!

Item was added:
+ ----- Method: SectorMorph class>>descriptionForPartsBin (in category 'parts bin') -----
+ descriptionForPartsBin
+ ^ self
+ partName: 'Sector' translatedNoop
+ categories: {'Graphics' translatedNoop}
+ documentation: 'A sector tool that lets you create slices of a pie of any angle for applications like fractions or drawing' translatedNoop!

Item was added:
+ ----- Method: SectorMorph>>addCustomMenuItems:hand: (in category 'menu & halo') -----
+ addCustomMenuItems: aMenu hand: aHandMorph
+ aMenu
+ addUpdating: #handlesShowingPhrase
+ target: self
+ action: #showOrHideHandles!

Item was added:
+ ----- Method: SectorMorph>>addHandles (in category 'editing') -----
+ addHandles
+ | handle |
+ self removeHandles.
+ handle := EllipseMorph
+ newBounds: (Rectangle center: vertices last extent: 16 @ 16)
+ color: Color yellow.
+ handle
+ on: #mouseMove
+ send: #dragEvent:fromHandle:
+ to: self.
+ handle
+ on: #mouseUp
+ send: #dropEvent:fromHandle:
+ to: self.
+ self addMorph: handle.
+ handles := {handle}.
+ self changed!

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

Item was added:
+ ----- Method: SectorMorph>>angle: (in category 'accessing') -----
+ angle: aNumber
+ angle = aNumber
+ ifTrue: [^ self].
+ angle := aNumber \\ 361.
+ self update!

Item was added:
+ ----- Method: SectorMorph>>computeBounds (in category 'updating') -----
+ computeBounds
+ super computeBounds.
+ self setRotationCenterFrom: vertices first!

Item was added:
+ ----- Method: SectorMorph>>dragEvent:fromHandle: (in category 'event handling') -----
+ dragEvent: evt fromHandle: morph
+ self angle: (evt position - vertices first * (1 @ -1)) degrees + self heading!

Item was added:
+ ----- Method: SectorMorph>>dropEvent:fromHandle: (in category 'event handling') -----
+ dropEvent: evt fromHandle: morph
+ self flag: #Richo!

Item was added:
+ ----- Method: SectorMorph>>extent: (in category 'accessing') -----
+ extent: newExtent
+ self radius: (newExtent x max: newExtent y)
+ / 2!

Item was added:
+ ----- Method: SectorMorph>>initialize (in category 'initialization') -----
+ initialize
+ angle := 45.
+ super initialize.
+ self initializeVertices; computeBounds!

Item was added:
+ ----- Method: SectorMorph>>initializeVertices (in category 'initialization') -----
+ initializeVertices
+ vertices := Array new: 50 withAll: 0 @ 0.
+ vertices at: 1 put: bounds bottomLeft;
+ at: 2 put: bounds bottomRight.
+ self updateVertices!

Item was added:
+ ----- Method: SectorMorph>>radius (in category 'accessing') -----
+ radius
+ ^ vertices first dist: vertices second!

Item was added:
+ ----- Method: SectorMorph>>radius: (in category 'accessing') -----
+ radius: aNumber
+ | v1 v2 dx dy ang dx2 dy2 |
+ self radius = aNumber
+ ifTrue: [^ self].
+ v1 := vertices first.
+ v2 := vertices second.
+ dx := v2 x - v1 x.
+ dx = 0
+ ifTrue: [dx := 0.0001].
+ dy := v2 y - v1 y.
+ ang := (dy / dx) arcTan.
+ (dx eToysLT: 0)
+ ifTrue: [(dy eToysGT: 0)
+ ifTrue: [ang:= ang + 3.1416]].
+ (dx eToysLT: 0)
+ ifTrue: [(dy eToysLT: 0)
+ ifTrue: [ang:= ang + 3.1416]].
+ dx2 := ang cos * aNumber.
+ dy2 := ang sin * aNumber.
+ vertices at: 2 put: v1 + (dx2 @ dy2).
+ self update!

Item was added:
+ ----- Method: SectorMorph>>update (in category 'updating') -----
+ update
+ self updateVertices; updateHandles; computeBounds!

Item was added:
+ ----- Method: SectorMorph>>updateHandles (in category 'updating') -----
+ updateHandles
+ | ign |
+ (ign := handles)
+ ifNotNil: [handles first center: vertices last]!

Item was added:
+ ----- Method: SectorMorph>>updateVertices (in category 'updating') -----
+ updateVertices
+ | nSegments sin cos xn yn xn1 yn1 |
+ nSegments := vertices size - 2.
+ sin := (angle / nSegments * (2 * Float pi / 360.0)) sin.
+ cos := (angle / nSegments * (2 * Float pi / 360.0)) cos.
+ xn := vertices second x - vertices first x.
+ yn := vertices second y - vertices first y.
+ 3
+ to: vertices size
+ do: [:i |
+ xn1 := xn * cos + (yn * sin).
+ yn1 := yn * cos - (xn * sin).
+ vertices at: i put: vertices first + (xn1 @ yn1).
+ xn := xn1.
+ yn := yn1]!

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