Source language: Translate to:

(Help!) Resize controls

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

(Help!) Resize controls

Postby TonyL » Sun Jun 11, 2006 8:17 pm

Created functions that resize controls in responce to the end users screen resolution. The 1st function (resize 1) I hard-coded the positions and size of the objects in my code and it works well.

The 2nd function (resize 2) I used variables to obtain size and position.
I would like to use this fuction since it requires a lot less coding to write. But I can't seem to get it to work right.

I would appreciate any help anyone can offer.

You can download the pub here: http://www.software-zone.com/neosoft/in ... &f=1&t=345

Thanks,

Tony :(
TonyL
 
Posts: 40
Joined: Mon Sep 19, 2005 7:20 pm

Postby Gaev » Mon Jun 12, 2006 5:04 am

Tony:

Not sure what your objective is ...
The 1st function (resize 1) I hard-coded the positions and size of the objects in my code and it works well.
... yes, the width and height are correctly adjusted ... but the left and top positions are not ... this is because you follow up everything with a
Code: Select all
SetVar "[WindowState]" "Maximized"
... which causes the Container object to re-position all contained objects to locations specified at compile time ... unless you intended the contained objects to retain original left margins, you might try ...
Code: Select all
SetVar "[WindowState]" "Maximized"
Math "0.03*[ScreenWidth]" "0" "[NewButtonLeft]"
Math "0.054*[ScreenHeight]" "0" "[NewButtonTop]"
MoveObject "PushButton1" "[NewButtonLeft]" "[NewButtonTop]"
... etc.
The 2nd function (resize 2) I used variables to obtain size and position.I would like to use this fuction since it requires a lot less coding to write. But I can't seem to get it to work right.
... if you can define your objective ... i.e. what repositioning/resizing do you want to occur.

Note that the way your pub is setup, user can switch between original and maximized state via button on title bar ... which will not automatically invoke actions you have in the menu items.
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby TonyL » Mon Jun 12, 2006 7:10 am

Hi Gaev,

Thanks for the reply. What I want to accomplish is at differnt screen resolutions, the objects retain there original positions and resize so that at any resolution the objects in the interface appear the same size.

I created the pub at 800 X 600 resolution. At 1280 X 1024, the objects on the form are too small. I want to code a resize event that will make the objects look uniform at any resolution.

If you try the (resize 1) function at differnt resolutions, this seems to work well.

If you have a code example on how I may accomplish this it would be much appreciated.

Thanks again for your help,

Tony
TonyL
 
Posts: 40
Joined: Mon Sep 19, 2005 7:20 pm

Postby Gaev » Mon Jun 12, 2006 7:52 am

Tony:
... at differnt screen resolutions, the objects retain there original positions and resize so that at any resolution the objects in the interface appear the same size.
... I am still not clear ...

Say, on an 800 by 600 window, the button's properties are left=100, top=50, width=200 and height=75 ... then, at 1024 by 768 (which is a magnification of 1.28 by 1.28 ), do you want ... left=100*1.28, top=50*1.28, width=200*1.28 and height=75*1.28 ? ... if not please specify desired values ?
I created the pub at 800 X 600 resolution. At 1280 X 1024, the objects on the form are too small. I want to code a resize event that will make the objects look uniform at any resolution.
... I think you mean that you want the width and height to expand/contract by the same proportion as the window size ... but what about the left/top positions ?
If you try the (resize 1) function at differnt resolutions, this seems to work well.
... as I mentioned in my earlier post, only the size appears to work ... not the location ... which will result in a lot of white space on the right and bottom when you go to bigger window sizes.

Also, be aware that NeoBook's container object has built in facilities to do some resizing ... your container has the "snap to center" property set ... but the contained objects do not ... have you looked at this ... before you develop all this code ?

Finally, note that when you increase/decrease the size of objects, you will also need to consider the font sizes of text within ... otherwise you will just be trading one "unesthetic" for another ... might also consider a design where the various contained objects remain the same, but the container is centered with a margin ... so only the margins (left, right, top and bottom) widen/narrow.

Once you provide the requested details, I will try and assist with the commands.
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby TonyL » Mon Jun 12, 2006 9:00 am

Say, on an 800 by 600 window, the button's properties are left=100, top=50, width=200 and height=75 ... then, at 1024 by 768 (which is a magnification of 1.28 by 1.28 ), do you want ... left=100*1.28, top=50*1.28, width=200*1.28 and height=75*1.28 ? ... if not please specify desired values ?


The code above is exactly what I am looking for.

... as I mentioned in my earlier post, only the size appears to work ... not the location ... which will result in a lot of white space on the right and bottom when you go to bigger window sizes.


Can you provide a code example as to how I may get the location to work right?

Thanks again,

Tony
TonyL
 
Posts: 40
Joined: Mon Sep 19, 2005 7:20 pm

Postby Gaev » Mon Jun 12, 2006 10:15 am

Tony:

First, some simple principles ...

a) If the objects are going to be contained inside the Container ... like in your example, you MUST do the resizing of the window first ... otherwise, it looks like the resizing of the Container (to match the window) negates any previous MoveObject commands.

b) In your Startup section ...
Code: Select all
SetVar "[BaseWidth]" "[PubWidth]"
SetVar "[BaseHeight]" "[PubHeight]"
SetVar "[WidthDifference]" "[WindowWidth]-[PubWidth]"
SetVar "[HeightDifference]" "[WindowHeight]-[PubHeight]"
... the difference values will tell you what the Windows Task Bar, your application's Title Bar etc. occupy in your user's machine.

c) When you want to resize the contained objects, resize the window ...
Code: Select all
SetVar "[WindowState]" "Maximized"

... and then calculate and set the [PubWidth]/[PubHeight]
SetVar "[PubWidth]" "[WindowWidth]-[WidthDifference]"
SetVar "[PubHeight]" "[WindowHeight]-[HeightDifference]"

... now, for each object you can multiply its width/height by the a factor of
... [PubWidth]/[BaseWidth] and [PUbHeight]/[BaseHeight]
GetObjectInfo "PushButton1" "Width" "[CurrentWidth]"
Math "([PubWidth]/[BaseWidth])*[CurrentWidth]" "0" "[NewWidth]"
GetObjectInfo "PushButton1" "Height" "[CurrentHeight]"
Math "([PubHeight]/[BaseHeight])*[CurrentHeight]" "0" "[NewHeight]"
SizeObject "PushButton1" "[NewWidth]" "[NewHeight]"

... and if you want ... its left/top ...
GetObjectInfo "PushButton1" "Left" "[CurrentLeft]"
Math "([PubWidth]/[BaseWidth])*[CurrentLeft]" "0" "[NewLeft]"
GetObjectInfo "PushButton1" "Top" "[CurrentTop]"
Math "([PubHeight]/[BaseHeight])*[CurrentTop]" "0" "[NewTop]"
MoveObject "PushButton1" "[NewLeft]" "[NewTop]"

... and repeat for other objects

... and finally update your [BaseWidth] & [BaseHeight] values to reflect the "new" base
SetVar "[BaseWidth]" "[PubWidth]"
SetVar "[BaseHeight]" "[PubHeight]"
... hopefully, this should do what you are looking for ... may I suggest that you try this with just one object ... before raising it one more level into a loop that iterates once for each object ... and if you make your Desktop color, PageColor, Container Background color all different, you will understand what is happening a little better.

Of course, it might be easier to just exploit the facilities in NeoBook's Container object.
User avatar
Gaev
 
Posts: 3737
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby TonyL » Mon Jun 12, 2006 10:44 am

Thanks so much Gaev. I'll work through the code example you gave.


Thanks again for taking the time to help with the code. It is much appreciated.

Tony
TonyL
 
Posts: 40
Joined: Mon Sep 19, 2005 7:20 pm


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest