-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from hpi-swa-teaching/feature/35-text-tool
Add text tool
- Loading branch information
Showing
82 changed files
with
456 additions
and
87 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
packages/SketchMorph2-Core.package/M2Backend.class/instance/addText.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
tool selection | ||
addText | ||
self | ||
isErasing: false; | ||
mode: #text; | ||
currentTool: #addText |
3 changes: 3 additions & 0 deletions
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/chooseFont.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tool selection | ||
chooseFont | ||
self temporaryTextMorph promptForFont |
5 changes: 3 additions & 2 deletions
5
packages/SketchMorph2-Core.package/M2Backend.class/instance/clearCanvas.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
drawing | ||
tool selection | ||
clearCanvas | ||
self form fillColor: self backgroundColor | ||
self switchMode. | ||
self form fillColor: self backgroundColor |
17 changes: 15 additions & 2 deletions
17
packages/SketchMorph2-Core.package/M2Backend.class/instance/clickAt..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
drawing | ||
clickAt: aPoint | ||
self isInFillMode | ||
ifTrue: [self fillShapeAt: aPoint] | ||
ifFalse: [self startDrawingAt: aPoint] | ||
ifTrue: [ | ||
self fillShapeAt: aPoint. | ||
^ self]. | ||
(self isInPenMode or: [self isInGeometricMode]) | ||
ifTrue: [ | ||
self startDrawingAt: aPoint. | ||
^ self]. | ||
self isInTextMode | ||
ifTrue: [ | ||
self startEditingTextAt: aPoint. | ||
^ self]. | ||
self isInEditingTextMode | ||
ifTrue: [ | ||
self printText. | ||
^ self] |
17 changes: 17 additions & 0 deletions
17
packages/SketchMorph2-Core.package/M2Backend.class/instance/commitText.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
drawing | ||
commitText | ||
| point | | ||
self temporaryTextMorph morphExists ifFalse: [^ self]. | ||
point := self temporaryTextMorph position - (self temporaryTextMorph owner | ||
ifNotNil: [self temporaryTextMorph owner position] | ||
ifNil: [0]). | ||
self temporaryTextMorph selectAt: 0. | ||
self temporaryTextMorph contents ifNotEmpty: [ | ||
self | ||
createTextUserActionWith: self temporaryTextMorph at: point; | ||
projectText: self temporaryTextMorph contents | ||
styled: self temporaryTextMorph textStyle | ||
colored: self temporaryTextMorph textColor | ||
at: point. | ||
]. | ||
self temporaryTextMorph dismissCurrent |
8 changes: 8 additions & 0 deletions
8
packages/SketchMorph2-Core.package/M2Backend.class/instance/createTextUserActionWith.at..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
undo | ||
createTextUserActionWith: aTextMorph at: aPoint | ||
self | ||
currentUserAction: (M2UserAction new backend: self); | ||
saveStateInCurrentUserAction. | ||
self currentUserAction addMethodCall: #projectText:styled:colored:at: | ||
withArguments: {aTextMorph contents . aTextMorph textStyle . aTextMorph textColor . aPoint }. | ||
self finishUserAction |
3 changes: 3 additions & 0 deletions
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/defaultTemporaryTextMorph.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
defaults | ||
defaultTemporaryTextMorph | ||
^ M2TemporaryTextMorph new |
10 changes: 6 additions & 4 deletions
10
packages/SketchMorph2-Core.package/M2Backend.class/instance/drawCircle.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
drawing | ||
tool selection | ||
drawCircle | ||
self isErasing: false. | ||
self currentPen roundNib: self brushSize. | ||
self mode: #pen. | ||
self currentTool: #drawCircle | ||
self | ||
isErasing: false; | ||
mode: #pen; | ||
currentTool: #drawCircle; | ||
switchMode |
10 changes: 6 additions & 4 deletions
10
packages/SketchMorph2-Core.package/M2Backend.class/instance/drawEraser.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
drawing | ||
tool selection | ||
drawEraser | ||
self isErasing: true. | ||
self eraser roundNib: self eraserSize. | ||
self mode: #pen. | ||
self currentTool: #drawEraser | ||
self | ||
isErasing: true; | ||
mode: #pen; | ||
currentTool: #drawEraser; | ||
switchMode |
12 changes: 7 additions & 5 deletions
12
packages/SketchMorph2-Core.package/M2Backend.class/instance/drawGeometricCircle.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
drawing | ||
tool selection | ||
drawGeometricCircle | ||
self isErasing: false. | ||
self mode: #geometric. | ||
self currentGeometricForm: #circle. | ||
self currentTool: #drawGeometricCircle | ||
self | ||
isErasing: false; | ||
mode: #geometric; | ||
currentGeometricForm: #circle; | ||
currentTool: #drawGeometricCircle; | ||
switchMode |
12 changes: 7 additions & 5 deletions
12
packages/SketchMorph2-Core.package/M2Backend.class/instance/drawGeometricRectangle.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
drawing | ||
tool selection | ||
drawGeometricRectangle | ||
self isErasing: false. | ||
self mode: #geometric. | ||
self currentGeometricForm: #rectangle. | ||
self currentTool: #drawGeometricRectangle | ||
self | ||
isErasing: false; | ||
mode: #geometric; | ||
currentGeometricForm: #rectangle; | ||
currentTool: #drawGeometricRectangle; | ||
switchMode |
10 changes: 6 additions & 4 deletions
10
packages/SketchMorph2-Core.package/M2Backend.class/instance/drawPencil.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
drawing | ||
tool selection | ||
drawPencil | ||
self isErasing: false. | ||
self pen roundNib: self pencilSize. | ||
self mode: #pen. | ||
self currentTool: #drawPencil | ||
self | ||
isErasing: false; | ||
mode: #pen; | ||
currentTool: #drawPencil; | ||
switchMode |
10 changes: 6 additions & 4 deletions
10
packages/SketchMorph2-Core.package/M2Backend.class/instance/drawRectangle.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
drawing | ||
tool selection | ||
drawRectangle | ||
self isErasing: false. | ||
self pen sourceForm: | ||
(Form extent: self rectangleBrushSize | ||
offset: (self penNibOffset: self rectangleBrushSize)) fillBlack. | ||
self mode: #pen. | ||
self currentTool: #drawRectangle | ||
self | ||
isErasing: false; | ||
mode: #pen; | ||
currentTool: #drawRectangle; | ||
switchMode |
10 changes: 6 additions & 4 deletions
10
packages/SketchMorph2-Core.package/M2Backend.class/instance/drawTriangle.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
drawing | ||
tool selection | ||
drawTriangle | ||
self isErasing: false. | ||
self pen sourceForm: self prepareTrianglePenSource. | ||
self mode: #pen. | ||
self currentTool: #drawTriangle | ||
self | ||
isErasing: false; | ||
mode: #pen; | ||
currentTool: #drawTriangle; | ||
switchMode |
5 changes: 3 additions & 2 deletions
5
packages/SketchMorph2-Core.package/M2Backend.class/instance/exportAsMorph.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
drawing | ||
tool selection | ||
exportAsMorph | ||
self switchMode. | ||
ImageMorph new | ||
image: self copyForm; | ||
openInHand. | ||
openInHand |
5 changes: 3 additions & 2 deletions
5
packages/SketchMorph2-Core.package/M2Backend.class/instance/exportAsPNG..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
drawing | ||
tool selection | ||
exportAsPNG: aFileName | ||
self form writePNGfileNamed: aFileName | ||
self switchMode. | ||
self form writePNGfileNamed: aFileName |
10 changes: 6 additions & 4 deletions
10
packages/SketchMorph2-Core.package/M2Backend.class/instance/fillShape.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
accessing | ||
tool selection | ||
fillShape | ||
self isErasing: false. | ||
self mode: #fill. | ||
self currentTool: #fillShape | ||
self | ||
isErasing: false; | ||
mode: #fill; | ||
currentTool: #fillShape; | ||
switchMode |
5 changes: 3 additions & 2 deletions
5
packages/SketchMorph2-Core.package/M2Backend.class/instance/finishUserAction.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
undo | ||
finishUserAction | ||
self currentUserAction addMethodCall: #stopDrawing. | ||
(self isInTextMode or: [self isInEditingTextMode]) | ||
ifFalse: [self currentUserAction addMethodCall: #stopDrawing]. | ||
self undoStack isEmpty ifTrue: [ self pushNewUndoLevelWithForm: self copyForm]. | ||
self latestActionQueue size < self defaultMaxActionQueueSize | ||
ifTrue: [ self latestActionQueue add: self currentUserAction ] | ||
ifFalse: [ self pushNewUndoLevelWithForm: self copyForm withAction: self currentUserAction ] | ||
ifFalse: [ self pushNewUndoLevelWithForm: self copyForm withAction: self currentUserAction ] |
8 changes: 5 additions & 3 deletions
8
packages/SketchMorph2-Core.package/M2Backend.class/instance/importPNG..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
drawing | ||
tool selection | ||
importPNG: aFileName | ||
| tempForm | | ||
self switchMode. | ||
tempForm := (Form fromFileNamed: aFileName). | ||
self form setExtent: (tempForm extent) depth: tempForm depth. | ||
self project: tempForm at: 0 asPoint. | ||
self formChanged. | ||
self pushNewUndoLevelWithForm: self copyForm. "add an empty User Action to simulate importPNG being one" | ||
self | ||
formChanged; | ||
pushNewUndoLevelWithForm: self copyForm "add an empty User Action to simulate importPNG being one" |
3 changes: 3 additions & 0 deletions
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/isInEditingTextMode.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
isInEditingTextMode | ||
^ self mode = #editingText |
3 changes: 3 additions & 0 deletions
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/isInPenMode.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
isInPenMode | ||
^ self mode = #pen |
3 changes: 3 additions & 0 deletions
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/isInTextMode.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
isInTextMode | ||
^ self mode = #text |
3 changes: 2 additions & 1 deletion
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/penColor..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
accessing | ||
penColor: aColor | ||
self pen color: aColor. | ||
self currentColor: aColor | ||
self currentColor: aColor. | ||
self temporaryTextMorph textColor: aColor |
5 changes: 5 additions & 0 deletions
5
packages/SketchMorph2-Core.package/M2Backend.class/instance/printText.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
drawing | ||
printText | ||
self | ||
commitText; | ||
mode: #text |
9 changes: 9 additions & 0 deletions
9
...ages/SketchMorph2-Core.package/M2Backend.class/instance/projectText.styled.colored.at..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
drawing | ||
projectText: aString styled: aTextStyle colored: aColor at: aPoint | ||
| textMorph | | ||
textMorph := TextMorph new | ||
contents: aString; | ||
setTextStyle: aTextStyle; | ||
textColor: aColor. | ||
self project: textMorph imageForm at: aPoint. | ||
textMorph delete |
8 changes: 8 additions & 0 deletions
8
packages/SketchMorph2-Core.package/M2Backend.class/instance/startEditingTextAt..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
drawing | ||
startEditingTextAt: aPoint | ||
| point | | ||
point := aPoint + (self temporaryTextMorph canvas | ||
ifNotNil: [self temporaryTextMorph canvas position] | ||
ifNil: [0]). | ||
self temporaryTextMorph moveTo: point. | ||
self mode: #editingText |
3 changes: 3 additions & 0 deletions
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/switchMode.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tool selection | ||
switchMode | ||
self commitText |
3 changes: 3 additions & 0 deletions
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/temporaryTextMorph..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
temporaryTextMorph: anM2TemporaryTextMorph | ||
temporaryTextMorph := anM2TemporaryTextMorph |
3 changes: 3 additions & 0 deletions
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/temporaryTextMorph.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
accessing | ||
temporaryTextMorph | ||
^ temporaryTextMorph ifNil: [temporaryTextMorph := self defaultTemporaryTextMorph] |
4 changes: 2 additions & 2 deletions
4
packages/SketchMorph2-Core.package/M2Backend.class/instance/toggleFillGeometricForm.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
drawing | ||
tool selection | ||
toggleFillGeometricForm | ||
self isFillingGeometricForm: self isFillingGeometricForm not | ||
self isFillingGeometricForm: self isFillingGeometricForm not |
3 changes: 2 additions & 1 deletion
3
packages/SketchMorph2-Core.package/M2Backend.class/instance/undo.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
undo | ||
tool selection | ||
undo | ||
self saveSettingsDuring: [self | ||
switchMode; | ||
removeLastUserAction; | ||
restoreFormFromStack; | ||
restoreUserActions] |
5 changes: 3 additions & 2 deletions
5
packages/SketchMorph2-Core.package/M2Backend.class/instance/userActionClickAt..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
undo | ||
userActionClickAt: aPoint | ||
self createUserActionWithStart: aPoint. | ||
self clickAt: aPoint | ||
(self isInTextMode or: [self isInEditingTextMode]) | ||
ifFalse: [self createUserActionWithStart: aPoint]. | ||
self clickAt: aPoint |
4 changes: 3 additions & 1 deletion
4
packages/SketchMorph2-Core.package/M2Backend.class/instance/userActionMoveDrawing..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
undo | ||
userActionMoveDrawing: aPoint | ||
(self isInTextMode or: [self isInEditingTextMode]) | ||
ifTrue: [^ self]. | ||
self addMovementToUserAction: aPoint. | ||
self moveDrawing: aPoint | ||
self moveDrawing: aPoint |
7 changes: 5 additions & 2 deletions
7
packages/SketchMorph2-Core.package/M2Backend.class/instance/userActionStopDrawing.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
undo | ||
userActionStopDrawing | ||
self finishUserAction. | ||
self stopDrawing | ||
(self isInTextMode or: [self isInEditingTextMode]) | ||
ifTrue: [^ self]. | ||
self | ||
finishUserAction; | ||
stopDrawing |
Oops, something went wrong.