Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,162 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#include "CrySystem_precompiled.h"
#include "DrawContext.h"
#include <ISystem.h>
#include <IRenderer.h>
#include <IRenderAuxGeom.h>
MINIGUI_BEGIN
//////////////////////////////////////////////////////////////////////////
CDrawContext::CDrawContext(SMetrics* pMetrics)
{
m_currentStackLevel = 0;
m_x = 0;
m_y = 0;
m_pMetrics = pMetrics;
m_color = ColorB(0, 0, 0, 0);
m_defaultZ = 0.0f;
m_pAuxRender = gEnv->pRenderer->GetIRenderAuxGeom();
m_frameWidth = (float)gEnv->pRenderer->GetWidth();
m_frameHeight = (float)gEnv->pRenderer->GetHeight();
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::SetColor(ColorB color)
{
m_color = color;
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::DrawLine(float x0, float y0, float x1, float y1, float thickness /*= 1.0f */)
{
m_pAuxRender->DrawLine(Vec3(m_x + x0, m_y + y0, m_defaultZ), m_color, Vec3(m_x + x1, m_y + y1, m_defaultZ), m_color, thickness);
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::DrawTriangle(float x0, float y0, float x1, float y1, float x2, float y2)
{
m_pAuxRender->DrawTriangle(Vec3(m_x + x0, m_y + y0, m_defaultZ), m_color, Vec3(m_x + x1, m_y + y1, m_defaultZ), m_color, Vec3(m_x + x2, m_y + y2, m_defaultZ), m_color);
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::DrawRect(const Rect& rc)
{
m_pAuxRender->DrawTriangle(Vec3(m_x + rc.left, m_y + rc.top, m_defaultZ), m_color, Vec3(m_x + rc.left, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.top, m_defaultZ), m_color);
m_pAuxRender->DrawTriangle(Vec3(m_x + rc.left, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.bottom, m_defaultZ), m_color, Vec3(m_x + rc.right, m_y + rc.top, m_defaultZ), m_color);
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::DrawFrame(const Rect& rc, ColorB lineColor, ColorB solidColor, float thickness)
{
ColorB prevColor = m_color;
SetColor(solidColor);
DrawRect(rc);
SetColor(lineColor);
uint32 curFlags = m_pAuxRender->GetRenderFlags().m_renderFlags;
m_pAuxRender->SetRenderFlags(curFlags | e_DrawInFrontOn);
DrawLine(rc.left, rc.top, rc.right, rc.top, thickness);
DrawLine(rc.right, rc.top, rc.right, rc.bottom, thickness);
DrawLine(rc.left, rc.top, rc.left, rc.bottom, thickness);
DrawLine(rc.left, rc.bottom, rc.right, rc.bottom, thickness);
m_pAuxRender->SetRenderFlags(curFlags);
m_color = prevColor;
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::StartDrawing()
{
uint32 width = gEnv->pRenderer->GetWidth();
uint32 height = gEnv->pRenderer->GetHeight();
gEnv->pRenderer->Set2DMode(width, height, m_backupSceneMatrices);
m_prevRenderFlags = m_pAuxRender->GetRenderFlags().m_renderFlags;
m_pAuxRender->SetRenderFlags(e_Mode3D | e_AlphaBlended | e_FillModeSolid | e_CullModeBack | e_DepthWriteOff | e_DepthTestOff);
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::StopDrawing()
{
// Restore old flags that where set before our draw context.
m_pAuxRender->SetRenderFlags(m_prevRenderFlags);
int width = gEnv->pRenderer->GetWidth();
int height = gEnv->pRenderer->GetHeight();
gEnv->pRenderer->Unset2DMode(m_backupSceneMatrices);
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::DrawString(float x, float y, float font_size, ETextAlign align, const char* format, ...)
{
//text will be off screen
if (y > m_frameHeight || x > m_frameWidth)
{
return;
}
va_list args;
va_start(args, format);
SDrawTextInfo ti;
ti.xscale = ti.yscale = font_size / 12.0f; // font size in pixels to text scale.
ti.flags = eDrawText_Monospace | eDrawText_2D | eDrawText_FixedSize | eDrawText_IgnoreOverscan;
if (align == eTextAlign_Left)
{
}
else if (align == eTextAlign_Right)
{
ti.flags |= eDrawText_Right;
}
else if (align == eTextAlign_Center)
{
ti.flags |= eDrawText_Center;
}
ti.color[0] = (float)m_color.r / 255.0f;
ti.color[1] = (float)m_color.g / 255.0f;
ti.color[2] = (float)m_color.b / 255.0f;
ti.color[3] = (float)m_color.a / 255.0f;
gEnv->pRenderer->DrawTextQueued(Vec3(m_x + x, m_y + y, m_defaultZ), ti, format, args);
va_end(args);
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::PushClientRect(const Rect& rc)
{
m_currentStackLevel++;
assert(m_currentStackLevel < MAX_ORIGIN_STACK);
m_clientRectStack[m_currentStackLevel] = rc;
m_x += rc.left;
m_y += rc.top;
}
//////////////////////////////////////////////////////////////////////////
void CDrawContext::PopClientRect()
{
if (m_currentStackLevel > 0)
{
Rect& rc = m_clientRectStack[m_currentStackLevel];
m_x -= rc.left;
m_y -= rc.top;
m_currentStackLevel--;
}
}
MINIGUI_END
@@ -0,0 +1,89 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : DrawContext helper class for MiniGUI
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H
#pragma once
#include "ICryMiniGUI.h"
#include <Cry_Color.h>
struct IRenderAuxGeom;
MINIGUI_BEGIN
enum ETextAlign
{
eTextAlign_Left,
eTextAlign_Right,
eTextAlign_Center
};
//////////////////////////////////////////////////////////////////////////
// Context of MiniGUI drawing.
//////////////////////////////////////////////////////////////////////////
class CDrawContext
{
public:
CDrawContext(SMetrics* pMetrics);
// Must be called before any drawing happens
void StartDrawing();
// Must be called after all drawing have been complete.
void StopDrawing();
void PushClientRect(const Rect& rc);
void PopClientRect();
SMetrics& Metrics() { return *m_pMetrics; }
void SetColor(ColorB color);
void DrawLine(float x0, float y0, float x1, float y1, float thickness = 1.0f);
void DrawTriangle(float x0, float y0, float x1, float y1, float x2, float y2);
void DrawRect(const Rect& rc);
void DrawFrame(const Rect& rc, ColorB lineColor, ColorB solidColor, float thickness = 1.0f);
void DrawString(float x, float y, float font_size, ETextAlign align, const char* format, ...);
protected:
SMetrics* m_pMetrics;
ColorB m_color;
float m_defaultZ;
IRenderAuxGeom* m_pAuxRender;
uint32 m_prevRenderFlags;
enum
{
MAX_ORIGIN_STACK = 16
};
int m_currentStackLevel;
float m_x, m_y; // Reference X,Y positions
Rect m_clientRectStack[MAX_ORIGIN_STACK];
float m_frameWidth;
float m_frameHeight;
private:
TransformationMatrices m_backupSceneMatrices;
};
MINIGUI_END
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_DRAWCONTEXT_H
@@ -0,0 +1,316 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Button implementation in the MiniGUI
#include "CrySystem_precompiled.h"
#include "MiniButton.h"
#include "DrawContext.h"
#include <ISystem.h>
#include <IConsole.h>
MINIGUI_BEGIN
CMiniButton::CMiniButton()
{
m_pCVar = NULL;
m_fCVarValue[0] = 0;
m_fCVarValue[1] = 1;
m_saveStateOn = false;
m_clickCallback = NULL;
m_pCallbackData = NULL;
m_pConnectedCtrl = NULL;
}
//////////////////////////////////////////////////////////////////////////
void CMiniButton::Reset()
{
/*if (m_pCVar)
{
pCVar->Set( m_fCVarValue[0] );
}*/
/*if(m_pConnectedCtrl)
{
m_pConnectedCtrl->SetVisible(false);
}*/
clear_flag(eCtrl_Checked);
}
//////////////////////////////////////////////////////////////////////////
void CMiniButton::SaveState()
{
if (is_flag(eCtrl_Checked))
{
if (m_pConnectedCtrl && m_pConnectedCtrl->CheckFlag(eCtrl_Hidden))
{
m_saveStateOn = false;
}
else
{
m_saveStateOn = true;
}
}
else
{
m_saveStateOn = false;
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniButton::RestoreState()
{
if (m_pCVar)
{
if (m_pCVar->GetFVal() == m_fCVarValue[1])
{
set_flag(eCtrl_Checked);
//Restoring CVars has caused a few issues, especially when the user is changing
//CVars through the console while perfHud is active, removing for now
//pCVar->Set( m_saveStateOn ? m_fCVarValue[1] : m_fCVarValue[0] );
}
else
{
clear_flag(eCtrl_Checked);
}
}
else
{
//connected controls (tables / info boxes etc) now look after themselves
/*if(m_pConnectedCtrl)
{
m_pConnectedCtrl->SetVisible(m_saveStateOn);
}*/
if (CheckFlag(eCtrl_CheckButton))
{
if (m_saveStateOn)
{
set_flag(eCtrl_Checked);
}
else
{
clear_flag(eCtrl_Checked);
}
}
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniButton::OnPaint(CDrawContext& dc)
{
ColorB bkgColor = dc.Metrics().clrBackground;
if (is_flag(eCtrl_Highlight))
{
bkgColor = dc.Metrics().clrBackgroundHighlight;
}
else if (is_flag(eCtrl_Checked))
{
//if connected control has been hidden, this button should not be checked
if (m_pConnectedCtrl && m_pConnectedCtrl->CheckFlag(eCtrl_Hidden))
{
clear_flag(eCtrl_Checked);
}
else
{
bkgColor = dc.Metrics().clrBackgroundSelected;
}
}
float borderThickness = 1.0f;
if (is_flag(eCtrl_Focus))
{
borderThickness = 3.0f;
}
ColorB borderCol = dc.Metrics().clrFrameBorder;
if (!m_pGUI->InFocus())
{
borderCol = dc.Metrics().clrFrameBorderOutOfFocus;
bkgColor.a = dc.Metrics().outOfFocusAlpha;
}
dc.DrawFrame(m_rect, borderCol, bkgColor, borderThickness);
ColorB textColor = dc.Metrics().clrText;
if (is_flag(eCtrl_Checked | eCtrl_Highlight))
{
textColor = dc.Metrics().clrTextSelected;
}
dc.SetColor(textColor);
ETextAlign align;
float startX;
if (is_flag(eCtrl_TextAlignCentre))
{
startX = (m_rect.left + m_rect.right) / 2.f;
align = eTextAlign_Center;
}
else
{
startX = m_rect.left + 5.f;
align = eTextAlign_Left;
}
dc.DrawString(startX, m_rect.top, dc.Metrics().fTitleSize, align, GetTitle());
//Check not very obvious
#if 0
if (is_flag(eCtrl_Checked))
{
// Draw checked mark.
float checkX = m_rect.left + 4;
float checkY = (m_rect.bottom + m_rect.top) * 0.5f;
dc.SetColor(dc.Metrics().clrChecked);
dc.DrawLine(checkX, checkY, checkX + 3, checkY + 3);
dc.DrawLine(checkX + 3, checkY + 3, checkX + 7, checkY - 6);
}
#endif
}
//////////////////////////////////////////////////////////////////////////
void CMiniButton::SetRect(const Rect& rc)
{
Rect newrc = rc;
newrc.bottom = newrc.top + m_pGUI->Metrics().fTitleSize + 2;
CMiniCtrl::SetRect(newrc);
}
//////////////////////////////////////////////////////////////////////////
void CMiniButton::OnEvent(float x, float y, EMiniCtrlEvent event)
{
switch (event)
{
case eCtrlEvent_LButtonDown:
{
SCommand cmd;
if (CheckFlag(eCtrl_CheckButton))
{
if (!CheckFlag(eCtrl_Checked))
{
cmd.command = eCommand_ButtonChecked;
}
else
{
cmd.command = eCommand_ButtonUnchecked;
}
}
else
{
cmd.command = eCommand_ButtonPress;
}
cmd.nCtrlID = GetId();
cmd.pCtrl = this;
GetGUI()->OnCommand(cmd);
if (CheckFlag(eCtrl_CheckButton))
{
bool bOn = false;
if (CheckFlag(eCtrl_Checked))
{
bOn = false;
ClearFlag(eCtrl_Checked);
}
else
{
bOn = true;
SetFlag(eCtrl_Checked);
}
if (m_pCVar)
{
m_pCVar->Set(m_fCVarValue[bOn ? 1 : 0]);
}
if (m_pConnectedCtrl)
{
m_pConnectedCtrl->SetVisible(bOn);
}
}
else
{
//cross button behavior
if (m_pConnectedCtrl)
{
m_pConnectedCtrl->SetVisible(false);
}
}
if (m_clickCallback)
{
m_clickCallback(m_pCallbackData, true);
}
}
break;
case eCtrlEvent_MouseOff:
{
if (m_pParent)
{
m_pParent->OnEvent(x, y, eCtrlEvent_MouseOff);
}
}
break;
}
}
//////////////////////////////////////////////////////////////////////////
bool CMiniButton::SetControlCVar(const char* sCVarName, float fOffValue, float fOnValue)
{
m_pCVar = GetISystem()->GetIConsole()->GetCVar(sCVarName);
if (!m_pCVar)
{
CryLogAlways("failed to find CVar: %s\n", sCVarName);
}
m_fCVarValue[0] = fOffValue;
m_fCVarValue[1] = fOnValue;
if (m_pCVar && m_pCVar->GetFVal() == fOnValue)
{
set_flag(eCtrl_Checked);
}
return true;
}
//////////////////////////////////////////////////////////////////////////
bool CMiniButton::SetClickCallback(ClickCallback callback, void* pCallbackData)
{
m_clickCallback = callback;
m_pCallbackData = pCallbackData;
return true;
}
//////////////////////////////////////////////////////////////////////////
bool CMiniButton::SetConnectedCtrl(IMiniCtrl* pConnectedCtrl)
{
m_pConnectedCtrl = pConnectedCtrl;
return true;
}
MINIGUI_END
@@ -0,0 +1,60 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Button implementation in the MiniGUI
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H
#pragma once
#include "MiniGUI.h"
MINIGUI_BEGIN
//////////////////////////////////////////////////////////////////////////
// Root window all other controls derive from
class CMiniButton
: public CMiniCtrl
{
public:
CMiniButton();
//////////////////////////////////////////////////////////////////////////
// CMiniCtrl interface implementation.
//////////////////////////////////////////////////////////////////////////
virtual EMiniCtrlType GetType() const { return eCtrlType_Button; }
virtual void SetRect(const Rect& rc);
virtual void OnPaint(CDrawContext& dc);
virtual void OnEvent(float x, float y, EMiniCtrlEvent event);
virtual void Reset();
virtual void SaveState();
virtual void RestoreState();
//////////////////////////////////////////////////////////////////////////
virtual bool SetControlCVar(const char* sCVarName, float fOffValue, float fOnValue);
virtual bool SetClickCallback(ClickCallback callback, void* pCallbackData);
virtual bool SetConnectedCtrl(IMiniCtrl* pConnectedCtrl);
protected:
ICVar* m_pCVar;
float m_fCVarValue[2];
ClickCallback m_clickCallback;
void* m_pCallbackData;
IMiniCtrl* m_pConnectedCtrl;
};
MINIGUI_END
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIBUTTON_H
@@ -0,0 +1,862 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Implementation of the MiniGUI class
#include "CrySystem_precompiled.h"
#include "MiniGUI.h"
#include "DrawContext.h"
#include "MiniButton.h"
#include "MiniMenu.h"
#include "MiniInfoBox.h"
#include "MiniTable.h"
#include <ISystem.h>
#include <IRenderer.h>
#include <LyShine/Bus/UiCursorBus.h>
#include <AzFramework/Input/Devices/Gamepad/InputDeviceGamepad.h>
#include <AzFramework/Input/Devices/Mouse/InputDeviceMouse.h>
namespace minigui
{
CRYREGISTER_SINGLETON_CLASS(CMiniGUI)
}
MINIGUI_BEGIN
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::InitMetrics()
{
m_metrics.clrText = ColorB(255, 255, 255, 255);
m_metrics.clrTextSelected = ColorB(0, 255, 0, 255);
m_metrics.fTextSize = 12.0f;
m_metrics.clrTitle = ColorB(255, 255, 255, 255);
m_metrics.fTitleSize = 14.0f;
const int backgroundAlpha = 255;
m_metrics.clrBackground = ColorB(20, 20, 20, backgroundAlpha);
m_metrics.clrBackgroundHighlight = ColorB(10, 10, 150, backgroundAlpha);
m_metrics.clrBackgroundSelected = ColorB(10, 120, 10, backgroundAlpha);
m_metrics.clrFrameBorder = ColorB(255, 0, 0, 255);
m_metrics.clrFrameBorderHighlight = ColorB(255, 255, 0, 255);
m_metrics.clrFrameBorderOutOfFocus = ColorB(0, 0, 0, 255);
m_metrics.clrChecked = ColorB(0, 0, 0, 255);
m_metrics.outOfFocusAlpha = 32;
}
class CMiniCtrlRoot
: public CMiniCtrl
{
public:
CMiniCtrlRoot() {};
virtual EMiniCtrlType GetType() const { return eCtrlType_Unknown; };
virtual void OnPaint([[maybe_unused]] class CDrawContext& dc) {};
};
//////////////////////////////////////////////////////////////////////////
CMiniGUI::CMiniGUI()
: m_enabled(false)
, m_inFocus(true)
, m_pDPadMenu(NULL)
, m_pMovingCtrl(NULL)
{
}
//////////////////////////////////////////////////////////////////////////
CMiniGUI::~CMiniGUI()
{
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::Init()
{
m_pEventListener = NULL;
InitMetrics();
AzFramework::InputChannelEventListener::Connect();
m_pRootCtrl = new CMiniCtrlRoot;
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::Reset()
{
m_pRootCtrl->Reset();
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::SaveState()
{
m_pRootCtrl->SaveState();
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::RestoreState()
{
m_pRootCtrl->RestoreState();
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::SetEnabled(bool status)
{
m_enabled = status;
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::SetInFocus(bool status)
{
if (status)
{
m_inFocus = true;
}
else
{
CloseDPadMenu();
m_inFocus = false;
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::Done()
{
AzFramework::InputChannelEventListener::Disconnect();
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::Draw()
{
FUNCTION_PROFILER_FAST(GetISystem(), PROFILE_SYSTEM, g_bProfilerEnabled);
// When console opened hide MiniGui
bool bConsoleOpened = gEnv->pConsole->IsOpened();
if (m_enabled && !bConsoleOpened)
{
ProcessInput();
CDrawContext dc(&m_metrics);
dc.StartDrawing();
{
// Draw all controls.
m_pRootCtrl->DrawCtrl(dc);
}
dc.StopDrawing();
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::ProcessInput()
{
//check we are not in digital selection mode
if (!m_pDPadMenu)
{
float mx(0), my(0);
AZ::Vector2 systemCursorPositionNormalized = AZ::Vector2::CreateZero();
AzFramework::InputSystemCursorRequestBus::EventResult(systemCursorPositionNormalized,
AzFramework::InputDeviceMouse::Id,
&AzFramework::InputSystemCursorRequests::GetSystemCursorPositionNormalized);
mx = systemCursorPositionNormalized.GetX() * gEnv->pRenderer->GetWidth();
my = systemCursorPositionNormalized.GetY() * gEnv->pRenderer->GetHeight();
//update moving control
if (m_pMovingCtrl)
{
m_pMovingCtrl->Move(mx, my);
}
IMiniCtrl* pCtrl = GetCtrlFromPoint(mx, my);
if (pCtrl)
{
SetHighlight(pCtrl, true, mx, my);
}
else
{
SetHighlight(m_highlightedCtrl, false, mx, my);
}
}
}
//////////////////////////////////////////////////////////////////////////
IMiniCtrl* CMiniGUI::GetCtrlFromPoint(float x, float y) const
{
// Draw all controls.
return m_pRootCtrl->GetCtrlFromPoint(x, y);
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::SetHighlight(IMiniCtrl* pCtrl, bool bEnable, float x, float y)
{
if (pCtrl)
{
if (m_highlightedCtrl && m_highlightedCtrl != pCtrl)
{
m_highlightedCtrl->OnEvent(x, y, eCtrlEvent_MouseOff);
m_highlightedCtrl->ClearFlag(eCtrl_Highlight);
}
if (bEnable)
{
pCtrl->OnEvent(x, y, eCtrlEvent_MouseOver);
pCtrl->SetFlag(eCtrl_Highlight);
m_highlightedCtrl = pCtrl;
}
else
{
pCtrl->OnEvent(x, y, eCtrlEvent_MouseOff);
pCtrl->ClearFlag(eCtrl_Highlight);
m_highlightedCtrl = NULL;
}
}
else
{
assert(bEnable == false);
if (m_highlightedCtrl)
{
m_highlightedCtrl->OnEvent(x, y, eCtrlEvent_MouseOff);
m_highlightedCtrl->ClearFlag(eCtrl_Highlight);
m_highlightedCtrl = NULL;
}
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::SetFocus(IMiniCtrl* pCtrl, bool bEnable)
{
if (m_focusCtrl)
{
m_focusCtrl->ClearFlag(eCtrl_Focus);
}
m_focusCtrl = pCtrl;
if (m_focusCtrl)
{
if (bEnable)
{
m_focusCtrl->SetFlag(eCtrl_Focus);
}
else
{
m_focusCtrl->ClearFlag(eCtrl_Focus);
}
}
}
//////////////////////////////////////////////////////////////////////////
SMetrics& CMiniGUI::Metrics()
{
return m_metrics;
}
//////////////////////////////////////////////////////////////////////////
IMiniCtrl* CMiniGUI::CreateCtrl(IMiniCtrl* pParentCtrl, int nCtrlID, EMiniCtrlType type, int nCtrlFlags, const Rect& rc, const char* title)
{
CMiniCtrl* pCtrl = 0;
// Test code.
switch (type)
{
case eCtrlType_Button:
pCtrl = new CMiniButton;
break;
case eCtrlType_Menu:
pCtrl = new CMiniMenu;
break;
case eCtrlType_InfoBox:
pCtrl = new CMiniInfoBox;
break;
case eCtrlType_Table:
pCtrl = new CMiniTable;
break;
default:
assert(0 && "Unknown MiniGUI control type");
break;
}
;
if (pCtrl)
{
pCtrl->SetGUI(this);
pCtrl->SetFlag(nCtrlFlags);
pCtrl->SetTitle(title);
pCtrl->SetRect(rc);
pCtrl->SetId(nCtrlID);
if (pCtrl->CheckFlag(eCtrl_AutoResize))
{
pCtrl->AutoResize();
}
if (pCtrl->CheckFlag(eCtrl_CloseButton))
{
pCtrl->CreateCloseButton();
}
if (pParentCtrl)
{
pParentCtrl->AddSubCtrl(pCtrl);
}
else
{
m_pRootCtrl->AddSubCtrl(pCtrl);
}
if (type == eCtrlType_Menu && pParentCtrl == NULL)
{
m_rootMenus.push_back(pCtrl);
}
}
return pCtrl;
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::OnCommand(SCommand& cmd)
{
if (m_pEventListener)
{
m_pEventListener->OnCommand(cmd);
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::OnMouseInputEvent(const AzFramework::InputChannel& inputChannel)
{
if (!m_inFocus || !m_enabled)
{
return;
}
const AzFramework::InputChannel::PositionData2D* positionData2D = inputChannel.GetCustomData<AzFramework::InputChannel::PositionData2D>();
if (!positionData2D)
{
return;
}
const float mx = positionData2D->m_normalizedPosition.GetX() * gEnv->pRenderer->GetWidth();
const float my = positionData2D->m_normalizedPosition.GetY() * gEnv->pRenderer->GetHeight();
IMiniCtrl* pCtrl = GetCtrlFromPoint(mx, my);
if (pCtrl)
{
const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
if (channelId == AzFramework::InputDeviceMouse::Button::Left)
{
if (inputChannel.IsStateBegan())
{
pCtrl->OnEvent(mx, my, eCtrlEvent_LButtonDown);
}
else if (inputChannel.IsStateEnded())
{
pCtrl->OnEvent(mx, my, eCtrlEvent_LButtonUp);
}
}
}
}
void CMiniGUI::SetDPadMenu(IMiniCtrl* pMenu)
{
m_pDPadMenu = (CMiniMenu*)pMenu;
UiCursorBus::Broadcast(&UiCursorInterface::DecrementVisibleCounter);
}
void CMiniGUI::CloseDPadMenu()
{
if (m_pDPadMenu)
{
CMiniMenu* closeMenu = m_pDPadMenu;
//close menu and all parent menus
do
{
closeMenu->Close();
closeMenu = (CMiniMenu*)closeMenu->GetParent();
} while (closeMenu->GetType() == eCtrlType_Menu);
m_pDPadMenu->ClearFlag(eCtrl_Highlight);
m_pDPadMenu = NULL;
UiCursorBus::Broadcast(&UiCursorInterface::IncrementVisibleCounter);
}
}
void CMiniGUI::UpdateDPadMenu(const AzFramework::InputChannel& inputChannel)
{
const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
const bool isPressed = inputChannel.IsStateBegan();
if (m_pDPadMenu)
{
if (channelId == AzFramework::InputDeviceGamepad::Button::B)
{
CloseDPadMenu();
return;
}
if (isPressed)
{
if (channelId == AzFramework::InputDeviceGamepad::Button::DD ||
channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LD)
{
m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadDown);
}
else if (channelId == AzFramework::InputDeviceGamepad::Button::DU ||
channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LU)
{
m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadUp);
}
else if (channelId == AzFramework::InputDeviceGamepad::Button::DL ||
channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LL)
{
CMiniMenu* pNewMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadLeft);
//get previous root menu
if (pNewMenu == NULL)
{
int i = 0, nRootMenus = m_rootMenus.size();
for (i = 0; i < nRootMenus; i++)
{
if (m_rootMenus[i] == m_pDPadMenu)
{
break;
}
}
if (i > 0)
{
m_pDPadMenu->Close();
m_pDPadMenu->ClearFlag(eCtrl_Highlight);
m_pDPadMenu = (CMiniMenu*)m_rootMenus[i - 1];
m_pDPadMenu->Open();
m_pDPadMenu->SetFlag(eCtrl_Highlight);
}
//else selected menu remains the same
}
else
{
m_pDPadMenu = pNewMenu;
}
}
else if (channelId == AzFramework::InputDeviceGamepad::Button::DR ||
channelId == AzFramework::InputDeviceGamepad::ThumbStickDirection::LR)
{
CMiniMenu* pNewMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_DPadRight);
//get next root menu
if (pNewMenu == NULL)
{
int i = 0, nRootMenus = m_rootMenus.size();
for (i = 0; i < nRootMenus; i++)
{
if (m_rootMenus[i] == m_pDPadMenu)
{
break;
}
}
if (i < nRootMenus - 1)
{
m_pDPadMenu->Close();
m_pDPadMenu->ClearFlag(eCtrl_Highlight);
m_pDPadMenu = (CMiniMenu*)m_rootMenus[i + 1];
m_pDPadMenu->Open();
m_pDPadMenu->SetFlag(eCtrl_Highlight);
}
//else selected menu remains the same
}
else
{
m_pDPadMenu = pNewMenu;
}
}
else if (channelId == AzFramework::InputDeviceGamepad::Button::A)
{
m_pDPadMenu = m_pDPadMenu->UpdateSelection(eCtrlEvent_LButtonDown);
}
}
}
}
bool CMiniGUI::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel)
{
const AzFramework::InputDeviceId& deviceId = inputChannel.GetInputDevice().GetInputDeviceId();
if (AzFramework::InputDeviceMouse::IsMouseDevice(deviceId))
{
OnMouseInputEvent(inputChannel);
return false;
}
if (!m_inFocus)
{
return false;
}
if (!AzFramework::InputDeviceGamepad::IsGamepadDevice(deviceId))
{
return false;
}
if (m_pDPadMenu)
{
UpdateDPadMenu(inputChannel);
}
else
{
float posX = 0.0f;
float posY = 0.0f;
const AzFramework::InputChannel::PositionData2D* positionData2D = inputChannel.GetCustomData<AzFramework::InputChannel::PositionData2D>();
if (positionData2D)
{
posX = positionData2D->m_normalizedPosition.GetX() * gEnv->pRenderer->GetWidth();
posY = positionData2D->m_normalizedPosition.GetY() * gEnv->pRenderer->GetHeight();
}
IMiniCtrl* pCtrl = GetCtrlFromPoint(posX, posY);
if (pCtrl)
{
const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
if (channelId == AzFramework::InputDeviceGamepad::Button::A)
{
switch (inputChannel.GetState())
{
case AzFramework::InputChannel::State::Began:
pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonDown);
break;
case AzFramework::InputChannel::State::Ended:
pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonUp);
break;
case AzFramework::InputChannel::State::Updated:
pCtrl->OnEvent(posX, posY, eCtrlEvent_LButtonPressed);
//if we've clicked on a menu, enter menu selection mode, disable mouse
if (pCtrl->GetType() == eCtrlType_Menu)
{
SetDPadMenu(pCtrl);
}
break;
}
}
}
}
return false;
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::SetEventListener(IMiniGUIEventListener* pListener)
{
m_pEventListener = pListener;
}
//////////////////////////////////////////////////////////////////////////
void CMiniGUI::RemoveAllCtrl()
{
m_highlightedCtrl = NULL;
//reset all console variables to default state
Reset();
m_pRootCtrl->RemoveAllSubCtrl();
}
//////////////////////////////////////////////////////////////////////////
//CMiniCtrl
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::Reset()
{
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
pSubCtrl->Reset();
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::SaveState()
{
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
pSubCtrl->SaveState();
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::RestoreState()
{
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
pSubCtrl->RestoreState();
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::AddSubCtrl(IMiniCtrl* pCtrl)
{
assert(pCtrl);
_smart_ptr<IMiniCtrl> pTempCtrl(pCtrl);
IMiniCtrl* pParent = pCtrl->GetParent();
if (pParent)
{
pParent->RemoveSubCtrl(pCtrl);
}
static_cast<CMiniCtrl*>(pCtrl)->m_pParent = this;
m_subCtrls.push_back(pCtrl);
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::RemoveSubCtrl(IMiniCtrl* pCtrl)
{
assert(pCtrl);
_smart_ptr<IMiniCtrl> pTempCtrl(pCtrl);
IMiniCtrl* pParent = pCtrl->GetParent();
if (pParent == this)
{
static_cast<CMiniCtrl*>(pCtrl)->m_pParent = 0;
for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++)
{
if (m_subCtrls[i] == pCtrl)
{
m_subCtrls.erase(m_subCtrls.begin() + i);
break;
}
}
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::RemoveAllSubCtrl()
{
int nSubCtrls = m_subCtrls.size();
if (nSubCtrls)
{
for (int i = 0; i < nSubCtrls; i++)
{
IMiniCtrl* pSubCtrl = m_subCtrls[i].get();
pSubCtrl->RemoveAllSubCtrl();
}
m_subCtrls.clear();
}
}
//////////////////////////////////////////////////////////////////////////
IMiniCtrl* CMiniCtrl::GetCtrlFromPoint(float x, float y)
{
if (is_flag(eCtrl_Hidden))
{
return 0;
}
for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++)
{
float lx = x - m_rect.left;
float ly = y - m_rect.top;
IMiniCtrl* pHit = m_subCtrls[i]->GetCtrlFromPoint(lx, ly);
if (pHit)
{
return pHit;
}
}
if (m_rect.IsPointInside(x, y))
{
return this;
}
return 0;
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::DrawCtrl(CDrawContext& dc)
{
OnPaint(dc);
dc.PushClientRect(m_rect);
for (int i = 0, num = (int)m_subCtrls.size(); i < num; i++)
{
CMiniCtrl* pCtrl = static_cast<CMiniCtrl*>((IMiniCtrl*)m_subCtrls[i]);
if (!pCtrl->is_flag(eCtrl_Hidden))
{
pCtrl->DrawCtrl(dc);
}
}
dc.PopClientRect();
}
//////////////////////////////////////////////////////////////////////////
int CMiniCtrl::GetSubCtrlCount() const
{
return (int)m_subCtrls.size();
}
//////////////////////////////////////////////////////////////////////////
IMiniCtrl* CMiniCtrl::GetSubCtrl(int nIndex) const
{
assert(nIndex >= 0 && nIndex < (int)m_subCtrls.size());
return m_subCtrls[nIndex];
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::SetRect(const Rect& rc)
{
m_rect = rc;
if (m_pCloseButton)
{
float width = rc.Width();
//relative position of cross box
Rect closeRect(width - 20.f, 0.f, width, 20.f);
m_pCloseButton->SetRect(closeRect);
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::SetVisible(bool state)
{
if (state)
{
clear_flag(eCtrl_Hidden);
}
else
{
set_flag(eCtrl_Hidden);
}
if (m_pCloseButton)
{
m_pCloseButton->SetVisible(state);
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::AutoResize()
{
uint32 stringLen = m_title.length();
if (stringLen)
{
//just an approximation for now - should take into account font size / kerning
m_rect.right = m_rect.left + (8.5f * stringLen);
}
m_requiresResize = false;
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::StartMoving(float x, float y)
{
if (!m_moving)
{
m_prevX = x;
m_prevY = y;
m_moving = true;
m_pGUI->SetMovingCtrl(this);
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::StopMoving()
{
if (m_moving)
{
m_moving = false;
m_pGUI->SetMovingCtrl(NULL);
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::Move(float x, float y)
{
if (m_moving)
{
float moveX = x - m_prevX;
float moveY = y - m_prevY;
m_rect.top += moveY;
m_rect.bottom += moveY;
m_rect.left += moveX;
m_rect.right += moveX;
m_prevX = x;
m_prevY = y;
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::OnEvent(float x, float y, EMiniCtrlEvent event)
{
switch (event)
{
case eCtrlEvent_LButtonDown:
{
if (is_flag(eCtrl_Highlight | eCtrl_Moveable))
{
StartMoving(x, y);
}
}
break;
case eCtrlEvent_LButtonUp:
if (m_moving)
{
StopMoving();
}
break;
case eCtrlEvent_MouseOver:
break;
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniCtrl::CreateCloseButton()
{
if (m_pGUI)
{
m_pCloseButton = m_pGUI->CreateCtrl(this, 100, eCtrlType_Button, 0, Rect(0, 0, 100, 20), "X");
if (m_pCloseButton)
{
m_pCloseButton->SetConnectedCtrl(this);
float width = m_rect.Width();
//relative position of cross box
Rect closeRect(width - 20.f, 0.f, width, 20.f);
m_pCloseButton->SetRect(closeRect);
}
}
}
MINIGUI_END
+219
View File
@@ -0,0 +1,219 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Interface to the Mini GUI subsystem
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H
#pragma once
#include "ICryMiniGUI.h"
#include <Cry_Color.h>
#include <AzFramework/Input/Events/InputChannelEventListener.h>
#include <CryExtension/Impl/ClassWeaver.h>
MINIGUI_BEGIN
class CMiniMenu;
//////////////////////////////////////////////////////////////////////////
// Root window all other controls derive from
class CMiniCtrl
: public IMiniCtrl
{
public:
CMiniCtrl()
: m_nFlags(0)
, m_id(0)
, m_renderCallback(NULL)
, m_fTextSize(12.f)
, m_prevX(0.f)
, m_prevY(0.f)
, m_moving(false)
, m_requiresResize(false)
, m_pCloseButton(NULL)
, m_saveStateOn(false)
{};
//////////////////////////////////////////////////////////////////////////
// IMiniCtrl interface implementation.
//////////////////////////////////////////////////////////////////////////
virtual void Reset();
virtual void SaveState();
virtual void RestoreState();
virtual void SetGUI(IMiniGUI* pGUI) { m_pGUI = pGUI; };
virtual IMiniGUI* GetGUI() const { return m_pGUI; };
virtual int GetId() const { return m_id; };
virtual void SetId(int id) { m_id = id; };
virtual const char* GetTitle() const { return m_title; };
virtual void SetTitle(const char* title) { m_title = title; };
virtual Rect GetRect() const { return m_rect; }
virtual void SetRect(const Rect& rc);
virtual void SetFlag(uint32 flag) { set_flag(flag); }
virtual void ClearFlag(uint32 flag) { clear_flag(flag); };
virtual bool CheckFlag(uint32 flag) const { return is_flag(flag); }
virtual void AddSubCtrl(IMiniCtrl* pCtrl);
virtual void RemoveSubCtrl(IMiniCtrl* pCtrl);
virtual void RemoveAllSubCtrl();
virtual int GetSubCtrlCount() const;
virtual IMiniCtrl* GetSubCtrl(int nIndex) const;
virtual IMiniCtrl* GetParent() const { return m_pParent; };
virtual IMiniCtrl* GetCtrlFromPoint(float x, float y);
virtual void SetVisible(bool state);
virtual void OnEvent(float x, float y, EMiniCtrlEvent);
virtual bool SetRenderCallback(RenderCallback callback) { m_renderCallback = callback; return true; };
// Not implemented in base control
virtual bool SetControlCVar([[maybe_unused]] const char* sCVarName, [[maybe_unused]] float fOffValue, [[maybe_unused]] float fOnValue) { assert(0); return false; };
virtual bool SetClickCallback([[maybe_unused]] ClickCallback callback, [[maybe_unused]] void* pCallbackData) { assert(0); return false; };
virtual bool SetConnectedCtrl([[maybe_unused]] IMiniCtrl* pConnectedCtrl) { assert(0); return false; };
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
virtual void AutoResize();
//////////////////////////////////////////////////////////////////////////
virtual void CreateCloseButton();
void DrawCtrl(CDrawContext& dc);
virtual void Move(float x, float y);
protected:
void set_flag(uint32 flag) { m_nFlags |= flag; }
void clear_flag(uint32 flag) { m_nFlags &= ~flag; };
bool is_flag(uint32 flag) const { return (m_nFlags & flag) == flag; }
//dynamic movement
void StartMoving(float x, float y);
void StopMoving();
protected:
int m_id;
IMiniGUI* m_pGUI;
uint32 m_nFlags;
CryFixedStringT<32> m_title;
Rect m_rect;
_smart_ptr<IMiniCtrl> m_pParent;
std::vector<IMiniCtrlPtr> m_subCtrls;
RenderCallback m_renderCallback;
float m_fTextSize;
//optional close 'X' button on controls, ref counted by m_subCtrls
IMiniCtrl* m_pCloseButton;
//dynamic movement
float m_prevX;
float m_prevY;
bool m_moving;
bool m_requiresResize;
bool m_saveStateOn;
};
//////////////////////////////////////////////////////////////////////////
class CMiniGUI
: public IMiniGUI
, public AzFramework::InputChannelEventListener
{
public:
CRYINTERFACE_BEGIN()
CRYINTERFACE_ADD(IMiniGUI)
CRYINTERFACE_END()
CRYGENERATE_SINGLETONCLASS(CMiniGUI, "MiniGUI", 0x1a049b879a4e4b58, 0xac14026e17e6255e)
public:
void InitMetrics();
void ProcessInput();
//////////////////////////////////////////////////////////////////////////
// IMiniGUI interface implementation.
//////////////////////////////////////////////////////////////////////////
virtual void Init();
virtual void Done();
virtual void Draw();
virtual void Reset();
virtual void SaveState();
virtual void RestoreState();
virtual void SetEnabled(bool status);
virtual void SetInFocus(bool status);
virtual bool InFocus() {return m_inFocus; }
virtual void SetEventListener(IMiniGUIEventListener* pListener);
virtual SMetrics& Metrics();
virtual void OnCommand(SCommand& cmd);
virtual void RemoveAllCtrl();
virtual IMiniCtrl* CreateCtrl(IMiniCtrl* pParentCtrl, int nCtrlID, EMiniCtrlType type, int nCtrlFlags, const Rect& rc, const char* title);
virtual IMiniCtrl* GetCtrlFromPoint(float x, float y) const;
void SetHighlight(IMiniCtrl* pCtrl, bool bEnable, float x, float y);
void SetFocus(IMiniCtrl* pCtrl, bool bEnable);
// AzFramework::InputChannelEventListener
bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
AZ::s32 GetPriority() const override { return AzFramework::InputChannelEventListener::GetPriorityUI(); }
virtual void SetMovingCtrl(IMiniCtrl* pCtrl)
{
m_pMovingCtrl = pCtrl;
}
protected:
void OnMouseInputEvent(const AzFramework::InputChannel& inputChannel);
//DPad menu navigation
void UpdateDPadMenu(const AzFramework::InputChannel& inputChannel);
void SetDPadMenu(IMiniCtrl* pMenu);
void CloseDPadMenu();
protected:
bool m_enabled;
bool m_inFocus;
SMetrics m_metrics;
_smart_ptr<CMiniCtrl> m_pRootCtrl;
_smart_ptr<IMiniCtrl> m_highlightedCtrl;
_smart_ptr<IMiniCtrl> m_focusCtrl;
IMiniGUIEventListener* m_pEventListener;
CMiniMenu* m_pDPadMenu;
IMiniCtrl* m_pMovingCtrl;
std::vector<minigui::IMiniCtrl*> m_rootMenus;
};
MINIGUI_END
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIGUI_H
@@ -0,0 +1,174 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Button implementation in the MiniGUI
#include "CrySystem_precompiled.h"
#include "MiniInfoBox.h"
#include "DrawContext.h"
#include <ISystem.h>
MINIGUI_BEGIN
CMiniInfoBox::CMiniInfoBox()
: m_fTextIndent(4)
{
}
//////////////////////////////////////////////////////////////////////////
void CMiniInfoBox::SaveState()
{
if (CheckFlag(eCtrl_Hidden))
{
m_saveStateOn = false;
}
else
{
m_saveStateOn = true;
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniInfoBox::Reset()
{
SetFlag(eCtrl_Hidden);
}
//////////////////////////////////////////////////////////////////////////
void CMiniInfoBox::RestoreState()
{
if (m_saveStateOn)
{
ClearFlag(eCtrl_Hidden);
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniInfoBox::OnPaint(CDrawContext& dc)
{
if (m_requiresResize)
{
AutoResize();
}
ColorB borderCol = dc.Metrics().clrFrameBorder;
ColorB backgroundCol = dc.Metrics().clrBackground;
if (!m_pGUI->InFocus())
{
borderCol = dc.Metrics().clrFrameBorderOutOfFocus;
backgroundCol.a = dc.Metrics().outOfFocusAlpha;
}
else if (m_moving)
{
borderCol = dc.Metrics().clrFrameBorderHighlight;
}
dc.DrawFrame(m_rect, borderCol, backgroundCol);
dc.SetColor(dc.Metrics().clrTitle);
dc.DrawString(m_rect.left + 4, m_rect.top, dc.Metrics().fTitleSize, eTextAlign_Left, GetTitle());
float fTextSize = m_fTextSize;
if (fTextSize == 0)
{
fTextSize = dc.Metrics().fTextSize;
}
float x = m_fTextIndent + m_rect.left + 8;
float y = m_rect.top + fTextSize + fTextSize;
// Draw entries.
for (int i = 0, num = (int)m_entries.size(); i < num; i++)
{
SInfoEntry& info = m_entries[i];
dc.SetColor(info.color);
dc.DrawString(x, y, info.textSize, eTextAlign_Left, info.text);
y += info.textSize * 0.8f;
if (y + info.textSize > m_rect.bottom)
{
break;
}
}
if (m_renderCallback)
{
m_renderCallback(m_rect.left, m_rect.top);
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniInfoBox::OnEvent(float x, float y, EMiniCtrlEvent event)
{
CMiniCtrl::OnEvent(x, y, event);
}
void CMiniInfoBox::AddEntry(const char* str, ColorB col, float textSize)
{
SInfoEntry info;
info.color = col;
info.textSize = textSize;
cry_strcpy(info.text, str);
m_entries.push_back(info);
if (CheckFlag(eCtrl_AutoResize))
{
//set dirty flag instead of resizing for every elem
m_requiresResize = true; //AutoResize();
}
}
void CMiniInfoBox::ClearEntries()
{
m_entries.clear();
m_requiresResize = true;
}
//////////////////////////////////////////////////////////////////////////
void CMiniInfoBox::AutoResize()
{
float width = 0.f;
float height = 32.f;
//must be at least the size of title and cross box
width = m_fTextIndent + ((float)m_title.size() * 14.f) + 30.f;
for (int i = 0, num = (int)m_entries.size(); i < num; i++)
{
SInfoEntry& info = m_entries[i];
uint32 strLength = strlen(info.text);
float strSize = info.textSize * strLength;
width = max(strSize, width);
height += info.textSize * 0.8f;
}
//scale width, could do with kerning info
width *= 0.6f;
Rect newRect = m_rect;
newRect.right = newRect.left + width;
newRect.bottom = newRect.top + height;
SetRect(newRect);
m_requiresResize = false;
}
MINIGUI_END
@@ -0,0 +1,79 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Button implementation in the MiniGUI
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H
#pragma once
#include "MiniGUI.h"
MINIGUI_BEGIN
//////////////////////////////////////////////////////////////////////////
// Root window all other controls derive from
class CMiniInfoBox
: public CMiniCtrl
, public IMiniInfoBox
{
public:
CMiniInfoBox();
//////////////////////////////////////////////////////////////////////////
// CMiniCtrl interface implementation.
//////////////////////////////////////////////////////////////////////////
virtual EMiniCtrlType GetType() const { return eCtrlType_InfoBox; }
virtual void OnPaint(CDrawContext& dc);
virtual void OnEvent(float x, float y, EMiniCtrlEvent event);
virtual void Reset();
virtual void SaveState();
virtual void RestoreState();
virtual void AutoResize();
//////////////////////////////////////////////////////////////////////////
virtual void SetTextIndent(float x) { m_fTextIndent = x; }
virtual void SetTextSize(float sz) { m_fTextSize = sz; }
virtual void ClearEntries();
virtual void AddEntry(const char* str, ColorB col, float textSize);
//////////////////////////////////////////////////////////////////////////
// IMiniTable interface implementation.
//////////////////////////////////////////////////////////////////////////
virtual bool IsHidden() { return CheckFlag(eCtrl_Hidden); }
virtual void Hide(bool stat) { SetVisible(!stat); }
public:
//////////////////////////////////////////////////////////////////////////
static const int MAX_TEXT_LENGTH = 64;
struct SInfoEntry
{
char text[MAX_TEXT_LENGTH];
ColorB color;
float textSize;
};
//////////////////////////////////////////////////////////////////////////
protected:
std::vector<SInfoEntry> m_entries;
float m_fTextIndent;
};
MINIGUI_END
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIINFOBOX_H
@@ -0,0 +1,364 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Button implementation in the MiniGUI
#include "CrySystem_precompiled.h"
#include "MiniMenu.h"
#include "DrawContext.h"
MINIGUI_BEGIN
CMiniMenu::CMiniMenu()
{
m_bVisible = false;
m_bSubMenu = false;
m_menuWidth = 0.f;
m_selectionIndex = -1;
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::OnPaint(CDrawContext& dc)
{
CMiniButton::OnPaint(dc);
if (m_bSubMenu)
{
// Draw checked mark.
float x1 = m_rect.right - 12;
float y1 = m_rect.top + 3;
float x2 = m_rect.right - 3;
float y2 = (m_rect.bottom + m_rect.top) / 2;
float x3 = m_rect.right - 12;
float y3 = m_rect.bottom - 3;
dc.SetColor(ColorB(0, 0, 0, 255));
dc.DrawLine(x1, y1, x2, y2, 2.f);
dc.DrawLine(x2, y2, x3, y3, 2.f);
x1 -= 1;
x2 -= 1;
x3 -= 1;
y1 -= 1;
y2 -= 1;
y3 -= 1;
dc.SetColor(ColorB(255, 255, 255, 255));
dc.DrawLine(x1, y1, x2, y2, 2.f);
dc.DrawLine(x2, y2, x3, y3, 2.f);
}
//dc.DrawFrame( m_rect,dc.Metrics().clrFrameBorder,dc.Metrics().clrBackground );
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::SetRect(const Rect& rc)
{
Rect newrc = rc;
newrc.bottom = newrc.top + m_pGUI->Metrics().fTitleSize + 2;
CMiniCtrl::SetRect(newrc);
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::OnEvent(float x, float y, EMiniCtrlEvent event)
{
switch (event)
{
case eCtrlEvent_LButtonDown:
{
if (m_bVisible)
{
Close();
}
else
{
Open();
}
}
break;
case eCtrlEvent_MouseOff:
{
bool closeMenu = true;
IMiniCtrl* pCtrl = m_pGUI->GetCtrlFromPoint(x, y);
//check if the cursor is still in one of the menu's children
if (pCtrl)
{
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
if (pCtrl == GetSubCtrl(i))
{
closeMenu = false;
break;
}
}
}
if (closeMenu)
{
Close();
if (m_pParent)
{
m_pParent->OnEvent(x, y, eCtrlEvent_MouseOff);
}
}
}
break;
}
}
CMiniMenu* CMiniMenu::UpdateSelection(EMiniCtrlEvent event)
{
CMiniMenu* pNewMenu = this;
IMiniCtrl* pCurrentSelection = NULL;
if (m_selectionIndex != -1)
{
pCurrentSelection = m_subCtrls[m_selectionIndex];
}
switch (event)
{
case eCtrlEvent_DPadLeft: //move to parent
if (!pCurrentSelection)
{
//move to previous root menu
pNewMenu = NULL;
}
else if (m_bSubMenu)
{
Close();
pNewMenu = (CMiniMenu*)m_pParent.get();
//pNewMenu->SetFlag(eCtrl_Highlight);
}
break;
case eCtrlEvent_DPadRight: //move to child
if (!pCurrentSelection)
{
//move to next root menu
pNewMenu = NULL;
}
else if (pCurrentSelection->GetType() == eCtrlType_Menu)
{
pNewMenu = (CMiniMenu*)pCurrentSelection;
pNewMenu->Open();
pNewMenu->ClearFlag(eCtrl_Highlight);
}
break;
case eCtrlEvent_DPadUp: //move up list
if (m_bSubMenu)
{
if (m_selectionIndex > 0)
{
m_selectionIndex--;
}
}
else
{
if (m_selectionIndex >= 0)
{
m_selectionIndex--;
if (m_selectionIndex == -1)
{
SetFlag(eCtrl_Highlight);
}
}
}
break;
case eCtrlEvent_DPadDown: //move down the list
if (m_selectionIndex < (int)(m_subCtrls.size() - 1))
{
if (m_selectionIndex == -1)
{
ClearFlag(eCtrl_Highlight);
}
m_selectionIndex++;
}
break;
case eCtrlEvent_LButtonDown: //pass on button press
{
if (pCurrentSelection)
{
if (pCurrentSelection->GetType() == eCtrlType_Menu)
{
pNewMenu = (CMiniMenu*)pCurrentSelection;
}
pCurrentSelection->OnEvent(0, 0, eCtrlEvent_LButtonDown);
}
else
{
OnEvent(0, 0, eCtrlEvent_LButtonDown);
}
}
break;
}
if (pCurrentSelection)
{
pCurrentSelection->ClearFlag(eCtrl_Highlight);
}
if (m_selectionIndex >= 0)
{
m_subCtrls[m_selectionIndex]->SetFlag(eCtrl_Highlight);
}
return pNewMenu;
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::Open()
{
m_bVisible = true;
Rect rc(0, 0, m_menuWidth, 1);
//render sub menu to the right
if (m_bSubMenu)
{
CMiniMenu* pParent = static_cast<CMiniMenu*>(m_pParent.get());
rc.left = pParent->m_menuWidth; //rcParent.right;
rc.right = rc.left + m_menuWidth;
}
else
{
Rect rcThis = GetRect();
rc.top = rcThis.Height();
}
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
pSubCtrl->ClearFlag(eCtrl_Hidden);
float h = pSubCtrl->GetRect().Height();
Rect rcCtrl = rc;
rcCtrl.top = rc.top;
rcCtrl.bottom = rcCtrl.top + h;
pSubCtrl->SetRect(rcCtrl);
rc.top += h;
}
//highlight first item when opened
if (m_bSubMenu)
{
m_selectionIndex = 0;
m_subCtrls[m_selectionIndex]->SetFlag(eCtrl_Highlight);
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::Close()
{
m_bVisible = false;
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
pSubCtrl->SetFlag(eCtrl_Hidden);
}
if (m_selectionIndex != -1)
{
m_subCtrls[m_selectionIndex]->ClearFlag(eCtrl_Highlight);
}
m_selectionIndex = -1;
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::Reset()
{
m_bVisible = false;
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
pSubCtrl->Reset();
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::SaveState()
{
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
pSubCtrl->SaveState();
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::RestoreState()
{
for (int i = 0, num = GetSubCtrlCount(); i < num; i++)
{
IMiniCtrl* pSubCtrl = GetSubCtrl(i);
pSubCtrl->RestoreState();
}
}
//////////////////////////////////////////////////////////////////////////
void CMiniMenu::AddSubCtrl(IMiniCtrl* pCtrl)
{
assert(pCtrl);
pCtrl->SetFlag(eCtrl_Hidden);
pCtrl->SetFlag(eCtrl_NoBorder);
bool bSubMenu = false;
if (pCtrl->GetType() == eCtrlType_Menu)
{
CMiniMenu* pSubMenu = static_cast<CMiniMenu*>(pCtrl);
pSubMenu->m_bSubMenu = true;
bSubMenu = true;
}
if (!m_bSubMenu)
{
//menu is at least the size of title bar
m_menuWidth = max(m_menuWidth, strlen(GetTitle()) * 8.5f);
}
const char* title = pCtrl->GetTitle();
if (title)
{
uint32 titleLen = strlen(title);
float width = (float)titleLen * 8.5f;
if (bSubMenu)
{
//increase width for submenu arrow
width += 10.f;
}
m_menuWidth = max(m_menuWidth, width);
}
// Call parent
CMiniButton::AddSubCtrl(pCtrl);
}
MINIGUI_END
@@ -0,0 +1,66 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Button implementation in the MiniGUI
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H
#pragma once
#include "MiniGUI.h"
#include "MiniButton.h"
MINIGUI_BEGIN
//////////////////////////////////////////////////////////////////////////
// Root window all other controls derive from
class CMiniMenu
: public CMiniButton
{
public:
CMiniMenu();
//////////////////////////////////////////////////////////////////////////
// CMiniCtrl interface implementation.
//////////////////////////////////////////////////////////////////////////
virtual EMiniCtrlType GetType() const { return eCtrlType_Menu; }
virtual void SetRect(const Rect& rc);
virtual void OnPaint(CDrawContext& dc);
virtual void OnEvent(float x, float y, EMiniCtrlEvent event);
virtual void AddSubCtrl(IMiniCtrl* pCtrl);
virtual void Reset();
virtual void SaveState();
virtual void RestoreState();
//////////////////////////////////////////////////////////////////////////
//digital selection funcs
CMiniMenu* UpdateSelection(EMiniCtrlEvent event);
void Open();
void Close();
protected:
protected:
bool m_bVisible;
bool m_bSubMenu;
float m_menuWidth;
int m_selectionIndex;
};
MINIGUI_END
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINIMENU_H
@@ -0,0 +1,337 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Table implementation in the MiniGUI
#include "CrySystem_precompiled.h"
#include "MiniTable.h"
#include "DrawContext.h"
#include <AzFramework/Input/Devices/Keyboard/InputDeviceKeyboard.h>
MINIGUI_BEGIN
CMiniTable::CMiniTable()
{
m_fTextSize = 15.f;
m_pageNum = 0;
m_pageSize = 35;
}
void CMiniTable::OnPaint(CDrawContext& dc)
{
if (m_requiresResize)
{
AutoResize();
}
ColorB borderCol;
ColorB backgroundCol = dc.Metrics().clrBackground;
if (m_pGUI->InFocus())
{
if (m_moving)
{
borderCol = dc.Metrics().clrFrameBorderHighlight;
}
else
{
borderCol = dc.Metrics().clrFrameBorder;
}
}
else
{
borderCol = dc.Metrics().clrFrameBorderOutOfFocus;
backgroundCol.a = dc.Metrics().outOfFocusAlpha;
}
dc.DrawFrame(m_rect, borderCol, backgroundCol);
float fTextSize = m_fTextSize;
if (fTextSize == 0)
{
fTextSize = dc.Metrics().fTextSize;
}
float indent = 4.f;
float x = m_rect.left + indent;
float y = m_rect.top + indent;
const int nColumns = m_columns.size();
int numEntries = nColumns > 0 ? m_columns[0].cells.size() : 0;
int startIdx = 0;
int endIdx = numEntries;
//Page number
if (nColumns)
{
int numPages = numEntries / m_pageSize;
if (numPages)
{
startIdx = m_pageNum * m_pageSize;
endIdx = min(startIdx + m_pageSize, numEntries);
dc.SetColor(ColorB(255, 255, 255, 255));
//print page details (adjust for zero indexed)
dc.DrawString(x, y, fTextSize, eTextAlign_Left, "Page %d of %d (Page Up / Page Down)", m_pageNum + 1, numPages + 1);
y += fTextSize;
}
}
float topOfTable = y;
for (int i = 0; i < nColumns; i++)
{
SColumn& column = m_columns[i];
y = topOfTable;
dc.SetColor(ColorB(32, 32, 255, 255));
dc.DrawString(x, y, fTextSize, eTextAlign_Left, column.name);
y += fTextSize + indent;
ColorB currentCol(255, 255, 255, 255);
dc.SetColor(currentCol);
const int nCells = column.cells.size();
for (int j = startIdx; j < endIdx && j < nCells; j++)
{
if (column.cells[j].col != currentCol)
{
dc.SetColor(column.cells[j].col);
currentCol = column.cells[j].col;
}
dc.DrawString(x, y, fTextSize, eTextAlign_Left, column.cells[j].text);
y += fTextSize;
}
x += column.width;
}
}
void CMiniTable::OnEvent(float x, float y, EMiniCtrlEvent event)
{
//movement
CMiniCtrl::OnEvent(x, y, event);
}
void CMiniTable::AutoResize()
{
//must be at least the size of cross box
float tableWidth = 30.f;
float tableHeight = 0.f;
const float widthScale = 0.6f;
const int nColumns = m_columns.size();
int startIdx = 0;
int endIdx = 0;
bool bPageHeader = false;
//Update Page index
if (nColumns)
{
int numEntries = m_columns[0].cells.size();
int numPages = numEntries / m_pageSize;
//page index is now invalid, cap at max
if ((m_pageNum * m_pageSize) > numEntries)
{
m_pageNum = (numEntries / m_pageSize);
}
startIdx = m_pageNum * m_pageSize;
endIdx = min(startIdx + m_pageSize, numEntries);
if (numEntries > m_pageSize)
{
bPageHeader = true;
}
}
for (int i = 0; i < nColumns; i++)
{
SColumn& column = m_columns[i];
float width = strlen(column.name) * m_fTextSize;
int nCells = column.cells.size();
for (int j = startIdx; j < endIdx && j < nCells; j++)
{
width = max(width, strlen(column.cells[j].text) * m_fTextSize);
}
width *= widthScale;
column.width = width;
tableWidth += width;
tableHeight = max(tableHeight, min(endIdx - startIdx, m_pageSize) * m_fTextSize);
}
tableHeight += m_fTextSize * 2.f;
//Page index
if (bPageHeader)
{
tableHeight += m_fTextSize;
}
Rect newRect = m_rect;
newRect.right = newRect.left + tableWidth;
newRect.bottom = newRect.top + tableHeight;
SetRect(newRect);
m_requiresResize = false;
}
void CMiniTable::Reset()
{
SetFlag(eCtrl_Hidden);
m_pageNum = 0;
}
void CMiniTable::SaveState()
{
if (CheckFlag(eCtrl_Hidden))
{
m_saveStateOn = false;
}
else
{
m_saveStateOn = true;
}
}
void CMiniTable::RestoreState()
{
if (m_saveStateOn)
{
ClearFlag(eCtrl_Hidden);
}
}
int CMiniTable::AddColumn(const char* name)
{
assert(name);
SColumn col;
cry_strcpy(col.name, name);
col.width = strlen(col.name) * 8.f;
m_columns.push_back(col);
m_requiresResize = true;
return m_columns.size() - 1;
}
void CMiniTable::RemoveColumns()
{
m_columns.clear();
}
int CMiniTable::AddData(int columnIndex, ColorB col, const char* format, ...)
{
assert(columnIndex < (int)m_columns.size());
SCell cell;
va_list args;
va_start(args, format);
int written = vsnprintf_s(cell.text, MAX_TEXT_LENGTH, MAX_TEXT_LENGTH - 1, format, args);
va_end(args);
if (written == -1)
{
cell.text[MAX_TEXT_LENGTH - 1] = '\0';
}
cell.col = col;
m_columns[columnIndex].cells.push_back(cell);
m_requiresResize = true;
return m_columns[columnIndex].cells.size() - 1;
}
void CMiniTable::ClearTable()
{
const int nColumns = m_columns.size();
for (int i = 0; i < nColumns; i++)
{
m_columns[i].cells.clear();
}
}
void CMiniTable::SetVisible(bool state)
{
if (state)
{
clear_flag(eCtrl_Hidden);
AzFramework::InputChannelEventListener::Connect();
}
else
{
set_flag(eCtrl_Hidden);
AzFramework::InputChannelEventListener::Disconnect();
}
if (m_pCloseButton)
{
m_pCloseButton->SetVisible(state);
}
}
void CMiniTable::Hide(bool stat)
{
SetVisible(!stat);
}
bool CMiniTable::OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel)
{
if (!IsHidden() && inputChannel.IsStateBegan())
{
const AzFramework::InputChannelId& channelId = inputChannel.GetInputChannelId();
if (channelId == AzFramework::InputDeviceKeyboard::Key::NavigationPageUp)
{
m_pageNum++;
m_requiresResize = true;
}
else if (channelId == AzFramework::InputDeviceKeyboard::Key::NavigationPageDown)
{
if (m_pageNum > 0)
{
m_pageNum--;
m_requiresResize = true;
}
}
}
return false;
}
MINIGUI_END
@@ -0,0 +1,96 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
// Description : Table implementation in the MiniGUI
#ifndef CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H
#define CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H
#pragma once
#include "MiniGUI.h"
MINIGUI_BEGIN
class CMiniTable
: public CMiniCtrl
, public IMiniTable
, public AzFramework::InputChannelEventListener
{
public:
CMiniTable();
//////////////////////////////////////////////////////////////////////////
// CMiniCtrl interface implementation.
//////////////////////////////////////////////////////////////////////////
virtual EMiniCtrlType GetType() const { return eCtrlType_Table; }
virtual void OnPaint(CDrawContext& dc);
virtual void OnEvent(float x, float y, EMiniCtrlEvent event);
virtual void Reset();
virtual void SaveState();
virtual void RestoreState();
virtual void AutoResize();
virtual void SetVisible(bool state);
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// IMiniTable interface implementation.
//////////////////////////////////////////////////////////////////////////
//Add a new column to the table, return column index
virtual int AddColumn(const char* name);
//Remove all columns an associated data
virtual void RemoveColumns();
//Add data to specified column (add onto the end), return row index
virtual int AddData(int columnIndex, ColorB col, const char* format, ...);
//Clear all data from table
virtual void ClearTable();
virtual bool IsHidden() { return CheckFlag(eCtrl_Hidden); }
virtual void Hide(bool stat);
// AzFramework::InputChannelEventListener
bool OnInputChannelEventFiltered(const AzFramework::InputChannel& inputChannel) override;
AZ::s32 GetPriority() const override { return AzFramework::InputChannelEventListener::GetPriorityUI(); }
static const int MAX_TEXT_LENGTH = 64;
protected:
struct SCell
{
char text[MAX_TEXT_LENGTH];
ColorB col;
};
struct SColumn
{
char name[MAX_TEXT_LENGTH];
float width;
std::vector<SCell> cells;
};
std::vector<SColumn> m_columns;
int m_pageSize;
int m_pageNum;
};
MINIGUI_END
#endif // CRYINCLUDE_CRYSYSTEM_MINIGUI_MINITABLE_H