Requires: Direct2D.lg32
Obtains the size of the current render target in either device independent pixels (DIP) or pixels.
D2GetSizeRT RT, width!, height! [,Pixels]
RT | : Object expression |
width!, height! | : float variables |
Pixels | : Boolean expression |
Returns the size of the current render target RT in device independent pixels (DIPs). The return values are stored in the floating point variables of type Float (Single). Other D2 drawing routines use device independent pixels, so D2GetSizeRT returns the relevant size of the surface. By passing True for the Pixels parameter the command returns the size in actual pixels.
Direct2D uses device-independent pixels (DIP) for its coordinate system. One DIP is 1/96 inch, for a dpi-unaware program 1/96 inch is 1 'logical pixel', because a dpi-unaware program uses a 96 dots-per-inch resolution. By using a DIP coordinate system, Direct2D will produce equally sized shapes on different displays. Think of a DIP as the size of a logical dot on a normal display with 96 DPI.
By default, the GFA-BASIC 32 IDE is a dpi-unaware program, just as the produced EXE programs, meaning that on high-dpi displays (DPI > 96) the applications are automatically scaled back to 96 dpi. Windows sizes the windows properly but the result may look a bit blurry. For a dpi-unaware program the screen resolution returned by Windows is also scaled back to 96 dpi. A high-resolution display of 1920 x 1080 pixels with a system scaling of 150% will return a desktop size of 1280x720 (_X,_Y) for a dpi-unaware program. This means that GFA-BASIC 32 and its programs use a coordinate system based on 96 dots-per-inch whether or not it runs on a high-resolution display.
When it comes to actually displaying the Windows OS rescales the dpi-unaware program's coordinate system to the high-resolution display's settings. For instance, on a high dpi display (1920x1280 pixels) a window of 1280x720 of 'logical pixels' will fill the entire display of 1920x1280 real pixels.
A dpi-unaware program using Direct2D a shape sized 100x100 DIP (<=> 100x100 logical pixels) occupies 150x150 real pixels. Since a dpi-unaware program uses a 96 dots per inch resolution, a Direct2D DIP is exactly one 'logical pixel'. The program's logical coordinate system matches Direct2D's DIP system.
This is not true for dpi-aware programs, Direct2D's DIP is 1/96 inch, but the real pixels used depends on the system's DPI. A high-resolution display of 1920x1080 with 150% scaling will use 1.5 real pixels to represent 1 DIP (1/96 inch). A dpi-aware program running on 1920x1280 will scale a 100x100 DIP to 150x150 physical pixels.
Because of the device independent pixels (DIP) coordinate system a Direct2D shape is equally sized, whether the app is dpi-unaware or dpi-aware. Direct2D using DIPs makes the resources (shapes, bitmaps) automatically independent of the display's resolution.
'
' D2GetSize sample (dpi-unaware)
'
$Library "Direct2D"
OpenW 1, 0, 0, 300, 200, ~15 ' Create a window
Global Object RT1
Set RT1 = D2GetRT()
Global Float Width1, Height1
D2GetSizeRT RT1, Width1, Height1
' Use Width1 and Height1 for drawing
Do
Sleep
Until Me Is Nothing
Sub Win_1_Paint
D2BeginDraw RT1, D2C_Aquamarine
D2Text 0, 0, "Width in DIPs: " + Str(Width1)
D2Text 0, 16, "Height in DIPs: " + Str(Height1)
D2EndDraw
EndSub
Sub Win_1_ReSize
D2ResizeRT RT1, _X, _Y ' resize render target to _X and _Y
D2GetSizeRT RT1, Width1, Height1 ' new size in DIPs
EndSub
Invokes the ID2D1RenderTarget::GetSize and ::GetPixelSize methods.
See D2SetDpiRT for more information on developing a dpi-aware program with GFA-BASIC 32.
D2SetDpiRT, D2SetRT, D2GetRT, D2Resize
{Created by Sjouke Hamstra; Last updated: 06/06/2021 by James Gaite}