Welcome, Guest
Username: Password: Remember me
CodeTyphon MacOS Development, discussions and problems
  • Page:
  • 1

TOPIC:

HiDPI images in menus 4 years 1 month ago #15032

  • Premysl Beran
  • Premysl Beran's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 52
  • Thank you received: 0
Hi all,

Recently, I find out that the TImageList component support HiDPI image export. I used it for adding icons to my TToolButtons and it works perfectly. I have very nice sharp images. I added the same ImageList to be used also for one of my TPopupMenu. But unfortunately, those images are blurred.

I found the procedure of how the tool button is painted and it uses the following method to draw the icon:
ImgList.ResolutionForPPI[FToolBar.ImagesWidth, Font.PixelsPerInch, GetCanvasScaleFactor]
        .Draw(Canvas, IconPos.X, IconPos.Y, ImgIndex, ImgEffect);

I tried to find similar for the TMenuItem, but I was unsuccessful. I tried the OwnerDraw method, but it seems doesn't work for me. Can anyone help me out how to get the sharp images also for the menu items? Thanks in advance.

With best regards

Premek

Please Log in or Create an account to join the conversation.

HiDPI images in menus 4 years 1 month ago #15033

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4523
  • Thank you received: 1108
Thanks Sir
Please
-your OS-CPU ?
-your CodeTyphon version ?
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

HiDPI images in menus 4 years 1 month ago #15034

  • Premysl Beran
  • Premysl Beran's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 52
  • Thank you received: 0
Hi Sternas,

macOS Catalina, CT 7.1

Premek

Please Log in or Create an account to join the conversation.

HiDPI images in menus 4 years 1 month ago #15035

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4523
  • Thank you received: 1108
My suggestion
for MacOS is to
test and LAB CT ver 7.20 OR
to wait for final CT ver 7.20 (soon, I hope)

LAB CT 7.20 on MacOS has many changes.
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

HiDPI images in menus 4 years 1 month ago #15036

  • Premysl Beran
  • Premysl Beran's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 52
  • Thank you received: 0
Hi Sternas,

I just tried the latest CT LAB 7.18, but with the same results. In the attachment is the screenshot of part with toolbutton with sharp images and popup menu with blurred one. They use the same image list component.

The menu uses to extract and store the image in TBitmap. The toolbutton is drawing directly on the canvas.

There is a GetBitmap function using the following code for extracting image from image list:
iml.ResolutionForPPI[imw, 96, 1].Resolution.GetBitmap(ImageIndex, FBitmap);

But I was not able to find the procedure where the menu bitmap is drawn on the canvas as for toolbuttons.

All other components as TBitBtn, TSpeedButton and TToolButton handle the images very nicely, only menus are blurred.

With best regards

Premek

Please Log in or Create an account to join the conversation.

HiDPI images in menus 3 weeks 3 days ago #18594

  • Premysl Beran
  • Premysl Beran's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 52
  • Thank you received: 0
Hi Sternas,
It has been some time. The menu images still don't work well. I prepared the test project with some DPI calculations. The ToolButton, BtnButtons or Speed button works quite nicely. When I change the monitor with a different DPI, they repaint themselves as needed. The menu icons stay the same, and on HiDPI, they look blurry. 

The resolution of my notebook retina display is 2560x1600 for 13.3 inches. That should be DPI around 210, but from the code, I get "only" 72. Does anybody have the same problem? Thanks for your help.

CT 8.3
macOS Sonoma 14.6.1

Please Log in or Create an account to join the conversation.

HiDPI images in menus 3 weeks 3 days ago #18595

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4523
  • Thank you received: 1108
Sir
TMainMenu has problems with HiDPI on "Virtual Resolutions"

1) For your tests
Set Scaled property of MainForm to False
On OnCreate event of MainForm add
Self.AutoAdjustLayout(lapAutoAdjustForDPI, 96, Screen.PixelsPerInch, Self.Width, ScaleX(Self.Width, 96));
set
Self.AutoAdjustLayout(lapAutoAdjustForDPI, 96, 200, Self.Width, ScaleX(Self.Width, 96));

 


2) One solution is to use a Vertical style MainMenu with TTreeView or with other TyphonIDE comp.
PilotLogic Architect and Core Programmer
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

HiDPI images in menus 3 weeks 3 days ago #18596

  • Premysl Beran
  • Premysl Beran's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 52
  • Thank you received: 0
Hi Sternas,

Thanks a lot for your answer. The "AutoAdjustLayout" works for the form itself. It means if I do as you wrote, I get a big form with the toolbars icon of size 32 px, but the menu icons are still 16.

I just tested on Windows HiDPI. The GetDeviceCap get me a proper PPI value, and the menu icons are properly scaled. So it seems that GetDeviceCap has a problem getting proper values on macOS. Below is the output what I get from GetDeviceCap on my Retina screen.



 
Attachments:

Please Log in or Create an account to join the conversation.

HiDPI images in menus 3 weeks 3 days ago #18597

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4523
  • Thank you received: 1108
Tomorrow I will test your project on MacOS 15,
I will report here.

"Cocoa" Platform has many fixes on LAB CT ver 8.50
 
PilotLogic Architect and Core Programmer
The following user(s) said Thank You: Premysl Beran

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

HiDPI images in menus 3 weeks 3 days ago #18599

  • Premysl Beran
  • Premysl Beran's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 52
  • Thank you received: 0
Hi Sternas,

Thanks a lot for the help.

I created an icon which clearly shows which one is selected (in the attachment - *.ico files is not possible to upload directly so it is zipped). If you replace one of those icons in the project with that one with all the resolutions, you can see what icon is selected for individual glyphs. I attached also print screens of the different systems handling as well as your proposed solution.  


Some more info:

in cocoawinapi.inc, there is LOGPIXELSX and LOGPIXELSY fixed to 72. I found info about the backingFactor which should be used for HiDPI. (wiki.freepascal.org/Cocoa_DPI and developer.apple.com/documentation/appkit...9-backingscalefactor)

When I modified the code in my project to the following, I got ± a good DPI. 
PixW := Round(NSScreen.mainScreen.frame.size.width * NSScreen.mainScreen.backingScaleFactor);  
PixH := Round(NSScreen.mainScreen.frame.size.height * NSScreen.mainScreen.backingScaleFactor);  

DevW := Round(NSScreen.mainScreen.frame.size.width / 72 * 25.4 / (PixW/PixH));  
DevH := Round(NSScreen.mainScreen.frame.size.height / 72 * 25.4 / (PixW/PixH));  
 

Please Log in or Create an account to join the conversation.

Last edit: by Premysl Beran. Reason: More info attached

HiDPI images in menus 3 weeks 2 days ago #18601

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4523
  • Thank you received: 1108
Thanks
sorry for the delay but we have problem with XCode 16 on MacOS 15 Sequoia
(with XCode 15.x  on MacOS 15 All are OK.)

Give us time to fix CT building.

The ERROR:
error: non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs

Assembling rtti
rtl-objpas/units/x86_64-darwin/rtti.s:14:1: error: non-private labels cannot appear between .cfi_startproc / .cfi_endproc pairs
_$RTTI$_Lj169:
^
rtl-objpas/units/x86_64-darwin/rtti.s:8:1: error: previous .cfi_startproc was here
.cfi_startproc
^
rtti.pp(7329) Error: Error while assembling exitcode 1
rtti.pp(7329) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

Last edit: by Sternas Stefanos.

HiDPI images in menus 2 weeks 4 days ago #18607

  • Premysl Beran
  • Premysl Beran's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 52
  • Thank you received: 0
Hi Strenas,

fixing CT is certainly the priority. :-)

I did some more tests. It is possible to get the resolution directly from the NSScreen object. It provides a basic logical resolution of 72 dpi (this is hardcoded in the GetDeviceCap function for macOS), or for HiDPI monitors, it gives this basic logical resolution multiplied by that scaling factor (link in the previous post). Hope that it helps.
var
    res: NSValue;
    res_: NSSize;
    scale: Double;
    fr: NSRect; 

res := NSScreen.mainScreen.valueForKey(NSSTR('resolution'));
res.getValue(@res_);
scale := NSScreen.mainScreen.backingScaleFactor;
fr := NSScreen.mainScreen.frame;

ShowMessage(Format('Screen width: %0.0f height: %0.0f res_X: %0.0f res_Y: %0.0f scale factor: %f', [fr.size.width * scale, fr.size.height * scale, res_.width, res_.height, scale]));
                   

Please Log in or Create an account to join the conversation.

HiDPI images in menus 2 weeks 4 days ago #18608

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4523
  • Thank you received: 1108
Thanks Sir
We will try to add this to LAB CT
PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

  • Page:
  • 1