From ac764da0761bf86f26b98b1a76db0b3a366be9c1 Mon Sep 17 00:00:00 2001 From: Dany LE Date: Sat, 19 Mar 2022 02:18:29 +0100 Subject: [PATCH] WIP: add support for input events --- Diya/Array2D.extension.st | 27 +++++++++ Diya/Diya2DNode.class.st | 49 +++++++++------- Diya/Diya2DPrimShape.class.st | 29 ++++++++-- Diya/DiyaBoot.class.st | 79 ++++++++++++++++---------- Diya/DiyaCoreAPIError.class.st | 5 ++ Diya/DiyaEllipse.class.st | 7 +++ Diya/DiyaError.class.st | 5 ++ Diya/DiyaEvent.class.st | 40 +++++++++++++ Diya/DiyaFFIBase.class.st | 2 +- Diya/DiyaFontManager.class.st | 4 +- Diya/DiyaLine.class.st | 5 ++ Diya/DiyaNode.class.st | 51 +++++++++++++++-- Diya/DiyaRootNode.class.st | 22 ++++++- Diya/DiyaSingleton.class.st | 2 +- Diya/DiyaText.class.st | 36 +++++------- Diya/OpenGLSL.class.st | 4 +- Diya/Point.extension.st | 15 +++++ Diya/Rectangle.extension.st | 8 +++ Diya/SDL2MappedEvent.extension.st | 6 ++ Diya/SDL_MouseButtonEvent.extension.st | 11 ++++ Diya/SDL_MouseMotionEvent.extension.st | 12 ++++ Diya/SDL_TouchFingerEvent.extension.st | 11 ++++ 22 files changed, 340 insertions(+), 90 deletions(-) create mode 100644 Diya/DiyaCoreAPIError.class.st create mode 100644 Diya/DiyaError.class.st create mode 100644 Diya/DiyaEvent.class.st create mode 100644 Diya/Rectangle.extension.st create mode 100644 Diya/SDL2MappedEvent.extension.st create mode 100644 Diya/SDL_MouseButtonEvent.extension.st create mode 100644 Diya/SDL_MouseMotionEvent.extension.st create mode 100644 Diya/SDL_TouchFingerEvent.extension.st diff --git a/Diya/Array2D.extension.st b/Diya/Array2D.extension.st index d86f27e..3459e56 100644 --- a/Diya/Array2D.extension.st +++ b/Diya/Array2D.extension.st @@ -12,3 +12,30 @@ Array2D >> asGLBuffer [ buffer autoRelease. ^buffer ] + +{ #category : #'*Diya' } +Array2D class >> rotationMatrix2D: rotation [ + ^Array2D rows: 3 columns: 3 contents:{ + rotation cos. (rotation sin) negated. 0.0. + rotation sin. rotation cos. 0.0. + 0.0. 0.0. 1.0 + } +] + +{ #category : #'*Diya' } +Array2D class >> scaleMatrix2D: scale [ + ^Array2D rows: 3 columns: 3 contents:{ + scale x. 0.0. 0.0. + 0.0. scale y. 0.0. + 0.0. 0.0. 1.0 + } +] + +{ #category : #'*Diya' } +Array2D class >> translateMatrix2D: translation [ + ^Array2D rows: 3 columns: 3 contents: { + 1.0. 0.0. translation x. + 0.0. 1.0. translation y. + 0.0. 0.0. 1.0 + } +] diff --git a/Diya/Diya2DNode.class.st b/Diya/Diya2DNode.class.st index b8aeddb..7559ddc 100644 --- a/Diya/Diya2DNode.class.st +++ b/Diya/Diya2DNode.class.st @@ -3,15 +3,21 @@ Class { #superclass : #DiyaNode, #instVars : [ 'color', - 'vbuffer', - 'bbox' + 'vbuffer' ], #category : #'Diya-Graphics' } { #category : #accessing } Diya2DNode >> boundingBox [ - ^ bbox + |rec| + children ifNil: [ ^ Rectangle origin: 0@0 corner: 0@0 ]. + rec := children first boundingBox. + children do:[:c| + rec = c ifFalse:[ + rec := rec merge: c boundingBox] + ]. + ^rec ] { #category : #accessing } @@ -24,9 +30,14 @@ Diya2DNode >> color: anObject [ color := anObject ] +{ #category : #accessing } +Diya2DNode >> draw [ + +] + { #category : #accessing } Diya2DNode >> extent [ - ^ bbox extent + ^ self boundingBox extent ] { #category : #accessing } @@ -46,6 +57,18 @@ Diya2DNode >> initialize [ vbuffer := nil. ] +{ #category : #'as yet unclassified' } +Diya2DNode >> inner: aPoint [ + ^ self boundingBox containsPoint: (self local: aPoint) +] + +{ #category : #accessing } +Diya2DNode >> local: aPoint [ + ^((aPoint - (0@0 applyTf: self tf) )/ scale) + rotateBy: rotation about: 0@0. + +] + { #category : #'as yet unclassified' } Diya2DNode >> recFromBuffer [ |maxX maxY minX minY x y| @@ -72,23 +95,11 @@ Diya2DNode >> setUpShader [ Diya2DNode >> updateTF [ tf := Array2D identity:3. "translation" - tf := tf +* (Array2D rows: 3 columns: 3 contents: { - 1.0. 0.0. translation x. - 0.0. 1.0. translation y. - 0.0. 0.0. 1.0 - }). + tf := tf +* (Array2D translateMatrix2D: translation). "rotation" - tf := tf +* (Array2D rows: 3 columns: 3 contents:{ - rotation cos. (rotation sin) negated. 0.0. - rotation sin. rotation cos. 0.0. - 0.0. 0.0. 1.0 - }). + tf := tf +* (Array2D rotationMatrix2D: rotation ). "scale" - tf := tf +* (Array2D rows: 3 columns: 3 contents:{ - scale x. 0.0. 0.0. - 0.0. scale y. 0.0. - 0.0. 0.0. 1.0 - }). + tf := tf +* (Array2D scaleMatrix2D: scale). self parent isRoot ifFalse: [ tf := self parent tf +* tf ]. children ifNotNil: [ children do:[:c| c updateTF ]]. diff --git a/Diya/Diya2DPrimShape.class.st b/Diya/Diya2DPrimShape.class.st index 4578c8c..f71cc5b 100644 --- a/Diya/Diya2DPrimShape.class.st +++ b/Diya/Diya2DPrimShape.class.st @@ -5,7 +5,8 @@ Class { 'texture', 'type', 'border', - 'bcolor' + 'bcolor', + 'bbox' ], #category : #'Diya-Graphics' } @@ -20,6 +21,11 @@ Diya2DPrimShape >> borderWidth: w [ border := w ] +{ #category : #accessing } +Diya2DPrimShape >> boundingBox [ + ^ bbox applyTf: self tf. +] + { #category : #initialization } Diya2DPrimShape >> draw [ vbuffer ifNil: [ ^self ]. @@ -62,6 +68,11 @@ Diya2DPrimShape >> drawLines [ self subclassResponsibility ] +{ #category : #accessing } +Diya2DPrimShape >> extent [ + ^ bbox extent +] + { #category : #initialization } Diya2DPrimShape >> initialize [ super initialize. @@ -70,15 +81,21 @@ Diya2DPrimShape >> initialize [ type := GL_TRIANGLES. border := 0. bcolor := Color white. + bbox := Rectangle origin: 0@0 corner: 0@0. +] + +{ #category : #'as yet unclassified' } +Diya2DPrimShape >> inner: aPoint [ + bbox ifNil: [ ^false ]. + ^ bbox containsPoint: (self local: aPoint) ] { #category : #initialization } Diya2DPrimShape >> setUpShader [ - super setUpShader - texture ifNotNil:[ - self shader - setUniform: #u_texture_type value: texture format. - ]. + super setUpShader. + self shader + setUniform: #u_texture_type value: + (self texture ifNil: [ 0 ] ifNotNil:[self texture format]). ] { #category : #accessing } diff --git a/Diya/DiyaBoot.class.st b/Diya/DiyaBoot.class.st index 7a618e6..9106980 100644 --- a/Diya/DiyaBoot.class.st +++ b/Diya/DiyaBoot.class.st @@ -38,10 +38,27 @@ DiyaBoot >> GLinit. [ OpenGL enable: GL_TEXTURE_2D. ] +{ #category : #events } +DiyaBoot >> bindGlobalEventTo: aNode [ + |pointer| + pointer := aNode addNode: (DiyaCircle r: 10) at: 200@200. + pointer color: Color orange. + "pointer borderColor: Color red. + pointer borderWidth: 3." + aNode on: #keydown do:[:e| Transcript show: 'keydown...';cr. running := false.]. + aNode on: #quit do: [:e| running := false]. + aNode on: #fingerdown do:[:e| self setCursorPosition: e mapped ]. + aNode on: #fingermotion do:[:e| self setCursorPosition: e mapped ]. + aNode on: #mousemotion do:[:e| + pointer position: e mapped worldPosition. + DiyaRendererContext uniqueInstance mouse: (e mapped x) @ (e mapped y). + ]. +] + { #category : #events } DiyaBoot >> createGLContext [ context := SDL2 glCreateContext: window. - context ifNil: [ ^self error: SDL2 getErrorMessage ]. + context ifNil: [ ^DiyaCoreAPIError signal: SDL2 getErrorMessage ]. ^context ] @@ -60,7 +77,7 @@ DiyaBoot >> createWindow [ width: display w height: display h flags: SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL. - window ifNil: [ ^self error: SDL2 getErrorMessage ]. + window ifNil: [ ^DiyaCoreAPIError signal: SDL2 getErrorMessage ]. "handle fullscreen: SDL_WINDOW_FULLSCREEN." "SDL2 glSetAttribute: SDL_GL_CONTEXT_PROFILE_MASK value: SDL_GL_CONTEXT_PROFILE_ES. SDL2 glSetAttribute: SDL_GL_CONTEXT_MAJOR_VERSION value: 2. @@ -73,10 +90,20 @@ DiyaBoot >> createWindow [ ] { #category : #events } -DiyaBoot >> exampleNodes [ - |root node tex| - root := DiyaRootNode new. +DiyaBoot >> exampleNodes: tree [ + |root node node1 ell tex txtNode| + root := tree addNode: (Diya2DNode new) at: 0@10. tex := (DiyaImageTex fromFile:Smalltalk imageDirectory / 'assets'/'mrsang.png'). + txtNode := root addNode: (DiyaText data: 'Event') at: 10@50. + txtNode color: Color orange. + txtNode extent: 200@40. + + node1 := root addNode: (DiyaRectangle size:100@150 shader: DiyaExampleShader uniqueInstance) at: 100 @ 400. + node1 rotation: (Float pi / 8.0). + node1 scale: 1.2@1.2. + node1 on: #mousebuttondown do:[:e| txtNode data: 'Mouse ', (node1 local: e mapped worldPosition) asIntegerPoint asString]. + node1 on: #fingerdown do:[:e| Transcript show:'finger down on image'; cr]. + node := root addNode: (DiyaRectangle size: 200@200) at: 250 @ 430. node texture: tex. node color: (Color r: 1.0 g:1.0 b:1.0 alpha:1.0 ). @@ -92,11 +119,8 @@ DiyaBoot >> exampleNodes [ node borderColor: Color red. node borderWidth: 3.0." - node := root addNode: (DiyaRectangle size:100@150 shader: DiyaExampleShader uniqueInstance) at: 20 @ 400. - node rotation: (Float pi / -8.0). - node scale: 1.5@1.5. - node := root addNode: (DiyaText data: String loremIpsum) at: 10@340. + node := root addNode: (DiyaText data: String loremIpsum) at: 10@400. node extent: 250@320. node wordWrap: true. @@ -105,11 +129,15 @@ DiyaBoot >> exampleNodes [ node borderWidth: 2.0. - node := root addNode: (DiyaCircle r: 100) at: 320@300. - node borderColor: Color red. - node color: Color white. - node borderWidth: 3.0. - node texture: tex. + ell := root addNode: (DiyaEllipse rx:150 ry: 100) at: 320@300. + ell borderColor: Color red. + ell color: Color white. + ell rotation: Float pi / 6.0. + ell borderWidth: 3.0. + "node rotation: Float pi / 2.0." + ell texture: tex. + ell on: #mousebuttondown do:[:e| txtNode data: 'Ellipse clicked', (ell local:e mapped worldPosition) asIntegerPoint asString]. + ell on: #fingerdown do:[:e| Transcript show:'finger down on ellipse'; cr]. node := root addNode: (DiyaConvexPolygon points:{250@100. 400@250. 450@80. 350@60}). @@ -117,6 +145,7 @@ DiyaBoot >> exampleNodes [ node borderColor: Color red. node texture: tex. node borderWidth: 3.0. + ^ root ] @@ -126,7 +155,7 @@ DiyaBoot >> init [ SDL2 setHint: 'SDL_RENDER_DRIVER' value: 'opengles2'. status := SDL2 init: SDL_INIT_EVERYTHING. status = 0 - ifFalse: [ ^ self error: SDL2 getErrorMessage ]. + ifFalse: [ ^ DiyaCoreAPIError signal: SDL2 getErrorMessage ]. display := SDL_DisplayMode externalNew autoRelease. SDL2 SDLGetCurrentDisplayMode: display from:0. DiyaRendererContext reset. @@ -144,18 +173,6 @@ DiyaBoot >> initialize [ clock := DiyaClock uniqueInstance. ] -{ #category : #events } -DiyaBoot >> processEvent: event [ - |mappedEvt| - mappedEvt := event mapped. - mappedEvt type = SDL_KEYDOWN ifTrue: [ Transcript show: 'keydown...';cr. ^running := false. ]. - mappedEvt type = SDL_QUIT ifTrue:[ ^running:= false ]. - mappedEvt type = SDL_FINGERDOWN ifTrue:[^self setCursorPosition: mappedEvt ]. - mappedEvt type = SDL_FINGERMOTION ifTrue:[^self setCursorPosition: mappedEvt ]. - mappedEvt type = SDL_MOUSEMOTION ifTrue:[DiyaRendererContext uniqueInstance mouse: (mappedEvt x) @ (mappedEvt y)]. - mappedEvt free. -] - { #category : #events } DiyaBoot >> randomColorChannel [ | rand | @@ -169,12 +186,14 @@ DiyaBoot >> randomColorChannel [ DiyaBoot >> render [ |event root text delta fps| event := SDL_Event new. - root := self exampleNodes. + root := DiyaRootNode new. + self exampleNodes: root. DiyaRenderer uniqueInstance root: root. text := root addNode:(DiyaText data: 'tick') at: (display w - 80)@40. text extent: 80@40. text fontSize: 18. text color: Color red. + self bindGlobalEventTo: root. DiyaRendererContext uniqueInstance. self GLinit. [ running ] whileTrue: [ @@ -183,7 +202,7 @@ DiyaBoot >> render [ text data: ('FPS:', fps asString). DiyaClock uniqueInstance tick. [(SDL2 pollEvent: event) > 0] whileTrue: [ - self processEvent: event + root trigger: (DiyaEvent from: event mapped). ]. DiyaRenderer uniqueInstance render. @@ -264,7 +283,7 @@ DiyaBoot >> showSystemInfo [ { #category : #events } DiyaBoot >> startx [ - display ifNil: [ ^self error: 'Please run #init before this method' ]. + display ifNil: [ ^DiyaCoreAPIError signal: 'Please run #init before this method' ]. self createWindow. self createGLContext. "SDL2 glMakeCurrent: window context: context." diff --git a/Diya/DiyaCoreAPIError.class.st b/Diya/DiyaCoreAPIError.class.st new file mode 100644 index 0000000..92d2935 --- /dev/null +++ b/Diya/DiyaCoreAPIError.class.st @@ -0,0 +1,5 @@ +Class { + #name : #DiyaCoreAPIError, + #superclass : #DiyaError, + #category : #'Diya-Events' +} diff --git a/Diya/DiyaEllipse.class.st b/Diya/DiyaEllipse.class.st index 790f00b..0607191 100644 --- a/Diya/DiyaEllipse.class.st +++ b/Diya/DiyaEllipse.class.st @@ -47,6 +47,13 @@ DiyaEllipse >> initialize [ shader := DiyaEllipseShader uniqueInstance. ] +{ #category : #initialization } +DiyaEllipse >> inner: aPoint [ + |dxy| + dxy := self local: aPoint. + ^ ((((dxy x) ** 2)/(rx**2)) + (((dxy y) ** 2) / (ry**2))) < 1. +] + { #category : #accessing } DiyaEllipse >> rx [ ^ rx diff --git a/Diya/DiyaError.class.st b/Diya/DiyaError.class.st new file mode 100644 index 0000000..73c7349 --- /dev/null +++ b/Diya/DiyaError.class.st @@ -0,0 +1,5 @@ +Class { + #name : #DiyaError, + #superclass : #Error, + #category : #'Diya-Events' +} diff --git a/Diya/DiyaEvent.class.st b/Diya/DiyaEvent.class.st new file mode 100644 index 0000000..d84810a --- /dev/null +++ b/Diya/DiyaEvent.class.st @@ -0,0 +1,40 @@ +Class { + #name : #DiyaEvent, + #superclass : #DiyaBaseObject, + #instVars : [ + 'enable', + 'mapped' + ], + #category : #'Diya-Events' +} + +{ #category : #'instance creation' } +DiyaEvent class >> from: mappedEvt [ + ^ self new mapped: mappedEvt; yourself +] + +{ #category : #accessing } +DiyaEvent >> enable [ + ^ enable +] + +{ #category : #initialization } +DiyaEvent >> initialize [ + super initialize. + enable := true. +] + +{ #category : #accessing } +DiyaEvent >> mapped [ + ^ mapped +] + +{ #category : #accessing } +DiyaEvent >> mapped: anObject [ + mapped := anObject +] + +{ #category : #initialization } +DiyaEvent >> preventDefault [ + enable := false +] diff --git a/Diya/DiyaFFIBase.class.st b/Diya/DiyaFFIBase.class.st index a1b5508..16042dc 100644 --- a/Diya/DiyaFFIBase.class.st +++ b/Diya/DiyaFFIBase.class.st @@ -26,7 +26,7 @@ DiyaFFIBase class >> moduleName [ ^ aName ]. ]. - self error: 'Unable to find FFI library (', self checkSymbol, ')'. + DiyaCoreAPIError signal: 'Unable to find FFI library (', self checkSymbol, ')'. ] { #category : #'library path' } diff --git a/Diya/DiyaFontManager.class.st b/Diya/DiyaFontManager.class.st index 19fc70b..36ee81a 100644 --- a/Diya/DiyaFontManager.class.st +++ b/Diya/DiyaFontManager.class.st @@ -22,7 +22,7 @@ DiyaFontManager class >> searchPaths [ { #category : #initialization } DiyaFontManager >> defaultFamily [ - ^self error: 'No font found' + ^'Ubuntu' ] @@ -66,7 +66,7 @@ DiyaFontManager >> loadFile: aFile [ numfaces ifNil: [ numfaces := face numFaces ]. self loadFace: face. i := i + 1. - i < numfaces ] whileTrue: [ ] + i < numfaces ] whileTrue ] { #category : #initialization } diff --git a/Diya/DiyaLine.class.st b/Diya/DiyaLine.class.st index 8c2cd65..2591fc8 100644 --- a/Diya/DiyaLine.class.st +++ b/Diya/DiyaLine.class.st @@ -76,6 +76,11 @@ DiyaLine >> initialize [ border := 1.0 ] +{ #category : #'as yet unclassified' } +DiyaLine >> inner: aPoint [ + ^false +] + { #category : #accessing } DiyaLine >> to [ ^ to diff --git a/Diya/DiyaNode.class.st b/Diya/DiyaNode.class.st index 508169a..b83b0a7 100644 --- a/Diya/DiyaNode.class.st +++ b/Diya/DiyaNode.class.st @@ -10,11 +10,14 @@ Class { 'tf', 'shader', 'context', - 'dirty' + 'dirty', + 'ehandlers', + 'root' ], #pools : [ 'OpenGLConstants', - 'OpenGLTypes' + 'OpenGLTypes', + 'SDL2Constants' ], #category : #'Diya-Graphics' } @@ -35,6 +38,7 @@ DiyaNode >> addNode: node at: pos [ node parent: self. node position: pos. children add: node. + node root: self root. ^ node ] @@ -65,12 +69,28 @@ DiyaNode >> initialize [ shader := nil. context := DiyaRendererContext uniqueInstance. children := OrderedCollection new. - dirty := false + dirty := false. + ehandlers := Dictionary new. + root := nil. +] + +{ #category : #'as yet unclassified' } +DiyaNode >> inner: aPoint [ + ^ self subclassResponsibility ] { #category : #testing } DiyaNode >> isRoot [ - ^false + ^ false +] + +{ #category : #convenience } +DiyaNode >> on: eventName do: aBlock [ + |evtCode| + evtCode := SDL2Constants bindingOf: ('SDL_', eventName asUppercase). + evtCode ifNil: [ ^DiyaCoreAPIError signal: 'Unknow event ', eventName ]. + ehandlers at: evtCode value put: aBlock. + ] { #category : #accessing } @@ -103,6 +123,16 @@ DiyaNode >> render [ children do: [:c | c render ]. ] +{ #category : #accessing } +DiyaNode >> root [ + ^ root +] + +{ #category : #accessing } +DiyaNode >> root: anObject [ + root := anObject +] + { #category : #accessing } DiyaNode >> rotation [ ^ rotation @@ -159,10 +189,21 @@ DiyaNode >> shader: anObject [ { #category : #accessing } DiyaNode >> tf [ - parent ifNil: [ self error: 'TF: This node is not attached to the main tree' ]. + parent ifNil: [ ^ DiyaCoreAPIError signal: 'TF: This node is not attached to the main tree' ]. ^ tf ] +{ #category : #'as yet unclassified' } +DiyaNode >> trigger: evt [ + evt enable ifFalse:[^self]. + ehandlers at: evt mapped type ifPresent:[:handler| handler value: evt]. + children ifNil: [^self]. + evt enable ifTrue: [ + "evt mapped triggableOn: children first." + children select: [:node | evt mapped triggableOn: node ] thenDo:[:node| node trigger: evt] + ]. +] + { #category : #accessing } DiyaNode >> update [ ^self subclassResponsibility diff --git a/Diya/DiyaRootNode.class.st b/Diya/DiyaRootNode.class.st index 72d7c67..963ce4a 100644 --- a/Diya/DiyaRootNode.class.st +++ b/Diya/DiyaRootNode.class.st @@ -4,6 +4,11 @@ Class { #category : #'Diya-Graphics' } +{ #category : #accessing } +DiyaRootNode >> boundingBox [ + ^ Rectangle origin: 0@0 corner: context resolution +] + { #category : #accessing } DiyaRootNode >> draw [ OpenGL clearColorR: 0.0 G: 0.0 B: 0.0 A:0. @@ -11,16 +16,27 @@ DiyaRootNode >> draw [ context vbo bind: GL_ARRAY_BUFFER. ] +{ #category : #accessing } +DiyaRootNode >> extent [ + ^ context resolution +] + { #category : #initialization } DiyaRootNode >> initialize [ super initialize. parent := self. shader := nil. + root := self. ] -{ #category : #testing } -DiyaRootNode >> isRoot [ - ^ true +{ #category : #'as yet unclassified' } +DiyaRootNode >> inner: aPoint [ + ^true +] + +{ #category : #accessing } +DiyaRootNode >> isRoot [ + ^true ] { #category : #initialization } diff --git a/Diya/DiyaSingleton.class.st b/Diya/DiyaSingleton.class.st index fa8a6e9..4740f67 100644 --- a/Diya/DiyaSingleton.class.st +++ b/Diya/DiyaSingleton.class.st @@ -19,7 +19,7 @@ DiyaSingleton class >> initialize [ { #category : #'instance creation' } DiyaSingleton class >> new [ - self error: 'Use #uniqueInstance' + ^ DiyaCoreAPIError signal: 'Use #uniqueInstance' ] { #category : #'instance creation' } diff --git a/Diya/DiyaText.class.st b/Diya/DiyaText.class.st index 27ad1ba..ad1921c 100644 --- a/Diya/DiyaText.class.st +++ b/Diya/DiyaText.class.st @@ -1,13 +1,14 @@ Class { #name : #DiyaText, - #superclass : #Diya2DNode, + #superclass : #Diya2DPrimShape, #instVars : [ 'fontStyle', 'fontSize', 'fontName', 'data', 'style', - 'wrap' + 'wrap', + 'texheight' ], #pools : [ 'FT2Types' @@ -36,23 +37,8 @@ DiyaText >> data: anObject [ dirty := true ] -{ #category : #accessing } -DiyaText >> draw [ - data ifNil: [ ^self ]. - self shader - setUniform: #u_texture_type value: self texture format. - "configure vao vbo for texture QUAD" - self texture setup. - context texture0 setImage2D: self texture. - context texture0 active. - context vao enableAttribute: 0. - OpenGLVertexArray vertexAttributePointerIndex: 0 size:4 type: GL_FLOAT normalized: GL_FALSE stride: 16 pointer: nil . - context vbo data: GL_ARRAY_BUFFER data: vbuffer usage: GL_STATIC_DRAW. - OpenGL drawArrays: GL_TRIANGLES first:0 count: ((vbuffer size) >> 2). - context vao disableAttribute: 0. - "reset value" - self texture drop. - +{ #category : #initialization } +DiyaText >> drawBorder [ ] { #category : #accessing } @@ -146,7 +132,8 @@ DiyaText >> initialize [ self fontName: 'Ubuntu' style:'Regular' size: 16. data := nil. wrap := false. - bbox := nil + bbox := nil. + texheight := 0. ] { #category : #'as yet unclassified' } @@ -159,7 +146,14 @@ DiyaText >> nextSpaceFrom: index [ { #category : #accessing } DiyaText >> texture [ - ^style textureOf: self fontSize + |tex| + tex := style textureOf: self fontSize. + texheight = tex height ifFalse: [ + texheight := tex height. + self update. + dirty := false. + ]. + ^tex ] { #category : #initialization } diff --git a/Diya/OpenGLSL.class.st b/Diya/OpenGLSL.class.st index a625e05..8ab8ffe 100644 --- a/Diya/OpenGLSL.class.st +++ b/Diya/OpenGLSL.class.st @@ -136,7 +136,7 @@ OpenGLSL >> checkStatus:status of: id [ ] ifFalse: [ OpenGLSL getShaderInfoLogOf: id maxLength: (infoLength at: 1) lengthPtr: nil buffer: buffer ]. - ^self error: buffer asString + ^DiyaCoreAPIError signal: buffer asString ]. ^self @@ -222,7 +222,7 @@ OpenGLSL >> locateUniforms [ OpenGLSL >> setUniform: uname value: values [ |uniform| uniform := uniforms at: uname asSymbol ifAbsent:[ - ^self error: 'Uniform ', uname, ' is not defined in this program']. + ^DiyaCoreAPIError signal: 'Uniform ', uname, ' is not defined in this program']. uniform value: values ] diff --git a/Diya/Point.extension.st b/Diya/Point.extension.st index de29c42..e378a73 100644 --- a/Diya/Point.extension.st +++ b/Diya/Point.extension.st @@ -1,5 +1,20 @@ Extension { #name : #Point } +{ #category : #'*Diya' } +Point >> applyTf: tf [ + ^(tf +* (self asArray3F)) asPoint +] + +{ #category : #'*Diya' } +Point >> asArray3F [ + ^ self asArray3F: 1.0 +] + +{ #category : #'*Diya' } +Point >> asArray3F: z [ + ^ { self x. self y. z } +] + { #category : #'*Diya' } Point >> asGLCoord [ |res| diff --git a/Diya/Rectangle.extension.st b/Diya/Rectangle.extension.st new file mode 100644 index 0000000..81563d8 --- /dev/null +++ b/Diya/Rectangle.extension.st @@ -0,0 +1,8 @@ +Extension { #name : #Rectangle } + +{ #category : #'*Diya' } +Rectangle >> applyTf: tf [ + ^ Rectangle + origin: (self origin applyTf: tf) + corner: (self corner applyTf: tf) +] diff --git a/Diya/SDL2MappedEvent.extension.st b/Diya/SDL2MappedEvent.extension.st new file mode 100644 index 0000000..9465b8f --- /dev/null +++ b/Diya/SDL2MappedEvent.extension.st @@ -0,0 +1,6 @@ +Extension { #name : #SDL2MappedEvent } + +{ #category : #'*Diya' } +SDL2MappedEvent >> triggableOn: aNode [ + ^aNode isRoot +] diff --git a/Diya/SDL_MouseButtonEvent.extension.st b/Diya/SDL_MouseButtonEvent.extension.st new file mode 100644 index 0000000..d592b39 --- /dev/null +++ b/Diya/SDL_MouseButtonEvent.extension.st @@ -0,0 +1,11 @@ +Extension { #name : #'SDL_MouseButtonEvent' } + +{ #category : #'*Diya' } +SDL_MouseButtonEvent >> triggableOn: aNode [ + ^ aNode inner: self worldPosition +] + +{ #category : #'*Diya' } +SDL_MouseButtonEvent >> worldPosition [ + ^ (self x) @ (DiyaRendererContext uniqueInstance resolution y - self y ) +] diff --git a/Diya/SDL_MouseMotionEvent.extension.st b/Diya/SDL_MouseMotionEvent.extension.st new file mode 100644 index 0000000..8fdc08f --- /dev/null +++ b/Diya/SDL_MouseMotionEvent.extension.st @@ -0,0 +1,12 @@ +Extension { #name : #'SDL_MouseMotionEvent' } + +{ #category : #'*Diya' } +SDL_MouseMotionEvent >> triggableOn: aNode [ + ^false + "^ aNode inner: self worldPosition " +] + +{ #category : #'*Diya' } +SDL_MouseMotionEvent >> worldPosition [ + ^ (self x) @ (DiyaRendererContext uniqueInstance resolution y - self y ) +] diff --git a/Diya/SDL_TouchFingerEvent.extension.st b/Diya/SDL_TouchFingerEvent.extension.st new file mode 100644 index 0000000..3bd35b8 --- /dev/null +++ b/Diya/SDL_TouchFingerEvent.extension.st @@ -0,0 +1,11 @@ +Extension { #name : #'SDL_TouchFingerEvent' } + +{ #category : #'*Diya' } +SDL_TouchFingerEvent >> triggableOn: aNode [ + ^ aNode inner: self worldPosition +] + +{ #category : #'*Diya' } +SDL_TouchFingerEvent >> worldPosition [ + ^ (self x) @ (DiyaRendererContext uniqueInstance resolution y - self y ) +]