Expose ui scaling and orientation

This commit is contained in:
Georg Hagen
2024-07-27 14:30:59 +02:00
parent 6a1a76f4d1
commit eb81c777bf
7 changed files with 45 additions and 43 deletions

View File

@@ -45,7 +45,7 @@ namespace OpenVulkano
if (w > 0 && h > 0)
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);*/
io.DisplaySize = { static_cast<float>(m_window->GetWidth()), static_cast<float>(m_window->GetHeight()) };
io.DisplayFramebufferScale = { 1, 1 };
io.DisplayFramebufferScale = { m_window->GetContentScale(), m_window->GetContentScale() };
//if (bd->WantUpdateMonitors)
//ImGui_ImplGlfw_UpdateMonitors();
@@ -68,4 +68,4 @@ namespace OpenVulkano
io.BackendPlatformUserData = nullptr;
io.BackendFlags = ImGuiBackendFlags_None;
}
}
}

View File

@@ -16,6 +16,8 @@ namespace OpenVulkano
IWindowHandler* handler = nullptr;
void* caMetalLayer = nullptr;
bool tickHandler = true;
float contentScale = 1;
float orientation = 0;
public:
void Init(RenderAPI::RenderApi renderApi) override {}
@@ -82,6 +84,14 @@ namespace OpenVulkano
void Close() override {}
void OnResize(uint32_t width, uint32_t height);
virtual float GetContentScale() const override { return contentScale; }
virtual float GetInterfaceOrientation() const override { return orientation; }
void SetContentScale(float scale) { contentScale = scale; }
void SetOrientation(float orientation) { this->orientation = orientation; }
void TickHandler();
};

View File

@@ -21,4 +21,6 @@
-(void)WillDisappear;
-(void)DidDisappear;
-(void)DidUnload;
-(void)SetInterfaceOrientation:(float)orientation;
@end

View File

@@ -35,6 +35,7 @@ using namespace OpenVulkano;
- (void) mtkView:(MTKView *) view drawableSizeWillChange:(CGSize) size
{
window->SetContentScale(UIScreen.mainScreen.nativeScale);
window->OnResize(size.width, size.height);
}
@@ -82,9 +83,8 @@ using namespace OpenVulkano;
- (void)commonInit {
[self setMultipleTouchEnabled:YES];
self.contentScaleFactor = UIScreen.mainScreen.nativeScale / 1.5f;
self.contentScaleFactor = UIScreen.mainScreen.nativeScale;
auto size = self.bounds.size;
auto sizeX = size.width * self.contentScaleFactor;
auto sizeY = size.height * self.contentScaleFactor;
@@ -126,10 +126,17 @@ using namespace OpenVulkano;
auto size = self.bounds.size;
auto sizeX = size.width * self.contentScaleFactor;
auto sizeY = size.height * self.contentScaleFactor;
m_window.SetContentScale(self.contentScaleFactor);
m_window.OnResize(sizeX, sizeY);
}
}
- (void)SetInterfaceOrientation:(float)orientation
{
m_window.SetOrientation(orientation);
}
- (Math::Vector2f)getTouchPosition:(UITouch*)touch
{
CGPoint uitouchLocation = [touch locationInView:touch.view];