22 #if defined(_DEBUG) && defined(_WINDOWS)
23 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
29 Configurator_Video::Check_State::Accept_Button::Accept_Button(Check_State &check_video,
const std::pair<Point2f, Point2f> &virtual_screen)
30 : Text_Button(Point2f(virtual_screen.second.
x - 100.0
f, virtual_screen.second.
y - 42.0
f),
31 Point2f(virtual_screen.second),
34 m_check_video(check_video)
38 void Configurator_Video::Check_State::Accept_Button::on_accept() {
39 m_check_video.m_code = CODE_SAVE;
43 Configurator_Video::Check_State::Check_State()
46 #pragma warning( push )
47 #pragma warning( disable : 4355 )
49 m_accept_button(*this, get_virtual_window()),
51 #pragma warning(
pop )
54 m_text(
Point2f(), get_virtual_window().second,
"system_36_x600",
55 "Click 'Accept' to save current rendering options.\n"
56 "Hit 'Escape' to reject current rendering options.\n"
57 "Current rendering options will be rejected in "
73 void Configurator_Video::Check_State::on_pop() {
76 if(m_code == CODE_SAVE)
78 else if(m_code == CODE_REVERT) {
93 #if SDL_VERSION_ATLEAST(2,0,0)
94 void Configurator_Video::Check_State::on_window_event(
const SDL_WindowEvent &event) {
100 void Configurator_Video::Check_State::on_video_resize(
const SDL_ResizeEvent &event) {
104 m_code = CODE_IGNORE;
110 void Configurator_Video::Check_State::perform_logic() {
113 const Time current_time;
114 const float seconds_remaining_f =
ZENI_REVERT_TIMEOUT - current_time.get_seconds_since(m_start_time);
116 if(seconds_remaining_f < 0.0
f) {
121 const int seconds_remaining(
int(seconds_remaining_f + 0.999
f));
123 if(seconds_remaining < m_seconds_remaining) {
124 m_seconds_remaining = seconds_remaining;
127 "Click 'Accept' to save current rendering options.\n"
128 "Hit 'Escape' to reject current rendering options.\n"
129 "Current rendering options will be rejected in " +
130 itoa(m_seconds_remaining) +
135 Configurator_Video::Check_Box_Element::Check_Box_Element(
const XML_Element &element,
137 const Point2f &upper_left,
139 : Check_Box(upper_left,
140 Point2f(upper_left.
x + height, upper_left.
y + height),
144 m_element.set_bool(checked);
147 void Configurator_Video::Check_Box_Element::on_accept() {
149 m_element.set_bool(is_checked());
152 void Configurator_Video::Check_Box_Element::render_impl()
const {
155 Font &font =
get_Fonts()[
"system_36_500x600"];
157 font.render_text(
" " + m_element.value(),
158 Point2f(get_lower_right().
x,
159 0.5
f * (get_lower_right().
y + get_upper_left().
y - font.get_text_height())),
163 Configurator_Video::Slider_Element::Slider_Element(
const XML_Element &element,
165 const std::pair<int, int> &
range,
166 const Point2f &upper_left,
167 const Point2f &lower_right)
169 Point2f(0.9
f * upper_left.
x + 0.1
f * lower_right.
x, 0.5
f * (upper_left.
y + lower_right.
y)),
170 Point2f(0.1
f * upper_left.
x + 0.9
f * lower_right.
x, 0.5
f * (upper_left.
y + lower_right.
y)),
171 0.2
f * (lower_right.
x - upper_left.
x)),
173 m_text_coord(lower_right.
x,
174 0.5
f * (lower_right.
y + upper_left.
y))
177 m_element.set_int(value);
180 void Configurator_Video::Slider_Element::on_accept() {
182 m_element.set_int(get_value());
185 void Configurator_Video::Slider_Element::render_impl()
const {
188 Font &font =
get_Fonts()[
"system_36_500x600"];
190 font.render_text(
" " + m_element.value() +
" (" +
itoa(get_value()) +
")",
191 Point2f(m_text_coord.x, m_text_coord.y - 0.5f * font.get_text_height()),
195 Configurator_Video::Text_Element::Text_Element(
const XML_Element &element,
197 const Point2f &upper_left,
198 const Point2f &lower_right)
199 : Text_Box(upper_left,
200 Point2f(lower_right.
x , lower_right.
y),
208 m_element.set_string(text);
211 void Configurator_Video::Text_Element::on_change() {
213 m_element.set_string(get_text());
216 void Configurator_Video::Text_Element::render_impl()
const {
227 Configurator_Video::Selector_Element::Selector_Element(
const XML_Element &element,
228 const Point2f &upper_left,
229 const Point2f &lower_right,
230 const Point2f &expanded_upper_left,
231 const Point2f &expanded_lower_right)
232 : Selector(upper_left, lower_right, expanded_upper_left, expanded_lower_right,
"system_36_500x600"),
237 void Configurator_Video::Selector_Element::add_entry(
const String &
option,
const String &save_as) {
239 m_save_as[
option] = save_as;
242 size_t Configurator_Video::Selector_Element::num_entries()
const {
243 return m_save_as.size();
246 void Configurator_Video::Selector_Element::on_accept(
const String &
option) {
248 m_element.set_string(m_save_as[option]);
251 Configurator_Video::Resolution_Element::Resolution_Element(
const XML_Element &element,
252 const Point2f &upper_left,
253 const Point2f &lower_right,
254 const Point2f &expanded_upper_left,
255 const Point2f &expanded_lower_right)
256 : Selector(upper_left, lower_right, expanded_upper_left, expanded_lower_right,
"system_36_500x600"),
261 for(std::vector<Point2i>::const_iterator it = resolutions.begin(); it != resolutions.end(); ++it)
262 add_option(
itoa(it->x) +
"x" +
itoa(it->y));
265 select_option(
itoa(resolutions.begin()->x) +
'x' +
itoa(resolutions.begin()->y));
268 select_option(
"640x480");
274 void Configurator_Video::Resolution_Element::on_accept(
const String &option) {
277 const size_t x = option.find(
'x');
279 m_element[
"Width"].set_string(option.substr(0, x));
280 m_element[
"Height"].set_string(option.substr(x + 1));
283 Configurator_Video::Custom_Resolution_Box::Custom_Resolution_Box(
Configurator_Video &configurator,
285 const Point2f &upper_left,
287 : Check_Box(upper_left,
288 Point2f(upper_left.x + height, upper_left.
y + height),
290 m_configurator(configurator)
294 void Configurator_Video::Custom_Resolution_Box::apply() {
296 m_configurator.m_widgets.unlend_Widget(m_configurator.resolution);
297 m_configurator.m_widgets.lend_Widget(m_configurator.custom_width);
298 m_configurator.m_widgets.lend_Widget(m_configurator.custom_height);
300 m_configurator.custom_width.on_change();
301 m_configurator.custom_height.on_change();
304 m_configurator.m_widgets.unlend_Widget(m_configurator.custom_width);
305 m_configurator.m_widgets.unlend_Widget(m_configurator.custom_height);
306 m_configurator.m_widgets.lend_Widget(m_configurator.resolution);
308 m_configurator.resolution.on_accept(m_configurator.resolution.get_selected());
312 void Configurator_Video::Custom_Resolution_Box::on_accept() {
317 void Configurator_Video::Custom_Resolution_Box::render_impl()
const {
320 Font &font =
get_Fonts()[
"system_36_500x600"];
322 font.render_text(
" Custom",
323 Point2f(get_lower_right().x,
324 0.5
f * (get_lower_right().
y + get_upper_left().
y - font.get_text_height())),
328 Configurator_Video::Apply_Button::Apply_Button(XML_Document &
file,
329 const Point2f &upper_left,
330 const Point2f &lower_right)
331 : Text_Button(upper_left, lower_right,
"system_36_500x600",
"Apply"),
336 void Configurator_Video::Apply_Button::on_accept() {
337 XML_Element_c zenilib = (*m_file)[
"Zenilib"];
338 XML_Element_c
textures = zenilib[
"Textures"];
339 XML_Element_c video = zenilib[
"Video"];
340 const String
api = video[
"API"].to_string();
343 #ifndef DISABLE_GL_SHADER
349 #ifndef DISABLE_GL_FIXED
354 video[
"Resolution"][
"Height"].to_int()));
360 textures[
"Bilinear_Filtering"].to_bool(),
361 textures[
"Mipmapping"].to_bool());
376 Configurator_Video::Cancel_Button::Cancel_Button(
const Point2f &upper_left,
377 const Point2f &lower_right)
378 : Text_Button(upper_left, lower_right,
"system_36_500x600",
"Cancel")
382 void Configurator_Video::Cancel_Button::on_accept() {
388 #pragma warning( push )
389 #pragma warning( disable : 4355 )
392 m_file(
get_File_Ops().get_appdata_path() +
"config/zenilib.xml",
"config/zenilib.xml"),
393 m_zenilib(m_file[
"Zenilib"]),
414 #pragma warning( pop )
419 #if !defined(DISABLE_DX9)
420 api.add_entry(
"Direct3D 9",
"Direct3D 9");
421 if(dynamic_cast<Video_DX9 *>(&
get_Video()))
422 api.select_option(
"Direct3D 9");
424 #if !defined(DISABLE_GL_FIXED)
425 api.add_entry(
"OpenGL Fixed",
"OpenGL Fixed");
426 if(dynamic_cast<Video_GL_Fixed *>(&
get_Video()))
427 api.select_option(
"OpenGL Fixed");
429 #if !defined(DISABLE_GL_SHADER)
430 api.add_entry(
"OpenGL Shader",
"OpenGL Shader");
431 if(dynamic_cast<Video_GL_Shader *>(&
get_Video()))
432 api.select_option(
"OpenGL Shader");
434 if(api.num_entries() < 2)
435 api.set_editable(
false);
448 const size_t x = selected.
find(
'x');
474 void Configurator_Video::on_push() {
489 void Configurator_Video::render() {
492 Font &font =
get_Fonts()[
"system_36_500x600"];
495 font.render_text(
"zenilib Renderer Configuration:", Point2f(10.0
f, 10.0
f), color);
496 font.render_text(
"Textures:", Point2f(10.0
f, 10.0
f + 1 * 42.0
f), color);
497 font.render_text(
"Video:", Point2f(10.0
f, 10.0
f + 5 * 42.0
f), color);
498 font.render_text(
"x", Point2f(52.0
f + 100.0
f, 10.0
f + 9 * 42.0
f), color,
ZENI_CENTER);
static const int & get_width()
Get the size of the window.
Slider_Element anisotropy
Check_Box_Element bilinear_filtering
virtual void on_accept()
Called when the cursor is released inside the button.
size_t find(const String &str, size_t pos=0) const
Colors & get_Colors()
Get access to the singleton.
static void change_resolution(const Point2i &resolution)
static void set_title(const String &title)
Set the window title.
virtual void set_clear_Color(const Color &color)=0
Set the blank background color.
static bool revert()
Restore previously saved options; Returns true if successful.
Custom_Resolution_Box custom_resolution
static int get_anisotropic_filtering()
Check the current level of anisotropy.
void give_BG_Renderer(Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget ownership.
Check_Box_Element full_screen
Gamestate pop_state()
Pop a Gamestate off the stack. Pop the current Gamestate with caution. All members will instantly bec...
static void reformat_all()
Reformat all Text_Box instances.
EGLSurface EGLint EGLint EGLint EGLint height
virtual void render_impl() const
Slider_Element multisampling
static void preinit_full_screen(const bool &full_screen=false)
Set the rendering window to be full screen at launch.
Text_Element custom_height
Game & get_Game()
Get access to the singleton.
String substr(size_t pos=0, size_t n=npos) const
static void preinit_resolution(const Point2i &resolution=Point2i(800, 600))
Set the rendering window to have a given resolution.
Keyboard button event structure (event.key.*)
static void preinit_multisampling(const int &multisampling=0)
Set a multisampling value.
void push_state(const Gamestate &state)
Push a new Gamestate onto the stack.
void set_2d()
Set the default 2D view filling the entire display area.
String itoa(const int &number)
static const bool & is_full_screen()
Determine whether the window is windowed or full screen.
static int get_multisampling()
Get the current level of multisampling.
static void save(const bool &backup=true)
Save options.
static void preinit_vertical_sync(const bool &vertical_sync=false)
Set vertical_sync to true.
Check_Box_Element vertical_sync
Textures & get_Textures()
Get access to the singleton.
Window state change event data (event.window.*)
Window & get_Window()
Get access to the singleton.
const std::vector< Point2i > & get_resolutions() const
Get available full screen resolutions.
EGLSurface EGLint EGLint y
void unlose_resources()
If resources have been lost, then reload them.
EGLSurface EGLint void ** value
virtual void on_accept(const String &option)
static const int & get_height()
Get the height of the window.
GLsizei const GLuint * textures
static bool get_vertical_sync()
Determine whether vertical sync is enabled.
static void set_texturing_mode(const int &anisotropic_filtering_, const bool &bilinear_filtering_, const bool &mipmapping_)
Check to see if Textures is set to use lazy loading if possible.
Fonts & get_Fonts()
Get access to the singleton.
Video & get_Video()
Get access to the singleton.
static void preinit_video_mode(const VIDEO_MODE &vm=ZENI_VIDEO_ANY)
Set which rendering engine to use.
static bool get_mipmapping()
Check if mipmapping is in use.
File_Ops & get_File_Ops()
Get access to the singleton.
#define ZENI_REVERT_TIMEOUT
static bool get_bilinear_filtering()
Check if bilinear filtering is in use.
A 2D Point represented with floats.
Text_Element custom_width
Resolution_Element resolution
Check_Box_Element mipmapping