1 /*
2  * DSFML - The Simple and Fast Multimedia Library for D
3  *
4  * Copyright (c) 2013 - 2017 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
8  * use of this software.
9  *
10  * Permission is granted to anyone to use this software for any purpose,
11  * including commercial applications, and to alter it and redistribute it
12  * freely, subject to the following restrictions:
13  *
14  * 1. The origin of this software must not be misrepresented; you must not claim
15  * that you wrote the original software. If you use this software in a product,
16  * an acknowledgment in the product documentation would be appreciated but is
17  * not required.
18  *
19  * 2. Altered source versions must be plainly marked as such, and must not be
20  * misrepresented as being the original software.
21  *
22  * 3. This notice may not be removed or altered from any source distribution
23  */
24 
25 /**
26  * $(U Window) is the main class of the Window module. It defines an OS window
27  * that is able to receive an OpenGL rendering.
28  *
29  * A $(U Window) can create its own new window, or be embedded into an already
30  * existing control using the create(handle) function. This can be useful for
31  * embedding an OpenGL rendering area into a view which is part of a bigger GUI
32  * with existing windows, controls, etc. It can also serve as embedding an
33  * OpenGL rendering area into a window created by another (probably richer) GUI
34  * library like Qt or wxWidgets.
35  *
36  * The $(U Window) class provides a simple interface for manipulating the
37  * window: move, resize, show/hide, control mouse cursor, etc. It also provides
38  * event handling through its `pollEvent()` and `waitEvent()` functions.
39  *
40  * Note that OpenGL experts can pass their own parameters (antialiasing level
41  * bits for the depth and stencil buffers, etc.) to the OpenGL context attached
42  * to the window, with the $(CONTEXTSETTINGS_LINK) structure which is passed as
43  * an optional argument when creating the window.
44  *
45  * Example:
46  * ---
47  * // Declare and create a new window
48  * auto window = new Window(VideoMode(800, 600), "DSFML window");
49  *
50  * // Limit the framerate to 60 frames per second (this step is optional)
51  * window.setFramerateLimit(60);
52  *
53  * // The main loop - ends as soon as the window is closed
54  * while (window.isOpen())
55  * {
56  *    // Event processing
57  *    Event event;
58  *    while (window.pollEvent(event))
59  *    {
60  *        // Request for closing the window
61  *        if (event.type == Event.EventType.Closed)
62  *            window.close();
63  *    }
64  *
65  *    // Activate the window for OpenGL rendering
66  *    window.setActive();
67  *
68  *    // OpenGL drawing commands go here...
69  *
70  *    // End the current frame and display its contents on screen
71  *    window.display();
72  * }
73  * ---
74  */
75 module dsfml.window.window;
76 
77 import dsfml.window.event;
78 import dsfml.window.videomode;
79 import dsfml.window.contextsettings;
80 import dsfml.window.windowhandle;
81 import dsfml.system.vector2;
82 import dsfml.system.err;
83 
84 /**
85  * Window that serves as a target for OpenGL rendering.
86  */
87 class Window
88 {
89 	/// Choices for window style
90 	enum Style
91 	{
92 		None = 0,
93 		Titlebar = 1 << 0,
94 		Resize = 1 << 1,
95 		Close = 1 << 2,
96 		Fullscreen = 1 << 3,
97 		DefaultStyle = Titlebar | Resize | Close
98 	}
99 
100 	package sfWindow* sfPtr;
101 
102 	//let's RenderWindow inherit from Window without trying to delete the null
103 	//pointer
104 	private bool m_needsToDelete = true;
105 
106 	/// Default constructor.
107 	this()
108 	{
109 		sfPtr = sfWindow_construct();
110 	}
111 
112 	//Construct a window without calling sfWindow_construct
113 	//This allows a RenderWindow to be created without creating a Window first
114 	protected this(int)
115 	{
116 		m_needsToDelete = false;
117 	}
118 
119 	//allows RenderWindow to delete the Window pointer when it is created
120 	//so that there are not both instances.
121 	protected void deleteWindowPtr()
122 	{
123 		sfWindow_destroy(sfPtr);
124 		m_needsToDelete = false;
125 	}
126 
127 	/**
128 	 * Construct a new window.
129 	 *
130 	 * This constructor creates the window with the size and pixel depth defined
131 	 * in mode. An optional style can be passed to customize the look and
132 	 * behaviour of the window (borders, title bar, resizable, closable, ...).
133 	 * If style contains Style::Fullscreen, then mode must be a valid video
134 	 * mode.
135 	 *
136 	 * The fourth parameter is an optional structure specifying advanced OpenGL
137 	 * context settings such as antialiasing, depth-buffer bits, etc.
138 	 *
139 	 * Params:
140 	 *    	mode = Video mode to use (defines the width, height and depth of the
141 	 *			   rendering area of the window)
142 	 *   	title = Title of the window
143 	 *    	style = Window style
144 	 *     	settings = Additional settings for the underlying OpenGL context
145 	 */
146 	this(T)(VideoMode mode, immutable(T)[] title, Style style = Style.DefaultStyle, ContextSettings settings = ContextSettings.init)
147 		if (is(T == dchar)||is(T == wchar)||is(T == char))
148 	{
149 		this();
150 		create(mode, title, style, settings);
151 	}
152 
153 	/**
154 	 * Construct the window from an existing control.
155 	 *
156 	 * Use this constructor if you want to create an OpenGL rendering area into
157 	 * an already existing control.
158 	 *
159 	 * The second parameter is an optional structure specifying advanced OpenGL
160 	 * context settings such as antialiasing, depth-buffer bits, etc.
161 	 *
162 	 * Params:
163      * 		handle = Platform-specific handle of the control
164      * 		settings = Additional settings for the underlying OpenGL context
165 	 */
166 	this(WindowHandle handle, ContextSettings settings = ContextSettings.init)
167 	{
168 		this();
169 		create(handle, settings);
170 	}
171 
172 	/// Destructor.
173 	~this()
174 	{
175 		import dsfml.system.config;
176 		//this takes care of not freeing a null pointer due to inheritance
177 		//(RenderWindow does not create the inherited sfWindow)
178 		if(m_needsToDelete)
179 		{
180 			mixin(destructorOutput);
181 			sfWindow_destroy(sfPtr);
182 		}
183 	}
184 
185 	/**
186 	 * Get's or set's the window's position.
187 	 *
188 	 * This function only works for top-level windows (i.e. it will be ignored
189 	 * for windows created from the handle of a child window/control).
190 	 */
191 	@property
192 	{
193 		Vector2i position(Vector2i newPosition)
194 		{
195 			sfWindow_setPosition(sfPtr,newPosition.x, newPosition.y);
196 			return newPosition;
197 		}
198 
199 		Vector2i position()
200 		{
201 			Vector2i temp;
202 			sfWindow_getPosition(sfPtr,&temp.x, &temp.y);
203 			return temp;
204 		}
205 	}
206 
207 	///Get's or set's the window's size.
208 	@property
209 	{
210 		Vector2u size(Vector2u newSize)
211 		{
212 			sfWindow_setSize(sfPtr, newSize.x, newSize.y);
213 			return newSize;
214 		}
215 		Vector2u size()
216 		{
217 			Vector2u temp;
218 			sfWindow_getSize(sfPtr,&temp.x, &temp.y);
219 			return temp;
220 		}
221 	}
222 
223 	/**
224 	 * Activate or deactivate the window as the current target for OpenGL
225 	 * rendering.
226 	 *
227 	 * A window is active only on the current thread, if you want to make it
228 	 * active on another thread you have to deactivate it on the previous thread
229 	 * first if it was active. Only one window can be active on a thread at a
230 	 * time, thus the window previously active (if any) automatically gets
231 	 * deactivated.
232 	 *
233 	 * Params:
234      * 		active = true to activate, false to deactivate
235      *
236 	 * Returns: true if operation was successful, false otherwise.
237 	 */
238 	bool setActive(bool active)
239 	{
240 		import dsfml.system..string;
241 		bool toReturn = sfWindow_setActive(sfPtr, active);
242 		err.write(dsfml.system..string.toString(sfErr_getOutput()));
243 		return toReturn;
244 	}
245 
246 	///Request the current window to be made the active foreground window.
247 	void requestFocus()
248 	{
249 		sfWindow_requestFocus(sfPtr);
250 	}
251 
252 	/**
253 	 * Check whether the window has the input focus
254 	 *
255 	 * Returns: true if the window has focus, false otherwise
256 	 */
257 	bool hasFocus() const
258 	{
259 		return sfWindow_hasFocus(sfPtr);
260 	}
261 
262 	/**
263 	 * Limit the framerate to a maximum fixed frequency.
264 	 *
265 	 * If a limit is set, the window will use a small delay after each call to
266 	 * display() to ensure that the current frame lasted long enough to match
267 	 * the framerate limit. SFML will try to match the given limit as much as it
268 	 * can, but since it internally uses dsfml.system.sleep, whose precision
269 	 * depends on the underlying OS, the results may be a little unprecise as
270 	 * well (for example, you can get 65 FPS when requesting 60).
271 	 *
272 	 * Params:
273      * 		limit = Framerate limit, in frames per seconds (use 0 to disable limit).
274 	 */
275 	void setFramerateLimit(uint limit)
276 	{
277 		sfWindow_setFramerateLimit(sfPtr, limit);
278 	}
279 
280 	/**
281 	 * Change the window's icon.
282 	 *
283 	 * pixels must be an array of width x height pixels in 32-bits RGBA format.
284 	 *
285 	 * The OS default icon is used by default.
286 	 *
287 	 * Params:
288 	 *     width = Icon's width, in pixels
289 	 *     height = Icon's height, in pixels
290 	 *     pixels = Pointer to the array of pixels in memory
291 	 */
292 	void setIcon(uint width, uint height, const(ubyte[]) pixels)
293 	{
294 		sfWindow_setIcon(sfPtr,width, height, pixels.ptr);
295 	}
296 
297 	/**
298 	 * Change the joystick threshold.
299 	 *
300 	 * The joystick threshold is the value below which no JoystickMoved event
301 	 * will be generated.
302 	 *
303 	 * The threshold value is 0.1 by default.
304 	 *
305 	 * Params:
306 	 *     threshold = New threshold, in the range [0, 100].
307 	 */
308 	void setJoystickThreshold(float threshold)
309 	{
310 		sfWindow_setJoystickThreshold(sfPtr, threshold);
311 	}
312 
313 	/**
314 	 * Change the joystick threshold.
315 	 *
316 	 * The joystick threshold is the value below which no JoystickMoved event
317 	 * will be generated.
318 	 *
319 	 * The threshold value is 0.1 by default.
320 	 *
321 	 * Params:
322 	 *     threshold = New threshold, in the range [0, 100].
323 	 *
324 	 * Deprecated: Use set `setJoystickThreshold` instead.
325 	 */
326 	deprecated("Use setJoystickThreshold instead.")
327 	void setJoystickThreshhold(float threshhold)
328 	{
329 		sfWindow_setJoystickThreshold(sfPtr, threshhold);
330 	}
331 
332 	/**
333 	 * Enable or disable automatic key-repeat.
334 	 *
335 	 * If key repeat is enabled, you will receive repeated KeyPressed events
336 	 * while keeping a key pressed. If it is disabled, you will only get a
337 	 * single event when the key is pressed.
338 	 *
339 	 * Key repeat is enabled by default.
340 	 *
341 	 * Params:
342 	 *     enabled = true to enable, false to disable.
343 	 */
344 	void setKeyRepeatEnabled(bool enabled)
345 	{
346 		enabled ? sfWindow_setKeyRepeatEnabled(sfPtr,true):sfWindow_setKeyRepeatEnabled(sfPtr,false);
347 	}
348 
349 	/**
350 	 * Show or hide the mouse cursor.
351 	 *
352 	 * The mouse cursor is visible by default.
353 	 *
354 	 * Params:
355      * 		visible = true to show the mouse cursor, false to hide it.
356 	 */
357 	void setMouseCursorVisible(bool visible)
358 	{
359 		visible ? sfWindow_setMouseCursorVisible(sfPtr,true): sfWindow_setMouseCursorVisible(sfPtr,false);
360 	}
361 
362 	//Cannot use templates here as template member functions cannot be virtual.
363 
364 	/**
365 	 * Change the title of the window.
366 	 *
367 	 * Params:
368      * 		title = New title
369 	 */
370 	void setTitle(const(char)[] newTitle)
371 	{
372 		import dsfml.system..string;
373 
374 		auto convertedTitle = stringConvert!(char, dchar)(newTitle);
375 		sfWindow_setUnicodeTitle(sfPtr, convertedTitle.ptr, convertedTitle.length);
376 	}
377 
378 	/// ditto
379 	void setTitle(const(wchar)[] newTitle)
380 	{
381 		import dsfml.system..string;
382 		auto convertedTitle = stringConvert!(wchar, dchar)(newTitle);
383 		sfWindow_setUnicodeTitle(sfPtr, convertedTitle.ptr, convertedTitle.length);
384 	}
385 
386 	/// ditto
387 	void setTitle(const(dchar)[] newTitle)
388 	{
389 		sfWindow_setUnicodeTitle(sfPtr, newTitle.ptr, newTitle.length);
390 	}
391 
392 	/**
393 	 * Show or hide the window.
394 	 *
395 	 * The window is shown by default.
396 	 *
397 	 * Params:
398 	 *     visible = true to show the window, false to hide it
399 	 */
400 	void setVisible(bool visible)
401 	{
402 		sfWindow_setVisible(sfPtr,visible);
403 	}
404 
405 	/**
406 	 * Enable or disable vertical synchronization.
407 	 *
408 	 * Activating vertical synchronization will limit the number of frames
409 	 * displayed to the refresh rate of the monitor. This can avoid some visual
410 	 * artifacts, and limit the framerate to a good value (but not constant
411 	 * across different computers).
412 	 *
413 	 * Vertical synchronization is disabled by default.
414 	 *
415 	 * Params:
416 	 *     enabled = true to enable v-sync, false to deactivate it
417 	 */
418 	void setVerticalSyncEnabled(bool enabled)
419 	{
420 		enabled ? sfWindow_setVerticalSyncEnabled(sfPtr, true): sfWindow_setVerticalSyncEnabled(sfPtr, false);
421 	}
422 
423 	/**
424 	 * Get the settings of the OpenGL context of the window.
425 	 *
426 	 * Note that these settings may be different from what was passed to the
427 	 * constructor or the create() function, if one or more settings were not
428 	 * supported. In this case, SFML chose the closest match.
429 	 *
430 	 * Returns: Structure containing the OpenGL context settings.
431 	 */
432 	ContextSettings getSettings() const
433 	{
434 		ContextSettings temp;
435 		sfWindow_getSettings(sfPtr,&temp.depthBits, &temp.stencilBits, &temp.antialiasingLevel, &temp.majorVersion, &temp.minorVersion);
436 		return temp;
437 	}
438 
439 	/**
440 	 * Get the OS-specific handle of the window.
441 	 *
442 	 * The type of the returned handle is sf::WindowHandle, which is a typedef
443 	 * to the handle type defined by the OS. You shouldn't need to use this
444 	 * function, unless you have very specific stuff to implement that SFML
445 	 * doesn't support, or implement a temporary workaround until a bug is
446 	 * fixed.
447 	 *
448 	 * Returns: System handle of the window.
449 	 */
450 	WindowHandle getSystemHandle() const
451 	{
452 		return sfWindow_getSystemHandle(sfPtr);
453 	}
454 
455 	//TODO: Consider adding these methods.
456 	//void onCreate
457 	//void onResize
458 
459 	/**
460 	 * Close the window and destroy all the attached resources.
461 	 *
462 	 * After calling this function, the Window instance remains valid and you
463 	 * can call create() to recreate the window. All other functions such as
464 	 * pollEvent() or display() will still work (i.e. you don't have to test
465 	 * isOpen() every time), and will have no effect on closed windows.
466 	 */
467 	void close()
468 	{
469 		sfWindow_close(sfPtr);
470 	}
471 
472 	//Cannot use templates here as template member functions cannot be virtual.
473 
474 	/**
475 	 * Create (or recreate) the window.
476 	 *
477 	 * If the window was already created, it closes it first. If style contains
478 	 * Style.Fullscreen, then mode must be a valid video mode.
479 	 *
480 	 * The fourth parameter is an optional structure specifying advanced OpenGL
481 	 * context settings such as antialiasing, depth-buffer bits, etc.
482 	 */
483 	void create(VideoMode mode, const(char)[] title, Style style = Style.DefaultStyle, ContextSettings settings = ContextSettings.init)
484 	{
485 		import dsfml.system..string;
486 
487 		auto convertedTitle = stringConvert!(char,dchar)(title);
488 		sfWindow_createFromSettings(sfPtr, mode.width, mode.height, mode.bitsPerPixel, convertedTitle.ptr, convertedTitle.length, style, settings.depthBits, settings.stencilBits, settings.antialiasingLevel, settings.majorVersion, settings.minorVersion);
489 		err.write(dsfml.system..string.toString(sfErr_getOutput()));
490 	}
491 
492 	/// ditto
493 	void create(VideoMode mode, const(wchar)[] title, Style style = Style.DefaultStyle, ContextSettings settings = ContextSettings.init)
494 	{
495 		import dsfml.system..string;
496 		auto convertedTitle = stringConvert!(wchar,dchar)(title);
497 		sfWindow_createFromSettings(sfPtr, mode.width, mode.height, mode.bitsPerPixel, convertedTitle.ptr, convertedTitle.length, style, settings.depthBits, settings.stencilBits, settings.antialiasingLevel, settings.majorVersion, settings.minorVersion);
498 		err.write(dsfml.system..string.toString(sfErr_getOutput()));
499 	}
500 
501 	/// ditto
502 	void create(VideoMode mode, const(dchar)[] title, Style style = Style.DefaultStyle, ContextSettings settings = ContextSettings.init)
503 	{
504 		import dsfml.system..string;
505 		sfWindow_createFromSettings(sfPtr, mode.width, mode.height, mode.bitsPerPixel, title.ptr, title.length, style, settings.depthBits, settings.stencilBits, settings.antialiasingLevel, settings.majorVersion, settings.minorVersion);
506 		err.write(dsfml.system..string.toString(sfErr_getOutput()));
507 	}
508 
509 	/// ditto
510 	void create(WindowHandle handle, ContextSettings settings = ContextSettings.init)
511 	{
512 		import dsfml.system..string;
513 		sfWindow_createFromHandle(sfPtr, handle, settings.depthBits,settings.stencilBits, settings.antialiasingLevel, settings.majorVersion, settings.minorVersion);
514 		err.write(dsfml.system..string.toString(sfErr_getOutput()));
515 	}
516 
517 	/**
518 	 * Display on screen what has been rendered to the window so far.
519 	 *
520 	 * This function is typically called after all OpenGL rendering has been
521 	 * done for the current frame, in order to show it on screen.
522 	 */
523 	void display()
524 	{
525 		sfWindow_display(sfPtr);
526 	}
527 
528 	/**
529 	 * Tell whether or not the window is open.
530 	 *
531 	 * This function returns whether or not the window exists. Note that a
532 	 * hidden window (setVisible(false)) is open (therefore this function would
533 	 * return true).
534 	 *
535 	 * Returns: true if the window is open, false if it has been closed.
536 	 */
537 	bool isOpen()
538 	{
539 		return (sfWindow_isOpen(sfPtr));
540 	}
541 
542 	/**
543 	 * Pop the event on top of the event queue, if any, and return it.
544 	 *
545 	 * This function is not blocking: if there's no pending event then it will
546 	 * return false and leave event unmodified. Note that more than one event
547 	 * may be present in the event queue, thus you should always call this
548 	 * function in a loop to make sure that you process every pending event.
549 	 *
550 	 * Params:
551      * 		event = Event to be returned.
552      *
553 	 * Returns: true if an event was returned, or false if the event queue was
554 	 * 			empty.
555 	 */
556 	bool pollEvent(ref Event event)
557 	{
558 		return (sfWindow_pollEvent(sfPtr, &event));
559 	}
560 
561 	/**
562 	 * Wait for an event and return it.
563 	 *
564 	 * This function is blocking: if there's no pending event then it will wait
565 	 * until an event is received. After this function returns (and no error
566 	 * occured), the event object is always valid and filled properly. This
567 	 * function is typically used when you have a thread that is dedicated to
568 	 * events handling: you want to make this thread sleep as long as no new
569 	 * event is received.
570 	 *
571 	 * Params:
572      * 		event = Event to be returned
573      *
574 	 * Returns: False if any error occured.
575 	 */
576 	bool waitEvent(ref Event event)
577 	{
578 		return (sfWindow_waitEvent(sfPtr, &event));
579 	}
580 
581 	//TODO: Clean this up. The names are so bad. :(
582 
583 	//Gives a way for RenderWindow to send its mouse position
584 	protected Vector2i getMousePosition()const
585 	{
586 		Vector2i temp;
587 		sfMouse_getPosition(sfPtr,&temp.x, &temp.y);
588 		return temp;
589 	}
590 
591 	//A method for the Mouse class to use in order to get the mouse position
592 	//relative to the window
593 	package Vector2i mouse_getPosition()const
594 	{
595 		return getMousePosition();
596 	}
597 
598 	//Gives a way for Render Window to set its mouse position
599 	protected void setMousePosition(Vector2i pos) const
600 	{
601 		sfMouse_setPosition(pos.x, pos.y, sfPtr);
602 	}
603 
604 	//A method for the mouse class to use
605 	package void mouse_SetPosition(Vector2i pos) const
606 	{
607 		setMousePosition(pos);
608 	}
609 
610 	//Circumvents the package restriction allowing Texture to get the internal
611 	//pointer of a regular window (for texture.update)
612 	protected static void* getWindowPointer(const(Window) window)
613 	{
614 		return cast(void*)window.sfPtr;
615 	}
616 }
617 
618 unittest
619 {
620 	version(DSFML_Unittest_Window)
621 	{
622 		import std.stdio;
623 		import dsfml.graphics.image;
624 
625 		writeln("Unit test for Window class.");
626 
627 
628 		//constructor
629 		auto window = new Window(VideoMode(800,600),"Test Window");
630 
631 		//perform each window call
632 		Vector2u windowSize = window.size;
633 
634 		windowSize.x = 1000;
635 		windowSize.y = 1000;
636 
637 		window.size = windowSize;
638 
639 		Vector2i windowPosition = window.position;
640 
641 		windowPosition.x = 100;
642 		windowPosition.y = 100;
643 
644 		window.position = windowPosition;
645 
646 		window.setTitle("thing");//uses the first set title
647 
648 		window.setTitle("素晴らしい !");//forces the dstring override and uses unicode
649 
650 		window.setActive(true);
651 
652 		window.setJoystickThreshhold(1);
653 
654 		window.setVisible(true);
655 
656 		window.setFramerateLimit(60);
657 
658 		window.setMouseCursorVisible(true);
659 
660 		window.setVerticalSyncEnabled(true);
661 
662 		auto settings = window.getSettings();
663 
664 		auto image = new Image();
665 		image.loadFromFile("res/TestImage.png");
666 
667 		window.setIcon(image.getSize().x,image.getSize().x,image.getPixelArray());
668 
669 		if(window.isOpen())
670 		{
671 			Event event;
672 			if(window.pollEvent(event))
673 			{
674 
675 			}
676 			//requires users input
677 			if(window.waitEvent(event))
678 			{
679 
680 			}
681 
682 			window.display();
683 		}
684 
685 		window.close();
686 
687 	}
688 }
689 
690 
691 package extern(C) struct sfWindow;
692 
693 private extern(C):
694 
695 	//Construct a new window
696 	sfWindow* sfWindow_construct();
697 
698 	//Construct a new window (with a UTF-32 title)
699 	void sfWindow_createFromSettings(sfWindow* window, uint width, uint height, uint bitsPerPixel, const(dchar)* title, size_t titleLength, int style, uint depthBits, uint stencilBits, uint antialiasingLevel, uint majorVersion, uint minorVersion);
700 
701 	//Construct a window from an existing control
702 	void sfWindow_createFromHandle(sfWindow* window, WindowHandle handle, uint depthBits, uint stencilBits, uint antialiasingLevel, uint majorVersion, uint minorVersion);
703 
704 	// Destroy a window
705 	void sfWindow_destroy(sfWindow* window);
706 
707 	//Close a window and destroy all the attached resources
708 	void sfWindow_close(sfWindow* window);
709 
710 	//Tell whether or not a window is opened
711 	bool sfWindow_isOpen(const(sfWindow)* window);
712 
713 	//Get the settings of the OpenGL context of a window
714 	void sfWindow_getSettings(const(sfWindow)* window, uint* depthBits, uint* stencilBits, uint* antialiasingLevel, uint* majorVersion, uint* minorVersion);
715 
716 	//Pop the event on top of event queue, if any, and return it
717 	bool sfWindow_pollEvent(sfWindow* window, Event* event);
718 
719 	//Wait for an event and return it
720 	bool sfWindow_waitEvent(sfWindow* window, Event* event);
721 
722 	//Get the position of a window
723 	void sfWindow_getPosition(const(sfWindow)* window, int* x, int* y);
724 
725 	//Change the position of a window on screen
726 	void sfWindow_setPosition(sfWindow* window, int x, int y);
727 
728 	//Get the size of the rendering region of a window
729 	void sfWindow_getSize(const(sfWindow)* window, uint* width, uint* height);
730 
731 	//Change the size of the rendering region of a window
732 	void sfWindow_setSize(sfWindow* window, uint width, uint height);
733 
734 	//Change the title of a window
735 	void sfWindow_setTitle(sfWindow* window, const(char)* title, size_t length);
736 
737 	//Change the title of a window (with a UTF-32 string)
738 	void sfWindow_setUnicodeTitle(sfWindow* window, const(dchar)* title, size_t length);
739 
740 	//Change a window's icon
741 	void sfWindow_setIcon(sfWindow* window, uint width, uint height, const(ubyte)* pixels);
742 
743 	//Show or hide a window
744 	void sfWindow_setVisible(sfWindow* window, bool visible);
745 
746 	//Show or hide the mouse cursor
747 	void sfWindow_setMouseCursorVisible(sfWindow* window, bool visible);
748 
749 	//Enable or disable vertical synchronization
750 	 void sfWindow_setVerticalSyncEnabled(sfWindow* window, bool enabled);
751 
752 	//Enable or disable automatic key-repeat
753 	 void sfWindow_setKeyRepeatEnabled(sfWindow* window, bool enabled);
754 
755 	//Activate or deactivate a window as the current target for OpenGL rendering
756 	 bool sfWindow_setActive(sfWindow* window, bool active);
757 
758 	 //Request the current window to be made the active foreground window.
759 	 void sfWindow_requestFocus(sfWindow* window);
760 
761 	 //Check whether the window has the input focus
762 	 bool sfWindow_hasFocus(const(sfWindow)* window);
763 
764 	//Display on screen what has been rendered to the window so far
765 	 void sfWindow_display(sfWindow* window);
766 
767 	//Limit the framerate to a maximum fixed frequency
768 	 void sfWindow_setFramerateLimit(sfWindow* window, uint limit);
769 
770 	//Change the joystick threshold
771 	 void sfWindow_setJoystickThreshold(sfWindow* window, float threshold);
772 
773 
774 	//Get the OS-specific handle of the window
775 	 WindowHandle sfWindow_getSystemHandle(const(sfWindow)* window);
776 
777 	void sfMouse_getPosition(const(sfWindow)* relativeTo, int* x, int* y);
778 	void sfMouse_setPosition(int x, int y, const(sfWindow)* relativeTo);
779 
780 	const(char)* sfErr_getOutput();