/*
    Various NUI Helpers
    Created By: Daz
*/

#include "nw_inc_nui"

const string NUI_WINDOW_ROOT_GROUP          = "_window_";

const string NUI_WINDOW_TITLE_BIND          = "wd_title";
const string NUI_WINDOW_GEOMETRY_BIND       = "wd_geometry";

const string NUI_EVENT_OPEN                 = "open";
const string NUI_EVENT_CLOSE                = "close";
const string NUI_EVENT_CLICK                = "click";
const string NUI_EVENT_WATCH                = "watch";
const string NUI_EVENT_MOUSEDOWN            = "mousedown";
const string NUI_EVENT_MOUSEUP              = "mouseup";
const string NUI_EVENT_MOUSESCROLL          = "mousescroll";

json NuiGetCenteredGeometryRect(object oPlayer, float fWindowWidth, float fWindowHeight);
json NuiSetRectWidth(json jRect, float fWidth);
json NuiSetRectHeight(json jRect, float fHeight);
json NuiInsertRow(json jCol, json jRow);
json NuiHeader(json jHeader, float fHeight = 24.0f, float fWidth = 0.0f);
float NuiGetMouseScrollDelta(json jPayload);

json NuiGetCenteredGeometryRect(object oPlayer, float fWindowWidth, float fWindowHeight)
{
    float fGuiScale = IntToFloat(GetPlayerDeviceProperty(oPlayer, PLAYER_DEVICE_PROPERTY_GUI_SCALE)) / 100.0f;

    float fX = IntToFloat(GetPlayerDeviceProperty(oPlayer, PLAYER_DEVICE_PROPERTY_GUI_WIDTH) / 2) - ((fWindowWidth * 0.5f) * fGuiScale);
    float fY = IntToFloat(GetPlayerDeviceProperty(oPlayer, PLAYER_DEVICE_PROPERTY_GUI_HEIGHT) / 2) - ((fWindowHeight * 0.5f) * fGuiScale);

    return NuiRect(fX, fY, fWindowWidth, fWindowHeight);
}

json NuiSetRectWidth(json jRect, float fWidth)
{
    return JsonObjectSet(jRect, "w", JsonFloat(fWidth));
}

json NuiSetRectHeight(json jRect, float fHeight)
{
    return JsonObjectSet(jRect, "h", JsonFloat(fHeight));
}

json NuiInsertRow(json jCol, json jRow)
{
    return JsonArrayInsert(jCol, NuiRow(jRow));
}

json NuiHeader(json jHeader, float fHeight = 24.0f, float fWidth = 0.0f)
{
    json jLabel = NuiLabel(jHeader, JsonInt(NUI_HALIGN_CENTER), JsonInt(NUI_VALIGN_MIDDLE));
    jLabel = NuiGroup(jLabel, TRUE, NUI_SCROLLBARS_NONE);
    jLabel = NuiHeight(jLabel, fHeight);

    if (fWidth > 0.0f)
        jLabel = NuiWidth(jLabel, fWidth);

    return jLabel;
}

float NuiGetMouseScrollDelta(json jPayload)
{
    return JsonGetFloat(JsonObjectGet(JsonObjectGet(jPayload, "mouse_scroll"), "y"));
}