Magic_Game/core/e2dcommon.h

806 lines
13 KiB
C
Raw Normal View History

2017-10-12 02:44:44 +08:00
#pragma once
2018-04-21 21:24:46 +08:00
#include "e2dmacros.h"
namespace e2d
{
2017-10-12 02:44:44 +08:00
// <20><><EFBFBD><EFBFBD>
enum class Direction : int
{
2018-05-24 20:37:34 +08:00
Up, /* <20><> */
Down, /* <20><> */
Left, /* <20><> */
Right /* <20><> */
};
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0BDBB>ʽ
enum class LineJoin : int
{
2018-05-24 20:37:34 +08:00
Miter = 0, /* б<><D0B1> */
Bevel = 1, /* б<><D0B1> */
Round = 2 /* Բ<><D4B2> */
};
2018-05-22 22:55:06 +08:00
class Size;
2018-03-01 00:19:09 +08:00
// <20><><EFBFBD><EFBFBD>
class Point
2017-12-11 18:17:24 +08:00
{
public:
double x; // X <20><><EFBFBD><EFBFBD>
double y; // Y <20><><EFBFBD><EFBFBD>
public:
2018-03-01 00:19:09 +08:00
Point();
2017-12-11 18:17:24 +08:00
2018-03-01 00:19:09 +08:00
Point(double x, double y);
2017-12-11 18:17:24 +08:00
2018-05-22 23:36:46 +08:00
Point(const Point& other);
2018-05-22 22:55:06 +08:00
Point operator + (Point const & point) const;
Point operator - (Point const & point) const;
Point operator * (double const & point) const;
Point operator / (double const & point) const;
Point operator - () const;
2018-05-22 22:55:06 +08:00
bool operator== (const Point& point) const;
2017-12-11 18:17:24 +08:00
2018-03-01 19:28:22 +08:00
operator e2d::Size() const;
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static double distance(const Point&, const Point&);
2017-12-11 18:17:24 +08:00
};
2018-05-22 22:55:06 +08:00
// <20><>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>
2018-07-02 23:13:49 +08:00
typedef Point Vector2;
2018-05-22 22:55:06 +08:00
// <20><>С
class Size
2017-12-11 18:17:24 +08:00
{
public:
double width; // <20><><EFBFBD><EFBFBD>
double height; // <20>߶<EFBFBD>
public:
2018-03-01 00:19:09 +08:00
Size();
2017-12-11 18:17:24 +08:00
2018-03-01 00:19:09 +08:00
Size(double width, double height);
2017-12-11 18:17:24 +08:00
2018-05-22 23:36:46 +08:00
Size(const Size& other);
Size operator + (Size const & size) const;
Size operator - (Size const & size) const;
2018-05-22 22:55:06 +08:00
Size operator * (double const & size) const;
Size operator / (double const & size) const;
Size operator - () const;
2018-05-22 22:55:06 +08:00
bool operator== (const Size& size) const;
2017-12-11 18:17:24 +08:00
2018-03-01 19:28:22 +08:00
operator e2d::Point() const;
2017-12-11 18:17:24 +08:00
};
2018-02-03 22:04:43 +08:00
2018-05-22 22:55:06 +08:00
// <20><><EFBFBD><EFBFBD>
class Rect
{
public:
Point origin; // ԭ<><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Size size; // <20><><EFBFBD>Ⱥ͸߶<CDB8>
public:
Rect();
2018-05-22 23:36:46 +08:00
Rect(double x, double y, double width, double height);
2018-05-22 22:55:06 +08:00
2018-05-22 23:36:46 +08:00
Rect(const Point& pos, const Size& size);
2018-05-22 22:55:06 +08:00
2018-05-22 23:36:46 +08:00
Rect(const Rect& other);
2018-05-22 22:55:06 +08:00
2018-05-22 23:36:46 +08:00
Rect& operator= (const Rect& other);
2018-05-22 22:55:06 +08:00
2018-05-22 23:36:46 +08:00
bool operator== (const Rect& rect) const;
2018-05-22 22:55:06 +08:00
// <20><><EFBFBD>þ<EFBFBD><C3BE><EFBFBD>
void setRect(
double x,
double y,
double width,
double height
);
// <20>жϵ<D0B6><CFB5>Ƿ<EFBFBD><C7B7>ھ<EFBFBD><DABE><EFBFBD><EFBFBD><EFBFBD>
bool containsPoint(
const Point& point
) const;
// <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>
bool intersects(
const Rect& rect
) const;
};
2017-12-11 18:17:24 +08:00
// <20>ַ<EFBFBD><D6B7><EFBFBD>
2018-04-02 23:40:08 +08:00
class String
2017-12-11 18:17:24 +08:00
{
public:
String();
String(const String &);
2018-03-12 13:42:49 +08:00
String(const char *);
String(const wchar_t *);
String(String &&);
2017-12-11 18:17:24 +08:00
~String();
2017-12-11 18:17:24 +08:00
// <20>ж<EFBFBD><D0B6>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA>
2018-02-27 16:32:17 +08:00
bool isEmpty() const;
2017-12-11 18:17:24 +08:00
// <20><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-02-27 16:32:17 +08:00
int getLength() const;
2017-12-11 18:17:24 +08:00
2018-02-27 16:32:17 +08:00
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ɢ<EFBFBD><C9A2>ֵ
unsigned int getHashCode() const;
2017-12-11 18:17:24 +08:00
2018-03-12 13:42:49 +08:00
// <20><>ȡ Unicode <20>ַ<EFBFBD><D6B7><EFBFBD>
std::wstring getWString() const;
// <20><>ȡ ANSI <20>ַ<EFBFBD><D6B7><EFBFBD>
std::string getCString() const;
// <20><>ȡָ<C8A1><D6B8>λ<EFBFBD><CEBB><EFBFBD>ַ<EFBFBD>
wchar_t at(
int index
) const;
2018-05-01 17:19:55 +08:00
// <20>Ƚ<EFBFBD><C8BD>ַ<EFBFBD><D6B7><EFBFBD>
int compare(
const String & str
) const;
// <20><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
e2d::String subtract(
2018-02-28 19:17:15 +08:00
int offset, /* ƫ<><C6AB><EFBFBD><EFBFBD> */
int count = -1 /* <20><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD> */
) const;
2018-02-27 16:32:17 +08:00
2018-05-01 17:19:55 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
void insert(
const String & str,
int pos
);
// <20><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>е<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void replace(
const String & from, /* <20><><EFBFBD><EFBFBD><E6BBBB><EFBFBD><EFBFBD> */
const String & to /* <20><EFBFBD><E6BBBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
);
2018-02-27 16:32:17 +08:00
2018-05-01 17:19:55 +08:00
// ɾ<><C9BE><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>е<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void erase(
int offset, /* ƫ<><C6AB><EFBFBD><EFBFBD> */
int count /* ɾ<><C9BE><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD> */
);
// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
int find(
const String & str, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
int offset = 0 /* ƫ<><C6AB><EFBFBD><EFBFBD> */
2018-02-28 19:17:15 +08:00
) const;
2017-12-11 18:17:24 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
void clear();
2018-02-27 16:32:17 +08:00
// <20><>ȡ<EFBFBD><C8A1>д<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
String toUpper() const;
// <20><>ȡСд<D0A1>ַ<EFBFBD><D6B7><EFBFBD>
String toLower() const;
// <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA>Ϊ int <20><>
int toInt() const;
// <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA>Ϊ double <20><>
double toDouble() const;
// <20><><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ת<EFBFBD><D7AA>Ϊ bool <20><>
bool toBool() const;
2018-04-01 23:08:11 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
static String parse(int value);
static String parse(unsigned int value);
2018-04-01 23:08:11 +08:00
static String parse(float value);
static String parse(double value);
2018-03-22 18:25:56 +08:00
2018-04-01 23:08:11 +08:00
// <20><>ʽ<EFBFBD><CABD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
2018-04-17 11:41:33 +08:00
static String format(const char * format, ...);
static String format(const wchar_t * format, ...);
2018-02-28 19:17:15 +08:00
2018-05-01 17:19:55 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
static void swap(String &str1, String &str2);
2018-03-12 13:42:49 +08:00
// <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-02-28 19:17:15 +08:00
String& operator= (const String &);
2018-03-12 13:42:49 +08:00
String& operator= (const char *);
String& operator= (const wchar_t *);
2018-02-28 19:17:15 +08:00
2018-03-12 13:42:49 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
String& operator+= (const String &);
String& operator+= (const char *);
String& operator+= (const wchar_t *);
2018-02-28 19:17:15 +08:00
String operator+ (const String &);
2018-03-12 13:42:49 +08:00
String operator+ (const char *);
String operator+ (const wchar_t *);
2018-02-28 19:17:15 +08:00
2018-03-12 13:42:49 +08:00
// <20><>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-05-25 00:33:46 +08:00
friend String operator+ (const char *, const String &);
friend String operator+ (const wchar_t*, const String &);
2018-02-28 19:17:15 +08:00
2018-03-12 13:42:49 +08:00
// <20><><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
E2D_OP_EXPLICIT operator const wchar_t* () const;
E2D_OP_EXPLICIT operator wchar_t* () const;
E2D_OP_EXPLICIT operator const char* () const;
E2D_OP_EXPLICIT operator char* () const;
2018-02-28 19:17:15 +08:00
2018-03-12 13:42:49 +08:00
// <20>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-05-22 22:55:06 +08:00
bool operator== (const String &) const;
bool operator== (const char *) const;
bool operator== (const wchar_t *) const;
bool operator!= (const String &) const;
bool operator!= (const char *) const;
bool operator!= (const wchar_t *) const;
2018-02-28 19:17:15 +08:00
bool operator> (const String &) const;
bool operator>= (const String &) const;
bool operator< (const String &) const;
bool operator<= (const String &) const;
2018-03-12 15:55:41 +08:00
// << <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
String& operator<< (const String &);
2018-03-12 13:42:49 +08:00
String& operator<< (const char *);
String& operator<< (char *);
String& operator<< (const wchar_t *);
String& operator<< (wchar_t *);
2018-03-12 15:55:41 +08:00
String& operator<< (int value);
String& operator<< (unsigned int value);
2018-03-12 15:55:41 +08:00
String& operator<< (float value);
String& operator<< (double value);
2018-02-28 19:17:15 +08:00
2018-03-12 13:42:49 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-03-12 15:55:41 +08:00
wchar_t& operator[] (int);
2018-02-28 19:17:15 +08:00
2018-05-24 16:27:32 +08:00
friend std::ostream& operator<< (std::ostream &, const String &);
friend std::wostream& operator<< (std::wostream &, const String &);
2018-02-28 19:17:15 +08:00
2018-05-24 16:27:32 +08:00
friend std::istream& operator>> (std::istream &, String &);
friend std::wistream& operator>> (std::wistream &, String &);
2018-02-28 19:17:15 +08:00
2017-12-11 18:17:24 +08:00
private:
2018-05-08 17:40:36 +08:00
std::wstring _str;
2017-12-11 18:17:24 +08:00
};
2018-01-30 16:45:38 +08:00
2017-12-11 18:17:24 +08:00
// <20><>ɫ
class Color
2017-10-17 21:22:25 +08:00
{
public:
2018-04-22 14:08:29 +08:00
Color();
Color(
double r,
double g,
double b
);
Color(
double r,
double g,
double b,
double alpha
);
Color(
UINT rgb
2018-04-22 14:08:29 +08:00
);
Color(
UINT rgb,
2018-04-22 14:08:29 +08:00
double alpha
);
D2D1_COLOR_F toD2DColorF() const;
public:
2018-05-24 20:37:34 +08:00
enum Value : UINT
{
2018-05-24 20:37:34 +08:00
Black = 0x000000,
Blue = 0x0000FF,
BlueViolet = 0x8A2BE2,
Brown = 0xA52A2A,
Chocolate = 0xD2691E,
DarkBlue = 0x00008B,
DarkGray = 0xA9A9A9,
DarkGreen = 0x006400,
DarkOrange = 0xFF8C00,
DarkRed = 0x8B0000,
DarkViolet = 0x9400D3,
ForestGreen = 0x228B22,
Gold = 0xFFD700,
Gray = 0x808080,
Green = 0x008000,
GreenYellow = 0xADFF2F,
LightBlue = 0xADD8E6,
LightCyan = 0xE0FFFF,
LightGreen = 0x90EE90,
LightGray = 0xD3D3D3,
LightPink = 0xFFB6C1,
LightSeaGreen = 0x20B2AA,
LightSkyBlue = 0x87CEFA,
LightYellow = 0xFFFFE0,
Orange = 0xFFA500,
OrangeRed = 0xFF4500,
Pink = 0xFFC0CB,
Purple = 0x800080,
Red = 0xFF0000,
Silver = 0xC0C0C0,
SkyBlue = 0x87CEEB,
Snow = 0xFFFAFA,
Violet = 0xEE82EE,
Wheat = 0xF5DEB3,
White = 0xFFFFFF,
WhiteSmoke = 0xF5F5F5,
Wood = 0xDEB887,
Yellow = 0xFFFF00,
Yellow_Green = 0x9ACD32
};
2018-05-24 20:37:34 +08:00
private:
2018-04-22 14:08:29 +08:00
void _init(
UINT rgb,
double alpha
);
2018-05-24 20:37:34 +08:00
private:
2018-04-22 14:08:29 +08:00
float r;
float g;
float b;
float a;
};
2018-03-31 22:34:18 +08:00
2018-04-22 15:52:46 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class Function
{
public:
Function();
Function(
std::nullptr_t
);
Function(
std::function<void()> func
);
template<typename Func>
2018-05-08 17:40:36 +08:00
Function(Func func) : _func(func) {}
2018-04-22 15:52:46 +08:00
template<typename Func, typename Object>
Function(
Func&& func, /* <20><><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD> */
Object&& obj /* <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> */
2018-04-22 15:52:46 +08:00
)
{
2018-05-08 17:40:36 +08:00
_func = std::bind(func, obj);
2018-04-22 15:52:46 +08:00
}
void operator() (void) const;
E2D_OP_EXPLICIT operator bool() const;
2018-04-22 15:52:46 +08:00
protected:
2018-05-08 17:40:36 +08:00
std::function<void()> _func;
2018-04-22 15:52:46 +08:00
};
2018-05-22 22:00:47 +08:00
// <20><><EFBFBD><EFBFBD>
class Font
{
public:
String family; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double size; // <20>ֺ<EFBFBD>
UINT weight; // <20><>ϸֵ
bool italic; // б<><D0B1>
public:
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸֵ
enum Weight : UINT
{
2018-05-24 20:37:34 +08:00
Thin = 100,
ExtraLight = 200,
Light = 300,
Normal = 400,
Medium = 500,
Bold = 700,
ExtraBold = 800,
Black = 900,
ExtraBlack = 950
2018-05-22 22:00:47 +08:00
};
public:
Font();
2018-05-24 16:25:05 +08:00
explicit Font(
2018-05-22 22:00:47 +08:00
const String& family,
double size = 22,
2018-05-24 20:37:34 +08:00
UINT weight = Font::Weight::Normal,
2018-05-22 22:00:47 +08:00
bool italic = false
);
};
2018-02-03 22:04:43 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-03-03 11:46:57 +08:00
class Object
{
public:
2018-03-03 11:46:57 +08:00
Object();
2018-03-03 11:46:57 +08:00
virtual ~Object();
2018-05-15 23:59:58 +08:00
// <20>Զ<EFBFBD><D4B6>ͷ<EFBFBD>
void autorelease();
// <20><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
void retain();
2017-10-28 18:48:21 +08:00
// <20><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>һ
void release();
2018-03-03 17:02:08 +08:00
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>
int getRefCount() const;
// <20><><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>
virtual void onDestroy() {}
2018-03-03 17:02:08 +08:00
private:
int _refCount;
};
2017-10-28 18:48:21 +08:00
2018-02-03 22:04:43 +08:00
// ͼƬ
class Image :
2018-03-03 11:46:57 +08:00
public Object
{
public:
Image();
2018-05-24 16:25:05 +08:00
explicit Image(
const String& filePath /* ͼƬ<CDBC>ļ<EFBFBD>·<EFBFBD><C2B7> */
);
2018-05-24 16:25:05 +08:00
explicit Image(
int resNameId, /* ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
const String& resType /* ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
);
2018-05-24 16:25:05 +08:00
explicit Image(
2018-05-17 12:22:52 +08:00
const String& filePath, /* ͼƬ<CDBC>ļ<EFBFBD>·<EFBFBD><C2B7> */
2018-05-22 23:36:46 +08:00
const Rect& cropRect /* <20>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD> */
2018-05-14 00:36:01 +08:00
);
2018-05-24 16:25:05 +08:00
explicit Image(
2018-05-17 12:22:52 +08:00
int resNameId, /* ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
const String& resType, /* ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
2018-05-22 23:36:46 +08:00
const Rect& cropRect /* <20>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD> */
2018-05-17 12:22:52 +08:00
);
virtual ~Image();
// <20><><EFBFBD><EFBFBD>ͼƬ<CDBC>ļ<EFBFBD>
bool open(
2018-05-14 00:36:01 +08:00
const String& filePath /* ͼƬ<CDBC>ļ<EFBFBD>·<EFBFBD><C2B7> */
);
// <20><><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC>Դ
bool open(
int resNameId, /* ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
const String& resType /* ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
);
2018-04-06 11:31:24 +08:00
// <20><>ͼƬ<CDBC>ü<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
void crop(
2018-05-22 23:36:46 +08:00
const Rect& cropRect /* <20>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD> */
2018-03-02 23:49:57 +08:00
);
2018-02-03 22:04:43 +08:00
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
2018-02-27 21:07:43 +08:00
virtual double getWidth() const;
2018-02-03 22:04:43 +08:00
// <20><>ȡ<EFBFBD>߶<EFBFBD>
2018-02-27 21:07:43 +08:00
virtual double getHeight() const;
2018-02-03 22:04:43 +08:00
// <20><>ȡ<EFBFBD><C8A1>С
virtual Size getSize() const;
2018-02-03 22:04:43 +08:00
// <20><>ȡԴͼƬ<CDBC><C6AC><EFBFBD><EFBFBD>
2018-02-27 21:07:43 +08:00
virtual double getSourceWidth() const;
// <20><>ȡԴͼƬ<CDBC>߶<EFBFBD>
2018-02-27 21:07:43 +08:00
virtual double getSourceHeight() const;
// <20><>ȡԴͼƬ<CDBC><C6AC>С
virtual Size getSourceSize() const;
2018-02-03 22:04:43 +08:00
// <20><>ȡ<EFBFBD>ü<EFBFBD>λ<EFBFBD><CEBB> X <20><><EFBFBD><EFBFBD>
2018-04-06 11:31:24 +08:00
virtual double getCropX() const;
2018-02-03 22:04:43 +08:00
// <20><>ȡ<EFBFBD>ü<EFBFBD>λ<EFBFBD><CEBB> Y <20><><EFBFBD><EFBFBD>
2018-04-06 11:31:24 +08:00
virtual double getCropY() const;
2018-02-03 22:04:43 +08:00
// <20><>ȡ<EFBFBD>ü<EFBFBD>λ<EFBFBD><CEBB>
2018-04-06 11:31:24 +08:00
virtual Point getCropPos() const;
2018-02-03 22:04:43 +08:00
// <20><>ȡ ID2D1Bitmap <20><><EFBFBD><EFBFBD>
ID2D1Bitmap * getBitmap();
// Ԥ<><D4A4><EFBFBD><EFBFBD>ͼƬ<CDBC>ļ<EFBFBD>
static bool preload(
const String& filePath /* ͼƬ<CDBC>ļ<EFBFBD>·<EFBFBD><C2B7> */
);
// Ԥ<><D4A4><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC>Դ
static bool preload(
int resNameId, /* ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
const String& resType /* ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
);
// <20><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>
static void clearCache();
2018-05-14 00:36:01 +08:00
protected:
// <20><><EFBFBD><EFBFBD> Bitmap
void _setBitmap(
ID2D1Bitmap * bitmap
);
protected:
2018-05-22 23:36:46 +08:00
Rect _cropRect;
ID2D1Bitmap * _bitmap;
};
2018-01-30 16:45:38 +08:00
class Node;
class SceneManager;
class Transition;
2017-12-11 18:17:24 +08:00
2018-01-30 16:45:38 +08:00
// <20><><EFBFBD><EFBFBD>
class Scene :
2018-03-03 11:46:57 +08:00
public Object
2018-01-30 16:45:38 +08:00
{
2018-05-24 00:58:16 +08:00
friend class SceneManager;
friend class Transition;
2017-12-11 18:17:24 +08:00
2018-01-30 16:45:38 +08:00
public:
Scene();
2017-12-11 18:17:24 +08:00
virtual ~Scene();
2017-12-11 18:17:24 +08:00
2018-01-30 16:45:38 +08:00
// <20><>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Զ<EFBFBD>ִ<EFBFBD><D6B4>
virtual void onEnter() {}
2017-12-11 18:17:24 +08:00
2018-01-30 16:45:38 +08:00
// <20><>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBBFAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Զ<EFBFBD>ִ<EFBFBD><D6B4>
virtual void onExit() {}
2017-12-11 18:17:24 +08:00
2018-03-31 22:34:18 +08:00
// <20><>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹرմ<D8B1><D5B4><EFBFBD>ʱִ<CAB1>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD> false <20><><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ڹرգ<D8B1>
2018-01-30 16:45:38 +08:00
virtual bool onCloseWindow() { return true; }
2017-12-11 18:17:24 +08:00
2018-01-30 16:45:38 +08:00
// <20><>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ֡<D2BB><D6A1><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2>ʱִ<CAB1><D6B4>
virtual void onUpdate() {}
2017-12-11 18:17:24 +08:00
2018-02-03 22:04:43 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> onUpdate <20><><EFBFBD><EFBFBD>
2018-02-04 21:24:27 +08:00
void setAutoUpdate(
2018-02-03 22:04:43 +08:00
bool bAutoUpdate
);
// <20><><EFBFBD>ӽڵ㵽<DAB5><E3B5BD><EFBFBD><EFBFBD>
2018-03-03 11:46:57 +08:00
void add(
2018-04-01 00:04:33 +08:00
Node * child, /* Ҫ<><D2AA><EFBFBD>ӵĽڵ<C4BD> */
int zOrder = 0 /* <20><>Ⱦ˳<C8BE><CBB3> */
);
2018-04-01 13:16:07 +08:00
// <20><><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ڵ㵽<DAB5><E3B5BD><EFBFBD><EFBFBD>
2018-04-01 00:04:33 +08:00
virtual void add(
const std::vector<Node*>& nodes, /* <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> */
int order = 0 /* <20><>Ⱦ˳<C8BE><CBB3> */
2018-01-30 16:45:38 +08:00
);
// ɾ<><C9BE><EFBFBD>ӽڵ<D3BD>
bool remove(
Node * child
2018-01-30 16:45:38 +08:00
);
2018-04-24 13:28:21 +08:00
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ӽڵ<D3BD>
std::vector<Node*> get(
const String& name
2018-04-24 13:28:21 +08:00
) const;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ӽڵ<D3BD>
Node* getOne(
const String& name
2018-04-24 13:28:21 +08:00
) const;
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD>
2018-05-10 14:16:36 +08:00
const std::vector<Node*>& getAll() const;
2018-04-24 13:28:21 +08:00
2018-01-30 16:45:38 +08:00
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ڵ<EFBFBD>
Node * getRoot() const;
2018-01-30 16:45:38 +08:00
2018-04-01 13:16:07 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رսڵ<D5BD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱦ
void showCollider(
2018-04-01 13:16:07 +08:00
bool visiable = true
2018-01-30 16:45:38 +08:00
);
// <20><><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>
virtual void onDestroy() override;
2018-01-30 16:45:38 +08:00
protected:
// <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void _render();
// <20><><EFBFBD>³<EFBFBD><C2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void _update();
protected:
bool _autoUpdate;
bool _colliderVisiable;
Node * _root;
2018-01-30 16:45:38 +08:00
};
2017-12-11 18:17:24 +08:00
2018-02-03 22:04:43 +08:00
#if _MSC_VER > 1700
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4>Ķ<EFBFBD><C4B6><EFBFBD>
template <typename Type, typename... Args>
inline Type * Create(Args&&... args)
{
auto newObj = new (std::nothrow) Type(std::forward<Args>(args)...);
if (newObj)
{
newObj->autorelease();
return newObj;
}
return nullptr;
}
#else
template <typename Type>
inline Type * Create()
{
auto newObj = new (std::nothrow) Type();
if (newObj) { newObj->autorelease(); return newObj; }
return nullptr;
}
template <typename Type, typename Arg1>
inline Type * Create(Arg1&& arg1)
{
auto newObj = new (std::nothrow) Type(std::forward<Arg1>(arg1));
if (newObj) { newObj->autorelease(); return newObj; }
return nullptr;
}
template <typename Type,
typename Arg1,
typename Arg2>
inline Type * Create(
Arg1&& arg1,
Arg2&& arg2
)
{
auto newObj = new (std::nothrow) Type(
std::forward<Arg1>(arg1),
std::forward<Arg2>(arg2)
);
if (newObj) { newObj->autorelease(); return newObj; }
return nullptr;
}
template <typename Type,
typename Arg1,
typename Arg2,
typename Arg3>
inline Type * Create(
Arg1&& arg1,
Arg2&& arg2,
Arg3&& arg3
)
{
auto newObj = new (std::nothrow) Type(
std::forward<Arg1>(arg1),
std::forward<Arg2>(arg2),
std::forward<Arg3>(arg3)
);
if (newObj) { newObj->autorelease(); return newObj; }
return nullptr;
}
template <typename Type,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4>
inline Type * Create(
Arg1&& arg1,
Arg2&& arg2,
Arg3&& arg3,
Arg4&& arg4
)
{
auto newObj = new (std::nothrow) Type(
std::forward<Arg1>(arg1),
std::forward<Arg2>(arg2),
std::forward<Arg3>(arg3),
std::forward<Arg4>(arg4)
);
if (newObj) { newObj->autorelease(); return newObj; }
return nullptr;
}
template <typename Type,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4,
typename Arg5>
inline Type * Create(
Arg1&& arg1,
Arg2&& arg2,
Arg3&& arg3,
Arg4&& arg4,
Arg5&& arg5
)
{
auto newObj = new (std::nothrow) Type(
std::forward<Arg1>(arg1),
std::forward<Arg2>(arg2),
std::forward<Arg3>(arg3),
std::forward<Arg4>(arg4),
std::forward<Arg5>(arg5)
);
if (newObj) { newObj->autorelease(); return newObj; }
return nullptr;
}
template <typename Type,
typename Arg1,
typename Arg2,
typename Arg3,
typename Arg4,
typename Arg5,
typename Arg6>
inline Type * Create(
Arg1&& arg1,
Arg2&& arg2,
Arg3&& arg3,
Arg4&& arg4,
Arg5&& arg5,
Arg6&& arg6
)
{
auto newObj = new (std::nothrow) Type(
std::forward<Arg1>(arg1),
std::forward<Arg2>(arg2),
std::forward<Arg3>(arg3),
std::forward<Arg4>(arg4),
std::forward<Arg5>(arg5),
std::forward<Arg6>(arg6)
);
if (newObj) { newObj->autorelease(); return newObj; }
return nullptr;
}
#endif
}