Author Topic: Resizeable Dragable Sprite  (Read 2534 times)

phenotype

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Resizeable Dragable Sprite
« on: September 15, 2012, 11:48:46 AM »
I have a UIPanel with the UIDraggablePanel script and within that a SlicedSprite which is the background and "container" for other controls. This is my chat dialog. I have this defined as a prefab and can have a number of them on screen at any one time. Now I am trying to add the ability to resize the panel. If the user hovers within x pixels of any edge the resize icon should be displayed and the user should be able to drag the edge within predefined limits. Of course this means the dialog itself should not be dragged during the resizing operation. I just wanted to check with anyone to see if this has been done before. Right off the bat I need to be able to determine if the mouse is close to an edge of a sprite, then I need to turn off dragging the dialog on mouse down and instead pass the delta of the mouse position to the correct dimension of the sprite transform. Any helpful suggestions would be most appreciated.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Resizeable Dragable Sprite
« Reply #1 on: September 16, 2012, 01:11:52 AM »
I've never attempted it myself, but if you have a clipped panel (since you're using a UIDraggablePanel script I assume your panel is clipped), then you will want to adjust its clipped rectangle rather than moving the panel around.

phenotype

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Resizeable Dragable Sprite
« Reply #2 on: September 16, 2012, 11:06:13 AM »
Don't know how that would work. The clipped panel doesn't change the size of the contained widgets. It just changes the limits the widget can be dragged. And I still need to drag I just don't want the widget to move, instead I want to change the size and or position based on the edge selected.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Resizeable Dragable Sprite
« Reply #3 on: September 16, 2012, 07:03:03 PM »
I am not sure what you mean with your last post. Changing the limits the widget can be dragged? If you want to limit the dragging of something, I suggest adding your own limiting logic. It will be easier.

phenotype

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Resizeable Dragable Sprite
« Reply #4 on: September 16, 2012, 08:38:35 PM »
OK I don't think we are understand each other at all. I'll start again from the top.

I require a chat dialog box. I can have zero or more dialogs on screen at any one time. Each dialog should be resizeable and dragable, ie the user can change the size and/or position of the dialog. If the user clicks on the dialog within x pixels of any edge the dialog goes into resize mode and the user can drag the edge to whichever extent they like; otherwise the dialog is simply dragged to a new location. This is pretty standard behaviour for chat dialogs in general.

My Problem is NGUI does not support this resizing natively so I have to write something. So how do I turn off the automatic drag functionality when the user is near an edge of the dialog, so that can intercept the OnDrag calls and resize the dialog?

The dialog is designed as follows; UIPanel with DraggablePanel script, SlicedSprite with DraggablePanelContents script. Dragging works fine. Now I have to figure out resizing.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Resizeable Dragable Sprite
« Reply #5 on: September 16, 2012, 11:27:56 PM »
No need to turn off anything. If you have a collider on the edges of the box covering only the edges, then those colliders will be the ones that receive all mouse events instead of your panel. You can then easily add logic that would resize a window this way. Think of it as creating a collider for each of the 9 pieces of a 9-sliced sprite you're using for the background (assuming you want all 9 sides / corners to react differently).