Magic_Game/src/kiwano/2d/Layer.h

144 lines
3.8 KiB
C
Raw Normal View History

2019-04-11 14:40:54 +08:00
// Copyright (c) 2016-2018 Kiwano - 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
2019-10-11 21:55:29 +08:00
#include <kiwano/2d/Actor.h>
2019-12-23 18:05:08 +08:00
#include <kiwano/renderer/LayerArea.h>
#include <kiwano/renderer/RenderTarget.h>
2019-04-11 14:40:54 +08:00
namespace kiwano
{
2019-12-23 18:05:08 +08:00
KGE_DECLARE_SMART_PTR(Layer);
/**
* \addtogroup Actors
* @{
*/
/**
* \~chinese
* @brief ͼ<EFBFBD><EFBFBD>
*/
2019-04-11 14:40:54 +08:00
class KGE_API Layer
: public Actor
{
public:
Layer();
virtual ~Layer();
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>û
bool IsSwallowEventsEnabled() const;
2019-08-20 19:32:36 +08:00
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>û<EFBFBD><C3BB><EFBFBD><EFBFBD>
/// @param enabled <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
void SetSwallowEvents(bool enabled);
2019-08-20 19:32:36 +08:00
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD>òü<C3B2><C3BC><EFBFBD><EFBFBD><EFBFBD>
/// @param clip_rect <20>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>
2019-08-20 19:32:36 +08:00
void SetClipRect(Rect const& clip_rect);
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>͸<EFBFBD><CDB8><EFBFBD><EFBFBD>
/// @param opacity ͸<><CDB8><EFBFBD><EFBFBD>
2019-09-29 22:23:13 +08:00
void SetOpacity(float opacity) override;
2019-08-20 19:32:36 +08:00
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD>ɲ<EFBFBD>
/// @param mask <20>ɲ<EFBFBD><C9B2>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>״
2019-08-20 19:32:36 +08:00
void SetMaskGeometry(Geometry const& mask);
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD>ɲ<EFBFBD><C9B2>Ķ<EFBFBD>ά<EFBFBD>
/// @param transform Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD>ɲ<EFBFBD><C9B2>Ķ<EFBFBD>ά<EFBFBD>
2019-08-20 19:32:36 +08:00
void SetMaskTransform(Matrix3x2 const& transform);
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param area ͼ<><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void SetArea(LayerArea const& area);
/// \~chinese
/// @brief <20><>ȡͼ<C8A1><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
LayerArea const& GetArea() const;
/// \~chinese
/// @brief <20><><EFBFBD>ظú<D8B8><C3BA><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EAB0B4><EFBFBD><EFBFBD>Ϣ
/// @param btn <20><><EFBFBD><EFBFBD><EAB0B4><EFBFBD><EFBFBD>ֵ
/// @param pos <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
virtual void OnMouseButtonDown(MouseButton::Value btn, Point const& pos) {}
/// \~chinese
/// @brief <20><><EFBFBD>ظú<D8B8><C3BA><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̧<EFBFBD><CCA7><EFBFBD><EFBFBD>Ϣ
/// @param btn <20><><EFBFBD><EFBFBD><EAB0B4><EFBFBD><EFBFBD>ֵ
/// @param pos <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
virtual void OnMouseButtonUp(MouseButton::Value btn, Point const& pos) {}
/// \~chinese
/// @brief <20><><EFBFBD>ظú<D8B8><C3BA><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>Ϣ
/// @param pos <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
virtual void OnMouseMoved(Point const& pos) {}
/// \~chinese
/// @brief <20><><EFBFBD>ظú<D8B8><C3BA><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
virtual void OnMouseWheel(float wheel) {}
2019-08-20 19:32:36 +08:00
2019-12-23 18:05:08 +08:00
/// \~chinese
/// @brief <20><><EFBFBD>ظú<D8B8><C3BA><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̰<EFBFBD><CCB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
/// @param key <20><><EFBFBD>̰<EFBFBD><CCB0><EFBFBD><EFBFBD><EFBFBD>ֵ
virtual void OnKeyDown(KeyCode::Value key) {}
/// \~chinese
/// @brief <20><><EFBFBD>ظú<D8B8><C3BA><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̰<EFBFBD><CCB0><EFBFBD>̧<EFBFBD><CCA7><EFBFBD><EFBFBD>Ϣ
/// @param key <20><><EFBFBD>̰<EFBFBD><CCB0><EFBFBD><EFBFBD><EFBFBD>ֵ
virtual void OnKeyUp(KeyCode::Value key) {}
/// \~chinese
/// @brief <20><><EFBFBD>ظú<D8B8><C3BA><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>Ϣ
/// @param c <20>ַ<EFBFBD>
virtual void OnChar(char c) {}
2019-11-14 13:18:16 +08:00
void Dispatch(Event& evt) override;
protected:
2019-08-20 19:32:36 +08:00
void Render(RenderTarget* rt) override;
2019-11-14 13:18:16 +08:00
void HandleMessages(Event& evt);
2019-12-23 18:05:08 +08:00
private:
2019-08-20 19:32:36 +08:00
bool swallow_;
LayerArea area_;
};
2019-12-23 18:05:08 +08:00
/** @} */
inline bool Layer::IsSwallowEventsEnabled() const { return swallow_; }
inline void Layer::SetSwallowEvents(bool enabled) { swallow_ = enabled; }
inline void Layer::SetArea(LayerArea const& area) { area_ = area; }
inline LayerArea const& Layer::GetArea() const { return area_; }
}