Skip to content

Commit

Permalink
executionControls
Browse files Browse the repository at this point in the history
  • Loading branch information
Das-Killer committed Jun 22, 2024
1 parent 080f296 commit 6768d25
Show file tree
Hide file tree
Showing 3 changed files with 380 additions and 12 deletions.
41 changes: 39 additions & 2 deletions src/SqueakKara-Core/SKEnvironment.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Class {
'grid',
'workspace',
'executer',
'kara'
'kara',
'executeControls'
],
#category : #'SqueakKara-Core'
}
Expand All @@ -31,6 +32,22 @@ SKEnvironment >> close [

]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 14:11'
}
SKEnvironment >> executeControls [
^ executeControls
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 14:11'
}
SKEnvironment >> executeControls: anObject [
executeControls := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'JJG 6/17/2024 16:40'
Expand All @@ -49,6 +66,15 @@ SKEnvironment >> executer: anObject [
executer := anObject
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 14:16'
}
SKEnvironment >> executerState [

^ self executer state.
]

{
#category : #accessing,
#'squeak_changestamp' : 'KD 6/12/2024 12:16'
Expand Down Expand Up @@ -101,7 +127,7 @@ SKEnvironment >> initializeWithChallenge1 [

{
#category : #initialization,
#'squeak_changestamp' : 'JJG 6/18/2024 18:47'
#'squeak_changestamp' : 'EB 6/22/2024 14:11'
}
SKEnvironment >> initializeWithKaraAt: aPoint [

Expand All @@ -111,6 +137,8 @@ SKEnvironment >> initializeWithKaraAt: aPoint [
self workspace: (SKWorkspace newWithKara: self kara).
self executer: (SKExecuter new).
(self executer kara) kara: self kara.
self executeControls: SKExecuteControls new.
executeControls environment: self.
]

{
Expand Down Expand Up @@ -161,6 +189,15 @@ SKEnvironment >> run [
self executer execute: code
]

{
#category : #commands,
#'squeak_changestamp' : 'EB 6/22/2024 14:30'
}
SKEnvironment >> stop [

self executer terminate.
]

{
#category : #accessing,
#'squeak_changestamp' : 'JJG 6/17/2024 16:41'
Expand Down
287 changes: 287 additions & 0 deletions src/SqueakKara-Core/SKExecuteControls.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
Class {
#name : #SKExecuteControls,
#superclass : #Morph,
#instVars : [
'environment',
'buttonRun',
'sliderSpeed',
'buttonStop'
],
#category : #'SqueakKara-Core'
}

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 15:05'
}
SKExecuteControls >> actionRun [
|dict label texture|
dict := Dictionary new.
dict at: #terminated put:[self environment run. label := 'pause'. texture := self pauseTextureFilename].
dict at: #suspended put:[self environment resume. label := 'pause'. texture := self pauseTextureFilename].
dict at: #running put:[self environment pause. label := 'resume'. texture := self runTextureFilename].
(dict at: self environment executerState) value.
self buttonRun label: label.
self buttonRunSetTexture: texture.
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 15:06'
}
SKExecuteControls >> actionStop [

self environment stop.
self buttonRunSetTexture: self runTextureFilename
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 15:00'
}
SKExecuteControls >> addAllWidgets [

| verticalSpace|

self buttonRun: self buildButtonRun.
self sliderSpeed: self buildSliderSpeed.
self buttonStop: self buildButtonStop.
self buttonRunSetTexture: self runTextureFilename.
self buttonStopSetTexture.
verticalSpace := self addWidgetCentered: self buttonRun atXPosition: self widgetMargin.
verticalSpace := self addWidgetCentered: self sliderSpeed atXPosition: verticalSpace + self widgetMargin.
verticalSpace := self addWidgetCentered: self buttonStop atXPosition: verticalSpace + self widgetMargin.
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 13:59'
}
SKExecuteControls >> addWidgetCentered: aWidget atXPosition: aXValue [

|verticalCenter widgetCenter|

self addMorph: aWidget.
verticalCenter := (self extent y)/2.
widgetCenter := (aWidget extent y)/2.
aWidget position: (aXValue @ (verticalCenter-widgetCenter)).
^ aXValue + aWidget extent x.
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 15:00'
}
SKExecuteControls >> buildButtonRun [

^IconicButton new
label: 'run';
target: self;
actionSelector: #actionRun;
color: Color lightGray.
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 15:00'
}
SKExecuteControls >> buildButtonStop [

^ IconicButton new
label: 'stop';
target: self;
actionSelector: #actionStop;
color: Color lightGray
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 14:41'
}
SKExecuteControls >> buildSliderSpeed [

^ SimpleSliderMorph new
bounds: (0@0 extent: 100@20);
minVal: 0;
maxVal: 50;
setNumericValue: 25;
orientation: #horizontal;
target: self;
actionSelector: #sliderSpeedValueChanged:.
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 13:53'
}
SKExecuteControls >> buttonRun [
^ buttonRun
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 13:53'
}
SKExecuteControls >> buttonRun: anObject [
buttonRun := anObject
]

{
#category : #texture,
#'squeak_changestamp' : 'EB 6/22/2024 14:58'
}
SKExecuteControls >> buttonRunSetTexture: aFilename [

self buttonRun labelGraphic: (self getTexture: aFilename).
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 13:53'
}
SKExecuteControls >> buttonStop [
^ buttonStop
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 13:53'
}
SKExecuteControls >> buttonStop: anObject [
buttonStop := anObject
]

{
#category : #texture,
#'squeak_changestamp' : 'EB 6/22/2024 15:04'
}
SKExecuteControls >> buttonStopSetTexture [

self buttonStop labelGraphic: (self getTexture: self stopTextureFilename).
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 14:06'
}
SKExecuteControls >> defaultBounds [

^0@0 extent: 250@50
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 13:53'
}
SKExecuteControls >> environment [
^ environment
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 13:53'
}
SKExecuteControls >> environment: anObject [
environment := anObject
]

{
#category : #texture,
#'squeak_changestamp' : 'EB 6/22/2024 14:50'
}
SKExecuteControls >> getTexture [

^ SKTextureLoader new getTexture: self textureFilename.
]

{
#category : #texture,
#'squeak_changestamp' : 'EB 6/22/2024 14:57'
}
SKExecuteControls >> getTexture: aFilename [

^ SKTextureLoader new getTexture: aFilename.
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 14:03'
}
SKExecuteControls >> initialize [

super initialize.
self bounds: self defaultBounds.
self color: Color white.
self addAllWidgets.
self openInWorld.
]

{
#category : #texture,
#'squeak_changestamp' : 'EB 6/22/2024 15:02'
}
SKExecuteControls >> pauseTextureFilename [

^'Trunk.png'
]

{
#category : #texture,
#'squeak_changestamp' : 'EB 6/22/2024 14:55'
}
SKExecuteControls >> runTextureFilename [

^'Trunk.png'
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 13:53'
}
SKExecuteControls >> sliderSpeed [
^ sliderSpeed
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 13:53'
}
SKExecuteControls >> sliderSpeed: anObject [
sliderSpeed := anObject
]

{
#category : #widgets,
#'squeak_changestamp' : 'EB 6/22/2024 14:41'
}
SKExecuteControls >> sliderSpeedValueChanged: aValue [

self environment executionSpeed: aValue.
Transcript showln: aValue.
]

{
#category : #texture,
#'squeak_changestamp' : 'EB 6/22/2024 15:02'
}
SKExecuteControls >> stopTextureFilename [

^'Trunk.png'
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 14:47'
}
SKExecuteControls >> textureFilename [

^'Trunk.png'
]

{
#category : #accessing,
#'squeak_changestamp' : 'EB 6/22/2024 14:06'
}
SKExecuteControls >> widgetMargin [
^20
]
Loading

0 comments on commit 6768d25

Please sign in to comment.