[squeak-dev] The Inbox: Morphic-kfr.1619.mcz

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Fri Feb 7 23:16:56 UTC 2020


+1 :-)

<http://www.hpi.de/>
________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von commits at source.squeak.org <commits at source.squeak.org>
Gesendet: Freitag, 7. Februar 2020 23:38:45
An: squeak-dev at lists.squeakfoundation.org
Betreff: [squeak-dev] The Inbox: Morphic-kfr.1619.mcz

A new version of Morphic was added to project The Inbox:
http://source.squeak.org/inbox/Morphic-kfr.1619.mcz

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

Name: Morphic-kfr.1619
Author: kfr
Time: 7 February 2020, 11:38:33.017512 pm
UUID: 7e9d5c46-aad5-ed46-b88d-22f30b5f597f
Ancestors: Morphic-cmm.1618

Enhancement for PolygonMorph. When a vertex is dropped it will snap if it is close to another PolygonMorphs vertex. It is possible to toggle functionality on/ off in menu.
( With suggestion from Christoph Thiede about basing snapping distance on screen resolution)

=============== Diff against Morphic-cmm.1618 ===============

Item was changed:
  BorderedMorph subclass: #PolygonMorph
+        instanceVariableNames: 'vertices closed filledForm arrows arrowForms smoothCurve curveState borderDashSpec handles borderForm snapToOtherPolygons'
-        instanceVariableNames: 'vertices closed filledForm arrows arrowForms smoothCurve curveState borderDashSpec handles borderForm'
         classVariableNames: ''
         poolDictionaries: ''
         category: 'Morphic-Basic'!

  !PolygonMorph commentStamp: 'md 2/24/2006 20:34' prior: 0!
  This class implements a morph which can behave as four different objects depending on the the following two facts:
  - is it OPEN or CLOSED?
  - is it SEGMENTED or SMOOTHED.

  1. The OPEN and SEGMENTED variant looks like polyline.

  2. The OPEN and SMOOTHED variant looks like spline (kind of curve)

  3. The CLOSED and SEGMENTED variant looks like polygon. This is actually what you get when you do
         PolygonMorph new openInWorld
  You get a triangle. See below how to manipulate these objects...

  4. The CLOSED and SMOOTHED variant looks like blob (???)

  Prototypes of this morph can also be found in "Object Catalog". Several (different variants) of this object are among "Basic" morphs.

  Explore the assiciated morph-menu. It enables you
  - to toggle showing of "handles". They make it possible to
         - reposition already existing vertices (by moving yellow handles)
         - create new vertices (by moving green handles)
         - delete already existing vertices (by dragging and dropping one yellow handle closely
           nearby the adjacent yellow handle
    Handles can be made visible/hidden by shift+leftclicking the morph. This way it is possible
    to quickly show handles, adjust vertices and then again hide handles.
  - making closed polygon open, i.e. converting it to a curve (and vice versa)
  - toggle smoothed/segmented line/outline
  - set up custom dashing (for line, curves or borders of closed polygons
  - set up custom arrow-heads (for lines resp. curves)

  ------------------------------------------------------------------------------------------
  Implementation notes:

  This class combines the old Polygon and Curve classes.

  The 1-bit fillForm to make display and containment tests reasonably fast.  However, this functionality is in the process of being supplanted by balloon capabilities, which should eventually provide anti-aliasing as well.

  wiz 7/18/2004 21:26
  s have made some changes to this class to

  1) correct some bugs associated with one vertex polygons.

  2) prepare for some enhancements with new curves.

  3) add shaping items to menu.!

Item was changed:
  ----- Method: PolygonMorph>>addCustomMenuItems:hand: (in category 'menu') -----
  addCustomMenuItems: aMenu hand: aHandMorph
         "Add morph-specific items to the given menu which was invoked by the given hand.  This method provides is invoked both from the halo-menu and from the control-menu regimes."

         super addCustomMenuItems: aMenu hand: aHandMorph.
         aMenu addUpdating: #handlesShowingPhrase target: self action: #showOrHideHandles.
         vertices size > 2 ifTrue:
                 [aMenu addUpdating: #openOrClosePhrase target: self action: #makeOpenOrClosed].

         aMenu addUpdating: #smoothPhrase target: self action: #toggleSmoothing.
+        aMenu addUpdating: #snapToOtherPolygonPhrase target: self action: #toggleSnapToOtherPolygons.
         aMenu addLine.
         aMenu add: 'specify dashed line' translated action:  #specifyDashedLine.

         self isOpen ifTrue:
                 [aMenu addLine.
                 aMenu addWithLabel: '---' enablement: [self isOpen and: [arrows ~~ #none]] action:  #makeNoArrows.
                 aMenu addWithLabel: '-->' enablement: [self isOpen and: [arrows ~~ #forward]] action:  #makeForwardArrow.
                 aMenu addWithLabel: '<--' enablement: [self isOpen and: [arrows ~~ #back]] action:  #makeBackArrow.
                 aMenu addWithLabel: '<->' enablement: [self isOpen and: [arrows ~~ #both]] action:  #makeBothArrows.
                 aMenu add: 'customize arrows' translated action: #customizeArrows:.
                 (self hasProperty: #arrowSpec)
                         ifTrue: [aMenu add: 'standard arrows' translated action: #standardArrows]].!

Item was changed:
  ----- Method: PolygonMorph>>dropVertex:event:fromHandle: (in category 'editing') -----
+ dropVertex: ix event: evt fromHandle: handle
+        "Leave vertex in new position. If dropped ontop another vertex delete
+        this one.
- dropVertex: ix event: evt fromHandle: handle
-        "Leave vertex in new position. If dropped ontop another vertex delete this one.
         Check for too few vertices before deleting. The alternative
+        is not pretty -wiz"
+        | p nearestOwner distance |
-                                is not pretty -wiz"
-        | p |
         p := vertices at: ix.
+        distance := (3 * RealEstateAgent scaleFactor).
+        "snap the dropped vertex to a vertex of another PolygonMorph if it is in near proximity"
+        self isSnappingToOtherPolygons
+                ifTrue: [nearestOwner := self ownerThatIsA: PasteUpMorph.
+                        nearestOwner submorphs
+                                do: [:each | ((each respondsTo: #vertices)
+                                                        and: [each ~= self])
+                                                ifTrue: [each vertices
+                                                                do: [:otherMorphsVertex | (otherMorphsVertex dist: p)
+                                                                                        <  distance
+                                                                                ifTrue: [vertices at: ix put: otherMorphsVertex]]]]].
         (vertices size >= 2
                         and: ["check for too few vertices before deleting. The alternative
                                 is not pretty -wiz"
                                 ((vertices atWrap: ix - 1)
                                                 dist: p)
+                                                < distance
-                                                < 3
                                         or: [((vertices atWrap: ix + 1)
                                                         dist: p)
+                                                        < distance]])
-                                                        < 3]])
                 ifTrue: ["Drag a vertex onto its neighbor means delete"
+                        self deleteVertexAt: ix].
-                                self deleteVertexAt: ix .].
         evt shiftPressed
                 ifTrue: [self removeHandles]
                 ifFalse: [self addHandles
                         "remove then add to recreate"]!

Item was changed:
  ----- Method: PolygonMorph>>initialize (in category 'initialization') -----
  initialize
  "initialize the state of the receiver"
         super initialize.
  ""
         vertices := Array
                                 with: 5 @ 0
                                 with: 20 @ 10
                                 with: 0 @ 20.
         closed := true.
         smoothCurve := false.
         arrows := #none.
+        snapToOtherPolygons := false.
         self computeBounds!

Item was added:
+ ----- Method: PolygonMorph>>isSnappingToOtherPolygons (in category 'access') -----
+ isSnappingToOtherPolygons
+   ^snapToOtherPolygons ifNil:[ snapToOtherPolygons := false].
+  !

Item was added:
+ ----- Method: PolygonMorph>>snapToOtherPolygonPhrase (in category 'menu') -----
+ snapToOtherPolygonPhrase
+        "Answer a string characterizing whether my vertices should snap to another polygons vertices."
+
+        ^ (self isSnappingToOtherPolygons ifTrue: ['<yes>'] ifFalse: ['<no>']), 'snap to other polygons' translated !

Item was added:
+ ----- Method: PolygonMorph>>toggleSnapToOtherPolygons (in category 'menu') -----
+ toggleSnapToOtherPolygons
+      ^snapToOtherPolygons := snapToOtherPolygons not!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200207/4313fa13/attachment-0001.html>


More information about the Squeak-dev mailing list