TGUI rocks
« on: 02 October 2014, 13:50:33 »
  :) :D ;D
Just came by to tell you that I really appreciate your work and cannot wait for 0.7 release. I read on your blog 0.7 has 9-slice-scaling. I'm really looking forward to this.
How will it work? I've had a quick look at the 0.7 Black.conf, don't I need to set the slices manually? Or are you doing some leftSlice.size.x = image.size.x/3? Never mind, I found Texture.cpp. 8)
« Last Edit: 02 October 2014, 14:38:50 by Heinrich »

*

texus

  • *****
  • 1163
    • View Profile
    • Texus's Blog
Re: TGUI rocks
« Reply #1 on: 02 October 2014, 18:47:28 »
Thanks. You will have to wait another year though for a final v0.7 release.

The Texture class is where it is all implemented, but is for internal usage.

Every texture in a theme file has two optional parameters "Part" and "Middle". The part parameter specifies which part of the image to load, while the middle parameter specifies how that part is scaled and if 9-slice scaling is used.

Suppose the image is 200x50 (or at least the part that you load has that size), and middle is given as (10, 20, 180, 15). The rectangle is given as (left, top, width, height) so the result is:
- The left slice would have a width of 10 pixels.
- The top slice is 20 pixels heigh
- The right slice is 200-180-10 = 10 pixels width
- The bottom slice is 50-15-20 = 15 pixels height

9-slice scaling is nice, but most widgets don't use it. There are 2 others ways of scaling. One of them is simply "stretching" everything which is done by not providing a middle rect.
But the other one is HorizontalScaling (which I called split image in 0.6 since this was the only way).

The Button class in Black.conf uses HorizontalScaling for instance.
Code: [Select]
NormalImage = "Black.png" Part( 0, 64, 45, 50) Middle(10, 0, 25, 50)
The line for 9-slice scaling or HorizontalScaling (or even VerticalScaling) is exactly the same. The middle parameter will just detect the one that we want. Here the top and bottom slice are 0 pixels height, thus 9-slice scaling wouldn't be a good option. The image is only split in 3 parts, so the scaling will be done that way. The ratio of the left and right parts will remain the same and only the middle part will be "stretched" horizontally.

There is a reason why I have been writing "stretched" between quotes. In v0.7 you can choose whether you want these parts to be stretched or if the image should be repeated. This can be chosen by adding the word Stretch or Repeat behind the line in the theme file.

There is also a fallback mechanism so that if you try to use 9-slice scaling and the image you draw is too small to use 9-slice scaling then horizontal or normal scaling will be aplied instead to always keep the image on the size that your requested.

That was basically image scaling in v0.7 in a nutshell :).

Re: TGUI rocks
« Reply #2 on: 03 October 2014, 03:39:39 »
Thank you for your thorough answer. In this case, I think I'll be an early adopter to 0.7dev next week.