1 /*
2 DSFML - The Simple and Fast Multimedia Library for D
3 
4 Copyright (c) 2013 - 2015 Jeremy DeHaan (dehaan.jeremiah@gmail.com)
5 
6 This software is provided 'as-is', without any express or implied warranty.
7 In no event will the authors be held liable for any damages arising from the use of this software.
8 
9 Permission is granted to anyone to use this software for any purpose, including commercial applications,
10 and to alter it and redistribute it freely, subject to the following restrictions:
11 
12 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
13 If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
14 
15 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
16 
17 3. This notice may not be removed or altered from any source distribution
18 */
19 
20 ///A module containing the Context class.
21 module dsfml.window.context;
22 
23 /**
24 *Class holding a valid drawing context.
25 *
26 *If you need to make OpenGL calls without having an active window (like in a thread), you can use an instance of this class to get a valid context.
27 *
28 *Having a valid context is necessary for every OpenGL call.
29 *
30 *Note that a context is only active in its current thread, if you create a new thread it will have no valid context by default.
31 *
32 *To use a Context instance, just construct it and let it live as long as you need a valid context. No explicit activation is needed, all it has to do is to exist. Its destructor will take care of deactivating and freeing all the attached resources.
33 */
34 class Context
35 {
36 	package sfContext* sfPtr;
37 	
38 	///Default constructor.
39 	///
40 	///The constructor creates and activates the context
41 	this()
42 	{
43 		sfPtr = sfContext_create();
44 	}
45 	
46 	///Destructor
47 	~this()
48 	{
49 		import dsfml.system.config;
50 		mixin(destructorOutput);
51 		sfContext_destroy(sfPtr);	
52 	}
53 	
54 	///Activate or deactivate explicitely the context.
55 	///
56 	///Params:
57     ///		active = True to activate, false to deactivate.
58     ///
59 	///Returns: True on success, false on failure.
60 	void setActive(bool active)
61 	{
62 		sfContext_setActive(sfPtr,active);
63 	}
64 	
65 }
66 
67 package extern(C)
68 {
69 	struct sfContext;
70 }
71 private extern(C)
72 {
73 	sfContext* sfContext_create();
74 	void sfContext_destroy(sfContext* context);
75 	void sfContext_setActive(sfContext* context, bool active);
76 }
77 //unittest?
78 //I'll probably write one just to confirm no segfaults happen and to up the coverage amount