Author Topic: UITexture custom  (Read 3258 times)

zyap

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
UITexture custom
« on: April 23, 2015, 12:49:28 PM »
Hi guys,
I'm new to the forum and currently using NGUI for work.
I have some questions in regards to UITexture.

There are types such as : Simple, Sliced, Tiled, Filled, and Advanced.
But none of these options seems to fit how I want to display images.

For example, I have attached 2 images.
Currently if you want to keep the aspect ratio of the image, you have to set Fixed Aspect to true. Now while that keeps the aspect ratio of the image, any resizing of the object, it will have empty spaces (left and right  as seen in the bottom section of the image that I attached).
The top section of the image is what I want to achieve. I managed to do this by creating my own UITextureCustom and changing some code.

I guess my first question is:
1) Is this achievable using the default UITexture? Maybe I overlooked some options.
My second question is this:
2) If this is not achievable using the default UITexture, how can I make it so that the path of the image that is outside the object are not rendered (drawed).
This is achievable if I put this object into a UIPanel and set its anchor to fit the UIPanels. But that seems like a hacky solution for me.

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture custom
« Reply #1 on: April 24, 2015, 07:47:33 AM »
Anchor the object on left and right, leaving top and bottom not anchored. Set the desired aspect ratio. Done.

zyap

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UITexture custom
« Reply #2 on: April 24, 2015, 10:22:47 AM »
I tried it. It gave me something similar to the bottom section of the picture I posted originally.
I've attached the result.
Anyway to achieve the top section of the image? While not rendering the top and bottom part that is outside the box.

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture custom
« Reply #3 on: April 27, 2015, 04:22:04 PM »
Your pic tells me that you didn't anchor it properly. Anchoring set to advanced, left side anchored to anchor to camera's left. Right side anchored to camera's right. Top and bottom left not anchored. UITexture should be in the center of the screen, with the central pivot. Fixed aspect ratio.

zyap

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: UITexture custom
« Reply #4 on: April 27, 2015, 09:19:51 PM »
I see where this is going at. Eventhough this does achieve the effect of removing the left and right side. This isnt exactly what I wish to achieve.

I would not want to rely on the Camera as the images would cut off where the screen cuts off.
What if I would like some padding between the end of the image and the end of the screen.
Not only that, I would like to remove the top and bottom sections of the image if the UITexture is tall, while the image itself is wide.

I dont want to rely of UIPanel or the camera to essentially not render certain parts of an image.
Somewhat like UITexture's type "Tiled", where the image covers the entire UITexture's boundary and anything outside of it is not rendered.

The reason I'm not using Tiled is because it zooms in too much on the image, I would like to view the majority of the image. Just like the top section of the 1st image I posted, except I would want the top and bottom part of the image that is outside UITexture's boundary not to be rendered.



Not sure if I clarify that enough to explain the effect I would like to achieve.

Thanks for the help though.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITexture custom
« Reply #5 on: April 29, 2015, 06:21:22 PM »
If you create a component derived from UITexture, you can overwrite the OnFill method and feed your own vertices inside to be whatever you want -- positions, UV coordinates, everything.