mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-27 03:48:21 +01:00
add basic primitive shapes (contd.)
This commit is contained in:
parent
a2af81994c
commit
8a59d8cba9
50
Diya/Diya2DNode.class.st
Normal file
50
Diya/Diya2DNode.class.st
Normal file
@ -0,0 +1,50 @@
|
||||
Class {
|
||||
#name : #Diya2DNode,
|
||||
#superclass : #DiyaNode,
|
||||
#category : #'Diya-Graphics'
|
||||
}
|
||||
|
||||
{ #category : #accessing }
|
||||
Diya2DNode >> drawOn: context [
|
||||
^self subclassResponsibility
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
Diya2DNode >> initialize [
|
||||
super initialize.
|
||||
translation := 0@0.
|
||||
scale := 0@0.
|
||||
rotation := 0.0.
|
||||
tf := Array2D identity: 3.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
Diya2DNode >> renderOn: context [
|
||||
self updateTF.
|
||||
self drawOn: context.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
Diya2DNode >> updateTF [
|
||||
tf := Array2D identity:3.
|
||||
"translation"
|
||||
tf := tf +* {
|
||||
1. 0. translation x.
|
||||
0. 1. translation y.
|
||||
0. 0. 1
|
||||
}.
|
||||
"scale"
|
||||
tf := tf +* {
|
||||
scale x. 0. 0.
|
||||
0. scale y. 0.
|
||||
0. 0. 1.
|
||||
}.
|
||||
"rotation"
|
||||
tf := tf +* {
|
||||
rotation cos. 0-(rotation sin). 0.
|
||||
rotation sin. rotation cos. 0.
|
||||
0. 0. 1
|
||||
}.
|
||||
self parent = DiyaRootNode uniqueInstance ifTrue: [ ^tf ].
|
||||
tf := self parent tf +* tf
|
||||
]
|
28
Diya/DiyaDefaultShader.class.st
Normal file
28
Diya/DiyaDefaultShader.class.st
Normal file
@ -0,0 +1,28 @@
|
||||
Class {
|
||||
#name : #DiyaDefaultShader,
|
||||
#superclass : #OpenGLSL,
|
||||
#category : #'Diya-Shaders'
|
||||
}
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaDefaultShader class >> fragmentShader [
|
||||
^ '
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
|
||||
}
|
||||
'
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaDefaultShader class >> vertextShader [
|
||||
^ '
|
||||
void main()
|
||||
{
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
'
|
||||
]
|
@ -19,6 +19,11 @@ DiyaFontFamily >> addFace: face [
|
||||
faces at: face styleName ifAbsentPut: face.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontFamily >> face: styleName [
|
||||
^faces at: styleName ifAbsent: [^faces at: 'Regular']
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontFamily >> faces [
|
||||
^ faces
|
||||
|
@ -24,6 +24,21 @@ DiyaFontManager class >> searchPaths [
|
||||
}
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaFontManager >> defaultFamily [
|
||||
^self error: 'No font found'
|
||||
|
||||
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaFontManager >> face: styleName from: familyName [
|
||||
|family|
|
||||
family := families at: familyName ifAbsent: [ self defaultFamily ].
|
||||
^family face: styleName
|
||||
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaFontManager >> families [
|
||||
^ families
|
||||
|
90
Diya/DiyaNode.class.st
Normal file
90
Diya/DiyaNode.class.st
Normal file
@ -0,0 +1,90 @@
|
||||
Class {
|
||||
#name : #DiyaNode,
|
||||
#superclass : #DiyaBaseObject,
|
||||
#instVars : [
|
||||
'translation',
|
||||
'parent',
|
||||
'scale',
|
||||
'rotation',
|
||||
'tf',
|
||||
'shader'
|
||||
],
|
||||
#pools : [
|
||||
'OpenGLConstants',
|
||||
'OpenGLTypes'
|
||||
],
|
||||
#category : #'Diya-Graphics'
|
||||
}
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
DiyaNode class >> with: shader [
|
||||
^self new shader: shader; yourself
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaNode >> initialize [
|
||||
super initialize.
|
||||
parent := nil.
|
||||
shader := DiyaDefaultShader uniqueInstance.
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> parent [
|
||||
^ parent
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> position [
|
||||
^ translation
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> position: anObject [
|
||||
translation := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> renderOn: context [
|
||||
^self subclassResponsibility
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> rotation [
|
||||
^ rotation
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> rotation: anObject [
|
||||
rotation := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> scale [
|
||||
^ scale
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> scale: anObject [
|
||||
scale := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> shader [
|
||||
^ shader
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> shader: anObject [
|
||||
shader := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> tf [
|
||||
parent ifNil: [ self error: 'TF: This node is not attached to the main tree' ].
|
||||
^ tf
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaNode >> updateTF [
|
||||
self subclassResponsibility
|
||||
]
|
30
Diya/DiyaRootNode.class.st
Normal file
30
Diya/DiyaRootNode.class.st
Normal file
@ -0,0 +1,30 @@
|
||||
Class {
|
||||
#name : #DiyaRootNode,
|
||||
#superclass : #DiyaNode,
|
||||
#classVars : [
|
||||
'singleton'
|
||||
],
|
||||
#category : #'Diya-Graphics'
|
||||
}
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
DiyaRootNode class >> new [
|
||||
self error: 'Please use uniqueInstance'
|
||||
]
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
DiyaRootNode class >> reset [
|
||||
singleton := nil
|
||||
]
|
||||
|
||||
{ #category : #'instance creation' }
|
||||
DiyaRootNode class >> uniqueInstance [
|
||||
singleton ifNil: [ singleton := super new].
|
||||
^singleton
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaRootNode >> initialize [
|
||||
super initialize.
|
||||
parent := self.
|
||||
]
|
48
Diya/DiyaText.class.st
Normal file
48
Diya/DiyaText.class.st
Normal file
@ -0,0 +1,48 @@
|
||||
Class {
|
||||
#name : #DiyaText,
|
||||
#superclass : #Diya2DNode,
|
||||
#instVars : [
|
||||
'fontStyle',
|
||||
'fontSize',
|
||||
'data'
|
||||
],
|
||||
#category : #'Diya-Graphics'
|
||||
}
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> data [
|
||||
^ data
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> data: anObject [
|
||||
data := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> fontSize [
|
||||
^ fontSize
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> fontSize: anObject [
|
||||
fontSize := anObject
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> fontStyle [
|
||||
^ fontStyle
|
||||
]
|
||||
|
||||
{ #category : #accessing }
|
||||
DiyaText >> fontStyle: anObject [
|
||||
fontStyle := anObject
|
||||
]
|
||||
|
||||
{ #category : #initialization }
|
||||
DiyaText >> initialize [
|
||||
super initialize.
|
||||
fontStyle := DiyaFontManager uniqueInstance face: 'Regular' from:'Ubuntu'.
|
||||
fontSize := 12.
|
||||
data := nil.
|
||||
]
|
Loading…
Reference in New Issue
Block a user