Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the initial SDL_Window wrapper code.
With this wrapper in place, Wesnoth shows a main window, all black and a lot of errors on the console.
- Loading branch information
Showing
5 changed files
with
235 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,6 +358,7 @@ endif() | |
|
||
set(wesnoth-sdl_SRC | ||
sdl/alpha.cpp | ||
sdl/window.cpp | ||
) | ||
|
||
add_library(wesnoth-sdl | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright (C) 2014 by Mark de Wever <koraq@xs4all.nl> | ||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/ | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY. | ||
See the COPYING file for more details. | ||
*/ | ||
|
||
#include "sdl/window.hpp" | ||
|
||
#if SDL_VERSION_ATLEAST(2, 0, 0) | ||
|
||
#include "log.hpp" | ||
#include "wml_exception.hpp" | ||
|
||
#include <SDL_render.h> | ||
|
||
static lg::log_domain log_display("display"); | ||
#define ERR_DP LOG_STREAM(err, log_display) | ||
|
||
namespace sdl | ||
{ | ||
|
||
twindow::twindow(const std::string& title, | ||
const int x, | ||
const int y, | ||
const int w, | ||
const int h, | ||
const Uint32 window_flags, | ||
const Uint32 render_flags) | ||
: window_(SDL_CreateWindow(title.c_str(), x, y, w, h, window_flags)) | ||
{ | ||
if(!window_) { | ||
ERR_DP << "Failed to create a SDL_Window object with error»" | ||
<< SDL_GetError() << "«.\n"; | ||
|
||
throw game::error(""); | ||
} | ||
|
||
if(!SDL_CreateRenderer(window_, -1, render_flags)) { | ||
ERR_DP << "Failed to create a SDL_Window object with error»" | ||
<< SDL_GetError() << "«.\n"; | ||
|
||
throw game::error(""); | ||
} | ||
} | ||
|
||
twindow::~twindow() | ||
{ | ||
if(window_) { | ||
SDL_DestroyWindow(window_); | ||
} | ||
} | ||
|
||
void twindow::set_size(const int w, const int h) | ||
{ | ||
SDL_SetWindowSize(window_, w, h); | ||
} | ||
|
||
void twindow::full_screen() | ||
{ | ||
/** @todo Implement. */ | ||
} | ||
|
||
twindow::operator SDL_Window*() | ||
{ | ||
return window_; | ||
} | ||
|
||
} // namespace sdl | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
Copyright (C) 2014 by Mark de Wever <koraq@xs4all.nl> | ||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/ | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY. | ||
See the COPYING file for more details. | ||
*/ | ||
|
||
#ifndef SDL_WINDOW_HPP_INCLUDED | ||
#define SDL_WINDOW_HPP_INCLUDED | ||
|
||
/** | ||
* @file | ||
* Contains a wrapper class for the @ref SDL_Window class. | ||
*/ | ||
|
||
#include <SDL_version.h> | ||
|
||
#if SDL_VERSION_ATLEAST(2, 0, 0) | ||
|
||
#include <boost/noncopyable.hpp> | ||
|
||
#include <SDL_video.h> | ||
|
||
#include <string> | ||
|
||
namespace sdl | ||
{ | ||
|
||
/** | ||
* The wrapper class for the @ref SDL_Window class. | ||
* | ||
* At the moment of writing it is not certain yet how many windows will be | ||
* created. At least one as main window, but maybe the GUI dialogues will have | ||
* their own window. Once that is known it might be a good idea to evaluate | ||
* whether the class should become a singleton or not. | ||
* | ||
* The class also wraps several functions operating on @ref SDL_Window objects. | ||
* For functions not wrapped the class offers an implicit conversion operator | ||
* to a pointer to the @ref SDL_Window object it owns. | ||
*/ | ||
class twindow : private boost::noncopyable | ||
{ | ||
public: | ||
/***** ***** ***** Constructor and destructor. ***** ***** *****/ | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* The function calls @ref SDL_CreateWindow and @ref SDL_CreateRenderer. | ||
* | ||
* @param title Used as title for @ref SDL_CreateWindow. | ||
* @param x Used as x for @ref SDL_CreateWindow. | ||
* @param y Used as y for @ref SDL_CreateWindow. | ||
* @param w Used as w for @ref SDL_CreateWindow. | ||
* @param h Used as x for @ref SDL_CreateWindow. | ||
* @param window_flags Used as flags for @ref SDL_CreateWindow. | ||
* @param render_flags Used as flags for @ref SDL_CreateRenderer. | ||
*/ | ||
twindow(const std::string& title, | ||
const int x, | ||
const int y, | ||
const int w, | ||
const int h, | ||
const Uint32 window_flags, | ||
const Uint32 render_flags); | ||
|
||
~twindow(); | ||
|
||
|
||
/***** ***** ***** Operations. ***** ***** *****/ | ||
|
||
/** | ||
* Wrapper for @ref SDL_SetWindowSize. | ||
* | ||
* @param w Used as w for @ref SDL_SetWindowSize. | ||
* @param h Used as x for @ref SDL_SetWindowSize. | ||
*/ | ||
void set_size(const int w, const int h); | ||
|
||
/** | ||
* Dummy function for setting the screen to full screen mode. | ||
* | ||
* @todo Implement this function properly. | ||
*/ | ||
void full_screen(); | ||
|
||
|
||
/***** ***** ***** Conversion operators. ***** ***** *****/ | ||
|
||
/** | ||
* Conversion operator to a SDL_Window*. | ||
*/ | ||
operator SDL_Window*(); | ||
|
||
|
||
private: | ||
/***** ***** ***** Members. ***** ***** *****/ | ||
|
||
/** The @ref SDL_Window we own. */ | ||
SDL_Window* window_; | ||
}; | ||
|
||
} // namespace sdl | ||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters