Add LayerArea

This commit is contained in:
Nomango 2019-08-16 10:12:34 +08:00
parent 7257ebf12b
commit a3fad67bfa
21 changed files with 251 additions and 106 deletions

View File

@ -5,8 +5,8 @@ skip_tags: true
# fetch repository as zip archive
shallow_clone: true
# pull_requests:
# do_not_increment_build_number: true
pull_requests:
do_not_increment_build_number: true
# Do not build feature branch with open Pull Requests
# skip_branch_with_pr: true
@ -54,6 +54,9 @@ for:
- master
only_commits:
message: /\[build\]/
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
VS_PLATFORM_TOOLSET: v142
configuration:
- Debug

View File

@ -28,7 +28,6 @@
<ClInclude Include="..\src\kiwano\macros.h" />
<ClInclude Include="..\src\kiwano\2d\include-forwards.h" />
<ClInclude Include="..\src\kiwano\2d\Canvas.h" />
<ClInclude Include="..\src\kiwano\2d\Color.h" />
<ClInclude Include="..\src\kiwano\2d\DebugActor.h" />
<ClInclude Include="..\src\kiwano\2d\Font.hpp" />
<ClInclude Include="..\src\kiwano\2d\FrameSequence.h" />
@ -67,15 +66,18 @@
<ClInclude Include="..\src\kiwano\math\Vec2.hpp" />
<ClInclude Include="..\src\kiwano\platform\Application.h" />
<ClInclude Include="..\src\kiwano\platform\modules.h" />
<ClInclude Include="..\src\kiwano\renderer\Color.h" />
<ClInclude Include="..\src\kiwano\renderer\D2DDeviceResources.h" />
<ClInclude Include="..\src\kiwano\renderer\D3D10DeviceResources.h" />
<ClInclude Include="..\src\kiwano\renderer\D3D11DeviceResources.h" />
<ClInclude Include="..\src\kiwano\renderer\D3DDeviceResourcesBase.h" />
<ClInclude Include="..\src\kiwano\renderer\Font.h" />
<ClInclude Include="..\src\kiwano\renderer\Geometry.h" />
<ClInclude Include="..\src\kiwano\renderer\GifImage.h" />
<ClInclude Include="..\src\kiwano\renderer\helper.hpp" />
<ClInclude Include="..\src\kiwano\renderer\Image.h" />
<ClInclude Include="..\src\kiwano\renderer\ImageCache.h" />
<ClInclude Include="..\src\kiwano\renderer\LayerArea.h" />
<ClInclude Include="..\src\kiwano\renderer\Renderer.h" />
<ClInclude Include="..\src\kiwano\renderer\RenderTarget.h" />
<ClInclude Include="..\src\kiwano\renderer\TextLayout.h" />
@ -98,7 +100,6 @@
<ClCompile Include="..\src\kiwano\2d\action\ActionTween.cpp" />
<ClCompile Include="..\src\kiwano\2d\action\Animation.cpp" />
<ClCompile Include="..\src\kiwano\2d\Canvas.cpp" />
<ClCompile Include="..\src\kiwano\2d\Color.cpp" />
<ClCompile Include="..\src\kiwano\2d\DebugActor.cpp" />
<ClCompile Include="..\src\kiwano\2d\Frame.cpp" />
<ClCompile Include="..\src\kiwano\2d\FrameSequence.cpp" />
@ -124,13 +125,16 @@
<ClCompile Include="..\src\kiwano\base\Window.cpp" />
<ClCompile Include="..\src\kiwano\platform\Application.cpp" />
<ClCompile Include="..\src\kiwano\platform\modules.cpp" />
<ClCompile Include="..\src\kiwano\renderer\Color.cpp" />
<ClCompile Include="..\src\kiwano\renderer\D2DDeviceResources.cpp" />
<ClCompile Include="..\src\kiwano\renderer\D3D10DeviceResources.cpp" />
<ClCompile Include="..\src\kiwano\renderer\D3D11DeviceResources.cpp" />
<ClCompile Include="..\src\kiwano\renderer\Font.cpp" />
<ClCompile Include="..\src\kiwano\renderer\Geometry.cpp" />
<ClCompile Include="..\src\kiwano\renderer\GifImage.cpp" />
<ClCompile Include="..\src\kiwano\renderer\Image.cpp" />
<ClCompile Include="..\src\kiwano\renderer\ImageCache.cpp" />
<ClCompile Include="..\src\kiwano\renderer\LayerArea.cpp" />
<ClCompile Include="..\src\kiwano\renderer\Renderer.cpp" />
<ClCompile Include="..\src\kiwano\renderer\RenderTarget.cpp" />
<ClCompile Include="..\src\kiwano\renderer\TextLayout.cpp" />

View File

@ -48,9 +48,6 @@
<ClInclude Include="..\src\kiwano\2d\Canvas.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\2d\Color.h">
<Filter>2d</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\2d\Font.hpp">
<Filter>2d</Filter>
</ClInclude>
@ -294,6 +291,15 @@
<ClInclude Include="..\src\kiwano\renderer\RenderTarget.h">
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\renderer\Color.h">
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\renderer\Font.h">
<Filter>renderer</Filter>
</ClInclude>
<ClInclude Include="..\src\kiwano\renderer\LayerArea.h">
<Filter>renderer</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\kiwano\ui\Button.cpp">
@ -305,9 +311,6 @@
<ClCompile Include="..\src\kiwano\2d\Canvas.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\src\kiwano\2d\Color.cpp">
<Filter>2d</Filter>
</ClCompile>
<ClCompile Include="..\src\kiwano\2d\Layer.cpp">
<Filter>2d</Filter>
</ClCompile>
@ -455,5 +458,14 @@
<ClCompile Include="..\src\kiwano\renderer\RenderTarget.cpp">
<Filter>renderer</Filter>
</ClCompile>
<ClCompile Include="..\src\kiwano\renderer\Color.cpp">
<Filter>renderer</Filter>
</ClCompile>
<ClCompile Include="..\src\kiwano\renderer\Font.cpp">
<Filter>renderer</Filter>
</ClCompile>
<ClCompile Include="..\src\kiwano\renderer\LayerArea.cpp">
<Filter>renderer</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -39,10 +39,8 @@ namespace kiwano
, window_size_()
, out_scene_(nullptr)
, in_scene_(nullptr)
, out_layer_(nullptr)
, in_layer_(nullptr)
, out_layer_prop_()
, in_layer_prop_()
, out_layer_()
, in_layer_()
{
}
@ -74,7 +72,8 @@ namespace kiwano
}
window_size_ = Renderer::GetInstance()->GetOutputSize();
out_layer_prop_ = in_layer_prop_ = LayerProperties{ Rect(Point(), window_size_),1.f };
out_layer_.SetAreaRect(Rect{ Point(), window_size_ });
in_layer_.SetAreaRect(Rect{ Point(), window_size_ });
}
void Transition::Update(Duration dt)
@ -101,7 +100,7 @@ namespace kiwano
{
renderer->SetTransform(out_scene_->GetTransformMatrix());
renderer->PushClipRect(Rect{ Point{}, window_size_ });
renderer->PushLayer(out_layer_, out_layer_prop_);
renderer->PushLayer(out_layer_);
out_scene_->Render(renderer);
@ -113,7 +112,7 @@ namespace kiwano
{
renderer->SetTransform(in_scene_->GetTransformMatrix());
renderer->PushClipRect(Rect{ Point{}, window_size_ });
renderer->PushLayer(in_layer_, in_layer_prop_);
renderer->PushLayer(in_layer_);
in_scene_->Render(renderer);
@ -141,7 +140,7 @@ namespace kiwano
{
Transition::Init(prev, next);
in_layer_prop_.opacity = 0;
in_layer_.SetOpacity(0.f);
}
void BoxTransition::Update(Duration dt)
@ -150,22 +149,26 @@ namespace kiwano
if (process_ < .5f)
{
out_layer_prop_.area = Rect(
window_size_.x * process_,
window_size_.y * process_,
window_size_.x * (1 - process_ * 2),
window_size_.y * (1 - process_ * 2)
out_layer_.SetAreaRect(
Rect(
window_size_.x * process_,
window_size_.y * process_,
window_size_.x * (1 - process_ * 2),
window_size_.y * (1 - process_ * 2)
)
);
}
else
{
out_layer_prop_.opacity = 0;
in_layer_prop_.opacity = 1;
in_layer_prop_.area = Rect(
window_size_.x * (1 - process_),
window_size_.y * (1 - process_),
window_size_.x * (2 * process_ - 1),
window_size_.y * (2 * process_ - 1)
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity(1.f);
in_layer_.SetAreaRect(
Rect(
window_size_.x * (1 - process_),
window_size_.y * (1 - process_),
window_size_.x * (2 * process_ - 1),
window_size_.y * (2 * process_ - 1)
)
);
}
}
@ -183,16 +186,16 @@ namespace kiwano
{
Transition::Init(prev, next);
out_layer_prop_.opacity = 1;
in_layer_prop_.opacity = 0;
out_layer_.SetOpacity(1.f);
in_layer_.SetOpacity(0.f);
}
void EmergeTransition::Update(Duration dt)
{
Transition::Update(dt);
out_layer_prop_.opacity = 1 - process_;
in_layer_prop_.opacity = process_;
out_layer_.SetOpacity(1 - process_);
in_layer_.SetOpacity(process_);
}
//-------------------------------------------------------
@ -208,8 +211,8 @@ namespace kiwano
{
Transition::Init(prev, next);
out_layer_prop_.opacity = 1;
in_layer_prop_.opacity = 0;
out_layer_.SetOpacity(1.f);
in_layer_.SetOpacity(0.f);
}
void FadeTransition::Update(Duration dt)
@ -218,13 +221,13 @@ namespace kiwano
if (process_ < 0.5)
{
out_layer_prop_.opacity = 1 - process_ * 2;
in_layer_prop_.opacity = 0;
out_layer_.SetOpacity(1 - process_ * 2);
in_layer_.SetOpacity(0.f);
}
else
{
out_layer_prop_.opacity = 0;
in_layer_prop_.opacity = (process_ - 0.5f) * 2;
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity((process_ - 0.5f) * 2);
}
}
@ -336,7 +339,7 @@ namespace kiwano
in_scene_->SetAnchor(0.5f, 0.5f);
}
in_layer_prop_.opacity = 0;
in_layer_.SetOpacity(0.f);
}
void RotationTransition::Update(Duration dt)
@ -357,8 +360,8 @@ namespace kiwano
{
if (in_scene_)
{
out_layer_prop_.opacity = 0;
in_layer_prop_.opacity = 1;
out_layer_.SetOpacity(0.f);
in_layer_.SetOpacity(1.f);
auto transform = in_scene_->GetTransform();
transform.scale = Point{ (process_ - .5f) * 2, (process_ - .5f) * 2 };

View File

@ -20,7 +20,7 @@
#pragma once
#include "include-forwards.h"
#include <d2d1.h>
#include "../renderer/LayerArea.h"
namespace kiwano
{
@ -57,17 +57,15 @@ namespace kiwano
virtual void Reset() { };
protected:
bool done_;
float process_;
Duration duration_;
Duration delta_;
Size window_size_;
StagePtr out_scene_;
StagePtr in_scene_;
ComPtr<ID2D1Layer> out_layer_;
ComPtr<ID2D1Layer> in_layer_;
LayerProperties out_layer_prop_;
LayerProperties in_layer_prop_;
bool done_;
float process_;
Duration duration_;
Duration delta_;
Size window_size_;
StagePtr out_scene_;
StagePtr in_scene_;
LayerArea out_layer_;
LayerArea in_layer_;
};

View File

@ -19,15 +19,15 @@
// THE SOFTWARE.
#pragma once
#include "Color.h"
#include "../core/core.h"
#include "../base/time.h"
#include "../base/RefCounter.hpp"
#include "../base/SmartPtr.hpp"
#include "../base/ComPtr.hpp"
#include "../base/Object.h"
#include "../math/helper.h"
#include "../base/types.h"
#include "../math/helper.h"
#include "../renderer/Color.h"
namespace kiwano
{

View File

@ -61,11 +61,4 @@ namespace kiwano
GrayScale, // 灰度抗锯齿
None // 不启用抗锯齿
};
// 图层属性
struct LayerProperties
{
Rect area;
float opacity;
};
}

View File

@ -59,11 +59,14 @@
// renderer
//
#include "renderer/Color.h"
#include "renderer/Font.h"
#include "renderer/Image.h"
#include "renderer/GifImage.h"
#include "renderer/TextLayout.h"
#include "renderer/TextRenderer.h"
#include "renderer/Geometry.h"
#include "renderer/LayerArea.h"
#include "renderer/ImageCache.h"
#include "renderer/RenderTarget.h"
#include "renderer/Renderer.h"
@ -96,8 +99,7 @@
// 2d
//
#include "2d/Font.hpp"
#include "2d/Color.h"
#include "2d/Transform.hpp"
#include "2d/TextStyle.hpp"

View File

@ -23,7 +23,7 @@
#include "../base/time.h"
#include "../base/Component.h"
#include "../base/Event.hpp"
#include "../2d/Color.h"
#include "../renderer/Color.h"
namespace kiwano
{

View File

@ -20,8 +20,8 @@
#pragma once
#include "helper.hpp"
#include "Font.h"
#include "../base/Resource.h"
#include "../2d/Font.hpp"
#include "../2d/TextStyle.hpp"
#include <dwrite.h>
#include <d2d1.h>

View File

@ -21,7 +21,7 @@
#pragma once
#include "../macros.h"
#include "../math/helper.h"
#include "../2d/Color.h"
#include "Color.h"
#include <Unknwnbase.h>
namespace kiwano

View File

@ -0,0 +1,32 @@
// 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.
#include "Font.h"
namespace kiwano
{
Font::Font(const String& family, float size, unsigned int weight, bool italic)
: family(family)
, size(size)
, weight(weight)
, italic(italic)
{
}
}

View File

@ -19,22 +19,22 @@
// THE SOFTWARE.
#pragma once
#include <string>
#include "../core/core.h"
namespace kiwano
{
// ×ÖÌå´Öϸֵ
enum FontWeight : unsigned int
{
Thin = 100,
ExtraLight = 200,
Light = 300,
Normal = 400,
Medium = 500,
Bold = 700,
ExtraBold = 800,
Black = 900,
ExtraBlack = 950
Thin = 100,
ExtraLight = 200,
Light = 300,
Normal = 400,
Medium = 500,
Bold = 700,
ExtraBold = 800,
Black = 900,
ExtraBlack = 950
};
// ×ÖÌå
@ -52,12 +52,6 @@ namespace kiwano
float size = 18,
unsigned int weight = FontWeight::Normal,
bool italic = false
)
: family(family)
, size(size)
, weight(weight)
, italic(italic)
{
}
);
};
}

View File

@ -0,0 +1,44 @@
// Copyright (c) 2016-2019 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.
#include "LayerArea.h"
namespace kiwano
{
LayerArea::LayerArea()
: opacity_(1.f)
{
}
bool LayerArea::IsValid() const
{
return layer_ != nullptr;
}
Size LayerArea::GetSize() const
{
if (layer_)
{
return reinterpret_cast<Size const&>(layer_->GetSize());
}
return Size();
}
}

View File

@ -0,0 +1,60 @@
// Copyright (c) 2016-2019 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
#include "D2DDeviceResources.h"
#include "Geometry.h"
namespace kiwano
{
// ͼ²ã
class KGE_API LayerArea
{
public:
LayerArea();
bool IsValid() const;
Size GetSize() const;
inline Rect const& GetAreaRect() const { return area_; }
inline void SetAreaRect(Rect const& area) { area_ = area; }
inline float GetOpacity() const { return opacity_; }
inline void SetOpacity(float opacity) { opacity_ = opacity; }
inline Geometry const& GetMaskGeometry() const { return mask_; }
inline void SetMaskGeometry(Geometry const& mask) { mask_ = mask; }
public:
inline ComPtr<ID2D1Layer> GetLayer() const { return layer_; }
inline void SetLayer(ComPtr<ID2D1Layer> layer) { layer_ = layer; }
protected:
Rect area_;
float opacity_;
Geometry mask_;
ComPtr<ID2D1Layer> layer_;
};
}

View File

@ -389,10 +389,9 @@ namespace kiwano
ThrowIfFailed(hr);
}
void RenderTarget::CreateLayer(ComPtr<ID2D1Layer>& layer) const
void RenderTarget::CreateLayer(LayerArea& layer) const
{
HRESULT hr = S_OK;
ComPtr<ID2D1Layer> new_layer;
if (!render_target_)
{
@ -401,12 +400,13 @@ namespace kiwano
if (SUCCEEDED(hr))
{
hr = render_target_->CreateLayer(&new_layer);
}
ComPtr<ID2D1Layer> output;
hr = render_target_->CreateLayer(&output);
if (SUCCEEDED(hr))
{
layer = new_layer;
if (SUCCEEDED(hr))
{
layer.SetLayer(output);
}
}
ThrowIfFailed(hr);
@ -424,7 +424,7 @@ namespace kiwano
{
render_target_->PushAxisAlignedClip(
DX::ConvertToRectF(clip_rect),
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
antialias_ ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED
);
}
@ -447,7 +447,7 @@ namespace kiwano
ThrowIfFailed(hr);
}
void RenderTarget::PushLayer(ComPtr<ID2D1Layer> const& layer, LayerProperties const& properties)
void RenderTarget::PushLayer(LayerArea const& layer)
{
HRESULT hr = S_OK;
if (!render_target_ || !solid_color_brush_)
@ -455,19 +455,19 @@ namespace kiwano
hr = E_UNEXPECTED;
}
if (SUCCEEDED(hr))
if (SUCCEEDED(hr) && layer.IsValid())
{
render_target_->PushLayer(
D2D1::LayerParameters(
DX::ConvertToRectF(properties.area),
nullptr,
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
DX::ConvertToRectF(layer.GetAreaRect()),
layer.GetMaskGeometry().GetGeometry().get(),
antialias_ ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED,
D2D1::Matrix3x2F::Identity(),
properties.opacity,
layer.GetOpacity(),
nullptr,
D2D1_LAYER_OPTIONS_NONE
),
layer.get()
layer.GetLayer().get()
);
}

View File

@ -24,6 +24,7 @@
#include "Geometry.h"
#include "TextLayout.h"
#include "TextRenderer.h"
#include "LayerArea.h"
namespace kiwano
{
@ -37,7 +38,7 @@ namespace kiwano
void EndDraw();
void CreateLayer(
ComPtr<ID2D1Layer>& layer
LayerArea& layer
) const;
void DrawGeometry(
@ -124,8 +125,7 @@ namespace kiwano
void PopClipRect();
void PushLayer(
ComPtr<ID2D1Layer> const& layer,
LayerProperties const& properties
LayerArea const& layer
);
void PopLayer();

View File

@ -20,7 +20,7 @@
#pragma once
#include "D2DDeviceResources.h"
#include "../2d/Font.hpp"
#include "Font.h"
#include "../2d/TextStyle.hpp"
namespace kiwano

View File

@ -21,7 +21,7 @@
#pragma once
#include "../base/ComPtr.hpp"
#include "../math/helper.h"
#include "../2d/Color.h"
#include "Color.h"
#include <d2d1.h>
namespace kiwano