PDA

View Full Version : Possible code changes to help with alignment


jmarshall
2005-06-30, 20:32
hi all,

as you know, scaling stuff for differing resolutions is a pain currently with python. you have to retrieve the width/height and use that info to scale where you place everything. this also has to be handled by python currently (ie in every script).

the ability to do the scaling within xbmc is ofcourse already there. i'm thinking of perhaps adding the ability for you to specify how python controls should be scaled in a single function call (ie basically specify somewhere in your script what resolution it is designed for, and then not have to worry about other resolutions at all)

the idea is you'd do something like:

xbmc.setscriptresolution(pal_4x3)

and if xbmc is running in a different resolution, it'll auto-scale the controls at render time.

please let me know what you think of this idea.

i'll probably also add xbmc.getresolution() at the same time so that if you want to, you can do custom setups for each resolution.

cheers,
jonathan

C-Quel
2005-06-30, 20:45
that is a great idea. would be nice to see that implemented.

Nuka1195
2005-06-30, 21:16
yes it is a pain, this would be great.

would this scale just positions or could it also scale control's height and width. that would be nice, cause sometimes a controls position is based on another controls height/width.

jmarshall
2005-06-30, 21:34
yes, it'll scale both position and width and height. i'll take a look at how xbmc handles it at the moment (been a while since i wrote it) to see how easily it can be done.

Bernd
2005-07-01, 00:26
sounds great :thumbsup:

will it also scale according to pal / ntsc?

if i remember right the skin contains different control positions for pal and ntsc.

bernd

Kain
2005-07-01, 05:54
dude that would be awesome, a lot of my favorite scripts dont have 720p support :(

jmarshall
2005-07-01, 12:29
ok, as promised, two new window functions have been added:

getresolution() - returns the current resolution that xbmc is running in. numbers between 0 and 9 inclusive - you can find them in guilib/graphicscontext.h, but here they are for reference anyway, including there frame sizes and pixel ratios.

hdtv_1080i = 0, (1920x1080, 16:9, pixels are 1:1)
hdtv_720p = 1, (1280x720, 16:9, pixels are 1:1)
hdtv_480p_4x3 = 2, (720x480, 4:3, pixels are 4320:4739)
hdtv_480p_16x9 = 3, (720x480, 16:9, pixels are 5760:4739)
ntsc_4x3 = 4, (720x480, 4:3, pixels are 4320:4739)
ntsc_16x9 = 5, (720x480, 16:9, pixels are 5760:4739)
pal_4x3 = 6, (720x576, 4:3, pixels are 128:117)
pal_16x9 = 7, (720x576, 16:9, pixels are 512:351)
pal60_4x3 = 8, (720x480, 4:3, pixels are 4320:4739)
pal60_16x9 = 9 (720x480, 16:9, pixels are 5760:4739)

this should help you to custom design for a particular resolution (eg a widescreen one).

setcoordinateresolution(long resolution)

this sets the coordinate resolution that you are using for the controls.

eg. you just design your script for (say) pal_4x3, thus having all coordinates designed so that it'll fit nicely onto a 720x576 drawing area (remember to allow for overscan!).

then you call setcoordinateresolution(pal_4x3), and if the user running your script is using 720p, xbmc will auto-scale all the control positions and sizes at render time up so that everything fits into 1280x720.

you can call setcoordinateresolution() whenever you like - it doesn't have to be before you create the controls, though that is the logical place to do so.

i haven't tested the above functions, so please test and report back on how fantastically it works ;)

cheers,
jonathan

EnderW
2005-07-01, 13:37
wonderful, wonderful! nice work

i don't have time to test right now, but i hope somebody else will :)

Kain
2005-07-01, 16:07
sweet dude, ill try it on the xmovie guide tonight when i get home from work :kickass:

nianhbg
2005-07-01, 17:57
:thumbsup: :bowdown:

Nuka1195
2005-07-02, 02:15
i have a little test.py script that has some images and labels and a button. that might be a good test for the scaling.

i'm on plain ol ntsc 4:3, if someone would like to test the new features for other resolutions, i could send it to you.

sorry no ftp access, unless it could be hosted here.there are two files test.py and test.png.

i use pmiii, so the fonts may not look right in another skin and it requires panel2.png, which i think most skins have.

http://img221.imageshack.us/img221/1338/scaling7eh.th.jpg (http://img221.imageshack.us/my.php?image=scaling7eh.jpg)

Nuka1195
2005-07-02, 04:42
just for fun i tried changing:

self.setcoordinateresolution(ntsc_4x3)
to:
self.setcoordinateresolution(hdtv_1080i)

and it didn't change anything. i set all the values for the above variables at the beginning of the script, so that's not the problem.

print self.getresolution() correctly returns 4

i tried for both a window and a windowdialog. i called setcoordinateresolution() before and after the controls were added.

did i miss something?

Nuka1195
2005-07-02, 16:17
thanks jonathan,

after playing around with this for a while. this is going to work out really nice. (fantastically)

going from widescreen to non-widescreen you can see it stretch, correct me if i'm wrong that wouldn't work right with just using scalex, they would have looked different on the two platforms.

great job.

Kain
2005-07-03, 02:06
ok im not much good with python but i thought i would give this a try. i tried adding it to xmovie guide and it keeps telling me that the global name is not defined. i tried with self.setcoordinateresolution(ntsc_4x3) and with self.getresolution()

same thing with each. am i missing something here? would anyone be will to add in the piece for the xmovie guide and post it here or send it to me? i can usually figure it out once i have seen it done correctly*:kickass:

Nuka1195
2005-07-03, 03:21
did you place it directly under:

class movieguide(xbmcgui.window):
* *def ..init..(self, bkgd = ""):

and did you update your build today?

edit: also is the following at the begining of the script?

ntsc_4x3 = 4 # (720x480, 4:3, pixels are 4320:4739)

Kain
2005-07-03, 04:01
sweet dude, worked like a charm. i forgot to define ntsc_4x3 at the beginning of the script. cheers dude :kickass:

Nuka1195
2005-07-03, 19:40
jonathan,

i was playing with this some more and it appears the list control does not scale height, it scales position and width only.

Asteron
2005-07-18, 23:41
hi jonathan,
i just thought that this functionality could solve the overscan problems my tv has with some scripts.

do you think that there could be a setting to set the scaled resolution to the video calibration setting? im hoping it's as simple as that. thanks so much!

-ast
/fellow jonathan irl (-:

Asteron
2005-12-08, 20:42
given the tight real estate i vote to un stickify this thread.

Nuka1195
2006-01-18, 03:25
hi jonathan,

i've just been able to play with self.setcoordinateresolution(ntsc_4x3) on 720p resolution.

to get controlimages to scale so they look close to the original i had to use this formula. it's probably not exact, but it looks alot better. the .91 is from dividing the 4:3 pixel ratio compared to the 1:1 of 720p.

self.padw = int(float((300 / 4)* 3 / .91))

should your code do this automatically, it appears the list control is scaling correctly.

the 1st picture is 720p with the formula, the second is 720p without the formula and the 3rd is the original at 480ntsc

http://www.supload.com/thumbs/default/720p_edited.jpg (http://www.supload.com/free/720p_edited.jpg/view/)
http://www.supload.com/thumbs/default/720p_unedited.jpg (http://www.supload.com/free/720p_unedited.jpg/view/)
http://www.supload.com/thumbs/default/native_4x3.jpg (http://www.supload.com/free/native_4x3.jpg/view/)

jmarshall
2006-01-18, 04:57
i don't think so, no.

the problem is basically the aspect ratio changes. if i did this then anything full screen in 4x3 wouldn't be fullscreen in 720p (and vice-versa).

images are the only thing this really effects (ie size of dialog boxes is not as much of an issue) and the <keepaspectratio> tag in the skin (and i think you can set this from python as well?) takes care of that.

the skin uses 2 resolutions (pal and pal16x9) as the base for exactly this reason, and i don't think there's an easy way to do any automatic conversion.

you could probably do it on the fly by setting the window coordinate system to be ntsc16x9 rather than ntsc if using a widescreen mode?

any ideas are welcome :)

cheers,
jonathan

Nuka1195
2006-01-18, 19:33
thanks jonathan,

getresolution() and then setcoordinateresolution() to ntsc or ntsc_16x9 based on if getresolution() is a widescreen result works. i'll test more, but it worked for 720p.

Alexpoet
2006-07-13, 22:40
Okay, I wasn't around to post when this was added, but this is all kinds of awesome! Thank you so much for adding this functionality.

Gonna plug it into all of my scripts and consider it a major update for each of them....