Karl Ramberg uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-kfr.1023.mcz ==================== Summary ==================== Name: Morphic-kfr.1023 Author: kfr Time: 1 November 2015, 9:20:03.104 pm UUID: 3f59454c-b3fb-44ac-a78a-29c653670044 Ancestors: Morphic-kfr.1022 Adding a code pane for reading/editing of the color ramp =============== Diff against Morphic-kfr.1022 =============== Item was changed: ----- Method: GradientEditor>>addHandles (in category 'change reporting') ----- addHandles | handle colorRamp | rampMorphs := OrderedCollection new. + colorRamp := gradientDisplay colorRamp asOrderedCollection. - colorRamp := self gradientDisplay colorRamp asOrderedCollection. handle := self handle. colorRamp do: [:i | self addHandleForColor: i value position: i key ]. self changed.! Item was changed: ----- Method: GradientEditor>>colorRamp (in category 'accessing') ----- colorRamp + ^gradientDisplay fillStyle colorRamp asArray printString. + ! - | i string | - string := gradientDisplay fillStyle colorRamp asOrderedCollection printString. - i := string indexOf:$(. - ^string copyFrom: i to: string size! Item was changed: ----- Method: GradientEditor>>colorRamp: (in category 'accessing') ----- colorRamp: aColorRamp - - "rampMorphs do:[ :i | rampMorphs remove:i. row removeMorph: i . ]. - self changed." gradientDisplay colorRamp: aColorRamp. + self changed: #colorRamp. + self changed + - self addHandles. ! Item was added: + ----- Method: GradientEditor>>colorRampExpression: (in category 'accessing') ----- + colorRampExpression: aString + "Set my color by evaluating aString, a Smalltalk expression which results in a Color instance." + | col | + + {aString.} + detect: + [ : each | ([ col := Compiler evaluate: each ] + on: Error + do: + [ : err | nil ]) notNil ] + ifNone: [ nil ]. + col ifNotNil: [ self colorRamp: col. + rampMorphs do:[ :each| each delete]. + self addHandles; updateColorRamp. ]! Item was added: + ----- Method: GradientEditor>>colorRampExpressionMorph (in category 'initialization') ----- + colorRampExpressionMorph + | inputField builder | + builder := ToolBuilder default. + inputField := (builder build: (builder pluggableInputFieldSpec new + model: self; + getText: #colorRamp; + setText: #colorRampExpression:; + softLineWrap: true)). + inputField + hResizing: #spaceFill ; + vResizing: #spaceFill ; + + height: (Preferences standardDefaultTextFont height * 3/2). + ^ inputField! Item was changed: ----- Method: GradientEditor>>eventHandler:target: (in category 'event handling') ----- + eventHandler: anInstance target: aTarget + (anInstance isKindOf: SketchMorph) + ifTrue: [anInstance + on: #mouseUp - eventHandler: anInstance target: aTarget - (anInstance isKindOf: SketchMorph) - ifTrue:[anInstance on: #mouseUp send: #changeColor:event:target: + to: self + withValue: aTarget] + ifFalse: [anInstance + on: #mouseDown - to: self withValue: aTarget] - ifFalse:[anInstance on: #mouseDown send: #limitHandleMove:event:from: + to: self + withValue: aTarget. + anInstance + on: #mouseMove - to: self withValue: aTarget. - anInstance on: #mouseMove send: #limitHandleMove:event:from: + to: self + withValue: aTarget]! - to: self withValue: aTarget]! Item was removed: - ----- Method: GradientEditor>>gradientDisplay (in category 'accessing') ----- - gradientDisplay - ^gradientDisplay! Item was changed: ----- Method: GradientEditor>>handle (in category 'initialization') ----- handle + | handle | + handle := PolygonMorph - | handle | - handle := PolygonMorph vertices: (Array with: 0 @ 0 with: 16 @ 0 with: 8 @ 16) + color: Color white darker - color: (Color white darker) borderWidth: 1 borderColor: Color black. + ^ handle - ^handle addMorph: ((RectangleMorph newBounds: (8 @ 18 extent: 1 @ (gradientDisplay height - 2)) color: Color orange) + borderWidth: 0)! - borderWidth: 0).! Item was changed: ----- Method: GradientEditor>>initialize (in category 'initialization') ----- initialize - super initialize. self myLayout. + self extent: 500 @ 200. + row := RectangleMorph new extent: self width @ 100; + color: Color transparent; + borderColor: #inset. - self extent: 600 @ 150. - row := RectangleMorph new extent: self width @ 100; color: Color transparent; borderColor: #inset. - row addMorph: (gradientDisplay := GradientDisplayMorph new position: 20 @ 20; extent: self width - 40 @ 40). gradientDisplay fillStyle direction: gradientDisplay width @ 0. - self addMorph: row. self addButtonRow. + self addMorph: self colorRampExpressionMorph! - "text := PluggableTextMorph - on: self - text: #colorRamp - accept: nil - readSelection: nil - menu: nil. - text color: Color white; - width: self width; - height: 50. - self addMorph: text." - ! Item was changed: ----- Method: GradientEditor>>setTarget:selector:forMorph:colorRamp: (in category 'initialization') ----- setTarget: aTarget selector: aSelector forMorph:aMorph colorRamp: aColorRamp + self target: aTarget; selector: aSelector; morph: aMorph; colorRamp: aColorRamp; addHandles - self target: aTarget. - self selector: aSelector. - self morph: aMorph. - self colorRamp: aColorRamp. ! Item was changed: ----- Method: GradientEditor>>updateColorRamp (in category 'change reporting') ----- updateColorRamp | newAssociation newKey newColor sketch colorRamp | self updateRampMorphs. colorRamp := OrderedCollection new. rampMorphs do: [:i | newKey := ((i position x - gradientDisplay left / gradientDisplay width) asFloat roundUpTo: 0.01) min: 1.0 max: 0.0. sketch := i findA: SketchMorph. newColor := sketch rotatedForm colorAt: sketch rotatedForm center. newAssociation := newKey -> newColor. colorRamp addLast: newAssociation]. colorRamp := colorRamp sorted. gradientDisplay colorRamp: colorRamp. gradientDisplay fillStyle direction: gradientDisplay extent x @ 0. self changed. target ifNotNil:[ target perform: selector with: colorRamp with: morph]. + self changed: #colorRamp! - "text setText: self colorRamp"! |
Free forum by Nabble | Edit this page |