Skip to content

Commit

Permalink
clicking near line works, darg for line works, copy does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
simonimmelmann committed Jul 7, 2024
1 parent f69f469 commit f09a78f
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 25 deletions.
39 changes: 39 additions & 0 deletions src/SqueakWhiteboard-Core/WBEdgeOfLine.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ WBEdgeOfLine >> checkArrwoDirection [
ifFalse: [self line switchVisibilityOfArrowHead]
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 17:52'
}
WBEdgeOfLine >> handlesMouseOver: anEvent [

^ true
]

{
#category : #initialization,
#'squeak_changestamp' : 'si 6/20/2024 23:26'
Expand Down Expand Up @@ -139,6 +148,24 @@ WBEdgeOfLine >> makeColorButtons [
yourself
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 17:54'
}
WBEdgeOfLine >> mouseEnter: anEvent [

self line edges do: [:d | d morph color: self line morph borderColor]
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 17:49'
}
WBEdgeOfLine >> mouseLeave: anEvent [

self line edges do: [:d | d morph color: Color transparent]
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 6/14/2024 11:46'
Expand Down Expand Up @@ -174,6 +201,18 @@ WBEdgeOfLine >> setDefaultValues [
supportsText: false
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 17:53'
}
WBEdgeOfLine >> setupEventHandling [
"pass event triggers from the element itself to the methods of the WBElement"

super setupEventHandling.
self morph on: #mouseEnter send: #mouseEnter: to: self.
self morph on: #mouseLeave send: #mouseLeave: to: self
]

{
#category : #geometry,
#'squeak_changestamp' : 'si 6/21/2024 00:24'
Expand Down
4 changes: 2 additions & 2 deletions src/SqueakWhiteboard-Core/WBElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,14 @@ WBElement >> setPopupPosition [

{
#category : #'event handling',
#'squeak_changestamp' : 'is 6/26/2024 22:57'
#'squeak_changestamp' : 'si 7/7/2024 17:51'
}
WBElement >> setupEventHandling [
"pass event triggers from the element itself to the methods of the WBElement"

self morph on: #mouseDown send: #mouseDown: to: self.
self morph on: #mouseUp send: #mouseUp: to: self.
self morph on: #mouseMove send: #mouseMove: to: self
self morph on: #mouseMove send: #mouseMove: to: self.
]

{
Expand Down
93 changes: 70 additions & 23 deletions src/SqueakWhiteboard-Core/WBLine.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,13 @@ Class {
#superclass : #WBPolygonElement,
#instVars : [
'state',
'arrowHead'
'arrowHead',
'hitbox'
],
#category : #'SqueakWhiteboard-Core',
#'squeak_changestamp' : 'is 6/23/2024 02:19'
}

{
#category : #geometry,
#'squeak_changestamp' : 'is 6/18/2024 00:03'
}
WBLine >> angleForEdgeOfLines [
| lengthX lengthY length sin |

lengthX := (self edges at: 2) position x - (self edges at: 1) position x.
lengthY :=(self edges at: 2) position y - (self edges at: 1) position y.
length := (lengthX squared + lengthY squared) safeSquareRoot.
sin := lengthY / length.
^ sin arcSin * (36 / 2 * (3.141592))


]

{
#category : #geometry,
#'squeak_changestamp' : 'is 6/18/2024 00:03'
Expand Down Expand Up @@ -121,6 +106,24 @@ WBLine >> delete [
super delete
]

{
#category : #drag,
#'squeak_changestamp' : 'si 7/7/2024 18:18'
}
WBLine >> dragEnd: anEvent [

self edges do: [:d | d dragEnd: anEvent]
]

{
#category : #drag,
#'squeak_changestamp' : 'si 7/7/2024 18:10'
}
WBLine >> dragStart: anEvent [

self dragOffset: self position - anEvent cursorPoint
]

{
#category : #arrow,
#'squeak_changestamp' : 'si 6/20/2024 23:03'
Expand All @@ -130,9 +133,27 @@ WBLine >> hideArrowHead [
self arrowHead isVisible: false
]

{
#category : #accessing,
#'squeak_changestamp' : 'si 7/5/2024 12:12'
}
WBLine >> hitbox [

^ hitbox
]

{
#category : #accessing,
#'squeak_changestamp' : 'si 7/5/2024 12:13'
}
WBLine >> hitbox: aMorph [

hitbox := aMorph
]

{
#category : #initialization,
#'squeak_changestamp' : 'is 6/23/2024 01:40'
#'squeak_changestamp' : 'si 7/5/2024 12:16'
}
WBLine >> initialize [

Expand All @@ -143,19 +164,40 @@ WBLine >> initialize [

{
#category : #'event handeling',
#'squeak_changestamp' : 'si 6/20/2024 23:00'
#'squeak_changestamp' : 'si 7/7/2024 18:20'
}
WBLine >> mouseDown: anEvent [

self state = 2 ifTrue:
[(self canvas elementToSpawn) isNil ifTrue:
[self canvas
deactivateElement;
deactivateTextbox.
self edges do: [:d | d mouseDown: anEvent].
self dragStart: anEvent.
(self edges at: 1) showPopUp.
self canvas activeElement: (self edges at: 1)]]
]

{
#category : #'event handeling',
#'squeak_changestamp' : 'is 6/18/2024 00:10'
#'squeak_changestamp' : 'si 7/7/2024 18:14'
}
WBLine >> mouseMove: anEvent [

self state = 2 ifTrue:
[super mouseMove: anEvent.
self edges do: [:d | d mouseMove: anEvent]]
]

{
#category : #'event handeling',
#'squeak_changestamp' : 'si 7/7/2024 18:18'
}
WBLine >> mouseUp: anEvent [

(self canvas elementToSpawn) isNil
ifTrue: [self dragOffset: self position - anEvent cursorPoint]
ifTrue: [self dragEnd: anEvent]
ifFalse: [self spawnEdgeOfLineAt: anEvent]
]

Expand All @@ -170,7 +212,7 @@ WBLine >> showArrowHead [

{
#category : #buildLine,
#'squeak_changestamp' : 'si 6/25/2024 13:39'
#'squeak_changestamp' : 'si 7/7/2024 17:34'
}
WBLine >> spawnEdgeOfLineAt: aMouseEvent [

Expand All @@ -196,6 +238,10 @@ WBLine >> spawnEdgeOfLineAt: aMouseEvent [
addElement: (self edges at: 1);
addElement: (self edges at: 2);
dropElement: aMouseEvent.
self hitbox: WBLineHitbox new.
self hitbox goBehind.
self hitbox line: self.
self addMorph: self hitbox.
self updateEdges.
self state: 2]
]
Expand Down Expand Up @@ -256,11 +302,12 @@ WBLine >> updateArrowHead [

{
#category : #buildLine,
#'squeak_changestamp' : 'is 6/18/2024 19:24'
#'squeak_changestamp' : 'si 7/5/2024 12:26'
}
WBLine >> updateEdges [

self setVertices: { (self edges at: 2) center . (self edges at: 1) center }.
self hitbox setVertices: { (self edges at: 2) center . (self edges at: 1) center . (self edges at: 2) center}.
self updateArrowHead

]
136 changes: 136 additions & 0 deletions src/SqueakWhiteboard-Core/WBLineHitbox.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
Class {
#name : #WBLineHitbox,
#superclass : #PolygonMorph,
#instVars : [
'line'
],
#category : #'SqueakWhiteboard-Core'
}

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 15:12'
}
WBLineHitbox >> containsPoint: aPoint [
"Extend the bounds to include the border area"

^ self isClickNearLine: aPoint
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/5/2024 12:23'
}
WBLineHitbox >> handlesMouseDown: anEvent [

^ true
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/5/2024 14:09'
}
WBLineHitbox >> handlesMouseOver: anEvent [

^ true
]

{
#category : #initialization,
#'squeak_changestamp' : 'si 7/7/2024 17:42'
}
WBLineHitbox >> initialize [

super initialize.
self borderWidth: 20.
self borderColor: Color transparent
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 15:11'
}
WBLineHitbox >> isClickNearLine: aPoint [

^ self point: aPoint isNearLineFrom: (self vertices at: 1) to: (self vertices at: 2) within: borderWidth / 2
]

{
#category : #accessing,
#'squeak_changestamp' : 'si 7/7/2024 17:33'
}
WBLineHitbox >> line [

^ line
]

{
#category : #accessing,
#'squeak_changestamp' : 'si 7/7/2024 17:33'
}
WBLineHitbox >> line: anElement [

line := anElement
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 17:35'
}
WBLineHitbox >> mouseDown: anEvent [

self line mouseDown: anEvent
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 17:49'
}
WBLineHitbox >> mouseEnter: anEvent [

self line edges do: [:d | d morph color: self line morph borderColor]
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 17:46'
}
WBLineHitbox >> mouseLeave: anEvent [

self line edges do: [:d | d morph color: Color transparent]
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 18:05'
}
WBLineHitbox >> mouseMove: anEvent [

self line mouseMove: anEvent
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 18:17'
}
WBLineHitbox >> mouseUp: anEvent [

self line mouseUp: anEvent
]

{
#category : #'event handling',
#'squeak_changestamp' : 'si 7/7/2024 15:11'
}
WBLineHitbox >> point: p isNearLineFrom: p1 to: p2 within: distance [
|slope b distanceToP|
"compute slope"
slope := (p2 y - p1 y)/(p2 x - p1 x).

"compute b for line"
b := p1 y - (slope * p1 x).

"compute distance to p"
distanceToP := (((slope negated * p x) + (p y) - b) abs) / (slope * slope + 1) sqrt.
^ distanceToP <= distance.
]

0 comments on commit f09a78f

Please sign in to comment.