emu_window_sdl2.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <utility>
  7. #include "core/frontend/emu_window.h"
  8. struct SDL_Window;
  9. class EmuWindow_SDL2 : public Core::Frontend::EmuWindow {
  10. public:
  11. explicit EmuWindow_SDL2(bool fullscreen);
  12. ~EmuWindow_SDL2();
  13. /// Swap buffers to display the next frame
  14. void SwapBuffers() override;
  15. /// Polls window events
  16. void PollEvents() override;
  17. /// Makes the graphics context current for the caller thread
  18. void MakeCurrent() override;
  19. /// Releases the GL context from the caller thread
  20. void DoneCurrent() override;
  21. std::unique_ptr<Core::Frontend::GraphicsContext> CreateSharedContext() const override;
  22. /// Whether the window is still open, and a close request hasn't yet been sent
  23. bool IsOpen() const;
  24. private:
  25. /// Called by PollEvents when a key is pressed or released.
  26. void OnKeyEvent(int key, u8 state);
  27. /// Called by PollEvents when the mouse moves.
  28. void OnMouseMotion(s32 x, s32 y);
  29. /// Called by PollEvents when a mouse button is pressed or released
  30. void OnMouseButton(u32 button, u8 state, s32 x, s32 y);
  31. /// Translates pixel position (0..1) to pixel positions
  32. std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const;
  33. /// Called by PollEvents when a finger starts touching the touchscreen
  34. void OnFingerDown(float x, float y);
  35. /// Called by PollEvents when a finger moves while touching the touchscreen
  36. void OnFingerMotion(float x, float y);
  37. /// Called by PollEvents when a finger stops touching the touchscreen
  38. void OnFingerUp();
  39. /// Called by PollEvents when any event that may cause the window to be resized occurs
  40. void OnResize();
  41. /// Called when user passes the fullscreen parameter flag
  42. void Fullscreen();
  43. /// Whether the GPU and driver supports the OpenGL extension required
  44. bool SupportsRequiredGLExtensions();
  45. /// Called when a configuration change affects the minimal size of the window
  46. void OnMinimalClientAreaChangeRequest(
  47. const std::pair<unsigned, unsigned>& minimal_size) override;
  48. /// Is the window still open?
  49. bool is_open = true;
  50. /// Internal SDL2 render window
  51. SDL_Window* render_window;
  52. using SDL_GLContext = void*;
  53. /// The OpenGL context associated with the window
  54. SDL_GLContext gl_context;
  55. };