"If" commands Thread last updated on 2004-03-04 12:01:20

Posted by member 117088 on 2004-03-03 22:33:34

I’m working on a set of If statements to relocate some buttons according to my screen resolution. This would not be as much of a big deal if I didn’t have dual monitors…but I do and I’m not giving them up for this! So I’m going to have to reconcile the differences between the theme (Saphardana) and my monitors. :)

My monitors are currently set to 1280x1024 and the line of code I changed to relocate this button works correctly…

*Shortcut "Internet Browser" 1253 -22 spacer3.png spacer4.png .none #2TO !execute ["$Browser$"]

…(just to clear this up before one asks, I using 1253 instead of -27 because my screen width is not 1280, but its 2560 b/c of the dual monitors) Well that works if I don’t change my screen resolution, but I like to change my resolution to accommodate what I’m working on like CAD or PhotoShop. So I wanted to create some If statements to make my life easier. Here is what I wrote…

*Shortcut "File Manager" 12 -22 spacer3.png spacer4.png .none #2TO !execute ["$FileManager$"]
If ResolutionX = 800
*Shortcut "Internet Browser" 773 -22 spacer3.png spacer4.png .none #2TO !execute ["$Browser$"]
If ResolutionX = 1023
*Shortcut "Internet Browser" 996 -22 spacer3.png spacer4.png .none #2TO !execute ["$Browser$"]
If ResolutionX = 1152
*Shortcut "Internet Browser" 1125 -22 spacer3.png spacer4.png .none #2TO !execute ["$Browser$"]
If ResolutionX = 1280
*Shortcut "Internet Browser" 1253 -22 spacer3.png spacer4.png .none #2TO !execute ["$Browser$"]
If ResolutionX = 1600
*Shortcut "Internet Browser" 1573 -22 spacer3.png spacer4.png .none #2TO !execute ["$Browser$"]
EndIf

…The result of this code ends up making the spacer3.png button disappear. I modlded my code after the authors code that changed the BottombarXXX.png file according to the resolution. His looked like this…

If ResolutionX = 800
*Shortcut "" 56 2 Topbar800.png .none .none #1 !None
*Shortcut "" 2 -22 Bottombar800.png .none .none #2 !None
ElseIf ResolutionX = 1024
*Shortcut "" 56 2 Topbar1024.png .none .none #1 !None
*Shortcut "" 2 -22 Bottombar1024.png .none .none #2 !None
ElseIf ResolutionX = 1152
*Shortcut "" 56 2 Topbar1152.png .none .none #1 !None
*Shortcut "" 2 -22 Bottombar1152.png .none .none #2 !None
ElseIf ResolutionX = 1280
*Shortcut "" 56 2 Topbar1280.png .none .none #1 !None
*Shortcut "" 2 -22 Bottombar1280.png .none .none #2 !None
ElseIf ResolutionX = 1600
*Shortcut "" 56 2 Topbar1600.png .none .none #1 !None
*Shortcut "" 2 -22 Bottombar1600.png .none .none #2 !None
EndIf

…So my first question is, can anyone tell me what I’m doing wrong? And/Or is there some way I can have Litestep do some math like taking the screen resolution and dividing it by 2, and then subtract 27 ([R/2]-27)? That would be the best way because I could not have to do as much to make it work. ;-)

Thanks for your help,
Jonboy

Posted by member 37809 on 2004-03-03 22:58:48 link

Something like this might work:
*Shortcut "Internet Browser" $ResolutionX-27$ -22 spacer3.png spacer4.png .none #2TO "$Browser$"
(there's only one action so !execute [] is not needed but can still be there)

Test things like
!alert "$(10-2)/4+1$"
!alert "$ResolutionX/2$"
, etc.

Posted by member 1 on 2004-03-03 23:14:03 link

$resolutionX/2-27$ should get you your desired result. another option would be to use the C flag for X/Y coordinates. This will automagically start you in the middle...but you would need to double 27 to make it work.

ie. $ResolutionX-54$C

Posted by member 99 on 2004-03-04 01:46:22 link

$ResolutionX$ = width of primary monitor alone

Negative coordinates and C depend on how the module deals with multiple monitors. I'm pretty sure shortcut2 does use desktop coordinates (ie, -0 = far right of all monitors), which would make -27C = $ResolutionX-27$ if your second monitor has the same x resolution and is to the right of your primary.

But I think the problem with your code is that you must have a matching EndIf for each If. Otherwise try changing all but the first If to ElseIf, as in the example. (but tnl's code should work)

Posted by member 1 on 2004-03-04 03:00:28 link

when $Resolution $ was originally put in it was the total of all resolutions. From what I can tell though that is still true.

Posted by member 117088 on 2004-03-04 10:31:03 link

Is there some way for LS to tell if there are 2 mons? I was thinking of writing some IF commands that would compare the total X and the total Y to help determin if there were 2 mons, but if there was some way to...

If dualmon
do ABC
If singmon
do XYZ
Endif

Posted by member 99 on 2004-03-04 12:01:20 link

ElseIf! Don't do If ... If ... EndIf. And that's not enough, there could be 3 monitors, and you need to know how they are arranged if you're going to make any use of them anyway.

dev:
StringCchPrintf(szTemp, MAX_PATH, "%d", GetSystemMetrics(SM_CXSCREEN));
SetVariable("ResolutionX", szTemp);

SM_CXSCREEN is primary monitor, SM_CXVIRTUALSCREEN is whole desktop. I do remember it being the total size, but if they're still that way it's only because that specific video driver is lying to Windows.