<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">

-- Create MiniMapCords Frame
<Frame name="MiniCoordsMiniMapFrame" parent="MinimapCluster"	enableMouse="true" hidden="false"	frameStrata="MEDIUM" movable="true">
		<Size>
			<AbsDimension	x="40" y="10"/>
		</Size>
		<Anchors>
			<Anchor	point="BOTTOM" relativeTo="Minimap"	relativePoint="BOTTOM">
				<Offset>
					<AbsDimension	x="0"	y="0"/>
				</Offset>
			</Anchor>
		</Anchors>
		<Layers>
			<Layer level="ARTWORK">
				-- Create a FontString within the MiniMapCordsFrame
				<FontString	name="MiniCoords" toplevel="true" hidden="false"	inherits="GameFontNormal"	text="">
					<Anchors>
						<Anchor	point="CENTER">
							<Offset>
								<AbsDimension	x="0"	y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>
		<Scripts>
			<OnLoad>
				-- Registering the event and set the Initalizing text
				this:RegisterEvent("ZONE_CHANGED_NEW_AREA")
			</OnLoad>
			<OnEvent>
				-- If we go to a new area, need to set the map that region to get the exact coords.
				if (event == "ZONE_CHANGED_NEW_AREA") then
					SetMapToCurrentZone()
				end
			</OnEvent>
			<OnUpdate>
				-- Write the coordinates if it's valid, or "instance" if we're an Instance (maybe get this message in another circumstances)
				if (not WorldMapFrame:IsVisible() and Minimap:IsVisible()) then
					SetMapToCurrentZone()
					MiniCoords:Show()				
					local mult = 10^0
					local MiniMap_px, MiniMap_py = GetPlayerMapPosition("player")
					if (MiniMap_px > 0 and MiniMap_py > 0) then
						output = math.floor(((MiniMap_px * 100) * mult + 0.5) / mult)..","..math.floor(((MiniMap_py * 100) * mult + 0.5) / mult)
						MiniCoords:SetText(output)
						MiniCoords:SetTextColor(0.5, 1, 0.5)
						--For WorldMap text
						playerCoordsText = "|cff88ff88"..output.."     |cffbbbb00".."-"..GetZoneText().."-"
					else
						output = "Instance"
						MiniCoords:SetText(output)
						MiniCoords:SetTextColor(1, 0.5, 0.5)
						--For WorldMap text
						playerCoordsText = "|cffff8888"..output.."     |cffbbbb00".."-"..GetZoneText().."-"
					end
				else
					MiniCoords:Hide()
				end
			</OnUpdate>
			<OnMouseDown>
				-- We can drag the coords text via the LeftMouseButton or paste our position in the chat editbox
				if(arg1== "LeftButton")	then
					if(IsShiftKeyDown())	then
						if (ChatFrameEditBox:IsVisible()) then
							local msg = "My location: "..GetRealZoneText().." ("..MiniCoords:GetText()..")"
							ChatFrameEditBox:Insert(msg)
						end
					else
						this:StartMoving()
					end
				end
					this.isMoving = true		
			</OnMouseDown>
			<OnMouseUp>
				if(this.isMoving) then
					this:StopMovingOrSizing()
					this.isMoving = false
				end		
			</OnMouseUp>
		</Scripts>
	</Frame>

	<Frame name="MiniCoordsWorldMapFrame" parent="WorldMapFrame">
		<Layers>
			<Layer level="ARTWORK">
				<FontString name="MiniCoordsCursorCoords" inherits="GameFontNormal" justifyH="LEFT">
					<Anchors>
						<Anchor point="LEFT" relativeTo="WorldMapFrame" relativePoint="CENTER">
							<Offset>
								<AbsDimension x="-160" y="-367"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="MiniCoordsPlayerCoords" inherits="GameFontNormal" justifyH="LEFT">
					<Anchors>
						<Anchor point="LEFT" relativeTo="WorldMapFrame" relativePoint="CENTER">
							<Offset>
								<AbsDimension x="40" y="-367"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>
		<Scripts>
			<OnLoad>
					MiniCoordsCursorCoords:Show()
					MiniCoordsPlayerCoords:Show()
			</OnLoad>
			<OnUpdate>
				if (WorldMapFrame:IsVisible()) then
					local OFFSET_X = 0.0022
					local OFFSET_Y = -0.0262
					local mult = 10^0
					local cursorCoordsText = ""
					MiniCoordsPlayerCoords:SetText("|cffffffffPlayer(X,Y): "..format("%s", playerCoordsText))
					local x, y = GetCursorPosition()
					local x = x / WorldMapFrame:GetScale()
					local y = y / WorldMapFrame:GetScale()
					local centerX, centerY = WorldMapFrame:GetCenter()
					local width = WorldMapButton:GetWidth()
					local height = WorldMapButton:GetHeight()
					local adjustedX = (x - (centerX - (width/2))) / width
					local adjustedY = (centerY + (height/2) - y ) / height
					local cx = (adjustedX + OFFSET_X)
					local cy = (adjustedY + OFFSET_Y)
					cursorCoordsText = format("%d, %d", 100 * cx, 100 * cy)
					MiniCoordsCursorCoords:SetText("|cffffffffCursor(X,Y): ".."|cff88ff88"..format("%s", cursorCoordsText))
				end
			</OnUpdate>
		</Scripts>
	</Frame>
</Ui>
