mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-28 12:28:21 +01:00
Extend SDL2 binding API
This commit is contained in:
parent
12a79139d7
commit
7371fd5032
@ -30,10 +30,10 @@ DiyaBoot class >> startUp: status [
|
|||||||
Transcript
|
Transcript
|
||||||
show: c className;
|
show: c className;
|
||||||
cr ].
|
cr ].
|
||||||
Transcript show: self tickSinceStart; cr.
|
self startx.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'system startup' }
|
{ #category : #'system startup' }
|
||||||
DiyaBoot class >> tickSinceStart [
|
DiyaBoot class >> startx [
|
||||||
^ self ffiCall: #( uint clock() ) module: 'libc.so.6'.
|
DiyaInit uniqueInstance eventLoop
|
||||||
]
|
]
|
||||||
|
48
Diya/DiyaInit.class.st
Normal file
48
Diya/DiyaInit.class.st
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
Class {
|
||||||
|
#name : #DiyaInit,
|
||||||
|
#superclass : #Object,
|
||||||
|
#classVars : [
|
||||||
|
'singleton'
|
||||||
|
],
|
||||||
|
#pools : [
|
||||||
|
'SDL2Constants',
|
||||||
|
'SDL2Types'
|
||||||
|
],
|
||||||
|
#category : #'Diya-Core'
|
||||||
|
}
|
||||||
|
|
||||||
|
{ #category : #'instance creation' }
|
||||||
|
DiyaInit class >> uniqueInstance [
|
||||||
|
singleton ifNil: [ singleton := self new ].
|
||||||
|
^ singleton
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #events }
|
||||||
|
DiyaInit >> checkDrivers [
|
||||||
|
|ndriver usableDrivers|
|
||||||
|
ndriver := SDL2 SDLGetNumVideoDrivers.
|
||||||
|
usableDrivers := OrderedCollection new.
|
||||||
|
Transcript show: 'Available drivers: '.
|
||||||
|
0 to: ndriver - 1 do: [ :i | |dname|
|
||||||
|
dname := SDL2 SDLGetVideoDriver: i.
|
||||||
|
Transcript show: dname, ' '.
|
||||||
|
(SDL2 SDLVideoInit: dname) = 0 ifTrue:[
|
||||||
|
usableDrivers add: dname.
|
||||||
|
SDL2 SDLVideoQuit
|
||||||
|
]
|
||||||
|
].
|
||||||
|
Transcript cr.
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #events }
|
||||||
|
DiyaInit >> eventLoop [
|
||||||
|
|status|
|
||||||
|
self checkDrivers.
|
||||||
|
status := SDL2 init: SDL_INIT_EVERYTHING.
|
||||||
|
status = 0 ifFalse:[
|
||||||
|
^ self error: SDL2 getErrorMessage.
|
||||||
|
].
|
||||||
|
Transcript show: 'Current selected video driver ', (SDL2 SDLGetCurrentVideoDriver); cr.
|
||||||
|
SDL2 quit
|
||||||
|
]
|
@ -1,18 +0,0 @@
|
|||||||
Class {
|
|
||||||
#name : #DiyaSDLBinding,
|
|
||||||
#superclass : #DiyaFFIBase,
|
|
||||||
#category : #'Diya-Graphics-SDL'
|
|
||||||
}
|
|
||||||
|
|
||||||
{ #category : #accessing }
|
|
||||||
DiyaSDLBinding class >> checkSymbol [
|
|
||||||
^ 'SDL_Init'
|
|
||||||
]
|
|
||||||
|
|
||||||
{ #category : #accessing }
|
|
||||||
DiyaSDLBinding class >> libNames [
|
|
||||||
#(
|
|
||||||
'libSDL2-2.0.so.0' "Linux 1"
|
|
||||||
'libSDL2-2.0.so.0.2.1' "Linux 2"
|
|
||||||
)
|
|
||||||
]
|
|
63
Diya/SDL2.extension.st
Normal file
63
Diya/SDL2.extension.st
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
Extension { #name : #SDL2 }
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> SDLClearError [
|
||||||
|
^ self ffiCall: #(void SDL_ClearError(void))
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> SDLGetCurrentDisplayMode: mode from:index [
|
||||||
|
^ self ffiCall: #(int SDL_GetCurrentDisplayMode(int index, SDL_DisplayMode* mode))
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> SDLGetCurrentVideoDriver [
|
||||||
|
^self ffiCall: #(const char* SDL_GetCurrentVideoDriver(void))
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> SDLGetNumRenderDrivers [
|
||||||
|
^self ffiCall: #(int SDL_GetNumRenderDrivers(void))
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> SDLGetNumVideoDrivers [
|
||||||
|
^ self ffiCall: #(int SDL_GetNumVideoDrivers(void))
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> SDLGetVideoDriver: index [
|
||||||
|
^self ffiCall: #(const char* SDL_GetVideoDriver(int index))
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> SDLVideoInit:driver_name [
|
||||||
|
^self ffiCall: #(int SDL_VideoInit(const char *driver_name))
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> SDLVideoQuit [
|
||||||
|
^ self ffiCall: #(void SDL_VideoQuit(void))
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'*Diya' }
|
||||||
|
SDL2 class >> findSDL2 [
|
||||||
|
"Look for SDL2 using different names."
|
||||||
|
#(0 "Static"
|
||||||
|
SDL2
|
||||||
|
'libSDL2-2.0.0.dylib' "Mac"
|
||||||
|
'libSDL2-2.0.so.0' "Linux 1"
|
||||||
|
'libSDL2-2.0.so.0.2.1' "Linux 2"
|
||||||
|
'SDL2.dll' "Windows"
|
||||||
|
) do: [ :eachName |
|
||||||
|
[ (self checkLibraryName: eachName) ifTrue: [ ^ eachName ] ]
|
||||||
|
ifError: [nil] ].
|
||||||
|
self error: 'Failed to find SDL2 library.'
|
||||||
|
]
|
86
Diya/SDL_DisplayMode.class.st
Normal file
86
Diya/SDL_DisplayMode.class.st
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
Class {
|
||||||
|
#name : #'SDL_DisplayMode',
|
||||||
|
#superclass : #SDL2Structure,
|
||||||
|
#classVars : [
|
||||||
|
'OFFSET_DRIVERDATA',
|
||||||
|
'OFFSET_FORMAT',
|
||||||
|
'OFFSET_H',
|
||||||
|
'OFFSET_REFRESH_RATE',
|
||||||
|
'OFFSET_W'
|
||||||
|
],
|
||||||
|
#pools : [
|
||||||
|
'SDL2Types'
|
||||||
|
],
|
||||||
|
#category : #'Diya-SDL2'
|
||||||
|
}
|
||||||
|
|
||||||
|
{ #category : #'field definition' }
|
||||||
|
SDL_DisplayMode class >> fieldsDesc [
|
||||||
|
^#(
|
||||||
|
Uint32 format;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
int refresh_rate;
|
||||||
|
void* driverdata;
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> driverdata [
|
||||||
|
"This method was automatically generated"
|
||||||
|
^ExternalData fromHandle: (handle pointerAt: OFFSET_DRIVERDATA) type: ExternalType void asPointerType
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> driverdata: anObject [
|
||||||
|
"This method was automatically generated"
|
||||||
|
handle pointerAt: OFFSET_DRIVERDATA put: anObject getHandle.
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> format [
|
||||||
|
"This method was automatically generated"
|
||||||
|
^handle unsignedLongAt: OFFSET_FORMAT
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> format: anObject [
|
||||||
|
"This method was automatically generated"
|
||||||
|
handle unsignedLongAt: OFFSET_FORMAT put: anObject
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> h [
|
||||||
|
"This method was automatically generated"
|
||||||
|
^handle signedLongAt: OFFSET_H
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> h: anObject [
|
||||||
|
"This method was automatically generated"
|
||||||
|
handle signedLongAt: OFFSET_H put: anObject
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> refresh_rate [
|
||||||
|
"This method was automatically generated"
|
||||||
|
^handle signedLongAt: OFFSET_REFRESH_RATE
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> refresh_rate: anObject [
|
||||||
|
"This method was automatically generated"
|
||||||
|
handle signedLongAt: OFFSET_REFRESH_RATE put: anObject
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> w [
|
||||||
|
"This method was automatically generated"
|
||||||
|
^handle signedLongAt: OFFSET_W
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #'accessing structure variables' }
|
||||||
|
SDL_DisplayMode >> w: anObject [
|
||||||
|
"This method was automatically generated"
|
||||||
|
handle signedLongAt: OFFSET_W put: anObject
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user