Skip to content

Commit

Permalink
Merge pull request #62 from hpi-swa-teaching/ui-julian2
Browse files Browse the repository at this point in the history
prettier ui design; should work for all display sizes
  • Loading branch information
jal1604 authored Jun 23, 2024
2 parents 10aeaf0 + 9ff2b00 commit 7ebf126
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 119 deletions.
27 changes: 17 additions & 10 deletions src/ComputationalArt/CAOverlay.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : #CAOverlay,
#superclass : #Morph,
#superclass : #CAOverlayItem,
#instVars : [
'game'
],
Expand All @@ -25,17 +25,24 @@ CAOverlay >> game: aCAGame [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/23/2024 15:32'
#'squeak_changestamp' : 'JAL 6/23/2024 15:27'
}
CAOverlay >> initialize [
| lastHeight menus|
super initialize.
"self color: Color black."
self color: Color transparent.
self extent: 300@600.

self addMorph: [|c| c:= CAOverlayPlayMenu new. c initialize. c ] value.
self addMorph: [|c| c:= CAOverlayBlockMenu new. c initialize. c y: 170. c ] value.
self addMorph: [|c| c:= CAOverlayBrushMenu new. c initialize. c y: 900. c ] value.


menus := OrderedCollection new.
menus add: CAOverlayPlayMenu new.
menus add: CAOverlayBlockMenu new.
menus add: CAOverlayBrushMenu new.

lastHeight := 0.
menus do: [:m |
m y: lastHeight.
m fitChildren; padding: (Rectangle origin: 10@10 corner: 10@30).
lastHeight := lastHeight + m height.
self addMorph: m].
self fitChildren.
self padding: (Rectangle origin: 10@10 corner: 10@10).
self color: Color gray.
]
23 changes: 3 additions & 20 deletions src/ComputationalArt/CAOverlayBlockMenu.class.st
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
Class {
#name : #CAOverlayBlockMenu,
#superclass : #Morph,
#instVars : [
'currentlySelectedBlock'
],
#superclass : #CAOverlayItem,
#category : #ComputationalArt
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/19/2024 16:06'
#'squeak_changestamp' : 'JAL 6/23/2024 15:03'
}
CAOverlayBlockMenu >> initialize [
| blockList |

super initialize.
"self color: Color black."
self color: Color transparent.
self extent: 300@300.

self addMorph: [|s| s := (CAOverlayItem new) initialize. s contents: 'BlockMenu'. s] value.
self addMorph: [|s| s := (CAOverlayListItem new) initialize. s contents: 'BlockMenu'. s] value.

blockList := CAOverlayList new fromListOfStrings:
#('Water' 'Sand' 'Stone' 'Air' 'TNT' 'Wood' 'Algae' 'Fire' 'Fish' 'Smoke').
Expand All @@ -41,16 +35,5 @@ CAOverlayBlockMenu >> initialize [
self addMorph: blockList.
blockList y: 70.

"blockTypes withIndexDo: [:type :i | |item|
Transcript show: type.
item := CAOverlayItem new.
item initialize; contents: type;
onclick: [:evt |
currentlySelectedBlock:= type.
self submorphsDo: [:t| t color: Color white].
item color: Color green.].
item y: (i * 70); x: 150.
self addMorph: item ]."


]
12 changes: 3 additions & 9 deletions src/ComputationalArt/CAOverlayBrushMenu.class.st
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
Class {
#name : #CAOverlayBrushMenu,
#superclass : #Morph,
#instVars : [
'currentlySelectedBlock'
],
#superclass : #CAOverlayItem,
#category : #ComputationalArt
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'Sars 6/19/2024 16:31'
#'squeak_changestamp' : 'JAL 6/23/2024 15:03'
}
CAOverlayBrushMenu >> initialize [
| brushList |

super initialize.
"self color: Color black."
self color: Color transparent.
self extent: 300@500.

self addMorph: [|s| s := (CAOverlayItem new) initialize. s contents: 'Brush Size'. s] value.
self addMorph: [|s| s := (CAOverlayListItem new) initialize. s contents: 'Brush Size'. s] value.

brushList := CAOverlayList new fromListOfStrings: #('1x1' '3x3' '5x5' '9x9' '15x15').
brushList horizontalWithMargin: 10.
Expand Down
80 changes: 19 additions & 61 deletions src/ComputationalArt/CAOverlayItem.class.st
Original file line number Diff line number Diff line change
@@ -1,85 +1,43 @@
Class {
#name : #CAOverlayItem,
#superclass : #Morph,
#instVars : [
'onclickhandler',
'stringmorph'
],
#category : #ComputationalArt
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/18/2024 12:08'
#'squeak_changestamp' : 'JAL 6/23/2024 15:00'
}
CAOverlayItem >> contents [
^stringmorph contents
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 16:06'
}
CAOverlayItem >> contents: aString [
stringmorph contents: aString.
self extent: (stringmorph extent).
CAOverlayItem >> fitChildren [
|originX originY cornerX cornerY|
originX := 10000. originY := 10000. cornerX := 0. cornerY:= 0.
self submorphsDo: [:s | s bounds corner x < originX
ifTrue: [originX := s bounds origin x]].
self submorphsDo: [:s | s bounds corner y < originY
ifTrue: [originY := (s bounds origin y)]].
self submorphsDo: [:s | s bounds corner x > cornerX
ifTrue: [cornerX := s bounds corner x]].
self submorphsDo: [:s | s bounds corner y > cornerY
ifTrue: [cornerY := (s bounds corner y)]].

self bounds: (Rectangle origin: originX@originY corner: cornerX@cornerY).
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 15:11'
}
CAOverlayItem >> handlesMouseDown: evt [
^true
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 16:06'
#'squeak_changestamp' : 'JAL 6/23/2024 14:13'
}
CAOverlayItem >> initialize [
super initialize.
stringmorph := StringMorph new.
self color: Color white.
self addMorph: stringmorph.
self extent: (stringmorph extent).
^self.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/18/2024 12:21'
}
CAOverlayItem >> mouseDown: evt [
Transcript show: evt.
Transcript show: onclickhandler.
onclickhandler ifNotNil: [onclickhandler value: evt].
self color: Color transparent.

]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 15:12'
#'squeak_changestamp' : 'JAL 6/23/2024 15:17'
}
CAOverlayItem >> mouseUp: evt [
Transcript show: evt.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 15:24'
}
CAOverlayItem >> onclick: aBlock [
onclickhandler := aBlock.

]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 15:27'
}
CAOverlayItem >> onclickhandler [
^onclickhandler

CAOverlayItem >> padding: aRectangle [
self extent: (self extent + aRectangle origin + aRectangle corner).
self submorphsDo: [:s | s position: (s position + aRectangle origin)]
]
18 changes: 9 additions & 9 deletions src/ComputationalArt/CAOverlayList.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : #CAOverlayList,
#superclass : #Morph,
#superclass : #CAOverlayItem,
#instVars : [
'onClickHandler'
],
Expand All @@ -9,11 +9,11 @@ Class {

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/18/2024 15:28'
#'squeak_changestamp' : 'JAL 6/23/2024 15:03'
}
CAOverlayList >> fromListOfStrings: aListOfStrings [
aListOfStrings reverse withIndexDo: [:type :i | |item|
item := CAOverlayItem new.
item := CAOverlayListItem new.
item initialize; contents: type;
onclick: [:evt | self onItemClick: item].
self addMorph: item ].
Expand All @@ -30,22 +30,21 @@ CAOverlayList >> horizontal [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/18/2024 11:55'
#'squeak_changestamp' : 'JAL 6/23/2024 15:02'
}
CAOverlayList >> horizontalWithMargin: aMargin [
| left |
left := 0.
self submorphsDo: [ :s| s x: left + (s width / 2). left := left + s width + aMargin].
self width: (left - aMargin).
self fitChildren.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/18/2024 12:00'
#'squeak_changestamp' : 'JAL 6/23/2024 15:01'
}
CAOverlayList >> initialize [
super initialize.
"self color: Color black."
self color: Color transparent.


Expand Down Expand Up @@ -77,11 +76,12 @@ CAOverlayList >> vertical [

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/18/2024 11:56'
#'squeak_changestamp' : 'JAL 6/23/2024 15:01'
}
CAOverlayList >> verticalWithMargin: aMargin [
| top |
top := 0.
self submorphsDo: [ :s| s y: top. top := top + s height + aMargin].
self height: (top - aMargin).
"self height: (top - aMargin)."
self fitChildren.
]
85 changes: 85 additions & 0 deletions src/ComputationalArt/CAOverlayListItem.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
Class {
#name : #CAOverlayListItem,
#superclass : #Morph,
#instVars : [
'onclickhandler',
'stringmorph'
],
#category : #ComputationalArt
}

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/18/2024 12:08'
}
CAOverlayListItem >> contents [
^stringmorph contents
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 16:06'
}
CAOverlayListItem >> contents: aString [
stringmorph contents: aString.
self extent: (stringmorph extent).

]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 15:11'
}
CAOverlayListItem >> handlesMouseDown: evt [
^true
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 16:06'
}
CAOverlayListItem >> initialize [
super initialize.
stringmorph := StringMorph new.
self color: Color white.
self addMorph: stringmorph.
self extent: (stringmorph extent).
^self.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/18/2024 12:21'
}
CAOverlayListItem >> mouseDown: evt [
Transcript show: evt.
Transcript show: onclickhandler.
onclickhandler ifNotNil: [onclickhandler value: evt].

]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 15:12'
}
CAOverlayListItem >> mouseUp: evt [
Transcript show: evt.
]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 15:24'
}
CAOverlayListItem >> onclick: aBlock [
onclickhandler := aBlock.

]

{
#category : #'as yet unclassified',
#'squeak_changestamp' : 'JAL 6/5/2024 15:27'
}
CAOverlayListItem >> onclickhandler [
^onclickhandler

]
Loading

0 comments on commit 7ebf126

Please sign in to comment.