Skip to content

Commit

Permalink
DPI changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhonnyg committed Nov 16, 2023
1 parent c952c6c commit 25b0530
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions defold-rive/src/comp_rive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ namespace dmRive
// static const dmhash_t UNIFORM_TRANSFORM_LOCAL = dmHashString64("transform_local");
// static const dmhash_t UNIFORM_COVER = dmHashString64("cover");

static float g_DisplayFactor = 1.0f;

static void ResourceReloadedCallback(const dmResource::ResourceReloadedParams& params);
static void DestroyComponent(struct RiveWorld* world, uint32_t index);
static void CompRiveAnimationReset(RiveComponent* component);
Expand Down Expand Up @@ -379,8 +381,6 @@ namespace dmRive
rive::Mat2D viewTransform = GetViewTransform(world->m_RiveRenderContext, render_context);
rive::Renderer* renderer = GetRiveRenderer(world->m_RiveRenderContext);

float device_dpi = dmGraphics::GetDisplayScaleFactor(world->m_Ctx->m_GraphicsContext);

for (uint32_t *i=begin;i!=end;i++)
{
RiveComponent* c = (RiveComponent*) buf[*i].m_UserData;
Expand All @@ -398,7 +398,7 @@ namespace dmRive
// Rive is using a different coordinate system than defold,
// we have to adhere to how our projection matrixes are
// constructed so we flip the renderer on the y axis here
rive::Vec2D yflip(device_dpi, -device_dpi);
rive::Vec2D yflip(g_DisplayFactor, -g_DisplayFactor);
transform = transform.scale(yflip);

renderer->transform(viewTransform * transform);
Expand Down Expand Up @@ -1091,6 +1091,8 @@ namespace dmRive
rivectx->m_RenderContext = *(dmRender::HRenderContext*)ctx->m_Contexts.Get(dmHashString64("render"));
rivectx->m_MaxInstanceCount = dmConfigFile::GetInt(ctx->m_Config, "rive.max_instance_count", 128);

g_DisplayFactor = dmGraphics::GetDisplayScaleFactor(rivectx->m_GraphicsContext);

// after script/anim/gui, before collisionobject
// the idea is to let the scripts/animations update the game object instance,
// and then let the component update its bones, allowing them to influence collision objects in the same frame
Expand Down
2 changes: 1 addition & 1 deletion main/circleui/circleui.script
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function init(self)
msg.post(".", "acquire_input_focus")
self.scale = (sys.get_config_int("display.high_dpi") == 1) and 2 or 1
self.scale = 1 -- (sys.get_config_int("display.high_dpi") == 1) and 2 or 1
end

function on_input(self, action_id, action)
Expand Down
2 changes: 1 addition & 1 deletion main/sophiahud/sophiahud.script
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function init(self)
msg.post(".", "acquire_input_focus")
self.scale = (sys.get_config_int("display.high_dpi") == 1) and 2 or 1
self.scale = 1 -- (sys.get_config_int("display.high_dpi") == 1) and 2 or 1
end

function on_input(self, action_id, action)
Expand Down

0 comments on commit 25b0530

Please sign in to comment.