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.
|
---|
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 | {
|
---|
19 | primal_window = nullptr;
|
---|
20 | nv::load_sdl_library();
|
---|
21 |
|
---|
22 | if ( SDL_Init(0) < 0 )
|
---|
23 | {
|
---|
24 | NV_LOG_CRITICAL( "SDL initialization failed: ", SDL_GetError( ) );
|
---|
25 | return; // TODO: Error report
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | window* sdl::window_manager::create_window( device* dev, uint16 width, uint16 height, bool fullscreen, bool msaa )
|
---|
30 | {
|
---|
31 | if ( ! SDL_WasInit( SDL_INIT_VIDEO ) ) SDL_InitSubSystem( SDL_INIT_VIDEO );
|
---|
32 | sdl::window* result = new sdl::window( dev, width, height, fullscreen, msaa );
|
---|
33 | primal_window = result->get_handle();
|
---|
34 | return result;
|
---|
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 );
|
---|
40 | if ( primal_window )
|
---|
41 | {
|
---|
42 | char buffer[128];
|
---|
43 | sprintf( buffer, "%p", primal_window );
|
---|
44 | SDL_bool result = SDL_SetHint( "SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT", buffer );
|
---|
45 | NV_UNUSED( result );
|
---|
46 | NV_ASSERT( result == SDL_TRUE, "SetHint failed!" );
|
---|
47 | }
|
---|
48 | primal_window = SDL_CreateWindowFrom( sys_w_handle );
|
---|
49 | return primal_window;
|
---|
50 | }
|
---|
51 |
|
---|
52 | void nv::sdl::window_manager::sleep( uint32 ms )
|
---|
53 | {
|
---|
54 | SDL_Delay( ms );
|
---|
55 | }
|
---|
56 |
|
---|
57 | nv::uint32 nv::sdl::window_manager::get_ticks()
|
---|
58 | {
|
---|
59 | return SDL_GetTicks();
|
---|
60 | }
|
---|
61 |
|
---|
62 | nv::sdl::window_manager::~window_manager()
|
---|
63 | {
|
---|
64 | SDL_Quit();
|
---|
65 | }
|
---|
66 |
|
---|