// Copyright (C) 2014-2015 ChaosForge Ltd // http://chaosforge.org/ // // This file is part of Nova libraries. // For conditions of distribution and use, see copying.txt file in root folder. #include "nv/sdl/sdl_window_manager.hh" #include "nv/sdl/sdl_window.hh" #include "nv/core/logging.hh" #include "nv/lib/sdl.hh" #include "nv/lib/sdl_image.hh" #include "nv/interface/image_data.hh" using namespace nv; sdl::window_manager::window_manager() { primal_window = nullptr; nv::load_sdl_library(); if ( SDL_Init(0) < 0 ) { NV_LOG_CRITICAL( "SDL initialization failed: ", SDL_GetError( ) ); return; // TODO: Error report } } window* sdl::window_manager::create_window( device* dev, uint16 width, uint16 height, bool fullscreen, bool msaa ) { if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO ); sdl::window* result = new sdl::window( dev, width, height, fullscreen, msaa ); primal_window = result->get_handle(); return result; } void* sdl::window_manager::adopt_window( void* sys_w_handle ) { if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO ); if ( primal_window ) { char buffer[128]; sprintf( buffer, "%p", primal_window ); SDL_bool result = SDL_SetHint( "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT", buffer ); NV_UNUSED( result ); NV_ASSERT( result == SDL_TRUE, "SetHint failed!" ); } primal_window = SDL_CreateWindowFrom( sys_w_handle ); return primal_window; } void nv::sdl::window_manager::sleep( uint32 ms ) { SDL_Delay( ms ); } nv::uint32 nv::sdl::window_manager::get_ticks() { return SDL_GetTicks(); } nv::sdl::window_manager::~window_manager() { SDL_Quit(); }