summaryrefslogtreecommitdiff
path: root/Editor/GUI/EditorWindows.cpp
blob: 00c573a3426ec5c30aa06368796c0eacbcb0c70d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "EditorWindows.h"
#include "WinUtils.h"

static const wchar_t* kContainerWindowClassName = L"GameLabContainerWndClass";
static const wchar_t* kPopupWindowClassName = L"GameLabPopupWndClass";
static const wchar_t* kViewportClassName = L"GameLabViewportWndClass";
static const char* kIsMainWindowMaximized = "IsMainWindowMaximized";

static ATOM s_ContainerWindowClassAtom;
static ATOM s_PopupWindowClassAtom;
static ATOM s_GUIViewClassAtom;

void RegisterWindowClasses()
{
    s_ContainerWindowClassAtom = winutils::RegisterWindowClass(kContainerWindowClassName, ContainnerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW);
    s_PopupWindowClassAtom = winutils::RegisterWindowClass(kPopupWindowClassName, ContainnerWindow::ContainerWndProc, CS_HREDRAW | CS_VREDRAW | CS_DROPSHADOW);//CS_HREDRAW宽度(水平)变化时重绘、CS_VREDRAW高度(垂直)变化时重绘
    s_GUIViewClassAtom = winutils::RegisterWindowClass(kViewportClassName, GUIView::GUIViewWndProc, CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS);
}

LRESULT CALLBACK ContainnerWindow::ContainerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    long flag = DefWindowProcW(hWnd, message, wParam, lParam);
    return flag;
}

ContainnerWindow::ContainnerWindow()
{
}


ContainnerWindow::~ContainnerWindow()
{

}

void ContainnerWindow::Init(Rectf pixelRect, int showMode, const Vector2f& minSize, const Vector2f& maxSize)
{
    // Aux windows are mac only. on windows they look just like normal utility windows.
    if (showMode == kShowAuxWindow)
        showMode = kShowUtility;

    m_ShowMode = static_cast<ShowMode>(showMode);
    m_IsClosing = false;
    m_InMenuLoop = false;
    m_CloseFromScriptDontShutdown = false;

    bool shouldMaximize = false;
    if (showMode == kShowMainWindow)
    {
        //shouldMaximize = s_IsMainWindowMaximized = EditorPrefs::GetBool(kIsMainWindowMaximized, false);
        //GetRestoredMainWindowDimensions();
    }

    RECT rect = { 120, 120, 220, 220 };
    m_InternalRect.x = m_InternalRect.y = m_InternalRect.width = m_InternalRect.height = 0.0f;

    DWORD windowStyle = 0;
    DWORD extendedStyle = 0;
    LPCWSTR windowClass = kContainerWindowClassName;

    switch (showMode) {
        // 容纳GUIPanel的非主窗口
    case kShowNormalWindow:
        windowStyle = WS_POPUP | WS_CLIPCHILDREN | WS_THICKFRAME;
        extendedStyle = WS_EX_TOOLWINDOW;
        break;
        // 主窗口,含菜单
    case kShowMainWindow:
        windowStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
        extendedStyle = 0;
        break;
    case kShowPopupMenu:
        windowStyle = WS_POPUP | WS_CLIPCHILDREN;
        extendedStyle = WS_EX_TOOLWINDOW;
        windowClass = kPopupWindowClassName;
        break;
    case kShowNoShadow:
        windowStyle = WS_POPUP | WS_CLIPCHILDREN;
        extendedStyle = WS_EX_TOOLWINDOW;
        break;
    case kShowUtility:
        windowStyle = WS_POPUP | WS_CAPTION | WS_THICKFRAME | WS_SYSMENU;
        extendedStyle = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW;
        break;
    default:
      // ErrorString("Unknown container show mode");
        break;
    }

    HWND parentWindow = NULL;
    if (showMode == kShowMainWindow)
    {
        parentWindow = NULL;
    }
    else
    {
 //       parentWindow = GetMainEditorWindow();
    }

    bool notSizeable = (minSize == maxSize) && (minSize != Vector2f::zero);
    if (notSizeable)
        windowStyle &= ~(WS_THICKFRAME);

    AdjustWindowRectEx(&rect, windowStyle, showMode == kShowMainWindow, extendedStyle);
    int extraX = rect.right - rect.left - 200;
    int extraY = rect.bottom - rect.top - 200;

    m_MinSize.x = minSize.x + extraX;
    m_MinSize.y = minSize.y + extraY;
    m_MaxSize.x = maxSize.x + extraX;
    m_MaxSize.y = maxSize.y + extraY;


    //if (showMode == kShowUtility)
    //    s_ZUtilityWindows.push_back(m_ContainerListNode);
    // Create window
    m_Window = CreateWindowExW(
        extendedStyle, 
        windowClass, 
        L"", 
        windowStyle,
        rect.left, 
        rect.top, 
        rect.right - rect.left, 
        rect.bottom - rect.top,
        parentWindow, 
        NULL, 
        winutils::GetInstanceHandle(), 
        NULL
    );
    SetWindowLongPtr(m_Window, GWLP_USERDATA, (LONG_PTR)this);
    //UpdateMaxMaximizedRect();

    if (pixelRect.width > 10 || pixelRect.height > 10)
    {
        //SetRect(pixelRect);
        if (shouldMaximize)
            SetWindowLong(m_Window, GWL_STYLE, windowStyle | WS_MAXIMIZE);
    }


    if (showMode == kShowMainWindow)
    {
        //SetMainEditorWindow(m_Window);
        //HMENU menu = GetMainMenuHandle();
        //if (menu)
        //    SetMenu(m_Window, menu);
        //GetApplication().UpdateMainWindowTitle();
        //GetApplication().UpdateDocumentEdited();
    }
    ShowWindow(m_Window, SW_SHOW);

    //s_ContainerWindows.insert(this);

    //ShowInTaskbarIfNoMainWindow(m_Window);

}

//------------------------------------------------------------------------------------------------------------------

LRESULT CALLBACK GUIView::GUIViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    long flag = DefWindowProcW(hWnd, message, wParam, lParam);
    return flag;
}

void GUIView::DoPaint()
{

}