It is currently Thu Jul 18, 2019 2:30 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Please update ButtonImageGadget example
PostPosted: Sun Apr 14, 2019 8:32 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1759
Location: Germany
New example with DPI
Code:
;-TOP

Procedure LoadImageDPI(Image, File.s)
  Protected Result, ResolutionX.f, ResolutionY.f
 
  ResolutionX = DesktopResolutionX()
  ResolutionY = DesktopResolutionY()
  Result = LoadImage(Image, File)
  If Result
    If Image = #PB_Any
      ResizeImage(Result, ImageWidth(Result) * ResolutionX, ImageHeight(Result) * ResolutionY)
    Else
      ResizeImage(Image, ImageWidth(Image) * ResolutionX, ImageHeight(Image) * ResolutionY)
    EndIf
  EndIf
  ProcedureReturn Result
EndProcedure

If OpenWindow(0, 0, 0, 200, 100, "ButtonImage", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If LoadImageDPI(0, #PB_Compiler_Home + "/Examples/Sources/Data/PureBasic.bmp")
    ButtonImageGadget(0, 10, 10, 180, 50, ImageID(0))
  EndIf
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Please update ButtonImageGadget example
PostPosted: Sun Apr 14, 2019 10:55 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3598
Location: Berlin, Germany
There are the functions DesktopScaledX() and DesktopScaledY().

So e.g. instead of
Code:
ResolutionX = DesktopResolutionX()
ImageWidth(Result) * ResolutionX

you can just use
Code:
DesktopScaledX(ImageWidth(Result))
:-)

Also, the code for resizing should be enclosed in
Code:
CompilerIf #PB_Compiler_OS = #PB_OS_Windows And #PB_Compiler_Version >= 570
   ; ...
CompilerEndif

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Please update ButtonImageGadget example
PostPosted: Sun Apr 14, 2019 11:07 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1759
Location: Germany
Thanks :wink:
Code:
;-TOP

Procedure LoadImageDPI(Image, File.s)
  Protected Result
 
  Result = LoadImage(Image, File)
  If Result
    If Image = #PB_Any
      ResizeImage(Result, DesktopScaledX(ImageWidth(Result)), DesktopScaledY(ImageHeight(Result)))
    Else
      ResizeImage(Image, DesktopScaledX(ImageWidth(Image)), DesktopScaledY(ImageHeight(Image)))
    EndIf
  EndIf
  ProcedureReturn Result
EndProcedure

If OpenWindow(0, 0, 0, 200, 100, "ButtonImage", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If LoadImageDPI(0, #PB_Compiler_Home + "/Examples/Sources/Data/PureBasic.bmp")
    ButtonImageGadget(0, 10, 10, 180, 50, ImageID(0))
  EndIf
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye