Thread Tools Display Modes
09-15-05, 05:54 AM   #1
ltdeta
A Murloc Raider
Join Date: Sep 2005
Posts: 9
Question Drag & Drop Save position

i have implemented drag and drop functionality for my MiniMapButton-Frame

it works perfect but then i exit the game and reenter
the position are reset



can anybody help me please ?
  Reply With Quote
09-15-05, 07:09 AM   #2
farang
A Deviate Faerie Dragon
 
farang's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 19
you need to Save the Positions between sessions.

http://www.wowwiki.com/HOWTO:_Save_V..._Game_Sessions
  Reply With Quote
09-22-05, 09:45 AM   #3
ltdeta
A Murloc Raider
Join Date: Sep 2005
Posts: 9
Question

i can save the values but i have problems restoreing the postion after load

i use this for saving drag/drop position

Code:
.....
AgentButton:StopMovingOrSizing()
AgentButton_BeingDragged = false;
local x,y = this:GetCenter();
local px,py = this:GetParent():GetCenter();
local ox = x-px;
local oy = y-py;
RogueAgent.AgentButtonXOffset=ox;
RogueAgent.AgentButtonYOffset=oy;
RogueAgent.AgentButtonScale=AgentButton:GetScale();
......
and i used this for restoring the postion
Code:
....						
AgentButton:SetScale(RogueAgent.AgentButtonScale);

local px,py = AgentButton:GetParent():GetCenter();

AgentButton:SetPoint("TOPLEFT","UIParent","BOTTOMLEFT",px+(RogueAgent.AgentButtonXOffset/RogueAgent.AgentButtonScale),py+(RogueAgent.AgentButtonYOffset/RogueAgent.AgentButtonScale));
....
the position after loading is not the same exit the game

does anybody now how to use the API function SetPoint correcty ?
  Reply With Quote
09-22-05, 10:16 AM   #4
farang
A Deviate Faerie Dragon
 
farang's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 19
yeah no wonder it doesn't work.

you mix the positions a bit ,so it will always shift with the same amount.

i will try to do an example later on and post it here.
  Reply With Quote
09-22-05, 04:24 PM   #5
ltdeta
A Murloc Raider
Join Date: Sep 2005
Posts: 9
that would be great
  Reply With Quote
09-22-05, 07:40 PM   #6
Kaelten
Jack's raging bile duct
 
Kaelten's Avatar
Featured
Join Date: May 2005
Posts: 782
check out the code I wrote in KC_Mobility, it does this by using GetTop and GetLeft
__________________
WowAce.com & CurseForge.com Adminstrator
Developer of Ace3, OneBag3, and many other addons and libraries
Project lead and Mac developer for the Curse Client

Anyone that needs what they want
And doesn't want what they need
I want nothing to do with
  Reply With Quote
09-23-05, 03:49 AM   #7
farang
A Deviate Faerie Dragon
 
farang's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 19
well ,you heard the pro

I shortly played with it yesterday (also with GetRight(), GetLeft()) , but i noticed that with my frames, the position is saved itself ,there was actually no need to set the positions myself.

Propably depends on the way the frame was created (the attributes?) , but i don't know for how long the positions are kept.

Propably safer to care for the positions yourself.
  Reply With Quote
09-23-05, 06:10 AM   #8
Kaelten
Jack's raging bile duct
 
Kaelten's Avatar
Featured
Join Date: May 2005
Posts: 782
many frames will save themselves but it also depends on how they where saved, there is an api call you can set that spost to make it think it was moved and remember its new location in the layout-cache.txt. Well it didn't work for the AH because that screen is 'doublewide'

Anyway, biggest thing about GetTop is that it returns how far the top is from the bottom of the screen not the top

so when you set it back up you'll have to do thi

frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y)

pretty sure thats correct order. I tried binding it to the TOPLEFT and it kept wondering about the screen for a while.
__________________
WowAce.com & CurseForge.com Adminstrator
Developer of Ace3, OneBag3, and many other addons and libraries
Project lead and Mac developer for the Curse Client

Anyone that needs what they want
And doesn't want what they need
I want nothing to do with
  Reply With Quote
09-23-05, 07:40 AM   #9
Littlejohn
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 90
You guys correct me if I'm wrong, but I think the OP thinks that GetCenter and SetPosition take absolute coordinates. Don't both of those APIs use relative coordinates by default? The broken code is adding the parent offset twice: once manually in the Lua code and once inside the WoW API.
  Reply With Quote
10-05-05, 04:35 AM   #10
Gorak
A Fallenroot Satyr
Join Date: Oct 2005
Posts: 21
The Widget API documents a command Frame::SetUserPlaced( bool isUserPlaced ). Calling this function on a frame object or one of it's derivates will notify the UI system that this frame is user-placed and it's position should be saved to the layout-cache file.

For example, the following creates a frame which supports drag & drop, saves it's position and is scaled according to the main interface settings, all without a single line of LUA code:
Code:
<Frame name="DummyFrame" parent="UIParent" movable="true" enableMouse="true">
   <Scripts>
      <OnLoad>
              this:RegisterForDrag("LeftButton");
              this:SetUserPlaced( true );
       </OnLoad>
       <OnDragStart> this:StartMoving(); </OnDragStart>
       <OnDragStop> this:StopMovingOrSizing(); </OnDragStop>
   </Scripts>
</Frame>
You could further customize this frame by saving a variable that determines a relative scale for the frame. This relative scale allows you to set the "main" scale of the UI by using the interface options, and then re-scaling the frame itself in relation to the existing scale. This relative scale could move between 0.5 to 1.5, with 1 being the same as the parent's scale.

This approach of position-saving works for all frames or their derivates. It might not work for frames that are span over multiple monitors, as the viewport-mechanism isn't due to arrive until 1.8.

- Gorak

Last edited by Gorak : 10-05-05 at 04:38 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Drag & Drop Save position


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off