mirror of
https://github.com/lxsang/Diya-API.git
synced 2024-12-28 12:28:21 +01:00
update SDL example entry point
This commit is contained in:
parent
03d3a59560
commit
4ecbd0af73
@ -4,7 +4,8 @@ Class {
|
|||||||
#instVars : [
|
#instVars : [
|
||||||
'running',
|
'running',
|
||||||
'window',
|
'window',
|
||||||
'renderer'
|
'renderer',
|
||||||
|
'display'
|
||||||
],
|
],
|
||||||
#classVars : [
|
#classVars : [
|
||||||
'singleton'
|
'singleton'
|
||||||
@ -13,7 +14,7 @@ Class {
|
|||||||
'SDL2Constants',
|
'SDL2Constants',
|
||||||
'SDL2Types'
|
'SDL2Types'
|
||||||
],
|
],
|
||||||
#category : #'Diya-Core'
|
#category : #'Diya-Runtime'
|
||||||
}
|
}
|
||||||
|
|
||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
@ -23,7 +24,7 @@ DiyaBoot class >> startUp: status [
|
|||||||
|
|
||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
DiyaBoot class >> startx [
|
DiyaBoot class >> startx [
|
||||||
self uniqueInstance eventLoop
|
self uniqueInstance run
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #'instance creation' }
|
{ #category : #'instance creation' }
|
||||||
@ -75,37 +76,27 @@ DiyaBoot >> createWindow [
|
|||||||
handle := SDL2 createWindow: 'Diya test'
|
handle := SDL2 createWindow: 'Diya test'
|
||||||
x: 0
|
x: 0
|
||||||
y: 0
|
y: 0
|
||||||
width: 480
|
width: display w
|
||||||
height: 640
|
height: display h
|
||||||
flags: SDL_WINDOW_SHOWN.
|
flags: SDL_WINDOW_SHOWN.
|
||||||
handle ifNil: [ ^self error: SDL2 getErrorMessage ].
|
handle ifNil: [ ^self error: SDL2 getErrorMessage ].
|
||||||
"handle fullscreen: SDL_WINDOW_FULLSCREEN."
|
"handle fullscreen: SDL_WINDOW_FULLSCREEN."
|
||||||
^handle
|
^handle
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #events }
|
|
||||||
DiyaBoot >> eventLoop [
|
|
||||||
| dm|
|
|
||||||
self init.
|
|
||||||
Transcript show: 'Current selected video driver ', (SDL2 SDLGetCurrentVideoDriver); cr.
|
|
||||||
dm := SDL_DisplayMode externalNew autoRelease.
|
|
||||||
SDL2 SDLGetCurrentDisplayMode: dm from:0.
|
|
||||||
Transcript show: dm w asString, 'x',dm h asString;cr.
|
|
||||||
window := self createWindow.
|
|
||||||
renderer := self createRenderer.
|
|
||||||
self render: renderer.
|
|
||||||
renderer destroy.
|
|
||||||
window destroy.
|
|
||||||
SDL2 quit.
|
|
||||||
Transcript show: 'System quit'
|
|
||||||
]
|
|
||||||
|
|
||||||
{ #category : #events }
|
{ #category : #events }
|
||||||
DiyaBoot >> init [
|
DiyaBoot >> init [
|
||||||
| tmp1 |
|
| status nvdrivers |
|
||||||
tmp1 := SDL2 init: SDL_INIT_EVERYTHING.
|
Transcript show:'System: ', (Smalltalk globals at: #CODENAME),'-v',(Smalltalk globals at: #VERSION);cr.
|
||||||
tmp1 = 0
|
status := SDL2 init: SDL_INIT_EVERYTHING.
|
||||||
ifFalse: [ ^ self error: SDL2 getErrorMessage ]
|
status = 0
|
||||||
|
ifFalse: [ ^ self error: SDL2 getErrorMessage ].
|
||||||
|
nvdrivers := SDL2 SDLGetNumVideoDrivers.
|
||||||
|
Transcript show: 'Supported video dirvers:'.
|
||||||
|
0 to: nvdrivers -1 do: [ :i |
|
||||||
|
Transcript show: (SDL2 SDLGetVideoDriver: i), ' '.
|
||||||
|
].
|
||||||
|
Transcript cr.
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #events }
|
{ #category : #events }
|
||||||
@ -119,8 +110,8 @@ DiyaBoot >> processEvent: event [
|
|||||||
mappedEvt := event mapped.
|
mappedEvt := event mapped.
|
||||||
mappedEvt type = SDL_KEYDOWN ifTrue: [ Transcript show: 'keydown...'. running := false. ].
|
mappedEvt type = SDL_KEYDOWN ifTrue: [ Transcript show: 'keydown...'. running := false. ].
|
||||||
mappedEvt type = SDL_QUIT ifTrue:[ running:= false ].
|
mappedEvt type = SDL_QUIT ifTrue:[ running:= false ].
|
||||||
mappedEvt type = SDL_FINGERDOWN ifTrue:[window warpMouseX:((mappedEvt x)* 480 )Y: ((mappedEvt y) * 640)].
|
mappedEvt type = SDL_FINGERDOWN ifTrue:[self setCursorPosition: mappedEvt ].
|
||||||
mappedEvt type = SDL_FINGERMOTION ifTrue:[window warpMouseX:((mappedEvt x)* 480 )Y: ((mappedEvt y) * 640)].
|
mappedEvt type = SDL_FINGERMOTION ifTrue:[self setCursorPosition: mappedEvt ].
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #events }
|
{ #category : #events }
|
||||||
@ -133,16 +124,42 @@ DiyaBoot >> randomColorChannel [
|
|||||||
]
|
]
|
||||||
|
|
||||||
{ #category : #events }
|
{ #category : #events }
|
||||||
DiyaBoot >> render: renderer [
|
DiyaBoot >> render [
|
||||||
|event|
|
|event|
|
||||||
event := SDL_Event new.
|
event := SDL_Event new.
|
||||||
[ running ] whileTrue: [
|
[ running ] whileTrue: [
|
||||||
[ (SDL2 pollEvent: event) > 0 ] whileTrue: [
|
[ (SDL2 pollEvent: event) > 0 ] whileTrue: [
|
||||||
self processEvent: event
|
self processEvent: event
|
||||||
].
|
].
|
||||||
renderer drawColorR: self randomColorChannel g: self randomColorChannel b: self randomColorChannel a: 255.
|
renderer drawColorR: self randomColorChannel
|
||||||
|
g: self randomColorChannel
|
||||||
|
b: self randomColorChannel
|
||||||
|
a: 255.
|
||||||
renderer clear.
|
renderer clear.
|
||||||
renderer present.
|
renderer present.
|
||||||
SDL2 delay: 50.
|
SDL2 delay: 50.
|
||||||
].
|
].
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #events }
|
||||||
|
DiyaBoot >> run [
|
||||||
|
self init.
|
||||||
|
Transcript show: 'Current selected video driver: ', (SDL2 SDLGetCurrentVideoDriver); cr.
|
||||||
|
display := SDL_DisplayMode externalNew autoRelease.
|
||||||
|
SDL2 SDLGetCurrentDisplayMode: display from:0.
|
||||||
|
Transcript show:'Display resolution: ', display w asString, 'x',display h asString;cr.
|
||||||
|
window := self createWindow.
|
||||||
|
renderer := self createRenderer.
|
||||||
|
self render.
|
||||||
|
renderer destroy.
|
||||||
|
window destroy.
|
||||||
|
SDL2 quit.
|
||||||
|
Transcript show: 'System quit'; cr.
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : #events }
|
||||||
|
DiyaBoot >> setCursorPosition: mappedEvt [
|
||||||
|
Transcript show: 'x: ', mappedEvt x asString, ' - y: ', mappedEvt y asString; cr.
|
||||||
|
window warpMouseX:((mappedEvt x)* (display w) )
|
||||||
|
Y: ((mappedEvt y) * (display h))
|
||||||
|
]
|
||||||
|
@ -87,7 +87,8 @@ ImageInitializer >> preloadSystem: loaded [
|
|||||||
|
|
||||||
{ #category : #activation }
|
{ #category : #activation }
|
||||||
ImageInitializer >> snap [
|
ImageInitializer >> snap [
|
||||||
Smalltalk globals at: #codeName put: 'diya'.
|
Smalltalk globals at: #CODENAME put: 'diya'.
|
||||||
|
Smalltalk globals at: #VERSION put: '0.1.0'.
|
||||||
self class removeFromSystem.
|
self class removeFromSystem.
|
||||||
Smalltalk addToStartUpList: DiyaBoot.
|
Smalltalk addToStartUpList: DiyaBoot.
|
||||||
Smalltalk garbageCollect.
|
Smalltalk garbageCollect.
|
||||||
|
Loading…
Reference in New Issue
Block a user