2018-11-08 21:39:26 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Easy2D - Nomango
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2018-11-16 15:53:39 +08:00
|
|
|
|
#include "base.hpp"
|
2018-11-14 16:39:24 +08:00
|
|
|
|
#include "time.h"
|
2018-11-20 01:20:06 +08:00
|
|
|
|
#include "Unit.h"
|
2018-11-08 21:39:26 +08:00
|
|
|
|
#include "KeyEvent.h"
|
|
|
|
|
|
#include "MouseEvent.h"
|
2018-11-15 23:40:13 +08:00
|
|
|
|
#include "ActionManager.h"
|
|
|
|
|
|
#include "TaskManager.h"
|
2018-11-16 15:53:39 +08:00
|
|
|
|
#include "intrusive/List.hpp"
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
|
|
|
|
|
namespace easy2d
|
|
|
|
|
|
{
|
|
|
|
|
|
class Game;
|
|
|
|
|
|
|
|
|
|
|
|
// <20>ڵ<EFBFBD>
|
|
|
|
|
|
class Node
|
2018-11-20 01:20:06 +08:00
|
|
|
|
: public Unit
|
2018-11-14 16:39:24 +08:00
|
|
|
|
, public ActionManager
|
|
|
|
|
|
, public TaskManager
|
2018-11-16 15:53:39 +08:00
|
|
|
|
, protected intrusive::ListItem<spNode>
|
2018-11-08 21:39:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
friend class Game;
|
|
|
|
|
|
friend class Scene;
|
2018-11-14 16:39:24 +08:00
|
|
|
|
friend class Transition;
|
2018-11-16 15:53:39 +08:00
|
|
|
|
friend class intrusive::List<spNode>;
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-16 15:53:39 +08:00
|
|
|
|
using Nodes = std::vector<spNode>;
|
|
|
|
|
|
using Children = intrusive::List<spNode>;
|
2018-11-15 23:40:13 +08:00
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
public:
|
|
|
|
|
|
Node();
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~Node();
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>Ⱦ<EFBFBD>ڵ<EFBFBD>
|
2018-11-16 16:16:16 +08:00
|
|
|
|
virtual void OnDraw() {}
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>½ڵ<C2BD>
|
2018-11-14 16:39:24 +08:00
|
|
|
|
virtual void OnUpdate(Duration const& dt) {}
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>ʾ״̬
|
2018-11-18 20:26:41 +08:00
|
|
|
|
bool IsVisible() const { return visible_; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
2018-11-18 20:26:41 +08:00
|
|
|
|
String const& GetName() const { return name_; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>Ƶ<EFBFBD> Hash ֵ
|
2018-11-18 20:26:41 +08:00
|
|
|
|
size_t GetHashName() const { return hash_name_; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>ͼ˳<CDBC><CBB3>
|
2018-11-18 20:26:41 +08:00
|
|
|
|
int GetOrder() const { return order_; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
virtual float GetWidth() const { return size_.width * transform_.scale.x; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD>߶<EFBFBD>
|
|
|
|
|
|
virtual float GetHeight() const { return size_.height * transform_.scale.y; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>С
|
2018-11-18 20:26:41 +08:00
|
|
|
|
Size GetSize() const { return Size{ GetWidth(), GetHeight() }; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ x <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>
|
|
|
|
|
|
virtual float GetPivotX() const { return pivot_.x; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ y <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>
|
|
|
|
|
|
virtual float GetPivotY() const { return pivot_.y; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<C8A1><CDB8><EFBFBD><EFBFBD>
|
2018-11-18 20:26:41 +08:00
|
|
|
|
virtual float GetOpacity() const { return opacity_; }
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-16 16:16:16 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>Χ<EFBFBD><CEA7>
|
|
|
|
|
|
virtual Rect GetBounds();
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>ά<EFBFBD>任<EFBFBD><E4BBBB><EFBFBD><EFBFBD>
|
|
|
|
|
|
virtual math::Matrix const& GetTransformMatrix() override;
|
|
|
|
|
|
|
2018-11-18 20:26:41 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ڵ<EFBFBD>
|
|
|
|
|
|
virtual spNode GetParent() const { return parent_; }
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ
|
2018-11-08 21:39:26 +08:00
|
|
|
|
void SetVisible(
|
2018-11-11 16:32:12 +08:00
|
|
|
|
bool val
|
2018-11-08 21:39:26 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-11-08 21:39:26 +08:00
|
|
|
|
void SetName(
|
2018-11-17 17:15:32 +08:00
|
|
|
|
String const& name
|
2018-11-08 21:39:26 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
// Ĭ<><C4AC>Ϊ 0, <20><>Χ [0, 1]
|
2018-11-14 16:39:24 +08:00
|
|
|
|
void SetPivotX(
|
2018-11-08 21:39:26 +08:00
|
|
|
|
float pivot_x
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
|
|
|
|
|
// Ĭ<><C4AC>Ϊ 0, <20><>Χ [0, 1]
|
2018-11-14 16:39:24 +08:00
|
|
|
|
void SetPivotY(
|
2018-11-08 21:39:26 +08:00
|
|
|
|
float pivot_y
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>λ<EFBFBD><CEBB>
|
|
|
|
|
|
// Ĭ<><C4AC>Ϊ (0, 0), <20><>Χ [0, 1]
|
|
|
|
|
|
virtual void SetPivot(
|
|
|
|
|
|
float pivot_x,
|
|
|
|
|
|
float pivot_y
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20>Ŀ<DEB8><C4BF><EFBFBD>
|
2018-11-18 20:26:41 +08:00
|
|
|
|
void SetWidth(
|
2018-11-08 21:39:26 +08:00
|
|
|
|
float width
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20>ĸ߶<C4B8>
|
2018-11-14 16:39:24 +08:00
|
|
|
|
void SetHeight(
|
2018-11-08 21:39:26 +08:00
|
|
|
|
float height
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20>Ĵ<DEB8>С
|
2018-11-14 16:39:24 +08:00
|
|
|
|
void SetSize(
|
2018-11-08 21:39:26 +08:00
|
|
|
|
float width,
|
|
|
|
|
|
float height
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20>Ĵ<DEB8>С
|
2018-11-14 16:39:24 +08:00
|
|
|
|
void SetSize(
|
2018-11-08 21:39:26 +08:00
|
|
|
|
const Size & size
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
virtual void SetTransform(
|
|
|
|
|
|
Transform const& transform
|
|
|
|
|
|
) override;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><CDB8><EFBFBD><EFBFBD>
|
|
|
|
|
|
// Ĭ<><C4AC>Ϊ 1.0, <20><>Χ [0, 1]
|
|
|
|
|
|
void SetOpacity(
|
|
|
|
|
|
float opacity
|
2018-11-08 21:39:26 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><><EFBFBD>û<EFBFBD>ͼ˳<CDBC><CBB3>
|
|
|
|
|
|
// Ĭ<><C4AC>Ϊ 0
|
|
|
|
|
|
void SetOrder(
|
|
|
|
|
|
int order
|
|
|
|
|
|
);
|
2018-11-14 16:39:24 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
// <20><><EFBFBD>ñ߿<C3B1><DFBF><EFBFBD>ɫ
|
|
|
|
|
|
void SetBorderColor(
|
|
|
|
|
|
const Color& color
|
2018-11-14 16:39:24 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
// <20>жϵ<D0B6><CFB5>Ƿ<EFBFBD><C7B7>ڽڵ<DABD><DAB5><EFBFBD>
|
|
|
|
|
|
bool ContainsPoint(
|
|
|
|
|
|
const Point& point
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ӽڵ<D3BD>
|
|
|
|
|
|
void AddChild(
|
2018-11-14 01:34:41 +08:00
|
|
|
|
spNode const& child,
|
2018-11-08 21:39:26 +08:00
|
|
|
|
int order = 0 /* <20><>Ⱦ˳<C8BE><CBB3> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD>ӽڵ<D3BD>
|
|
|
|
|
|
void AddChild(
|
|
|
|
|
|
const Nodes& nodes, /* <20>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
|
int order = 0 /* <20><>Ⱦ˳<C8BE><CBB3> */
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ӽڵ<D3BD>
|
|
|
|
|
|
Nodes GetChildren(
|
2018-11-17 17:15:32 +08:00
|
|
|
|
String const& name
|
2018-11-08 21:39:26 +08:00
|
|
|
|
) const;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ӽڵ<D3BD>
|
2018-11-14 01:34:41 +08:00
|
|
|
|
spNode GetChild(
|
2018-11-17 17:15:32 +08:00
|
|
|
|
String const& name
|
2018-11-08 21:39:26 +08:00
|
|
|
|
) const;
|
|
|
|
|
|
|
2018-11-15 23:40:13 +08:00
|
|
|
|
// <20><>ȡȫ<C8A1><C8AB><EFBFBD>ӽڵ<D3BD>
|
|
|
|
|
|
Children const& GetChildren() const;
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3>ӽڵ<D3BD>
|
|
|
|
|
|
bool RemoveChild(
|
2018-11-14 01:34:41 +08:00
|
|
|
|
spNode const& child
|
2018-11-08 21:39:26 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>ӽڵ<D3BD>
|
|
|
|
|
|
void RemoveChildren(
|
2018-11-17 17:15:32 +08:00
|
|
|
|
String const& child_name
|
2018-11-08 21:39:26 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>нڵ<D0BD>
|
|
|
|
|
|
void RemoveAllChildren();
|
|
|
|
|
|
|
|
|
|
|
|
// <20>Ӹ<EFBFBD><D3B8>ڵ<EFBFBD><DAB5>Ƴ<EFBFBD>
|
|
|
|
|
|
void RemoveFromParent();
|
|
|
|
|
|
|
2018-11-15 14:35:19 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>֧<EFBFBD><D6A7>
|
|
|
|
|
|
static void SetDefaultPivot(
|
|
|
|
|
|
float pivot_x,
|
|
|
|
|
|
float pivot_y
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
virtual void Visit();
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool Dispatch(
|
|
|
|
|
|
const MouseEvent& e,
|
|
|
|
|
|
bool handled
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
virtual bool Dispatch(
|
|
|
|
|
|
const KeyEvent& e,
|
|
|
|
|
|
bool handled
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-11-14 16:39:24 +08:00
|
|
|
|
protected:
|
2018-11-16 16:16:16 +08:00
|
|
|
|
virtual void Update(Duration const& dt);
|
2018-11-08 21:39:26 +08:00
|
|
|
|
|
2018-11-20 01:20:06 +08:00
|
|
|
|
virtual void DrawBorder();
|
|
|
|
|
|
|
|
|
|
|
|
void DrawChildrenBorder();
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateBorder();
|
|
|
|
|
|
|
2018-11-08 21:39:26 +08:00
|
|
|
|
void UpdateTransform();
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateOpacity();
|
|
|
|
|
|
|
2018-11-14 16:39:24 +08:00
|
|
|
|
protected:
|
2018-11-17 20:27:04 +08:00
|
|
|
|
String name_;
|
|
|
|
|
|
size_t hash_name_;
|
|
|
|
|
|
float display_opacity_;
|
2018-11-18 20:26:41 +08:00
|
|
|
|
float opacity_;
|
2018-11-17 20:27:04 +08:00
|
|
|
|
int order_;
|
|
|
|
|
|
bool visible_;
|
|
|
|
|
|
bool dirty_sort_;
|
|
|
|
|
|
Node* parent_;
|
|
|
|
|
|
Color border_color_;
|
|
|
|
|
|
Children children_;
|
|
|
|
|
|
cpGeometry border_;
|
2018-11-20 01:20:06 +08:00
|
|
|
|
Point pivot_;
|
|
|
|
|
|
Size size_;
|
2018-11-17 20:27:04 +08:00
|
|
|
|
math::Matrix initial_matrix_;
|
|
|
|
|
|
math::Matrix final_matrix_;
|
2018-11-08 21:39:26 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|