remove ResolutionMode
This commit is contained in:
parent
7e9a3f150b
commit
7f954e0c2c
|
|
@ -128,7 +128,7 @@ namespace kiwano
|
|||
{
|
||||
if (show_border_ && !size_.IsOrigin())
|
||||
{
|
||||
Rect bounds = GetBounds();
|
||||
Rect bounds = GetBounds();
|
||||
|
||||
rt->SetTransform(transform_matrix_);
|
||||
rt->FillRectangle(bounds, Color(Color::Red, .4f));
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace kiwano
|
|||
};
|
||||
};
|
||||
|
||||
static bool Check(UInt32 type);
|
||||
static bool Check(Int32 type);
|
||||
};
|
||||
|
||||
// 键盘事件
|
||||
|
|
@ -65,7 +65,7 @@ namespace kiwano
|
|||
};
|
||||
};
|
||||
|
||||
static bool Check(UInt32 type);
|
||||
static bool Check(Int32 type);
|
||||
};
|
||||
|
||||
// 窗口事件
|
||||
|
|
@ -96,7 +96,7 @@ namespace kiwano
|
|||
};
|
||||
};
|
||||
|
||||
static bool Check(UInt32 type);
|
||||
static bool Check(Int32 type);
|
||||
};
|
||||
|
||||
// 自定义事件
|
||||
|
|
@ -110,7 +110,7 @@ namespace kiwano
|
|||
// 事件
|
||||
struct KGE_API Event
|
||||
{
|
||||
enum Type : UInt32
|
||||
enum Type : Int32
|
||||
{
|
||||
First,
|
||||
|
||||
|
|
@ -144,34 +144,34 @@ namespace kiwano
|
|||
Last
|
||||
};
|
||||
|
||||
UInt32 type;
|
||||
Int32 type;
|
||||
Actor* target;
|
||||
|
||||
union
|
||||
{
|
||||
MouseEvent mouse;
|
||||
KeyboardEvent key;
|
||||
WindowEvent win;
|
||||
WindowEvent window;
|
||||
CustomEvent custom;
|
||||
};
|
||||
|
||||
Event(UInt32 type = Type::First) : type(type), target(nullptr) {}
|
||||
Event(Int32 type = Type::First) : type(type), target(nullptr) {}
|
||||
};
|
||||
|
||||
|
||||
// Check-functions
|
||||
|
||||
inline bool MouseEvent::Check(UInt32 type)
|
||||
inline bool MouseEvent::Check(Int32 type)
|
||||
{
|
||||
return type > Event::MouseFirst && type < Event::MouseLast;
|
||||
}
|
||||
|
||||
inline bool KeyboardEvent::Check(UInt32 type)
|
||||
inline bool KeyboardEvent::Check(Int32 type)
|
||||
{
|
||||
return type > Event::KeyFirst && type < Event::KeyLast;
|
||||
}
|
||||
|
||||
inline bool WindowEvent::Check(UInt32 type)
|
||||
inline bool WindowEvent::Check(Int32 type)
|
||||
{
|
||||
return type > Event::WindowFirst && type < Event::WindowLast;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -382,8 +382,8 @@ namespace kiwano
|
|||
Window::GetInstance()->UpdateWindowRect();
|
||||
|
||||
Event evt(Event::WindowResized);
|
||||
evt.win.width = LOWORD(lparam);
|
||||
evt.win.height = HIWORD(lparam);
|
||||
evt.window.width = LOWORD(lparam);
|
||||
evt.window.height = HIWORD(lparam);
|
||||
app->DispatchEvent(evt);
|
||||
}
|
||||
}
|
||||
|
|
@ -395,8 +395,8 @@ namespace kiwano
|
|||
Int32 y = (Int32)(short)HIWORD(lparam);
|
||||
|
||||
Event evt(Event::WindowMoved);
|
||||
evt.win.x = x;
|
||||
evt.win.y = y;
|
||||
evt.window.x = x;
|
||||
evt.window.y = y;
|
||||
app->DispatchEvent(evt);
|
||||
}
|
||||
break;
|
||||
|
|
@ -408,7 +408,7 @@ namespace kiwano
|
|||
Window::GetInstance()->SetActive(active);
|
||||
|
||||
Event evt(Event::WindowFocusChanged);
|
||||
evt.win.focus = active;
|
||||
evt.window.focus = active;
|
||||
app->DispatchEvent(evt);
|
||||
}
|
||||
break;
|
||||
|
|
@ -418,7 +418,7 @@ namespace kiwano
|
|||
// KGE_LOG(L"Window title changed");
|
||||
|
||||
Event evt(Event::WindowTitleChanged);
|
||||
evt.win.title = reinterpret_cast<const WChar*>(lparam);
|
||||
evt.window.title = reinterpret_cast<const WChar*>(lparam);
|
||||
app->DispatchEvent(evt);
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ namespace kiwano
|
|||
: hwnd_(nullptr)
|
||||
, vsync_(true)
|
||||
, clear_color_(Color::Black)
|
||||
, resolution_mode_(ResolutionMode::Fixed)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +53,6 @@ namespace kiwano
|
|||
KGE_LOG(L"Creating device resources");
|
||||
|
||||
hwnd_ = Window::GetInstance()->GetHandle();
|
||||
resolution_ = output_size_ = Window::GetInstance()->GetSize();
|
||||
|
||||
d2d_res_ = nullptr;
|
||||
d3d_res_ = nullptr;
|
||||
|
|
@ -71,19 +69,11 @@ namespace kiwano
|
|||
// Direct3D device resources
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
#if defined(KGE_USE_DIRECTX10)
|
||||
hr = ID3D10DeviceResources::Create(
|
||||
hr = ID3DDeviceResources::Create(
|
||||
&d3d_res_,
|
||||
d2d_res_.get(),
|
||||
hwnd_
|
||||
);
|
||||
#else
|
||||
hr = ID3D11DeviceResources::Create(
|
||||
&d3d_res_,
|
||||
d2d_res_.get(),
|
||||
hwnd_
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
// DrawingStateBlock
|
||||
|
|
@ -172,12 +162,6 @@ namespace kiwano
|
|||
hr = d3d_res_->ClearRenderTarget(clear_color_);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
SetTransform(Matrix3x2{});
|
||||
PushClipRect(Rect{ Point{}, resolution_ });
|
||||
}
|
||||
|
||||
ThrowIfFailed(hr);
|
||||
}
|
||||
|
||||
|
|
@ -193,8 +177,6 @@ namespace kiwano
|
|||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
PopClipRect();
|
||||
|
||||
EndDraw();
|
||||
|
||||
render_target_->RestoreDrawingState(drawing_state_block_.get());
|
||||
|
|
@ -895,24 +877,6 @@ namespace kiwano
|
|||
vsync_ = enabled;
|
||||
}
|
||||
|
||||
void Renderer::SetResolution(Size const& resolution)
|
||||
{
|
||||
if (resolution_ != resolution)
|
||||
{
|
||||
resolution_ = resolution;
|
||||
UpdateResolution();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::SetResolutionMode(ResolutionMode mode)
|
||||
{
|
||||
if (resolution_mode_ != mode)
|
||||
{
|
||||
resolution_mode_ = mode;
|
||||
UpdateResolution();
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::SetClearColor(const Color& color)
|
||||
{
|
||||
clear_color_ = color;
|
||||
|
|
@ -933,58 +897,7 @@ namespace kiwano
|
|||
hr = d3d_res_->SetLogicalSize(output_size_);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
UpdateResolution();
|
||||
}
|
||||
|
||||
ThrowIfFailed(hr);
|
||||
}
|
||||
|
||||
void Renderer::UpdateResolution()
|
||||
{
|
||||
switch (resolution_mode_)
|
||||
{
|
||||
case ResolutionMode::Fixed:
|
||||
{
|
||||
SetGlobalTransform(nullptr);
|
||||
break;
|
||||
}
|
||||
|
||||
case ResolutionMode::Center:
|
||||
{
|
||||
Float32 left = math::Ceil((output_size_.x - resolution_.x) / 2);
|
||||
Float32 top = math::Ceil((output_size_.y - resolution_.y) / 2);
|
||||
SetGlobalTransform(Matrix3x2::Translation(Vec2{ left, top }));
|
||||
break;
|
||||
}
|
||||
|
||||
case ResolutionMode::Stretch:
|
||||
{
|
||||
Float32 scalex = Float32(Int32((output_size_.x / resolution_.x) * 100 + 0.5f)) / 100;
|
||||
Float32 scaley = Float32(Int32((output_size_.y / resolution_.y) * 100 + 0.5f)) / 100;
|
||||
SetGlobalTransform(Matrix3x2::Scaling(Vec2{ scalex, scaley }));
|
||||
break;
|
||||
}
|
||||
|
||||
case ResolutionMode::Adaptive:
|
||||
{
|
||||
Float32 scalex = Float32(Int32((output_size_.x / resolution_.x) * 100 + 0.5f)) / 100;
|
||||
Float32 scaley = Float32(Int32((output_size_.y / resolution_.y) * 100 + 0.5f)) / 100;
|
||||
if (scalex > scaley)
|
||||
{
|
||||
Float32 left = math::Ceil((output_size_.x - resolution_.x * scaley) / 2);
|
||||
SetGlobalTransform(Matrix3x2::SRT(Vec2{ left, 0 }, Vec2{ scaley, scaley }, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
Float32 top = math::Ceil((output_size_.y - resolution_.y * scalex) / 2);
|
||||
SetGlobalTransform(Matrix3x2::SRT(Vec2{ 0, top }, Vec2{ scalex, scalex }, 0));
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,20 +51,8 @@ namespace kiwano
|
|||
);
|
||||
};
|
||||
|
||||
// 分辨率模式
|
||||
// 分辨率模式决定了将画面渲染到视区上的方式
|
||||
// Fixed (固定): 分辨率不随视区改变, 且画面始终与视区边界对齐(默认)
|
||||
// Center (居中): 分辨率不随视区改变, 且画面始终在视区上居中
|
||||
// Stretch (拉伸): 分辨率始终随视区等比例拉伸
|
||||
// Adaptive (宽高自适应): 分辨率始终保持宽高比, 且尽可能的填充视区, 可能会出现黑色边界
|
||||
enum class ResolutionMode
|
||||
{
|
||||
Fixed, /* 固定 */
|
||||
Center, /* 居中 */
|
||||
Stretch, /* 拉伸 */
|
||||
Adaptive, /* 宽高自适应 */
|
||||
};
|
||||
|
||||
// 渲染器
|
||||
class KGE_API Renderer
|
||||
: public Singleton<Renderer>
|
||||
, public Component
|
||||
|
|
@ -83,16 +71,6 @@ namespace kiwano
|
|||
bool enabled
|
||||
);
|
||||
|
||||
// 设置画面分辨率
|
||||
void SetResolution(
|
||||
Size const& resolution
|
||||
);
|
||||
|
||||
// 设置分辨率模式
|
||||
void SetResolutionMode(
|
||||
ResolutionMode mode
|
||||
);
|
||||
|
||||
public:
|
||||
void CreateTexture(
|
||||
Texture& texture,
|
||||
|
|
@ -190,8 +168,6 @@ namespace kiwano
|
|||
|
||||
inline Size const& GetOutputSize() const { return output_size_; }
|
||||
|
||||
inline Size const& GetResolution() const { return resolution_; }
|
||||
|
||||
inline Color const& GetClearColor() const { return clear_color_; }
|
||||
|
||||
inline ID2DDeviceResources* GetD2DDeviceResources() const { KGE_ASSERT(d2d_res_); return d2d_res_.get(); }
|
||||
|
|
@ -209,15 +185,11 @@ namespace kiwano
|
|||
|
||||
void ResizeTarget(UInt32 width, UInt32 height);
|
||||
|
||||
void UpdateResolution();
|
||||
|
||||
private:
|
||||
bool vsync_;
|
||||
HWND hwnd_;
|
||||
Color clear_color_;
|
||||
Size output_size_;
|
||||
Size resolution_;
|
||||
ResolutionMode resolution_mode_;
|
||||
|
||||
ComPtr<ID2DDeviceResources> d2d_res_;
|
||||
ComPtr<ID3DDeviceResources> d3d_res_;
|
||||
|
|
|
|||
Loading…
Reference in New Issue