[nostalgia/core] Make display size function return common::Size instead of common::Point
This commit is contained in:
parent
445db97d31
commit
8f7de171af
@ -10,6 +10,7 @@ install(
|
|||||||
bounds.hpp
|
bounds.hpp
|
||||||
common.hpp
|
common.hpp
|
||||||
point.hpp
|
point.hpp
|
||||||
|
size.hpp
|
||||||
DESTINATION
|
DESTINATION
|
||||||
include/nostalgia/common
|
include/nostalgia/common
|
||||||
)
|
)
|
||||||
|
192
src/nostalgia/common/size.hpp
Normal file
192
src/nostalgia/common/size.hpp
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -108,7 +108,7 @@ int getScreenHeight(Context*) {
|
|||||||
return 160;
|
return 160;
|
||||||
}
|
}
|
||||||
|
|
||||||
common::Point getScreenSize(Context*) {
|
common::Size getScreenSize(Context*) {
|
||||||
return {240, 160};
|
return {240, 160};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <ox/std/types.hpp>
|
#include <ox/std/types.hpp>
|
||||||
#include <nostalgia/common/point.hpp>
|
#include <nostalgia/common/size.hpp>
|
||||||
|
|
||||||
#include "color.hpp"
|
#include "color.hpp"
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
@ -80,7 +80,7 @@ int getScreenWidth(Context *ctx);
|
|||||||
|
|
||||||
int getScreenHeight(Context *ctx);
|
int getScreenHeight(Context *ctx);
|
||||||
|
|
||||||
common::Point getScreenSize(Context *ctx);
|
common::Size getScreenSize(Context *ctx);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
uint8_t bgStatus(Context *ctx);
|
uint8_t bgStatus(Context *ctx);
|
||||||
|
@ -66,7 +66,7 @@ int getScreenHeight(Context *ctx) {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
common::Point getScreenSize(Context *ctx) {
|
common::Size getScreenSize(Context *ctx) {
|
||||||
auto id = ctx->windowerData<SdlImplData>();
|
auto id = ctx->windowerData<SdlImplData>();
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
SDL_GetWindowSize(id->window, &x, &y);
|
SDL_GetWindowSize(id->window, &x, &y);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user