Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/lcb/notes/feature-my_pixel_scale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# LiveCode Builder Host Library
## Widget library

A new expression `my pixel scale` has been implemented. Use the widget's
pixel scale to calculate the size of an image to draw. For example,
when drawing an image to `my bounds` create an image sized using
`my width * my pixel scale, my height * my pixel scale` otherwise the image will be
stretched to match the pixel scale. The pixel scale is a per-window/screen property
so may change if the user moves a window to a new screen.
8 changes: 8 additions & 0 deletions engine/src/widget-syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ extern "C" MC_DLLEXPORT_DEF void MCWidgetGetMyPaint(uinteger_t p_type, MCCanvasP
MCCanvasSolidPaintMakeWithColor(kMCCanvasColorBlack, (MCCanvasSolidPaintRef&)r_paint);
}

extern "C" MC_DLLEXPORT_DEF void MCWidgetGetMyPixelScale(MCCanvasFloat& r_pixel_scale)
{
if (!MCWidgetEnsureCurrentWidget())
return;

r_pixel_scale = MCWidgetGetHost(MCcurrentwidget)->getstack()->view_getbackingscale();
}

extern "C" MC_DLLEXPORT_DEF void MCWidgetGetMousePosition(bool p_current, MCCanvasPointRef& r_point)
{
if (!MCWidgetEnsureCurrentWidget())
Expand Down
19 changes: 19 additions & 0 deletions engine/src/widget.lcb
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ public foreign handler MCWidgetGetMyFont(out rFont as Font) returns nothing bind
public foreign handler MCWidgetGetMyEnabled(out rEnabled as CBool) returns nothing binds to "<builtin>"
public foreign handler MCWidgetGetMyDisabled(out rDisabled as CBool) returns nothing binds to "<builtin>"
public foreign handler MCWidgetGetMyPaint(in pPaintType as CUInt, out rPaint as Paint) returns nothing binds to "<builtin>"
public foreign handler MCWidgetGetMyPixelScale(out rPixelScale as CanvasFloat) returns nothing binds to "<builtin>"

/**
Summary: Returns the widget script object.
Expand Down Expand Up @@ -654,6 +655,24 @@ begin
MCWidgetGetMyPaint(mPaintType, output)
end syntax

/**
Summary: Returns the scaling factor of pixels for the widget

Description:
Use the widget's pixel scale to calculate the size of an image to draw. For example,
when drawing an image to `my bounds` create an image sized using
`my width * my pixel scale, my height * my pixel scale` otherwise the image will be
stretched to match the pixel scale. The pixel scale is a per-window/screen property
so may change if the user moves a window to a new screen.

Returns: The current scaling factor of pixels for the widget
*/
syntax MyPixelScale is expression
"my" "pixel" "scale"
begin
MCWidgetGetMyPixelScale(output)
end syntax

// ---------- Synchronous and asynchronous ("current") event information ---------- //

//foreign type PressedState binds to "MCPressedState"
Expand Down