mirror of
https://github.com/isledecomp/LEGOIslandRebuilder.git
synced 2025-02-17 00:20:40 -05:00
started constructing UI
This commit is contained in:
parent
439a2df101
commit
552cebbe90
3 changed files with 97 additions and 3 deletions
|
@ -2,12 +2,19 @@ cmake_minimum_required(VERSION 3.5)
|
|||
|
||||
project(Rebuilder LANGUAGES CXX)
|
||||
|
||||
add_definitions(-D_AFXDLL)
|
||||
set(CMAKE_MFC_FLAG 2)
|
||||
|
||||
option(BUILD_UNICODE "Build with Unicode support" ON)
|
||||
|
||||
add_executable(Rebuilder WIN32
|
||||
src/app.cpp
|
||||
src/app.h
|
||||
src/window.cpp
|
||||
src/window.h
|
||||
)
|
||||
|
||||
target_compile_definitions(Rebuilder PRIVATE _AFXDLL)
|
||||
if (BUILD_UNICODE)
|
||||
target_compile_definitions(Rebuilder PRIVATE UNICODE _UNICODE)
|
||||
target_link_options(Rebuilder PRIVATE /entry:wWinMainCRTStartup)
|
||||
endif()
|
||||
|
|
|
@ -1,8 +1,76 @@
|
|||
#include "window.h"
|
||||
|
||||
#define super CFrameWnd
|
||||
|
||||
CRebuilderWindow::CRebuilderWindow()
|
||||
{
|
||||
Create(NULL, "LEGO Island Rebuilder");
|
||||
SetWindowPos(NULL, 0, 0, 420, 420, 0);
|
||||
// Declare default width/height
|
||||
static const UINT defaultWindowWidth = 420;
|
||||
static const UINT defaultWindowHeight = 420;
|
||||
|
||||
// Create form
|
||||
Create(NULL, _T("LEGO Island Rebuilder"));
|
||||
|
||||
// Get default Win32 dialog font
|
||||
m_fDialogFont.CreateStockObject(DEFAULT_GUI_FONT);
|
||||
|
||||
// Create bolded variant of the above
|
||||
LOGFONT lf;
|
||||
m_fDialogFont.GetLogFont(&lf);
|
||||
lf.lfWeight = FW_BOLD;
|
||||
m_fBoldDialogFont.CreateFontIndirect(&lf);
|
||||
|
||||
// Get information about font height for layout
|
||||
HDC hDC = ::GetDC(NULL);
|
||||
HGDIOBJ hFontOld = SelectObject(hDC, m_fDialogFont.GetSafeHandle());
|
||||
TEXTMETRIC tm;
|
||||
GetTextMetrics(hDC, &tm);
|
||||
m_nFontHeight = tm.tmHeight + tm.tmExternalLeading;
|
||||
SelectObject(hDC, hFontOld);
|
||||
::ReleaseDC(NULL, hDC);
|
||||
|
||||
// Create title
|
||||
m_cTopLevelTitle.Create(_T("LEGO Island Rebuilder"), WS_CHILD | WS_VISIBLE | SS_CENTER, CRect(), this);
|
||||
m_cTopLevelTitle.SetFont(&m_fBoldDialogFont);
|
||||
|
||||
// Create subtitle
|
||||
m_cTopLevelSubtitle.Create(_T("by MattKC (itsmattkc.com)"), WS_CHILD | WS_VISIBLE | SS_CENTER, CRect(), this);
|
||||
m_cTopLevelSubtitle.SetFont(&m_fDialogFont);
|
||||
|
||||
// Create run button
|
||||
m_cRunBtn.Create(_T("Run"), WS_CHILD | WS_VISIBLE, CRect(), this, IDI_RUN);
|
||||
m_cRunBtn.SetFont(&m_fBoldDialogFont);
|
||||
|
||||
// Call this after all UI objects are created because this will call LayoutObjects
|
||||
SetWindowPos(NULL, 0, 0, defaultWindowWidth, defaultWindowHeight, 0);
|
||||
CenterWindow(NULL);
|
||||
|
||||
// Set background color to Win32 window color
|
||||
::SetClassLong(GetSafeHwnd(), GCL_HBRBACKGROUND, COLOR_WINDOW);
|
||||
}
|
||||
|
||||
LRESULT CRebuilderWindow::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message) {
|
||||
case WM_SIZE:
|
||||
UINT width = LOWORD(lParam);
|
||||
UINT height = HIWORD(lParam);
|
||||
|
||||
LayoutObjects(width, height);
|
||||
break;
|
||||
}
|
||||
|
||||
return super::WindowProc(message, wParam, lParam);
|
||||
}
|
||||
|
||||
void CRebuilderWindow::LayoutObjects(UINT width, UINT height)
|
||||
{
|
||||
const int btnHeight = 25;
|
||||
|
||||
int padding = m_nFontHeight/2;
|
||||
|
||||
m_cTopLevelTitle.SetWindowPos(NULL, 0, padding, width, m_nFontHeight*2, 0);
|
||||
m_cTopLevelSubtitle.SetWindowPos(NULL, 0, padding+m_nFontHeight*2, width, m_nFontHeight, 0);
|
||||
|
||||
m_cRunBtn.SetWindowPos(NULL, padding, height - btnHeight - padding, width - padding * 2, btnHeight, 0);
|
||||
}
|
||||
|
|
19
src/window.h
19
src/window.h
|
@ -7,6 +7,25 @@ class CRebuilderWindow : public CFrameWnd
|
|||
{
|
||||
public:
|
||||
CRebuilderWindow();
|
||||
|
||||
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
private:
|
||||
void LayoutObjects(UINT width, UINT height);
|
||||
|
||||
enum {
|
||||
IDI_RUN
|
||||
};
|
||||
|
||||
CFont m_fDialogFont;
|
||||
CFont m_fBoldDialogFont;
|
||||
UINT m_nFontHeight;
|
||||
|
||||
CStatic m_cTopLevelTitle;
|
||||
CStatic m_cTopLevelSubtitle;
|
||||
|
||||
CButton m_cRunBtn;
|
||||
|
||||
};
|
||||
|
||||
#endif // CREBUILDERWINDOW_H
|
||||
|
|
Loading…
Reference in a new issue