Remove more unused things from CryCommon and CrySystem. (#709)

Lots of unrelated removals, I basically tried to remove everything exposed via gEnv that isn't used anymore, and following the threads found a few other things to remove also.
This commit is contained in:
bosnichd
2021-05-12 08:30:15 -06:00
committed by GitHub
parent f9fb61cc5d
commit 7cec2d8b07
198 changed files with 29 additions and 28558 deletions
-132
View File
@@ -1,132 +0,0 @@
/*
* 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 "StdAfx.h"
#include "EULADialog.h"
#include "Win32GUI.h"
#include "ModuleHelpers.h"
#include "Richedit.h"
#include <Windows.h>
EULADialog::EULADialog()
: m_frameWindow()
, m_cancelButton(_T("Cancel"), this, &EULADialog::CancelPressed)
, m_buttonSpacer(0, 0, 2000, 0)
, m_acceptButton(_T("Accept"), this, &EULADialog::AcceptPressed)
, m_buttonLayout(Layout::DirectionHorizontal)
, m_edit()
{
Win32GUI::Initialize();
m_buttonLayout.AddComponent(&m_buttonSpacer);
m_buttonLayout.AddComponent(&m_cancelButton);
m_buttonLayout.AddComponent(&m_acceptButton);
m_frameWindow.AddComponent(&m_edit);
m_frameWindow.AddComponent(&m_buttonLayout);
}
namespace
{
class EditStreamCallbackObject
{
public:
EditStreamCallbackObject(const char* data, int size)
: data(data)
, position(0)
, size(size) {}
static DWORD WINAPI EditStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
{
return ((EditStreamCallbackObject*)dwCookie)->EditStreamCallback_Member(dwCookie, pbBuff, cb, pcb);
}
private:
DWORD EditStreamCallback_Member(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
{
int bytesToRead = (std::min)(this->size - this->position, (int)cb);
std::memcpy(pbBuff, this->data + this->position, bytesToRead);
this->position += bytesToRead;
if (pcb)
{
*pcb = bytesToRead;
}
return 0;
}
const char* data;
int position;
int size;
};
}
EULADialog::UserResponse EULADialog::Run(int width, int height, TCHAR* resourceID)
{
m_frameWindow.Show(true, width, height);
// Attempt to load the resource.
HINSTANCE module = ModuleHelpers::GetCurrentModule(ModuleHelpers::CurrentModuleSpecifier_Library);
HRSRC resource = (resourceID ? FindResource(module, resourceID, RT_RCDATA) : 0);
int resourceLength = (resource ? SizeofResource(module, resource) : 0);
HGLOBAL resourceGlobal = (resource ? LoadResource(module, resource) : 0);
void* resourceData = (resourceGlobal ? LockResource(resourceGlobal) : 0);
// No need to unlock/delete data.
m_userResponse = UserResponseNone;
// Load the text.
if (resourceData && resourceLength > 0)
{
EditStreamCallbackObject callbackObject((const char*)resourceData, resourceLength);
EDITSTREAM editStream;
std::memset(&editStream, 0, sizeof(editStream));
editStream.dwCookie = (DWORD_PTR)&callbackObject;
editStream.pfnCallback = &EditStreamCallbackObject::EditStreamCallback;
SendMessage((HWND)m_edit.m_edit, EM_STREAMIN, SF_RTF, (LPARAM)&editStream);
}
MSG msg;
BOOL status;
bool waitingAcceptance = false;
while (m_userResponse == UserResponseNone && (status = GetMessage(&msg, HWND(0), UINT(0), UINT(0))) != 0)
{
if (status == -1)
{
break;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
m_frameWindow.Show(false, 0, 0);
return m_userResponse;
}
void EULADialog::CancelPressed()
{
m_userResponse = UserResponseCancel;
}
void EULADialog::AcceptPressed()
{
m_userResponse = UserResponseAccept;
}
EULADialog::UserResponse EULADialog::Show(int width, int height, TCHAR* resourceID)
{
EULADialog dlg;
return dlg.Run(width, height, resourceID);
}
-55
View File
@@ -1,55 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_EULADIALOG_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_EULADIALOG_H
#pragma once
#include "FrameWindow.h"
#include "EditControl.h"
#include "Spacer.h"
#include "Layout.h"
#include "PushButton.h"
class EULADialog
{
public:
enum UserResponse
{
UserResponseNone,
UserResponseCancel,
UserResponseAccept
};
static UserResponse Show(int width, int height, TCHAR* resourceID);
private:
EULADialog();
UserResponse Run(int width, int height, TCHAR* resourceID);
void CancelPressed();
void AcceptPressed();
FrameWindow m_frameWindow;
PushButton m_cancelButton;
Spacer m_buttonSpacer;
PushButton m_acceptButton;
Layout m_buttonLayout;
EditControl m_edit;
UserResponse m_userResponse;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_EULADIALOG_H
@@ -1,48 +0,0 @@
/*
* 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 "StdAfx.h"
#include "EditControl.h"
#include "Win32GUI.h"
#include <Windows.h>
#include <CommCtrl.h>
#include <Richedit.h>
EditControl::EditControl()
: m_edit(0)
{
}
void EditControl::CreateUI(void* window, int left, int top, int width, int height)
{
m_edit = Win32GUI::CreateControl(RICHEDIT_CLASS, ES_MULTILINE /*| ES_READONLY*/, (HWND)window, left, top, width, height);
}
void EditControl::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_edit, left, top, width, height, true);
}
void EditControl::DestroyUI(void* window)
{
DestroyWindow((HWND)m_edit);
m_edit = 0;
}
void EditControl::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 20;
maxWidth = 2000;
minHeight = 20;
maxHeight = 2000;
}
@@ -1,36 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_EDITCONTROL_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_EDITCONTROL_H
#pragma once
#include "IUIComponent.h"
class EditControl
: public IUIComponent
{
public:
EditControl();
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
void* m_edit;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_EDITCONTROL_H
@@ -1,116 +0,0 @@
/*
* 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 "StdAfx.h"
#include "FrameWindow.h"
#include "Win32GUI.h"
#include "IUIComponent.h"
#include <Windows.h>
#include <cassert>
FrameWindow::FrameWindow()
: m_hwnd(0)
, m_layout(Layout::DirectionVertical)
{
}
FrameWindow::~FrameWindow()
{
if (m_hwnd)
{
Show(false, 0, 0);
}
}
void FrameWindow::AddComponent(IUIComponent* component)
{
assert(m_hwnd == 0);
m_layout.AddComponent(component);
}
void FrameWindow::Show(bool show, int width, int height)
{
if (show)
{
assert(m_hwnd == 0);
TCHAR* className = _T("CustomFrameWindowClass212");
Win32GUI::RegisterFrameClass(className);
m_hwnd = Win32GUI::CreateFrame(className, WS_MINIMIZEBOX | WS_OVERLAPPED | WS_THICKFRAME | WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX, width, height);
Win32GUI::SetCallback<Win32GUI::EventCallbacks::GetDimensions, FrameWindow>((HWND)m_hwnd, this, &FrameWindow::CalculateExtremeDimensions);
Win32GUI::SetCallback<Win32GUI::EventCallbacks::SizeChanged, FrameWindow>((HWND)m_hwnd, this, &FrameWindow::OnSizeChanged);
std::pair<int, int> size = InitializeSize();
m_layout.CreateUI(m_hwnd, 0, 0, size.first, size.second);
ShowWindow((HWND)m_hwnd, SW_SHOWDEFAULT);
}
else
{
m_layout.DestroyUI(m_hwnd);
assert(m_hwnd != 0);
DestroyWindow((HWND)m_hwnd);
m_hwnd = 0;
}
}
void FrameWindow::SetCaption(const TCHAR* caption)
{
SendMessage((HWND)m_hwnd, WM_SETTEXT, 0, (LPARAM)caption);
}
void* FrameWindow::GetHWND()
{
return m_hwnd;
}
std::pair<int, int> FrameWindow::InitializeSize()
{
int minW, maxW, minH, maxH;
CalculateExtremeDimensions(minW, maxW, minH, maxH);
RECT rect;
GetWindowRect((HWND)m_hwnd, &rect);
int width = int((std::min)(maxW, (std::max)(minW, int(rect.right - rect.left))));
int height = int((std::min)(maxH, (std::max)(minH, int(rect.bottom - rect.top))));
MoveWindow((HWND)m_hwnd, rect.left, rect.top, width, height, false);
return std::make_pair(width, height);
}
void FrameWindow::CalculateExtremeDimensions(int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
int minW = 0;
int maxW = 0;
int minH = 0;
int maxH = 0;
m_layout.GetExtremeDimensions(m_hwnd, minW, maxW, minH, maxH);
// Add the space required for the window decorations.
RECT rect;
rect.left = 0, rect.top = 0, rect.right = minW, rect.bottom = minH;
unsigned style = GetWindowLong((HWND)m_hwnd, GWL_STYLE);
AdjustWindowRect(&rect, style, false);
minW = rect.right - rect.left;
minH = rect.bottom - rect.top;
rect.left = 0, rect.top = 0, rect.right = maxW, rect.bottom = maxH;
AdjustWindowRect(&rect, style, false);
maxW = rect.right - rect.left;
maxH = rect.bottom - rect.top;
minWidth = minW;
maxWidth = maxW;
minHeight = minH;
maxHeight = maxH;
}
void FrameWindow::OnSizeChanged(int width, int height)
{
m_layout.Resize(m_hwnd, 0, 0, width, height);
}
@@ -1,44 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_FRAMEWINDOW_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_FRAMEWINDOW_H
#pragma once
#include <vector>
#include "Layout.h"
class IUIComponent;
class FrameWindow
{
public:
FrameWindow();
~FrameWindow();
void AddComponent(IUIComponent* component);
void Show(bool show, int width, int height);
void SetCaption(const TCHAR* caption);
void* GetHWND();
private:
void UpdateComponentUI(bool create);
std::pair<int, int> InitializeSize();
void CalculateExtremeDimensions(int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
void OnSizeChanged(int width, int height);
void* m_hwnd;
Layout m_layout;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_FRAMEWINDOW_H
@@ -1,28 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_IUICOMPONENT_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_IUICOMPONENT_H
#pragma once
class IUIComponent
{
public:
virtual void CreateUI(void* window, int left, int top, int width, int height) = 0;
virtual void Resize(void* window, int left, int top, int width, int height) = 0;
virtual void DestroyUI(void* window) = 0;
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight) = 0;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_IUICOMPONENT_H
-233
View File
@@ -1,233 +0,0 @@
/*
* 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 "StdAfx.h"
#include "Layout.h"
#include <cassert>
#include <Windows.h>
Layout::Layout(Direction direction)
: m_direction(direction)
{
}
void Layout::AddComponent(IUIComponent* component)
{
m_components.push_back(ComponentEntry(component));
}
void Layout::CreateUI(void* window, int left, int top, int width, int height)
{
UpdateLayout(window, left, top, width, height);
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
component->CreateUI(window, m_components[componentIndex].left, m_components[componentIndex].top, m_components[componentIndex].width, m_components[componentIndex].height);
}
}
void Layout::Resize(void* window, int left, int top, int width, int height)
{
UpdateLayout(window, left, top, width, height);
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
component->Resize(window, m_components[componentIndex].left, m_components[componentIndex].top, m_components[componentIndex].width, m_components[componentIndex].height);
}
}
void Layout::DestroyUI(void* window)
{
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
component->DestroyUI(window);
}
}
void Layout::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
int minW = 0;
int maxW = 0;
int minH = 0;
int maxH = 0;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
int compMinW, compMaxW, compMinH, compMaxH;
component->GetExtremeDimensions(window, compMinW, compMaxW, compMinH, compMaxH);
switch (m_direction)
{
case DirectionVertical:
minW = (minW > compMinW ? minW : compMinW);
maxW = (maxW > compMaxW ? maxW : compMaxW); // Deliberately take the larger maximum.
minH += compMinH;
maxH += compMaxH;
break;
case DirectionHorizontal:
minW += compMinW;
maxW += compMaxW;
minH = (minH > compMinH ? minH : compMinH);
maxH = (maxH > compMaxH ? maxH : compMaxH); // Deliberately take the larger maximum.
break;
}
}
// Make sure the window is at least a certain size;
minW = (minW >= 10 ? minW : 10);
maxW = (maxW >= minW ? maxW : minW);
minH = (minH >= 10 ? minH : 10);
maxH = (maxH >= minH ? maxH : minH);
minWidth = minW;
maxWidth = maxW;
minHeight = minH;
maxHeight = maxH;
}
void Layout::UpdateLayout(void* window, int left, int top, int width, int height)
{
assert(window);
int remainingToAllocate;
switch (m_direction)
{
case DirectionVertical:
remainingToAllocate = height;
break;
case DirectionHorizontal:
remainingToAllocate = width;
break;
}
int smallestAllocationAmount = INT_MAX;
int canBeExtendedCount = 0;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
int compMinW, compMaxW, compMinH, compMaxH;
component->GetExtremeDimensions(window, compMinW, compMaxW, compMinH, compMaxH);
switch (m_direction)
{
case DirectionVertical:
{
int allocationAmount = compMaxH - compMinH;
if (allocationAmount > 0)
{
++canBeExtendedCount;
smallestAllocationAmount = (smallestAllocationAmount < allocationAmount ? smallestAllocationAmount : allocationAmount);
}
m_components[componentIndex].height = compMinH;
m_components[componentIndex].width = (width > compMaxW ? compMaxW : width);
remainingToAllocate -= m_components[componentIndex].height;
}
break;
case DirectionHorizontal:
{
int allocationAmount = compMaxW - compMinW;
if (allocationAmount > 0)
{
++canBeExtendedCount;
smallestAllocationAmount = (smallestAllocationAmount < allocationAmount ? smallestAllocationAmount : allocationAmount);
}
m_components[componentIndex].width = compMinW;
m_components[componentIndex].height = (height > compMaxH ? compMaxH : height);
remainingToAllocate -= m_components[componentIndex].width;
}
break;
}
}
while (remainingToAllocate > 0 && canBeExtendedCount > 0)
{
int equitablePerCompAllocation = remainingToAllocate / canBeExtendedCount;
int compAllocation = (equitablePerCompAllocation < smallestAllocationAmount ? equitablePerCompAllocation : smallestAllocationAmount);
compAllocation = (compAllocation > 0 ? compAllocation : 1);
canBeExtendedCount = 0;
smallestAllocationAmount = INT_MAX;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
IUIComponent* component = m_components[componentIndex].component;
int compMinW, compMaxW, compMinH, compMaxH;
component->GetExtremeDimensions(window, compMinW, compMaxW, compMinH, compMaxH);
switch (m_direction)
{
case DirectionVertical:
{
int componentExpandAmount = compMaxH - m_components[componentIndex].height;
if (componentExpandAmount > 0)
{
m_components[componentIndex].height += compAllocation;
assert(m_components[componentIndex].height <= compMaxH);
componentExpandAmount -= compAllocation;
remainingToAllocate -= compAllocation;
if (componentExpandAmount > 0)
{
smallestAllocationAmount = (smallestAllocationAmount < componentExpandAmount ? smallestAllocationAmount : componentExpandAmount);
++canBeExtendedCount;
}
}
}
break;
case DirectionHorizontal:
{
int componentExpandAmount = compMaxW - m_components[componentIndex].width;
if (componentExpandAmount > 0)
{
m_components[componentIndex].width += compAllocation;
assert(m_components[componentIndex].width <= compMaxW);
componentExpandAmount -= compAllocation;
remainingToAllocate -= compAllocation;
if (componentExpandAmount > 0)
{
smallestAllocationAmount = (smallestAllocationAmount < componentExpandAmount ? smallestAllocationAmount : componentExpandAmount);
++canBeExtendedCount;
}
}
}
break;
}
}
}
switch (m_direction)
{
case DirectionVertical:
{
int posY = top;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
m_components[componentIndex].left = left;
m_components[componentIndex].top = posY;
posY += m_components[componentIndex].height;
}
}
break;
case DirectionHorizontal:
{
int posX = left;
for (int componentIndex = 0, componentCount = int(m_components.size()); componentIndex < componentCount; ++componentIndex)
{
m_components[componentIndex].top = top;
m_components[componentIndex].left = posX;
posX += m_components[componentIndex].width;
}
}
break;
}
}
-61
View File
@@ -1,61 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_LAYOUT_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_LAYOUT_H
#pragma once
#include "IUIComponent.h"
#include <vector>
class Layout
: public IUIComponent
{
public:
enum Direction
{
DirectionHorizontal,
DirectionVertical
};
Layout(Direction direction);
void AddComponent(IUIComponent* component);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
void UpdateLayout(void* window, int left, int top, int width, int height);
struct ComponentEntry
{
explicit ComponentEntry(IUIComponent* component)
: component(component)
, left(0)
, top(0)
, width(0)
, height(0) {}
IUIComponent* component;
int left;
int top;
int width;
int height;
};
std::vector<ComponentEntry> m_components;
Direction m_direction;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_LAYOUT_H
-96
View File
@@ -1,96 +0,0 @@
/*
* 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 "StdAfx.h"
#include "ListView.h"
#include "Win32GUI.h"
#include "resource.h"
#include "ModuleHelpers.h"
#include <Windows.h>
#include <CommCtrl.h>
#include <cstring>
ListView::ListView()
: m_list(0)
{
}
void ListView::Add(int imageIndex, const TCHAR* message)
{
int itemCount = int(SendMessage((HWND)m_list, LVM_GETITEMCOUNT, 0, 0));
LVITEM item;
std::memset(&item, 0, sizeof(item));
item.mask = LVIF_TEXT | LVIF_IMAGE;
item.iItem = itemCount;
item.iSubItem = 0;
item.pszText = (TCHAR*)message;
item.iImage = imageIndex;
SendMessage((HWND)m_list, LVM_INSERTITEM, 0, (LPARAM)&item);
}
void ListView::Clear()
{
SendMessage((HWND)m_list, LVM_DELETEALLITEMS, 0, 0);
}
void ListView::CreateUI(void* window, int left, int top, int width, int height)
{
m_list = Win32GUI::CreateControl(WC_LISTVIEW, LVS_REPORT | LVS_NOCOLUMNHEADER, (HWND)window, left, top, width, height);
LVCOLUMN column;
std::memset(&column, 0, sizeof(column));
column.mask = LVCF_TEXT | LVCF_WIDTH;
column.pszText = _T("Message");
column.cx = width;
SendMessage((HWND)m_list, LVM_INSERTCOLUMN, 0, (LPARAM)&column);
HIMAGELIST imageList = (HIMAGELIST)CreateImageList();
SendMessage((HWND)m_list, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)imageList);
}
void ListView::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_list, left, top, width, height, true);
SendMessage((HWND)m_list, LVM_SETCOLUMNWIDTH, 0, width);
}
void ListView::DestroyUI(void* window)
{
DestroyWindow((HWND)m_list);
m_list = 0;
}
void ListView::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 20;
maxWidth = 2000;
minHeight = 20;
maxHeight = 2000;
}
void* ListView::CreateImageList()
{
HINSTANCE instance = ModuleHelpers::GetCurrentModule(ModuleHelpers::CurrentModuleSpecifier_Library);
HBITMAP image = (HBITMAP)LoadImage(instance, MAKEINTRESOURCE(IDB_LOG_ICONS), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
DIBSECTION dibSection;
GetObject(image, sizeof(dibSection), &dibSection);
int height = dibSection.dsBmih.biHeight;
int width = height;
int count = dibSection.dsBmih.biWidth / width;
HIMAGELIST imageList = ImageList_Create(16, 16, ILC_COLOR32, count, 0);
ImageList_Add(imageList, image, 0);
return imageList;
}
-42
View File
@@ -1,42 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_LISTVIEW_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_LISTVIEW_H
#pragma once
#include "IUIComponent.h"
class ListView
: public IUIComponent
{
public:
ListView();
void Add(int imageIndex, const TCHAR* message);
void Clear();
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
void* CreateImageList();
void* m_list;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_LISTVIEW_H
-158
View File
@@ -1,158 +0,0 @@
/*
* 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 "StdAfx.h"
#include "LogWindow.h"
LogWindow::LogWindow()
: m_mainLayout(Layout::DirectionVertical)
, m_toolbarLayout(Layout::DirectionHorizontal)
, m_filterFlags(0)
{
m_buttons.push_back(new ToggleButton(_T("Debug"), this, &LogWindow::DebugToggled));
m_buttons.push_back(new ToggleButton(_T("Info"), this, &LogWindow::InfoToggled));
m_buttons.push_back(new ToggleButton(_T("Warnings"), this, &LogWindow::WarningsToggled));
m_buttons.push_back(new ToggleButton(_T("Errors"), this, &LogWindow::ErrorsToggled));
SetFilter(ILogger::eSeverity_Error, true);
SetFilter(ILogger::eSeverity_Warning, true);
SetFilter(ILogger::eSeverity_Info, true);
SetFilter(ILogger::eSeverity_Debug, false);
m_toolbarLayout.AddComponent(m_buttons[3]);
m_toolbarLayout.AddComponent(m_buttons[2]);
m_toolbarLayout.AddComponent(m_buttons[1]);
m_toolbarLayout.AddComponent(m_buttons[0]);
m_mainLayout.AddComponent(&m_toolbarLayout);
m_mainLayout.AddComponent(&m_list);
}
LogWindow::~LogWindow()
{
for (std::vector<ToggleButton*>::iterator button = m_buttons.begin(), end = m_buttons.end(); button != end; ++button)
{
delete *button;
}
}
void LogWindow::Log(ILogger::ESeverity eSeverity, const TCHAR* message)
{
m_messages.push_back(LogMessage(eSeverity, message));
if (m_filterFlags & (1 << GetSeverityIndex(eSeverity)))
{
m_list.Add(GetImageIndex(eSeverity), message);
}
}
void LogWindow::SetFilter(ILogger::ESeverity eSeverity, bool visible)
{
int index = GetSeverityIndex(eSeverity);
if (visible)
{
m_filterFlags |= (1 << index);
}
else
{
m_filterFlags &= ~(1 << index);
}
m_buttons[index]->SetState(visible);
RefillList();
}
void LogWindow::CreateUI(void* window, int left, int top, int width, int height)
{
m_mainLayout.CreateUI(window, left, top, width, height);
}
void LogWindow::Resize(void* window, int left, int top, int width, int height)
{
m_mainLayout.Resize(window, left, top, width, height);
}
void LogWindow::DestroyUI(void* window)
{
m_mainLayout.DestroyUI(window);
}
void LogWindow::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
m_mainLayout.GetExtremeDimensions(window, minWidth, maxWidth, minHeight, maxHeight);
}
void LogWindow::ErrorsToggled(bool value)
{
SetFilter(ILogger::eSeverity_Error, value);
}
void LogWindow::WarningsToggled(bool value)
{
SetFilter(ILogger::eSeverity_Warning, value);
}
void LogWindow::InfoToggled(bool value)
{
SetFilter(ILogger::eSeverity_Info, value);
}
void LogWindow::DebugToggled(bool value)
{
SetFilter(ILogger::eSeverity_Debug, value);
}
void LogWindow::RefillList()
{
m_list.Clear();
for (int messageIndex = 0, messageCount = int(m_messages.size()); messageIndex < messageCount; ++messageIndex)
{
if (m_filterFlags & (1 << m_messages[messageIndex].severity))
{
m_list.Add(GetImageIndex(m_messages[messageIndex].severity), m_messages[messageIndex].message.c_str());
}
}
}
int LogWindow::GetImageIndex(ILogger::ESeverity eSeverity)
{
switch (eSeverity)
{
case ILogger::eSeverity_Debug:
return 2;
case ILogger::eSeverity_Info:
return -1;
case ILogger::eSeverity_Warning:
return 1;
case ILogger::eSeverity_Error:
return 0;
default:
return 0;
}
}
int LogWindow::GetSeverityIndex(ILogger::ESeverity eSeverity)
{
switch (eSeverity)
{
case ILogger::eSeverity_Debug:
return 0;
case ILogger::eSeverity_Info:
return 1;
case ILogger::eSeverity_Warning:
return 2;
case ILogger::eSeverity_Error:
return 3;
default:
return 3;
}
}
-71
View File
@@ -1,71 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_LOGWINDOW_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_LOGWINDOW_H
#pragma once
#include "IUIComponent.h"
#include "Layout.h"
#include "ListView.h"
#include "ToggleButton.h"
#include <list>
#include "ILogger.h"
class LogWindow
: public IUIComponent
{
public:
LogWindow();
~LogWindow();
void Log(ILogger::ESeverity eSeverity, const TCHAR* message);
void SetFilter(ILogger::ESeverity eSeverity, bool visible);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
struct LogMessage
{
LogMessage(ILogger::ESeverity severity, tstring message)
: severity(severity)
, message(message)
{
}
ILogger::ESeverity severity;
tstring message;
};
void ErrorsToggled(bool value);
void WarningsToggled(bool value);
void InfoToggled(bool value);
void DebugToggled(bool value);
void RefillList();
static int GetImageIndex(ILogger::ESeverity eSeverity);
static int GetSeverityIndex(ILogger::ESeverity eSeverity);
Layout m_mainLayout;
Layout m_toolbarLayout;
ListView m_list;
std::vector<ToggleButton*> m_buttons;
std::vector<LogMessage> m_messages;
unsigned m_filterFlags;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_LOGWINDOW_H
@@ -1,65 +0,0 @@
/*
* 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 "StdAfx.h"
#include "ProgressBar.h"
#include <Windows.h>
#include <CommCtrl.h>
ProgressBar::ProgressBar()
: m_progressBar(0)
{
}
void ProgressBar::CreateUI(void* window, int left, int top, int width, int height)
{
m_progressBar = CreateWindowEx(
0,
PROGRESS_CLASS,
0,
WS_CHILD | WS_VISIBLE,
left,
top,
width,
height,
(HWND)window,
(HMENU)0,
GetModuleHandle(0),
0);
SendMessage((HWND)m_progressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
SendMessage((HWND)m_progressBar, PBM_SETSTEP, (WPARAM) 1, 0);
}
void ProgressBar::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_progressBar, left, top, width, height, true);
}
void ProgressBar::DestroyUI(void* window)
{
DestroyWindow((HWND)m_progressBar);
}
void ProgressBar::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 200;
maxWidth = 2000;
minHeight = 30;
maxHeight = 30;
}
void ProgressBar::SetProgress(float progress)
{
int newPos = int(progress * 1000.0f);
SendMessage((HWND)m_progressBar, PBM_SETPOS, newPos, 0);
}
@@ -1,39 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_PROGRESSBAR_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_PROGRESSBAR_H
#pragma once
#include "IUIComponent.h"
class ProgressBar
: public IUIComponent
{
public:
ProgressBar();
void SetProgress(float progress);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
void* m_progressBar;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_PROGRESSBAR_H
@@ -1,64 +0,0 @@
/*
* 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 "StdAfx.h"
#include "PushButton.h"
#include "Win32GUI.h"
PushButton::~PushButton()
{
m_callback->Release();
}
void PushButton::Enable(bool enabled)
{
m_enabled = enabled;
EnableWindow((HWND)m_button, m_enabled);
}
void PushButton::CreateUI(void* window, int left, int top, int width, int height)
{
m_button = Win32GUI::CreateControl(_T("BUTTON"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, (HWND)window, left, top, 40, 20);
m_font = Win32GUI::CreateFont();
SendMessage((HWND)m_button, WM_SETFONT, (WPARAM)m_font, 0);
SendMessage((HWND)m_button, WM_SETTEXT, 0, (LPARAM)m_text.c_str());
EnableWindow((HWND)m_button, m_enabled);
Win32GUI::SetCallback<Win32GUI::EventCallbacks::Pushed, PushButton>((HWND)m_button, this, &PushButton::OnPushed);
}
void PushButton::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_button, left, top, width, height, true);
}
void PushButton::DestroyUI(void* window)
{
DestroyWindow((HWND)m_button);
m_button = 0;
DeleteObject(m_font);
m_font = 0;
}
void PushButton::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 50;
maxWidth = 50;
minHeight = 20;
maxHeight = 20;
}
void PushButton::OnPushed()
{
m_callback->Call();
}
-78
View File
@@ -1,78 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_PUSHBUTTON_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_PUSHBUTTON_H
#pragma once
#include "IUIComponent.h"
#include <string>
class PushButton
: public IUIComponent
{
public:
template <typename T>
PushButton(const TCHAR* text, T* object, void (T::* method)());
~PushButton();
void Enable(bool enabled);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
PushButton(const PushButton&);
PushButton& operator=(const PushButton&);
struct ICallback
{
virtual void Release() = 0;
virtual void Call() = 0;
};
template <typename T>
struct Callback
: public ICallback
{
Callback(T* object, void (T::* method)())
: object(object)
, method(method) {}
virtual void Release() {delete this; }
virtual void Call() {(object->*method)(); }
T* object;
void (T::* method)();
};
void OnPushed();
std::basic_string<TCHAR> m_text;
void* m_button;
void* m_font;
ICallback* m_callback;
bool m_enabled;
};
template <typename T>
PushButton::PushButton(const TCHAR* text, T* object, void (T::* method)())
: m_text(text)
, m_callback(new Callback<T>(object, method))
, m_enabled(true)
{
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_PUSHBUTTON_H
-43
View File
@@ -1,43 +0,0 @@
/*
* 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 "StdAfx.h"
#include "Spacer.h"
Spacer::Spacer(int minWidth, int minHeight, int maxWidth, int maxHeight)
: m_minWidth(minWidth)
, m_minHeight(minHeight)
, m_maxWidth(maxWidth)
, m_maxHeight(maxHeight)
{
}
void Spacer::CreateUI(void* window, int left, int top, int width, int height)
{
}
void Spacer::Resize(void* window, int left, int top, int width, int height)
{
}
void Spacer::DestroyUI(void* window)
{
}
void Spacer::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = m_minWidth;
maxWidth = m_maxWidth;
minHeight = m_minHeight;
maxHeight = m_maxHeight;
}
-40
View File
@@ -1,40 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_SPACER_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_SPACER_H
#pragma once
#include "IUIComponent.h"
class Spacer
: public IUIComponent
{
public:
Spacer(int minWidth, int minHeight, int maxWidth, int maxHeight);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
int m_minWidth;
int m_minHeight;
int m_maxWidth;
int m_maxHeight;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_SPACER_H
-148
View File
@@ -1,148 +0,0 @@
/*
* 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 "StdAfx.h"
#include "TaskList.h"
#include "Win32GUI.h"
#include <Windows.h>
#include <CommCtrl.h>
#include <Richedit.h>
#include <cstdlib>
TaskList::TaskList()
: m_edit(0)
{
}
void TaskList::AddTask(const std::string& id, const std::string description)
{
int taskIndex = int(m_tasks.size());
m_tasks.push_back(std::make_pair(id, description));
m_idTaskMap.insert(std::make_pair(id, taskIndex));
}
void TaskList::SetCurrentTask(const std::string& id)
{
SetText(id);
}
void TaskList::SetColor()
{
SendMessage((HWND)m_edit, EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_3DFACE));
}
void TaskList::SetText(const std::string& highlightedTask)
{
PARAFORMAT2 paragraphFormat;
std::memset(&paragraphFormat, 0, sizeof(paragraphFormat));
paragraphFormat.cbSize = sizeof(paragraphFormat);
paragraphFormat.dwMask = PFM_LINESPACING | PFM_SPACEBEFORE;
paragraphFormat.bLineSpacingRule = 5; // Specify spacing in 20ths of a line.
paragraphFormat.dyLineSpacing = 22;
paragraphFormat.dySpaceBefore = 70;
SendMessage((HWND)m_edit, EM_SETPARAFORMAT, 0, (LPARAM)&paragraphFormat);
CHARFORMAT format;
std::memset(&format, 0, sizeof(format));
format.cbSize = sizeof(format);
format.dwMask = CFM_BOLD;
format.dwEffects = 0;
SendMessage((HWND)m_edit, EM_SETCHARFORMAT, 0, (LPARAM)&format);
SETTEXTEX textEx;
std::memset(&textEx, 0, sizeof(textEx));
textEx.flags = ST_DEFAULT;
textEx.codepage = CP_ACP;
SendMessage((HWND)m_edit, EM_SETTEXTEX, (WPARAM)&textEx, (LPARAM)_T(""));
int highlightedLineStart = 0;
int highlightedLineEnd = 0;
for (std::vector<std::pair<std::string, std::string> >::const_iterator taskPos = m_tasks.begin(), taskEnd = m_tasks.end(); taskPos != taskEnd; ++taskPos)
{
textEx.flags = ST_SELECTION;
const std::string& id = (*taskPos).first;
const std::string& description = (*taskPos).second;
const char* margin = " ";
if (highlightedTask == id)
{
margin = "* ";
CHARRANGE range;
SendMessage((HWND)m_edit, EM_EXGETSEL, 0, (LPARAM)&range);
highlightedLineStart = range.cpMin;
}
SendMessageA((HWND)m_edit, EM_SETTEXTEX, (WPARAM)&textEx, (LPARAM)margin);
SendMessageA((HWND)m_edit, EM_SETTEXTEX, (WPARAM)&textEx, (LPARAM)description.c_str());
SendMessageA((HWND)m_edit, EM_SETTEXTEX, (WPARAM)&textEx, (LPARAM)"\n");
if (highlightedTask == id)
{
CHARRANGE range;
SendMessage((HWND)m_edit, EM_EXGETSEL, 0, (LPARAM)&range);
highlightedLineEnd = range.cpMin;
}
}
CHARRANGE range = {highlightedLineStart, highlightedLineEnd};
SendMessage((HWND)m_edit, EM_EXSETSEL, 0, (LPARAM)&range);
format.dwEffects = CFE_BOLD;
SendMessage((HWND)m_edit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&format);
range.cpMin = 0;
range.cpMax = 0;
SendMessage((HWND)m_edit, EM_EXSETSEL, 0, (LPARAM)&range);
}
void TaskList::CreateUI(void* window, int left, int top, int width, int height)
{
// Create the window.
LoadLibrary(_T("Riched20.dll"));
m_edit = CreateWindowEx(
0, //DWORD dwExStyle,
RICHEDIT_CLASS, //LPCTSTR lpClassName,
0, //LPCTSTR lpWindowName,
WS_CHILD | WS_VISIBLE | ES_LEFT | ES_MULTILINE | ES_READONLY, //DWORD dwStyle,
left, //int x,
top, //int y,
width, //int nWidth,
height, //int nHeight,
(HWND)window, //HWND hWndParent,
0, //HMENU hMenu,
GetModuleHandle(0), //HINSTANCE hInstance,
0); //LPVOID lpParam);
HFONT font = Win32GUI::CreateFont();
SendMessage((HWND)m_edit, WM_SETFONT, (WPARAM)font, 0);
DeleteObject(font);
SetColor();
SetText("");
}
void TaskList::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_edit, left, top, width, height, true);
}
void TaskList::DestroyUI(void* window)
{
DestroyWindow((HWND)m_edit);
m_edit = 0;
}
void TaskList::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 10;
maxWidth = 2000;
int height = 25 * int(m_tasks.size());
minHeight = height;
maxHeight = height;
}
-48
View File
@@ -1,48 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_TASKLIST_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_TASKLIST_H
#pragma once
#include "IUIComponent.h"
#include <map>
#include <vector>
#include <string>
class TaskList
: public IUIComponent
{
public:
TaskList();
void AddTask(const std::string& id, const std::string description);
void SetCurrentTask(const std::string& id);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
void SetColor();
void SetText(const std::string& highlightedTask);
std::map<std::string, int> m_idTaskMap;
std::vector<std::pair<std::string, std::string> > m_tasks;
void* m_edit;
};
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_TASKLIST_H
@@ -1,65 +0,0 @@
/*
* 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 "StdAfx.h"
#include "ToggleButton.h"
#include "Win32GUI.h"
ToggleButton::~ToggleButton()
{
m_callback->Release();
}
void ToggleButton::SetState(bool state)
{
m_state = state;
SendMessage((HWND)m_button, BM_SETCHECK, m_state, 0);
}
void ToggleButton::CreateUI(void* window, int left, int top, int width, int height)
{
m_button = Win32GUI::CreateControl(_T("BUTTON"), WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_NOTIFY | BS_PUSHLIKE, (HWND)window, left, top, 40, 20);
m_font = Win32GUI::CreateFont();
SendMessage((HWND)m_button, WM_SETFONT, (WPARAM)m_font, 0);
SendMessage((HWND)m_button, WM_SETTEXT, 0, (LPARAM)m_text.c_str());
SendMessage((HWND)m_button, BM_SETCHECK, m_state, 0);
Win32GUI::SetCallback<Win32GUI::EventCallbacks::Checked, ToggleButton>((HWND)m_button, this, &ToggleButton::OnChecked);
}
void ToggleButton::Resize(void* window, int left, int top, int width, int height)
{
MoveWindow((HWND)m_button, left, top, width, height, true);
}
void ToggleButton::DestroyUI(void* window)
{
DestroyWindow((HWND)m_button);
m_button = 0;
DeleteObject(m_font);
m_font = 0;
}
void ToggleButton::GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight)
{
minWidth = 50;
maxWidth = 50;
minHeight = 20;
maxHeight = 20;
}
void ToggleButton::OnChecked(bool checked)
{
m_state = checked;
m_callback->Call(checked);
}
@@ -1,78 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_TOGGLEBUTTON_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_TOGGLEBUTTON_H
#pragma once
#include "IUIComponent.h"
#include <string>
class ToggleButton
: public IUIComponent
{
public:
template <typename T>
ToggleButton(const TCHAR* text, T* object, void (T::* method)(bool value));
~ToggleButton();
void SetState(bool value);
// IUIComponent
virtual void CreateUI(void* window, int left, int top, int width, int height);
virtual void Resize(void* window, int left, int top, int width, int height);
virtual void DestroyUI(void* window);
virtual void GetExtremeDimensions(void* window, int& minWidth, int& maxWidth, int& minHeight, int& maxHeight);
private:
ToggleButton(const ToggleButton&);
ToggleButton& operator=(const ToggleButton);
struct ICallback
{
virtual void Release() = 0;
virtual void Call(bool value) = 0;
};
template <typename T>
struct Callback
: public ICallback
{
Callback(T* object, void (T::* method)(bool value))
: object(object)
, method(method) {}
virtual void Release() {delete this; }
virtual void Call(bool value) {(object->*method)(value); }
T* object;
void (T::* method)(bool value);
};
void OnChecked(bool checked);
tstring m_text;
void* m_button;
void* m_font;
bool m_state;
ICallback* m_callback;
};
template <typename T>
ToggleButton::ToggleButton(const TCHAR* text, T* object, void (T::* method)(bool value))
: m_text(text)
, m_state(false)
, m_callback(new Callback<T>(object, method))
{
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_TOGGLEBUTTON_H
-390
View File
@@ -1,390 +0,0 @@
/*
* 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 "StdAfx.h"
#include "Win32GUI.h"
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include "commctrl.h"
#include "StringHelpers.h"
namespace Win32GUI
{
const int WM_REFLECT_BASE = WM_USER + 0x1c00;
const int WM_COMMAND_REFLECT = WM_REFLECT_BASE + WM_COMMAND;
const int WM_NOTIFY_REFLECT = WM_REFLECT_BASE + WM_NOTIFY;
class Window
{
public:
typedef LRESULT (Window::* WindowProcMethod)(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Window(WindowProcMethod windowProc);
~Window();
static LRESULT CALLBACK StaticWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT FrameWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void Subclass(HWND window);
void Unsubclass(HWND window);
WNDPROC m_oldWndProc;
WindowProcMethod m_windowProc;
typedef std::multimap<unsigned, EventCallbacks::ICallback*> CallbackMap;
CallbackMap m_callbackMap;
};
}
void Win32GUI::Initialize()
{
InitCommonControls();
LoadLibrary(_T("riched20.dll"));
}
void Win32GUI::RegisterFrameClass(const TCHAR* name)
{
WNDCLASS cls;
std::memset(&cls, 0, sizeof(cls));
cls.style = 0;
cls.lpfnWndProc = &Window::StaticWindowProc;
cls.cbClsExtra = 0;
cls.cbWndExtra = 0;
cls.hInstance = GetModuleHandle(0);
cls.hIcon = 0;
cls.hCursor = LoadCursor(0, IDC_ARROW);
cls.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
cls.lpszMenuName = 0;
cls.lpszClassName = name;
RegisterClass(&cls);
}
HWND Win32GUI::CreateFrame(const TCHAR* className, unsigned style, int width, int height)
{
Window* window = new Window(&Window::FrameWindowProc);
HWND hwnd = CreateWindow(
className, // LPCTSTR lpClassName,
TEXT(""), // LPCTSTR lpWindowName,
style, // DWORD dwStyle,
CW_USEDEFAULT, // int x,
CW_USEDEFAULT, // int y,
width, // int nWidth,
height, // int nHeight,
0, // HWND hWndParent,
0, // HMENU hMenu,
GetModuleHandle(0), // HINSTANCE hInstance,
window); // LPVOID lpParam
return hwnd;
}
HWND Win32GUI::CreateControl(const TCHAR* className, unsigned style, HWND parent, int left, int top, int width, int height)
{
Window* window = new Window(&Window::WindowProc);
HWND hwnd = CreateWindow(
className, // LPCTSTR lpClassName,
0, // LPCTSTR lpWindowName,
style | WS_CHILD | WS_VISIBLE, // DWORD dwStyle,
left, // int x,
top, // int y,
width, // int nWidth,
height, // int nHeight,
parent, // HWND hWndParent,
0, // HMENU hMenu,
GetModuleHandle(0), // HINSTANCE hInstance,
0); // LPVOID lpParam
window->Subclass(hwnd);
return hwnd;
}
int Win32GUI::Run()
{
MSG msg;
BOOL status;
while ((status = GetMessage(&msg, HWND(0), UINT(0), UINT(0))) != 0)
{
if (status == -1)
{
return -1;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
Win32GUI::Window::Window(WindowProcMethod windowProc)
: m_windowProc(windowProc)
, m_oldWndProc(0)
{
}
Win32GUI::Window::~Window()
{
for (CallbackMap::iterator callbackPos = m_callbackMap.begin(); callbackPos != m_callbackMap.end(); ++callbackPos)
{
(*callbackPos).second->Release();
}
}
LRESULT CALLBACK Win32GUI::Window::StaticWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
Window* window = 0;
{
if (uMsg == WM_CREATE)
{
CREATESTRUCT* create_struct = (CREATESTRUCT*)lParam;
window = (Window*)create_struct->lpCreateParams;
#if defined(_WIN64)
SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(window));
#else //defined(_WIN64)
SetWindowLong(hwnd, GWL_USERDATA, PtrToLong(window));
#endif //defined(_WIN64)
}
else
{
#if defined(_WIN64)
window = (Window*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
#else //defined(_WIN64)
window = (Window*)LongToPtr(GetWindowLong(hwnd, GWL_USERDATA));
#endif //defined(_WIN64)
}
}
LRESULT result = 0;
if (window)
{
result = (window->*(window->m_windowProc))(hwnd, uMsg, wParam, lParam);
}
else
{
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
}
if (uMsg == WM_DESTROY)
{
delete window;
#if defined(_WIN64)
SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
#else //defined(_WIN64)
SetWindowLong(hwnd, GWL_USERDATA, 0);
#endif //defined(_WIN64)
}
return result;
}
LRESULT Win32GUI::Window::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
{
HWND control = (HWND)lParam;
if (control)
{
SendMessage(control, WM_COMMAND_REFLECT, wParam, lParam);
}
}
break;
case WM_NOTIFY:
{
NMHDR* notify_header = reinterpret_cast<NMHDR*>(lParam);
if (notify_header->hwndFrom)
{
SendMessage(notify_header->hwndFrom, WM_NOTIFY_REFLECT, wParam, lParam);
}
}
break;
case WM_COMMAND_REFLECT:
switch (HIWORD(wParam))
{
case EN_CHANGE:
{
std::string text = GetWindowString(hwnd);
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::TextChanged::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::IStringCallback* callback = static_cast<EventCallbacks::IStringCallback*>((*callbackPos).second);
callback->Call(text);
}
}
break;
case BN_CLICKED:
{
if (GetWindowLong(hwnd, GWL_STYLE) & BS_CHECKBOX)
{
bool checked = (0 != SendMessage(hwnd, BM_GETCHECK, 0, 0));
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::Checked::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::IBoolCallback* callback = static_cast<EventCallbacks::IBoolCallback*>((*callbackPos).second);
callback->Call(checked);
}
}
else
{
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::Pushed::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::IVoidCallback* callback = static_cast<EventCallbacks::IVoidCallback*>((*callbackPos).second);
callback->Call();
}
}
}
break;
}
break;
case WM_GETMINMAXINFO:
{
int minW = 0, maxW = 0, minH = 100000, maxH = 100000;
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::GetDimensions::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::IGetDimensionsCallback* callback = static_cast<EventCallbacks::IGetDimensionsCallback*>((*callbackPos).second);
callback->Call(minW, maxW, minH, maxH);
}
MINMAXINFO* minMaxInfo = (MINMAXINFO*)lParam;
minMaxInfo->ptMinTrackSize.x = minW;
minMaxInfo->ptMaxTrackSize.x = maxW;
minMaxInfo->ptMinTrackSize.y = minH;
minMaxInfo->ptMaxTrackSize.y = maxH;
}
break;
case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
std::pair<CallbackMap::iterator, CallbackMap::iterator> range = m_callbackMap.equal_range(EventCallbacks::SizeChanged::ID);
for (CallbackMap::iterator callbackPos = range.first; callbackPos != range.second; ++callbackPos)
{
EventCallbacks::ISizeCallback* callback = static_cast<EventCallbacks::ISizeCallback*>((*callbackPos).second);
callback->Call(width, height);
}
}
break;
case WM_NOTIFY_REFLECT:
break;
}
LRESULT result = 0;
if (m_oldWndProc)
{
result = CallWindowProc(m_oldWndProc, hwnd, uMsg, wParam, lParam);
}
else
{
result = DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return result;
}
LRESULT Win32GUI::Window::FrameWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
}
return WindowProc(hwnd, uMsg, wParam, lParam);
}
void Win32GUI::Window::Subclass(HWND window)
{
#if defined(_WIN64)
SetWindowLongPtr(window, GWLP_USERDATA, LONG_PTR(this));
m_oldWndProc = (WNDPROC)GetWindowLongPtr(window, GWLP_WNDPROC);
SetWindowLongPtr(window, GWLP_WNDPROC, LONG_PTR(&Window::StaticWindowProc));
#else //defined(_WIN64)
SetWindowLong(window, GWL_USERDATA, PtrToLong(this));
m_oldWndProc = (WNDPROC)LongToPtr(GetWindowLong(window, GWL_WNDPROC));
SetWindowLong(window, GWL_WNDPROC, PtrToLong(&Window::StaticWindowProc));
#endif //defined(_WIN64)
}
void Win32GUI::Window::Unsubclass(HWND window)
{
#if defined(_WIN64)
SetWindowLongPtr(window, GWLP_USERDATA, 0);
SetWindowLongPtr(window, GWLP_WNDPROC, LONG_PTR(m_oldWndProc));
#else //defined(_WIN64)
SetWindowLongPtr(window, GWL_USERDATA, 0);
SetWindowLong(window, GWLP_WNDPROC, PtrToLong(m_oldWndProc));
#endif //defined(_WIN64)
m_oldWndProc = 0;
}
std::string Win32GUI::GetWindowString(HWND hwnd)
{
LRESULT length = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0);
std::wstring wtext(length, 0);
SendMessageW(hwnd, WM_GETTEXT, length + 1, (LPARAM)&wtext[0]);
return StringHelpers::ConvertUtf16ToAnsi(wtext.c_str(), '?');
}
void Win32GUI::SetWindowString(HWND hwnd, const std::string& text)
{
std::wstring wtext = StringHelpers::ConvertAnsiToUtf16(text.c_str());
SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)&wtext[0]);
}
HFONT Win32GUI::CreateFont()
{
HFONT hFont = 0;
HFONT hGuiFont = static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT));
LOGFONT lfGuiFont = { 0 };
if (::GetObject(hGuiFont, sizeof(LOGFONT), &lfGuiFont) == sizeof(LOGFONT))
{
_tcsncpy(lfGuiFont.lfFaceName, _T("MS Shell Dlg 2"), sizeof(lfGuiFont.lfFaceName) / sizeof(TCHAR));
lfGuiFont.lfFaceName[(sizeof(lfGuiFont.lfFaceName) / sizeof(TCHAR)) - 1] = '\0';
hFont = ::CreateFontIndirect(&lfGuiFont);
return hFont;
}
return 0;
}
void Win32GUI::SetCallbackObject(HWND hwnd, unsigned eventID, EventCallbacks::ICallback* callback)
{
#if defined(_WIN64)
Window* window = (Window*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
#else //defined(_WIN64)
Window* window = (Window*)LongToPtr(GetWindowLong(hwnd, GWL_USERDATA));
#endif //defined(_WIN64)
window->m_callbackMap.insert(std::make_pair(eventID, callback));
}
-216
View File
@@ -1,216 +0,0 @@
/*
* 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.
#ifndef CRYINCLUDE_CRYCOMMONTOOLS_UI_WIN32GUI_H
#define CRYINCLUDE_CRYCOMMONTOOLS_UI_WIN32GUI_H
#pragma once
#include <Windows.h>
#include <string>
namespace Win32GUI
{
void Initialize();
void RegisterFrameClass(const TCHAR* name);
HWND CreateFrame(const TCHAR* className, unsigned style, int width, int height);
HWND CreateControl(const TCHAR* className, unsigned style, HWND parent, int left, int top, int width, int height);
int Run();
std::string GetWindowString(HWND hwnd);
void SetWindowString(HWND hwnd, const std::string& text);
HFONT CreateFont();
namespace EventCallbacks
{
class ICallback
{
public:
virtual ~ICallback() {}
virtual void Release() = 0;
};
struct IVoidCallback
: public ICallback
{
virtual void Call() = 0;
};
struct VoidCallback
{
template <typename O>
struct Callback
: public IVoidCallback
{
typedef void (O::* Signature)();
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call() {(m_object->*m_method)(); }
O* m_object;
Signature m_method;
};
};
struct IStringCallback
: public ICallback
{
virtual void Call(const std::string& text) = 0;
};
struct StringCallback
{
template <typename O>
struct Callback
: public IStringCallback
{
typedef void (O::* Signature)(const std::string& text);
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call(const std::string& text) {(m_object->*m_method)(text); }
O* m_object;
Signature m_method;
};
};
struct IGetDimensionsCallback
: public ICallback
{
virtual void Call(int& minW, int& maxW, int& minH, int& maxH) = 0;
};
struct GetDimensionsCallback
{
template <typename O>
struct Callback
: public IGetDimensionsCallback
{
typedef void (O::* Signature)(int& minW, int& maxW, int& minH, int& maxH);
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call(int& minW, int& maxW, int& minH, int& maxH) {(m_object->*m_method)(minW, maxW, minH, maxH); }
O* m_object;
Signature m_method;
};
};
struct ISizeCallback
: public ICallback
{
virtual void Call(int width, int height) = 0;
};
struct SizeCallback
{
template <typename O>
struct Callback
: public ISizeCallback
{
typedef void (O::* Signature)(int width, int height);
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call(int width, int height) {(m_object->*m_method)(width, height); }
O* m_object;
Signature m_method;
};
};
struct IBoolCallback
: public ICallback
{
virtual void Call(bool value) = 0;
};
struct BoolCallback
{
template <typename O>
struct Callback
: public IBoolCallback
{
typedef void (O::* Signature)(bool callback);
Callback(O* object, Signature method)
: m_object(object)
, m_method(method) {}
virtual void Release() {delete this; }
virtual void Call(bool value) {(m_object->*m_method)(value); }
O* m_object;
Signature m_method;
};
};
struct TextChanged
: public StringCallback
{
enum
{
ID = 0x00005001
};
};
struct GetDimensions
: public GetDimensionsCallback
{
enum
{
ID = 0x00005002
};
};
struct SizeChanged
: public SizeCallback
{
enum
{
ID = 0x00005003
};
};
struct Pushed
: public VoidCallback
{
enum
{
ID = 0x00005004
};
};
struct Checked
: public BoolCallback
{
enum
{
ID = 0x00005005
};
};
};
void SetCallbackObject(HWND hwnd, unsigned eventID, EventCallbacks::ICallback* callback);
template <typename T, typename O>
inline void SetCallback(HWND hwnd, O* object, typename T::template Callback<O>::Signature method);
}
template <typename T, typename O>
inline void Win32GUI::SetCallback(HWND hwnd, O* object, typename T::template Callback<O>::Signature method)
{
typedef T::template Callback<O> Callback;
Callback* callback = new Callback(object, method);
SetCallbackObject(hwnd, T::ID, callback);
}
#endif // CRYINCLUDE_CRYCOMMONTOOLS_UI_WIN32GUI_H