Skip to content

Commit

Permalink
Issue #4: initial cut at bringing over the Text class from GLASS (3.7…
Browse files Browse the repository at this point in the history
…) ... successful load of GsDevKit_stones-GLASS package
  • Loading branch information
dalehenrich committed Jul 28, 2023
1 parent 61d6e04 commit 1280518
Show file tree
Hide file tree
Showing 325 changed files with 2,710 additions and 2 deletions.
10 changes: 10 additions & 0 deletions rowan/components/GLASS.ston
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RwSimpleProjectLoadComponentV2 {
#name : 'GLASS',
#condition : 'common',
#projectNames : [ ],
#componentNames : [ ],
#packageNames : [
'GsDevKit_stones-GLASS'
],
#comment : 'GLASS classes needed to support the Text, since Text is (currently) passed back as a result when a remote tODE command is executed ... a feature we want (remote tODE commands)'
}
6 changes: 4 additions & 2 deletions rowan/components/Tode.ston
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ RwSimpleProjectLoadComponentV2 {
#name : 'Tode',
#condition : 'common',
#projectNames : [ ],
#componentNames : [ ],
#componentNames : [
'GLASS'
],
#packageNames : [
'GsDevKit_stones-Tode'
],
#comment : 'Shared classes between GsDevKit_stones and Tode'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am an abstract collection of elements with a fixed range of integers (from 1 to n>=0) as external keys.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
instance creation
new
"Answer a new instance of me, with size = 0."

^self new: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
instance creation
new: size withAll: value
"Answer an instance of me, with number of elements equal to size, each
of which refers to the argument, value."

^(self new: size) atAllPut: value
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
instance creation
newFrom: aCollection
"Answer an instance of me containing the same elements as aCollection."
| newArray |
newArray _ self new: aCollection size.
1 to: aCollection size do: [:i | newArray at: i put: (aCollection at: i)].
^ newArray

" Array newFrom: {1. 2. 3}
{1. 2. 3} as: Array
{1. 2. 3} as: ByteArray
{$c. $h. $r} as: String
{$c. $h. $r} as: Text
"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
instance creation
with: anObject
"Answer a new instance of me, containing only anObject."

| newCollection |
newCollection _ self new: 1.
newCollection at: 1 put: anObject.
^newCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
instance creation
with: firstObject with: secondObject
"Answer a new instance of me, containing firstObject and secondObject."

| newCollection |
newCollection _ self new: 2.
newCollection at: 1 put: firstObject.
newCollection at: 2 put: secondObject.
^newCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
instance creation
with: firstObject with: secondObject with: thirdObject
"Answer a new instance of me, containing only the three arguments as
elements."

| newCollection |
newCollection _ self new: 3.
newCollection at: 1 put: firstObject.
newCollection at: 2 put: secondObject.
newCollection at: 3 put: thirdObject.
^newCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
instance creation
with: firstObject with: secondObject with: thirdObject with: fourthObject
"Answer a new instance of me, containing only the three arguments as
elements."

| newCollection |
newCollection _ self new: 4.
newCollection at: 1 put: firstObject.
newCollection at: 2 put: secondObject.
newCollection at: 3 put: thirdObject.
newCollection at: 4 put: fourthObject.
^newCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
instance creation
with: firstObject with: secondObject with: thirdObject with: fourthObject with: fifthObject
"Answer a new instance of me, containing only the five arguments as
elements."

| newCollection |
newCollection _ self new: 5.
newCollection at: 1 put: firstObject.
newCollection at: 2 put: secondObject.
newCollection at: 3 put: thirdObject.
newCollection at: 4 put: fourthObject.
newCollection at: 5 put: fifthObject.
^newCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
instance creation
with: firstObject with: secondObject with: thirdObject with: fourthObject with: fifthObject with: sixthObject
"Answer a new instance of me, containing only the 6 arguments as elements."

| newCollection |
newCollection _ self new: 6.
newCollection at: 1 put: firstObject.
newCollection at: 2 put: secondObject.
newCollection at: 3 put: thirdObject.
newCollection at: 4 put: fourthObject.
newCollection at: 5 put: fifthObject.
newCollection at: 6 put: sixthObject.
^ newCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
instance creation
withAll: aCollection
"Create a new collection containing all the elements from aCollection."

^ (self new: aCollection size) replaceFrom: 1 to: aCollection size with: aCollection
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
adding
add: newObject
self shouldNotImplement
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sorting
asSortedArray
self isSorted ifTrue: [^ self asArray].
^ super asSortedArray
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
objects from disk
byteSize
^self basicSize * self bytesPerBasicElement
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
objects from disk
bytesPerBasicElement
"Answer the number of bytes that each of my basic elements requires.
In other words:
self basicSize * self bytesPerBasicElement
should equal the space required on disk by my variable sized representation."
^self class isBytes ifTrue: [ 1 ] ifFalse: [ 4 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
objects from disk
bytesPerElement
^self class isBytes ifTrue: [ 1 ] ifFalse: [ 4 ].
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private
defaultElement

^nil
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sorting
isSorted
"Return true if the receiver is sorted by the given criterion.
Optimization for isSortedBy: [:a :b | a <= b]."

| lastElm elm |
self isEmpty ifTrue: [^ true].
lastElm _ self first.
2 to: self size do:
[:index |
elm _ self at: index.
lastElm <= elm ifFalse: [^ false].
lastElm _ elm].
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sorting
isSortedBy: aBlock
"Return true if the receiver is sorted by the given criterion."

| lastElm elm |
self isEmpty ifTrue: [^ true].
lastElm _ self first.
2 to: self size do:
[:index |
elm _ self at: index.
(aBlock value: lastElm value: elm) ifFalse: [^ false].
lastElm _ elm].
^ true
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
private
storeElementsFrom: firstIndex to: lastIndex on: aStream

| noneYet defaultElement arrayElement |
noneYet _ true.
defaultElement _ self defaultElement.
firstIndex to: lastIndex do:
[:index |
arrayElement _ self at: index.
arrayElement = defaultElement
ifFalse:
[noneYet
ifTrue: [noneYet _ false]
ifFalse: [aStream nextPut: $;].
aStream nextPutAll: ' at: '.
aStream store: index.
aStream nextPutAll: ' put: '.
aStream store: arrayElement]].
^noneYet
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
printing
storeOn: aStream

aStream nextPutAll: '(('.
aStream nextPutAll: self class name.
aStream nextPutAll: ' new: '.
aStream store: self size.
aStream nextPut: $).
(self storeElementsFrom: 1 to: self size on: aStream)
ifFalse: [aStream nextPutAll: '; yourself'].
aStream nextPut: $)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"class" : {
"new" : "",
"new:withAll:" : "",
"newFrom:" : "",
"with:" : "",
"with:with:" : "",
"with:with:with:" : "",
"with:with:with:with:" : "",
"with:with:with:with:with:" : "",
"with:with:with:with:with:with:" : "sw 10/24/1998 22:22",
"withAll:" : "sma 5/12/2000 17:37" },
"instance" : {
"add:" : "sma 5/12/2000 14:09",
"asSortedArray" : "sma 5/12/2000 18:18",
"byteSize" : "nk 3/17/2004 15:22",
"bytesPerBasicElement" : "nk 3/17/2004 16:28",
"bytesPerElement" : "nk 3/17/2004 18:51",
"defaultElement" : "",
"isSorted" : "sma 6/1/2000 11:57",
"isSortedBy:" : "sma 6/1/2000 11:58",
"storeElementsFrom:to:on:" : "",
"storeOn:" : "" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "GsDevKit_stones-GLASS",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "<historical>",
"instvars" : [
],
"name" : "ArrayedCollection",
"pools" : [
],
"super" : "SequenceableCollection",
"type" : "normal" }
Empty file.
3 changes: 3 additions & 0 deletions src/GsDevKit_stones-GLASS.package/Color.class/class/black.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
named colors
black
^Black
3 changes: 3 additions & 0 deletions src/GsDevKit_stones-GLASS.package/Color.class/class/blue.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
named colors
blue
^Blue
3 changes: 3 additions & 0 deletions src/GsDevKit_stones-GLASS.package/Color.class/class/brown.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
named colors
brown
^Brown
26 changes: 26 additions & 0 deletions src/GsDevKit_stones-GLASS.package/Color.class/class/colorFrom..st
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
instance creation
colorFrom: parm
"Return an instantiated color from parm. If parm is already a color, return it, else return the result of my performing it if it's a symbol or, if it is a list, it can either be an array of three numbers, which will be interpreted as RGB values, or a list of symbols, the first of which is sent to me and then the others of which are in turn sent to the prior result, thus allowing entries of the form #(blue darker). Else just return the thing"

| aColor firstParm |
(parm isKindOf: Color) ifTrue: [^ parm].
(parm isSymbol) ifTrue: [^ self perform: parm].
(parm isString) ifTrue: [^ self fromString: parm].
((parm isKindOf: SequenceableCollection) and: [parm size > 0])
ifTrue:
[firstParm := parm first.
(firstParm isKindOf: Number) ifTrue:
[^ self fromRgbTriplet: parm].
aColor := self colorFrom: firstParm.
parm doWithIndex:
[:sym :ind | ind > 1 ifTrue:
[aColor := aColor perform: sym]].
^ aColor].
^ parm

"
Color colorFrom: #(blue darker)
Color colorFrom: Color blue darker
Color colorFrom: #blue
Color colorFrom: #(0.0 0.0 1.0)
"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
instance creation
colorFromPixelValue: p depth: d
"Convert a pixel value for the given display depth into a color."
"Details: For depths of 8 or less, the pixel value is simply looked up in a table. For greater depths, the color components are extracted and converted into a color."

| r g b alpha |
d = 8 ifTrue: [^ IndexedColors at: (p bitAnd: 16rFF) + 1].
d = 4 ifTrue: [^ IndexedColors at: (p bitAnd: 16r0F) + 1].
d = 2 ifTrue: [^ IndexedColors at: (p bitAnd: 16r03) + 1].
d = 1 ifTrue: [^ IndexedColors at: (p bitAnd: 16r01) + 1].

(d = 16) | (d = 15) ifTrue: [
"five bits per component"
r _ (p bitShift: -10) bitAnd: 16r1F.
g _ (p bitShift: -5) bitAnd: 16r1F.
b _ p bitAnd: 16r1F.
(r = 0 and: [g = 0]) ifTrue: [
b = 0 ifTrue: [^Color transparent].
b = 1 ifTrue: [^Color black]].
^ Color r: r g: g b: b range: 31].

d = 32 ifTrue: [
"eight bits per component; 8 bits of alpha"
r _ (p bitShift: -16) bitAnd: 16rFF.
g _ (p bitShift: -8) bitAnd: 16rFF.
b _ p bitAnd: 16rFF.
alpha _ p bitShift: -24.
alpha = 0 ifTrue: [^Color transparent].
(r = 0 and: [g = 0 and: [b = 0]]) ifTrue: [^Color transparent].
alpha < 255
ifTrue: [^ (Color r: r g: g b: b range: 255) alpha: (alpha asFloat / 255.0)]
ifFalse: [^ (Color r: r g: g b: b range: 255)]].

d = 12 ifTrue: [
"four bits per component"
r _ (p bitShift: -8) bitAnd: 16rF.
g _ (p bitShift: -4) bitAnd: 16rF.
b _ p bitAnd: 16rF.
^ Color r: r g: g b: b range: 15].

d = 9 ifTrue: [
"three bits per component"
r _ (p bitShift: -6) bitAnd: 16r7.
g _ (p bitShift: -3) bitAnd: 16r7.
b _ p bitAnd: 16r7.
^ Color r: r g: g b: b range: 7].

self error: 'unknown pixel depth: ', d printString
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
other
colorNames
"Return a collection of color names."

^ ColorNames
3 changes: 3 additions & 0 deletions src/GsDevKit_stones-GLASS.package/Color.class/class/cyan.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
named colors
cyan
^Cyan
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
named colors
darkGray
^DarkGray
Loading

0 comments on commit 1280518

Please sign in to comment.