Skip to content

Commit

Permalink
Merge pull request #64 from hpi-swa-teaching/feature/35-text-tool
Browse files Browse the repository at this point in the history
Add text tool
  • Loading branch information
ClFeSc authored Jun 2, 2021
2 parents 7801d67 + cbf1da9 commit 278ec04
Show file tree
Hide file tree
Showing 82 changed files with 456 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tool selection
addText
self
isErasing: false;
mode: #text;
currentTool: #addText
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tool selection
chooseFont
self temporaryTextMorph promptForFont
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
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]
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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
defaults
defaultTemporaryTextMorph
^ M2TemporaryTextMorph new
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
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
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
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
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
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
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
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
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
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
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 ]
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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isInEditingTextMode
^ self mode = #editingText
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isInPenMode
^ self mode = #pen
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
isInTextMode
^ self mode = #text
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
drawing
printText
self
commitText;
mode: #text
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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tool selection
switchMode
self commitText
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
temporaryTextMorph: anM2TemporaryTextMorph
temporaryTextMorph := anM2TemporaryTextMorph
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
temporaryTextMorph
^ temporaryTextMorph ifNil: [temporaryTextMorph := self defaultTemporaryTextMorph]
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
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]
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
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
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
Loading

0 comments on commit 278ec04

Please sign in to comment.