Commit 1ff31583 authored by Screwtape's avatar Screwtape

Update to v104r13 release.

byuu says:

Changelog:

  - nall/GNUmakefile: build=release changed to -O2, build=optimize is
    now -O3
  - hiro: added Monitor::dpi(uint index) → Position [returns logical
    DPI for x, y]
      - Position is a bad name, but dpi(monitor).(x,y)() make more sense
        than .(width,height)()
  - hiro: Position, Size, Geometry, Font changed from using signed int
    to float
  - hiro: Alignment changed from using double to float
  - hiro: added skeleton (unused) Application::scale(), setScale()
    functions

Errata:

  - hiro/cocoa's Monitor::dpi() is untested. Probably will cause issues
    with macOS' automatic scaling.
  - hiro/gtk lacks a way to get both per-monitor and per-axis (x,y) DPI
    scaling
  - hiro/qt lacks a way to get per-monitor DPI scaling (Qt 5.x has this,
    but I still use Qt 4.x)
      - and just to get global DPI, hiro/qt's DPI retrieval has to use
        undocumented functions ... fun

The goal with this WIP was basically to prepare hiro for potential
automatic scaling. It'll be extremely difficult, but I'm convinced that
it must be possible if macOS can do it.

By moving from signed integers to floats for coordinates, we can now
scale and unscale without losing precision. That of course isn't the
hard part, though. The hard part is where and how to do the scaling. In
the ideal application, hiro/core and hiro/extension will handle 100% of
this, and the per-platform hiro/(cocoa,gtk,qt,windows) will not be aware
of what's going on, but ... to even make that possible, things will need
to change in every per-platform core, eg the per-platform code will have
to call a core function to change geometry, which will know about the
scaling and unscale the values back down again.

Gonna be a lot of work, but ... it's a start.
parent 2e4cd098
build := release
build := optimize
include ../nall/GNUmakefile
target := tomoko
......
......@@ -12,7 +12,7 @@ using namespace nall;
namespace Emulator {
static const string Name = "higan";
static const string Version = "104.12";
static const string Version = "104.13";
static const string Author = "byuu";
static const string License = "GPLv3";
static const string Website = "https://byuu.org/";
......
......@@ -8,6 +8,15 @@ auto pMonitor::count() -> uint {
}
}
auto pMonitor::dpi(uint monitor) -> Position {
@autoreleasepool {
NSScreen* screen = [[NSScreen screens] objectAtIndex:monitor];
NSDistionary* dictionary = [screen deviceDescription];
NSSize dpi = [[dictionary objectForKey:NSDeviceSize] sizeValue];
return {dpi.width, dpi.height};
}
}
auto pMonitor::geometry(uint monitor) -> Geometry {
@autoreleasepool {
NSRect rectangle = [[[NSScreen screens] objectAtIndex:monitor] frame];
......
......@@ -4,6 +4,7 @@ namespace hiro {
struct pMonitor {
static auto count() -> uint;
static auto dpi(uint monitor) -> Position;
static auto geometry(uint monitor) -> Geometry;
static auto primary() -> uint;
};
......
......@@ -4,7 +4,7 @@ Alignment::Alignment() {
setAlignment(-1.0, -1.0);
}
Alignment::Alignment(double horizontal, double vertical) {
Alignment::Alignment(float horizontal, float vertical) {
setAlignment(horizontal, vertical);
}
......@@ -13,7 +13,7 @@ Alignment::operator bool() const {
&& state.vertical >= 0.0 && state.vertical <= 1.0;
}
auto Alignment::horizontal() const -> double {
auto Alignment::horizontal() const -> float {
return state.horizontal;
}
......@@ -21,23 +21,23 @@ auto Alignment::reset() -> type& {
return setAlignment(-1.0, -1.0);
}
auto Alignment::setAlignment(double horizontal, double vertical) -> type& {
auto Alignment::setAlignment(float horizontal, float vertical) -> type& {
state.horizontal = horizontal;
state.vertical = vertical;
return *this;
}
auto Alignment::setHorizontal(double horizontal) -> type& {
auto Alignment::setHorizontal(float horizontal) -> type& {
state.horizontal = horizontal;
return *this;
}
auto Alignment::setVertical(double vertical) -> type& {
auto Alignment::setVertical(float vertical) -> type& {
state.vertical = vertical;
return *this;
}
auto Alignment::vertical() const -> double {
auto Alignment::vertical() const -> float {
return state.vertical;
}
......
......@@ -35,6 +35,14 @@ auto Application::quit() -> void {
return pApplication::quit();
}
auto Application::scale() -> float {
return state.scale;
}
auto Application::scale(float value) -> float {
return value * state.scale;
}
auto Application::setFont(const Font& font) -> void {
state.font = font;
}
......@@ -43,6 +51,10 @@ auto Application::setName(const string& name) -> void {
state.name = name;
}
auto Application::setScale(float scale) -> void {
state.scale = scale;
}
//Windows
//=======
......
......@@ -90,8 +90,8 @@ Declare(Viewport)
#undef Declare
enum class Orientation : unsigned { Horizontal, Vertical };
enum class Navigation : unsigned { Top, Bottom, Left, Right };
enum class Orientation : uint { Horizontal, Vertical };
enum class Navigation : uint { Top, Bottom, Left, Right };
#if defined(Hiro_Color)
struct Color {
......@@ -153,18 +153,18 @@ struct Alignment {
using type = Alignment;
Alignment();
Alignment(double horizontal, double vertical = 0.5);
Alignment(float horizontal, float vertical = 0.5);
explicit operator bool() const;
auto operator==(const Alignment& source) const -> bool;
auto operator!=(const Alignment& source) const -> bool;
auto horizontal() const -> double;
auto horizontal() const -> float;
auto reset() -> type&;
auto setAlignment(double horizontal = -1.0, double vertical = 0.5) -> type&;
auto setHorizontal(double horizontal) -> type&;
auto setVertical(double vertical) -> type&;
auto vertical() const -> double;
auto setAlignment(float horizontal = -1.0, float vertical = 0.5) -> type&;
auto setHorizontal(float horizontal) -> type&;
auto setVertical(float vertical) -> type&;
auto vertical() const -> float;
//private:
struct State {
......@@ -203,9 +203,9 @@ struct Position {
using type = Position;
Position();
Position(signed x, signed y);
Position(float x, float y);
template<typename X, typename Y>
Position(X x, Y y) : Position((signed)x, (signed)y) {}
Position(X x, Y y) : Position((float)x, (float)y) {}
explicit operator bool() const;
auto operator==(const Position& source) const -> bool;
......@@ -213,16 +213,16 @@ struct Position {
auto reset() -> type&;
auto setPosition(Position position = {}) -> type&;
auto setPosition(signed x, signed y) -> type&;
auto setX(signed x) -> type&;
auto setY(signed y) -> type&;
auto x() const -> signed;
auto y() const -> signed;
auto setPosition(float x, float y) -> type&;
auto setX(float x) -> type&;
auto setY(float y) -> type&;
auto x() const -> float;
auto y() const -> float;
//private:
struct State {
signed x;
signed y;
float x;
float y;
} state;
};
#endif
......@@ -232,29 +232,29 @@ struct Size {
using type = Size;
Size();
Size(signed width, signed height);
Size(float width, float height);
template<typename W, typename H>
Size(W width, H height) : Size((signed)width, (signed)height) {}
Size(W width, H height) : Size((float)width, (float)height) {}
explicit operator bool() const;
auto operator==(const Size& source) const -> bool;
auto operator!=(const Size& source) const -> bool;
auto height() const -> signed;
auto height() const -> float;
auto reset() -> type&;
auto setHeight(signed height) -> type&;
auto setHeight(float height) -> type&;
auto setSize(Size source = {}) -> type&;
auto setSize(signed width, signed height) -> type&;
auto setWidth(signed width) -> type&;
auto width() const -> signed;
auto setSize(float width, float height) -> type&;
auto setWidth(float width) -> type&;
auto width() const -> float;
static const signed Maximum = ~0; //~0 == -1
static const signed Minimum = 0;
static constexpr float Maximum = -1.0;
static constexpr float Minimum = +0.0;
//private:
struct State {
signed width;
signed height;
float width;
float height;
} state;
};
#endif
......@@ -265,39 +265,39 @@ struct Geometry {
Geometry();
Geometry(Position position, Size size);
Geometry(signed x, signed y, signed width, signed height);
Geometry(float x, float y, float width, float height);
template<typename X, typename Y, typename W, typename H>
Geometry(X x, Y y, W width, H height) : Geometry((signed)x, (signed)y, (signed)width, (signed)height) {}
Geometry(X x, Y y, W width, H height) : Geometry((float)x, (float)y, (float)width, (float)height) {}
explicit operator bool() const;
auto operator==(const Geometry& source) const -> bool;
auto operator!=(const Geometry& source) const -> bool;
auto height() const -> signed;
auto height() const -> float;
auto position() const -> Position;
auto reset() -> type&;
auto setGeometry(Geometry geometry = {}) -> type&;
auto setGeometry(Position position, Size size) -> type&;
auto setGeometry(signed x, signed y, signed width, signed height) -> type&;
auto setHeight(signed height) -> type&;
auto setGeometry(float x, float y, float width, float height) -> type&;
auto setHeight(float height) -> type&;
auto setPosition(Position position = {}) -> type&;
auto setPosition(signed x, signed y) -> type&;
auto setPosition(float x, float y) -> type&;
auto setSize(Size size = {}) -> type&;
auto setSize(signed width, signed height) -> type&;
auto setWidth(signed width) -> type&;
auto setX(signed x) -> type&;
auto setY(signed y) -> type&;
auto setSize(float width, float height) -> type&;
auto setWidth(float width) -> type&;
auto setX(float x) -> type&;
auto setY(float y) -> type&;
auto size() const -> Size;
auto width() const -> signed;
auto x() const -> signed;
auto y() const -> signed;
auto width() const -> float;
auto x() const -> float;
auto y() const -> float;
//private:
struct State {
signed x;
signed y;
signed width;
signed height;
float x;
float y;
float width;
float height;
} state;
};
#endif
......@@ -306,7 +306,7 @@ struct Geometry {
struct Font {
using type = Font;
Font(const string& family = "", unsigned size = 0);
Font(const string& family = "", float size = 0);
explicit operator bool() const;
auto operator==(const Font& source) const -> bool;
......@@ -319,8 +319,8 @@ struct Font {
auto setBold(bool bold = true) -> type&;
auto setFamily(const string& family = "") -> type&;
auto setItalic(bool italic = true) -> type&;
auto setSize(unsigned size = 0) -> type&;
auto size() const -> unsigned;
auto setSize(float size = 0) -> type&;
auto size() const -> float;
auto size(const string& text) const -> Size;
static const string Sans;
......@@ -330,7 +330,7 @@ struct Font {
//private:
struct State {
string family;
unsigned size;
float size;
bool bold;
bool italic;
} state;
......@@ -377,11 +377,14 @@ struct Application {
static auto name() -> string;
static auto onMain(const function<void ()>& callback = {}) -> void;
static auto run() -> void;
static auto scale() -> float;
static auto scale(float value) -> float;
static auto pendingEvents() -> bool;
static auto processEvents() -> void;
static auto quit() -> void;
static auto setFont(const Font& font = {}) -> void;
static auto setName(const string& name = "") -> void;
static auto setScale(float scale = 1.0) -> void;
struct Windows {
static auto doModalChange(bool modal) -> void;
......@@ -405,6 +408,7 @@ struct Application {
string name;
function<void ()> onMain;
bool quit = false;
float scale = 1.0;
struct Windows {
function<void (bool)> onModalChange;
......@@ -435,9 +439,10 @@ struct Desktop {
struct Monitor {
Monitor() = delete;
static auto count() -> unsigned;
static auto geometry(unsigned monitor) -> Geometry;
static auto primary() -> unsigned;
static auto count() -> uint;
static auto dpi(uint monitor) -> Position;
static auto geometry(uint monitor) -> Geometry;
static auto primary() -> uint;
};
#endif
......@@ -1680,7 +1685,7 @@ struct mTableViewColumn : mObject {
auto editable() const -> bool;
auto expandable() const -> bool;
auto foregroundColor() const -> Color;
auto horizontalAlignment() const -> double;
auto horizontalAlignment() const -> float;
auto icon() const -> image;
auto remove() -> type& override;
auto resizable() const -> bool;
......@@ -1690,18 +1695,18 @@ struct mTableViewColumn : mObject {
auto setEditable(bool editable = true) -> type&;
auto setExpandable(bool expandable = true) -> type&;
auto setForegroundColor(Color color = {}) -> type&;
auto setHorizontalAlignment(double alignment = 0.0) -> type&;
auto setHorizontalAlignment(float alignment = 0.0) -> type&;
auto setIcon(const image& icon = {}) -> type&;
auto setResizable(bool resizable = true) -> type&;
auto setSortable(bool sortable = true) -> type&;
auto setText(const string& text = "") -> type&;
auto setVerticalAlignment(double alignment = 0.5) -> type&;
auto setVerticalAlignment(float alignment = 0.5) -> type&;
auto setVisible(bool visible = true) -> type&;
auto setWidth(signed width = 0) -> type&;
auto setWidth(float width = 0) -> type&;
auto sortable() const -> bool;
auto text() const -> string;
auto verticalAlignment() const -> double;
auto width() const -> signed;
auto verticalAlignment() const -> float;
auto width() const -> float;
//private:
struct State {
......@@ -1710,14 +1715,14 @@ struct mTableViewColumn : mObject {
bool editable = false;
bool expandable = false;
Color foregroundColor;
double horizontalAlignment = 0.0;
float horizontalAlignment = 0.0;
image icon;
bool resizable = true;
bool sortable = false;
string text;
double verticalAlignment = 0.5;
float verticalAlignment = 0.5;
bool visible = true;
signed width = 0;
float width = 0;
} state;
};
#endif
......
......@@ -4,7 +4,7 @@ const string Font::Sans = "{sans}";
const string Font::Serif = "{serif}";
const string Font::Mono = "{mono}";
Font::Font(const string& family, unsigned size) {
Font::Font(const string& family, float size) {
setFamily(family);
setSize(size);
state.bold = false;
......@@ -58,12 +58,12 @@ auto Font::setItalic(bool italic) -> type& {
return *this;
}
auto Font::setSize(unsigned size) -> type& {
auto Font::setSize(float size) -> type& {
state.size = size;
return *this;
}
auto Font::size() const -> unsigned {
auto Font::size() const -> float {
return state.size;
}
......
......@@ -8,7 +8,7 @@ Geometry::Geometry(Position position, Size size) {
setGeometry(position, size);
}
Geometry::Geometry(signed x, signed y, signed width, signed height) {
Geometry::Geometry(float x, float y, float width, float height) {
setGeometry(x, y, width, height);
}
......@@ -24,7 +24,7 @@ auto Geometry::operator!=(const Geometry& source) const -> bool {
return !operator==(source);
}
auto Geometry::height() const -> signed {
auto Geometry::height() const -> float {
return state.height;
}
......@@ -36,7 +36,7 @@ auto Geometry::reset() -> type& {
return setGeometry(0, 0, 0, 0);
}
auto Geometry::setHeight(signed height) -> type& {
auto Geometry::setHeight(float height) -> type& {
state.height = height;
return *this;
}
......@@ -50,7 +50,7 @@ auto Geometry::setGeometry(Position position, Size size) -> type& {
return *this;
}
auto Geometry::setGeometry(signed x, signed y, signed width, signed height) -> type& {
auto Geometry::setGeometry(float x, float y, float width, float height) -> type& {
state.x = x;
state.y = y;
state.width = width;
......@@ -62,7 +62,7 @@ auto Geometry::setPosition(Position position) -> type& {
return setPosition(position.x(), position.y());
}
auto Geometry::setPosition(signed x, signed y) -> type& {
auto Geometry::setPosition(float x, float y) -> type& {
state.x = x;
state.y = y;
return *this;
......@@ -72,23 +72,23 @@ auto Geometry::setSize(Size size) -> type& {
return setSize(size.width(), size.height());
}
auto Geometry::setSize(signed width, signed height) -> type& {
auto Geometry::setSize(float width, float height) -> type& {
state.width = width;
state.height = height;
return *this;
}
auto Geometry::setWidth(signed width) -> type& {
auto Geometry::setWidth(float width) -> type& {
state.width = width;
return *this;
}
auto Geometry::setX(signed x) -> type& {
auto Geometry::setX(float x) -> type& {
state.x = x;
return *this;
}
auto Geometry::setY(signed y) -> type& {
auto Geometry::setY(float y) -> type& {
state.y = y;
return *this;
}
......@@ -97,15 +97,15 @@ auto Geometry::size() const -> Size {
return {state.width, state.height};
}
auto Geometry::width() const -> signed {
auto Geometry::width() const -> float {
return state.width;
}
auto Geometry::x() const -> signed {
auto Geometry::x() const -> float {
return state.x;
}
auto Geometry::y() const -> signed {
auto Geometry::y() const -> float {
return state.y;
}
......
#if defined(Hiro_Monitor)
auto Monitor::count() -> unsigned {
auto Monitor::count() -> uint {
return pMonitor::count();
}
auto Monitor::geometry(unsigned monitor) -> Geometry {
auto Monitor::dpi(uint monitor) -> Position {
return pMonitor::dpi(monitor);
}
auto Monitor::geometry(uint monitor) -> Geometry {
return pMonitor::geometry(monitor);
}
auto Monitor::primary() -> unsigned {
auto Monitor::primary() -> uint {
return pMonitor::primary();
}
......
......@@ -4,7 +4,7 @@ Position::Position() {
setPosition(0, 0);
}
Position::Position(signed x, signed y) {
Position::Position(float x, float y) {
setPosition(x, y);
}
......@@ -28,27 +28,27 @@ auto Position::setPosition(Position position) -> type& {
return setPosition(position.x(), position.y());
}
auto Position::setPosition(signed x, signed y) -> type& {
auto Position::setPosition(float x, float y) -> type& {
state.x = x;
state.y = y;
return *this;
}
auto Position::setX(signed x) -> type& {
auto Position::setX(float x) -> type& {
state.x = x;
return *this;
}
auto Position::setY(signed y) -> type& {
auto Position::setY(float y) -> type& {
state.y = y;
return *this;
}
auto Position::x() const -> signed {
auto Position::x() const -> float {
return state.x;
}
auto Position::y() const -> signed {
auto Position::y() const -> float {
return state.y;
}
......
......@@ -648,11 +648,13 @@ struct TableViewColumn : sTableViewColumn {
auto setEditable(bool editable = true) { return self().setEditable(editable), *this; }
auto setExpandable(bool expandable = true) { return self().setExpandable(expandable), *this; }
auto setForegroundColor(Color color = {}) { return self().setForegroundColor(color), *this; }
auto setHorizontalAlignment(float alignment = 0.0) { return self().setHorizontalAlignment(alignment), *this; }
auto setIcon(const image& icon = {}) { return self().setIcon(icon), *this; }
auto setResizable(bool resizable = true) { return self().setResizable(resizable), *this; }
auto setSortable(bool sortable = true) { return self().setSortable(sortable), *this; }
auto setText(const string& text = "") { return self().setText(text), *this; }
auto setWidth(signed width = 0) { return self().setWidth(width), *this; }
auto setVerticalAlignment(float alignment = 0.5) { return self().setVerticalAlignment(alignment), *this; }
auto setWidth(float width = 0) { return self().setWidth(width), *this; }
auto sortable() const { return self().sortable(); }
auto text() const { return self().text(); }
auto verticalAlignment() const { return self().verticalAlignment(); }
......
......@@ -4,7 +4,7 @@ Size::Size() {
setSize(0, 0);
}
Size::Size(signed width, signed height) {
Size::Size(float width, float height) {
setSize(width, height);
}
......@@ -20,7 +20,7 @@ auto Size::operator!=(const Size& source) const -> bool {
return !operator==(source);
}
auto Size::height() const -> signed {
auto Size::height() const -> float {
return state.height;
}
......@@ -28,7 +28,7 @@ auto Size::reset() -> type& {
return setSize(0, 0);
}
auto Size::setHeight(signed height) -> type& {
auto Size::setHeight(float height) -> type& {
state.height = height;
return *this;
}
......@@ -37,18 +37,18 @@ auto Size::setSize(Size size) -> type& {
return setSize(size.width(), size.height());
}
auto Size::setSize(signed width, signed height) -> type& {
auto Size::setSize(float width, float height) -> type& {
state.width = width;
state.height = height;
return *this;
}
auto Size::setWidth(signed width) -> type& {
auto Size::setWidth(float width) -> type& {
state.width = width;
return *this;
}
auto Size::width() const -> signed {
auto Size::width() const -> float {
return state.width;
}
......
......@@ -31,7 +31,7 @@ auto mTableViewColumn::foregroundColor() const -> Color {
return state.foregroundColor;
}
auto mTableViewColumn::horizontalAlignment() const -> double {
auto mTableViewColumn::horizontalAlignment() const -> float {
return state.horizontalAlignment;
}
......@@ -84,7 +84,7 @@ auto mTableViewColumn::setForegroundColor(Color color) -> type& {
return *this;
}
auto mTableViewColumn::setHorizontalAlignment(double alignment) -> type& {
auto mTableViewColumn::setHorizontalAlignment(float alignment) -> type& {
alignment = max(0.0, min(1.0, alignment));
state.horizontalAlignment = alignment;
signal(setHorizontalAlignment, alignment);
......@@ -115,7 +115,7 @@ auto mTableViewColumn::setText(const string& text) -> type& {
return *this;
}
auto mTableViewColumn::setVerticalAlignment(double alignment) -> type& {
auto mTableViewColumn::setVerticalAlignment(float alignment) -> type& {
alignment = max(0.0, min(1.0, alignment));
state.verticalAlignment = alignment;
signal(setVerticalAlignment, alignment);
......@@ -128,7 +128,7 @@ auto mTableViewColumn::setVisible(bool visible) -> type& {
return *this;
}
auto mTableViewColumn::setWidth(signed width) -> type& {
auto mTableViewColumn::setWidth(float width) -> type& {
state.width = max(0, width);
signal(setWidth, width);
return *this;
......@@ -142,11 +142,11 @@ auto mTableViewColumn::text() const -> string {
return state.text;
}
auto mTableViewColumn::verticalAlignment() const -> double {
auto mTableViewColumn::verticalAlignment() const -> float {
return state.verticalAlignment;
}
auto mTableViewColumn::width() const -> signed {
auto mTableViewColumn::width() const -> float {
return state.width;
}
......
......@@ -16,7 +16,7 @@ auto mFixedLayout::modify(sSizable sizable, Geometry geometry) -> type& {
}
auto mFixedLayout::minimumSize() const -> Size {
signed width = Size::Minimum, height = Size::Minimum;
float width = Size::Minimum, height = Size::Minimum;
for(auto n : range(sizableCount())) {
width = max(width, sizable(n)->minimumSize().width());
height = max(height, sizable(n)->minimumSize().height());
......
......@@ -14,10 +14,10 @@ struct mFixedLayout : mLayout {
auto setFont(const Font& font = {}) -> type& override;
auto setVisible(bool visible = true) ->type& override;
struct Properties {
struct Property {
Geometry geometry;
};