How would I make a drawing method for a block like this: 
Last edited by Billybob-Mario (2010-08-30 10:04:54)
Offline
Not the same as Scratch blocks. Nice design!
Offline
I'll try, but I'm not really sure how.
Edit: I looked, and it doesn't make much sense. To save time, I'll post it here.
drawNumericOn: aCanvas
| right topY bottomY radius xInset c l t cArgs relevant |
self computeHighlightColors.
l _ OrderedCollection new.
right _ self width.
topY _ bottomY _ radius _ self height // 2.
self height even ifTrue: [topY _ bottomY - 1].
[topY >= 0] whileTrue: [
xInset _ radius - (radius squared - (radius - topY - 1) squared) sqrt rounded.
topY = 0 ifTrue: [c _ highlightColor1].
topY = 1 ifTrue: [c _ highlightColor2].
topY > 1 ifTrue: [c _ color].
self addHLineFrom: xInset to: right - xInset y: topY color: c to: l.
(xInset > 0) & (topY > 1) ifTrue: [
self addPoint: xInset@topY color: highlightColor1 to: l.
self addPoint: (right - xInset - 1)@topY color: highlightColor1 to: l].
c _ bottomY = (self height - 1) ifTrue: [shadowColor] ifFalse: [color].
self addHLineFrom: xInset to: right - xInset y: bottomY color: c to: l.
xInset > 0 ifTrue: [
self addPoint: xInset@bottomY color: shadowColor to: l.
self addPoint: (right - xInset - 1)@bottomY color: shadowColor to: l].
bottomY _ bottomY + 1.
topY _ topY - 1].
cArgs _ self nonControlFlowSubmorphs select: [:s |
(s isKindOf: CArgSlotMorph)
or: [(s isKindOf: CReporterSlotMorph)
or: [(s isKindOf: MultiArgMorph)
and: [#(loop reporterSlot) includes: s type]]]].
cArgs isEmpty
ifFalse: [
cArgs do: [:ca |
relevant _ ca bounds.
(ca isKindOf: MultiArgMorph) ifTrue: [
relevant _ ca transparentRect].
t _ OrderedCollection new.
l do: [:pair |
self addAreasOf: pair first outside: (relevant insetBy: 3) color: pair second to: t].
l _ t]].
l do: [:pair |
aCanvas fillRectangle: pair first color: pair second ].Last edited by Billybob-Mario (2010-08-30 10:10:28)
Offline
Billybob-Mario wrote:
I'll try, but I'm not really sure how.
Edit: I looked, and it doesn't make much sense. To save time, I'll post it here.Code:
drawNumericOn: aCanvas | right topY bottomY radius xInset c l t cArgs relevant | self computeHighlightColors. l _ OrderedCollection new. right _ self width. topY _ bottomY _ radius _ self height // 2. self height even ifTrue: [topY _ bottomY - 1]. [topY >= 0] whileTrue: [ xInset _ radius - (radius squared - (radius - topY - 1) squared) sqrt rounded. topY = 0 ifTrue: [c _ highlightColor1]. topY = 1 ifTrue: [c _ highlightColor2]. topY > 1 ifTrue: [c _ color]. self addHLineFrom: xInset to: right - xInset y: topY color: c to: l. (xInset > 0) & (topY > 1) ifTrue: [ self addPoint: xInset@topY color: highlightColor1 to: l. self addPoint: (right - xInset - 1)@topY color: highlightColor1 to: l]. c _ bottomY = (self height - 1) ifTrue: [shadowColor] ifFalse: [color]. self addHLineFrom: xInset to: right - xInset y: bottomY color: c to: l. xInset > 0 ifTrue: [ self addPoint: xInset@bottomY color: shadowColor to: l. self addPoint: (right - xInset - 1)@bottomY color: shadowColor to: l]. bottomY _ bottomY + 1. topY _ topY - 1]. cArgs _ self nonControlFlowSubmorphs select: [:s | (s isKindOf: CArgSlotMorph) or: [(s isKindOf: CReporterSlotMorph) or: [(s isKindOf: MultiArgMorph) and: [#(loop reporterSlot) includes: s type]]]]. cArgs isEmpty ifFalse: [ cArgs do: [:ca | relevant _ ca bounds. (ca isKindOf: MultiArgMorph) ifTrue: [ relevant _ ca transparentRect]. t _ OrderedCollection new. l do: [:pair | self addAreasOf: pair first outside: (relevant insetBy: 3) color: pair second to: t]. l _ t]]. l do: [:pair | aCanvas fillRectangle: pair first color: pair second ].
It's made complicated by cArgs requiring their spaced to be filled.
Offline
nXIII wrote:
nXIII wrote:
It's made complicated by cArgs requiring their spaced to be filled.
Er, rather, emptied...
So can I just get rid of the cArgs parts like this: (to make it simpler)
drawNumericOn: aCanvas
| right topY bottomY radius xInset c l t relevant |
self computeHighlightColors.
l _ OrderedCollection new.
right _ self width.
topY _ bottomY _ radius _ self height // 2.
self height even ifTrue: [topY _ bottomY - 1].
[topY >= 0] whileTrue: [
xInset _ radius - (radius squared - (radius - topY - 1) squared) sqrt rounded.
topY = 0 ifTrue: [c _ highlightColor1].
topY = 1 ifTrue: [c _ highlightColor2].
topY > 1 ifTrue: [c _ color].
self addHLineFrom: xInset to: right - xInset y: topY color: c to: l.
(xInset > 0) & (topY > 1) ifTrue: [
self addPoint: xInset@topY color: highlightColor1 to: l.
self addPoint: (right - xInset - 1)@topY color: highlightColor1 to: l].
c _ bottomY = (self height - 1) ifTrue: [shadowColor] ifFalse: [color].
self addHLineFrom: xInset to: right - xInset y: bottomY color: c to: l.
xInset > 0 ifTrue: [
self addPoint: xInset@bottomY color: shadowColor to: l.
self addPoint: (right - xInset - 1)@bottomY color: shadowColor to: l].
bottomY _ bottomY + 1.
topY _ topY - 1].
l _ t]].
l do: [:pair |
aCanvas fillRectangle: pair first color: pair second ].Last edited by Billybob-Mario (2010-09-01 17:05:38)
Offline
Billybob-Mario wrote:
nXIII wrote:
nXIII wrote:
It's made complicated by cArgs requiring their spaced to be filled.
Er, rather, emptied...
So can I just get rid of the cArgs parts like this: (to make it simpler)
Code:
drawNumericOn: aCanvas | right topY bottomY radius xInset c l t relevant | self computeHighlightColors. l _ OrderedCollection new. right _ self width. topY _ bottomY _ radius _ self height // 2. self height even ifTrue: [topY _ bottomY - 1]. [topY >= 0] whileTrue: [ xInset _ radius - (radius squared - (radius - topY - 1) squared) sqrt rounded. topY = 0 ifTrue: [c _ highlightColor1]. topY = 1 ifTrue: [c _ highlightColor2]. topY > 1 ifTrue: [c _ color]. self addHLineFrom: xInset to: right - xInset y: topY color: c to: l. (xInset > 0) & (topY > 1) ifTrue: [ self addPoint: xInset@topY color: highlightColor1 to: l. self addPoint: (right - xInset - 1)@topY color: highlightColor1 to: l]. c _ bottomY = (self height - 1) ifTrue: [shadowColor] ifFalse: [color]. self addHLineFrom: xInset to: right - xInset y: bottomY color: c to: l. xInset > 0 ifTrue: [ self addPoint: xInset@bottomY color: shadowColor to: l. self addPoint: (right - xInset - 1)@bottomY color: shadowColor to: l]. bottomY _ bottomY + 1. topY _ topY - 1]. l _ t]]. l do: [:pair | aCanvas fillRectangle: pair first color: pair second ].
no....
Offline
I just can't figure out where to start.
Offline
Drawing method:
drawCostumeOn: aCanvas
| right topY bottomY radius xInset c knobbleInset |
self computeHighlightColors.
right _ self width.
topY _ bottomY _ radius _ self height // 2.
knobbleInset _ self height.
self height even ifTrue: [topY _ bottomY - 1].
[topY >= 0] whileTrue: [
xInset _ radius - (radius squared - (radius - topY - 1) squared) sqrt rounded.
topY = 0 ifTrue: [c _ highlightColor1].
topY = 1 ifTrue: [c _ highlightColor2].
topY > 1 ifTrue: [c _ color].
self drawHLineFrom: xInset to: knobbleInset - xInset y: topY color: c on: aCanvas.
self drawHLineFrom: knobbleInset + xInset to: right - knobbleInset - xInset y: topY color: c on: aCanvas.
self drawHLineFrom: right - knobbleInset + xInset to: right - xInset y: topY color: c on: aCanvas.
(xInset > 0) & (topY > 1) ifTrue: [
self drawPoint: xInset@topY color: highlightColor1 on: aCanvas.
self drawPoint: (right - xInset - 1)@topY color: highlightColor1 on: aCanvas].
c _ bottomY = (self height - 1) ifTrue: [shadowColor] ifFalse: [color].
self drawHLineFrom: xInset to: knobbleInset - xInset y: bottomY color: c on: aCanvas.
self drawHLineFrom: knobbleInset + xInset to: right - knobbleInset - xInset y: bottomY color: c on: aCanvas.
self drawHLineFrom: right - knobbleInset + xInset to: right - xInset y: bottomY color: c on: aCanvas.
xInset > 0 ifTrue: [
self drawPoint: xInset@bottomY color: shadowColor on: aCanvas.
self drawPoint: (right - xInset - 1)@bottomY color: shadowColor on: aCanvas].
bottomY _ bottomY + 1.
topY _ topY - 1].fixBlockLayout code:
fixBlockLayout
"Update the positions of my submorphs."
| mList maxH h x y |
blockLayoutNeeded ifFalse: [^ self].
cachedForm _ nil.
cachedFeedbackForm _ nil.
mList _ self nonControlFlowSubmorphs.
maxH _ 0.
mList do: [:m |
(m isKindOf: ArgMorph) ifTrue: [m fixArgLayout].
(m isKindOf: BlockMorph) ifTrue: [m fixBlockLayout].
maxH _ maxH max: m height].
h _ (maxH + 4) max: 17.
x _ 22.
(mList size > 0 and: [mList first isKindOf: StringMorph]) ifTrue: [x _ x + 2].
mList do: [:m |
(m isKindOf: StringMorph) ifTrue: [m color: self labelColor].
y _ (h - m height) // 2.
m position: self position + (x@y).
x _ x + m width + 3].
self extent: (x + 19) @ h.
(self ownerThatIsA: ScratchBlockPaletteMorph) ifNotNil: [
(self ownerThatIsA: ScratchBlockPaletteMorph) fixLayout].You'll need to fix the highlighting/shadowing though. I haven't done that yet.
Last edited by TheSuccessor (2010-09-02 05:36:58)
Offline
TheSuccessor wrote:
Drawing method:
Code:
drawCostumeOn: aCanvas | right topY bottomY radius xInset c knobbleInset | self computeHighlightColors. right _ self width. topY _ bottomY _ radius _ self height // 2. knobbleInset _ self height. self height even ifTrue: [topY _ bottomY - 1]. [topY >= 0] whileTrue: [ xInset _ radius - (radius squared - (radius - topY - 1) squared) sqrt rounded. topY = 0 ifTrue: [c _ highlightColor1]. topY = 1 ifTrue: [c _ highlightColor2]. topY > 1 ifTrue: [c _ color]. self drawHLineFrom: xInset to: knobbleInset - xInset y: topY color: c on: aCanvas. self drawHLineFrom: knobbleInset + xInset to: right - knobbleInset - xInset y: topY color: c on: aCanvas. self drawHLineFrom: right - knobbleInset + xInset to: right - xInset y: topY color: c on: aCanvas. (xInset > 0) & (topY > 1) ifTrue: [ self drawPoint: xInset@topY color: highlightColor1 on: aCanvas. self drawPoint: (right - xInset - 1)@topY color: highlightColor1 on: aCanvas]. c _ bottomY = (self height - 1) ifTrue: [shadowColor] ifFalse: [color]. self drawHLineFrom: xInset to: knobbleInset - xInset y: bottomY color: c on: aCanvas. self drawHLineFrom: knobbleInset + xInset to: right - knobbleInset - xInset y: bottomY color: c on: aCanvas. self drawHLineFrom: right - knobbleInset + xInset to: right - xInset y: bottomY color: c on: aCanvas. xInset > 0 ifTrue: [ self drawPoint: xInset@bottomY color: shadowColor on: aCanvas. self drawPoint: (right - xInset - 1)@bottomY color: shadowColor on: aCanvas]. bottomY _ bottomY + 1. topY _ topY - 1].fixBlockLayout code:
Code:
fixBlockLayout "Update the positions of my submorphs." | mList maxH h x y | blockLayoutNeeded ifFalse: [^ self]. cachedForm _ nil. cachedFeedbackForm _ nil. mList _ self nonControlFlowSubmorphs. maxH _ 0. mList do: [:m | (m isKindOf: ArgMorph) ifTrue: [m fixArgLayout]. (m isKindOf: BlockMorph) ifTrue: [m fixBlockLayout]. maxH _ maxH max: m height]. h _ (maxH + 4) max: 17. x _ 22. (mList size > 0 and: [mList first isKindOf: StringMorph]) ifTrue: [x _ x + 2]. mList do: [:m | (m isKindOf: StringMorph) ifTrue: [m color: self labelColor]. y _ (h - m height) // 2. m position: self position + (x@y). x _ x + m width + 3]. self extent: (x + 19) @ h. (self ownerThatIsA: ScratchBlockPaletteMorph) ifNotNil: [ (self ownerThatIsA: ScratchBlockPaletteMorph) fixLayout].You'll need to fix the highlighting/shadowing though. I haven't done that yet.
That looks good! How can I put the circles a bit closer to the main block?
Offline
In drawOn:...
Change: "knobbleInset _ self height" to: "knobbleInset _ self height - (an amount)"
Change: "self drawHLineFrom: xInset to: knobbleInset - xInset" to: "self drawHLineFrom: xInset to: knobbleInset - xInset + (the same amount)" (both occurences)
Change: "self drawHLineFrom: right - knobbleInset + xInset" to: "self drawHLineFrom: right - knobbleInset + xInset - (the same amount again)" (both occurences)
In fixBlockLayout...
Change: "x _ 22" to: "x _ (whatever 22 - the same amount is)"
Change: "self extent: (x + 17) @ h" to: "self extent: (x + (whatever 17 - the same amount is)) @ h"
Last edited by TheSuccessor (2010-09-03 12:19:17)
Offline
TheSuccessor wrote:
In drawOn:...
Change: "knobbleInset _ self height" to: "knobbleInset _ self height - (an amount)"
Change: "self drawHLineFrom: xInset to: knobbleInset - xInset" to: "self drawHLineFrom: xInset to: knobbleInset - xInset + (the same amount)" (both occurences)
Change: "self drawHLineFrom: right - knobbleInset + xInset" to: "self drawHLineFrom: right - knobbleInset + xInset - (the same amount again)" (both occurences)
In fixBlockLayout...
Change: "x _ 22" to: "x _ (whatever 22 - the same amount is)"
Change: "self extent: (x + 17) @ h" to: "self extent: (x + (whatever 17 - the same amount is)) @ h"
I used 3 and it works. Thanks!
Offline
woa! People actually have methods for drawing morphs? Wow I thought it was just changing a skin or something.
Offline
midnightleopard wrote:
woa! People actually have methods for drawing morphs? Wow I thought it was just changing a skin or something.
I think skin items are slightly too slow because they have to repeat images in ImageFrameMorphs a lot. Multiply that by the number of blocks on the screen and that a lot of images being drawn.
Offline
How should I modify it for the slot?
Offline
I tried making the CoustumeArgMorph's drawing method based on the CostumeBlockMorph's, but it didn't work. How would I make it work? I changed the names of the methods and deleted things that caused small errors, but it still didn't work.
Offline