Author Topic: Color Picker  (Read 13570 times)

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
Re: Color Picker
« Reply #15 on: February 12, 2013, 11:03:23 AM »
Where would you take that part into account?  I'm not sure what you mean by this, because I thought that WAS the origin point.

I've updated my previous post with an example image to help grasp the problem better.


To clarify further, it appears to be giving me correct coordinates in the debug, since clicking in the bottom left hand corner of the image gives back 1,1.

Also, changing my screen size seems to throw off how wrong the point click is even more.  Using a small screen gives me a blue color when clicking near the "1".
« Last Edit: February 12, 2013, 11:14:17 AM by Disastercake »
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Color Picker
« Reply #16 on: February 13, 2013, 02:11:17 PM »
Ok let's start from the beginning.

transform.position is world space, which you shouldn't be using it at all. Touch position is in screen space: UICamera.lastTouchPosition.

Take your widget's cachedTransform.localPosition and apply the UIWidget's pivotOffset, scaled by the transform's scale:
  1. cachedTransform.localScale.Scale((Vector3)widget.pivotOffset);
...this gives you the pixel-size pivot offset that you then add to your UIWidget's cachedTransform.localPosition to figure out the actual origin point (top left corner).

You may then need to add parent transform offsets leading up to this widgets if you've moved one of the parents. Make sure to add up localPosition, never transform.position.

Now that you have true screen-coordinate full top-left corner, the rest should be easy.