DesktopX Functions

Object Center in Screen

Sunday, January 18, 2009 by RomanDA | Discussion: DesktopX Tutorials

Im looking at posting some simple code samples and this was one i was asked for. 

 

Its a simple "center" function.  It centers any object in the screen.
It can be modified to work across multiple screens (see code). 

Code: vbscript
  1. Function CenterOBJ(obj)
  2.     '  QUICK and DIRTY "Center" Function
  3.     ' vars:
  4.     ' obj - object name
  5.     '--- if you want to use for multi-monitors change ScreenHeight - VScreenHeight
  6.     sw = system.ScreenWidth
  7.     sh = system.ScreenHeight
  8.     '-- divide these all in 1/2   
  9.     scw = sw / 2 '-- screen center width
  10.     sch = sh / 2 '-- screen center height
  11.     ow = desktopx.Object(obj).Width
  12.     oh = desktopx.Object(obj).height
  13.     '-- divide these in 1/2
  14.     ocw = ow / 2 '-- object center width
  15.     och = oh / 2 '-- object center height
  16.    
  17.     ol = scw - ocw
  18.     ot = sch - och
  19.     desktopx.Object(obj).left = ol
  20.     desktopx.Object(obj).top = ot
  21. End Function

 

To use this function simply use the following code:

Code: vbscript
  1.   Call CenterOBJ("ObjNameHere")

I dont know if people are interested in these types of "tutorials" but if you are, please let me know of some things you would like to see.  Im not sure if this has been posted before (I'm sure it has somewhere).

RomanDA

ZubaZ
Reply #1 Sunday, January 18, 2009 3:21 PM

That's ratehr cool.  Thanks!

Tailsgirl
Reply #2 Sunday, January 18, 2009 3:55 PM

Sweet David, would that script be like semi-locking something to the center? because that would rock!

RomanDA
Reply #3 Sunday, January 18, 2009 5:39 PM

i dont know what you mean by "semi-locking".

This moves whatever object you want to the center of the screen.

Tailsgirl
Reply #4 Sunday, January 18, 2009 6:20 PM

hehe Ok, fully locking it to the center

RomanDA
Reply #5 Sunday, January 18, 2009 6:34 PM

just make the object unable to be moved..

Tailsgirl
Reply #6 Sunday, January 18, 2009 6:39 PM

*smacks forhead* I'm an idiot.. hehe I've seen that option before

PuterDudeJim
Reply #7 Sunday, January 18, 2009 8:08 PM

Thanx, David!

Tailsgirl
Reply #8 Sunday, January 18, 2009 8:56 PM

What I'd really love.. is an easy to follow tut on making a calendar

 

Tailsgirl really WILL start ticking if she makes another clock

PuterDudeJim
Reply #9 Monday, January 19, 2009 12:17 AM

What I'd really love.. is an easy to follow tut on making a calendar

Here is the easiest tut you will find. Go to Martin's gallery, he has a template there intended for you to use for learning calendars. Use your own graphics, give Martin credit for his script.  Easy enough?  Hope this helps.

Tailsgirl
Reply #10 Monday, January 19, 2009 12:42 AM

Jim, is that the calendar with the link to the red DX one? there is a missing PNG listed in the tut, and it's too confusing.. I've tried that a dozen times, basically, I edit existing calandars to use myself, but just can't get them right.. I'd like to do one from scratch, with a template included ... hehe well, that wouldn't be from scratch, but a blank template would be nice, I might be able to get somewhere hehehe, love Martin's stuff though

superman
Reply #11 Monday, January 19, 2009 9:39 AM

thanks

CerebroJD
Reply #12 Friday, February 27, 2009 1:33 AM

As a side note:

system.ScreenWidth and system.ScreenHeight can go a bit crazy on multi-monitor setups that dont use a 1-2-3 lineup of monitors.  Those only get the width/height of the primary monitor.  To determine 'true' width and height on all screens, try using the following:

Code: vbscript
  1. sw = System.VScreenWidth
  2. sh = System.VScreenHeight

However, if you're going to do calculations with this full width, you need to take into account that the left-most pixel wont always be at 0.  For example my secondary monitor is on my left, not my right, which means that its left-most pixel is at -1680.  This means, in order to place the objects properly 'centered' in the full width, you need to use the proper left-value.

Code: vbscript
  1. sw = sw / 2
  2. sh = sh / 2
  3. scw = System.VScreenLeft + sw
  4. sch = System.VScreenTop + sh

After this bit, you still need to do the part that centres the object on that point, but that should get ya started on true positioning on multi-monitor setups.

 

I use a slightly more complex version in this object: Filler

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01