[395] | 1 | // Copyright (C) 2014-2015 ChaosForge Ltd
|
---|
| 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
| 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[336] | 6 |
|
---|
| 7 | #include "nv/sdl/sdl_window_manager.hh"
|
---|
| 8 |
|
---|
| 9 | #include "nv/sdl/sdl_window.hh"
|
---|
| 10 | #include "nv/core/logging.hh"
|
---|
| 11 | #include "nv/lib/sdl.hh"
|
---|
| 12 | #include "nv/lib/sdl_image.hh"
|
---|
| 13 | #include "nv/interface/image_data.hh"
|
---|
| 14 |
|
---|
| 15 | using namespace nv;
|
---|
| 16 |
|
---|
| 17 | sdl::window_manager::window_manager()
|
---|
| 18 | {
|
---|
[505] | 19 | primal_window = nullptr;
|
---|
[336] | 20 | nv::load_sdl_library();
|
---|
| 21 |
|
---|
| 22 | if ( SDL_Init(0) < 0 )
|
---|
| 23 | {
|
---|
[365] | 24 | NV_LOG_CRITICAL( "SDL initialization failed: ", SDL_GetError( ) );
|
---|
[336] | 25 | return; // TODO: Error report
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | window* sdl::window_manager::create_window( device* dev, uint16 width, uint16 height, bool fullscreen )
|
---|
| 30 | {
|
---|
| 31 | if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO );
|
---|
[505] | 32 | sdl::window* result = new sdl::window( dev, width, height, fullscreen );
|
---|
| 33 | primal_window = result->get_handle();
|
---|
| 34 | return result;
|
---|
[336] | 35 | }
|
---|
| 36 |
|
---|
| 37 | void* sdl::window_manager::adopt_window( void* sys_w_handle )
|
---|
| 38 | {
|
---|
| 39 | if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO );
|
---|
[505] | 40 | if ( primal_window )
|
---|
| 41 | {
|
---|
| 42 | char buffer[128];
|
---|
| 43 | sprintf( buffer, "%p", primal_window );
|
---|
| 44 | NV_ASSERT( SDL_SetHint( "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT", buffer ) == SDL_TRUE );
|
---|
| 45 | }
|
---|
| 46 | primal_window = SDL_CreateWindowFrom( sys_w_handle );
|
---|
| 47 | return primal_window;
|
---|
[336] | 48 | }
|
---|
| 49 |
|
---|
| 50 | void nv::sdl::window_manager::sleep( uint32 ms )
|
---|
| 51 | {
|
---|
| 52 | SDL_Delay( ms );
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | nv::uint32 nv::sdl::window_manager::get_ticks()
|
---|
| 56 | {
|
---|
| 57 | return SDL_GetTicks();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | nv::sdl::window_manager::~window_manager()
|
---|
| 61 | {
|
---|
| 62 | SDL_Quit();
|
---|
| 63 | }
|
---|
| 64 |
|
---|