Refactored Math::IntPoint in CApplication and various classes
parent
55c692e8bb
commit
0ef4579da8
|
@ -575,8 +575,7 @@ bool CApplication::Create()
|
||||||
|
|
||||||
// GetVideoResolutionList() has to be called here because it is responsible
|
// GetVideoResolutionList() has to be called here because it is responsible
|
||||||
// for list of resolutions in options menu, not calling it results in empty list
|
// for list of resolutions in options menu, not calling it results in empty list
|
||||||
std::vector<Math::IntPoint> modes;
|
auto modes = GetVideoResolutionList();
|
||||||
GetVideoResolutionList(modes);
|
|
||||||
|
|
||||||
if ( GetConfigFile().GetStringProperty("Setup", "Resolution", sValue) && !m_resolutionOverride )
|
if ( GetConfigFile().GetStringProperty("Setup", "Resolution", sValue) && !m_resolutionOverride )
|
||||||
{
|
{
|
||||||
|
@ -1028,7 +1027,7 @@ void CApplication::UpdateJoystick()
|
||||||
|
|
||||||
void CApplication::UpdateMouse()
|
void CApplication::UpdateMouse()
|
||||||
{
|
{
|
||||||
Math::IntPoint pos;
|
glm::ivec2 pos{};
|
||||||
SDL_GetMouseState(&pos.x, &pos.y);
|
SDL_GetMouseState(&pos.x, &pos.y);
|
||||||
m_input->MouseMove(pos);
|
m_input->MouseMove(pos);
|
||||||
}
|
}
|
||||||
|
@ -1302,7 +1301,7 @@ Event CApplication::ProcessSystemEvent()
|
||||||
{
|
{
|
||||||
event.type = EVENT_MOUSE_MOVE;
|
event.type = EVENT_MOUSE_MOVE;
|
||||||
|
|
||||||
m_input->MouseMove(Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
|
m_input->MouseMove({ m_private->currentEvent.button.x, m_private->currentEvent.button.y });
|
||||||
}
|
}
|
||||||
else if (m_private->currentEvent.type == SDL_JOYAXISMOTION)
|
else if (m_private->currentEvent.type == SDL_JOYAXISMOTION)
|
||||||
{
|
{
|
||||||
|
@ -1627,19 +1626,21 @@ Gfx::DeviceConfig CApplication::GetVideoConfig() const
|
||||||
return m_deviceConfig;
|
return m_deviceConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions, int display) const
|
std::vector<glm::ivec2> CApplication::GetVideoResolutionList(int display) const
|
||||||
{
|
{
|
||||||
resolutions.clear();
|
std::vector<glm::ivec2> resolutions;
|
||||||
|
|
||||||
for(int i = 0; i < SDL_GetNumDisplayModes(display); i++)
|
for(int i = 0; i < SDL_GetNumDisplayModes(display); i++)
|
||||||
{
|
{
|
||||||
SDL_DisplayMode mode;
|
SDL_DisplayMode mode;
|
||||||
SDL_GetDisplayMode(display, i, &mode);
|
SDL_GetDisplayMode(display, i, &mode);
|
||||||
Math::IntPoint resolution = Math::IntPoint(mode.w, mode.h);
|
glm::ivec2 resolution = { mode.w, mode.h };
|
||||||
|
|
||||||
if (std::find(resolutions.begin(), resolutions.end(), resolution) == resolutions.end())
|
if (std::find(resolutions.begin(), resolutions.end(), resolution) == resolutions.end())
|
||||||
resolutions.push_back(resolution);
|
resolutions.push_back(resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return resolutions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CApplication::SetDebugModeActive(DebugMode mode, bool active)
|
void CApplication::SetDebugModeActive(DebugMode mode, bool active)
|
||||||
|
@ -1713,7 +1714,7 @@ MouseMode CApplication::GetMouseMode() const
|
||||||
|
|
||||||
void CApplication::MoveMouse(Math::Point pos)
|
void CApplication::MoveMouse(Math::Point pos)
|
||||||
{
|
{
|
||||||
Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos);
|
glm::ivec2 windowPos = m_engine->InterfaceToWindowCoords(pos);
|
||||||
m_input->MouseMove(windowPos);
|
m_input->MouseMove(windowPos);
|
||||||
SDL_WarpMouseInWindow(m_private->window, windowPos.x, windowPos.y);
|
SDL_WarpMouseInWindow(m_private->window, windowPos.x, windowPos.y);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,8 @@
|
||||||
#include "graphics/core/device.h"
|
#include "graphics/core/device.h"
|
||||||
|
|
||||||
#include "level/level_category.h"
|
#include "level/level_category.h"
|
||||||
#include "math/intpoint.h"
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -184,7 +185,7 @@ public:
|
||||||
const std::string& GetErrorMessage() const;
|
const std::string& GetErrorMessage() const;
|
||||||
|
|
||||||
//! Returns a list of possible video modes
|
//! Returns a list of possible video modes
|
||||||
void GetVideoResolutionList(std::vector<Math::IntPoint> &resolutions, int display = 0) const;
|
std::vector<glm::ivec2> GetVideoResolutionList(int display = 0) const;
|
||||||
|
|
||||||
//! Returns the current video mode
|
//! Returns the current video mode
|
||||||
Gfx::DeviceConfig GetVideoConfig() const;
|
Gfx::DeviceConfig GetVideoConfig() const;
|
||||||
|
|
|
@ -237,7 +237,7 @@ bool CMotionToto::EventFrame(const Event &event)
|
||||||
Math::Vector eye, lookat, dir, perp, nPos, aPos, pos, speed;
|
Math::Vector eye, lookat, dir, perp, nPos, aPos, pos, speed;
|
||||||
Math::Vector vibLin, vibCir, dirSpeed, aAntenna;
|
Math::Vector vibLin, vibCir, dirSpeed, aAntenna;
|
||||||
Math::Point dim;
|
Math::Point dim;
|
||||||
Math::IntPoint wDim;
|
glm::ivec2 wDim;
|
||||||
Gfx::ParticleType type;
|
Gfx::ParticleType type;
|
||||||
float progress, focus, distance, shift, verti, level, zoom;
|
float progress, focus, distance, shift, verti, level, zoom;
|
||||||
float aAngle, nAngle, mAngle, angle, linSpeed, cirSpeed;
|
float aAngle, nAngle, mAngle, angle, linSpeed, cirSpeed;
|
||||||
|
|
|
@ -114,7 +114,7 @@ bool CTaskGoto::EventProcess(const Event &event)
|
||||||
{
|
{
|
||||||
if (m_bmArray != nullptr)
|
if (m_bmArray != nullptr)
|
||||||
{
|
{
|
||||||
std::unique_ptr<CImage> debugImage = MakeUnique<CImage>(Math::IntPoint(m_bmSize, m_bmSize));
|
std::unique_ptr<CImage> debugImage = MakeUnique<CImage>(glm::ivec2(m_bmSize, m_bmSize));
|
||||||
debugImage->Fill(Gfx::IntColor(255, 255, 255, 255));
|
debugImage->Fill(Gfx::IntColor(255, 255, 255, 255));
|
||||||
for (int x = 0; x < m_bmSize; x++)
|
for (int x = 0; x < m_bmSize; x++)
|
||||||
{
|
{
|
||||||
|
@ -126,7 +126,7 @@ bool CTaskGoto::EventProcess(const Event &event)
|
||||||
{
|
{
|
||||||
Gfx::Color c = Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f);
|
Gfx::Color c = Gfx::Color(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
if (b) c = Gfx::Color(0.0f, 0.0f, 1.0f, 1.0f);
|
if (b) c = Gfx::Color(0.0f, 0.0f, 1.0f, 1.0f);
|
||||||
debugImage->SetPixel(Math::IntPoint(x, y), c);
|
debugImage->SetPixel({ x, y }, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1031,7 +1031,7 @@ void CMap::UpdateTerrain()
|
||||||
{
|
{
|
||||||
if (! m_fixImage.empty()) return; // still image?
|
if (! m_fixImage.empty()) return; // still image?
|
||||||
|
|
||||||
CImage img(Math::IntPoint(256, 256));
|
CImage img(glm::ivec2(256, 256));
|
||||||
|
|
||||||
float scale = m_terrain->GetReliefScale();
|
float scale = m_terrain->GetReliefScale();
|
||||||
float water = m_water->GetLevel();
|
float water = m_water->GetLevel();
|
||||||
|
@ -1077,7 +1077,7 @@ void CMap::UpdateTerrain()
|
||||||
color.b = Math::Norm(m_waterColor.b + (intensity - 0.5f));
|
color.b = Math::Norm(m_waterColor.b + (intensity - 0.5f));
|
||||||
}
|
}
|
||||||
|
|
||||||
img.SetPixel(Math::IntPoint(x, y), color);
|
img.SetPixel({ x, y }, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -890,7 +890,6 @@ void CDisplayInfo::ViewDisplayInfo()
|
||||||
{
|
{
|
||||||
Ui::CWindow* pw;
|
Ui::CWindow* pw;
|
||||||
Ui::CEdit* edit;
|
Ui::CEdit* edit;
|
||||||
Math::IntPoint dim;
|
|
||||||
|
|
||||||
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW4));
|
pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW4));
|
||||||
if ( pw == nullptr ) return;
|
if ( pw == nullptr ) return;
|
||||||
|
@ -898,7 +897,7 @@ void CDisplayInfo::ViewDisplayInfo()
|
||||||
edit = static_cast<Ui::CEdit*>(pw->SearchControl(EVENT_EDIT1));
|
edit = static_cast<Ui::CEdit*>(pw->SearchControl(EVENT_EDIT1));
|
||||||
if ( edit == nullptr ) return;
|
if ( edit == nullptr ) return;
|
||||||
|
|
||||||
dim = m_engine->GetWindowSize();
|
auto dim = m_engine->GetWindowSize();
|
||||||
edit->SetFontSize(CSettings::GetInstancePointer()->GetFontSize()/(dim.x / 640.0f));
|
edit->SetFontSize(CSettings::GetInstancePointer()->GetFontSize()/(dim.x / 640.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ bool CMainShort::CreateShortcuts()
|
||||||
m_shortcuts.clear();
|
m_shortcuts.clear();
|
||||||
|
|
||||||
|
|
||||||
Math::IntPoint size = m_engine->GetWindowSize();
|
glm::ivec2 size = m_engine->GetWindowSize();
|
||||||
float ratio = static_cast<float>(size.y) / static_cast<float>(size.x);
|
float ratio = static_cast<float>(size.y) / static_cast<float>(size.x);
|
||||||
|
|
||||||
// Display pause / movie indicator
|
// Display pause / movie indicator
|
||||||
|
|
|
@ -64,8 +64,8 @@ void CScreenSetupDisplay::CreateInterface()
|
||||||
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
|
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
|
||||||
if ( pw == nullptr ) return;
|
if ( pw == nullptr ) return;
|
||||||
|
|
||||||
std::vector<Math::IntPoint> modes;
|
auto modes = m_app->GetVideoResolutionList();
|
||||||
m_app->GetVideoResolutionList(modes);
|
|
||||||
for (auto it = modes.begin(); it != modes.end(); ++it)
|
for (auto it = modes.begin(); it != modes.end(); ++it)
|
||||||
{
|
{
|
||||||
if (it->x == m_app->GetVideoConfig().size.x && it->y == m_app->GetVideoConfig().size.y)
|
if (it->x == m_app->GetVideoConfig().size.x && it->y == m_app->GetVideoConfig().size.y)
|
||||||
|
@ -218,10 +218,9 @@ static int GCD(int a, int b)
|
||||||
return (b == 0) ? a : GCD(b, a%b);
|
return (b == 0) ? a : GCD(b, a%b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Math::IntPoint AspectRatio(Math::IntPoint resolution)
|
static glm::ivec2 AspectRatio(const glm::ivec2& resolution)
|
||||||
{
|
{
|
||||||
int gcd = GCD(resolution.x, resolution.y);
|
return resolution / GCD(resolution.x, resolution.y);
|
||||||
return Math::IntPoint(static_cast<float>(resolution.x) / gcd, static_cast<float>(resolution.y) / gcd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScreenSetupDisplay::UpdateDisplayMode()
|
void CScreenSetupDisplay::UpdateDisplayMode()
|
||||||
|
@ -235,14 +234,14 @@ void CScreenSetupDisplay::UpdateDisplayMode()
|
||||||
if ( pl == nullptr ) return;
|
if ( pl == nullptr ) return;
|
||||||
pl->Flush();
|
pl->Flush();
|
||||||
|
|
||||||
std::vector<Math::IntPoint> modes;
|
auto modes = m_app->GetVideoResolutionList();
|
||||||
m_app->GetVideoResolutionList(modes);
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
std::stringstream mode_text;
|
std::stringstream mode_text;
|
||||||
for (Math::IntPoint mode : modes)
|
for (const auto& mode : modes)
|
||||||
{
|
{
|
||||||
mode_text.str("");
|
mode_text.str("");
|
||||||
Math::IntPoint aspect = AspectRatio(mode);
|
glm::ivec2 aspect = AspectRatio(mode);
|
||||||
mode_text << mode.x << "x" << mode.y << " [" << aspect.x << ":" << aspect.y << "]";
|
mode_text << mode.x << "x" << mode.y << " [" << aspect.x << ":" << aspect.y << "]";
|
||||||
pl->SetItemName(i++, mode_text.str());
|
pl->SetItemName(i++, mode_text.str());
|
||||||
}
|
}
|
||||||
|
@ -272,8 +271,7 @@ void CScreenSetupDisplay::ChangeDisplay()
|
||||||
bFull = pc->TestState(STATE_CHECK);
|
bFull = pc->TestState(STATE_CHECK);
|
||||||
m_setupFull = bFull;
|
m_setupFull = bFull;
|
||||||
|
|
||||||
std::vector<Math::IntPoint> modes;
|
auto modes = m_app->GetVideoResolutionList();
|
||||||
m_app->GetVideoResolutionList(modes);
|
|
||||||
|
|
||||||
Gfx::DeviceConfig config = m_app->GetVideoConfig();
|
Gfx::DeviceConfig config = m_app->GetVideoConfig();
|
||||||
config.size = modes[m_setupSelMode];
|
config.size = modes[m_setupSelMode];
|
||||||
|
|
|
@ -1111,7 +1111,6 @@ void CStudio::ViewEditScript()
|
||||||
{
|
{
|
||||||
CWindow* pw;
|
CWindow* pw;
|
||||||
CEdit* edit;
|
CEdit* edit;
|
||||||
Math::IntPoint dim;
|
|
||||||
|
|
||||||
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));
|
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));
|
||||||
if ( pw == nullptr ) return;
|
if ( pw == nullptr ) return;
|
||||||
|
@ -1119,7 +1118,7 @@ void CStudio::ViewEditScript()
|
||||||
edit = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT));
|
edit = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT));
|
||||||
if ( edit == nullptr ) return;
|
if ( edit == nullptr ) return;
|
||||||
|
|
||||||
dim = m_engine->GetWindowSize();
|
glm::ivec2 dim = m_engine->GetWindowSize();
|
||||||
edit->SetFontSize(m_settings->GetFontSize()/(dim.x/640.0f));
|
edit->SetFontSize(m_settings->GetFontSize()/(dim.x/640.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue