--- /dev/null
+/*
+** ClanLib SDK
+** Copyright (c) 1997-2005 The ClanLib Team
+**
+** This software is provided 'as-is', without any express or implied
+** warranty. In no event will the authors be held liable for any damages
+** arising from the use of this software.
+**
+** Permission is granted to anyone to use this software for any purpose,
+** including commercial applications, and to alter it and redistribute it
+** freely, subject to the following restrictions:
+**
+** 1. The origin of this software must not be misrepresented; you must not
+** claim that you wrote the original software. If you use this software
+** in a product, an acknowledgment in the product documentation would be
+** appreciated but is not required.
+** 2. Altered source versions must be plainly marked as such, and must not be
+** misrepresented as being the original software.
+** 3. This notice may not be removed or altered from any source distribution.
+**
+** Note: Some of the libraries ClanLib may link to may have additional
+** requirements or restrictions.
+**
+** File Author(s):
+**
+** Magnus Norddahl
+** (if your name is missing here, please add it)
+*/
+
+//! clanCore="Math"
+//! header=core.h
+
+#ifndef HEADER_WINDSTILLE_MATH_SIZE_HPP
+#define HEADER_WINDSTILLE_MATH_SIZE_HPP
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+#include <iostream>
+
+class Sizef;
+
+//: 2D (width,height) size structure.
+//- !group=Core/Math!
+//- !header=core.h!
+class Size
+{
+ //! Construction:
+public:
+ //: Constructs a size structure.
+ //param width: Initial width of size structure.
+ //param height: Initial height of size structure.
+ //param size: Size structure to construct this one from.
+ Size()
+ : width(0), height(0)
+ {}
+
+ Size(int width_, int height_)
+ : width(width_), height(height_)
+ {}
+
+ Size(const Size &s)
+ : width(s.width),
+ height(s.height)
+ {}
+
+ explicit Size(const Sizef& s);
+
+ //! Attributes:
+public:
+ //: Size width.
+ int width;
+
+ //: Size height.
+ int height;
+
+ //! Operations:
+public:
+ //: Size += Size operator.
+ Size &operator+=(const Size &s)
+ { width += s.width; height += s.height; return *this; }
+
+ //: Size -= Size operator.
+ Size &operator-=(const Size &s)
+ { width -= s.width; height -= s.height; return *this; }
+
+ //: Size + Size operator.
+ Size operator+(const Size &s) const
+ { return Size(width + s.width, height + s.height); }
+
+ //: Size - Size operator.
+ Size operator-(const Size &s) const
+ { return Size(width - s.width, height - s.height); }
+
+ //: Size == Size operator (deep compare).
+ bool operator==(const Size &s) const
+ { return (width == s.width) && (height == s.height); }
+
+ //: Size != Size operator (deep compare).
+ bool operator!=(const Size &s) const
+ { return (width != s.width) || (height != s.height); }
+};
+
+//: 2D (width,height) floating point size structure.
+class Sizef
+{
+ //! Construction:
+public:
+ //: Constructs a size structure.
+ //param width: Initial width of size structure.
+ //param height: Initial height of size structure.
+ //param size: Size structure to construct this one from.
+ Sizef()
+ : width(0.0f),
+ height(0.0f)
+ {}
+
+ Sizef(const Size& s)
+ : width(static_cast<float>(s.width)),
+ height(static_cast<float>(s.height))
+ {}
+
+ Sizef(float width_, float height_)
+ : width(width_),
+ height(height_)
+ {}
+
+ Sizef(const Sizef &s)
+ : width(s.width),
+ height(s.height)
+ {}
+
+ //! Attributes:
+public:
+ //: Size width.
+ float width;
+
+ //: Size height.
+ float height;
+
+ //! Operations:
+public:
+ //: Size += Size operator.
+ Sizef &operator+=(const Sizef &s)
+ { width += s.width; height += s.height; return *this; }
+
+ //: Size -= Size operator.
+ Sizef &operator-=(const Sizef &s)
+ { width -= s.width; height -= s.height; return *this; }
+
+ //: Size + Size operator.
+ Sizef operator+(const Sizef &s) const
+ { return Sizef(width + s.width, height + s.height); }
+
+ //: Size - Size operator.
+ Sizef operator-(const Sizef &s) const
+ { return Sizef(width - s.width, height - s.height); }
+
+ //: Size == Size operator (deep compare).
+ bool operator==(const Sizef &s) const
+ { return (width == s.width) && (height == s.height); }
+
+ //: Size != Size operator (deep compare).
+ bool operator!=(const Size &s) const
+ { return (width != s.width) || (height != s.height); }
+};
+
+inline Size::Size(const Sizef& s)
+ : width(static_cast<int>(s.width)),
+ height(static_cast<int>(s.height))
+{}
+
+inline std::ostream& operator<<(std::ostream& s, const Size& size)
+{
+ return s << "Size(" << size.width << ", " << size.height << ")";
+}
+
+#endif
Config::Config() :
profile(1),
- fullscreen_width (800),
- fullscreen_height(600),
- window_width (800),
- window_height(600),
- aspect_width (0), // auto detect
- aspect_height(0),
+ fullscreen_size(800, 600),
+ window_size(800, 600),
+ aspect_size(0, 0), // auto detect
magnification(1.0f),
use_fullscreen(false),
video(AUTO_VIDEO),
video = get_video_system(video_string);
config_video_lisp->get("vsync", try_vsync);
- config_video_lisp->get("fullscreen_width", fullscreen_width);
- config_video_lisp->get("fullscreen_height", fullscreen_height);
+ config_video_lisp->get("fullscreen_width", fullscreen_size.width);
+ config_video_lisp->get("fullscreen_height", fullscreen_size.height);
- config_video_lisp->get("window_width", window_width);
- config_video_lisp->get("window_height", window_height);
+ config_video_lisp->get("window_width", window_size.width);
+ config_video_lisp->get("window_height", window_size.height);
- config_video_lisp->get("aspect_width", aspect_width);
- config_video_lisp->get("aspect_height", aspect_height);
+ config_video_lisp->get("aspect_width", aspect_size.width);
+ config_video_lisp->get("aspect_height", aspect_size.height);
}
const lisp::Lisp* config_audio_lisp = config_lisp->get_lisp("audio");
writer.write("video", get_video_string(video));
writer.write("vsync", try_vsync);
- writer.write("fullscreen_width", fullscreen_width);
- writer.write("fullscreen_height", fullscreen_height);
+ writer.write("fullscreen_width", fullscreen_size.width);
+ writer.write("fullscreen_height", fullscreen_size.height);
- writer.write("window_width", window_width);
- writer.write("window_height", window_height);
+ writer.write("window_width", window_size.width);
+ writer.write("window_height", window_size.height);
- writer.write("aspect_width", aspect_width);
- writer.write("aspect_height", aspect_height);
+ writer.write("aspect_width", aspect_size.width);
+ writer.write("aspect_height", aspect_size.height);
writer.end_list("video");
#define HEADER_SUPERTUX_SUPERTUX_GAMECONFIG_HPP
#include "video/video_systems.hpp"
+#include "math/size.hpp"
class Config
{
int profile;
// the width/height to be used to display the game in fullscreen
- int fullscreen_width;
- int fullscreen_height;
+ Size fullscreen_size;
- // the width/height of the window managers window
- int window_width;
- int window_height;
+ /** the width/height of the window managers window */
+ Size window_size;
- // the aspect ratio
- int aspect_width;
- int aspect_height;
+ /** the aspect ratio */
+ Size aspect_size;
float magnification;
} else if(arg == "--default" || arg == "-d") {
g_config->use_fullscreen = false;
- g_config->window_width = 800;
- g_config->window_height = 600;
-
- g_config->fullscreen_width = 800;
- g_config->fullscreen_height = 600;
-
- g_config->aspect_width = 0; // auto detect
- g_config->aspect_height = 0;
+ g_config->window_size = Size(800, 600);
+ g_config->fullscreen_size = Size(800, 600);
+ g_config->aspect_size = Size(0, 0); // auto detect
} else if(arg == "--window" || arg == "-w") {
g_config->use_fullscreen = false;
}
else
{
- g_config->window_width = width;
- g_config->window_height = height;
-
- g_config->fullscreen_width = width;
- g_config->fullscreen_height = height;
+ g_config->window_size = Size(width, height);
+ g_config->fullscreen_size = Size(width, height);
}
}
} else if(arg == "--aspect" || arg == "-a") {
}
else
{
- float aspect_ratio = static_cast<double>(g_config->aspect_width) /
- static_cast<double>(g_config->aspect_height);
+ float aspect_ratio = static_cast<float>(aspect_width) / static_cast<float>(aspect_height);
// use aspect ratio to calculate logical resolution
if (aspect_ratio > 1) {
- g_config->aspect_width = static_cast<int> (600 * aspect_ratio + 0.5);
- g_config->aspect_height = 600;
+ g_config->aspect_size = Size(static_cast<int>(600 * aspect_ratio + 0.5),
+ 600);
} else {
- g_config->aspect_width = 600;
- g_config->aspect_height = static_cast<int> (600 * 1/aspect_ratio + 0.5);
+ g_config->aspect_size = Size(600,
+ static_cast<int>(600 * 1/aspect_ratio + 0.5));
}
}
}
SDL_ShowCursor(0);
log_info << (g_config->use_fullscreen?"fullscreen ":"window ")
- << " Window: " << g_config->window_width << "x" << g_config->window_height
- << " Fullscreen: " << g_config->fullscreen_width << "x" << g_config->fullscreen_height
- << " Area: " << g_config->aspect_width << "x" << g_config->aspect_height << std::endl;
+ << " Window: " << g_config->window_size
+ << " Fullscreen: " << g_config->fullscreen_size
+ << " Area: " << g_config->aspect_size << std::endl;
}
void
aspect->list.push_back("16:9");
aspect->list.push_back("1368:768");
- if (g_config->aspect_width != 0 && g_config->aspect_height != 0)
+ if (g_config->aspect_size != Size(0, 0))
{
std::ostringstream out;
- out << g_config->aspect_width << ":" << g_config->aspect_height;
+ out << g_config->aspect_size.width << ":" << g_config->aspect_size.height;
std::string aspect_ratio = out.str();
for(std::vector<std::string>::iterator i = aspect->list.begin(); i != aspect->list.end(); ++i)
{
{
if (item->list[item->selected] == "auto")
{
- g_config->aspect_width = 0; // Magic values
- g_config->aspect_height = 0;
+ g_config->aspect_size = Size(0, 0); // Magic values
Renderer::instance()->apply_config();
MenuManager::recalc_pos();
}
- else if(sscanf(item->list[item->selected].c_str(), "%d:%d", &g_config->aspect_width, &g_config->aspect_height) == 2)
+ else if (sscanf(item->list[item->selected].c_str(), "%d:%d",
+ &g_config->aspect_size.width, &g_config->aspect_size.height) == 2)
{
Renderer::instance()->apply_config();
MenuManager::recalc_pos();
break;
case MNID_FULLSCREEN_RESOLUTION:
- if(sscanf(item->list[item->selected].c_str(), "%dx%d", &g_config->fullscreen_width, &g_config->fullscreen_height) == 2)
+ if(sscanf(item->list[item->selected].c_str(), "%dx%d",
+ &g_config->fullscreen_size.width, &g_config->fullscreen_size.height) == 2)
{
// do nothing, changes are only applied when toggling fullscreen mode
}
if(g_config->use_fullscreen)
{
flags |= SDL_FULLSCREEN;
- width = g_config->fullscreen_width;
- height = g_config->fullscreen_height;
+ width = g_config->fullscreen_size.width;
+ height = g_config->fullscreen_size.height;
}
else
{
// flags |= SDL_RESIZABLE;
- width = g_config->window_width;
- height = g_config->window_height;
+ width = g_config->window_size.width;
+ height = g_config->window_size.height;
}
int bpp = 0;
// unavoidable with SDL at the moment
SDL_SetVideoMode(w, h, 0, SDL_OPENGL /*| SDL_RESIZABLE*/);
- g_config->window_width = w;
- g_config->window_height = h;
+ g_config->window_size = Size(w, h);
apply_config();
}
{
std::cout << "Applying Config:"
<< "\n Desktop: " << desktop_width << "x" << desktop_height
- << "\n Window: " << g_config->window_width << "x" << g_config->window_height
- << "\n FullRes: " << g_config->fullscreen_width << "x" << g_config->fullscreen_height
- << "\n Aspect: " << g_config->aspect_width << ":" << g_config->aspect_height
+ << "\n Window: " << g_config->window_size
+ << "\n FullRes: " << g_config->fullscreen_size
+ << "\n Aspect: " << g_config->aspect_size
<< "\n Magnif: " << g_config->magnification
<< std::endl;
}
float target_aspect = static_cast<float>(desktop_width) / static_cast<float>(desktop_height);
- if (g_config->aspect_width != 0 && g_config->aspect_height != 0)
- target_aspect = float(g_config->aspect_width) / float(g_config->aspect_height);
+ if (g_config->aspect_size != Size(0, 0))
+ {
+ target_aspect = float(g_config->aspect_size.width) / float(g_config->aspect_size.height);
+ }
float desktop_aspect = 4.0f / 3.0f; // random default fallback guess
// Get the screen width
if (g_config->use_fullscreen)
{
- w = g_config->fullscreen_width;
- h = g_config->fullscreen_height;
+ w = g_config->fullscreen_size.width;
+ h = g_config->fullscreen_size.height;
desktop_aspect = float(w) / float(h);
}
else
{
- w = g_config->window_width;
- h = g_config->window_height;
+ w = g_config->window_size.width;
+ h = g_config->window_size.height;
}
if (target_aspect > 1.0f)