kick
/Users/morten/Programmering/cpp/kick/src/kick/context/sdl2_context.h
00001 //
00002 //  SDL2_Context.h
00003 //  KickCPP
00004 //
00005 //  Created by morten on 8/10/13.
00006 //  Copyright (c) 2013 Morten Nobel-Joergensen. All rights reserved.
00007 //
00008 
00009 #pragma once
00010 #include "context.h"
00011 
00012 
00013 #if defined(EMSCRIPTEN)
00014 #   include <emscripten.h>
00015 #   include <SDL/SDL.h>
00016 #   include <SDL/SDL_image.h>
00017 #elif defined(_WIN32)
00018 #   define SDL_MAIN_HANDLED
00019 #   include <SDL.h>
00020 #else
00021 #   define SDL_MAIN_HANDLED
00022 #   include <SDL2/SDL.h>
00023 #endif
00024 
00025 namespace kick {
00026     class SDL2Context : public Context {
00027     public:
00028         SDL2Context();
00029         SDL2Context(const SDL2Context&) = delete;
00030         virtual ~SDL2Context();
00031         virtual bool init(int &argc, char **argv) override;
00032         virtual bool showWindow(const WindowConfig& config = WindowConfig::plain)  override;
00033         virtual void swapBuffer() override;
00034         virtual void mainLoop()  override;
00035         std::string getBasePath();
00036 
00037         virtual bool isFullscreen() override;
00038 
00039         virtual void setFullscreen(bool fullscreen) override;
00040 
00041         virtual void setWindowTitle(std::string title) override;
00042 
00043         virtual std::string getWindowTitle() override;
00044 
00045         void step();
00046         bool tick();
00047     private:
00048         void handleMouseMotion(SDL_MouseMotionEvent event);
00049         void handleMouseButton(SDL_MouseButtonEvent event, bool buttonDown);
00050         void handleMouseWheel(SDL_MouseWheelEvent event);
00051         void handleKey(SDL_KeyboardEvent event, bool keyDown);
00052         void handleTouch(SDL_TouchFingerEvent event);
00053         Uint32 timeLeft();
00054         Uint32 nextTime;
00055         Uint32 tickInterval = 16; // 60 fps
00056         SDL_Window *window = nullptr;
00057         SDL_GLContext glContext = nullptr;
00058         std::string basePath;
00059     };
00060 };
 All Classes Functions Variables