Skip to content

Commit a828893

Browse files
authored
Merge pull request livecode#6337 from montegoulding/feature-my_pixel_scale
[[ MyPixelScale ]] Implement my pixel scale expression
2 parents 98b7cd6 + f12d88c commit a828893

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# LiveCode Builder Host Library
2+
## Widget library
3+
4+
A new expression `my pixel scale` has been implemented. Use the widget's
5+
pixel scale to calculate the size of an image to draw. For example,
6+
when drawing an image to `my bounds` create an image sized using
7+
`my width * my pixel scale, my height * my pixel scale` otherwise the image will be
8+
stretched to match the pixel scale. The pixel scale is a per-window/screen property
9+
so may change if the user moves a window to a new screen.

engine/src/widget-syntax.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ extern "C" MC_DLLEXPORT_DEF void MCWidgetGetMyPaint(uinteger_t p_type, MCCanvasP
316316
MCCanvasSolidPaintMakeWithColor(kMCCanvasColorBlack, (MCCanvasSolidPaintRef&)r_paint);
317317
}
318318

319+
extern "C" MC_DLLEXPORT_DEF void MCWidgetGetMyPixelScale(MCCanvasFloat& r_pixel_scale)
320+
{
321+
if (!MCWidgetEnsureCurrentWidget())
322+
return;
323+
324+
r_pixel_scale = MCWidgetGetHost(MCcurrentwidget)->getstack()->view_getbackingscale();
325+
}
326+
319327
extern "C" MC_DLLEXPORT_DEF void MCWidgetGetMousePosition(bool p_current, MCCanvasPointRef& r_point)
320328
{
321329
if (!MCWidgetEnsureCurrentWidget())

engine/src/widget.lcb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ public foreign handler MCWidgetGetMyFont(out rFont as Font) returns nothing bind
520520
public foreign handler MCWidgetGetMyEnabled(out rEnabled as CBool) returns nothing binds to "<builtin>"
521521
public foreign handler MCWidgetGetMyDisabled(out rDisabled as CBool) returns nothing binds to "<builtin>"
522522
public foreign handler MCWidgetGetMyPaint(in pPaintType as CUInt, out rPaint as Paint) returns nothing binds to "<builtin>"
523+
public foreign handler MCWidgetGetMyPixelScale(out rPixelScale as CanvasFloat) returns nothing binds to "<builtin>"
523524

524525
/**
525526
Summary: Returns the widget script object.
@@ -654,6 +655,24 @@ begin
654655
MCWidgetGetMyPaint(mPaintType, output)
655656
end syntax
656657

658+
/**
659+
Summary: Returns the scaling factor of pixels for the widget
660+
661+
Description:
662+
Use the widget's pixel scale to calculate the size of an image to draw. For example,
663+
when drawing an image to `my bounds` create an image sized using
664+
`my width * my pixel scale, my height * my pixel scale` otherwise the image will be
665+
stretched to match the pixel scale. The pixel scale is a per-window/screen property
666+
so may change if the user moves a window to a new screen.
667+
668+
Returns: The current scaling factor of pixels for the widget
669+
*/
670+
syntax MyPixelScale is expression
671+
"my" "pixel" "scale"
672+
begin
673+
MCWidgetGetMyPixelScale(output)
674+
end syntax
675+
657676
// ---------- Synchronous and asynchronous ("current") event information ---------- //
658677

659678
//foreign type PressedState binds to "MCPressedState"

0 commit comments

Comments
 (0)