[nostalgia/core] Make display size function return common::Size instead of common::Point

This commit is contained in:
Gary Talent 2021-03-31 02:29:25 -05:00
parent 445db97d31
commit 8f7de171af
5 changed files with 197 additions and 4 deletions

View File

@ -10,6 +10,7 @@ install(
bounds.hpp
common.hpp
point.hpp
size.hpp
DESTINATION
include/nostalgia/common
)

View File

@ -0,0 +1,192 @@
/*
* Copyright 2016 - 2021 gary@drinkingtea.net
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <ox/std/error.hpp>
namespace nostalgia::common {
class Size {
public:
int width = 0;
int height = 0;
constexpr Size() = default;
constexpr Size(int width, int height);
constexpr Size operator+(common::Size p) const;
constexpr Size operator-(common::Size p) const;
constexpr Size operator*(common::Size p) const;
constexpr Size operator/(common::Size p) const;
constexpr Size operator+=(common::Size p);
constexpr Size operator-=(common::Size p);
constexpr Size operator*=(common::Size p);
constexpr Size operator/=(common::Size p);
constexpr Size operator+(int i) const;
constexpr Size operator-(int i) const;
constexpr Size operator*(int i) const;
constexpr Size operator/(int i) const;
constexpr Size operator+=(int i);
constexpr Size operator-=(int i);
constexpr Size operator*=(int i);
constexpr Size operator/=(int i);
constexpr bool operator==(const Size&) const;
constexpr bool operator!=(const Size&) const;
};
constexpr Size::Size(int width, int height) {
this->width = width;
this->height = height;
}
constexpr Size Size::operator+(common::Size p) const {
p.width += width;
p.height += height;
return p;
}
constexpr Size Size::operator-(common::Size p) const {
auto out = *this;
out.width -= p.width;
out.height -= p.height;
return out;
}
constexpr Size Size::operator*(common::Size p) const {
p.width *= width;
p.height *= height;
return p;
}
constexpr Size Size::operator/(common::Size p) const {
auto out = *this;
out.width /= p.width;
out.height /= p.height;
return out;
}
constexpr Size Size::operator+=(common::Size p) {
width += p.width;
height += p.height;
return *this;
}
constexpr Size Size::operator-=(common::Size p) {
width -= p.width;
height -= p.height;
return *this;
}
constexpr Size Size::operator*=(common::Size p) {
width *= p.width;
height *= p.height;
return *this;
}
constexpr Size Size::operator/=(common::Size p) {
width /= p.width;
height /= p.height;
return *this;
}
constexpr Size Size::operator+(int i) const {
auto out = *this;
out.width += i;
out.height += i;
return out;
}
constexpr Size Size::operator-(int i) const {
auto out = *this;
out.width -= i;
out.height -= i;
return out;
}
constexpr Size Size::operator*(int i) const {
auto out = *this;
out.width *= i;
out.height *= i;
return out;
}
constexpr Size Size::operator/(int i) const {
auto out = *this;
out.width /= i;
out.height /= i;
return out;
}
constexpr Size Size::operator+=(int i) {
width += i;
height += i;
return *this;
}
constexpr Size Size::operator-=(int i) {
width -= i;
height -= i;
return *this;
}
constexpr Size Size::operator*=(int i) {
width *= i;
height *= i;
return *this;
}
constexpr Size Size::operator/=(int i) {
width /= i;
height /= i;
return *this;
}
constexpr bool Size::operator==(const Size &p) const {
return width == p.width && height == p.height;
}
constexpr bool Size::operator!=(const Size &p) const {
return width != p.width || height != p.height;
}
template<typename T>
ox::Error model(T *io, Size *obj) {
io->setTypeInfo("nostalgia::common::Bounds", 2);
oxReturnError(io->field("width", &obj->width));
oxReturnError(io->field("height", &obj->height));
return OxError(0);
}
}

View File

@ -108,7 +108,7 @@ int getScreenHeight(Context*) {
return 160;
}
common::Point getScreenSize(Context*) {
common::Size getScreenSize(Context*) {
return {240, 160};
}

View File

@ -9,7 +9,7 @@
#pragma once
#include <ox/std/types.hpp>
#include <nostalgia/common/point.hpp>
#include <nostalgia/common/size.hpp>
#include "color.hpp"
#include "context.hpp"
@ -80,7 +80,7 @@ int getScreenWidth(Context *ctx);
int getScreenHeight(Context *ctx);
common::Point getScreenSize(Context *ctx);
common::Size getScreenSize(Context *ctx);
[[nodiscard]]
uint8_t bgStatus(Context *ctx);

View File

@ -66,7 +66,7 @@ int getScreenHeight(Context *ctx) {
return y;
}
common::Point getScreenSize(Context *ctx) {
common::Size getScreenSize(Context *ctx) {
auto id = ctx->windowerData<SdlImplData>();
int x = 0, y = 0;
SDL_GetWindowSize(id->window, &x, &y);