X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fscreen.cpp;h=9ee15b49dc1b2dd9f679d015aee780ea4468fd72;hp=6909be2acaa73c7be81148029a594d5135a93e1c;hb=b0c05b83db47aa91cb2da4244f1401aaf2c41ba0;hpb=245ccc8576d4bd29ab04d506ddb0c44b04a67e39 diff --git a/src/screen.cpp b/src/screen.cpp index 6909be2..9ee15b4 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -18,6 +18,8 @@ Screen::Screen() } m_gl_context = SDL_GL_CreateContext(m_window); + + ResizeViewport(800, 600); } @@ -55,6 +57,29 @@ bool Screen::PumpEvents() break; } break; + case SDL_MOUSEMOTION: + m_last_mouse_x = evt.motion.x; + m_last_mouse_y = evt.motion.y; + if (m_mouse_handler) + { + m_mouse_handler(evt.motion.x, evt.motion.y,evt.motion.state, 0); + } + break; + case SDL_MOUSEBUTTONDOWN: + case SDL_MOUSEBUTTONUP: + m_last_mouse_x = evt.button.x; + m_last_mouse_y = evt.button.y; + if (m_mouse_handler) + { + m_mouse_handler(evt.button.x, evt.button.y, evt.button.state, 0); + } + break; + case SDL_MOUSEWHEEL: + if (m_mouse_handler) + { + m_mouse_handler(m_last_mouse_x, m_last_mouse_y, 0, evt.wheel.y); + } + break; default: break; } @@ -62,6 +87,23 @@ bool Screen::PumpEvents() return no_quit_requested; } +void Screen::SetMouseCursor(Screen::MouseCursors cursor) +{ + SDL_SystemCursor system_cursor_id = SDL_SYSTEM_CURSOR_ARROW; + switch (cursor) + { + case CursorArrow: system_cursor_id = SDL_SYSTEM_CURSOR_ARROW; break; + case CursorWait: system_cursor_id = SDL_SYSTEM_CURSOR_WAIT; break; + case CursorWaitArrow: system_cursor_id = SDL_SYSTEM_CURSOR_WAITARROW; break; + case CursorMove: system_cursor_id = SDL_SYSTEM_CURSOR_SIZEALL; break; + case CursorHand: system_cursor_id = SDL_SYSTEM_CURSOR_HAND; break; + default: break; + } + SDL_Cursor *system_cursor = SDL_CreateSystemCursor(system_cursor_id); + SDL_SetCursor(system_cursor); + //TODO: Check if we need to free the system cursors. +} + void Screen::Present() { SDL_GL_SwapWindow(m_window);