Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\kit_memory.cpp":
- #include "_kit_common.hpp"
- //turns something into a void**
- //(this makes some code here easier for me to read)
- #define VPP(_ptr_p) ((void**)(_ptr_p))
- namespace kit {
- size_t numAllocations = 0;
- void* memory::alloc(size_t size){
- void* newHeapMemory = SDL_malloc(size);
- if(newHeapMemory != nullptr) ++numAllocations;
- return newHeapMemory;
- }
- void memory::free(void* ptr_p){
- if(VPP(ptr_p) != nullptr && *VPP(ptr_p) != nullptr){
- --numAllocations;
- SDL_free(*VPP(ptr_p));
- *VPP(ptr_p) = nullptr;
- }
- }
- void* memory::realloc(void* ptr_p, size_t newSize){
- void* ptr_new = nullptr;
- if(VPP(ptr_p) != nullptr){
- ptr_new = SDL_realloc(*VPP(ptr_p), newSize);
- if(ptr_new != nullptr){
- if(*VPP(ptr_p) == nullptr) ++numAllocations;
- *VPP(ptr_p) = ptr_new;
- }
- }
- return ptr_new;
- }
- void* memory::alloc2(size_t size){
- void* newHeapMemory = SDL_malloc(size);
- if(newHeapMemory == nullptr)
- throw PUSH_ERROR("memory::alloc2(): failed to allocate memory");
- ++numAllocations;
- return newHeapMemory;
- }
- void memory::free2(void* ptr_p){
- if( VPP(ptr_p) == nullptr) throw PUSH_ERROR("memory::free2(): ptr_p == nullptr");
- if(*VPP(ptr_p) == nullptr) throw PUSH_ERROR("memory::free2(): *ptr_p == nullptr");
- --numAllocations;
- SDL_free(*VPP(ptr_p));
- *VPP(ptr_p) = nullptr;
- }
- void* memory::realloc2(void* ptr_p, size_t newSize){
- void* ptr_new = nullptr;
- if(VPP(ptr_p) != nullptr){
- ptr_new = SDL_realloc(*VPP(ptr_p), newSize);
- if(ptr_new != nullptr){
- if(*VPP(ptr_p) == nullptr) ++numAllocations; //if memory is new, not realloc'd
- *VPP(ptr_p) = ptr_new;
- }
- } else {
- throw PUSH_ERROR("memory::realloc2(): ptr_p = nullptr");
- }
- if(ptr_new == nullptr)
- throw PUSH_ERROR("memory::realloc2(): failed to reallocate memory");
- return ptr_new;
- }
- size_t memory::getNumAllocations(){
- return numAllocations;
- }
- //currently just a wrapper, but now i can make my own implementation
- //whenever i want, without replacing every call to memset with it
- void* memory::set(void* ptr, s32 value, size_t size){
- if(ptr == nullptr) return nullptr; //now it's safe to pass nullptr :D
- return memset(ptr, value, size);
- }
- void* memory::set2(void* ptr, s32 value, size_t size){
- if(ptr == nullptr) throw PUSH_ERROR("memory::set2(): ptr = nullptr");
- return memset(ptr, value, size);
- }
- void* memory::copy(void* destination, const void* source, size_t size){
- //tbd: maybe make it so that memcpy is only called if dst&src aren't nullptr
- return memcpy(destination, source, size);
- }
- void* memory::copy2(void* destination, const void* source, size_t size){
- if(destination == nullptr) throw PUSH_ERROR("memory::copy2(): destination = nullptr");
- if(source == nullptr) throw PUSH_ERROR("memory::copy2(): source = nullptr");
- return memcpy(destination, source, size);
- }
- }; /* namespace kit */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\kit_Mutex.cpp":
- #include "_kit_common.hpp"
- #define KIT_MUTEX_NULLPTR "internal mutex = nullptr"
- #define KIT_MUTEX_TIMEDOUT "mutex timed out"
- #define MUTEX_PTR ((SDL_mutex*)_mutex_p)
- using namespace kit;
- Mutex::Mutex(){
- _type = KIT_CLASSTYPE_MUTEX;
- _mutex_p = SDL_CreateMutex(); //can't use MUTEX_PTR here
- if(MUTEX_PTR == nullptr)
- throw PUSH_ERRORF("Mutex::Mutex(): \"%s\"", SDL_GetError());
- _valid = true;
- _constructing = false;
- }
- Mutex::~Mutex(){
- if(!_valid) return;
- _valid = false;
- //(destroying a locked mutex will result in undefined behavior!)
- if(MUTEX_PTR != nullptr) SDL_DestroyMutex(MUTEX_PTR);
- _mutex_p = nullptr; //can't use MUTEX_PTR here
- }
- void Mutex::lock(bool locked){
- if(MUTEX_PTR == nullptr)
- throw PUSH_ERROR("Mutex::lock(): " KIT_MUTEX_NULLPTR);
- int result;
- if(locked) result = SDL_LockMutex (MUTEX_PTR);
- else result = SDL_UnlockMutex(MUTEX_PTR);
- if(result < 0){
- throw PUSH_ERRORF("Mutex::lock(): \"%s\"", SDL_GetError());
- } else if(result == SDL_MUTEX_TIMEDOUT){
- throw PUSH_ERROR("Mutex::lock(): " KIT_MUTEX_TIMEDOUT);
- }
- }
- bool Mutex::tryLock(){
- if(MUTEX_PTR == nullptr)
- throw PUSH_ERROR("Mutex::tryLock(): " KIT_MUTEX_NULLPTR);
- int result = SDL_TryLockMutex(MUTEX_PTR);
- if(result < 0) throw PUSH_ERRORF("Mutex::tryLock(): \"%s\"", SDL_GetError());
- return result == 0;
- }
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\kit_Thread.cpp":
- #include "_kit_common.hpp"
- #define KIT_THREAD_NAME _kit_thread_name //(default thread name)
- #define KIT_INVALID_THREAD "invalid Thread" //this should remain a literal
- #define KIT_IS_INVALID_THREAD (!_valid && !_constructing)
- #define THREAD_PTR ((SDL_Thread*)_thread) //only applicable for Thread objects
- namespace kit {
- static const char _kit_thread_name[] = "kit_sdl2 thread";
- //returns whether or not priority of current thread was successfully set
- //may fail if setting priority requires elevated privileges (or at least when
- //setting a higher priority), if it's even allowed at all
- bool Thread_setPriority(s32 priority, bool throwOnFailure){
- SDL_ThreadPriority priority_real;
- switch(priority){
- case THREAD_LOW : priority_real = SDL_THREAD_PRIORITY_LOW; break;
- case THREAD_NORMAL : priority_real = SDL_THREAD_PRIORITY_NORMAL; break;
- case THREAD_HIGH : priority_real = SDL_THREAD_PRIORITY_HIGH; break;
- case THREAD_HIGHEST: priority_real = SDL_THREAD_PRIORITY_TIME_CRITICAL; break;
- default: throw PUSH_ERROR("Thread_setPriority(): invalid thread priority");
- }
- bool success = !(SDL_SetThreadPriority(priority_real)<0);
- if(!success && throwOnFailure)
- throw PUSH_ERROR("Thread_setPriority(): failed to set thread priority");
- return success;
- }
- struct _ThreadOpq {
- ThreadFunction func;
- void* userdata;
- bool outsideCreate; //set after exiting SDL_CreateThreadWithStackSize()
- u8 _padding8;
- u16 _padding16;
- u32 _padding32;
- };
- static s32 ThreadFunctionWrapper(void* data){
- _ThreadOpq* _opq = (_ThreadOpq*)data;
- if(_opq == nullptr) return 0; //should be impossible
- while(!_opq->outsideCreate) SDL_Delay(1); //one of the solutions of all time
- _ThreadOpq opq = *_opq; //make stack copy
- memory::free(&_opq); //free original
- s32 result = 0;
- try {
- if(opq.func) result = opq.func(opq.userdata);
- } catch(const char* errortext){
- SDL_threadID thread_id = SDL_GetThreadID(nullptr);
- const char* thread_name = SDL_GetThreadName(nullptr);
- if(thread_name == nullptr) thread_name = "NAMELESS";
- SDL_Log("ERROR ON THREAD %lu (%s): %s",
- thread_id, thread_name, errortext);
- //i think this outputs to stderr? idk
- SDL_LogError(SDL_LOG_CATEGORY_ERROR,
- "ERROR ON THREAD %lu (%s): %s",
- thread_id, thread_name, errortext);
- freeThreadError();
- }
- return result;
- }
- Thread::Thread(ThreadFunction func, void* userdata,
- bool waitInDestructor, size_t stackSize,
- const char* threadName)
- {
- _type = KIT_CLASSTYPE_THREAD;
- //handle parameters
- if(func == nullptr)
- throw PUSH_ERROR("Thread::Thread(): nullptr was given as ThreadFunction");
- _waitInDestructor = waitInDestructor;
- if(threadName == nullptr) threadName = KIT_THREAD_NAME; //set to default if nullptr
- _ThreadOpq* opq = (_ThreadOpq*)memory::alloc(sizeof(_ThreadOpq));
- if(opq == nullptr)
- throw PUSH_ERROR("Thread::Thread(): failed to allocate memory for Thread's opaque struct");
- memset(opq, 0, sizeof(_ThreadOpq));
- opq->func = func;
- opq->userdata = userdata;
- //(can't use THREAD_PTR on lvalue)
- _thread = (GenOpqPtr)SDL_CreateThreadWithStackSize(ThreadFunctionWrapper,
- threadName, stackSize, opq);
- opq->outsideCreate = true;
- if(THREAD_PTR == nullptr){
- memory::free(&opq);
- throw PUSH_ERRORF("Thread::Thread(): \"%s\"", SDL_GetError());
- }
- _valid = true;
- _constructing = false;
- }
- Thread::~Thread(){
- if(!_valid) return;
- _valid = false;
- if(THREAD_PTR != nullptr){
- if(_waitInDestructor && !_detached)
- SDL_WaitThread(THREAD_PTR, nullptr); //cleans up memory too
- else if(!_detached)
- SDL_DetachThread(THREAD_PTR);
- }
- }
- //returns ID of current thread instead if thread is nullptr
- u32 Thread::getID(){
- if(KIT_IS_INVALID_THREAD)
- throw PUSH_ERROR("Thread::getID(): " KIT_INVALID_THREAD);
- return SDL_GetThreadID((SDL_Thread*)_thread);
- }
- //returns UTF-8 string, or nullptr if thread doesn't have a name
- const char* Thread::getName(){
- if(KIT_IS_INVALID_THREAD)
- throw PUSH_ERROR("Thread::getName(): " KIT_INVALID_THREAD);
- return SDL_GetThreadName(THREAD_PTR);
- }
- s32 Thread::waitUntilDone(){
- if(KIT_IS_INVALID_THREAD)
- throw PUSH_ERROR("Thread::waitUntilDone(): " KIT_INVALID_THREAD);
- s32 returnStatus = 0;
- if(!_detached) SDL_WaitThread((SDL_Thread*)_thread, &returnStatus);
- return returnStatus;
- }
- void Thread::detach(){
- if(KIT_IS_INVALID_THREAD)
- throw PUSH_ERROR("Thread::detach(): " KIT_INVALID_THREAD);
- if(!_detached){
- SDL_DetachThread(THREAD_PTR);
- _detached = true;
- }
- }
- }; /* namespace kit */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\kit_time.cpp":
- #include "_kit_common.hpp"
- namespace kit {
- timerID timerAdd(timerCallback func, u32 interval_ms, void* userdata){
- if(!_gl.init.timer) throw PUSH_ERROR("timerAdd(): timer subsystem is uninitialized");
- timerID id_new = SDL_AddTimer(interval_ms, func, userdata);
- if(!id_new) throw PUSH_ERRORF("timerAdd(): \"%s\"", SDL_GetError());
- else return id_new;
- }
- void timerRemove(timerID id){
- if(!_gl.init.timer) throw PUSH_ERROR("timerRemove(): timer subsystem is uninitialized");
- bool success = SDL_RemoveTimer(id);
- if(!success) throw PUSH_ERRORF("timerRemove(): \"%s\"", SDL_GetError());
- }
- u64 time::getTicks(){
- return SDL_GetPerformanceCounter();
- }
- u64 time::getTicksPerSecond(){
- if(!_gl.performanceFreq)
- _gl.performanceFreq = SDL_GetPerformanceFrequency();
- return _gl.performanceFreq;
- }
- u64 time::getMS(){
- return SDL_GetTicks64();
- }
- u32 time::getMS_32(){
- return SDL_GetTicks();
- }
- f64 time::getSeconds(){
- return (f64)SDL_GetTicks64()/1000;
- }
- void time::sleep(u32 milliseconds){
- SDL_Delay(milliseconds);
- }
- }; /* namespace kit */
- /******************************************************************************/
- /******************************************************************************/
- //"ksdl2\src\kit_sdl2\kit_Window.cpp":
- #include "_kit_common.hpp"
- #define WIN_PTR ((SDL_Window*)_win)
- #define KIT_WIN_IS_INVALID (!_valid && !_constructing)
- #define KIT_WIN_CHECK_INVALID(_funcname) \
- if(KIT_WIN_IS_INVALID) throw PUSH_ERROR(_funcname ": window is invalid");
- #define WIN_DATA_NAME "Window class"
- namespace kit {
- /* functions to potentially maybe incorporate:
- SDL_GetWindowBordersSize
- SDL_GetWindowSurface
- SDL_GetWindowGammaRamp
- SDL_SetWindowGammaRamp
- SDL_SetWindowHitTest
- SDL_SetWindowShape
- SDL_UpdateWindowSurface
- SDL_UpdateWindowSurfaceRects
- SDL_IsShapedWindow
- SDL_SetWindowModalFor
- SDL_SetWindowIcon
- */
- #define VALID_WINFLAGS ( \
- WINFLAG_FULLSCREEN | \
- WINFLAG_OPENGL | \
- WINFLAG_HIDDEN | \
- WINFLAG_BORDERLESS | \
- WINFLAG_RESIZABLE | \
- WINFLAG_MINIMIZED | \
- WINFLAG_MAXIMIZED | \
- WINFLAG_INPUT_GRABBED | \
- WINFLAG_FULLSCREEN_DESKTOP | \
- WINFLAG_VULKAN \
- )
- Window::Window(const char* winTitle,
- s32 winWidth, s32 winHeight,
- u32 winFlags,
- s32 winX, s32 winY)
- {
- _type = KIT_CLASSTYPE_WINDOW;
- if(winWidth < 0) throw PUSH_ERROR("Window::Window(): winWidth < 0");
- if(winHeight < 0) throw PUSH_ERROR("Window::Window(): winHeight < 0");
- _win = SDL_CreateWindow(winTitle, winX, winY,
- winWidth, winHeight,
- winFlags & VALID_WINFLAGS);
- if(_win == nullptr)
- throw PUSH_ERRORF("Window::Window(): \"%s\"", SDL_GetError());
- SDL_SetWindowData(WIN_PTR, WIN_DATA_NAME, this);
- _valid = true;
- _constructing = false;
- }
- Window::~Window(){
- if(!_valid) return;
- _valid = false;
- if(_win != nullptr){
- SDL_DestroyWindow(WIN_PTR);
- _win = nullptr;
- }
- }
- bool Window::hasSurface(){
- KIT_WIN_CHECK_INVALID("Window::hasSurface()");
- return SDL_HasWindowSurface(WIN_PTR);
- }
- u32 Window::getPixelFormat(){
- KIT_WIN_CHECK_INVALID("Window::getPixelFormat()");
- u32 pixelFormat = SDL_GetWindowPixelFormat(WIN_PTR);
- if(pixelFormat == SDL_PIXELFORMAT_UNKNOWN)
- throw PUSH_ERRORF("Window::getPixelFormat(): \"%s\"", SDL_GetError());
- return pixelFormat;
- }
- u32 Window::getID(){
- KIT_WIN_CHECK_INVALID("Window::getID()");
- u32 id = SDL_GetWindowID(WIN_PTR);
- if(!id) throw PUSH_ERRORF("Window::getID(): \"%s\"", SDL_GetError());
- return id;
- }
- u32 Window::getDisplayIndex(){
- KIT_WIN_CHECK_INVALID("Window::getDisplayIndex()");
- s32 index = SDL_GetWindowDisplayIndex(WIN_PTR);
- if(index < 0)
- throw PUSH_ERRORF("Window::getDisplayIndex(): \"%s\"", SDL_GetError());
- return (u32)index;
- }
- void* Window::getUserdata(const char* name){
- KIT_WIN_CHECK_INVALID("Window::getUserdata()");
- if(name == nullptr)
- throw PUSH_ERROR("Window::getUserdata(): name = nullptr");
- return SDL_GetWindowData(WIN_PTR, name);
- }
- DisplayMode Window::getDisplayMode(){
- KIT_WIN_CHECK_INVALID("Window::getDisplayMode()");
- SDL_DisplayMode mode_sdl;
- if(SDL_GetWindowDisplayMode(WIN_PTR, &mode_sdl) < 0)
- throw PUSH_ERRORF("Window::getDisplayMode(): \"%s\"", SDL_GetError());
- DisplayMode mode_kit;
- mode_kit.pixelFmt = mode_sdl.format;
- mode_kit.w = mode_sdl.w;
- mode_kit.h = mode_sdl.h;
- mode_kit.refreshRate = mode_sdl.refresh_rate;
- return mode_kit;
- }
- const char* Window::getTitle(){
- KIT_WIN_CHECK_INVALID("Window::getTitle()");
- return SDL_GetWindowTitle(WIN_PTR);
- }
- shape::point Window::getSize(){
- KIT_WIN_CHECK_INVALID("Window::getSize()");
- shape::point size;
- SDL_GetWindowSize(WIN_PTR, &size.x, &size.y);
- return size;
- }
- u32 Window::getFlags(){
- KIT_WIN_CHECK_INVALID("Window::getFlags()");
- return SDL_GetWindowFlags(WIN_PTR);
- }
- f32 Window::getOpacity(){
- KIT_WIN_CHECK_INVALID("Window::getOpacity()");
- f32 opacity;
- if(SDL_GetWindowOpacity(WIN_PTR, &opacity) < 0)
- throw PUSH_ERRORF("Window::getOpacity(): \"%s\"", SDL_GetError());
- return opacity;
- }
- shape::point Window::getMinSize(){
- KIT_WIN_CHECK_INVALID("Window::getMinSize()");
- shape::point minSize;
- SDL_GetWindowMinimumSize(WIN_PTR, &minSize.x, &minSize.y);
- return minSize;
- }
- shape::point Window::getMaxSize(){
- KIT_WIN_CHECK_INVALID("Window::getMaxSize()");
- shape::point maxSize;
- SDL_GetWindowMaximumSize(WIN_PTR, &maxSize.x, &maxSize.y);
- return maxSize;
- }
- shape::point Window::getPosition(){
- KIT_WIN_CHECK_INVALID("Window::getPosition()");
- shape::point pos;
- SDL_GetWindowPosition(WIN_PTR, &pos.x, &pos.y);
- return pos;
- }
- bool Window::getGrab(){
- KIT_WIN_CHECK_INVALID("Window::getGrab()");
- return SDL_GetWindowGrab(WIN_PTR);
- }
- bool Window::getKeyboardGrab(){
- KIT_WIN_CHECK_INVALID("Window::getKeyboardGrab()");
- return SDL_GetWindowKeyboardGrab(WIN_PTR);
- }
- bool Window::getMouseGrab(){
- KIT_WIN_CHECK_INVALID("Window::getMouseGrab()");
- return SDL_GetWindowMouseGrab(WIN_PTR);
- }
- shape::rect Window::getMouseGrabRect(){
- KIT_WIN_CHECK_INVALID("Window::getMouseGrabRect()");
- const SDL_Rect* _rect = SDL_GetWindowMouseRect(WIN_PTR);
- shape::rect rect;
- if(_rect != nullptr){
- rect.x = _rect->x;
- rect.y = _rect->y;
- rect.w = _rect->w;
- rect.h = _rect->h;
- } else { //no rect set; use full window
- shape::point winSize = getSize();
- rect.x = 0;
- rect.y = 0;
- rect.w = winSize.x;
- rect.h = winSize.y;
- }
- return rect;
- }
- f32 Window::getBrightness(){
- KIT_WIN_CHECK_INVALID("Window::getBrightness()");
- return SDL_GetWindowBrightness(WIN_PTR);
- }
- void* Window::setUserdata(const char* name, void* userdata){
- KIT_WIN_CHECK_INVALID("Window::setUserdata()");
- if(name == nullptr)
- throw PUSH_ERROR("Window::setUserdata(): name = nullptr");
- if(!strnCmp(WIN_DATA_NAME, name))
- throw PUSH_ERROR("Window::setUserdata(): name = \"" WIN_DATA_NAME "\"");
- return SDL_SetWindowData(WIN_PTR, name, userdata);
- }
- void Window::setDisplayMode(const DisplayMode* mode){
- KIT_WIN_CHECK_INVALID("Window::setDisplayMode()");
- SDL_DisplayMode mode_sdl;
- if(mode != nullptr){
- mode_sdl.format = mode->pixelFmt;
- mode_sdl.w = mode->w;
- mode_sdl.h = mode->h;
- mode_sdl.refresh_rate = mode->refreshRate;
- }
- if(SDL_SetWindowDisplayMode(WIN_PTR, (mode) ? &mode_sdl : nullptr) < 0)
- throw PUSH_ERRORF("Window::setDisplayMode(): \"%s\"", SDL_GetError());
- }
- void Window::setTitle(const char* title){
- KIT_WIN_CHECK_INVALID("Window::setTitle()");
- SDL_SetWindowTitle(WIN_PTR, title);
- }
- void Window::setSize(s32 width, s32 height){
- KIT_WIN_CHECK_INVALID("Window::setSize()");
- if(width < 0) throw PUSH_ERROR("Window::setSize(): width < 0");
- if(height < 0) throw PUSH_ERROR("Window::setSize(): height < 0");
- SDL_SetWindowSize(WIN_PTR, width, height);
- }
- void Window::setVisibility(bool visible){
- KIT_WIN_CHECK_INVALID("Window::setVisibility()");
- if(visible) SDL_ShowWindow(WIN_PTR);
- else SDL_HideWindow(WIN_PTR);
- }
- void Window::setFullscreen(u32 mode){
- KIT_WIN_CHECK_INVALID("Window::setFullscreen()");
- u32 flags = 0;
- if (mode == 1) flags = SDL_WINDOW_FULLSCREEN;
- else if(mode == 2) flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
- if(SDL_SetWindowFullscreen(WIN_PTR, flags) < 0)
- throw PUSH_ERRORF("Window::setFullscreen(): \"%s\"", SDL_GetError());
- }
- void Window::setResizable(bool enable){
- KIT_WIN_CHECK_INVALID("Window::setResizable()");
- SDL_SetWindowResizable(WIN_PTR, (SDL_bool)enable);
- }
- void Window::setBordered(bool enable){
- KIT_WIN_CHECK_INVALID("Window::setBordered()");
- SDL_SetWindowBordered(WIN_PTR, (SDL_bool)enable);
- }
- void Window::setAlwaysOnTop(bool enable){
- KIT_WIN_CHECK_INVALID("Window::setAlwaysOnTop()");
- SDL_SetWindowAlwaysOnTop(WIN_PTR, (SDL_bool)enable);
- }
- void Window::setOpacity(f32 opacity){
- KIT_WIN_CHECK_INVALID("Window::setOpacity()");
- if(SDL_SetWindowOpacity(WIN_PTR, opacity) < 0)
- throw PUSH_ERRORF("Window::setOpacity(): \"%s\"", SDL_GetError());
- }
- void Window::setMinSize(s32 minWidth, s32 minHeight){
- KIT_WIN_CHECK_INVALID("Window::setMinSize()");
- if(minWidth < 0) throw PUSH_ERROR("Window::setMinSize(): minWidth < 0");
- if(minHeight < 0) throw PUSH_ERROR("Window::setMinSize(): minHeight < 0");
- SDL_SetWindowMinimumSize(WIN_PTR, minWidth, minHeight);
- }
- void Window::setMaxSize(s32 maxWidth, s32 maxHeight){
- KIT_WIN_CHECK_INVALID("Window::setMaxSize()");
- if(maxWidth < 0) throw PUSH_ERROR("Window::setMaxSize(): maxWidth < 0");
- if(maxHeight < 0) throw PUSH_ERROR("Window::setMaxSize(): maxHeight < 0");
- SDL_SetWindowMaximumSize(WIN_PTR, maxWidth, maxHeight);
- }
- void Window::setPosition(s32 x, s32 y){
- KIT_WIN_CHECK_INVALID("Window::setPosition()");
- SDL_SetWindowPosition(WIN_PTR, x, y);
- }
- void Window::setGrab(bool enable){
- KIT_WIN_CHECK_INVALID("Window::setGrab()");
- SDL_SetWindowGrab(WIN_PTR, (SDL_bool)enable);
- }
- void Window::setKeyboardGrab(bool enable){
- KIT_WIN_CHECK_INVALID("Window::setKeyboardGrab()");
- SDL_SetWindowKeyboardGrab(WIN_PTR, (SDL_bool)enable);
- }
- void Window::setMouseGrab(bool enable){
- KIT_WIN_CHECK_INVALID("Window::setMouseGrab()");
- SDL_SetWindowMouseGrab(WIN_PTR, (SDL_bool)enable);
- }
- void Window::setMouseGrabRect(const shape::rect* rect){
- KIT_WIN_CHECK_INVALID("Window::setMouseGrabRect()");
- if(SDL_SetWindowMouseRect(WIN_PTR, (const SDL_Rect*)rect) < 0)
- throw PUSH_ERRORF("Window::setMouseGrabRect(): \"%s\"", SDL_GetError());
- }
- void Window::setBrightness(f32 brightness){
- KIT_WIN_CHECK_INVALID("Window::setBrightness()");
- if(SDL_SetWindowBrightness(WIN_PTR, brightness) < 0)
- throw PUSH_ERRORF("Window::setBrightness(): \"%s\"", SDL_GetError());
- }
- void Window::warpMouse(s32 x, s32 y){
- KIT_WIN_CHECK_INVALID("Window::warpMouse()");
- SDL_WarpMouseInWindow(WIN_PTR, x, y);
- }
- void Window::minimize(){
- KIT_WIN_CHECK_INVALID("Window::minimize()");
- SDL_MinimizeWindow(WIN_PTR);
- }
- void Window::maximize(){
- KIT_WIN_CHECK_INVALID("Window::maximize()");
- SDL_MaximizeWindow(WIN_PTR);
- }
- void Window::restore(){
- KIT_WIN_CHECK_INVALID("Window::restore()");
- SDL_RestoreWindow(WIN_PTR);
- }
- void Window::raise(){
- KIT_WIN_CHECK_INVALID("Window::raise()");
- SDL_RaiseWindow(WIN_PTR);
- }
- Window* getGrabbedWindow(){ //not a part of Window
- SDL_Window* win_sdl = SDL_GetGrabbedWindow();
- if(win_sdl == nullptr) return nullptr;
- return (Window*)SDL_GetWindowData(win_sdl, WIN_DATA_NAME);
- }
- }; /* namespace kit */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement