Source

pyGAP / game / src / platform / x11 / platform_x11.cpp

Full commit
#include "platform/x11/platform_x11.h"

#include <X11/Xlib.h>

#include "platform/x11/clock.h"
#include "platform/x11/display.h"
#include "renderer/opengl/renderer_opengl.h"
//#include "platform/x11/window_glx.h"
#include "input/x11/keyboard.h"
#include "input/x11/mouse.h"


namespace platform { namespace x11 {


PlatformX11::PlatformX11():
    Platform(),
    display_(::XOpenDisplay(0))
{}


PlatformX11::~PlatformX11()
{}


void PlatformX11::update_key_map()
{
    ::XQueryKeymap(display_, reinterpret_cast< char* >(key_map_));
}


platform::Display* PlatformX11::create_display() {
    return reinterpret_cast< platform::Display* >(new ::platform::x11::Display(display_));
}


void PlatformX11::delete_display(platform::Display* display) {
    delete reinterpret_cast< ::platform::x11::Display* >(display);
}


Renderer* PlatformX11::create_renderer() {
    return reinterpret_cast< Renderer* >(new ::renderer::opengl::RendererOpenGL);
}


void PlatformX11::delete_renderer(Renderer* renderer) {
    delete reinterpret_cast< ::renderer::opengl::RendererOpenGL* >(renderer);
}


platform::Clock* PlatformX11::create_clock() {
    return reinterpret_cast< platform::Clock* >(new ::platform::x11::Clock);
}


void PlatformX11::delete_clock(platform::Clock* clock) {
    delete reinterpret_cast< ::platform::x11::Clock* >(clock);
}


InputDevice* PlatformX11::create_input_device(int type)
{
    //TODO: add parameter to factory to create different types of input devices
    // Returns a keyboard for now
    switch(type)
    {
        case 0:
            return reinterpret_cast< InputDevice* >(new input::x11::Keyboard(display_, key_map_));
        case 1:
            return reinterpret_cast< InputDevice* >(new input::x11::Mouse(display_));
    }
}


void PlatformX11::delete_input_device(InputDevice* input_device)
{
    delete reinterpret_cast< input::InputDevice* >(input_device);
}


} /* namespace x11 */ } /* namespace platform */