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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@
#pragma once #pragma once
#include "../macros.h" #include "../macros.h"
#include "../math/helper.h" #include "../math/helper.h"
#include "../2d/Color.h" #include "Color.h"
#include <Unknwnbase.h> #include <Unknwnbase.h>
namespace kiwano 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. // THE SOFTWARE.
#pragma once #pragma once
#include <string> #include "../core/core.h"
namespace kiwano namespace kiwano
{ {
// ×ÖÌå´Öϸֵ // ×ÖÌå´Öϸֵ
enum FontWeight : unsigned int enum FontWeight : unsigned int
{ {
Thin = 100, Thin = 100,
ExtraLight = 200, ExtraLight = 200,
Light = 300, Light = 300,
Normal = 400, Normal = 400,
Medium = 500, Medium = 500,
Bold = 700, Bold = 700,
ExtraBold = 800, ExtraBold = 800,
Black = 900, Black = 900,
ExtraBlack = 950 ExtraBlack = 950
}; };
// ×ÖÌå // ×ÖÌå
@ -52,12 +52,6 @@ namespace kiwano
float size = 18, float size = 18,
unsigned int weight = FontWeight::Normal, unsigned int weight = FontWeight::Normal,
bool italic = false 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); ThrowIfFailed(hr);
} }
void RenderTarget::CreateLayer(ComPtr<ID2D1Layer>& layer) const void RenderTarget::CreateLayer(LayerArea& layer) const
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
ComPtr<ID2D1Layer> new_layer;
if (!render_target_) if (!render_target_)
{ {
@ -401,12 +400,13 @@ namespace kiwano
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = render_target_->CreateLayer(&new_layer); ComPtr<ID2D1Layer> output;
} hr = render_target_->CreateLayer(&output);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
layer = new_layer; layer.SetLayer(output);
}
} }
ThrowIfFailed(hr); ThrowIfFailed(hr);
@ -424,7 +424,7 @@ namespace kiwano
{ {
render_target_->PushAxisAlignedClip( render_target_->PushAxisAlignedClip(
DX::ConvertToRectF(clip_rect), 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); ThrowIfFailed(hr);
} }
void RenderTarget::PushLayer(ComPtr<ID2D1Layer> const& layer, LayerProperties const& properties) void RenderTarget::PushLayer(LayerArea const& layer)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
if (!render_target_ || !solid_color_brush_) if (!render_target_ || !solid_color_brush_)
@ -455,19 +455,19 @@ namespace kiwano
hr = E_UNEXPECTED; hr = E_UNEXPECTED;
} }
if (SUCCEEDED(hr)) if (SUCCEEDED(hr) && layer.IsValid())
{ {
render_target_->PushLayer( render_target_->PushLayer(
D2D1::LayerParameters( D2D1::LayerParameters(
DX::ConvertToRectF(properties.area), DX::ConvertToRectF(layer.GetAreaRect()),
nullptr, layer.GetMaskGeometry().GetGeometry().get(),
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, antialias_ ? D2D1_ANTIALIAS_MODE_PER_PRIMITIVE : D2D1_ANTIALIAS_MODE_ALIASED,
D2D1::Matrix3x2F::Identity(), D2D1::Matrix3x2F::Identity(),
properties.opacity, layer.GetOpacity(),
nullptr, nullptr,
D2D1_LAYER_OPTIONS_NONE D2D1_LAYER_OPTIONS_NONE
), ),
layer.get() layer.GetLayer().get()
); );
} }

View File

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

View File

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

View File

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