This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
forked from abodelot/sfml-widgets
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Refined Geometry.hpp
- Loading branch information
Showing
10 changed files
with
80 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,66 @@ | ||
#ifndef SFW_GEOMETRY_HPP | ||
#define SFW_GEOMETRY_HPP | ||
|
||
#include "sfw/util/generic.hpp" // using sfw::Unknown, sfw::UseDefault; | ||
|
||
namespace sfw | ||
{ | ||
/* | ||
2D (on-screen) orientation of geometric entities | ||
enum Orientation | ||
{ | ||
Horizontal, | ||
Vertical | ||
}; | ||
- The interpretation of Horizontal|Vertical combinations as "diagonal" | ||
is intentionally undefined here.) | ||
*/ | ||
struct Orientation // `enum class Orientation` would forbid all the num. ops. (despite the :int)! | ||
//!! This is the best trade-off between the namespace pollution of plain | ||
//!! enums and the overly restrictive & cumbersome enum classes. This way | ||
//!! there's no mandatory `Orientation::` qualifiers, but only for selected | ||
//!! names, where that makes sense. Also, implicit num. conversions work. | ||
{ | ||
enum _symbolic_ { | ||
Unknown = sfw::Unknown, | ||
UseDefault = sfw::UseDefault, | ||
// `Default` would be hopelessly ambiguous: should it directly | ||
// encode a value (like `Horizontal`), and then remain hardcoded | ||
// + possibly too context-specific forever, or should it have a | ||
// dedicated pseudo-value meaning "use the actually configured | ||
// default for the given usage context"?... | ||
|
||
Horizontal = 1, | ||
Vertical = Horizontal << 1, // Support Horizontal|Vertical | ||
|
||
Directed = 1 << 4, | ||
Leftward = Directed | Horizontal, | ||
Rightward = Directed | Horizontal | (Directed << 1), | ||
Upward = Directed | Vertical, | ||
Downward = Directed | Vertical | (Directed << 1), | ||
}; | ||
|
||
Orientation() : value(Unknown) {} | ||
Orientation(_symbolic_ x) : value(x) {} | ||
|
||
operator _symbolic_() const { return value; } | ||
//!!Unfortunately, this doesn't alleviate the need for an op= and op!=: | ||
// operator int() { return value; } | ||
bool operator ==(_symbolic_ x) const { return x == value; } | ||
bool operator !=(_symbolic_ x) const { return x != value; } | ||
|
||
_symbolic_ value; | ||
}; | ||
|
||
// Emulate (only the "good parts"!) of a plain enum version... | ||
// (Note: an enum class can't be `using`ed into scope all at once, | ||
// only its values one by one. :-/ ) | ||
using Orientation::Horizontal, Orientation::Vertical, | ||
//Orientation::Directed, // <- This one's kinda internal. | ||
Orientation::Leftward, Orientation::Rightward, Orientation::Upward, Orientation::Downward; | ||
|
||
// Sanity chk.: | ||
static_assert((int)Unknown != UseDefault); | ||
static_assert((int)Unknown != Horizontal); | ||
static_assert((int)UseDefault != Horizontal); | ||
static_assert(Orientation::Directed > (Horizontal|Vertical)); | ||
|
||
} | ||
} // namespace | ||
|
||
#endif // SFW_GEOMETRY_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef SFW_GENERIC_HPP | ||
#define SFW_GENERIC_HPP | ||
|
||
namespace sfw | ||
{ | ||
enum : int | ||
{ | ||
Unknown = 0, | ||
UseDefault = -1, | ||
}; | ||
} | ||
|
||
#endif // SFW_GENERIC_HPP |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters