2021-12-18 02:02:16 +01:00
|
|
|
Class {
|
|
|
|
#name : #DiyaBoot,
|
|
|
|
#superclass : #DiyaBaseObject,
|
2021-12-19 12:32:23 +01:00
|
|
|
#instVars : [
|
|
|
|
'running',
|
|
|
|
'window',
|
2021-12-19 16:15:10 +01:00
|
|
|
'renderer',
|
|
|
|
'display'
|
2021-12-19 12:32:23 +01:00
|
|
|
],
|
|
|
|
#classVars : [
|
|
|
|
'singleton'
|
|
|
|
],
|
|
|
|
#pools : [
|
|
|
|
'SDL2Constants',
|
|
|
|
'SDL2Types'
|
|
|
|
],
|
2021-12-19 16:15:10 +01:00
|
|
|
#category : #'Diya-Runtime'
|
2021-12-18 02:02:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-19 20:03:54 +01:00
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaBoot class >> reset [
|
|
|
|
singleton := nil
|
|
|
|
]
|
|
|
|
|
2021-12-19 12:32:23 +01:00
|
|
|
{ #category : #'instance creation' }
|
2021-12-18 02:02:16 +01:00
|
|
|
DiyaBoot class >> startUp: status [
|
2021-12-18 22:49:03 +01:00
|
|
|
self startx.
|
2021-12-18 02:02:16 +01:00
|
|
|
]
|
|
|
|
|
2021-12-19 12:32:23 +01:00
|
|
|
{ #category : #'instance creation' }
|
2021-12-18 22:49:03 +01:00
|
|
|
DiyaBoot class >> startx [
|
2021-12-19 16:15:10 +01:00
|
|
|
self uniqueInstance run
|
2021-12-19 12:32:23 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #'instance creation' }
|
|
|
|
DiyaBoot class >> uniqueInstance [
|
|
|
|
singleton ifNil: [ singleton := self new ].
|
|
|
|
^ singleton
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> createRenderer [
|
|
|
|
renderer := window primCreateRenderer: -1 flags: SDL_RENDERER_ACCELERATED.
|
|
|
|
renderer ifNil: [ ^self error: SDL2 getErrorMessage ].
|
|
|
|
^renderer
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> createWindow [
|
|
|
|
|handle|
|
2021-12-19 20:12:36 +01:00
|
|
|
handle := SDL2 createWindow: 'Diya'
|
2021-12-19 12:32:23 +01:00
|
|
|
x: 0
|
|
|
|
y: 0
|
2021-12-19 16:15:10 +01:00
|
|
|
width: display w
|
|
|
|
height: display h
|
2021-12-19 12:32:23 +01:00
|
|
|
flags: SDL_WINDOW_SHOWN.
|
|
|
|
handle ifNil: [ ^self error: SDL2 getErrorMessage ].
|
|
|
|
"handle fullscreen: SDL_WINDOW_FULLSCREEN."
|
|
|
|
^handle
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> init [
|
2021-12-19 22:17:29 +01:00
|
|
|
| status |
|
2021-12-19 16:15:10 +01:00
|
|
|
status := SDL2 init: SDL_INIT_EVERYTHING.
|
|
|
|
status = 0
|
|
|
|
ifFalse: [ ^ self error: SDL2 getErrorMessage ].
|
2021-12-19 22:17:29 +01:00
|
|
|
display := SDL_DisplayMode externalNew autoRelease.
|
|
|
|
SDL2 SDLGetCurrentDisplayMode: display from:0.
|
2021-12-19 12:32:23 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> initialize [
|
|
|
|
running := true
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> processEvent: event [
|
|
|
|
|mappedEvt|
|
|
|
|
mappedEvt := event mapped.
|
2021-12-19 20:03:54 +01:00
|
|
|
mappedEvt type = SDL_KEYDOWN ifTrue: [ Transcript show: 'keydown...'. ^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 ].
|
2021-12-19 12:32:23 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> randomColorChannel [
|
|
|
|
| rand |
|
|
|
|
rand := Random new.
|
|
|
|
rand := (rand next) * 255.
|
|
|
|
rand := rand asInteger.
|
|
|
|
^ rand
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
2021-12-19 16:15:10 +01:00
|
|
|
DiyaBoot >> render [
|
2021-12-19 12:32:23 +01:00
|
|
|
|event|
|
|
|
|
event := SDL_Event new.
|
|
|
|
[ running ] whileTrue: [
|
|
|
|
[ (SDL2 pollEvent: event) > 0 ] whileTrue: [
|
|
|
|
self processEvent: event
|
|
|
|
].
|
2021-12-19 16:15:10 +01:00
|
|
|
renderer drawColorR: self randomColorChannel
|
|
|
|
g: self randomColorChannel
|
|
|
|
b: self randomColorChannel
|
|
|
|
a: 255.
|
2021-12-19 12:32:23 +01:00
|
|
|
renderer clear.
|
|
|
|
renderer present.
|
|
|
|
SDL2 delay: 50.
|
|
|
|
].
|
2021-12-18 02:02:16 +01:00
|
|
|
]
|
2021-12-19 16:15:10 +01:00
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> run [
|
|
|
|
self init.
|
2021-12-19 22:17:29 +01:00
|
|
|
self startx.
|
2021-12-19 20:03:54 +01:00
|
|
|
]
|
|
|
|
|
2021-12-19 22:17:29 +01:00
|
|
|
{ #category : #running }
|
2021-12-19 20:03:54 +01:00
|
|
|
DiyaBoot >> run: screenSize [
|
2021-12-19 22:17:29 +01:00
|
|
|
self run: screenSize app: nil
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #running }
|
|
|
|
DiyaBoot >> run: screenSize app: application [
|
2021-12-19 20:03:54 +01:00
|
|
|
self init.
|
|
|
|
display w: screenSize x.
|
|
|
|
display h: screenSize y.
|
|
|
|
self startx
|
|
|
|
]
|
|
|
|
|
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> setCursorPosition: mappedEvt [
|
|
|
|
window warpMouseX:((mappedEvt x)* (display w) )
|
|
|
|
Y: ((mappedEvt y) * (display h))
|
|
|
|
]
|
|
|
|
|
2021-12-19 22:17:29 +01:00
|
|
|
{ #category : #logging }
|
|
|
|
DiyaBoot >> showSystemInfo [
|
|
|
|
|stream numdriver rinfo |
|
|
|
|
stream := String new writeStream.
|
|
|
|
stream nextPutAll:'System: ';
|
|
|
|
nextPutAll:(Smalltalk globals at: #CODENAME ifAbsent:['']);
|
|
|
|
nextPutAll: '-v';
|
|
|
|
nextPutAll:(Smalltalk globals at: #VERSION ifAbsent: ['']);cr.
|
|
|
|
numdriver := SDL2 SDLGetNumVideoDrivers.
|
|
|
|
stream nextPutAll: 'Supported video dirvers:'.
|
|
|
|
0 to: numdriver -1 do: [ :i |
|
|
|
|
stream nextPutAll: (SDL2 SDLGetVideoDriver: i); nextPutAll: ' '.
|
|
|
|
].
|
|
|
|
stream cr.
|
|
|
|
stream nextPutAll: 'Current selected video driver: ';
|
|
|
|
nextPutAll:(SDL2 SDLGetCurrentVideoDriver);cr.
|
|
|
|
numdriver := SDL2 SDLGetNumRenderDrivers.
|
|
|
|
stream nextPutAll: 'SDL_RENDER_DRIVER available:'.
|
|
|
|
rinfo := SDL_RendererInfo externalNew autoRelease.
|
|
|
|
0 to: numdriver - 1 do:[:i|
|
|
|
|
SDL2 SDLGetRendererDriverInfo: rinfo from: i.
|
|
|
|
stream nextPutAll: rinfo name readString; nextPutAll:' '.
|
|
|
|
].
|
|
|
|
stream cr.
|
|
|
|
renderer primGetRendererInfo: rinfo.
|
|
|
|
stream nextPutAll: 'SDL_RENDER_DRIVER selected: '; nextPutAll: rinfo name readString; cr.
|
|
|
|
stream nextPutAll:'Display resolution: ';
|
|
|
|
nextPutAll:display w asString;
|
|
|
|
nextPutAll: 'x';
|
|
|
|
nextPutAll: display h asString; cr.
|
|
|
|
Transcript show: stream contents
|
|
|
|
|
|
|
|
]
|
|
|
|
|
2021-12-19 20:03:54 +01:00
|
|
|
{ #category : #events }
|
|
|
|
DiyaBoot >> startx [
|
2021-12-19 16:15:10 +01:00
|
|
|
window := self createWindow.
|
|
|
|
renderer := self createRenderer.
|
2021-12-19 22:17:29 +01:00
|
|
|
self showSystemInfo.
|
2021-12-19 16:15:10 +01:00
|
|
|
self render.
|
|
|
|
renderer destroy.
|
|
|
|
window destroy.
|
|
|
|
SDL2 quit.
|
2021-12-19 20:12:36 +01:00
|
|
|
self class reset.
|
|
|
|
Smalltalk garbageCollect.
|
2021-12-19 16:15:10 +01:00
|
|
|
]
|