In my tutorial I've been building a quadrangle editor.
The idea is that there are two menuus. One appears if I click on the background, the other if I click inside a quadrangle. In the quad menu I have options to move, resize, set color and delete the quadrangle that is being clicked. It all works ok except for the resize and move options. Here is the menu building code that holds the critical blocks. What I'm trying to do in both cases is create a new quadrangle from the original and replace the original in the OrderedCollection which is the super class for the editor. edit "edit a quadrangle" | menu cmdMenu quadMenu finished point actions quadActions cmdActions select qd | quadMenu := PopUpMenu labels: 'move resize set to red delete' lines: #(3 ). quadActions := Array new: 4. quadActions at: 1 put: [:q | self at: (self whichIndex: q) put: (q translateBy: Point fromUser)]. quadActions at: 2 put: [:q | self at: (self whichIndex: q) put: (q scaleBy: Point fromUser)]. quadActions at: 3 put: [:q | q insideColor: Color red]. quadActions at: 4 put: [:q | super removeAt: (self whichIndex: q)]. whichIndex is a new method I added to the editor, and it seems to work since the remove menu action works OK. It looks like: whichIndex: aQuad "returns index containing aQuad or nil" 1 to: lastIndex do: [:i | (self at: i) == aQuad ifTrue: [^ i]]. ^ nil I assume I'm misunderstanding how translateBy and scaleBy work, or something? But I'm stuck. Any clues or pointers welcomed! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On 28/12/11 10:12, Alan Gauld wrote:
> In my tutorial I've been building a quadrangle editor. Some progress, move now works: quadActions at: 1 put: [:q | self at: (self whichIndex: q) put: (q translateBy: Point fromUser - q origin)]. My previous version was actually moving it but moving it off the display so it looked like it had been killed. BTW Apologies if the formatting is getting lost (as per below) I'm supposed to be using plain text according to Thunderbird! Now for resize... > Here is the menu building code that holds the critical blocks. > What I'm trying to do in both cases is create a new quadrangle from the > original and replace the original in the OrderedCollection which is the > super class for the editor. > > edit > "edit a quadrangle" > | menu cmdMenu quadMenu finished point > actions quadActions cmdActions select qd | > > quadMenu := PopUpMenu labels: 'move > resize > set to red > delete' lines: #(3 ). > quadActions > at: 2 > put: [:q | self > at: (self whichIndex: q) > put: (q scaleBy: Point fromUser)]. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
On 29/12/11 11:43, Alan Gauld wrote:
> On 28/12/11 10:12, Alan Gauld wrote: >> In my tutorial I've been building a quadrangle editor. > > Some progress, move now works: And eventually resize, although not using scaleBy, I gave up on that. Here is what I used: quadActions at: 2 put: [:q | q region: (Rectangle origin: q origin corner: Point fromUser)]. Onwards and upwards.... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |