2010-08-05 00:09:45 +00:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 07:40:48 +00:00
|
|
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
2010-08-05 00:09:45 +00:00
|
|
|
//
|
|
|
|
// You can redistribute this code 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
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#include "metrics.h"
|
|
|
|
#include <stdexcept>
|
2012-04-14 21:21:09 +00:00
|
|
|
#include "platform_util.h"
|
2010-08-05 00:09:45 +00:00
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class Metrics
|
|
|
|
// =====================================================
|
|
|
|
|
2011-06-11 08:52:49 +00:00
|
|
|
Metrics::Metrics() {
|
2013-01-01 02:24:23 +00:00
|
|
|
reloadData();
|
|
|
|
}
|
|
|
|
|
2013-01-01 10:18:42 +00:00
|
|
|
void Metrics::reload(int resWidth, int resHeight) {
|
2013-01-01 02:24:23 +00:00
|
|
|
Metrics *metrics = getInstancePtr();
|
2013-01-01 10:18:42 +00:00
|
|
|
metrics->reloadData(resWidth, resHeight);
|
2013-01-01 02:24:23 +00:00
|
|
|
}
|
|
|
|
|
2013-01-01 10:18:42 +00:00
|
|
|
void Metrics::reloadData(int resWidth, int resHeight) {
|
2011-06-11 08:52:49 +00:00
|
|
|
Config &config = Config::getInstance();
|
2010-08-05 00:09:45 +00:00
|
|
|
|
|
|
|
virtualW= 1000;
|
|
|
|
virtualH= 750;
|
|
|
|
|
2013-01-01 10:18:42 +00:00
|
|
|
if(resWidth > 0) {
|
|
|
|
screenW= resWidth;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
screenW= config.getInt("ScreenWidth");
|
|
|
|
}
|
|
|
|
if(resHeight > 0) {
|
|
|
|
screenH= resHeight;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
screenH= config.getInt("ScreenHeight");
|
|
|
|
}
|
2010-08-05 00:09:45 +00:00
|
|
|
|
|
|
|
minimapX= 10;
|
|
|
|
minimapY= 750-128-30+16;
|
|
|
|
minimapW= 128;
|
|
|
|
minimapH= 128;
|
|
|
|
|
|
|
|
displayX= 800;
|
|
|
|
displayY= 250;
|
|
|
|
displayW= 128;
|
|
|
|
displayH= 480;
|
|
|
|
}
|
|
|
|
|
2013-01-01 02:24:23 +00:00
|
|
|
Metrics * Metrics::getInstancePtr() {
|
|
|
|
static Metrics metrics;
|
|
|
|
return &metrics;
|
|
|
|
}
|
|
|
|
|
2010-08-05 00:09:45 +00:00
|
|
|
const Metrics &Metrics::getInstance(){
|
2013-01-01 02:24:23 +00:00
|
|
|
Metrics *metrics = getInstancePtr();
|
|
|
|
return *metrics;
|
2010-08-05 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float Metrics::getAspectRatio() const{
|
|
|
|
if(screenH == 0) {
|
2012-04-14 21:21:09 +00:00
|
|
|
throw megaglest_runtime_error("div by 0 screenH == 0");
|
2010-08-05 00:09:45 +00:00
|
|
|
}
|
|
|
|
return static_cast<float>(screenW)/screenH;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Metrics::toVirtualX(int w) const{
|
|
|
|
if(screenW == 0) {
|
2012-04-14 21:21:09 +00:00
|
|
|
throw megaglest_runtime_error("div by 0 screenW == 0");
|
2010-08-05 00:09:45 +00:00
|
|
|
}
|
|
|
|
return w*virtualW/screenW;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Metrics::toVirtualY(int h) const{
|
|
|
|
if(screenH == 0) {
|
2012-04-14 21:21:09 +00:00
|
|
|
throw megaglest_runtime_error("div by 0 screenH == 0");
|
2010-08-05 00:09:45 +00:00
|
|
|
}
|
2011-07-01 01:18:47 +00:00
|
|
|
|
|
|
|
//printf("h [%d] virtualH [%d] screenH [%d] result = %d\n",h,virtualH,screenH,(h*virtualH/screenH));
|
|
|
|
|
2010-08-05 00:09:45 +00:00
|
|
|
return h*virtualH/screenH;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Metrics::isInDisplay(int x, int y) const{
|
|
|
|
return
|
|
|
|
x > displayX &&
|
|
|
|
y > displayY &&
|
|
|
|
x < displayX+displayW &&
|
|
|
|
y < displayY+displayH;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Metrics::isInMinimap(int x, int y) const{
|
|
|
|
return
|
|
|
|
x > minimapX &&
|
|
|
|
y > minimapY &&
|
|
|
|
x < minimapX+minimapW &&
|
|
|
|
y < minimapY+minimapH;
|
|
|
|
}
|
|
|
|
|
|
|
|
}}// end namespace
|