Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 21, 2019 2:22 pm

All times are UTC - 5 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Automating Window Layout Mac IDE to Windows and Linux
PostPosted: Mon Oct 11, 2010 2:20 pm 

Joined: Mon Apr 02, 2007 5:51 pm
Posts: 420
Location: Cosalient EHR in Washington
Textsize and control positions often need readjustment to look correct when porting an app from MacOS IDE to other platforms. I save a lot of work by letting my apps do it for me. This slightly increases PushButton and Bevelbutton size and repositions for Windows and Linux. Also changes textsizes of multiple controls so text better matches Mac IDE appearance.

Of course, you'll want to test the results under each target OS and rejigger the Mac version so all end up with a decent appearance.

In each window you want automatically adjusted, add this to its open event

if not hasFixedWindowAppearance then
hasFixedWindowAppearance = true

also add a property to those windows

hasFixedWindowAppearance As Boolean = false

Place the following two methods in a module so they can be used globally

This first one does the actual layout readjustment

'Adjust text sizes and buttons of a window to look better cross platform based on layout in Mac IDE
'this must be called only once in open event of window.
'by Guy Kuo

#pragma BackgroundTasks false

#if TargetLinux or TargetWin32

dim i , imax as integer
dim scalingFactor as double
dim dpi as integer
dim aControl as control
const kBaseTextSizeIfZero = 12

dpi = screenDPI
if dpi < 10 then exit

scalingFactor = (96/dpi) 'factor to scale from mac 96 dpi pixel size to windows equivalent size per inch

imax = w.ControlCount-1

for i = 0 to imax
aControl = w.Control(i) 'assign for better code readability

if aControl isa textField then '-----------------------------

if textField(aControl).TextSize <> 0 then
textField(aControl).TextSize = round(scalingFactor * textField(aControl).TextSize) 'base on actual textsize
textField(aControl).TextSize = round(scalingFactor * kBaseTextSizeIfZero) 'base on 12

elseif aControl isa textArea then '-----------------------------

if textArea(aControl).TextSize <> 0 then
textArea(aControl).TextSize = round(scalingFactor * textArea(aControl).TextSize)
textArea(aControl).TextSize = round(scalingFactor * kBaseTextSizeIfZero)

elseif aControl isa staticText then '-----------------------------

if staticText(aControl).TextSize <> 0 then
staticText(aControl).TextSize = round(scalingFactor * staticText(aControl).TextSize)
staticText(aControl).TextSize = round(scalingFactor * kBaseTextSizeIfZero)

elseif aControl isa ListBox then '-----------------------------

if ListBox(aControl).TextSize <> 0 then
ListBox(aControl).TextSize = round(scalingFactor * ListBox(aControl).TextSize)
ListBox(aControl).TextSize = round(scalingFactor * kBaseTextSizeIfZero)

elseif aControl isa CheckBox then '-----------------------------

if CheckBox(aControl).TextSize <> 0 then
CheckBox(aControl).TextSize = round(scalingFactor * CheckBox(aControl).TextSize)
CheckBox(aControl).TextSize = round(scalingFactor * kBaseTextSizeIfZero)

elseif aControl isa PushButton then '-----------------------------

if PushButton(aControl).TextSize <> 0 then
PushButton(aControl).TextSize = round(scalingFactor * PushButton(aControl).TextSize)
PushButton(aControl).TextSize = round(scalingFactor * kBaseTextSizeIfZero)

#if TargetLinux then
PushButton(aControl).Top = PushButton(aControl).Top - 5
PushButton(aControl).Height = PushButton(aControl).Height + 10

#if TargetWin32 then
PushButton(aControl).Top = PushButton(aControl).Top - 4
PushButton(aControl).Height = PushButton(aControl).Height + 8

elseif aControl isa BevelButton then '-----------------------------

if BevelButton(aControl).TextSize <> 0 then
BevelButton(aControl).TextSize = round(scalingFactor * BevelButton(aControl).TextSize)
BevelButton(aControl).TextSize = round(scalingFactor * kBaseTextSizeIfZero)

#if TargetLinux then
BevelButton(aControl).Top = BevelButton(aControl).Top - 5
BevelButton(aControl).Height = BevelButton(aControl).Height + 10

#if TargetWin32 then
BevelButton(aControl).Top = BevelButton(aControl).Top - 4
BevelButton(aControl).Height = BevelButton(aControl).Height + 8




This one calculates the target screen dpi for readjusting the text size

Function screenDPI() As integer
dim result as integer = 72

#if TargetWin32
soft Declare Function GetDC Lib "User32" ( hwnd as Integer ) as Integer
soft Declare Sub ReleaseDC Lib "User32" ( hwnd as Integer, hdc as Integer )
soft Declare Function GetDeviceCaps Lib "Gdi32" ( hdc as Integer, index as Integer ) as Integer

dim hdcScreen as Integer = GetDC( 0 )
dim iDPI as Integer = -1

if hdcScreen <> 0 then
iDPI = GetDeviceCaps( hdcScreen, LOGPIXELSX )
ReleaseDC( 0, hdcScreen )
end if

result = iDPI

result = 72

#elseif TargetLinux
'value for Ubuntu best appearance
result = 105


result = 72


return result
End Function

RS 2012r1.1x OSX 10.8.x Win7 XP; MBP17 w OWC SSD

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours

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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group