mirror of
https://github.com/edubart/otclient.git
synced 2025-12-16 05:39:47 +01:00
reorganize all constants and place them into namespaces
This commit is contained in:
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011 OTClient <https://github.com/edubart/otclient>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "color.h"
|
||||
|
||||
Color Color::white (0xFF, 0xFF, 0xFF, 0xFF);
|
||||
Color Color::black (0x00, 0x00, 0x00, 0xFF);
|
||||
Color Color::alpha (0x00, 0x00, 0x00, 0x00);
|
||||
Color Color::red (0xFF, 0x00, 0x00, 0xFF);
|
||||
Color Color::green (0x00, 0xFF, 0x00, 0xFF);
|
||||
Color Color::blue (0x00, 0x00, 0xFF, 0xFF);
|
||||
Color Color::pink (0xFF, 0x00, 0xFF, 0xFF);
|
||||
Color Color::yellow(0xFF, 0xFF, 0x00, 0xFF);
|
||||
@@ -77,15 +77,6 @@ public:
|
||||
bool operator==(const Color& other) const { return other.color.rgba == color.rgba; }
|
||||
bool operator!=(const Color& other) const { return other.color.rgba != color.rgba; }
|
||||
|
||||
static Color white;
|
||||
static Color black;
|
||||
static Color alpha;
|
||||
static Color red;
|
||||
static Color green;
|
||||
static Color blue;
|
||||
static Color pink;
|
||||
static Color yellow;
|
||||
|
||||
private:
|
||||
RGBA color;
|
||||
};
|
||||
@@ -111,11 +102,11 @@ inline std::istream& operator>>(std::istream& in, Color& color)
|
||||
in >> tmp;
|
||||
|
||||
if(tmp.length() == 6 || tmp.length() == 8) {
|
||||
color.setRed((uint8)fw::hex2dec(tmp.substr(0, 2)));
|
||||
color.setGreen((uint8)fw::hex2dec(tmp.substr(2, 2)));
|
||||
color.setBlue((uint8)fw::hex2dec(tmp.substr(4, 2)));
|
||||
color.setRed((uint8)Fw::hex2dec(tmp.substr(0, 2)));
|
||||
color.setGreen((uint8)Fw::hex2dec(tmp.substr(2, 2)));
|
||||
color.setBlue((uint8)Fw::hex2dec(tmp.substr(4, 2)));
|
||||
if(tmp.length() == 8)
|
||||
color.setAlpha((uint8)fw::hex2dec(tmp.substr(6, 2)));
|
||||
color.setAlpha((uint8)Fw::hex2dec(tmp.substr(6, 2)));
|
||||
else
|
||||
color.setAlpha(255);
|
||||
} else
|
||||
|
||||
@@ -24,12 +24,7 @@
|
||||
#define SIZE_H
|
||||
|
||||
#include "point.h"
|
||||
|
||||
enum ESizeScaleMode {
|
||||
IGNORE_ASPECT_RATIO,
|
||||
KEEP_ASPECT_RATIO,
|
||||
KEEP_ASPECT_RATIO_BY_EXPANDING
|
||||
};
|
||||
#include "../const.h"
|
||||
|
||||
template<class T>
|
||||
class TSize
|
||||
@@ -74,17 +69,17 @@ public:
|
||||
TSize<T> expandedTo(const TSize<T>& other) const { return TSize<T>(std::max(wd,other.wd), std::max(ht,other.ht)); }
|
||||
TSize<T> boundedTo(const TSize<T>& other) const { return TSize<T>(std::min(wd,other.wd), std::min(ht,other.ht)); }
|
||||
|
||||
void scale(const TSize<T>& s, ESizeScaleMode mode) {
|
||||
if(mode == IGNORE_ASPECT_RATIO || wd == 0 || ht == 0) {
|
||||
void scale(const TSize<T>& s, Fw::AspectRatioMode mode) {
|
||||
if(mode == Fw::IgnoreAspectRatio || wd == 0 || ht == 0) {
|
||||
wd = s.wd;
|
||||
ht = s.ht;
|
||||
} else {
|
||||
bool useHeight;
|
||||
T rw = (s.ht * wd) / ht;
|
||||
|
||||
if(mode == KEEP_ASPECT_RATIO)
|
||||
if(mode == Fw::KeepAspectRatio)
|
||||
useHeight = (rw <= s.wd);
|
||||
else // mode == KEEP_ASPECT_RATIO_BY_EXPANDING
|
||||
else // mode == Fw::KeepAspectRatioByExpanding
|
||||
useHeight = (rw >= s.wd);
|
||||
|
||||
if(useHeight) {
|
||||
@@ -96,7 +91,7 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
void scale(int w, int h, ESizeScaleMode mode) { scale(TSize<T>(w, h)); }
|
||||
void scale(int w, int h, Fw::AspectRatioMode mode) { scale(TSize<T>(w, h)); }
|
||||
|
||||
float ratio() const { return (float)wd/ht; }
|
||||
T area() const { return wd*ht; }
|
||||
|
||||
@@ -31,22 +31,22 @@
|
||||
#include <cxxabi.h>
|
||||
#include "types.h"
|
||||
|
||||
namespace fw {
|
||||
namespace Fw {
|
||||
|
||||
// read utilities for istream
|
||||
inline uint8 getu8(std::istream& in) {
|
||||
inline uint8 getU8(std::istream& in) {
|
||||
uint8 tmp;
|
||||
in.read((char*)&tmp, 1);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline uint16 getu16(std::istream& in) {
|
||||
inline uint16 getU16(std::istream& in) {
|
||||
uint16 tmp;
|
||||
in.read((char*)&tmp, 2);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline uint32 getu32(std::istream& in) {
|
||||
inline uint32 getU32(std::istream& in) {
|
||||
uint32 tmp;
|
||||
in.read((char*)&tmp, 4);
|
||||
return tmp;
|
||||
@@ -54,21 +54,21 @@ inline uint32 getu32(std::istream& in) {
|
||||
|
||||
/// Fill an ostream by concatenating args
|
||||
/// Usage:
|
||||
/// fw::fill_ostream(stream, a1, a2, ..., aN);
|
||||
inline void fill_ostream(std::ostringstream&) { }
|
||||
/// Fw::fill_ostream(stream, a1, a2, ..., aN);
|
||||
inline void fillOstream(std::ostringstream&) { }
|
||||
template<class T, class... Args>
|
||||
void fill_ostream(std::ostringstream& stream, const T& first, const Args&... rest) {
|
||||
void fillOstream(std::ostringstream& stream, const T& first, const Args&... rest) {
|
||||
stream << first;
|
||||
fill_ostream(stream, rest...);
|
||||
fillOstream(stream, rest...);
|
||||
}
|
||||
|
||||
/// Makes a std::string by concatenating args
|
||||
/// Usage:
|
||||
/// std::string str = fw::mkstr(a1, a2, ..., aN);
|
||||
/// std::string str = Fw::mkstr(a1, a2, ..., aN);
|
||||
template<class... T>
|
||||
std::string mkstr(const T&... args) {
|
||||
std::ostringstream buf;
|
||||
fill_ostream(buf, args...);
|
||||
fillOstream(buf, args...);
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ struct dump_util {
|
||||
|
||||
/// Utility for dumping variables
|
||||
/// Usage:
|
||||
/// fw::dump << v1, v2, ..., vN;
|
||||
/// Fw::dump << v1, v2, ..., vN;
|
||||
struct dumper {
|
||||
dumper() { }
|
||||
template<class T>
|
||||
@@ -97,15 +97,15 @@ struct dumper {
|
||||
|
||||
/// Utility for printing messages into stdout
|
||||
/// Usage:
|
||||
/// fw::print(v1, v2, ..., vN);
|
||||
/// Fw::print(v1, v2, ..., vN);
|
||||
template<class... T>
|
||||
void print(const T&... args) {
|
||||
std::ostringstream buf;
|
||||
fill_ostream(buf, args...);
|
||||
fillOstream(buf, args...);
|
||||
std::cout << buf.str();
|
||||
}
|
||||
|
||||
/// Same as fw::print but adds a new line at the end
|
||||
/// Same as Fw::print but adds a new line at the end
|
||||
template<class... T>
|
||||
void println(const T&... args) {
|
||||
print(args...);
|
||||
@@ -113,7 +113,7 @@ void println(const T&... args) {
|
||||
}
|
||||
|
||||
/// Demangle names for GNU g++ compiler
|
||||
inline std::string demangle_name(const char* name) {
|
||||
inline std::string demangleName(const char* name) {
|
||||
size_t len;
|
||||
int status;
|
||||
std::string ret;
|
||||
@@ -126,10 +126,10 @@ inline std::string demangle_name(const char* name) {
|
||||
}
|
||||
|
||||
/// Returns the name of a type
|
||||
/// e.g. fw::demangle_type<Foo*>() returns a string containing 'Foo*'
|
||||
/// e.g. Fw::demangle_type<Foo*>() returns a string containing 'Foo*'
|
||||
template<typename T>
|
||||
std::string demangle_type() {
|
||||
return demangle_name(typeid(T).name());
|
||||
std::string demangleType() {
|
||||
return demangleName(typeid(T).name());
|
||||
}
|
||||
|
||||
/// Cast a type to another type
|
||||
@@ -185,27 +185,27 @@ inline bool cast(const bool& in, std::string& out) {
|
||||
}
|
||||
|
||||
// used by safe_cast
|
||||
class bad_cast : public std::bad_cast {
|
||||
class BadCast : public std::bad_cast {
|
||||
public:
|
||||
virtual ~bad_cast() throw() { }
|
||||
virtual ~BadCast() throw() { }
|
||||
template<class T, class R>
|
||||
void setWhat() {
|
||||
m_what = mkstr("failed to cast value of type '", demangle_type<T>(),
|
||||
"' to type '", demangle_type<R>(), "'");
|
||||
m_what = mkstr("failed to cast value of type '", demangleType<T>(),
|
||||
"' to type '", demangleType<R>(), "'");
|
||||
}
|
||||
virtual const char* what() { return m_what.c_str(); }
|
||||
private:
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
/// Cast a type to another type, any error throws a fw::bad_cast_exception
|
||||
/// Cast a type to another type, any error throws a Fw::bad_cast_exception
|
||||
/// Usage:
|
||||
/// R r = fw::safe_cast<R>(t);
|
||||
/// R r = Fw::safe_cast<R>(t);
|
||||
template<typename R, typename T>
|
||||
R safe_cast(const T& t) {
|
||||
R safeCast(const T& t) {
|
||||
R r;
|
||||
if(!cast(t, r)) {
|
||||
bad_cast e;
|
||||
BadCast e;
|
||||
e.setWhat<T,R>();
|
||||
throw e;
|
||||
}
|
||||
@@ -214,12 +214,12 @@ R safe_cast(const T& t) {
|
||||
|
||||
/// Cast a type to another type, cast errors are ignored
|
||||
/// Usage:
|
||||
/// R r = fw::unsafe_cast<R>(t);
|
||||
/// R r = Fw::unsafe_cast<R>(t);
|
||||
template<typename R, typename T>
|
||||
R unsafe_cast(const T& t, R def = R()) {
|
||||
R unsafeCast(const T& t, R def = R()) {
|
||||
try {
|
||||
return safe_cast<R,T>(t);
|
||||
} catch(bad_cast& e) {
|
||||
return safeCast<R,T>(t);
|
||||
} catch(BadCast& e) {
|
||||
println("CAST ERROR: ", e.what());
|
||||
return def;
|
||||
}
|
||||
@@ -227,12 +227,12 @@ R unsafe_cast(const T& t, R def = R()) {
|
||||
|
||||
template<typename T>
|
||||
std::string tostring(const T& t) {
|
||||
return unsafe_cast<std::string, T>(t);
|
||||
return unsafeCast<std::string, T>(t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T fromstring(const std::string& str, T def = T()) {
|
||||
return unsafe_cast<T, std::string>(str, def);
|
||||
return unsafeCast<T, std::string>(str, def);
|
||||
}
|
||||
|
||||
inline std::string dec2hex(unsigned int num) {
|
||||
@@ -261,7 +261,7 @@ const static std::string empty_string;
|
||||
|
||||
}
|
||||
|
||||
// shortcut for fw::dump
|
||||
const static fw::dumper dump;
|
||||
// shortcut for Fw::dump
|
||||
const static Fw::dumper dump;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,46 +23,46 @@
|
||||
#include "translator.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
AlignmentFlag fw::translateAlignment(std::string aligment)
|
||||
Fw::AlignmentFlag Fw::translateAlignment(std::string aligment)
|
||||
{
|
||||
boost::to_lower(aligment);
|
||||
boost::erase_all(aligment, " ");
|
||||
if(aligment == "topleft")
|
||||
return AlignTopLeft;
|
||||
return Fw::AlignTopLeft;
|
||||
else if(aligment == "topright")
|
||||
return AlignTopRight;
|
||||
return Fw::AlignTopRight;
|
||||
else if(aligment == "bottomleft")
|
||||
return AlignBottomLeft;
|
||||
return Fw::AlignBottomLeft;
|
||||
else if(aligment == "bottomright")
|
||||
return AlignBottomRight;
|
||||
return Fw::AlignBottomRight;
|
||||
else if(aligment == "left")
|
||||
return AlignLeftCenter;
|
||||
return Fw::AlignLeftCenter;
|
||||
else if(aligment == "right")
|
||||
return AlignRightCenter;
|
||||
return Fw::AlignRightCenter;
|
||||
else if(aligment == "top")
|
||||
return AlignTopCenter;
|
||||
return Fw::AlignTopCenter;
|
||||
else if(aligment == "bottom")
|
||||
return AlignBottomCenter;
|
||||
return Fw::AlignBottomCenter;
|
||||
else if(aligment == "center")
|
||||
return AlignCenter;
|
||||
return AlignNone;
|
||||
return Fw::AlignCenter;
|
||||
return Fw::AlignNone;
|
||||
}
|
||||
|
||||
AnchorEdge fw::translateAnchorEdge(std::string anchorEdge)
|
||||
Fw::AnchorEdge Fw::translateAnchorEdge(std::string anchorEdge)
|
||||
{
|
||||
boost::to_lower(anchorEdge);
|
||||
boost::erase_all(anchorEdge, " ");
|
||||
if(anchorEdge == "left")
|
||||
return AnchorLeft;
|
||||
return Fw::AnchorLeft;
|
||||
else if(anchorEdge == "right")
|
||||
return AnchorRight;
|
||||
return Fw::AnchorRight;
|
||||
else if(anchorEdge == "top")
|
||||
return AnchorTop;
|
||||
return Fw::AnchorTop;
|
||||
else if(anchorEdge == "bottom")
|
||||
return AnchorBottom;
|
||||
return Fw::AnchorBottom;
|
||||
else if(anchorEdge == "horizontalcenter")
|
||||
return AnchorHorizontalCenter;
|
||||
return Fw::AnchorHorizontalCenter;
|
||||
else if(anchorEdge == "verticalcenter")
|
||||
return AnchorVerticalCenter;
|
||||
return AnchorNone;
|
||||
return Fw::AnchorVerticalCenter;
|
||||
return Fw::AnchorNone;
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "../const.h"
|
||||
#include <string>
|
||||
|
||||
namespace fw {
|
||||
namespace Fw {
|
||||
|
||||
AlignmentFlag translateAlignment(std::string aligment);
|
||||
AnchorEdge translateAnchorEdge(std::string anchorEdge);
|
||||
|
||||
Reference in New Issue
Block a user