add Renderer::ResetResolutionWhenWindowResized

This commit is contained in:
Nomango 2020-07-26 19:00:00 +08:00
parent 2285449eef
commit 1c8c92862a
6 changed files with 38 additions and 32 deletions

View File

@ -150,8 +150,6 @@ void Director::OnUpdate(UpdateModuleContext& ctx)
if (debug_actor_)
debug_actor_->Update(ctx.dt);
ctx.Next();
}
void Director::OnRender(RenderModuleContext& ctx)
@ -174,8 +172,6 @@ void Director::OnRender(RenderModuleContext& ctx)
{
debug_actor_->Render(ctx.render_ctx);
}
ctx.Next();
}
void Director::HandleEvent(EventModuleContext& ctx)
@ -188,8 +184,6 @@ void Director::HandleEvent(EventModuleContext& ctx)
if (debug_actor_)
debug_actor_->DispatchEvent(ctx.evt);
ctx.Next();
}
} // namespace kiwano

View File

@ -161,8 +161,6 @@ void Input::HandleEvent(EventModuleContext& ctx)
UpdateKey(dynamic_cast<KeyUpEvent*>(evt)->code, false);
}
}
ctx.Next();
}
} // namespace kiwano

View File

@ -19,7 +19,6 @@
// THE SOFTWARE.
#include <kiwano/utils/Logger.h>
#include <kiwano/event/WindowEvent.h>
#include <kiwano/platform/FileSystem.h>
#include <kiwano/platform/Application.h>
#include <kiwano/render/ShapeMaker.h>
@ -131,15 +130,6 @@ void RendererImpl::Destroy()
::CoUninitialize();
}
void RendererImpl::HandleEvent(EventModuleContext& ctx)
{
if (ctx.evt->IsType<WindowResizedEvent>())
{
auto evt = ctx.evt->SafeCast<WindowResizedEvent>();
Resize(evt->width, evt->height);
}
}
void RendererImpl::Clear()
{
KGE_ASSERT(d3d_res_);

View File

@ -81,8 +81,6 @@ public:
void Destroy() override;
void HandleEvent(EventModuleContext& ctx) override;
protected:
RendererImpl();

View File

@ -19,14 +19,43 @@
// THE SOFTWARE.
#include <kiwano/render/Renderer.h>
#include <kiwano/event/WindowEvent.h>
namespace kiwano
{
Renderer::Renderer()
: vsync_(true)
, auto_reset_resolution_(false)
, clear_color_(Color::Black)
{
}
void Renderer::SetClearColor(const Color& color)
{
clear_color_ = color;
}
void Renderer::SetVSyncEnabled(bool enabled)
{
vsync_ = enabled;
}
void Renderer::ResetResolutionWhenWindowResized(bool enabled)
{
auto_reset_resolution_ = enabled;
}
void Renderer::HandleEvent(EventModuleContext& ctx)
{
if (auto_reset_resolution_)
{
if (ctx.evt->IsType<WindowResizedEvent>())
{
auto evt = ctx.evt->SafeCast<WindowResizedEvent>();
Resize(evt->width, evt->height);
}
}
}
} // namespace kiwano

View File

@ -69,11 +69,15 @@ public:
/// \~chinese
/// @brief 设置清屏颜色
virtual void SetClearColor(const Color& clear_color);
void SetClearColor(const Color& clear_color);
/// \~chinese
/// @brief 开启或关闭垂直同步
virtual void SetVSyncEnabled(bool enabled);
void SetVSyncEnabled(bool enabled);
/// \~chinese
/// @brief 窗口大小变化时自动调整分辨率
void ResetResolutionWhenWindowResized(bool enabled);
/// \~chinese
/// @brief 创建纹理内部资源
@ -235,11 +239,14 @@ public:
/// @brief 销毁渲染器资源
virtual void Destroy() = 0;
void HandleEvent(EventModuleContext& ctx) override;
protected:
Renderer();
protected:
bool vsync_;
bool auto_reset_resolution_;
Color clear_color_;
Size output_size_;
RenderContextPtr render_ctx_;
@ -262,14 +269,4 @@ inline Color Renderer::GetClearColor() const
return clear_color_;
}
inline void Renderer::SetVSyncEnabled(bool enabled)
{
vsync_ = enabled;
}
inline void Renderer::SetClearColor(const Color& color)
{
clear_color_ = color;
}
} // namespace kiwano