diff --git a/Diya/DiskStore.extension.st b/Diya/DiskStore.extension.st new file mode 100644 index 0000000..14bdc3a --- /dev/null +++ b/Diya/DiskStore.extension.st @@ -0,0 +1,6 @@ +Extension { #name : #DiskStore } + +{ #category : #'*Diya' } +DiskStore class >> inform: string [ + Transcript show: string; cr. +] diff --git a/Diya/DiyaApplicationLauncher.class.st b/Diya/DiyaApplicationLauncher.class.st index 7ea7fd3..407e268 100644 --- a/Diya/DiyaApplicationLauncher.class.st +++ b/Diya/DiyaApplicationLauncher.class.st @@ -34,7 +34,7 @@ DiyaApplicationLauncher >> defaultApplication [ ^DiyaExampleApp ] -{ #category : #'as yet unclassified' } +{ #category : #accessing } DiyaApplicationLauncher >> delta: delta [ |fps| delta = 0 ifTrue:[^self]. diff --git a/Diya/DiyaBoot.class.st b/Diya/DiyaBoot.class.st index 245cf43..3eae063 100644 --- a/Diya/DiyaBoot.class.st +++ b/Diya/DiyaBoot.class.st @@ -84,14 +84,12 @@ DiyaBoot >> init [ status = 0 ifFalse: [ ^ DiyaCoreAPIError signal: SDL2 getErrorMessage ]. display := SDL_DisplayMode externalNew autoRelease. - Smalltalk globals at: #Display ifAbsentPut:display. - Smalltalk globals at: #DiyaDisplay put:display. SDL2 SDLGetCurrentDisplayMode: display from:0. SDL2 showCursor: 0. + Smalltalk globals at: #Display ifAbsentPut:display. + Smalltalk globals at: #DiyaDisplay put:display. DiyaSingleton resetAll. DiyaFontManager uniqueInstance loadFonts. - -Form class removeSelector: #serviceImageAsBackground ] { #category : #events } @@ -191,6 +189,7 @@ DiyaBoot >> showSystemInfo [ ]. stream cr. stream nextPutAll: DiyaDisplay asString; cr. + stream cr. self stdout nextPutAll: stream contents ] @@ -203,8 +202,10 @@ DiyaBoot >> startx [ "SDL2 glMakeCurrent: window context: context." self showSystemInfo. DiyaRendererContext - uniqueInstance display: display; - useProjection: OrthoProjectionMatrix. + uniqueInstance + display: display; + window: window; + useProjection: OrthoProjectionMatrix. self render. context delete. window destroy. diff --git a/Diya/DiyaButton.class.st b/Diya/DiyaButton.class.st index 401a96b..c849c19 100644 --- a/Diya/DiyaButton.class.st +++ b/Diya/DiyaButton.class.st @@ -39,14 +39,14 @@ DiyaButton >> label [ ] { #category : #accessing } -DiyaButton >> text: string [ - label txt: string. -] - -{ #category : #accessing } -DiyaButton >> update [ +DiyaButton >> process [ rec extent: self extent. label position: 0@0. label extent: self extent. ^true ] + +{ #category : #accessing } +DiyaButton >> text: string [ + label txt: string. +] diff --git a/Diya/DiyaEllipse.class.st b/Diya/DiyaEllipse.class.st index b3bdd16..b3ba463 100644 --- a/Diya/DiyaEllipse.class.st +++ b/Diya/DiyaEllipse.class.st @@ -49,6 +49,21 @@ DiyaEllipse >> inner: aPoint [ ^ ((((dxy x) ** 2)/(rx**2)) + (((dxy y) ** 2) / (ry**2))) < 1. ] +{ #category : #accessing } +DiyaEllipse >> process [ + bbox := Rectangle origin: ((rx negated) @ (ry negated)) corner: (rx @ ry). + { + bbox origin x. bbox origin y. 0.0. 0.0. + bbox origin x. bbox corner y. 0.0. 1.0. + bbox corner x. bbox corner y. 1.0. 1.0. + + bbox corner x. bbox corner y. 1.0. 1.0. + bbox corner x. bbox origin y. 1.0. 0.0. + bbox origin x. bbox origin y. 0.0. 0.0. + } doWithIndex: [:e :i| vbuffer at: i put: e]. + ^true +] + { #category : #accessing } DiyaEllipse >> rx [ ^ rx @@ -80,18 +95,3 @@ DiyaEllipse >> setUpShader [ setUniform: #u_rx value: rx; setUniform: #u_ry value: ry. ] - -{ #category : #accessing } -DiyaEllipse >> update [ - bbox := Rectangle origin: ((rx negated) @ (ry negated)) corner: (rx @ ry). - { - bbox origin x. bbox origin y. 0.0. 0.0. - bbox origin x. bbox corner y. 0.0. 1.0. - bbox corner x. bbox corner y. 1.0. 1.0. - - bbox corner x. bbox corner y. 1.0. 1.0. - bbox corner x. bbox origin y. 1.0. 0.0. - bbox origin x. bbox origin y. 0.0. 0.0. - } doWithIndex: [:e :i| vbuffer at: i put: e]. - ^true -] diff --git a/Diya/DiyaExampleApp.class.st b/Diya/DiyaExampleApp.class.st index 3233f63..9a3392e 100644 --- a/Diya/DiyaExampleApp.class.st +++ b/Diya/DiyaExampleApp.class.st @@ -130,5 +130,6 @@ DiyaExampleApp >> setup [ button icon:16rF185"'mrsang.png'". "button rotation: Float pi / 2.0." button styleName: #button_view. + Transcript show: 'Application setup';cr. ^ root ] diff --git a/Diya/DiyaFontIcon.class.st b/Diya/DiyaFontIcon.class.st index 55be2cb..713171e 100644 --- a/Diya/DiyaFontIcon.class.st +++ b/Diya/DiyaFontIcon.class.st @@ -59,8 +59,8 @@ DiyaFontIcon >> lastSeparatorFrom: i [ ] { #category : #initialization } -DiyaFontIcon >> update [ +DiyaFontIcon >> process [ data ifNil: [ ^self ]. bbox := Rectangle origin: 0@0 corner: ((data size) * (self fontSize) ) @ self fontSize. - ^ super update. + ^ super process. ] diff --git a/Diya/DiyaImageIcon.class.st b/Diya/DiyaImageIcon.class.st index 4b0aa08..cf73cf9 100644 --- a/Diya/DiyaImageIcon.class.st +++ b/Diya/DiyaImageIcon.class.st @@ -20,9 +20,9 @@ DiyaImageIcon >> initialize [ ] { #category : #accessing } -DiyaImageIcon >> update [ +DiyaImageIcon >> process [ |v| v := self iconSize. self extent: (v@v). - ^super update + ^super process ] diff --git a/Diya/DiyaImageTex.class.st b/Diya/DiyaImageTex.class.st index 925269d..8575755 100644 --- a/Diya/DiyaImageTex.class.st +++ b/Diya/DiyaImageTex.class.st @@ -36,32 +36,28 @@ DiyaImageTex >> drop [ { #category : #capture } DiyaImageTex >> flipY [ - |buffer idx idxf| - buffer := FFIExternalArray externalNewType: GLubyte size: width * height * 4. + |buffer size linesize top bottom| + size := self bytesSize. + linesize := width << 2. + buffer := FFIExternalArray externalNewType: GLubyte size: linesize. LibC memset: buffer getHandle value: 0 size: buffer size. - buffer autoRelease. - 0 to: height - 1 do:[:y| - 0 to: width - 1 do:[:x| - idx := ((y * width) + x)*4 + 1. - idxf := ((height - y)*width + x)*4 + 1. - buffer at: idx put: (data at: idxf). - buffer at: idx+1 put: (data at: idxf+1). - buffer at: idx+2 put: (data at: idxf+2). - buffer at: idx+3 put: (data at: idxf+3). - ]. + 0 to: (height >> 1) -1 do: [ :line| + top := line * linesize. + bottom := (size - (linesize * (line + 1))). + LibC memCopy: (data getHandle) + top to: buffer getHandle size: linesize. + LibC memCopy: (data getHandle) + bottom to: (data getHandle) + top size: linesize. + LibC memCopy: buffer getHandle to: (data getHandle) + bottom size: linesize. ]. - data free. - data := buffer. - - + buffer free ] { #category : #capture } DiyaImageTex >> fromDisplay: aRect as: assetName [ surface ifNotNil: [ surface free ] ifNil: [data ifNotNil: [data free]]. surface := nil. - Transcript show:'allocate ', ((aRect extent x) * (aRect extent y) * 4) asInteger asString,' bytes';cr. - data := FFIExternalArray externalNewType: GLubyte size:((aRect extent x) * (aRect extent y) * 4) asInteger. + width := aRect extent x asInteger. + height := aRect extent y asInteger. + data := FFIExternalArray externalNewType: GLubyte size: self bytesSize. LibC memset: data getHandle value: 0 size: data size. data autoRelease. OpenGL readPixelsOn: data getHandle @@ -71,11 +67,8 @@ DiyaImageTex >> fromDisplay: aRect as: assetName [ h: aRect extent y format:GL_RGBA type: GL_UNSIGNED_BYTE. - width := aRect extent x. - height := aRect extent y. name := assetName. self flipY. - ] { #category : #capture } diff --git a/Diya/DiyaLabel.class.st b/Diya/DiyaLabel.class.st index 4d441a8..3c0184d 100644 --- a/Diya/DiyaLabel.class.st +++ b/Diya/DiyaLabel.class.st @@ -52,18 +52,7 @@ DiyaLabel >> initialize [ ] { #category : #accessing } -DiyaLabel >> txt [ - ^ txt -] - -{ #category : #accessing } -DiyaLabel >> txt: anObject [ - txt data: anObject. - self setDirty -] - -{ #category : #accessing } -DiyaLabel >> update [ +DiyaLabel >> process [ |offset isize align| offset := 0. icon ifNotNil: [ @@ -73,7 +62,7 @@ DiyaLabel >> update [ ]. txt extent: (extent x - offset) @ (extent y). "lookahead update" - txt update. + txt process. align := self getHAlign: offset. txt position: offset @ ( (self extent y - txt extent y ) >> 1). @@ -83,3 +72,14 @@ DiyaLabel >> update [ ^ true ] + +{ #category : #accessing } +DiyaLabel >> txt [ + ^ txt +] + +{ #category : #accessing } +DiyaLabel >> txt: anObject [ + txt data: anObject. + self setDirty +] diff --git a/Diya/DiyaLine.class.st b/Diya/DiyaLine.class.st index 0f4a962..9d035b9 100644 --- a/Diya/DiyaLine.class.st +++ b/Diya/DiyaLine.class.st @@ -82,18 +82,7 @@ DiyaLine >> inner: aPoint [ ] { #category : #accessing } -DiyaLine >> to [ - ^ to -] - -{ #category : #accessing } -DiyaLine >> to: anObject [ - to := anObject. - self setDirty -] - -{ #category : #accessing } -DiyaLine >> update [ +DiyaLine >> process [ |extent| bbox := (Rectangle origin: from corner: to ). bbox origin = translation ifFalse:[self position: bbox origin]. @@ -108,3 +97,14 @@ DiyaLine >> update [ } doWithIndex: [:e :i| vbuffer at: i put: e]. ^true ] + +{ #category : #accessing } +DiyaLine >> to [ + ^ to +] + +{ #category : #accessing } +DiyaLine >> to: anObject [ + to := anObject. + self setDirty +] diff --git a/Diya/DiyaNode.class.st b/Diya/DiyaNode.class.st index 8e11efb..5c3c6e5 100644 --- a/Diya/DiyaNode.class.st +++ b/Diya/DiyaNode.class.st @@ -57,7 +57,21 @@ DiyaNode >> addNode: node at: pos [ node position: pos. children add: node. node root: self root. - ^ node + Transcript show:'Added node #', self id asString; cr. + ^ node +] + +{ #category : #accessing } +DiyaNode >> allChildren [ + |nodes| + nodes := OrderedCollection new. + children ifNil: [ ^ nodes ]. + children do:[:c| + nodes add: c. + c allChildren do:[:e| nodes add:e]. + ]. + ^nodes + ] { #category : #accessing } @@ -148,6 +162,11 @@ DiyaNode >> position: anObject [ self updateTF. ] +{ #category : #accessing } +DiyaNode >> process [ + ^self subclassResponsibility +] + { #category : #convenience } DiyaNode >> register: aBlock to: eventName [ |evtCode| @@ -159,12 +178,13 @@ DiyaNode >> register: aBlock to: eventName [ { #category : #accessing } DiyaNode >> render [ + self step. dirty ifTrue:[ - dirty := self update not]. + dirty := self process not]. shader ifNotNil: [self setUpShader]. self draw. children ifNil: [ ^self ]. - children do: [:c | c render ]. + children do: [:c | c render ]. ] { #category : #accessing } @@ -241,6 +261,10 @@ DiyaNode >> shader: anObject [ shader := anObject ] +{ #category : #stepping } +DiyaNode >> step [ +] + { #category : #accessing } DiyaNode >> styleName [ ^ styleName @@ -276,11 +300,6 @@ DiyaNode >> trigger: evt [ ]. ] -{ #category : #accessing } -DiyaNode >> update [ - ^self subclassResponsibility -] - { #category : #accessing } DiyaNode >> updateTF [ self subclassResponsibility diff --git a/Diya/DiyaPolygon.class.st b/Diya/DiyaPolygon.class.st index 8c9c92c..f4b4cb6 100644 --- a/Diya/DiyaPolygon.class.st +++ b/Diya/DiyaPolygon.class.st @@ -40,6 +40,16 @@ DiyaPolygon >> points: anObject [ self setDirty ] +{ #category : #accessing } +DiyaPolygon >> process [ + bbox := self recFromPoints. + translation = bbox origin ifFalse:[ self position: bbox origin]. + points := points collect:[:e | e - bbox origin]. + bbox := self recFromPoints. + self calculateVertices. + ^true +] + { #category : #accessing } DiyaPolygon >> recFromPoints [ |maxX maxY minX minY x y| @@ -55,13 +65,3 @@ DiyaPolygon >> recFromPoints [ ]. ^ Rectangle origin: minX@minY corner: maxX @ maxY ] - -{ #category : #accessing } -DiyaPolygon >> update [ - bbox := self recFromPoints. - translation = bbox origin ifFalse:[ self position: bbox origin]. - points := points collect:[:e | e - bbox origin]. - bbox := self recFromPoints. - self calculateVertices. - ^true -] diff --git a/Diya/DiyaRectangle.class.st b/Diya/DiyaRectangle.class.st index df669f3..0ce9863 100644 --- a/Diya/DiyaRectangle.class.st +++ b/Diya/DiyaRectangle.class.st @@ -37,7 +37,7 @@ DiyaRectangle >> initialize [ ] { #category : #accessing } -DiyaRectangle >> update [ +DiyaRectangle >> process [ |extent| extent := self extent. { diff --git a/Diya/DiyaRendererContext.class.st b/Diya/DiyaRendererContext.class.st index 6945403..f83a4dc 100644 --- a/Diya/DiyaRendererContext.class.st +++ b/Diya/DiyaRendererContext.class.st @@ -8,7 +8,8 @@ Class { 'vao', 'texture0', 'projection', - 'assets' + 'assets', + 'window' ], #pools : [ 'OpenGLConstants', @@ -106,3 +107,13 @@ DiyaRendererContext >> vao [ DiyaRendererContext >> vbo [ ^ vbo ] + +{ #category : #accessing } +DiyaRendererContext >> window [ + ^ window +] + +{ #category : #accessing } +DiyaRendererContext >> window: anObject [ + window := anObject +] diff --git a/Diya/DiyaRootNode.class.st b/Diya/DiyaRootNode.class.st index 66b52e5..a3bb469 100644 --- a/Diya/DiyaRootNode.class.st +++ b/Diya/DiyaRootNode.class.st @@ -43,7 +43,7 @@ DiyaRootNode >> isRoot [ ] { #category : #initialization } -DiyaRootNode >> update [ +DiyaRootNode >> process [ ^true ] diff --git a/Diya/DiyaText.class.st b/Diya/DiyaText.class.st index 1bb889d..d6c7e96 100644 --- a/Diya/DiyaText.class.st +++ b/Diya/DiyaText.class.st @@ -200,6 +200,18 @@ DiyaText >> maxLineWidth [ ^ maxLineWidth ] +{ #category : #initialization } +DiyaText >> process [ + bbox ifNil: [ ^true ]. + data ifNil:[^true]. + data ifEmpty:[^true]. + vbuffer ifNotNil: [vbuffer free]. + vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16. + vbuffer autoRelease. + self drawText. + ^true +] + { #category : #accessing } DiyaText >> splitLines [ |line ret tex2D| @@ -219,24 +231,12 @@ DiyaText >> texture [ texture ifNil: [ self initTexture ]. texheight = texture height ifFalse: [ texheight := texture height. - self update. + self process. self setClean. ]. ^texture ] -{ #category : #initialization } -DiyaText >> update [ - bbox ifNil: [ ^true ]. - data ifNil:[^true]. - data ifEmpty:[^true]. - vbuffer ifNotNil: [vbuffer free]. - vbuffer := FFIExternalArray externalNewType: GLfloat size: data size * 16. - vbuffer autoRelease. - self drawText. - ^true -] - { #category : #'menu messages' } DiyaText >> valign [ ^ self ? #yAlign diff --git a/Diya/OpenGLTexImage2D.class.st b/Diya/OpenGLTexImage2D.class.st index 0643749..c993b2a 100644 --- a/Diya/OpenGLTexImage2D.class.st +++ b/Diya/OpenGLTexImage2D.class.st @@ -29,6 +29,11 @@ OpenGLTexImage2D >> border: anObject [ border := anObject ] +{ #category : #accessing } +OpenGLTexImage2D >> bytesSize [ + ^(width * height) << 2 +] + { #category : #accessing } OpenGLTexImage2D >> data [ ^ data diff --git a/Diya/SDL2.extension.st b/Diya/SDL2.extension.st index e1b935f..5286218 100644 --- a/Diya/SDL2.extension.st +++ b/Diya/SDL2.extension.st @@ -6,6 +6,11 @@ SDL2 class >> SDLAllocFormat: pixel_format [ ] +{ #category : #'*Diya' } +SDL2 class >> SDLBlitSurface: src srcRect: srcrect dest: dst dstRect: dstrect [ + ^ self ffiCall: #(int SDL_UpperBlit(SDL_Surface* src,SDL_Rect* srcrect,SDL_Surface* dst,SDL_Rect* dstrect)) +] + { #category : #'*Diya' } SDL2 class >> SDLClearError [ ^ self ffiCall: #(void SDL_ClearError(void))