{ include "SDL.h" } { include "_sdl.h" } { import: Object } { import: Event } SDL : Object (_screen) SDL new [ self := super new. self _initialize ] SDL _initialize { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(300, 20); SDL_AddTimer(100, windowTimer, 0); } SDL quit { SDL_Quit(); } SDL SDLK_BACKSPACE [ ^SmallInteger value_: self _SDLK_BACKSPACE ] SDL _SDLK_BACKSPACE { _return (oop) SDLK_BACKSPACE; } SDL SDLK_UP [ ^SmallInteger value_: self _SDLK_UP ] SDL _SDLK_UP { _return (oop) SDLK_UP; } SDL SDLK_DOWN [ ^SmallInteger value_: self _SDLK_DOWN ] SDL _SDLK_DOWN { _return (oop) SDLK_DOWN; } SDL SDLK_RIGHT [ ^SmallInteger value_: self _SDLK_RIGHT ] SDL _SDLK_RIGHT { _return (oop) SDLK_RIGHT; } SDL SDLK_LEFT [ ^SmallInteger value_: self _SDLK_LEFT ] SDL _SDLK_LEFT { _return (oop) SDLK_LEFT; } SDL SDLK_HOME [ ^SmallInteger value_: self _SDLK_HOME ] SDL _SDLK_HOME { _return (oop) SDLK_HOME; } SDL SDLK_END [ ^SmallInteger value_: self _SDLK_END ] SDL _SDLK_END { _return (oop) SDLK_END; } SDL SDL_RESIZABLE [ ^SmallInteger value_: self _SDL_RESIZABLE ] SDL _SDL_RESIZABLE { _return (oop) SDL_RESIZABLE; } SDL KMOD_CTRL [ ^SmallInteger value_: self _KMOD_CTRL ] SDL _KMOD_CTRL { _return (oop) KMOD_CTRL; } SDL KMOD_SHIFT [ ^SmallInteger value_: self _KMOD_SHIFT ] SDL _KMOD_SHIFT { _return (oop) KMOD_SHIFT; } SDL KMOD_ALT [ ^SmallInteger value_: self _KMOD_ALT ] SDL _KMOD_ALT { _return (oop) KMOD_ALT; } SDL KMOD_META [ ^SmallInteger value_: self _KMOD_META ] SDL _KMOD_META { _return (oop) KMOD_META; } "---------- Video ----------" SDL pixels [ ^ self _pixels: _screen ] SDL _pixels: screen { return (oop) ((SDL_Surface *) v_screen)->pixels; } SDL setVideoMode :width :height :depth :mode [ | _width _height _depth _mode _s | _width := width _integerValue. _height := height _integerValue. _depth := depth _integerValue. _mode := mode _integerValue. { v__s = (oop)SDL_SetVideoMode((int)v__width, (int)v__height, (int)v__depth, (int)v__mode); }. _screen := _s. ] SDL setCaption: title icon: icon [ self _WM_SetCaption :title _stringValue :icon _stringValue ] SDL _WM_SetCaption :title :icon { SDL_WM_SetCaption((char *) v_title, (char *) v_icon); } SDL flip [ self _flip: _screen ] SDL _flip: screen { SDL_Flip((SDL_Surface *)v_screen); } SDL delay: millisecond [ self _delay: millisecond _integerValue ] SDL _delay: millisecond { SDL_Delay((int)v_millisecond); } "---------- Event ----------" SDL waitEvent [ | name a b c d | { SDL_Event event; SDL_WaitEvent(&event); v_name = v_nil; switch (event.type) { case SDL_QUIT : v_name = s_quitEvent; break; case SDL_KEYDOWN : v_name = s_keyDownEvent; v_a = (oop)(long) event.key.keysym.unicode; v_b = (oop) event.key.keysym.sym; v_c = (oop) event.key.keysym.mod; break; case SDL_MOUSEBUTTONDOWN : v_name = s_pointerDownEvent; v_c = (oop)(long) event.button.x; v_d = (oop)(long) event.button.y; break; case SDL_MOUSEBUTTONUP : v_name = s_pointerUpEvent; v_c = (oop)(long) event.button.x; v_d = (oop)(long) event.button.y; break; case SDL_MOUSEMOTION : v_name = s_pointerMotionEvent; v_c = (oop)(long) event.button.x; v_d = (oop)(long) event.button.y; break; case SDL_VIDEORESIZE : v_name = s_resizeEvent; v_c = (oop)(long) event.resize.w; v_d = (oop)(long) event.resize.h; break; case SDL_USEREVENT : v_name = s_tickEvent; break; default: break; } }. ^ self makeEvent: name :a :b :c :d. ] SDL makeEvent: name :a :b :c :d [ name isNil ifTrue: [^ nil]. ^ self perform: name with: (Integer value_: a) with: (Integer value_: b) with: (Integer value_: c) with: (Integer value_: d) ] SDL keyDownEvent :unicode :key :mod :unused [ | event | event := KeyDownEvent new. event position: 0, 0. event ucs4: unicode. event key: key. event state: 0. mod & SDL KMOD_SHIFT ~~ 0 ifTrue: [ event setShiftPressed ]. mod & SDL KMOD_CTRL ~~ 0 ifTrue: [ event setControlPressed ]. mod & SDL KMOD_ALT ~~ 0 ifTrue: [ event setAltPressed ]. mod & SDL KMOD_META ~~ 0 ifTrue: [ event setAltPressed ]. ^event ] SDL pointerDownEvent :state :button :x :y [ ^PointerDownEvent new position: x,y; state: state; button: button; yourself ] SDL pointerUpEvent :state :button :x :y [ ^PointerUpEvent new position: x,y; state: state; button: button; yourself ] SDL pointerMotionEvent :state :unused :x :y [ ^PointerMotionEvent new position: x,y; state: state; yourself ] SDL resizeEvent :state :unused :x :y [ ^ResizeEvent new position: x,y; yourself ] SDL quitEvent :a :b :c :d [ ^QuitEvent new position: 0, 0; yourself ] SDL tickEvent :a :b :c :d [ ^TickEvent new position: 0, 0; yourself ] "---------- Audio ----------" SDL openAudio { Desired.freq= 22050; /* Sampling rate: 22050Hz */ Desired.format= AUDIO_S16LSB; /* 16-bit signed audio */ Desired.channels= 0; /* Mono */ Desired.samples= 8192; /* Buffer size: 8K = 0.37 sec. */ Desired.callback= callback; Desired.userdata= NULL; SDL_OpenAudio(&Desired, &Obtained); SDL_PauseAudio(0); }