-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from outlandkarasu/62-add-window
close #62 add window
- Loading branch information
Showing
9 changed files
with
284 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/** | ||
Events module. | ||
*/ | ||
module warabe.sdl.events; | ||
|
||
import sdl = bindbc.sdl; | ||
import bindbc.sdl : SDL_PollEvent; | ||
|
||
alias Event = sdl.SDL_Event; | ||
alias CommonEvent = sdl.SDL_CommonEvent; | ||
alias WindowEvent = sdl.SDL_WindowEvent; | ||
alias KeyboardEvent = sdl.SDL_KeyboardEvent; | ||
alias TextEditingEvent = sdl.SDL_TextEditingEvent; | ||
alias TextInputEvent = sdl.SDL_TextInputEvent; | ||
alias MouseMotionEvent = sdl.SDL_MouseMotionEvent; | ||
alias MouseButtonEvent = sdl.SDL_MouseButtonEvent; | ||
alias MouseWheelEvent = sdl.SDL_MouseWheelEvent; | ||
alias JoyAxisEvent = sdl.SDL_JoyAxisEvent; | ||
alias JoyBallEvent = sdl.SDL_JoyBallEvent; | ||
alias JoyHatEvent = sdl.SDL_JoyHatEvent; | ||
alias JoyButtonEvent = sdl.SDL_JoyButtonEvent; | ||
alias JoyDeviceEvent = sdl.SDL_JoyDeviceEvent; | ||
alias ControllerAxisEvent = sdl.SDL_ControllerAxisEvent; | ||
alias ControllerButtonEvent = sdl.SDL_ControllerButtonEvent; | ||
alias ControllerDeviceEvent = sdl.SDL_ControllerDeviceEvent; | ||
alias QuitEvent = sdl.SDL_QuitEvent; | ||
alias UserEvent = sdl.SDL_UserEvent; | ||
alias SysWMEvent = sdl.SDL_SysWMEvent; | ||
alias TouchFingerEvent = sdl.SDL_TouchFingerEvent; | ||
alias MultiGestureEvent = sdl.SDL_MultiGestureEvent; | ||
alias DollarGestureEvent = sdl.SDL_DollarGestureEvent; | ||
|
||
/** | ||
SDL event type enum. | ||
*/ | ||
enum EventType : sdl.SDL_EventType | ||
{ | ||
firstEvent = sdl.SDL_FIRSTEVENT, | ||
quit = sdl.SDL_QUIT, | ||
|
||
appTerminating = sdl.SDL_APP_TERMINATING, | ||
appLowMemory = sdl.SDL_APP_LOWMEMORY, | ||
appWillEnterBackground = sdl.SDL_APP_WILLENTERBACKGROUND, | ||
appDidEnterBackground = sdl.SDL_APP_DIDENTERBACKGROUND, | ||
appWillEnterForeground = sdl.SDL_APP_WILLENTERFOREGROUND, | ||
appDidEnterForeground = sdl.SDL_APP_DIDENTERFOREGROUND, | ||
|
||
windowEvent = sdl.SDL_WINDOWEVENT, | ||
sysWMEvent = sdl.SDL_SYSWMEVENT, | ||
|
||
keyDown = sdl.SDL_KEYDOWN, | ||
keyUp = sdl.SDL_KEYUP, | ||
textEditing = sdl.SDL_TEXTEDITING, | ||
textInput = sdl.SDL_TEXTINPUT, | ||
|
||
mouseMotion = sdl.SDL_MOUSEMOTION, | ||
mouseButtonDown = sdl.SDL_MOUSEBUTTONDOWN, | ||
mouseButtonUp = sdl.SDL_MOUSEBUTTONUP, | ||
mouseWheel = sdl.SDL_MOUSEWHEEL, | ||
|
||
joyAxisMotion = sdl.SDL_JOYAXISMOTION, | ||
joyBallMotion = sdl.SDL_JOYBALLMOTION, | ||
joyHatMotion = sdl.SDL_JOYHATMOTION, | ||
joyButtonDown = sdl.SDL_JOYBUTTONDOWN, | ||
joyButtonUp = sdl.SDL_JOYBUTTONUP, | ||
joyDeviceAdded = sdl.SDL_JOYDEVICEADDED, | ||
joyDeviceRemoved = sdl.SDL_JOYDEVICEREMOVED, | ||
|
||
controllerAxisMotion = sdl.SDL_CONTROLLERAXISMOTION, | ||
controllerButtonDown = sdl.SDL_CONTROLLERBUTTONDOWN, | ||
controllerButtonUp = sdl.SDL_CONTROLLERBUTTONUP, | ||
controllerDeviceAdded = sdl.SDL_CONTROLLERDEVICEADDED, | ||
controllerDeviceRemoved = sdl.SDL_CONTROLLERDEVICEREMOVED, | ||
controllerDeviceRemapped = sdl.SDL_CONTROLLERDEVICEREMAPPED, | ||
fingerDown = sdl.SDL_FINGERDOWN, | ||
fingerUp = sdl.SDL_FINGERUP, | ||
fingerMotion = sdl.SDL_FINGERMOTION, | ||
|
||
dollarGesture = sdl.SDL_DOLLARGESTURE, | ||
dollarRecord = sdl.SDL_DOLLARRECORD, | ||
multiGesture = sdl.SDL_MULTIGESTURE, | ||
|
||
clipBoardUpdate = sdl.SDL_CLIPBOARDUPDATE, | ||
|
||
userEvent = sdl.SDL_USEREVENT, | ||
lastEvent = sdl.SDL_LASTEVENT, | ||
} | ||
|
||
/** | ||
poll event. | ||
Params: | ||
event = filled event | ||
Returns: | ||
true if there is a pending event. | ||
*/ | ||
bool pollEvent(out Event event) @nogc nothrow | ||
{ | ||
return SDL_PollEvent(&event) == 1; | ||
} | ||
|
||
/** | ||
poll event. | ||
Returns: | ||
true if there is a pending event. | ||
*/ | ||
bool pollEvent() @nogc nothrow | ||
{ | ||
return SDL_PollEvent(null) == 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
Timer module. | ||
*/ | ||
module warabe.sdl.timer; | ||
|
||
import bindbc.sdl : SDL_Delay; | ||
|
||
/** | ||
Delay timer. | ||
Params: | ||
ms = milliseconds. | ||
*/ | ||
void delay(uint ms) @nogc nothrow | ||
{ | ||
SDL_Delay(ms); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
Window module. | ||
*/ | ||
module warabe.sdl.window; | ||
|
||
import bindbc.sdl : | ||
SDL_CreateWindow, | ||
SDL_DestroyWindow; | ||
|
||
import bindbc.sdl : | ||
SDL_WINDOW_FULLSCREEN, | ||
SDL_WINDOW_FULLSCREEN_DESKTOP, | ||
SDL_WINDOW_OPENGL, | ||
SDL_WINDOW_HIDDEN, | ||
SDL_WINDOW_BORDERLESS, | ||
SDL_WINDOW_RESIZABLE, | ||
SDL_WINDOW_MINIMIZED, | ||
SDL_WINDOW_MAXIMIZED, | ||
SDL_WINDOW_INPUT_GRABBED, | ||
SDL_WINDOW_SHOWN; | ||
|
||
import bindbc.sdl : | ||
SDL_WINDOWPOS_CENTERED, | ||
SDL_WINDOWPOS_UNDEFINED; | ||
|
||
import bindbc.sdl : | ||
SDL_Window, | ||
SDL_WindowFlags, | ||
Uint32; | ||
|
||
/** | ||
Window type. | ||
*/ | ||
alias Window = SDL_Window; | ||
|
||
/** | ||
Window flags. | ||
*/ | ||
enum WindowFlags : SDL_WindowFlags | ||
{ | ||
fullscrenn = SDL_WINDOW_FULLSCREEN, | ||
fullscreenDesktop = SDL_WINDOW_FULLSCREEN_DESKTOP, | ||
openGL = SDL_WINDOW_OPENGL, | ||
hidden = SDL_WINDOW_HIDDEN, | ||
borderless = SDL_WINDOW_BORDERLESS, | ||
resizable = SDL_WINDOW_RESIZABLE, | ||
minimized = SDL_WINDOW_MINIMIZED, | ||
maximized = SDL_WINDOW_MAXIMIZED, | ||
inputGrabbed = SDL_WINDOW_INPUT_GRABBED, | ||
shown = SDL_WINDOW_SHOWN, | ||
} | ||
|
||
/** | ||
Window position constants. | ||
*/ | ||
enum WindowPos : int | ||
{ | ||
centered = SDL_WINDOWPOS_CENTERED, | ||
undefined = SDL_WINDOWPOS_UNDEFINED, | ||
} | ||
|
||
/** | ||
Create a window. | ||
Params: | ||
tile = window title. | ||
x = window position x. | ||
y = window position y. | ||
w = window width. | ||
h = window height. | ||
flags = window flags. | ||
*/ | ||
Window* createWindow( | ||
scope const(char)* title, | ||
int x, | ||
int y, | ||
int w, | ||
int h, | ||
WindowFlags flags) @nogc nothrow | ||
{ | ||
return SDL_CreateWindow(title, x, y, w, h, flags); | ||
} | ||
|
||
/** | ||
Destroy window. | ||
Params: | ||
window = destroy window and clear pointer. | ||
*/ | ||
void destroyWindow(scope ref Window* window) @nogc nothrow | ||
{ | ||
SDL_DestroyWindow(window); | ||
window = null; | ||
} | ||
|